1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\r
5 // By downloading, copying, installing or using the software you agree to this license.
\r
6 // If you do not agree to this license, do not download, install,
\r
7 // copy or use the software.
\r
10 // Intel License Agreement
\r
11 // For Open Source Computer Vision Library
\r
13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
\r
14 // Third party copyrights are property of their respective owners.
\r
16 // Redistribution and use in source and binary forms, with or without modification,
\r
17 // are permitted provided that the following conditions are met:
\r
19 // * Redistribution's of source code must retain the above copyright notice,
\r
20 // this list of conditions and the following disclaimer.
\r
22 // * Redistribution's in binary form must reproduce the above copyright notice,
\r
23 // this list of conditions and the following disclaimer in the documentation
\r
24 // and/or other materials provided with the distribution.
\r
26 // * The name of Intel Corporation may not be used to endorse or promote products
\r
27 // derived from this software without specific prior written permission.
\r
29 // This software is provided by the copyright holders and contributors "as is" and
\r
30 // any express or implied warranties, including, but not limited to, the implied
\r
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
\r
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
\r
33 // indirect, incidental, special, exemplary, or consequential damages
\r
34 // (including, but not limited to, procurement of substitute goods or services;
\r
35 // loss of use, data, or profits; or business interruption) however caused
\r
36 // and on any theory of liability, whether in contract, strict liability,
\r
37 // or tort (including negligence or otherwise) arising in any way out of
\r
38 // the use of this software, even if advised of the possibility of such damage.
\r
40 //M*/// StereoGRView.cpp : implementation of the CStereoGRView class
\r
44 #include "StereoGR.h"
\r
45 #include "MainFrm.h"
\r
47 #include "StereoGRDoc.h"
\r
48 #include "StereoGRView.h"
\r
49 #include "ChildFrm.h"
\r
50 #include "PGControl.h"
\r
54 #include "triclops.h"
\r
57 #define new DEBUG_NEW
\r
59 static char THIS_FILE[] = __FILE__;
\r
62 #define IS_PTGREY_DOCTYPE IS_PTGREY_DATATYPE(GetDocument()->GetDocType())
\r
64 /////////////////////////////////////////////////////////////////////////////
\r
67 IMPLEMENT_DYNCREATE(CStereoGRView, CView)
\r
69 BEGIN_MESSAGE_MAP(CStereoGRView, COpenGLView)
\r
70 //{{AFX_MSG_MAP(CStereoGRView)
\r
74 ON_WM_RBUTTONDBLCLK()
\r
78 // Standard printing commands
\r
79 ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
\r
80 ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
\r
81 ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
\r
85 /////////////////////////////////////////////////////////////////////////////
\r
86 // CStereoGRView construction/destruction
\r
88 CStereoGRView::CStereoGRView()
\r
94 memset(m_texture, 0, 3*sizeof(void*));
\r
95 memset(m_planes, 0, 3*sizeof(IplImage*));
\r
105 CStereoGRView::~CStereoGRView()
\r
107 ((CMainFrame*)AfxGetMainWnd())->RemoveView(this);
\r
108 iplDeallocate(m_image, IPL_IMAGE_ALL);
\r
109 cvReleaseImageHeader(&m_recipient);
\r
111 ::DeleteObject(m_bitmap);
\r
113 PTGreyUnFreezeData();
\r
115 for(int i = 0; i < 3; i++)
\r
117 free(m_texture[i]);
\r
118 cvReleaseImage(&m_planes[i]);
\r
122 BOOL CStereoGRView::PreCreateWindow(CREATESTRUCT& cs)
\r
124 // TODO: Modify the Window class or styles here by modifying
\r
125 // the CREATESTRUCT cs
\r
127 return CView::PreCreateWindow(cs);
\r
130 /////////////////////////////////////////////////////////////////////////////
\r
131 // CStereoGRView drawing
\r
133 void CStereoGRView::OnDraw(CDC* pDC)
\r
135 if(!m_wasInitialized)
\r
140 TRACE("OnDraw: time = %d\n", GetTickCount());
\r
142 CStereoGRDoc* pDoc = GetDocument();
\r
143 ASSERT_VALID(pDoc);
\r
148 /////////////////////////////////////////////////////////////////////////////
\r
149 // CStereoGRView printing
\r
151 BOOL CStereoGRView::OnPreparePrinting(CPrintInfo* pInfo)
\r
153 // default preparation
\r
154 return DoPreparePrinting(pInfo);
\r
157 void CStereoGRView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
\r
159 // TODO: add extra initialization before printing
\r
162 void CStereoGRView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
\r
164 // TODO: add cleanup after printing
\r
167 /////////////////////////////////////////////////////////////////////////////
\r
168 // CStereoGRView diagnostics
\r
171 void CStereoGRView::AssertValid() const
\r
173 CView::AssertValid();
\r
176 void CStereoGRView::Dump(CDumpContext& dc) const
\r
181 CStereoGRDoc* CStereoGRView::GetDocument() // non-debug version is inline
\r
183 ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CStereoGRDoc)));
\r
184 return (CStereoGRDoc*)m_pDocument;
\r
188 /////////////////////////////////////////////////////////////////////////////
\r
189 // CStereoGRView message handlers
\r
191 void CStereoGRView::OnInitialUpdate()
\r
193 CView::OnInitialUpdate();
\r
195 // Update the document
\r
196 GetDocument()->Initialize();
\r
199 // Now initialize the view
\r
202 // Initialize the parent's data
\r
203 ((CChildFrame*)GetParent())->m_view = this;
\r
204 ((CMainFrame*)AfxGetMainWnd())->AddView(this);
\r
206 // Initialize OpenGL
\r
207 switch(GetDocument()->GetDocType())
\r
209 case PT_POINTCLOUD_IMAGE:
\r
217 m_wasInitialized = TRUE;
\r
220 void CStereoGRView::UpdateParams()
\r
223 int dataType = GetDocument()->GetDocType();
\r
224 int width = PTGreyGetWidth(IS_PTGREY_DOCTYPE ? dataType : PT_RIGHT_RAW_IMAGE);
\r
225 int height = PTGreyGetHeight(IS_PTGREY_DOCTYPE ? dataType : PT_RIGHT_RAW_IMAGE);
\r
226 m_pixelSize = PTGreyGetPixelSize(IS_PTGREY_DOCTYPE ? dataType : 1);
\r
228 ((CChildFrame*)GetParent())->m_imageSize.cx = width;
\r
229 ((CChildFrame*)GetParent())->m_imageSize.cy = height;
\r
231 if(dataType != PT_POINTCLOUD_IMAGE)
\r
233 m_image = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 3);
\r
234 m_recipient = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, m_pixelSize);
\r
235 if(m_pixelSize == 4)
\r
236 m_recipient->alphaChannel = 4;
\r
239 /* Restoring the window size */
\r
240 CWnd* parent = GetParent();
\r
241 CRect client, window, mainRect;
\r
243 parent->GetClientRect(&client);
\r
244 parent->GetWindowRect(&window);
\r
245 AfxGetMainWnd()->GetWindowRect(&mainRect);
\r
246 POINT tl = app->m_TopLefts[dataType];
\r
247 if(tl.x < 0 || tl.x > mainRect.Size().cx)
\r
249 if(tl.y < 0 || tl.y > mainRect.Size().cy)
\r
252 newSize = CSize(width, height) + window.Size() - client.Size();
\r
253 // parent->MoveWindow(tl.x, tl.y, newSize.cx, newSize.cy);
\r
254 // parent->ShowWindow(SW_SHOW);
\r
256 if(!IS_PTGREY_DOCTYPE)
\r
258 iplSet(m_image, 0);
\r
265 BOOL CStereoGRView::RetrieveImage()
\r
267 if(!m_wasInitialized)
\r
271 TRACE("RetrieveImage: time = %d\n", GetTickCount());
\r
274 int dataType = GetDocument()->GetDocType();
\r
276 m_recipient->imageData = const_cast<char*>(PTGreyGetDataPointer(dataType));
\r
277 switch(m_pixelSize)
\r
281 // Convert the data
\r
282 for(int i = 0; i < 3; i++)
\r
284 m_image->roi = iplCreateROI(i + 1, 0, 0, m_image->width, m_image->height);
\r
285 m_recipient->roi = m_image->roi;
\r
286 iplCopy(m_recipient, m_image);
\r
287 iplDeleteROI(m_image->roi);
\r
290 m_recipient->roi = 0;
\r
297 PTGreyGetProperty("MinDisparity", &mind);
\r
298 PTGreyGetProperty("MaxDisparity", &maxd);
\r
300 int scale = (int)floor(255.0f/(maxd - mind));
\r
301 for(int i = 0; i < 3; i++)
\r
303 m_image->roi = iplCreateROI(i + 1, 0, 0, m_image->width, m_image->height);
\r
304 m_recipient->roi = iplCreateROI(1, 0, 0, m_image->width, m_image->height);
\r
305 iplCopy(m_recipient, m_image);
\r
306 if(dataType == PT_DISPARITY_IMAGE)
\r
308 // Rescale the image
\r
309 iplMultiplyS(m_image, m_image, scale);
\r
311 iplDeleteROI(m_image->roi);
\r
312 iplDeleteROI(m_recipient->roi);
\r
315 m_recipient->roi = 0;
\r
328 void CStereoGRView::OnSize(UINT nType, int cx, int cy)
\r
331 CStereoGRDoc* pDoc = GetDocument();
\r
332 int docType = pDoc->GetDocType();
\r
333 if(docType == PT_POINTCLOUD_IMAGE || docType == GR_MAGICCUBE)
\r
334 COpenGLView::OnSize(nType, cx, cy);
\r
336 CView::OnSize(nType, cx, cy);
\r
338 InvalidateRect(0, 0);
\r
342 BOOL CStereoGRView::OnEraseBkgnd(CDC* pDC)
\r
347 void CStereoGRView::Update()
\r
353 if(GetDocument()->GetDocType() == PT_DISPARITY_IMAGE)
\r
354 TRACE0("Updated the image\n");
\r
360 if(GetDocument()->GetDocType() == PT_DISPARITY_IMAGE)
\r
361 TRACE0("The image did not change\n");
\r
365 int gl_frame_count = -1;
\r
367 double camDist = 3, camAzim = 0, camIncl = 0/*-900*/, camX = 0, camY = -0.5;
\r
368 int shifting = 0, xold, yold, WHICH_BUTTON_ON, DispCount = 0;
\r
369 double coneMinX = -0.5, coneMaxX = 0.5, coneMinY = -0.5, coneMaxY = 0.5, coneMaxZ = 1.0;
\r
370 const MinCloudCount = 200;
\r
372 void CStereoGRView::InitGL()
\r
374 // Make the GL window a child of the main frame...
\r
379 /* Initialize GL */
\r
381 GetClientRect(&clientRect);
\r
382 glViewport(0, 0, clientRect.Size().cx, clientRect.Size().cy);
\r
383 glEnable(GL_CULL_FACE);
\r
384 glEnable(GL_DEPTH_TEST);
\r
386 if(GetDocument()->GetDocType() == GR_MAGICCUBE)
\r
388 /* initialize the model */
\r
393 void CStereoGRView::ProcessImage()
\r
395 int dataType = GetDocument()->GetDocType();
\r
398 void CStereoGRView::UpdateData()
\r
400 int dataType = GetDocument()->GetDocType();
\r
401 if(dataType == PT_POINTCLOUD_IMAGE)
\r
403 RetrievePointCloud();
\r
405 else if(IS_PTGREY_DATATYPE(dataType))
\r
411 RetrieveUserImage();
\r
415 void CStereoGRView::UpdateView()
\r
417 InvalidateRect(0, 0);
\r
421 IplImage* CStereoGRView::GetImage()
\r
426 IplImage* CStereoGRView::GetRecipient()
\r
428 return m_recipient;
\r
431 BOOL CStereoGRView::IsNewData()
\r
433 int docType = GetDocument()->GetDocType();
\r
434 if(IS_PTGREY_DATATYPE(docType))
\r
436 return PTGreyIsNewData(docType);
\r
441 return app->IsNewData();
\r
445 BOOL CStereoGRView::RetrieveUserImage()
\r
447 int dataType = GetDocument()->GetDocType();
\r
453 IplImage* image = app->m_findHand.m_mask;
\r
456 iplSet(m_image, 0);
\r
457 IplROI roi = {0, 0, 0, 0, 0};
\r
458 roi.width = image->width;
\r
459 roi.height = image->height;
\r
460 m_image->roi = &roi;
\r
461 for(int i = 0; i < 3; i++)
\r
464 iplCopy(image, m_image);
\r
469 iplSet(m_image, 0);
\r
477 void CStereoGRView::DefaultData()
\r
479 switch(GetDocument()->GetDocType())
\r
482 iplSet(m_image, 0);
\r
487 void CStereoGRView::DefaultView()
\r
492 void CStereoGRView::UpdatePosition()
\r
495 int docType = GetDocument()->GetDocType();
\r
496 int width = PTGreyGetWidth(IS_PTGREY_DOCTYPE ? docType : PT_RIGHT_RAW_IMAGE);
\r
497 int height = PTGreyGetHeight(IS_PTGREY_DOCTYPE ? docType : PT_RIGHT_RAW_IMAGE);
\r
498 CView* view = app->GetView(docType);
\r
501 CRect windowRect, clientRect, mainRect;
\r
502 CWnd* wnd = GetParent();
\r
503 wnd->GetWindowRect(&windowRect);
\r
504 wnd->GetClientRect(&clientRect);
\r
505 ((CMainFrame*)AfxGetMainWnd())->GetClientRect(mainRect);
\r
506 CPoint tl = CPoint(app->m_TopLefts[docType]) + mainRect.TopLeft() - CPoint(4, 4);
\r
510 if(tl.x < 0 || tl.x > clientRect.Size().cx)
\r
512 if(tl.y < 0 || tl.y > clientRect.Size().cy)
\r
514 CSize windowSize = CSize(width, height) + windowRect.Size() - clientRect.Size();
\r
515 ::MoveWindow(wnd->m_hWnd, tl.x, tl.y, windowSize.cx, windowSize.cy, TRUE);
\r
519 void CStereoGRView::OnDrawImage(CDC *pDC)
\r
527 hdc = ::CreateCompatibleDC(pDC->m_hDC);
\r
529 // Display the current image
\r
530 char buffer[sizeof(BITMAPINFO)];
\r
531 BITMAPINFO* binfo = (BITMAPINFO*)buffer;
\r
532 memset(binfo, 0, sizeof(BITMAPINFOHEADER));
\r
533 binfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
536 // Create the bitmap
\r
538 BITMAPINFOHEADER* bih = &binfo->bmiHeader;
\r
539 bih->biBitCount = m_image->nChannels*8;
\r
540 bih->biWidth = m_image->width;
\r
541 bih->biHeight = m_image->height;
\r
543 bih->biCompression = BI_RGB;
\r
544 bih->biSizeImage = 0;
\r
546 m_bitmap = CreateDIBSection(hdc, binfo, 0, 0, 0, DIB_RGB_COLORS);
\r
549 int colors = DIB_RGB_COLORS;
\r
551 ::SelectObject(hdc, m_bitmap);
\r
552 binfo->bmiHeader.biBitCount = 0;
\r
553 GetDIBits(hdc, m_bitmap, 0, 0, 0, binfo, colors);
\r
554 binfo->bmiHeader.biBitCount = 24;
\r
555 binfo->bmiHeader.biHeight = -abs(binfo->bmiHeader.biHeight);
\r
556 SetDIBits(hdc, m_bitmap, 0, m_image->height, m_image->imageData, binfo, colors);
\r
559 ::SetStretchBltMode(pDC->m_hDC, COLORONCOLOR);
\r
561 GetClientRect(&client);
\r
562 ::StretchBlt(pDC->m_hDC, 0, 0, client.Size().cx, client.Size().cy,
\r
563 hdc, 0, 0, m_image->width, m_image->height, SRCCOPY);
\r
564 // ::BitBlt(pDC->m_hDC, 0, 0, m_image->width, m_image->height,
\r
565 // hdc, 0, 0, SRCCOPY);
\r
569 void CStereoGRView::OnDrawPointCloud()
\r
571 CvPoint3D32f *ZKeyBuffer; float v[6];
\r
573 glViewport(0, 0, m_width, m_height);
\r
575 // Setup projection matrix
\r
576 glMatrixMode(GL_PROJECTION);
\r
578 gluPerspective( /* field of view in degree */ 45.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 1000.0);
\r
580 // position the camera
\r
581 glMatrixMode(GL_MODELVIEW);
\r
583 glTranslated(0, 0, -camDist);
\r
584 glTranslated(m_translate[0], m_translate[1], m_translate[2]);
\r
585 glTranslated(0,0,-1.3);
\r
586 glMultMatrixd(m_rotate);
\r
587 glRotated(180, 0.0, 0.0, 1.0);
\r
589 // PTGreyFreezeData(INFINITE);
\r
590 ZKeyBuffer = (CvPoint3D32f*)m_points.begin();
\r
593 int pointCount = m_points.size()/3;
\r
595 int swidth = PTGreyGetWidth(PT_DISPARITY_IMAGE);
\r
596 int sheight = PTGreyGetHeight(PT_DISPARITY_IMAGE);
\r
597 glVertexPointer(3, GL_FLOAT, 0, ZKeyBuffer);
\r
598 glEnableClientState(GL_VERTEX_ARRAY);
\r
599 glDrawArrays(GL_POINTS, 0, pointCount);
\r
601 glBegin(GL_POINTS);
\r
602 for(int i = 0; i < pointCount; i++)
\r
604 glVertex3f(ZKeyBuffer[i].x, ZKeyBuffer[i].y, ZKeyBuffer[i].z);
\r
609 // PTGreyUnFreezeData();
\r
611 if (pointCount > MinCloudCount)
\r
613 float* OpenGLLine = (float*)&((CStereoGRApp*)AfxGetApp())->m_findHand.m_line;
\r
616 glBegin(GL_LINE_STRIP);
\r
617 v[0] = OpenGLLine[3] - OpenGLLine[0];
\r
618 v[1] = OpenGLLine[4] - OpenGLLine[1];
\r
619 v[2] = OpenGLLine[5] - OpenGLLine[2];
\r
620 v[3] = OpenGLLine[3] + OpenGLLine[0];
\r
621 v[4] = OpenGLLine[4] + OpenGLLine[1];
\r
622 v[5] = OpenGLLine[5] + OpenGLLine[2];
\r
623 glVertex3d(v[0], v[1], v[2]);
\r
624 glVertex3d(v[3], v[4], v[5]);
\r
628 // draw the viewing cone
\r
631 glBegin(GL_LINE_STRIP);
\r
632 glVertex3d(coneMinX, coneMinY, coneMaxZ);
\r
633 glVertex3d(coneMinX, coneMaxY, coneMaxZ);
\r
634 glVertex3d(coneMaxX, coneMaxY, coneMaxZ);
\r
635 glVertex3d(coneMaxX, coneMinY, coneMaxZ);
\r
640 glVertex3d(coneMinX, coneMinY, coneMaxZ);
\r
642 glVertex3d(coneMinX, coneMaxY, coneMaxZ);
\r
644 glVertex3d(coneMaxX, coneMaxY, coneMaxZ);
\r
646 glVertex3d(coneMaxX, coneMinY, coneMaxZ);
\r
649 glTranslated(0,0,1.3);
\r
654 void CStereoGRView::OnMouseMove(UINT nFlags, CPoint point)
\r
656 CStereoGRDoc* pDoc = GetDocument();
\r
657 int docType = pDoc->GetDocType();
\r
658 if(docType == PT_POINTCLOUD_IMAGE || docType == GR_MAGICCUBE)
\r
659 COpenGLView::OnMouseMove(nFlags, point);
\r
661 CView::OnMouseMove(nFlags, point);
\r
665 void CStereoGRView::OnRButtonDblClk(UINT nFlags, CPoint point)
\r
667 InitCameraPosition();
\r
668 OnDrawPointCloud();
\r
669 COpenGLView::OnRButtonDblClk(nFlags, point);
\r
672 void CStereoGRView::OnDrawMagicCube()
\r
674 bool is_texture = m_texture[0] ? true : false;
\r
677 glViewport(0, 0, m_width, m_height);
\r
680 data[0] = app->GetView(PT_RIGHT_RAW_IMAGE)->GetImage();
\r
681 data[1] = app->GetView(PT_TOP_RAW_IMAGE)->GetImage();
\r
682 data[2] = app->GetView(PT_LEFT_RAW_IMAGE)->GetImage();
\r
683 int width = data[0]->width;
\r
684 int height = data[0]->height;
\r
685 const char* bits[3];
\r
686 for(int i = 0; i < 3; i++)
\r
687 bits[i] = data[i]->imageData;
\r
689 InitTexture(width, height);
\r
690 ScaleTextures(width, height, (const void**)bits, 3);
\r
691 glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
\r
693 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
\r
694 // glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
\r
695 glShadeModel(GL_SMOOTH);
\r
698 glDisable(GL_CULL_FACE);
\r
699 glMatrixMode(GL_PROJECTION);
\r
701 gluPerspective( /* field of view in degree */ 45.0, /* aspect ratio */ 1.0, /* Z near */ 1.0, /* Z far */ 1000.0);
\r
702 glMatrixMode(GL_MODELVIEW);
\r
704 m_azim += m_azimInc*10;
\r
705 m_incl += m_inclInc*10;
\r
706 m_dist += m_distInc;
\r
707 m_azimInc *= 0.95f;
\r
708 m_inclInc *= 0.95f;
\r
709 m_distInc *= 0.95f;
\r
710 glTranslated(0, 0, -m_dist);
\r
711 glTranslated(0, 0, -2);
\r
712 glRotated(m_azim, 0.0, 1.0, 0.0);
\r
713 glRotated(m_incl, 0.0, 0.0, 1.0);
\r
714 glMultMatrixd(m_rotate);
\r
718 glTexImage2D(GL_TEXTURE_2D, 0, 3, m_tex_width, m_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_texture[0]);
\r
722 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_width, m_tex_height, GL_RGB, GL_UNSIGNED_BYTE, m_texture[0]);
\r
724 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
\r
725 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
\r
726 glEnable(GL_TEXTURE_2D);
\r
728 glColor3f(1, 1, 1);
\r
730 glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, -0.5);
\r
731 glTexCoord2f(1, 1); glVertex3f( 0.5, -0.5, -0.5);
\r
732 glTexCoord2f(1, 0); glVertex3f( 0.5, 0.5, -0.5);
\r
733 glTexCoord2f(0, 0); glVertex3f(-0.5, 0.5, -0.5);
\r
735 glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, 0.5);
\r
736 glTexCoord2f(1, 1); glVertex3f( 0.5, -0.5, 0.5);
\r
737 glTexCoord2f(1, 0); glVertex3f( 0.5, 0.5, 0.5);
\r
738 glTexCoord2f(0, 0); glVertex3f(-0.5, 0.5, 0.5);
\r
744 glTexImage2D(GL_TEXTURE_2D, 0, 3, m_tex_width, m_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_texture[1]);
\r
748 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_width, m_tex_height, GL_RGB, GL_UNSIGNED_BYTE, m_texture[1]);
\r
750 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
\r
751 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
\r
752 glEnable(GL_TEXTURE_2D);
\r
754 glColor3f(1, 1, 1);
\r
756 glTexCoord2f(0, 1); glVertex3f(0.5, -0.5, -0.5);
\r
757 glTexCoord2f(1, 1); glVertex3f(0.5, -0.5, 0.5);
\r
758 glTexCoord2f(1, 0); glVertex3f(0.5, 0.5, 0.5);
\r
759 glTexCoord2f(0, 0); glVertex3f(0.5, 0.5, -0.5);
\r
761 glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, -0.5);
\r
762 glTexCoord2f(1, 1); glVertex3f(-0.5, -0.5, 0.5);
\r
763 glTexCoord2f(1, 0); glVertex3f(-0.5, 0.5, 0.5);
\r
764 glTexCoord2f(0, 0); glVertex3f(-0.5, 0.5, -0.5);
\r
770 glTexImage2D(GL_TEXTURE_2D, 0, 3, m_tex_width, m_tex_height, 0, GL_RGB, GL_UNSIGNED_BYTE, m_texture[2]);
\r
774 glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_tex_width, m_tex_height, GL_RGB, GL_UNSIGNED_BYTE, m_texture[2]);
\r
776 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
\r
777 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
\r
778 glEnable(GL_TEXTURE_2D);
\r
780 glColor3f(1, 1, 1);
\r
782 glTexCoord2f(0, 1); glVertex3f(-0.5, 0.5, -0.5);
\r
783 glTexCoord2f(1, 1); glVertex3f(-0.5, 0.5, 0.5);
\r
784 glTexCoord2f(1, 0); glVertex3f( 0.5, 0.5, 0.5);
\r
785 glTexCoord2f(0, 0); glVertex3f( 0.5, 0.5, -0.5);
\r
787 glTexCoord2f(0, 1); glVertex3f(-0.5, -0.5, -0.5);
\r
788 glTexCoord2f(1, 1); glVertex3f(-0.5, -0.5, 0.5);
\r
789 glTexCoord2f(1, 0); glVertex3f( 0.5, -0.5, 0.5);
\r
790 glTexCoord2f(0, 0); glVertex3f( 0.5, -0.5, -0.5);
\r
796 void CStereoGRView::InitMagicCube()
\r
802 void CStereoGRView::DrawScene(CDC* pDC)
\r
804 switch(GetDocument()->GetDocType())
\r
806 case PT_POINTCLOUD_IMAGE:
\r
807 OnDrawPointCloud();
\r
819 void CStereoGRView::OnChar(UINT nChar, UINT nRepCnt, UINT nFlags)
\r
822 CView::OnChar(nChar, nRepCnt, nFlags);
\r
824 COpenGLView::OnChar(nChar, nRepCnt, nFlags);
\r
827 void CStereoGRView::InitTexture(int width, int height)
\r
836 m_tex_height = 128;
\r
841 m_tex_height = 256;
\r
846 m_tex_height = 512;
\r
850 int pixel_count = m_tex_width*m_tex_height;
\r
851 for(int i = 0; i < 3; i++)
\r
852 m_texture[i] = malloc(3*pixel_count);
\r
856 void CStereoGRView::ScaleTextures(int width, int height, const void** bits, int count)
\r
858 int pixel_count = m_tex_width*m_tex_height;
\r
859 IplImage* source = cvCreateImageHeader(cvSize(width, height), IPL_DEPTH_8U, 3);
\r
860 IplImage* dest = cvCreateImageHeader(cvSize(m_tex_width, m_tex_height), IPL_DEPTH_8U, 3);
\r
864 m_planes[0] = cvCreateImage(cvSize(m_tex_width, m_tex_height), IPL_DEPTH_8U, 1);
\r
865 m_planes[1] = cvCreateImage(cvSize(m_tex_width, m_tex_height), IPL_DEPTH_8U, 1);
\r
868 for(int i = 0; i < count; i++)
\r
870 source->imageData = (char*)bits[i];
\r
871 dest->imageData = (char*)m_texture[i];
\r
874 iplResize(source, dest, m_tex_width, width, m_tex_height, height, IPL_INTER_NN);
\r
876 dest->roi = iplCreateROI(1, 0, 0, m_tex_width, m_tex_height);
\r
877 iplCopy(dest, m_planes[0]);
\r
878 dest->roi->coi = 3;
\r
879 iplCopy(dest, m_planes[1]);
\r
880 iplCopy(m_planes[0], dest);
\r
881 dest->roi->coi = 1;
\r
882 iplCopy(m_planes[0], dest);
\r
883 iplDeleteROI(dest->roi);
\r
887 cvReleaseImageHeader(&source);
\r
888 cvReleaseImageHeader(&dest);
\r
889 // int e = gluScaleImage(GL_RGB, width, height, GL_UNSIGNED_BYTE, bits,
\r
890 // m_tex_width, m_tex_height*height/width, GL_UNSIGNED_BYTE, m_texture);
\r
893 void CStereoGRView::RetrievePointCloud()
\r
896 PTGreyFreezeData(INFINITE);
\r
898 int count = PTGreyGetPointCount();
\r
901 const float* points = (const float*)PTGreyGetDataPointer(PT_POINTCLOUD_IMAGE);
\r
902 m_points.insert(m_points.begin(), &points[0], &points[3*count - 1]);
\r
904 PTGreyUnFreezeData();
\r
907 void CStereoGRView::RotateAzim(float val)
\r
912 void CStereoGRView::RotateIncl(float val)
\r
917 void CStereoGRView::Translate(float val)
\r
922 void CStereoGRView::InitModel()
\r
933 void CStereoGRView::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
\r
938 InitCameraPosition();
\r
941 COpenGLView::OnKeyDown(nChar, nRepCnt, nFlags);
\r