DGtal  0.6.devel
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
Viewer3D.cpp
1 
29 
30 #ifdef _MSC_VER
31 #define NOMINMAX
32 #include <windows.h>
33 #include <GL/gl.h>
34 #include "DGtal/io/viewers/windows/GL/glext.h"
35 #endif
36 
37 #include "DGtal/io/viewers/Viewer3D.h"
38 #include <limits>
39 #include <QColor>
41 
42 using namespace std;
43 using namespace qglviewer;
44 
45 
47 // class Viewer3D
49 
51 // Standard services - public :
52 
53 
54 
55 
56 
58 // Interface - public :
59 
64 void
65 DGtal::Viewer3D::selfDisplay ( std::ostream & out ) const
66 {
67  out << "[Viewer3D]";
68 }
69 
74 bool
76 {
77  return true;
78 }
79 
80 
81 
82 
83 
84 
85 void
87 {
88  for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
89  {
90  glCallList ( myListToAff+i );
91  }
92  for ( unsigned int i=0; i<myLineSetList.size(); i++ )
93  {
94  glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +i ) );
95  }
96 
97  for ( unsigned int i=0; i<myPointSetList.size(); i++ )
98  {
99  glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +myLineSetList.size() +i ) );
100  }
101 }
102 
103 
104 void
106 {
107  glPushMatrix();
108  glMultMatrixd ( manipulatedFrame()->matrix() );
109 
110  glPushMatrix();
111  glScalef(myScaleX, myScaleY, myScaleZ);
112 
113  for ( unsigned int i =0; i< myClippingPlaneList.size(); i++ )
114  {
115  clippingPlaneD3D cp = myClippingPlaneList.at ( i );
116  double eq [4];
117  eq[0]=cp.a;
118  eq[1]=cp.b;
119  eq[2]=cp.c;
120  eq[3]=cp.d;
121  glEnable ( GL_CLIP_PLANE0+i );
122  glClipPlane ( GL_CLIP_PLANE0+i, eq );
123  }
124 
125 
126  Vec centerS = sceneCenter();
127  Vec posCam = camera()->position();
128  double distCam =sqrt ( ( posCam.x-centerS.x ) * ( posCam.x-centerS.x ) +
129  ( posCam.y-centerS.y ) * ( posCam.y-centerS.y ) +
130  ( posCam.z-centerS.z ) * ( posCam.z-centerS.z ) );
131 
132 
133  for ( unsigned int i=0; i<myPointSetList.size(); i++ )
134  {
135  if ( myPointSetList.at ( i ).size() !=0 )
136  {
137  glPointSize ( ( myPointSetList.at ( i ).at ( 0 ).size ) /distCam );
138  }
139  glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +myLineSetList.size() +i+1 ) );
140  }
141 
142  for ( unsigned int i=0; i<myLineSetList.size(); i++ )
143  {
144  if ( myLineSetList.at ( i ).size() !=0 )
145  {
146  glLineWidth ( ( myLineSetList.at ( i ).at ( 0 ).width ) );
147  }
148  glCallList ( GLuint ( myListToAff+myVoxelSetList.size() +1+i ) );
149  }
150 
151  glCallList ( GLuint ( myListToAff+myVoxelSetList.size() ) );
152  for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
153  {
154  glCallList ( myListToAff+i );
155  }
156 
157 
158 
159  // Calling lists associated to Mesh display (see. updateList)
160  unsigned int nbListOfPrimitives = myLineSetList.size() +myVoxelSetList.size() + myPointSetList.size();
161  glLineWidth ( myMeshDefaultLineWidth /distCam );
162  glDisable(GL_CULL_FACE);
163  glCallList ( GLuint ( myListToAff+nbListOfPrimitives+1 ) );
164  if(myViewWire){
165  glLineWidth ( myMeshDefaultLineWidth /distCam );
166  glCallList ( GLuint ( myListToAff+nbListOfPrimitives+2 ) );
167  }
168 
169  glDisable(GL_CULL_FACE);
170  glCallList ( GLuint ( myListToAff+nbListOfPrimitives+3 ) );
171 
172  if(myViewWire){
173  glLineWidth ( myMeshDefaultLineWidth /distCam );
174  glCallList ( GLuint ( myListToAff+nbListOfPrimitives+4 ) );
175  }
176 
177 
178  glDisable(GL_CULL_FACE);
179  glCallList ( GLuint ( myListToAff+nbListOfPrimitives+5 ) );
180  if(myViewWire){
181  glLineWidth ( myMeshDefaultLineWidth /distCam );
182  glCallList ( GLuint ( myListToAff+nbListOfPrimitives+6 ) );
183  }
184 
185 
186 
187 
188 
189 
190 
191  // Drawing all Khalimsky Space Cells
192 
193  for ( unsigned int i=0; i< myKSPointelList.size(); i++ )
194  {
195  glDrawGLPointel ( myKSPointelList.at ( i ) );
196  }
197  for ( unsigned int i=0; i< myKSLinelList.size(); i++ )
198  {
199  glDrawGLLinel ( myKSLinelList.at ( i ) );
200  }
201 
202 
203 
204 
205 
206  // Drawing all Khalimsky Space Cells
207 
208  for ( unsigned int i=0; i< myKSPointelList.size(); i++ )
209  {
210  glDrawGLPointel ( myKSPointelList.at ( i ) );
211  }
212  for ( unsigned int i=0; i< myKSLinelList.size(); i++ )
213  {
214  glDrawGLLinel ( myKSLinelList.at ( i ) );
215  }
216 
217 
218 
219 
220 
221  // Drawing all Khalimsky Space Cells
222 
223  for ( unsigned int i=0; i< myKSPointelList.size(); i++ )
224  {
225  glDrawGLPointel ( myKSPointelList.at ( i ) );
226  }
227  for ( unsigned int i=0; i< myKSLinelList.size(); i++ )
228  {
229  glDrawGLLinel ( myKSLinelList.at ( i ) );
230  }
231 
232  glPopMatrix();
233 
234  glPopMatrix();
235 }
236 
237 #if defined( max )
238 #undef max
239 #define _HAS_MSVC_MAX_ true
240 #endif
241 
242 #if defined( min )
243 #undef min
244 #define _HAS_MSVC_MIN_ true
245 #endif
246 
247 void
249 {
250  myMeshDefaultLineWidth=10.0;
251  myNbListe=0;
252  myViewWire=true;
253  createNewVoxelList ( true );
254  vector<lineD3D> listeLine;
255  myLineSetList.push_back ( listeLine );
256  vector<pointD3D> listePoint;
257  myPointSetList.push_back ( listePoint );
258  myCurrentFillColor = Color ( 220, 220, 220 );
259  myCurrentLineColor = Color ( 22, 22, 222, 50 );
260  myDefaultBackgroundColor = Color ( backgroundColor().red(), backgroundColor().green(),
261  backgroundColor().blue() );
262  myIsBackgroundDefault=true;
263  myBoundingPtLow[0]=numeric_limits<double>::max( );
264  myBoundingPtLow[1]=numeric_limits<double>::max( );
265  myBoundingPtLow[2]=numeric_limits<double>::max( );
266 
267  myBoundingPtUp[0]=numeric_limits<double>::min( );
268  myBoundingPtUp[1]=numeric_limits<double>::min( );
269  myBoundingPtUp[2]=numeric_limits<double>::min( );
270  createNewVoxelList ( true );
271  std::vector<voxelD3D> aKSVoxelList;
272 
273  myCurrentfShiftVisuKSSurfels=0.0;
274  myDefaultColor= Color ( 255, 255, 255 );
275  camera()->showEntireScene();
276  setKeyDescription ( Qt::Key_E, "Export the current display into OFF file (just Voxel, surfel and KSSurfel for now)." );
277  setKeyDescription ( Qt::Key_W, "Switch display with and without wired view of triangle and quad faces." );
278  setKeyDescription ( Qt::Key_T, "Sort elements for display improvements." );
279  setKeyDescription ( Qt::Key_L, "Load last visualisation settings." );
280  setKeyDescription ( Qt::Key_B, "Switch background color with White/Black colors." );
281  setKeyDescription ( Qt::Key_C, "Show camera informations." );
282  setKeyDescription ( Qt::Key_R, "Reset default scale for 3 axes to 1.0f." );
283 
284 
285  setMouseBindingDescription ( Qt::ShiftModifier+Qt::RightButton, "Delete the mouse selected list." );
286  setManipulatedFrame ( new ManipulatedFrame() );
287 
288 }
289 
290 #if defined( _HAS_MSVC_MAX_ )
291 #define max(A,B) ((A)>(B)?(A):(B))
292 #endif
293 
294 #if defined( _HAS_MSVC_MIN_ )
295 #define min(A,B) ((A)<(B)?(A):(B))
296 #endif
297 
298 void
300 {
302  comp.posCam= camera()->position();
303  for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
304  {
305  sort ( myVoxelSetList.at ( i ).begin(), myVoxelSetList.at ( i ).end(), comp );
306  }
308  DGtal::trace.info() << "sort surfel size" << myKSSurfelList.size() << std::endl;
309  sort ( myKSSurfelList.begin(), myKSSurfelList.end(), compSurf );
310 
311 }
312 
313 
314 void
316 {
318  comp.posCam= camera()->position();
319 
320  DGtal::trace.info() << "sort triangle size" << myTriangleList.size() << std::endl;
321  sort ( myTriangleList.begin(), myTriangleList.end(), comp );
322 
323 }
324 
325 
326 
327 
328 void
330 {
332  comp.posCam= camera()->position();
333 
334  DGtal::trace.info() << "sort quad size" << myTriangleList.size() << std::endl;
335  sort ( myQuadList.begin(), myQuadList.end(), comp );
336 
337 }
338 
339 
340 
341 void
343 {
345  comp.posCam= camera()->position();
346 
347  DGtal::trace.info() << "sort polygon size" << myPolygonList.size() << std::endl;
348  sort ( myPolygonList.begin(), myPolygonList.end(), comp );
349 
350 }
351 
352 
353 
354 
355 
356 void
357 DGtal::Viewer3D::postSelection ( const QPoint& point )
358 {
359  camera()->convertClickToLine ( point, myOrig, myDir );
360  bool found;
361  this->myPosSelector= point;
362  mySelectedPoint = camera()->pointUnderPixel ( point, found );
363  if ( found )
364  {
365  DGtal::trace.info() << "Element of liste= " << selectedName() << "selected" << endl;
366  if ( selectedName() !=-1 )
367  {
368  unsigned int id = abs ( selectedName()-1 );
369  if ( id< myVoxelSetList.size() )
370  {
371  DGtal::trace.info() << "deleting list="<< id<<endl;
372  myVoxelSetList.erase ( myVoxelSetList.begin() +id );
373  updateList ( false );
374  }
375  else if ( id< myVoxelSetList.size() +myLineSetList.size() )
376  {
377  myLineSetList.erase ( myLineSetList.begin() + ( id-myVoxelSetList.size() ) );
378  updateList ( false );
379  }
380  else if ( id< myPointSetList.size() +myLineSetList.size() +myVoxelSetList.size() )
381  {
382  myPointSetList.erase ( myPointSetList.begin() + ( id-myVoxelSetList.size()-myLineSetList.size() ) );
383  updateList ( false );
384  }
385 
386  }
387  }
388 
389 }
390 
391 
392 
393 
394 void
395 DGtal::Viewer3D::updateList ( bool needToUpdateBoundingBox )
396 {
397  // Additionnaly to the primitive list (of myVoxelSetList myLineSetList.size() myPointSetList.size()) we add
398  // 6 new lists associated to the mesh Display.
399  unsigned int nbList= ( unsigned int ) ( myVoxelSetList.size() + myLineSetList.size() + myPointSetList.size() +6 );
400  glDeleteLists ( myListToAff, myNbListe );
401  myListToAff = glGenLists ( nbList );
402  myNbListe=0;
403  unsigned int listeID=0;
404  glEnable ( GL_BLEND );
405  glEnable ( GL_MULTISAMPLE_ARB );
406  glEnable ( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB );
407  glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
408 
409 
410  for ( unsigned int i=0; i<myVoxelSetList.size(); i++ )
411  {
412  glNewList ( myListToAff+i, GL_COMPILE );
413  if ( myListVoxelDepthTest.at ( i ) )
414  {
415  glEnable ( GL_DEPTH_TEST );
416  }
417  else
418  {
419  glDisable ( GL_DEPTH_TEST );
420  }
421  myNbListe++;
422  glPushName ( myNbListe );
423  glBegin ( GL_QUADS );
424  for ( std::vector<voxelD3D>::iterator s_it = myVoxelSetList.at ( i ).begin();
425  s_it != myVoxelSetList.at ( i ).end();
426  ++s_it )
427  {
428 
429  glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
430  double _width= ( *s_it ).width;
431 
432  //z+
433  glNormal3f ( 0.0, 0.0, 1.0 );
434  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
435  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
436  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
437  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
438  //z-
439  glNormal3f ( 0.0, 0.0, -1.0 );
440  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
441  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
442  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
443  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
444  //x+
445  glNormal3f ( 1.0, 0.0, 0.0 );
446  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
447  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
448  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
449  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
450  //x-
451  glNormal3f ( -1.0, 0.0, 0.0 );
452  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
453  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
454  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
455  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
456  //y+
457  glNormal3f ( 0.0, 1.0, 0.0 );
458  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
459  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z+_width );
460  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
461  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y+_width, ( *s_it ).z-_width );
462  //y-
463  glNormal3f ( 0.0, -1.0, 0.0 );
464  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
465  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z+_width );
466  glVertex3f ( ( *s_it ).x+_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
467  glVertex3f ( ( *s_it ).x-_width, ( *s_it ).y-_width, ( *s_it ).z-_width );
468  }
469  glEnd();
470  glEndList();
471  }
472  glNewList ( GLuint ( myListToAff+myVoxelSetList.size() ), GL_COMPILE );
473  myNbListe++;
474  glPushName ( myNbListe );
475  glEnable ( GL_DEPTH_TEST );
476  glEnable ( GL_BLEND );
477  glEnable ( GL_MULTISAMPLE_ARB );
478  glEnable ( GL_SAMPLE_ALPHA_TO_COVERAGE_ARB );
479  glBlendFunc ( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );
480 
481  glBegin ( GL_QUADS );
482  glEnable ( GL_DEPTH_TEST );
483  for ( std::vector<quadD3D>::iterator s_it = myKSSurfelList.begin();
484  s_it != myKSSurfelList.end();
485  ++s_it )
486  {
487  glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
488  glNormal3f ( ( *s_it ).nx, ( *s_it ).ny, ( *s_it ).nz );
489  glVertex3f ( ( *s_it ).x1, ( *s_it ).y1 , ( *s_it ).z1 );
490  glVertex3f ( ( *s_it ).x2, ( *s_it ).y2 , ( *s_it ).z2 );
491  glVertex3f ( ( *s_it ).x3, ( *s_it ).y3 , ( *s_it ).z3 );
492  glVertex3f ( ( *s_it ).x4, ( *s_it ).y4 , ( *s_it ).z4 );
493 
494  }
495  glEnd();
496  glEndList();
497 
498 
499  for ( unsigned int i=0; i<myLineSetList.size(); i++ )
500  {
501  listeID++;
502  glNewList ( GLuint ( myListToAff+myVoxelSetList.size() +i+1 ), GL_COMPILE );
503  myNbListe++;
504  glDisable ( GL_LIGHTING );
505  glPushName ( myNbListe );
506  glBegin ( GL_LINES );
507  for ( std::vector<lineD3D>::iterator s_it = myLineSetList.at ( i ).begin();
508  s_it != myLineSetList.at ( i ).end();
509  ++s_it )
510  {
511  glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
512  glVertex3f ( ( *s_it ).x1, ( *s_it ).y1, ( *s_it ).z1 );
513  glVertex3f ( ( *s_it ).x2, ( *s_it ).y2, ( *s_it ).z2 );
514 
515  }
516  glEnd();
517  glEnable ( GL_LIGHTING );
518  glEndList();
519 
520  }
521 
522 
523  for ( unsigned int i=0; i<myPointSetList.size(); i++ )
524  {
525  glNewList ( GLuint ( myListToAff+myLineSetList.size() +myVoxelSetList.size() +i+1 ), GL_COMPILE );
526  myNbListe++;
527  glDepthMask ( GL_TRUE );
528  glDisable ( GL_TEXTURE_2D );
529  glDisable ( GL_POINT_SMOOTH );
530  glDisable ( GL_LIGHTING );
531 
532  glPushName ( myNbListe );
533  glBegin ( GL_POINTS );
534  for ( std::vector<pointD3D>::iterator s_it = myPointSetList.at ( i ).begin();
535  s_it != myPointSetList.at ( i ).end();
536  ++s_it )
537  {
538 
539  glColor4ub ( ( *s_it ).R, ( *s_it ).G, ( *s_it ).B, ( *s_it ).T );
540  glVertex3f ( ( *s_it ).x, ( *s_it ).y, ( *s_it ).z );
541  }
542  glEnd();
543  glEnable ( GL_LIGHTING );
544  glEndList();
545 
546  }
547 
548 
549 
561  unsigned int nbListOfPrimitives = myLineSetList.size() +myVoxelSetList.size() + myPointSetList.size();
562 
563  // First List (quad faces)
564  glNewList ( GLuint ( myListToAff +nbListOfPrimitives + 1 ), GL_COMPILE );
565  myNbListe++;
566  glPushName ( myNbListe );
567 
568  glEnable ( GL_LIGHTING );
569  glBegin ( GL_QUADS );
570 
571  for ( unsigned int i=0; i<myQuadList.size(); i++ )
572  {
573  glColor4ub ( myQuadList.at ( i ).R, myQuadList.at ( i ).G, myQuadList.at ( i ).B, myQuadList.at ( i ).T );
574  glNormal3f ( -myQuadList.at ( i ).nx, -myQuadList.at ( i ).ny ,-myQuadList.at ( i ).nz );
575  glVertex3f ( myQuadList.at ( i ).x1, myQuadList.at ( i ).y1, myQuadList.at ( i ).z1 );
576  glVertex3f ( myQuadList.at ( i ).x2, myQuadList.at ( i ).y2, myQuadList.at ( i ).z2 );
577  glVertex3f ( myQuadList.at ( i ).x3, myQuadList.at ( i ).y3, myQuadList.at ( i ).z3 );
578  glVertex3f ( myQuadList.at ( i ).x4, myQuadList.at ( i ).y4, myQuadList.at ( i ).z4 );
579 
580  }
581  glEnd();
582  glEndList();
583 
584  // Second list: Wired version of quad face.
585  glNewList ( GLuint ( myListToAff +nbListOfPrimitives + 2 ), GL_COMPILE );
586  myNbListe++;
587  glPushName ( myNbListe );
588  glDisable ( GL_LIGHTING );
589  glBegin ( GL_LINES );
590  for ( unsigned int i=0; i<myQuadList.size(); i++ )
591  {
592  glColor4ub ( 150.0,150.0,150.0,255.0 );
593  glColor4ub ( myCurrentLineColor.red(), myCurrentLineColor.green(), myCurrentLineColor.blue() , myCurrentLineColor.alpha() );
594  glVertex3f ( myQuadList.at ( i ).x1, myQuadList.at ( i ).y1, myQuadList.at ( i ).z1 );
595  glVertex3f ( myQuadList.at ( i ).x2, myQuadList.at ( i ).y2, myQuadList.at ( i ).z2 );
596  glVertex3f ( myQuadList.at ( i ).x2, myQuadList.at ( i ).y2, myQuadList.at ( i ).z2 );
597  glColor4ub ( myCurrentLineColor.red(), myCurrentLineColor.green(), myCurrentLineColor.blue() , myCurrentLineColor.alpha() );
598  glVertex3f ( myQuadList.at ( i ).x3, myQuadList.at ( i ).y3, myQuadList.at ( i ).z3 );
599  glVertex3f ( myQuadList.at ( i ).x3, myQuadList.at ( i ).y3, myQuadList.at ( i ).z3 );
600  glVertex3f ( myQuadList.at ( i ).x4, myQuadList.at ( i ).y4, myQuadList.at ( i ).z4 );
601  glColor4ub ( myCurrentLineColor.red(), myCurrentLineColor.green(), myCurrentLineColor.blue() , myCurrentLineColor.alpha() );
602  glVertex3f ( myQuadList.at ( i ).x4, myQuadList.at ( i ).y4, myQuadList.at ( i ).z4 );
603  glVertex3f ( myQuadList.at ( i ).x1, myQuadList.at ( i ).y1, myQuadList.at ( i ).z1 );
604 
605  }
606  glEnable ( GL_LIGHTING );
607  glEnd();
608  glEndList();
609 
610  // Third list: Triangle faces.
611  glNewList ( GLuint (myListToAff +nbListOfPrimitives + 3 ), GL_COMPILE );
612  myNbListe++;
613  glPushName ( myNbListe );
614  glEnable ( GL_LIGHTING );
615  glBegin ( GL_TRIANGLES );
616  for ( unsigned int i=0; i<myTriangleList.size(); i++ )
617  {
618  glColor4ub ( myTriangleList.at ( i ).R, myTriangleList.at ( i ).G, myTriangleList.at ( i ).B, myTriangleList.at ( i ).T );
619  glNormal3f ( -myTriangleList.at ( i ).nx, -myTriangleList.at ( i ).ny ,-myTriangleList.at ( i ).nz );
620  glVertex3f ( myTriangleList.at ( i ).x1, myTriangleList.at ( i ).y1, myTriangleList.at ( i ).z1 );
621  glVertex3f ( myTriangleList.at ( i ).x2, myTriangleList.at ( i ).y2, myTriangleList.at ( i ).z2 );
622  glVertex3f ( myTriangleList.at ( i ).x3, myTriangleList.at ( i ).y3, myTriangleList.at ( i ).z3 );
623  }
624  glEnd();
625  glEndList();
626 
627 
628  // Fourth list: Wired version of triangle face.
629  glNewList ( GLuint ( myListToAff + nbListOfPrimitives +4), GL_COMPILE );
630  myNbListe++;
631  glPushName ( myNbListe );
632 
633  glDisable ( GL_LIGHTING );
634  glBegin ( GL_LINES );
635  for ( unsigned int i=0; i<myTriangleList.size(); i++ )
636  {
637  glColor4ub ( myCurrentLineColor.red(), myCurrentLineColor.green(), myCurrentLineColor.blue() , myCurrentLineColor.alpha() );
638  glVertex3f ( myTriangleList.at ( i ).x1, myTriangleList.at ( i ).y1, myTriangleList.at ( i ).z1 );
639  glVertex3f ( myTriangleList.at ( i ).x2, myTriangleList.at ( i ).y2, myTriangleList.at ( i ).z2 );
640  glVertex3f ( myTriangleList.at ( i ).x2, myTriangleList.at ( i ).y2, myTriangleList.at ( i ).z2 );
641  glVertex3f ( myTriangleList.at ( i ).x3, myTriangleList.at ( i ).y3, myTriangleList.at ( i ).z3 );
642  glVertex3f ( myTriangleList.at ( i ).x3, myTriangleList.at ( i ).y3, myTriangleList.at ( i ).z3 );
643  glVertex3f ( myTriangleList.at ( i ).x1, myTriangleList.at ( i ).y1, myTriangleList.at ( i ).z1 );
644 
645  }
646  glEnd();
647  glEnable ( GL_LIGHTING );
648  glEndList();
649 
650  // Fifth list: Polygonal faces.
651  glNewList ( GLuint (myListToAff + nbListOfPrimitives +5 ), GL_COMPILE );
652  myNbListe++;
653  glPushName ( myNbListe );
654  glEnable ( GL_LIGHTING );
655  for ( unsigned int i=0; i<myPolygonList.size(); i++ )
656  {
657  glBegin ( GL_POLYGON );
658  glColor4ub ( myPolygonList.at ( i ).R, myPolygonList.at ( i ).G, myPolygonList.at ( i ).B, myPolygonList.at ( i ).T );
659  glNormal3f ( -myPolygonList.at ( i ).nx, -myPolygonList.at ( i ).ny ,-myPolygonList.at ( i ).nz );
660  vector<pointD3D> vectVertex = myPolygonList.at ( i ).vectPoints;
661  for(unsigned int j=0;j < vectVertex.size();j++){
662  glVertex3f ( vectVertex.at(j).x, vectVertex.at(j).y, vectVertex.at ( j ).z );
663  }
664  glEnd();
665  }
666  glEndList();
667 
668 
669  // Sixth list: Wired version of polygonal face.
670  glNewList ( GLuint (myListToAff + nbListOfPrimitives +6 ), GL_COMPILE );
671  myNbListe++;
672  glPushName ( myNbListe );
673  glDisable ( GL_LIGHTING );
674  glBegin ( GL_LINES );
675  for ( unsigned int i=0; i<myPolygonList.size(); i++ )
676  {
677  glColor4ub ( myCurrentLineColor.red(), myCurrentLineColor.green(), myCurrentLineColor.blue() , myCurrentLineColor.alpha() );
678  vector<pointD3D> vectVertex = myPolygonList.at ( i ).vectPoints;
679  for(unsigned int j=0;j < vectVertex.size();j++){
680  glVertex3f ( vectVertex.at(j).x, vectVertex.at(j).y, vectVertex.at ( j ).z );
681  glVertex3f ( vectVertex.at((j+1)%vectVertex.size()).x, vectVertex.at((j+1)%vectVertex.size()).y, vectVertex.at ( (j+1)%vectVertex.size() ).z );
682  }
683  }
684  glEnd();
685  glEndList();
686 
687 
688  if ( needToUpdateBoundingBox )
689  {
690  setSceneBoundingBox ( qglviewer::Vec ( myBoundingPtLow[0],myBoundingPtLow[1],myBoundingPtLow[2] ),
691  qglviewer::Vec ( myBoundingPtUp[0], myBoundingPtUp[1], myBoundingPtUp[2] ) );
692  showEntireScene();
693  }
694  glPopMatrix();
695 
696 }
697 
698 
699 
700 
701 
702 void
704 {
705  glPushMatrix();
706  glTranslatef ( aLinel.x1, aLinel.y1, aLinel.z1 );
707  Vec dir ( aLinel.x2-aLinel.x1, aLinel.y2-aLinel.y1, aLinel.z2-aLinel.z1 );
708  glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
709  GLUquadric* quadric = gluNewQuadric();
710  glColor4ub ( aLinel.R, aLinel.G, aLinel.B, aLinel.T );
711 
712  gluCylinder ( quadric, ( aLinel.signPos || !aLinel.isSigned ) ? aLinel.width :0 ,
713  ( aLinel.signPos && aLinel.isSigned ) ? 0 :aLinel.width ,
714  dir.norm(),10, 4 );
715  glPopMatrix();
716 }
717 
718 
719 
720 
721 
722 void
724 {
725 
726  if ( !pointel.isSigned )
727  {
728  glPushMatrix();
729  glTranslatef ( pointel.x, pointel.y, pointel.z );
730  GLUquadric* quadric = gluNewQuadric();
731  glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
732  gluSphere ( quadric, pointel.size, 10, 10 );
733  glPopMatrix();
734  }
735  else
736  {
737  // a small "+" is drawn with cylinder
738  if ( pointel.signPos )
739  {
740  glPushMatrix();
741  glTranslatef ( pointel.x-0.07, pointel.y-0.07, pointel.z );
742  Vec dir ( 0.14, 0.14, 0 );
743  glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
744  GLUquadric* quadric = gluNewQuadric();
745  glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
746  gluCylinder ( quadric, pointel.size/3.0 , pointel.size/3.0,
747  dir.norm(),10, 4 );
748  glPopMatrix();
749  glPushMatrix();
750  glTranslatef ( pointel.x-0.07, pointel.y+0.07, pointel.z );
751  dir=Vec ( 0.14, -0.14, 0 );
752  glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
753  quadric = gluNewQuadric();
754  glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
755  gluCylinder ( quadric, pointel.size/3.0 , pointel.size/3.0,
756  dir.norm(),10, 4 );
757  glPopMatrix();
758  }
759  else
760  {
761  glPushMatrix();
762  glTranslatef ( pointel.x, pointel.y+0.07, pointel.z-0.07 );
763  Vec dir ( 0.0, -0.14, 0.14 );
764  glMultMatrixd ( Quaternion ( Vec ( 0,0,1 ), dir ).matrix() );
765  GLUquadric* quadric = gluNewQuadric();
766  glColor4ub ( pointel.R, pointel.G, pointel.B, pointel.T );
767  gluCylinder ( quadric, pointel.size/4.0 , pointel.size/4.0,
768  dir.norm(),10, 4 );
769  glPopMatrix();
770  }
771  }
772 }
773 
774 
775 
776 
777 
778 void
780 {
781  bool handled = false;
782 
783  if( e->key() == Qt::Key_E){
784  trace.info() << "Exporting mesh..." ;
785  (*this) >> "exportedMesh.off";
786  trace.info() << "[done]"<< endl ;
787  }
788 
789 
790  if ( ( e->key() ==Qt::Key_W ) )
791  {
792  myViewWire=!myViewWire;
793  updateList(false);
794  updateGL();
795  }
796 
797  if ( ( e->key() ==Qt::Key_R ) )
798  {
799  myScaleX=1.0f;
800  myScaleY=1.0f;
801  myScaleZ=1.0f;
802  updateGL();
803  }
804 
805 
806  if ( ( e->key() ==Qt::Key_T ) )
807  {
808  handled=true;
809  DGtal::trace.info() << "sorting surfel according camera position....";
810  sortSurfelFromCamera();
811  sortTriangleFromCamera();
812  sortQuadFromCamera();
813  sortPolygonFromCamera();
814  DGtal::trace.info() << " [done]"<< std::endl;
815  updateList(false);
816  updateGL();
817  }
818  if ( ( e->key() ==Qt::Key_B ) )
819  {
820  handled=true;
821  myIsBackgroundDefault=!myIsBackgroundDefault;
822  if ( !myIsBackgroundDefault )
823  {
824  setBackgroundColor ( QColor ( 255, 255,255 ) );
825  }
826  else
827  {
828  setBackgroundColor ( QColor ( 51, 51, 51 ) );
829  }
830  updateGL();
831  }
832  if ( ( e->key() ==Qt::Key_L ) )
833  {
834  restoreStateFromFile();
835  updateGL();
836  }
837  if ( ( e->key() ==Qt::Key_C ) ) // MT
838  {
839  handled=true;
840  GLint Viewport[4];
841  GLdouble Projection[16], Modelview[16];
842  //Unused matrix so I remove it (DC)
843  //GLdouble matrix[16];
844 
845  // Precomputation begin
846  glGetIntegerv ( GL_VIEWPORT , Viewport );
847  glGetDoublev ( GL_MODELVIEW_MATRIX , Modelview );
848  glGetDoublev ( GL_PROJECTION_MATRIX, Projection );
849 
850  for ( unsigned short m=0; m<4; ++m )
851  {
852  for ( unsigned short l=0; l<4; ++l )
853  {
854  double sum = 0.0;
855  for ( unsigned short k=0; k<4; ++k )
856  sum += Projection[l+4*k]*Modelview[k+4*m];
857  //matrix[l+4*m] = sum;
858  }
859  }
860  // Precomputation end
861 
862  // print
863  DGtal::trace.info() << "Viewport: ";
864  for ( unsigned short l=0; l<4; ++l )
865  DGtal::trace.info() << Viewport[l] << ", ";
866  DGtal::trace.info() << std::endl;
867 
868  Vec cp = camera()->position();
869  Vec cd = camera()->viewDirection();
870  Vec cup = camera()->upVector();
871 
872  DGtal::trace.info() << "camera.position: " ;
873  for ( unsigned short l=0; l<3; ++l )
874  DGtal::trace.info() << cp[l] << ", ";
875  DGtal::trace.info() << std::endl;
876 
877  DGtal::trace.info() << "camera.direction: ";
878  for ( unsigned short l=0; l<3; ++l )
879  DGtal::trace.info() << cd[l] << ", ";
880  DGtal::trace.info() << std::endl;
881 
882  DGtal::trace.info() << "camera.upVector: ";
883  for ( unsigned short l=0; l<3; ++l )
884  DGtal::trace.info() << cup[l] << ", ";
885  DGtal::trace.info() << std::endl;
886 
887  DGtal::trace.info() << "zNear: " << camera()->zNear() << " - zFar: " << camera()->zFar() << std::endl;
888  // print
889  }
890 
891 
892 
893  if ( !handled )
894  QGLViewer::keyPressEvent ( e );
895 
896 }
897 
898 
899 
900 
901 
902 
903 
904 QString
906 {
907  QString text ( "<h2> Viewer3D</h2>" );
908  text += "Use the mouse to move the camera around the object. ";
909  text += "You can respectively revolve around, zoom and translate with the three mouse buttons. ";
910  text += "Left and middle buttons pressed together rotate around the camera view direction axis<br><br>";
911  text += "Pressing <b>Alt</b> and one of the function keys (<b>F1</b>..<b>F12</b>) defines a camera keyFrame. ";
912  text += "Simply press the function key again to restore it. Several keyFrames define a ";
913  text += "camera path. Paths are saved when you quit the application and restored at next start.<br><br>";
914  text += "Press <b>F</b> to display the frame rate, <b>A</b> for the world axis, ";
915  text += "<b>Alt+Return</b> for full screen mode and <b>Control+S</b> to save a snapshot. ";
916  text += "See the <b>Keyboard</b> tab in this window for a complete shortcut list.<br><br>";
917  text += "Double clicks automates single click actions: A left button double click aligns the closer axis with the camera (if close enough). ";
918  text += "A middle button double click fits the zoom of the camera and the right button re-centers the scene.<br><br>";
919  text += "A left button double click while holding right button pressed defines the camera <i>Revolve Around Point</i>. ";
920  text += "See the <b>Mouse</b> tab and the documentation web pages for details.<br><br>";
921  text += "Press <b>Escape</b> to exit the viewer.";
922  return text;
923 }
924 
925 
927 // Internals - private :
928 
929 // //
931 
932