added GlArrays class and pointCloudShow function
This commit is contained in:
@@ -139,12 +139,17 @@ CV_EXPORTS void setOpenGlContext(const string& winname);
|
||||
|
||||
CV_EXPORTS void updateWindow(const string& winname);
|
||||
|
||||
CV_EXPORTS void imshow(const string& winname, const gpu::GlTexture& tex);
|
||||
CV_EXPORTS void imshow(const string& winname, const gpu::GlBuffer& buf);
|
||||
CV_EXPORTS void imshow(const string& winname, const gpu::GpuMat& d_mat);
|
||||
|
||||
CV_EXPORTS void imshow(const string& winname, const gpu::GlBuffer& buf);
|
||||
|
||||
CV_EXPORTS void imshow(const string& winname, const gpu::GlTexture& tex);
|
||||
|
||||
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlArrays& arr);
|
||||
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlBuffer& points,
|
||||
const gpu::GlBuffer& colors = gpu::GlBuffer(gpu::GlBuffer::ARRAY_BUFFER));
|
||||
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GpuMat& points,
|
||||
const gpu::GpuMat& colors = gpu::GpuMat());
|
||||
CV_EXPORTS void pointCloudShow(const string& winname, const gpu::GlCamera& camera, InputArray points,
|
||||
InputArray colors = InputArray());
|
||||
|
||||
//Only for Qt
|
||||
|
||||
|
@@ -228,6 +228,7 @@ void cv::updateWindow(const string& windowName)
|
||||
namespace
|
||||
{
|
||||
const int CV_TEXTURE_MAGIC_VAL = 0x00287653;
|
||||
const int CV_POINT_CLOUD_MAGIC_VAL = 0x00287654;
|
||||
|
||||
struct GlObjBase
|
||||
{
|
||||
@@ -273,19 +274,40 @@ namespace
|
||||
delete glObj;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
struct GlObj : GlObjBase
|
||||
struct GlObjTex : GlObjBase
|
||||
{
|
||||
T obj;
|
||||
cv::gpu::GlTexture tex;
|
||||
};
|
||||
|
||||
void CV_CDECL glDrawTextureCallback(void* userdata)
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = static_cast<GlObj<cv::gpu::GlTexture>*>(userdata);
|
||||
GlObjTex* texObj = static_cast<GlObjTex*>(userdata);
|
||||
|
||||
CV_DbgAssert(texObj->flag == CV_TEXTURE_MAGIC_VAL);
|
||||
|
||||
cv::gpu::render(texObj->obj);
|
||||
static cv::gpu::GlCamera glCamera;
|
||||
|
||||
glCamera.setupProjectionMatrix();
|
||||
|
||||
cv::gpu::render(texObj->tex);
|
||||
}
|
||||
|
||||
struct GlObjPointCloud : GlObjBase
|
||||
{
|
||||
cv::gpu::GlArrays arr;
|
||||
cv::gpu::GlCamera camera;
|
||||
};
|
||||
|
||||
void CV_CDECL glDrawPointCloudCallback(void* userdata)
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(userdata);
|
||||
|
||||
CV_DbgAssert(pointCloudObj->flag == CV_POINT_CLOUD_MAGIC_VAL);
|
||||
|
||||
pointCloudObj->camera.setupProjectionMatrix();
|
||||
pointCloudObj->camera.setupModelViewMatrix();
|
||||
|
||||
cv::gpu::render(pointCloudObj->arr);
|
||||
}
|
||||
|
||||
void CV_CDECL glCleanCallback(void* userdata)
|
||||
@@ -297,6 +319,58 @@ namespace
|
||||
}
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T> void imshowImpl(const std::string& winname, const T& img)
|
||||
{
|
||||
using namespace cv;
|
||||
|
||||
namedWindow(winname, WINDOW_OPENGL | WINDOW_AUTOSIZE);
|
||||
|
||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||
|
||||
if (autoSize > 0)
|
||||
resizeWindow(winname, img.cols, img.rows);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_TEXTURE_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObjTex* texObj = static_cast<GlObjTex*>(glObj);
|
||||
texObj->tex.copyFrom(img);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjTex* texObj = new GlObjTex;
|
||||
texObj->tex.copyFrom(img);
|
||||
|
||||
glObj = texObj;
|
||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawTextureCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
void cv::imshow( const string& winname, InputArray _img )
|
||||
{
|
||||
Mat img = _img.getMat();
|
||||
@@ -313,43 +387,7 @@ void cv::imshow( const string& winname, InputArray _img )
|
||||
}
|
||||
else
|
||||
{
|
||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||
|
||||
if (autoSize > 0)
|
||||
resizeWindow(winname, img.cols, img.rows);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_TEXTURE_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = static_cast<GlObj<cv::gpu::GlTexture>*>(glObj);
|
||||
texObj->obj.copyFrom(img);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = new GlObj<cv::gpu::GlTexture>;
|
||||
texObj->obj.copyFrom(img);
|
||||
|
||||
glObj = texObj;
|
||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawTextureCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
imshowImpl(winname, img);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
@@ -359,47 +397,7 @@ void cv::imshow(const string& winname, const gpu::GlBuffer& buf)
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
CV_Assert(buf.usage() == gpu::GlBuffer::TEXTURE_BUFFER);
|
||||
|
||||
namedWindow(winname, WINDOW_OPENGL | WINDOW_AUTOSIZE);
|
||||
|
||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||
|
||||
if (autoSize > 0)
|
||||
resizeWindow(winname, buf.cols(), buf.rows());
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_TEXTURE_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = static_cast<GlObj<cv::gpu::GlTexture>*>(glObj);
|
||||
texObj->obj.copyFrom(buf);
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = new GlObj<cv::gpu::GlTexture>;
|
||||
texObj->obj.copyFrom(buf);
|
||||
|
||||
glObj = texObj;
|
||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawTextureCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
imshowImpl(winname, buf);
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -424,7 +422,7 @@ void cv::imshow(const string& winname, const gpu::GlTexture& tex)
|
||||
double autoSize = getWindowProperty(winname, WND_PROP_AUTOSIZE);
|
||||
|
||||
if (autoSize > 0)
|
||||
resizeWindow(winname, tex.cols(), tex.rows());
|
||||
resizeWindow(winname, tex.cols, tex.rows);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
@@ -438,13 +436,13 @@ void cv::imshow(const string& winname, const gpu::GlTexture& tex)
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = static_cast<GlObj<cv::gpu::GlTexture>*>(glObj);
|
||||
texObj->obj = tex;
|
||||
GlObjTex* texObj = static_cast<GlObjTex*>(glObj);
|
||||
texObj->tex = tex;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObj<cv::gpu::GlTexture>* texObj = new GlObj<cv::gpu::GlTexture>;
|
||||
texObj->obj = tex;
|
||||
GlObjTex* texObj = new GlObjTex;
|
||||
texObj->tex = tex;
|
||||
|
||||
glObj = texObj;
|
||||
glObj->flag = CV_TEXTURE_MAGIC_VAL;
|
||||
@@ -461,6 +459,136 @@ void cv::imshow(const string& winname, const gpu::GlTexture& tex)
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlArrays& arr)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
namedWindow(winname, WINDOW_OPENGL);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_POINT_CLOUD_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(glObj);
|
||||
pointCloudObj->arr = arr;
|
||||
pointCloudObj->camera = camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = new GlObjPointCloud;
|
||||
pointCloudObj->arr = arr;
|
||||
pointCloudObj->camera = camera;
|
||||
|
||||
glObj = pointCloudObj;
|
||||
glObj->flag = CV_POINT_CLOUD_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawPointCloudCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_OPENGL
|
||||
|
||||
namespace
|
||||
{
|
||||
template <typename T> void pointCloudShowImpl(const std::string& winname, const cv::gpu::GlCamera& camera, const T& points, const T& colors)
|
||||
{
|
||||
using namespace cv;
|
||||
|
||||
namedWindow(winname, WINDOW_OPENGL);
|
||||
|
||||
setOpenGlContext(winname);
|
||||
|
||||
GlObjBase* glObj = findGlObjByName(winname);
|
||||
|
||||
if (glObj && glObj->flag != CV_POINT_CLOUD_MAGIC_VAL)
|
||||
{
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), 0, 0);
|
||||
glObj = 0;
|
||||
}
|
||||
|
||||
if (glObj)
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = static_cast<GlObjPointCloud*>(glObj);
|
||||
|
||||
pointCloudObj->arr.setVertexArray(points);
|
||||
if (colors.empty())
|
||||
pointCloudObj->arr.resetColorArray();
|
||||
else
|
||||
pointCloudObj->arr.setColorArray(colors);
|
||||
|
||||
pointCloudObj->camera = camera;
|
||||
}
|
||||
else
|
||||
{
|
||||
GlObjPointCloud* pointCloudObj = new GlObjPointCloud;
|
||||
|
||||
pointCloudObj->arr.setVertexArray(points);
|
||||
if (!colors.empty())
|
||||
pointCloudObj->arr.setColorArray(colors);
|
||||
|
||||
pointCloudObj->camera = camera;
|
||||
|
||||
glObj = pointCloudObj;
|
||||
glObj->flag = CV_POINT_CLOUD_MAGIC_VAL;
|
||||
glObj->winname = winname;
|
||||
|
||||
addGlObj(glObj);
|
||||
|
||||
icvSetOpenGlCleanCallback(winname.c_str(), glCleanCallback, glObj);
|
||||
}
|
||||
|
||||
setOpenGlDrawCallback(winname, glDrawPointCloudCallback, glObj);
|
||||
|
||||
updateWindow(winname);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // HAVE_OPENGL
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GlBuffer& points, const gpu::GlBuffer& colors)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
pointCloudShowImpl(winname, camera, points, colors);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, const gpu::GpuMat& points, const gpu::GpuMat& colors)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
pointCloudShowImpl(winname, camera, points, colors);
|
||||
#endif
|
||||
}
|
||||
|
||||
void cv::pointCloudShow(const string& winname, const gpu::GlCamera& camera, InputArray points, InputArray colors)
|
||||
{
|
||||
#ifndef HAVE_OPENGL
|
||||
CV_Error(CV_OpenGlNotSupported, "The library is compiled without OpenGL support");
|
||||
#else
|
||||
pointCloudShowImpl(winname, camera, points, colors);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifndef HAVE_OPENGL
|
||||
|
||||
CV_IMPL void cvCreateOpenGLCallback(const char*, CvOpenGLCallback, void*, double, double, double)
|
||||
|
@@ -405,12 +405,12 @@ double cvGetModeWindow_W32(const char* name)//YV
|
||||
|
||||
CvWindow* window;
|
||||
|
||||
if(!name)
|
||||
if (!name)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL name string" );
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if( !window )
|
||||
CV_ERROR( CV_StsNullPtr, "NULL window" );
|
||||
if (!window)
|
||||
EXIT; // keep silence here
|
||||
|
||||
result = window->status;
|
||||
|
||||
@@ -503,7 +503,7 @@ double cvGetPropWindowAutoSize_W32(const char* name)
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if (!window)
|
||||
EXIT;
|
||||
EXIT; // keep silence here
|
||||
|
||||
result = window->flags & CV_WINDOW_AUTOSIZE;
|
||||
|
||||
@@ -527,7 +527,7 @@ double cvGetRatioWindow_W32(const char* name)
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if (!window)
|
||||
CV_ERROR( CV_StsNullPtr, "NULL window" );
|
||||
EXIT; // keep silence here
|
||||
|
||||
result = static_cast<double>(window->width) / window->height;
|
||||
|
||||
@@ -552,7 +552,7 @@ double cvGetOpenGlProp_W32(const char* name)
|
||||
|
||||
window = icvFindWindowByName( name );
|
||||
if (!window)
|
||||
__CV_EXIT__;
|
||||
EXIT; // keep silence here
|
||||
|
||||
result = window->useGl;
|
||||
|
||||
@@ -808,7 +808,7 @@ namespace
|
||||
0, // Shift Bit Ignored
|
||||
0, // No Accumulation Buffer
|
||||
0, 0, 0, 0, // Accumulation Bits Ignored
|
||||
16, // 16Bit Z-Buffer (Depth Buffer)
|
||||
32, // 32 Bit Z-Buffer (Depth Buffer)
|
||||
0, // No Stencil Buffer
|
||||
0, // No Auxiliary Buffer
|
||||
PFD_MAIN_PLANE, // Main Drawing Layer
|
||||
@@ -845,6 +845,8 @@ namespace
|
||||
|
||||
__BEGIN__;
|
||||
|
||||
delete window->glFuncTab;
|
||||
|
||||
if (window->hGLRC)
|
||||
{
|
||||
wglDeleteContext(window->hGLRC);
|
||||
@@ -1177,9 +1179,6 @@ static void icvRemoveWindow( CvWindow* window )
|
||||
#ifdef HAVE_OPENGL
|
||||
if (window->useGl)
|
||||
{
|
||||
delete window->glFuncTab;
|
||||
cv::gpu::setGlFuncTab(0);
|
||||
|
||||
wglMakeCurrent(window->dc, window->hGLRC);
|
||||
|
||||
if (window->glCleanCallback)
|
||||
|
Reference in New Issue
Block a user