+++ /dev/null
-/*M///////////////////////////////////////////////////////////////////////////////////////\r
-//\r
-// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
-//\r
-// By downloading, copying, installing or using the software you agree to this license.\r
-// If you do not agree to this license, do not download, install,\r
-// copy or use the software.\r
-//\r
-//\r
-// Intel License Agreement\r
-// For Open Source Computer Vision Library\r
-//\r
-// Copyright (C) 2000, Intel Corporation, all rights reserved.\r
-// Third party copyrights are property of their respective owners.\r
-//\r
-// Redistribution and use in source and binary forms, with or without modification,\r
-// are permitted provided that the following conditions are met:\r
-//\r
-// * Redistribution's of source code must retain the above copyright notice,\r
-// this list of conditions and the following disclaimer.\r
-//\r
-// * Redistribution's in binary form must reproduce the above copyright notice,\r
-// this list of conditions and the following disclaimer in the documentation\r
-// and/or other materials provided with the distribution.\r
-//\r
-// * The name of Intel Corporation may not be used to endorse or promote products\r
-// derived from this software without specific prior written permission.\r
-//\r
-// This software is provided by the copyright holders and contributors "as is" and\r
-// any express or implied warranties, including, but not limited to, the implied\r
-// warranties of merchantability and fitness for a particular purpose are disclaimed.\r
-// In no event shall the Intel Corporation or contributors be liable for any direct,\r
-// indirect, incidental, special, exemplary, or consequential damages\r
-// (including, but not limited to, procurement of substitute goods or services;\r
-// loss of use, data, or profits; or business interruption) however caused\r
-// and on any theory of liability, whether in contract, strict liability,\r
-// or tort (including negligence or otherwise) arising in any way out of\r
-// the use of this software, even if advised of the possibility of such damage.\r
-//\r
-//M*/// StereoGRView.cpp : implementation of the CStereoGRView class\r
-//\r
-\r
-#include "stdafx.h"\r
-#include "StereoGR.h"\r
-#include "MainFrm.h"\r
-\r
-#include "StereoGRDoc.h"\r
-#include "StereoGRView.h"\r
-#include "ChildFrm.h"\r
-#include "PGControl.h"\r
-#include <math.h>\r
-#include "cv.h"\r
-#include <gl\glu.h>\r
-#include "triclops.h"\r
-\r
-#ifdef _DEBUG\r
-#define new DEBUG_NEW\r
-#undef THIS_FILE\r
-static char THIS_FILE[] = __FILE__;\r
-#endif\r
-\r
-#define IS_PTGREY_DOCTYPE IS_PTGREY_DATATYPE(GetDocument()->GetDocType())\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CStereoGRView\r
-\r
-IMPLEMENT_DYNCREATE(CStereoGRView, CView)\r
-\r
-BEGIN_MESSAGE_MAP(CStereoGRView, COpenGLView)\r
- //{{AFX_MSG_MAP(CStereoGRView)\r
- ON_WM_SIZE()\r
- ON_WM_ERASEBKGND()\r
- ON_WM_MOUSEMOVE()\r
- ON_WM_RBUTTONDBLCLK()\r
- ON_WM_CHAR()\r
- ON_WM_KEYDOWN()\r
- //}}AFX_MSG_MAP\r
- // Standard printing commands\r
- ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)\r
- ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)\r
- ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)\r
-END_MESSAGE_MAP()\r
-\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CStereoGRView construction/destruction\r
-\r
-CStereoGRView::CStereoGRView()\r
-{\r
- m_image = 0;\r
- m_auxImage = 0;\r
- m_recipient = 0;\r
- m_bitmap = 0;\r
- memset(m_texture, 0, 3*sizeof(void*));\r
- memset(m_planes, 0, 3*sizeof(IplImage*));\r
-\r
- m_dist = 0;\r
- m_azim = 0;\r
- m_incl = 0;\r
- m_distInc = 0;\r
- m_azimInc = 0;\r
- m_inclInc = 0;\r
-}\r
-\r
-CStereoGRView::~CStereoGRView()\r
-{\r
- ((CMainFrame*)AfxGetMainWnd())->RemoveView(this);\r
- iplDeallocate(m_image, IPL_IMAGE_ALL);\r
- cvReleaseImageHeader(&m_recipient);\r
- if(m_bitmap)\r
- ::DeleteObject(m_bitmap);\r
-\r
- PTGreyUnFreezeData();\r
-\r
- for(int i = 0; i < 3; i++)\r
- {\r
- free(m_texture[i]);\r
- cvReleaseImage(&m_planes[i]);\r
- }\r
-}\r
-\r
-BOOL CStereoGRView::PreCreateWindow(CREATESTRUCT& cs)\r
-{\r
- // TODO: Modify the Window class or styles here by modifying\r
- // the CREATESTRUCT cs\r
-\r
- return CView::PreCreateWindow(cs);\r
-}\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CStereoGRView drawing\r
-\r
-void CStereoGRView::OnDraw(CDC* pDC)\r
-{\r
- if(!m_wasInitialized)\r
- return;\r
-\r
-\r
-#ifdef _GR_TRACE\r
- TRACE("OnDraw: time = %d\n", GetTickCount());\r
-#endif\r
- CStereoGRDoc* pDoc = GetDocument();\r
- ASSERT_VALID(pDoc);\r
-\r
- DrawScene(pDC);\r
-}\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CStereoGRView printing\r
-\r
-BOOL CStereoGRView::OnPreparePrinting(CPrintInfo* pInfo)\r
-{\r
- // default preparation\r
- return DoPreparePrinting(pInfo);\r
-}\r
-\r
-void CStereoGRView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)\r
-{\r
- // TODO: add extra initialization before printing\r
-}\r
-\r
-void CStereoGRView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)\r
-{\r
- // TODO: add cleanup after printing\r
-}\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CStereoGRView diagnostics\r
-\r
-#ifdef _DEBUG\r
-void CStereoGRView::AssertValid() const\r
-{\r
- CView::AssertValid();\r
-}\r
-\r
-void CStereoGRView::Dump(CDumpContext& dc) const\r
-{\r
- CView::Dump(dc);\r
-}\r
-\r
-CStereoGRDoc* CStereoGRView::GetDocument() // non-debug version is inline\r
-{\r
- ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStereoGRDoc)));\r
- return (CStereoGRDoc*)m_pDocument;\r
-}\r
-#endif //_DEBUG\r
-\r
-/////////////////////////////////////////////////////////////////////////////\r
-// CStereoGRView message handlers\r
-\r
-void CStereoGRView::OnInitialUpdate() \r
-{\r
- CView::OnInitialUpdate();\r
-\r
- // Update the document\r
- GetDocument()->Initialize();\r
-\r
- \r
- // Now initialize the view\r
- UpdateParams();\r
-\r
- // Initialize the parent's data\r
- ((CChildFrame*)GetParent())->m_view = this;\r
- ((CMainFrame*)AfxGetMainWnd())->AddView(this);\r
-\r
- // Initialize OpenGL\r
- switch(GetDocument()->GetDocType())\r
- {\r
- case PT_POINTCLOUD_IMAGE:\r
- case GR_MAGICCUBE:\r
- InitGL();\r
- break;\r
- }\r
-\r
- UpdatePosition();\r
-\r
- m_wasInitialized = TRUE;\r
-}\r
-\r
-void CStereoGRView::UpdateParams()\r
-{\r
- STEREOGRAPP(app)\r
- int dataType = GetDocument()->GetDocType();\r
- int width = PTGreyGetWidth(IS_PTGREY_DOCTYPE ? dataType : PT_RIGHT_RAW_IMAGE);\r
- int height = PTGreyGetHeight(IS_PTGREY_DOCTYPE ? dataType : PT_RIGHT_RAW_IMAGE);\r
- m_pixelSize = PTGreyGetPixelSize(IS_PTGREY_DOCTYPE ? dataType : 1);\r
-\r
- ((CChildFrame*)GetParent())->m_imageSize.cx = width;\r
- ((CChildFrame*)GetParent())->m_imageSize.cy = height;\r
-\r
- if(dataType != PT_POINTCLOUD_IMAGE)\r
- {\r
- m_image = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);\r
- m_recipient = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, m_pixelSize);\r
- if(m_pixelSize == 4)\r
- m_recipient->alphaChannel = 4;\r
- }\r
-\r
- /* Restoring the window size */\r
- CWnd* parent = GetParent();\r
- CRect client, window, mainRect;\r
- CSize newSize;\r
- parent->GetClientRect(&client);\r
- parent->GetWindowRect(&window);\r
- AfxGetMainWnd()->GetWindowRect(&mainRect);\r
- POINT tl = app->m_TopLefts[dataType];\r
- if(tl.x < 0 || tl.x > mainRect.Size().cx)\r
- tl.x = 0;\r
- if(tl.y < 0 || tl.y > mainRect.Size().cy)\r
- tl.y = 0;\r
-\r
- newSize = CSize(width, height) + window.Size() - client.Size();\r
-// parent->MoveWindow(tl.x, tl.y, newSize.cx, newSize.cy);\r
-// parent->ShowWindow(SW_SHOW);\r
-\r
- if(!IS_PTGREY_DOCTYPE)\r
- {\r
- iplSet(m_image, 0);\r
- Invalidate();\r
- UpdateWindow();\r
- }\r
-}\r
-\r
-\r
-BOOL CStereoGRView::RetrieveImage()\r
-{\r
- if(!m_wasInitialized)\r
- return FALSE;\r
-\r
-#ifdef _GR_TRACE\r
- TRACE("RetrieveImage: time = %d\n", GetTickCount());\r
-#endif\r
- \r
- int dataType = GetDocument()->GetDocType();\r
- \r
- m_recipient->imageData = const_cast<char*>(PTGreyGetDataPointer(dataType));\r
- switch(m_pixelSize)\r
- {\r
- case 4:\r
- {\r
- // Convert the data\r
- for(int i = 0; i < 3; i++)\r
- {\r
- m_image->roi = iplCreateROI(i + 1, 0, 0, m_image->width, m_image->height);\r
- m_recipient->roi = m_image->roi;\r
- iplCopy(m_recipient, m_image);\r
- iplDeleteROI(m_image->roi);\r
- }\r
- m_image->roi = 0;\r
- m_recipient->roi = 0;\r
- break;\r
- }\r
- \r
- case 1:\r
- {\r
- int mind, maxd;\r
- PTGreyGetProperty("MinDisparity", &mind);\r
- PTGreyGetProperty("MaxDisparity", &maxd);\r
-\r
- int scale = (int)floor(255.0f/(maxd - mind));\r
- for(int i = 0; i < 3; i++)\r
- {\r
- m_image->roi = iplCreateROI(i + 1, 0, 0, m_image->width, m_image->height);\r
- m_recipient->roi = iplCreateROI(1, 0, 0, m_image->width, m_image->height);\r
- iplCopy(m_recipient, m_image);\r
- if(dataType == PT_DISPARITY_IMAGE) \r
- {\r
- // Rescale the image\r
- iplMultiplyS(m_image, m_image, scale);\r
- }\r
- iplDeleteROI(m_image->roi);\r
- iplDeleteROI(m_recipient->roi);\r
- }\r
- m_image->roi = 0;\r
- m_recipient->roi = 0;\r
-\r
- break;\r
- }\r
-\r
- default:\r
- ASSERT(0);\r
- break;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-void CStereoGRView::OnSize(UINT nType, int cx, int cy) \r
-{\r
- \r
- CStereoGRDoc* pDoc = GetDocument();\r
- int docType = pDoc->GetDocType();\r
- if(docType == PT_POINTCLOUD_IMAGE || docType == GR_MAGICCUBE)\r
- COpenGLView::OnSize(nType, cx, cy);\r
- else\r
- CView::OnSize(nType, cx, cy);\r
- \r
- InvalidateRect(0, 0); \r
- UpdateWindow();\r
-}\r
-\r
-BOOL CStereoGRView::OnEraseBkgnd(CDC* pDC) \r
-{\r
- return TRUE;\r
-}\r
-\r
-void CStereoGRView::Update() \r
-{\r
- if(IsNewData())\r
- {\r
- UpdateData();\r
- UpdateView();\r
- if(GetDocument()->GetDocType() == PT_DISPARITY_IMAGE)\r
- TRACE0("Updated the image\n");\r
- }\r
- else\r
- {\r
- DefaultData();\r
- DefaultView();\r
- if(GetDocument()->GetDocType() == PT_DISPARITY_IMAGE)\r
- TRACE0("The image did not change\n");\r
- }\r
-}\r
-\r
-int gl_frame_count = -1;\r
-\r
-double camDist = 3, camAzim = 0, camIncl = 0/*-900*/, camX = 0, camY = -0.5;\r
-int shifting = 0, xold, yold, WHICH_BUTTON_ON, DispCount = 0; \r
-double coneMinX = -0.5, coneMaxX = 0.5, coneMinY = -0.5, coneMaxY = 0.5, coneMaxZ = 1.0;\r
-const MinCloudCount = 200;\r
-\r
-void CStereoGRView::InitGL()\r
-{\r
- // Make the GL window a child of the main frame...\r
- STEREOGRAPP(app)\r
-\r
- InitOpenGL();\r
-\r
- /* Initialize GL */\r
- CRect clientRect;\r
- GetClientRect(&clientRect);\r
- glViewport(0, 0, clientRect.Size().cx, clientRect.Size().cy);\r
- glEnable(GL_CULL_FACE);\r
- glEnable(GL_DEPTH_TEST);\r
-\r
- if(GetDocument()->GetDocType() == GR_MAGICCUBE)\r
- {\r
- /* initialize the model */\r
- InitMagicCube();\r
- }\r
-}\r
-\r
-void CStereoGRView::ProcessImage()\r
-{\r
- int dataType = GetDocument()->GetDocType();\r
-}\r
-\r
-void CStereoGRView::UpdateData()\r
-{\r
- int dataType = GetDocument()->GetDocType();\r
- if(dataType == PT_POINTCLOUD_IMAGE)\r
- {\r
- RetrievePointCloud();\r
- }\r
- else if(IS_PTGREY_DATATYPE(dataType))\r
- {\r
- RetrieveImage();\r
- }\r
- else\r
- {\r
- RetrieveUserImage();\r
- }\r
-}\r
-\r
-void CStereoGRView::UpdateView()\r
-{\r
- InvalidateRect(0, 0);\r
- UpdateWindow();\r
-}\r
-\r
-IplImage* CStereoGRView::GetImage()\r
-{\r
- return m_image;\r
-}\r
-\r
-IplImage* CStereoGRView::GetRecipient()\r
-{\r
- return m_recipient;\r
-}\r
-\r
-BOOL CStereoGRView::IsNewData()\r
-{\r
- int docType = GetDocument()->GetDocType();\r
- if(IS_PTGREY_DATATYPE(docType))\r
- {\r
- return PTGreyIsNewData(docType);\r
- }\r
- else\r
- {\r
- STEREOGRAPP(app)\r
- return app->IsNewData();\r
- }\r
-}\r
-\r
-BOOL CStereoGRView::RetrieveUserImage()\r
-{\r
- int dataType = GetDocument()->GetDocType();\r
- switch(dataType)\r
- {\r
- case GR_MASK_VIEW:\r
- {\r
- STEREOGRAPP(app)\r
- IplImage* image = app->m_findHand.m_mask;\r
- if(image)\r
- {\r
- iplSet(m_image, 0);\r
- IplROI roi = {0, 0, 0, 0, 0};\r
- roi.width = image->width;\r
- roi.height = image->height;\r
- m_image->roi = &roi;\r
- for(int i = 0; i < 3; i++)\r
- {\r
- roi.coi = i + 1;\r
- iplCopy(image, m_image);\r
- }\r
- m_image->roi = 0;\r
- }\r
- else\r
- iplSet(m_image, 0);\r
- }\r
- break;\r
- }\r
-\r
- return TRUE;\r
-}\r
-\r
-void CStereoGRView::DefaultData()\r
-{\r
- switch(GetDocument()->GetDocType())\r
- {\r
- case GR_MASK_VIEW:\r
- iplSet(m_image, 0);\r
- break;\r
- }\r
-}\r
-\r
-void CStereoGRView::DefaultView()\r
-{\r
- UpdateView();\r
-}\r
-\r
-void CStereoGRView::UpdatePosition()\r
-{\r
- STEREOGRAPP(app)\r
- int docType = GetDocument()->GetDocType();\r
- int width = PTGreyGetWidth(IS_PTGREY_DOCTYPE ? docType : PT_RIGHT_RAW_IMAGE);\r
- int height = PTGreyGetHeight(IS_PTGREY_DOCTYPE ? docType : PT_RIGHT_RAW_IMAGE);\r
- CView* view = app->GetView(docType);\r
- if(view)\r
- {\r
- CRect windowRect, clientRect, mainRect;\r
- CWnd* wnd = GetParent();\r
- wnd->GetWindowRect(&windowRect);\r
- wnd->GetClientRect(&clientRect);\r
- ((CMainFrame*)AfxGetMainWnd())->GetClientRect(mainRect);\r
- CPoint tl = CPoint(app->m_TopLefts[docType]) + mainRect.TopLeft() - CPoint(4, 4);\r
- if(tl.x == -1)\r
- return;\r
-\r
- if(tl.x < 0 || tl.x > clientRect.Size().cx)\r
- tl.x = 0;\r
- if(tl.y < 0 || tl.y > clientRect.Size().cy)\r
- tl.y = 0;\r
- CSize windowSize = CSize(width, height) + windowRect.Size() - clientRect.Size();\r
- ::MoveWindow(wnd->m_hWnd, tl.x, tl.y, windowSize.cx, windowSize.cy, TRUE);\r
- }\r
-}\r
-\r
-void CStereoGRView::OnDrawImage(CDC *pDC)\r
-{\r
- if(!m_image)\r
- {\r
- return;\r
- }\r
-\r
- HDC hdc;\r
- hdc = ::CreateCompatibleDC(pDC->m_hDC);\r
-\r
- // Display the current image\r
- char buffer[sizeof(BITMAPINFO)];\r
- BITMAPINFO* binfo = (BITMAPINFO*)buffer;\r
- memset(binfo, 0, sizeof(BITMAPINFOHEADER));\r
- binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);\r
- if(!m_bitmap)\r
- {\r
- // Create the bitmap\r
-\r
- BITMAPINFOHEADER* bih = &binfo->bmiHeader;\r
- bih->biBitCount = m_image->nChannels*8;\r
- bih->biWidth = m_image->width;\r
- bih->biHeight = m_image->height;\r
- bih->biPlanes = 1;\r
- bih->biCompression = BI_RGB;\r
- bih->biSizeImage = 0;\r
- \r
- m_bitmap = CreateDIBSection(hdc, binfo, 0, 0, 0, DIB_RGB_COLORS);\r
- }\r
-\r
- int colors = DIB_RGB_COLORS;\r
- \r
- ::SelectObject(hdc, m_bitmap);\r
- binfo->bmiHeader.biBitCount = 0;\r
- GetDIBits(hdc, m_bitmap, 0, 0, 0, binfo, colors);\r
- binfo->bmiHeader.biBitCount = 24;\r
- binfo->bmiHeader.biHeight = -abs(binfo->bmiHeader.biHeight);\r
- SetDIBits(hdc, m_bitmap, 0, m_image->height, m_image->imageData, binfo, colors);\r
-\r
-\r
- ::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);\r
- CRect client;\r
- GetClientRect(&client);\r
- ::StretchBlt(pDC->m_hDC, 0, 0, client.Size().cx, client.Size().cy, \r
- hdc, 0, 0, m_image->width, m_image->height, SRCCOPY);\r
-// ::BitBlt(pDC->m_hDC, 0, 0, m_image->width, m_image->height, \r
-// hdc, 0, 0, SRCCOPY);\r
- ::DeleteDC(hdc);\r
-}\r
-\r
-void CStereoGRView::OnDrawPointCloud()\r
-{\r
- CvPoint3D32f *ZKeyBuffer; float v[6];\r
- BeginScene();\r
- glViewport(0, 0, m_width, m_height);\r
-\r
- // Setup projection matrix\r
- glMatrixMode(GL_PROJECTION);\r
- glLoadIdentity();\r
- gluPerspective( /* field of view in degree */ 45.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 1000.0);\r
-\r
- // position the camera\r
- glMatrixMode(GL_MODELVIEW);\r
- glLoadIdentity();\r
- glTranslated(0, 0, -camDist);\r
- glTranslated(m_translate[0], m_translate[1], m_translate[2]);\r
- glTranslated(0,0,-1.3);\r
- glMultMatrixd(m_rotate);\r
- glRotated(180, 0.0, 0.0, 1.0);\r
-\r
-// PTGreyFreezeData(INFINITE);\r
- ZKeyBuffer = (CvPoint3D32f*)m_points.begin();\r
-\r
- glColor3f(0,1,0);\r
- int pointCount = m_points.size()/3;\r
-\r
- int swidth = PTGreyGetWidth(PT_DISPARITY_IMAGE);\r
- int sheight = PTGreyGetHeight(PT_DISPARITY_IMAGE);\r
- glVertexPointer(3, GL_FLOAT, 0, ZKeyBuffer);\r
- glEnableClientState(GL_VERTEX_ARRAY);\r
- glDrawArrays(GL_POINTS, 0, pointCount);\r
-/*\r
- glBegin(GL_POINTS);\r
- for(int i = 0; i < pointCount; i++)\r
- {\r
- glVertex3f(ZKeyBuffer[i].x, ZKeyBuffer[i].y, ZKeyBuffer[i].z);\r
- }\r
- glEnd();\r
-*/\r
-\r
-// PTGreyUnFreezeData();\r
- \r
- if (pointCount > MinCloudCount) \r
- {\r
- float* OpenGLLine = (float*)&((CStereoGRApp*)AfxGetApp())->m_findHand.m_line;\r
- // draw the line \r
- glColor3f(1,0,0);\r
- glBegin(GL_LINE_STRIP);\r
- v[0] = OpenGLLine[3] - OpenGLLine[0];\r
- v[1] = OpenGLLine[4] - OpenGLLine[1];\r
- v[2] = OpenGLLine[5] - OpenGLLine[2];\r
- v[3] = OpenGLLine[3] + OpenGLLine[0];\r
- v[4] = OpenGLLine[4] + OpenGLLine[1];\r
- v[5] = OpenGLLine[5] + OpenGLLine[2];\r
- glVertex3d(v[0], v[1], v[2]); \r
- glVertex3d(v[3], v[4], v[5]); \r
- glEnd();\r
- }\r
- \r
- // draw the viewing cone\r
- glColor3f(1,1,0); \r
- // big square\r
- glBegin(GL_LINE_STRIP);\r
- glVertex3d(coneMinX, coneMinY, coneMaxZ);\r
- glVertex3d(coneMinX, coneMaxY, coneMaxZ);\r
- glVertex3d(coneMaxX, coneMaxY, coneMaxZ);\r
- glVertex3d(coneMaxX, coneMinY, coneMaxZ);\r
-\r
- // four lines\r
- glBegin(GL_LINES);\r
- glVertex3d(0,0,0);\r
- glVertex3d(coneMinX, coneMinY, coneMaxZ);\r
- glVertex3d(0,0,0);\r
- glVertex3d(coneMinX, coneMaxY, coneMaxZ);\r
- glVertex3d(0,0,0);\r
- glVertex3d(coneMaxX, coneMaxY, coneMaxZ);\r
- glVertex3d(0,0,0);\r
- glVertex3d(coneMaxX, coneMinY, coneMaxZ);\r
- glEnd();\r
-\r
- glTranslated(0,0,1.3);\r
-\r
- EndScene();\r
-}\r
-\r
-void CStereoGRView::OnMouseMove(UINT nFlags, CPoint point) \r
-{\r
- CStereoGRDoc* pDoc = GetDocument();\r
- int docType = pDoc->GetDocType();\r
- if(docType == PT_POINTCLOUD_IMAGE || docType == GR_MAGICCUBE)\r
- COpenGLView::OnMouseMove(nFlags, point);\r
- else\r
- CView::OnMouseMove(nFlags, point);\r
-}\r
-\r
-\r
-void CStereoGRView::OnRButtonDblClk(UINT nFlags, CPoint point) \r
-{\r
- InitCameraPosition(); \r
- OnDrawPointCloud();\r
- COpenGLView::OnRButtonDblClk(nFlags, point);\r
-}\r
-\r
-void CStereoGRView::OnDrawMagicCube()\r
-{\r
- bool is_texture = m_texture[0] ? true : false;\r
- STEREOGRAPP(app);\r
- SetOwnContext();\r
- glViewport(0, 0, m_width, m_height);\r
-\r
- IplImage* data[3];\r
- data[0] = app->GetView(PT_RIGHT_RAW_IMAGE)->GetImage();\r
- data[1] = app->GetView(PT_TOP_RAW_IMAGE)->GetImage();\r
- data[2] = app->GetView(PT_LEFT_RAW_IMAGE)->GetImage();\r
- int width = data[0]->width;\r
- int height = data[0]->height;\r
- const char* bits[3];\r
- for(int i = 0; i < 3; i++)\r
- bits[i] = data[i]->imageData;\r
- \r
- InitTexture(width, height);\r
- ScaleTextures(width, height, (const void**)bits, 3);\r
- glPixelStorei(GL_UNPACK_ALIGNMENT, 1);\r
-\r
-// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);\r
-// glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);\r
- glShadeModel(GL_SMOOTH);\r
-\r
- BeginScene();\r
- glDisable(GL_CULL_FACE);\r
- glMatrixMode(GL_PROJECTION);\r
- glLoadIdentity();\r
- gluPerspective( /* field of view in degree */ 45.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 1000.0);\r
- glMatrixMode(GL_MODELVIEW);\r
- glLoadIdentity();\r
- m_azim += m_azimInc*10;\r
- m_incl += m_inclInc*10;\r
- m_dist += m_distInc;\r
- m_azimInc *= 0.95f;\r
- m_inclInc *= 0.95f;\r
- m_distInc *= 0.95f;\r
- glTranslated(0, 0, -m_dist);\r
- glTranslated(0, 0, -2);\r
- glRotated(m_azim, 0.0, 1.0, 0.0);\r
- glRotated(m_incl, 0.0, 0.0, 1.0);\r
- glMultMatrixd(m_rotate);\r
-\r
- if(!is_texture)\r
- {\r
- glTexImage2D(GL_TEXTURE_2D, 0, 3, m_tex_width, m_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_texture[0]);\r
- }\r
- else\r
- {\r
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_width, m_tex_height, GL_RGB, GL_UNSIGNED_BYTE, m_texture[0]);\r
- }\r
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\r
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
- glEnable(GL_TEXTURE_2D);\r
- glBegin(GL_QUADS);\r
- glColor3f(1, 1, 1);\r
-\r
- glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, -0.5);\r
- glTexCoord2f(1, 1); glVertex3f( 0.5, -0.5, -0.5);\r
- glTexCoord2f(1, 0); glVertex3f( 0.5, 0.5, -0.5);\r
- glTexCoord2f(0, 0); glVertex3f(-0.5, 0.5, -0.5);\r
-\r
- glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, 0.5);\r
- glTexCoord2f(1, 1); glVertex3f( 0.5, -0.5, 0.5);\r
- glTexCoord2f(1, 0); glVertex3f( 0.5, 0.5, 0.5);\r
- glTexCoord2f(0, 0); glVertex3f(-0.5, 0.5, 0.5);\r
-\r
- glEnd();\r
- \r
- if(!is_texture)\r
- {\r
- glTexImage2D(GL_TEXTURE_2D, 0, 3, m_tex_width, m_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_texture[1]);\r
- }\r
- else\r
- {\r
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_width, m_tex_height, GL_RGB, GL_UNSIGNED_BYTE, m_texture[1]);\r
- }\r
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\r
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
- glEnable(GL_TEXTURE_2D);\r
- glBegin(GL_QUADS);\r
- glColor3f(1, 1, 1);\r
-\r
- glTexCoord2f(0, 1); glVertex3f(0.5, -0.5, -0.5);\r
- glTexCoord2f(1, 1); glVertex3f(0.5, -0.5, 0.5);\r
- glTexCoord2f(1, 0); glVertex3f(0.5, 0.5, 0.5);\r
- glTexCoord2f(0, 0); glVertex3f(0.5, 0.5, -0.5);\r
-\r
- glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, -0.5);\r
- glTexCoord2f(1, 1); glVertex3f(-0.5, -0.5, 0.5);\r
- glTexCoord2f(1, 0); glVertex3f(-0.5, 0.5, 0.5);\r
- glTexCoord2f(0, 0); glVertex3f(-0.5, 0.5, -0.5);\r
-\r
- glEnd();\r
-\r
- if(!is_texture)\r
- {\r
- glTexImage2D(GL_TEXTURE_2D, 0, 3, m_tex_width, m_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_texture[2]);\r
- }\r
- else\r
- {\r
- glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_width, m_tex_height, GL_RGB, GL_UNSIGNED_BYTE, m_texture[2]);\r
- }\r
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);\r
- glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);\r
- glEnable(GL_TEXTURE_2D);\r
- glBegin(GL_QUADS);\r
- glColor3f(1, 1, 1);\r
-\r
- glTexCoord2f(0, 1); glVertex3f(-0.5, 0.5, -0.5);\r
- glTexCoord2f(1, 1); glVertex3f(-0.5, 0.5, 0.5);\r
- glTexCoord2f(1, 0); glVertex3f( 0.5, 0.5, 0.5);\r
- glTexCoord2f(0, 0); glVertex3f( 0.5, 0.5, -0.5);\r
-\r
- glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, -0.5);\r
- glTexCoord2f(1, 1); glVertex3f(-0.5, -0.5, 0.5);\r
- glTexCoord2f(1, 0); glVertex3f( 0.5, -0.5, 0.5);\r
- glTexCoord2f(0, 0); glVertex3f( 0.5, -0.5, -0.5);\r
-\r
- glEnd();\r
- EndScene();\r
-}\r
-\r
-void CStereoGRView::InitMagicCube()\r
-{\r
- STEREOGRAPP(app);\r
- SetOwnContext();\r
-}\r
-\r
-void CStereoGRView::DrawScene(CDC* pDC)\r
-{\r
- switch(GetDocument()->GetDocType())\r
- {\r
- case PT_POINTCLOUD_IMAGE:\r
- OnDrawPointCloud();\r
- break;\r
- case GR_MAGICCUBE:\r
- OnDrawMagicCube();\r
- break;\r
-\r
- default:\r
- OnDrawImage(pDC);\r
- break;\r
- }\r
-}\r
-\r
-void CStereoGRView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags) \r
-{\r
- STEREOGRAPP(app)\r
- CView::OnChar(nChar, nRepCnt, nFlags);\r
- \r
- COpenGLView::OnChar(nChar, nRepCnt, nFlags);\r
-}\r
-\r
-void CStereoGRView::InitTexture(int width, int height)\r
-{\r
- if(m_texture[0])\r
- return;\r
- \r
- switch(width)\r
- {\r
- case 160:\r
- m_tex_width = 128;\r
- m_tex_height = 128;\r
- break;\r
-\r
- case 320:\r
- m_tex_width = 256;\r
- m_tex_height = 256;\r
- break;\r
-\r
- case 640:\r
- m_tex_width = 512;\r
- m_tex_height = 512;\r
- break;\r
- }\r
-\r
- int pixel_count = m_tex_width*m_tex_height;\r
- for(int i = 0; i < 3; i++)\r
- m_texture[i] = malloc(3*pixel_count);\r
-}\r
-\r
-\r
-void CStereoGRView::ScaleTextures(int width, int height, const void** bits, int count)\r
-{\r
- int pixel_count = m_tex_width*m_tex_height;\r
- IplImage* source = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);\r
- IplImage* dest = cvCreateImageHeader(cvSize(m_tex_width, m_tex_height), IPL_DEPTH_8U, 3);\r
-\r
- if(!m_planes[0])\r
- {\r
- m_planes[0] = cvCreateImage(cvSize(m_tex_width, m_tex_height), IPL_DEPTH_8U, 1);\r
- m_planes[1] = cvCreateImage(cvSize(m_tex_width, m_tex_height), IPL_DEPTH_8U, 1); \r
- }\r
- \r
- for(int i = 0; i < count; i++)\r
- {\r
- source->imageData = (char*)bits[i];\r
- dest->imageData = (char*)m_texture[i];\r
-\r
- iplSet(dest, 255);\r
- iplResize(source, dest, m_tex_width, width, m_tex_height, height, IPL_INTER_NN);\r
-\r
- dest->roi = iplCreateROI(1, 0, 0, m_tex_width, m_tex_height);\r
- iplCopy(dest, m_planes[0]);\r
- dest->roi->coi = 3;\r
- iplCopy(dest, m_planes[1]);\r
- iplCopy(m_planes[0], dest);\r
- dest->roi->coi = 1;\r
- iplCopy(m_planes[0], dest);\r
- iplDeleteROI(dest->roi);\r
- dest->roi = 0;\r
- }\r
- \r
- cvReleaseImageHeader(&source);\r
- cvReleaseImageHeader(&dest);\r
-// int e = gluScaleImage(GL_RGB, width, height, GL_UNSIGNED_BYTE, bits, \r
-// m_tex_width, m_tex_height*height/width, GL_UNSIGNED_BYTE, m_texture);\r
-}\r
-\r
-void CStereoGRView::RetrievePointCloud()\r
-{\r
- m_points.clear();\r
- PTGreyFreezeData(INFINITE);\r
-\r
- int count = PTGreyGetPointCount();\r
- if(count > 0)\r
- {\r
- const float* points = (const float*)PTGreyGetDataPointer(PT_POINTCLOUD_IMAGE);\r
- m_points.insert(m_points.begin(), &points[0], &points[3*count - 1]);\r
- }\r
- PTGreyUnFreezeData();\r
-}\r
-\r
-void CStereoGRView::RotateAzim(float val)\r
-{\r
- m_azimInc = val;\r
-}\r
-\r
-void CStereoGRView::RotateIncl(float val)\r
-{\r
- m_inclInc = val;\r
-}\r
-\r
-void CStereoGRView::Translate(float val)\r
-{\r
- m_distInc = val;\r
-}\r
-\r
-void CStereoGRView::InitModel()\r
-{\r
- m_azimInc = 0;\r
- m_inclInc = 0;\r
- m_distInc = 0;\r
-\r
- m_azim = 0;\r
- m_incl = 0;\r
- m_dist = 0;\r
-}\r
-\r
-void CStereoGRView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags) \r
-{\r
- if(nChar == '7') \r
- {\r
- InitModel();\r
- InitCameraPosition();\r
- OnDrawMagicCube();\r
- }\r
- COpenGLView::OnKeyDown(nChar, nRepCnt, nFlags);\r
-}\r