MEPP2 Project
SimpleViewer.inl
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published
6 // by the Free Software Foundation; either version 3 of the License,
7 // or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 
13 //#include <osgFX/Outline>
14 //#include <osgFX/SpecularHighlights>
15 //#include <osg/LightModel>
16 
17 // osgManipulator
18 #define MANIPULATOR
19 #include <osg/MatrixTransform>
20 
21 #include <osgManipulator/TabBoxDragger>
22 //#include "Visualization/OSG/Manipulator/TabBoxDragger2.h"
23 
24 #include <osgManipulator/TrackballDragger>
25 // osgManipulator
26 
27 #include <osg/LineWidth>
28 #include <osg/Point>
29 
30 #include <memory>
31 
33 
40 
41 
42 inline
44 {
45 #ifdef DEBUG_VISU2
46  std::cout << "*** this=" << this << " entering " << __func__ << std::endl;
47 #endif
48 
49 #ifdef DEBUG_VISU2
50  std::cout << "*** this=" << this << " leaving " << __func__ << std::endl;
51 #endif
52 }
53 
54 
55 inline
57 {
58 #ifdef DEBUG_VISU2
59  std::cout << "*** this=" << this << " entering " << __func__ << std::endl;
60 #endif
61 
62  // std::cout << "--> ~SimpleViewer" << std::endl;
63 
64  // BaseViewer *bv = dynamic_cast< BaseViewer* >(this);
65  // BaseAdapterVisuQt *bavQt = dynamic_cast< BaseAdapterVisuQt*
66  // >(bv->getAdapter());
67 
68  std::vector< Adapter * > *adapters = myWindow->getAdapters();
69  for(unsigned int ii = 0; ii < (*adapters).size(); ++ii)
70  {
71  if((*adapters)[ii] == myAdapter)
72  {
73  (*adapters).erase((*adapters).begin() + ii);
74  // std::cout << "--> myAdapter erase in ~SimpleViewer - TAB SIZE: " <<
75  // (*adapters).size() << std::endl;
76 
77  SimpleWindow *sw = static_cast< SimpleWindow * >(getWindow());
78  sw->update();
79  }
80  }
81 
82  /*for (unsigned int ii = 0; ii < v_geodes.size(); ++ii)
83  delete v_geodes[ii]; // -> impossible, car "smart pointer"*/
84 
85  /*for (unsigned int ii = 0; ii < v_draggers1.size(); ++ii)
86  delete v_draggers1[ii]; // -> impossible, car "smart pointer"
87  for (unsigned int ii = 0; ii < v_draggers2.size(); ++ii)
88  delete v_draggers2[ii]; // -> impossible, car "smart pointer"*/
89 
90  for(unsigned int ii = 0; ii < v_mixed_meshes.size(); ++ii)
91  {
92  {
93  auto mesh_type_pair = v_mixed_meshes[ii];
94 
95 #ifdef FEVV_USE_CGAL
96  if(mesh_type_pair.second == "POLYHEDRON")
97  {
98  auto mesh_ptr = static_cast< FEVV::MeshPolyhedron* >(mesh_type_pair.first);
99  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr << " with datastructure POLYHEDRON" << std::endl;
100  delete mesh_ptr;
101  }
102  if(mesh_type_pair.second == "SURFACEMESH")
103  {
104  auto mesh_ptr = static_cast< FEVV::MeshSurface* >(mesh_type_pair.first);
105  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr << " with datastructure SURFACEMESH" << std::endl;
106  delete mesh_ptr;
107  }
108  if(mesh_type_pair.second == "LCC")
109  {
110  auto mesh_ptr = static_cast< FEVV::MeshLCC* >(mesh_type_pair.first);
111  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr << " with datastructure LCC" << std::endl;
112  delete mesh_ptr;
113  }
114  if(mesh_type_pair.second == "CGALPOINTSET")
115  {
116  auto mesh_ptr = static_cast< FEVV::CGALPointSet* >(mesh_type_pair.first);
117  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr
118  << " with datastructure CGALPOINTSET" << std::endl;
119  delete mesh_ptr;
120  }
121 #endif //FEVV_USE_CGAL
122 
123 #ifdef FEVV_USE_OPENMESH
124  if(mesh_type_pair.second == "OPENMESH")
125  {
126  auto mesh_ptr = static_cast< FEVV::MeshOpenMesh* >(mesh_type_pair.first);
127  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr << " with datastructure OPENMESH" << std::endl;
128  delete mesh_ptr;
129  }
130 #endif //FEVV_USE_OPENMESH
131 
132 #ifdef FEVV_USE_AIF
133  if(mesh_type_pair.second == "AIF")
134  {
135  auto mesh_ptr = static_cast< FEVV::MeshAIF* >(mesh_type_pair.first);
136  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr << " with datastructure AIF" << std::endl;
137  delete mesh_ptr;
138  }
139 #endif //FEVV_USE_AIF
140 
141 #ifdef FEVV_USE_PCL
142  if(mesh_type_pair.second == "PCLPOINTCLOUD")
143  {
144  auto mesh_ptr = static_cast< FEVV::PCLPointCloud* >(mesh_type_pair.first);
145  std::cout << "[SimpleViewer] deleting mesh " << mesh_ptr
146  << " with datastructure PCLPOINTCLOUD" << std::endl;
147  delete mesh_ptr;
148  }
149 #endif //FEVV_USE_PCL
150  }
151  }
152 
153  for(unsigned int ii = 0; ii < v_properties_maps.size(); ++ii)
154  {
155  delete v_properties_maps[ii];
156  // std::cout << "--> delete v_properties_maps[ii] (" <<
157  // bavQt->windowTitle().toStdString() << ") in ~SimpleViewer" << std::endl;
158  }
159 
160  /*for(unsigned int ii = 0; ii < v_geometries.size(); ++ii)
161  {
162  for(unsigned int jj = 0; jj < v_geometries[ii].size(); ++jj)
163  {
164  delete v_geometries[ii][jj]; // -> impossible, car "smart pointer"
165  // std::cout << "--> delete v_geometries[ii][jj] (" <<
166  // bavQt->windowTitle().toStdString() << ") in ~SimpleViewer" <<
167  std::endl;
168  }
169  }*/
170 
171  // NOTE : same for geometries_edges, geometries_vertices, geometries_normals,
172  // vertexArrays, vertexArrays_edges, vertexArrays_vertices, vertexArrays_normals,
173  // colorsArrays, colorsArrays_edges, colorsArrays_vertices, colorsArrays_normals,
174  // etc...
175 
176 #ifdef DEBUG_VISU2
177  std::cout << "*** this=" << this << " leaving " << __func__ << std::endl;
178 #endif
179 }
180 
181 
182 inline
183 void
185 {
186  if(!Assert::check(
187  !bIsInit, "is already init. Leaving...", "SimpleViewer::init"))
188  {
189  return;
190  }
191 
192 #if(FEVV_USE_QT5) // FOR_QT6
193  // empty
194 #else
195  // disable the default setting of viewer.done() by pressing Escape
196  setKeyEventSetsDone(0);
197 #endif
198 
200 
201  // LIGHT (test)
202 #if(0)
203  // osg:Light nous permet de donner à notre lumière ses caractéristiques
204  osg::Light *pLight = new osg::Light;
205  pLight->setLightNum(1); // ici cette lumière sera donc GL_LIGHT1
206 
207  // On va ici créer la lumière numéro 1 (GL_LIGHT1). C'est une lumière blanche
208  // (couleur diffuse) et sa composante ambiante est également blanche.
209  pLight->setAmbient(osg::Vec4d(1.0, 1.0, 1.0, 0.0));
210  pLight->setDiffuse(osg::Vec4(1.0f, 1.0f, 1.0f, 0.0f));
211  pLight->setSpecular(osg::Vec4(1.0f, 1.0f, 1.0f, 1.0f));
212 
213  // Elle est située à la position 2, 0, 2.
214  // Le 4e paramètre w sert en fait ici, comme en OpenGL, à dire si notre
215  // lumière est ponctuelle ou directionnelle. Si w=0 notre lumière est
216  // directionnelle, sinon elle est ponctuelle. On a donc bien ici une lumière
217  // ponctuelle située en 2,0,2.
218  pLight->setPosition(osg::Vec4(2.0f, 0.0f, 2.0f, 1.0f));
219 
220  osg::LightSource *pLightSource = new osg::LightSource;
221  pLightSource->setLight(pLight);
222  root_node->addChild(pLightSource);
223 
224  // IMPORTANT : étant donné que le viewer donne une valeur par défaut à
225  // GL_LIGHT0, nous allons éteindre celle-ci et activer la lumière numéro 1.
226  osg::StateSet *state = root_node->getOrCreateStateSet();
227  state->setMode(GL_LIGHT0, osg::StateAttribute::OFF);
228  state->setMode(GL_LIGHT1, osg::StateAttribute::ON);
229 #endif
230  // LIGHT (test)
231 
232  gizmo = Debug::createGizmo();
233  gizmo->setNodeMask(m_ShowAxis ? 0xffffffff : 0x0);
234  addGroup(gizmo);
235 
236  grid = Debug::createUnitGrid();
237  grid->setNodeMask(m_ShowGrid ? 0xffffffff : 0x0);
238  addGroup(grid);
239 
240  // hud = Debug::createHud(hudText);
241  // addGroup(hud);
242 
243  // time
244  i_time = current_i_time = -1;
245  // time
246 
247  std::cout << "SimpleViewer init" << std::endl;
248 
249  bIsInit = true;
250 }
251 
252 
253 inline
254 bool
256 {
257  return bIsInit;
258 }
259 
260 
261 inline
262 bool
264 {
265  return bIsInit;
266 }
267 
268 /*template< typename HalfedgeGraph >
269 bool
270 FEVV::SimpleViewer<HalfedgeGraph>::isSelected() const
271 {
272  for( bool b : v_meshIsSelected )
273  {
274  if( b )
275  {
276  return true;
277  }
278  }
279  return false;
280 }*/
281 
282 
283 inline
284 bool
286  const FEVV::Color &_color)
287 {
288  // osgViewer::View* _osgView = getView(0); // for osgViewer::CompositeViewer
289  osgViewer::View *_osgView =
290  dynamic_cast< osgViewer::View * >(this); // for osgViewer::Viewer
291 
292 #if(FEVV_USE_QT5) // FOR_QT6
293  BaseViewer *bv = dynamic_cast< BaseViewer * >(this);
294  SimpleAdapterVisu *sav =
295  dynamic_cast< SimpleAdapterVisu * >(bv->getAdapter());
296 
297  //_osgView = sav->my_osgQOpenGLWidget->getOsgViewer();
298  _osgView = sav->my_osgQOpenGLWindow->getOsgViewer();
299 #endif
300 
301  if(_osgView)
302  {
303  _osgView->getCamera()->setClearColor(Helpers::ColorConverter(_color));
304  }
305 
306  return true;
307 }
308 
309 
310 inline
311 bool
312 FEVV::SimpleViewer::saveScreenshot(const std::string &_name)
313 {
314  std::unique_ptr< osgViewer::ScreenCaptureHandler > scrn(
315  new osgViewer::ScreenCaptureHandler());
316  std::unique_ptr< osgViewer::ScreenCaptureHandler::WriteToFile > captureOper(
317  new osgViewer::ScreenCaptureHandler::WriteToFile(_name, "png"));
318 
319  scrn->setCaptureOperation(captureOper.get());
320 #if(FEVV_USE_QT5) // FOR_QT6
321  // empty
322 #else
323  scrn->captureNextFrame(*this);
324  this->frame();
325 #endif
326 
327  return true;
328 }
329 
330 
331 inline
332 void
334 {
335  root_node->addChild(_geode);
336  if(myWindow != nullptr)
337  {
338  myWindow->notify();
339  }
340 
341  // osgUtil::Optimizer optimizer;
342  // optimizer.optimize( root_node );
343 }
344 
345 
346 inline
347 void
349 {
350  root_node->addChild(_group);
351  if(myWindow != nullptr)
352  {
353  myWindow->notify();
354  }
355 
356  // osgUtil::Optimizer optimizer;
357  // optimizer.optimize( root_node );
358 }
359 
360 
361 inline
364 {
365  visitor->reset();
366 
367  root_node->traverse(*visitor);
368 
369  return visitor->exportResults();
370 }
371 
372 
373 inline
374 std::vector< osg::Geode * >
376 {
377  std::vector< osg::Geode * > result;
378  unsigned int i_pos = 0;
379  for(bool b : v_meshIsSelected)
380  {
381  if(b)
382  {
383  result.push_back(v_geodes[i_pos]);
384  }
385  ++i_pos;
386  }
387 
388  return result;
389 }
390 
391 
392 inline
393 std::vector< osg::Geode * >
395 {
396  return v_geodes;
397 }
398 
399 
400 inline
403 {
405  unsigned int i_pos = 0;
406  for(bool b : v_meshIsSelected)
407  {
408  if(b)
409  {
410  result.push_back(v_mixed_meshes[i_pos]);
411  }
412  ++i_pos;
413  }
414 
415  return result;
416 }
417 
418 
419 inline
422 {
423  return v_mixed_meshes;
424 }
425 
426 
427 inline
428 std::vector< std::string >
430 {
431  std::vector< std::string > result;
432  unsigned int i_pos = 0;
433  for(bool b : v_meshIsSelected)
434  {
435  if(b)
436  {
437  result.push_back(v_meshes_names[i_pos]);
438  }
439  ++i_pos;
440  }
441 
442  return result;
443 }
444 
445 
446 inline
447 std::vector< std::string >
449 {
450  return v_meshes_names;
451 }
452 
453 
454 inline
455 std::vector< FEVV::PMapsContainer * >
457 {
458  std::vector< FEVV::PMapsContainer * > result;
459  unsigned int i_pos = 0;
460  for(bool b : v_meshIsSelected)
461  {
462  if(b)
463  {
464  result.push_back(v_properties_maps[i_pos]);
465  }
466  ++i_pos;
467  }
468 
469  return result;
470 }
471 
472 
473 inline
474 std::vector< FEVV::PMapsContainer * >
476 {
477  return v_properties_maps;
478 }
479 
480 
481 inline
482 std::vector< osg::Group * >
484 {
485  std::vector< osg::Group * > result;
486  unsigned int i_pos = 0;
487  for(bool b : v_meshIsSelected)
488  {
489  if(b)
490  {
491  result.push_back(v_draggers1[i_pos]);
492  }
493  ++i_pos;
494  }
495 
496  return result;
497 }
498 
499 
500 inline
501 std::vector< osg::Group * >
503 {
504  return v_draggers1;
505 }
506 
507 
508 inline
509 std::vector< osg::Group * >
511 {
512  std::vector< osg::Group * > result;
513  unsigned int i_pos = 0;
514  for(bool b : v_meshIsSelected)
515  {
516  if(b)
517  {
518  result.push_back(v_draggers2[i_pos]);
519  }
520  ++i_pos;
521  }
522 
523  return result;
524 }
525 
526 
527 inline
528 std::vector< osg::Group * >
530 {
531  return v_draggers2;
532 }
533 
534 #if 0 //TODO-elo-rm-?-ask_MTO
535 template< typename HalfedgeGraph >
536 HalfedgeGraph *
537 FEVV::SimpleViewer< HalfedgeGraph >::getMesh(unsigned int _position)
538 {
539  Assert::check(_position < v_meshes.size(),
540  "The given position must be lower than v_meshes.size()",
541  "SimpleViewer::getMesh(int)");
542 
543  return v_meshes[_position];
544 }
545 #endif
546 
547 
548 template< typename HalfedgeGraph, typename PointMap >
549 osg::Geode *
551  HalfedgeGraph *_g,
552  PMapsContainer *_pmaps,
553  std::vector< osg::ref_ptr< osg::Geometry > > &geometries,
554  std::vector< osg::ref_ptr< osg::Geometry > > &geometriesL,
555  std::vector< osg::ref_ptr< osg::Geometry > > &geometriesP,
556  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_edges,
557  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_vertices,
558  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_normals,
559  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_custom_vectors,
560  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays,
561  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_edges,
562  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_vertices,
563  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_normals,
564  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_custom_vectors,
565  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays,
566  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArraysF,
567  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_edges,
568  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_vertices,
569  std::vector< osg::ref_ptr< osg::Vec3Array > > &tangentsArrays,
570  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays,
571  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_edges,
572  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_vertices,
573  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_normals,
574  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_custom_vectors,
575  std::vector< osg::ref_ptr< osg::Vec2Array > > &texcoordsArrays,
576  PointMap *_pm,
577  std::string _mesh_file)
578 {
579  osg::Geode *geode =
580  new osg::Geode; // MT OSG_GEODE : bug from JL ? Ici devrait être
581  // osg::ref_ptr<osg::Geode> geode = new osg::Geode(); ???
582  internal_createMesh(geode,
583  _g,
584  _pmaps,
585  geometries,
586  geometriesL,
587  geometriesP,
588  geometries_edges,
589  geometries_vertices,
590  geometries_normals,
591  geometries_custom_vectors,
592  vertexArrays,
593  vertexArrays_edges,
594  vertexArrays_vertices,
595  vertexArrays_normals,
596  vertexArrays_custom_vectors,
597  normalsArrays,
598  normalsArraysF,
599  normalsArrays_edges,
600  normalsArrays_vertices,
601  tangentsArrays,
602  colorsArrays,
603  colorsArrays_edges,
604  colorsArrays_vertices,
605  colorsArrays_normals,
606  colorsArrays_custom_vectors,
607  texcoordsArrays,
608  _pm,
609  _mesh_file);
610  return geode;
611 }
612 
613 
614 template< typename HalfedgeGraph, typename PointMap >
615 void
617  osg::Geode *&geode,
618  HalfedgeGraph *_g,
619  PMapsContainer *_pmaps,
620  std::vector< osg::ref_ptr< osg::Geometry > > &geometries,
621  std::vector< osg::ref_ptr< osg::Geometry > > &geometriesL,
622  std::vector< osg::ref_ptr< osg::Geometry > > &geometriesP,
623  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_edges,
624  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_vertices,
625  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_normals,
626  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_custom_vectors,
627  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays,
628  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_edges,
629  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_vertices,
630  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_normals,
631  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_custom_vectors,
632  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays,
633  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArraysF,
634  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_edges,
635  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_vertices,
636  std::vector< osg::ref_ptr< osg::Vec3Array > > &tangentsArrays,
637  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays,
638  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_edges,
639  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_vertices,
640  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_normals,
641  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_custom_vectors,
642  std::vector< osg::ref_ptr< osg::Vec2Array > > &texcoordsArrays,
643  PointMap *_pm,
644  std::string _mesh_file)
645 {
646  using GraphTraits = boost::graph_traits< HalfedgeGraph >;
647  using GeometryTraits = FEVV::Geometry_traits< HalfedgeGraph >;
648  using face_iterator = typename GraphTraits::face_iterator;
649  //using face_descriptor = typename GraphTraits::face_descriptor;
650  using edge_iterator = typename GraphTraits::edge_iterator;
651  //using edge_descriptor = typename GraphTraits::edge_descriptor;
652  using halfedge_descriptor = typename GraphTraits::halfedge_descriptor;
653  using vertex_iterator = typename GraphTraits::vertex_iterator;
655  using halfedge_point = typename GeometryTraits::Point;
656  using halfedge_vector = typename GeometryTraits::Vector;
657 
658  // property maps stuff
659  using VertexNormalMap =
661  HalfedgeGraph >::pmap_type;
662  using FaceNormalMap = typename FEVV::PMap_traits< FEVV::face_normal_t,
663  HalfedgeGraph >::pmap_type;
664 
665  using VertexColorMap = typename FEVV::PMap_traits< FEVV::vertex_color_t,
666  HalfedgeGraph >::pmap_type;
667  using FaceColorMap = typename FEVV::PMap_traits< FEVV::face_color_t,
668  HalfedgeGraph >::pmap_type;
669 
670  using VertexUVMap = typename FEVV::PMap_traits< FEVV::vertex_texcoord_t,
671  HalfedgeGraph >::pmap_type;
672  using HalfedgeUVMap = typename FEVV::PMap_traits< FEVV::halfedge_texcoord_t,
673  HalfedgeGraph >::pmap_type;
674 
675  // RM: tangents are used primarily for normal mapping
676  using VertexTangentMap =
678  HalfedgeGraph >::pmap_type;
679 
680  using FaceMaterialMap =
682  HalfedgeGraph >::pmap_type;
683  using MeshMaterialsMap =
685  HalfedgeGraph >::pmap_type;
686 
687  using VertexCustomVectorMap =
689  HalfedgeGraph >::pmap_type;
690 
691  using VertexCustomVectorColorMap =
693  HalfedgeGraph >::pmap_type;
694 
695  using VertexCustomVectorParamMap =
697  HalfedgeGraph >::pmap_type;
698 
699  using MeshGuipropertiesMap =
701  HalfedgeGraph >::pmap_type;
702 
703  VertexNormalMap v_nm;
704  FaceNormalMap f_nm;
705  VertexColorMap v_cm;
706  FaceColorMap f_cm;
707  VertexUVMap v_uvm;
708  HalfedgeUVMap h_uvm;
709 
710  VertexTangentMap vt_m; // RM
711 
712  FaceMaterialMap f_mm;
713  MeshMaterialsMap m_mm;
714 
715  VertexCustomVectorMap v_CVm;
716  VertexCustomVectorColorMap v_CVCm;
717  VertexCustomVectorParamMap v_CVPm;
718 
719  MeshGuipropertiesMap m_gpm;
720 
721  VertexNormalMap *_vt_nm = nullptr;
722  FaceNormalMap *_f_nm = nullptr;
723  VertexColorMap *_vt_cm = nullptr;
724  FaceColorMap *_f_cm = nullptr;
725  VertexUVMap *_vt_uv_m = nullptr;
726  HalfedgeUVMap *_het_uv_m = nullptr;
727 
728  VertexTangentMap *v_tan_m = nullptr; // RM
729 
730  FaceMaterialMap *_f_mm = nullptr;
731  MeshMaterialsMap *_m_mm = nullptr;
732 
733  VertexCustomVectorMap *_vt_CVm = nullptr;
734  VertexCustomVectorColorMap *_vt_CVCm = nullptr;
735  VertexCustomVectorParamMap *_vt_CVPm = nullptr;
736 
737  size_t _m_mm_size = 0;
738 
739  // textures stuff
740  int _texture_type = NO_TEXCOORDS;
741 
742  //FEVV::Filters::translate(*_g, *_pm, m_step, 0., 0.); // TEMP for test
743 
744  // retrieve or create mesh gui-properties property map
745  if(has_map(*_pmaps, FEVV::mesh_guiproperties))
746  {
747  m_gpm = get_property_map(FEVV::mesh_guiproperties, *_g, *_pmaps);
748  // std::cout << "[SimpleViewer] **************get mesh_guiproperties
749  // property_map" << std::endl;
750  }
751  else
752  {
754  FEVV::Types::GuiProperties gui_props;
755  put(m_gpm, 0, gui_props);
756  put_property_map(FEVV::mesh_guiproperties, *_g, *_pmaps, m_gpm);
757  // std::cout << "[SimpleViewer] **************make mesh_guiproperties
758  // property_map" << std::endl;
759  }
760 
761  //MeshGuipropertiesMap *_m_gpm = &m_gpm;
762 
763  // --- face_normal
764  if(has_map(*_pmaps, FEVV::face_normal))
765  {
766  if(!m_redraw)
767  std::cout << "[SimpleViewer] using face normal" << std::endl;
768  f_nm = get_property_map(FEVV::face_normal, *_g, *_pmaps);
770  _f_nm = &f_nm;
771  }
772  // compute face normals if not provided
773  if(_f_nm == nullptr || m_recomputeNT_if_redraw)
774  {
775  if(!m_redraw)
776  std::cout << "[SimpleViewer] face normal missing, computing it"
777  << std::endl;
779  _f_nm = &f_nm;
780  FEVV::Filters::calculate_face_normals(*_g, *_pm, f_nm);
782  FEVV::face_normal, *_g, *_pmaps, f_nm); // MT add (for later redraw)
783  }
784  // --- face_normal
785 
786  // --- vertex_normal
787  if(has_map(*_pmaps, FEVV::vertex_normal))
788  {
789  if(!m_redraw)
790  std::cout << "[SimpleViewer] using vertex normal" << std::endl;
791  v_nm = get_property_map(FEVV::vertex_normal, *_g, *_pmaps);
793  _vt_nm = &v_nm;
794  }
795  // compute vertex normals if not provided
796  if(_vt_nm == nullptr || m_recomputeNT_if_redraw)
797  {
798  if(!m_redraw)
799  std::cout << "[SimpleViewer] vertex normal missing, computing it"
800  << std::endl;
802  _vt_nm = &v_nm;
803  FEVV::Filters::calculate_vertex_normals(*_g, *_pm, f_nm, v_nm);
805  FEVV::vertex_normal, *_g, *_pmaps, v_nm); // MT add (for later redraw)
806  }
807  // --- vertex_normal
808 
809  // --- face_color
810  if(has_map(*_pmaps, FEVV::face_color))
811  {
812  if(!m_redraw)
813  std::cout << "[SimpleViewer] using face color" << std::endl;
814  f_cm = get_property_map(FEVV::face_color, *_g, *_pmaps);
815  _f_cm = &f_cm;
816 
817  if(!m_redraw)
818  {
819  m_UseVertexColor = false;
820  m_UseFaceColor = true;
821  m_UseTexture = false;
822  }
823  }
824  // --- face_color
825 
826  // --- vertex_color
827  if(has_map(*_pmaps, FEVV::vertex_color))
828  {
829  if(!m_redraw)
830  std::cout << "[SimpleViewer] using vertex color" << std::endl;
831  v_cm = get_property_map(FEVV::vertex_color, *_g, *_pmaps);
832  _vt_cm = &v_cm;
833 
834  if(!m_redraw)
835  {
836  m_UseVertexColor = true;
837  m_UseFaceColor = false;
838  m_UseTexture = false;
839  }
840  }
841  // --- vertex_color
842 
843  // --- texture
844  if(has_map(*_pmaps, FEVV::vertex_texcoord))
845  {
846  if(!m_redraw)
847  std::cout << "[SimpleViewer] using vertex texture-coordinates"
848  << std::endl;
849  v_uvm = get_property_map(FEVV::vertex_texcoord, *_g, *_pmaps);
850  _vt_uv_m = &v_uvm;
851  _texture_type = VERTEX_TEXCOORDS2D;
852 
853  if(!m_redraw)
854  {
855  m_UseVertexColor = false;
856  m_UseFaceColor = false;
857  m_UseTexture = true;
858  }
859 
860  if(has_map(*_pmaps, FEVV::vertex_tangent) && (!m_recomputeNT_if_redraw))
861  {
862  if(!m_redraw)
863  std::cout << "[SimpleViewer] using vertex tangents" << std::endl;
864  vt_m = get_property_map(FEVV::vertex_tangent, *_g, *_pmaps);
865  v_tan_m = &vt_m;
866  }
867  else
868  {
869  // RM: compute vertex tangents
870  // Note: shouldn't be added if no normal map available, causing extra
871  // process
872  if(!m_redraw)
873  std::cout << "[SimpleViewer] vertex tangents missing, computing it"
874  << std::endl;
876  v_tan_m = &vt_m;
877  FEVV::Filters::calculate_vertices_tangent(*_g, *_pm, v_uvm, *v_tan_m);
878  put_property_map(FEVV::vertex_tangent, *_g, *_pmaps, *v_tan_m);
879  }
880  }
881  else if(has_map(*_pmaps, FEVV::halfedge_texcoord))
882  {
883  if(!m_redraw)
884  std::cout << "[SimpleViewer] using halfedge texture-coordinates"
885  << std::endl;
886  h_uvm = get_property_map(FEVV::halfedge_texcoord, *_g, *_pmaps);
887  _het_uv_m = &h_uvm;
888  _texture_type = HALFEDGE_TEXCOORDS2D;
889 
890  if(!m_redraw)
891  {
892  m_UseVertexColor = false;
893  m_UseFaceColor = false;
894  m_UseTexture = true;
895  }
896 
897  if(has_map(*_pmaps, FEVV::vertex_tangent) && (!m_recomputeNT_if_redraw))
898  {
899  if(!m_redraw)
900  std::cout << "[SimpleViewer] using halfedge tangents" << std::endl;
901  vt_m = get_property_map(FEVV::vertex_tangent, *_g, *_pmaps);
902  v_tan_m = &vt_m;
903  }
904  else
905  {
906  // RM: compute halfedge tangents
907  // Note: shouldn't be added if no normal map available, causing extra
908  // process
909  if(!m_redraw)
910  std::cout << "[SimpleViewer] halfedge tangents missing, computing it"
911  << std::endl;
913  v_tan_m = &vt_m;
914  FEVV::Filters::calculate_halfedges_tangent(*_g, *_pm, h_uvm, *v_tan_m);
915  put_property_map(FEVV::vertex_tangent, *_g, *_pmaps, *v_tan_m);
916  }
917  }
918 
919  if(has_map(*_pmaps, FEVV::face_material))
920  {
921  f_mm = get_property_map(FEVV::face_material, *_g, *_pmaps);
922  _f_mm = &f_mm;
923  }
924  else
925  {
926  if(_texture_type == HALFEDGE_TEXCOORDS2D)
927  _texture_type =
928  NO_TEXCOORDS; // if face material map is missing, we can not display
929  // any texture in HALFEDGE_TEXCOORDS2D mode
930  }
931 
932  if(has_map(*_pmaps, FEVV::mesh_materials))
933  {
934  m_mm = get_property_map(FEVV::mesh_materials, *_g, *_pmaps);
935  _m_mm = &m_mm;
936 
937  _m_mm_size = std::distance(m_mm.storage_begin(), m_mm.storage_end());
938  if(!m_redraw)
939  std::cout << "[SimpleViewer] number of materials: " << _m_mm_size
940  << std::endl;
941  }
942  else
943  {
944  _texture_type = NO_TEXCOORDS; // disable textures if no material
945  if(!m_redraw)
946  std::cout << "[SimpleViewer] no material found, disabling textures"
947  << std::endl;
948  }
949  // --- texture
950 
951  // --- vertex_custom_vector
952  if(has_map(*_pmaps, FEVV::vertex_custom_vector))
953  {
954  if(!m_redraw)
955  std::cout << "[SimpleViewer] using vertex CUSTOM VECTOR" << std::endl;
956  v_CVm = get_property_map(FEVV::vertex_custom_vector, *_g, *_pmaps);
957  _vt_CVm = &v_CVm;
958  }
959  // TEMP for CUSTOM VECTOR
960  if(0) // OFF, but it is normal so don't delete please...
961  if(_vt_CVm == nullptr || m_recomputeNT_if_redraw)
962  {
963  if(!m_redraw)
964  std::cout << "[SimpleViewer] vertex CUSTOM VECTOR missing, filling it with example values"
965  << std::endl;
967  _vt_CVm = &v_CVm;
968 
969  // HERE WE FORCE a full v(1., 1., 1.) vertex-custom_vector map
970  using Vector = typename GeometryTraits::Vector;
971 
972  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
973  vertex_iterator vi = iterator_pair.first;
974  vertex_iterator vi_end = iterator_pair.second;
975  for (; vi != vi_end; ++vi)
976  {
977  v_CVm[*vi] = Vector(1., 1., 1.);
978  }
979  // HERE WE FORCE a full v(1., 1., 1.) vertex-custom_vector map
980 
982  FEVV::vertex_custom_vector, *_g, *_pmaps, v_CVm); // MT add (for later redraw)
983  }
984  // TEMP for CUSTOM VECTOR
985  // --- vertex_custom_vector
986 
987  // --- vertex_custom_vector_color
989  {
990  if(!m_redraw)
991  std::cout << "[SimpleViewer] using vertex CUSTOM VECTOR COLOR" << std::endl;
992  v_CVCm = get_property_map(FEVV::vertex_custom_vector_color, *_g, *_pmaps);
993  _vt_CVCm = &v_CVCm;
994  }
995  // TEMP for CUSTOM VECTOR COLOR
996  if(0) // OFF, but it is normal so don't delete please...
997  if(_vt_CVCm == nullptr || m_recomputeNT_if_redraw)
998  {
999  if(!m_redraw)
1000  std::cout << "[SimpleViewer] vertex CUSTOM VECTOR COLOR missing, filling it with example values"
1001  << std::endl;
1003  _vt_CVCm = &v_CVCm;
1004 
1005  // HERE WE FORCE a full LightGreen vertex-custom_vector_color map
1006  using Vector = typename GeometryTraits::Vector;
1007 
1008  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
1009  vertex_iterator vi = iterator_pair.first;
1010  vertex_iterator vi_end = iterator_pair.second;
1011  for (; vi != vi_end; ++vi)
1012  {
1013  v_CVCm[*vi] = Vector(139/255.0f, 195/255.0f, 74/255.0f); // LightGreen
1014  }
1015  // HERE WE FORCE a full LightGreen vertex-custom_vector_color map
1016 
1018  FEVV::vertex_custom_vector_color, *_g, *_pmaps, v_CVCm); // MT add (for later redraw)
1019  }
1020  // TEMP for CUSTOM VECTOR COLOR
1021  // --- vertex_custom_vector_color
1022 
1023  // --- vertex_custom_vector_param
1025  {
1026  if(!m_redraw)
1027  std::cout << "[SimpleViewer] using vertex CUSTOM VECTOR PARAM" << std::endl;
1028  v_CVPm = get_property_map(FEVV::vertex_custom_vector_param, *_g, *_pmaps);
1029  _vt_CVPm = &v_CVPm;
1030  }
1031  // TEMP for CUSTOM VECTOR PARAM
1032  if(0) // OFF, but it is normal so don't delete please...
1033  if(_vt_CVPm == nullptr || m_recomputeNT_if_redraw)
1034  {
1035  if(!m_redraw)
1036  std::cout << "[SimpleViewer] vertex CUSTOM VECTOR PARAM missing, filling it with example values"
1037  << std::endl;
1039  _vt_CVPm = &v_CVPm;
1040 
1041  // HERE WE FORCE a full B_CV, E_CV, M_CV vertex-custom_vector_param map with default values
1042  using Vector = typename GeometryTraits::Vector;
1043 
1044  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
1045  vertex_iterator vi = iterator_pair.first;
1046  vertex_iterator vi_end = iterator_pair.second;
1047  for (; vi != vi_end; ++vi)
1048  {
1049  v_CVPm[*vi] = Vector(0.1f, 0.1f, 0.08f); // B_CV, E_CV, M_CV
1050  }
1051  // HERE WE FORCE a full B_CV, E_CV, M_CV vertex-custom_vector_param map with default values
1052 
1054  FEVV::vertex_custom_vector_param, *_g, *_pmaps, v_CVPm); // MT add (for later redraw)
1055  }
1056  // TEMP for CUSTOM VECTOR PARAM
1057  // --- vertex_custom_vector_param
1058 
1059  // TEMP - not used
1060  /*GeometryTraits gt(*_g);
1061 
1062  typename GeometryTraits::Point minAABB, maxAABB;
1063 
1064  FEVV::Tools::compute_bounding_box(*_g, *_pm, minAABB, maxAABB, gt);*/
1065  // TEMP - not used
1066 
1067  if(m_redraw) // IMPORTANT -> ONLY IF REDRAW via GUI or CODE
1068  {
1069  if(m_UseVertexColor || m_UseFaceColor ||
1070  m_UseTexture) // else automatic detection, as for a first DRAW
1071  if((!m_space_time) || (m_space_time && m_space_time_changeColorMode))
1072  {
1073  //_vt_nm = nullptr;
1074  //_f_nm = nullptr;
1075  _vt_cm = nullptr;
1076  _f_cm = nullptr;
1077  _vt_uv_m = nullptr;
1078  _het_uv_m = nullptr;
1079 
1080  // textures stuff
1081  _texture_type = NO_TEXCOORDS;
1082 
1083  _f_mm = nullptr;
1084  _m_mm = nullptr;
1085  //_m_mm_size = 0; // NEW
1086  // textures stuff
1087 
1088  if(m_UseVertexColor)
1089  {
1090  if(has_map(*_pmaps, FEVV::vertex_color))
1091  {
1092  v_cm = get_property_map(FEVV::vertex_color, *_g, *_pmaps);
1093  _vt_cm = &v_cm;
1094  }
1095  /*else
1096  {
1097  // -- TODO MT - TEMP - HERE WE FORCE a full RED vertex-color map for the REDRAW
1098  using Vector = typename GeometryTraits::Vector;
1099 
1100  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
1101  vertex_iterator vi = iterator_pair.first;
1102  vertex_iterator vi_end = iterator_pair.second;
1103  for (; vi != vi_end; ++vi)
1104  {
1105  v_cm[*vi] = Vector(1., 0., 0.); // RGB
1106  }
1107 
1108  _vt_cm = &v_cm;
1109  // -- TODO MT - TEMP - HERE WE FORCE a full RED vertex-color map for the REDRAW
1110  }*/
1111  else
1112  {
1113  //_vt_nm = nullptr;
1114  }
1115  }
1116  else if(m_UseFaceColor)
1117  {
1118  if(has_map(*_pmaps, FEVV::face_color))
1119  {
1120  f_cm = get_property_map(FEVV::face_color, *_g, *_pmaps);
1121  _f_cm = &f_cm;
1122  }
1123  else
1124  {
1125  //_vt_nm = nullptr;
1126  }
1127  }
1128  else if(m_UseTexture)
1129  {
1130  if(has_map(*_pmaps, FEVV::vertex_texcoord))
1131  {
1132  v_uvm = get_property_map(FEVV::vertex_texcoord, *_g, *_pmaps);
1133  _vt_uv_m = &v_uvm;
1134  _texture_type = VERTEX_TEXCOORDS2D;
1135  }
1136  else if(has_map(*_pmaps, FEVV::halfedge_texcoord))
1137  {
1138  h_uvm = get_property_map(FEVV::halfedge_texcoord, *_g, *_pmaps);
1139  _het_uv_m = &h_uvm;
1140  _texture_type = HALFEDGE_TEXCOORDS2D;
1141  }
1142  else
1143  {
1144  //_vt_nm = nullptr;
1145  }
1146 
1147  if(has_map(*_pmaps, FEVV::face_material))
1148  {
1149  f_mm = get_property_map(FEVV::face_material, *_g, *_pmaps);
1150  _f_mm = &f_mm;
1151  }
1152  else
1153  {
1154  if(_texture_type == HALFEDGE_TEXCOORDS2D)
1155  _texture_type = NO_TEXCOORDS; // if face material map is missing,
1156  // we can not display any texture in
1157  // HALFEDGE_TEXCOORDS2D mode
1158  }
1159 
1160  if(has_map(*_pmaps, FEVV::mesh_materials))
1161  {
1162  m_mm = get_property_map(FEVV::mesh_materials, *_g, *_pmaps);
1163  _m_mm = &m_mm;
1164 
1165  _m_mm_size =
1166  std::distance(m_mm.storage_begin(), m_mm.storage_end());
1167  }
1168  else
1169  _texture_type = NO_TEXCOORDS; // disable textures if no material
1170  }
1171  else
1172  {
1173  //_vt_nm = nullptr;
1174  //_f_nm = nullptr;
1175  }
1176  }
1177  }
1178 
1179  QApplication::setOverrideCursor(Qt::ForbiddenCursor);
1180  SimpleWindow *sw = static_cast< SimpleWindow * >(
1181  getWindow()); // here static_cast instead of dynamic_cast only for OSX and
1182  // because of plugins... don't understand why...
1183  sw->statusBar()->showMessage(
1184  QObject::tr("Create and populate OSG objects...") /*, 2000*/);
1185 
1186  GeometryTraits gt(*_g);
1187 
1188  if(geode == nullptr)
1189  {
1190  geode = new osg::Geode; // MT OSG_GEODE : bug from JL ? Ici geode devrait
1191  // être osg::ref_ptr<osg::Geode> ???
1192  }
1193  else
1194  {
1195  geode->removeDrawables(0, geode->getNumDrawables());
1196  }
1197 
1198  // we must handle one geometry per texture/material
1199  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1200  {
1201  geometries.push_back(new osg::Geometry());
1202  geometries[0]->setSupportsDisplayList(true);
1203  geometries[0]->setUseDisplayList(true);
1204  geometries[0]->setUseVertexBufferObjects(
1205  false); /*geometries[0]->setUseVertexArrayObject(false);*/
1206  }
1207  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1208  {
1209  geometriesL.push_back(new osg::Geometry());
1210  geometriesL[0]->setSupportsDisplayList(true);
1211  geometriesL[0]->setUseDisplayList(true);
1212  geometriesL[0]->setUseVertexBufferObjects(
1213  false); /*geometriesL[0]->setUseVertexArrayObject(false);*/
1214  }
1215  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1216  {
1217  geometriesP.push_back(new osg::Geometry());
1218  geometriesP[0]->setSupportsDisplayList(true);
1219  geometriesP[0]->setUseDisplayList(true);
1220  geometriesP[0]->setUseVertexBufferObjects(
1221  false); /*geometriesP[0]->setUseVertexArrayObject(false);*/
1222  }
1223  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1224  {
1225  geometries_edges.push_back(new osg::Geometry());
1226  geometries_edges[0]->setSupportsDisplayList(true);
1227  geometries_edges[0]->setUseDisplayList(true);
1228  geometries_edges[0]->setUseVertexBufferObjects(
1229  false); /*geometries_edges[0]->setUseVertexArrayObject(false);*/
1230  }
1231  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1232  {
1233  geometries_vertices.push_back(new osg::Geometry());
1234  geometries_vertices[0]->setSupportsDisplayList(true);
1235  geometries_vertices[0]->setUseDisplayList(true);
1236  geometries_vertices[0]->setUseVertexBufferObjects(
1237  false); /*geometries_vertices[0]->setUseVertexArrayObject(false);*/
1238  }
1239  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1240  {
1241  geometries_normals.push_back(new osg::Geometry());
1242  geometries_normals[0]->setSupportsDisplayList(true);
1243  geometries_normals[0]->setUseDisplayList(true);
1244  geometries_normals[0]->setUseVertexBufferObjects(
1245  false); /*geometries_normals[0]->setUseVertexArrayObject(false);*/
1246  }
1247  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1248  {
1249  geometries_custom_vectors.push_back(new osg::Geometry());
1250  geometries_custom_vectors[0]->setSupportsDisplayList(true);
1251  geometries_custom_vectors[0]->setUseDisplayList(true);
1252  geometries_custom_vectors[0]->setUseVertexBufferObjects(
1253  false); /*geometries_custom_vectors[0]->setUseVertexArrayObject(false);*/
1254  }
1255  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1256  {
1257  vertexArrays.push_back(new osg::Vec3Array);
1258  }
1259  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1260  {
1261  vertexArrays_edges.push_back(new osg::Vec3Array);
1262  }
1263  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1264  {
1265  vertexArrays_vertices.push_back(new osg::Vec3Array);
1266  }
1267  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1268  {
1269  vertexArrays_normals.push_back(new osg::Vec3Array);
1270  }
1271  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1272  {
1273  vertexArrays_custom_vectors.push_back(new osg::Vec3Array);
1274  }
1275  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1276  {
1277  normalsArrays.push_back(new osg::Vec3Array);
1278  }
1279  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1280  {
1281  normalsArraysF.push_back(new osg::Vec3Array);
1282  }
1283  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1284  {
1285  normalsArrays_edges.push_back(new osg::Vec3Array);
1286  }
1287  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1288  {
1289  normalsArrays_vertices.push_back(new osg::Vec3Array);
1290  }
1291  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1292  {
1293  tangentsArrays.push_back(new osg::Vec3Array);
1294  }
1295  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1296  {
1297  colorsArrays.push_back(new osg::Vec4Array);
1298  }
1299  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1300  {
1301  colorsArrays_edges.push_back(new osg::Vec4Array);
1302  }
1303  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1304  {
1305  colorsArrays_vertices.push_back(new osg::Vec4Array);
1306  }
1307  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1308  {
1309  colorsArrays_normals.push_back(new osg::Vec4Array);
1310  }
1311  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1312  {
1313  colorsArrays_custom_vectors.push_back(new osg::Vec4Array);
1314  }
1315  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1316  {
1317  texcoordsArrays.push_back(new osg::Vec2Array);
1318  }
1319  // std::cout << "---------> geometries.push_back" << std::endl;
1320  size_t mtl_id = 0;
1321 
1322  // add ONLY if multi-textures
1323  for(size_t mi = 1; mi < _m_mm_size; mi++)
1324  {
1325  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1326  {
1327  geometries.push_back(new osg::Geometry());
1328  geometries[mi]->setSupportsDisplayList(true);
1329  geometries[mi]->setUseDisplayList(true);
1330  geometries[mi]->setUseVertexBufferObjects(
1331  false); /*geometries[mi]->setUseVertexArrayObject(false);*/
1332  }
1333  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1334  {
1335  geometriesL.push_back(new osg::Geometry());
1336  geometriesL[mi]->setSupportsDisplayList(true);
1337  geometriesL[mi]->setUseDisplayList(true);
1338  geometriesL[mi]->setUseVertexBufferObjects(
1339  false); /*geometriesL[mi]->setUseVertexArrayObject(false);*/
1340  }
1341  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1342  {
1343  geometriesP.push_back(new osg::Geometry());
1344  geometriesP[mi]->setSupportsDisplayList(true);
1345  geometriesP[mi]->setUseDisplayList(true);
1346  geometriesP[mi]->setUseVertexBufferObjects(
1347  false); /*geometriesP[mi]->setUseVertexArrayObject(false);*/
1348  }
1349  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1350  {
1351  geometries_edges.push_back(new osg::Geometry());
1352  geometries_edges[mi]->setSupportsDisplayList(true);
1353  geometries_edges[mi]->setUseDisplayList(true);
1354  geometries_edges[mi]->setUseVertexBufferObjects(
1355  false); /*geometries_edges[mi]->setUseVertexArrayObject(false);*/
1356  }
1357  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1358  {
1359  geometries_vertices.push_back(new osg::Geometry());
1360  geometries_vertices[mi]->setSupportsDisplayList(true);
1361  geometries_vertices[mi]->setUseDisplayList(true);
1362  geometries_vertices[mi]->setUseVertexBufferObjects(
1363  false); /*geometries_vertices[mi]->setUseVertexArrayObject(false);*/
1364  }
1365  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1366  {
1367  geometries_normals.push_back(new osg::Geometry());
1368  geometries_normals[mi]->setSupportsDisplayList(true);
1369  geometries_normals[mi]->setUseDisplayList(true);
1370  geometries_normals[mi]->setUseVertexBufferObjects(
1371  false); /*geometries_normals[mi]->setUseVertexArrayObject(false);*/
1372  }
1373  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1374  {
1375  geometries_custom_vectors.push_back(new osg::Geometry());
1376  geometries_custom_vectors[mi]->setSupportsDisplayList(true);
1377  geometries_custom_vectors[mi]->setUseDisplayList(true);
1378  geometries_custom_vectors[mi]->setUseVertexBufferObjects(
1379  false); /*geometries_custom_vectors[mi]->setUseVertexArrayObject(false);*/
1380  }
1381  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1382  {
1383  vertexArrays.push_back(new osg::Vec3Array);
1384  }
1385  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1386  {
1387  vertexArrays_edges.push_back(new osg::Vec3Array);
1388  }
1389  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1390  {
1391  vertexArrays_vertices.push_back(new osg::Vec3Array);
1392  }
1393  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1394  {
1395  vertexArrays_normals.push_back(new osg::Vec3Array);
1396  }
1397  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1398  {
1399  vertexArrays_custom_vectors.push_back(new osg::Vec3Array);
1400  }
1401  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1402  {
1403  normalsArrays.push_back(new osg::Vec3Array);
1404  }
1405  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1406  {
1407  normalsArraysF.push_back(new osg::Vec3Array);
1408  }
1409  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1410  {
1411  normalsArrays_edges.push_back(new osg::Vec3Array);
1412  }
1413  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1414  {
1415  normalsArrays_vertices.push_back(new osg::Vec3Array);
1416  }
1417  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1418  {
1419  tangentsArrays.push_back(new osg::Vec3Array);
1420  }
1421  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1422  {
1423  colorsArrays.push_back(new osg::Vec4Array);
1424  }
1425  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1426  {
1427  colorsArrays_edges.push_back(new osg::Vec4Array);
1428  }
1429  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1430  {
1431  colorsArrays_vertices.push_back(new osg::Vec4Array);
1432  }
1433  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1434  {
1435  colorsArrays_normals.push_back(new osg::Vec4Array);
1436  }
1437  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1438  {
1439  colorsArrays_custom_vectors.push_back(new osg::Vec4Array);
1440  }
1441  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
1442  {
1443  texcoordsArrays.push_back(new osg::Vec2Array);
1444  }
1445  // std::cout << "---------> geometries.push_back" << std::endl;
1446  }
1447 
1448  unsigned int sizeVertex = 0;
1449  unsigned int sizeFace = 0;
1450  unsigned int sizeSPoints = 0;
1451  unsigned int sizeSLines = 0;
1452 
1453  face_iterator fb, fe;
1454  halfedge_point p0;
1455  vertex_descriptor vd0;
1456  halfedge_vector normal;
1457 
1458  bool texture_corner_mode_on =
1459  (_het_uv_m != nullptr && _texture_type == HALFEDGE_TEXCOORDS2D);
1460  bool texture_vertex_mode_on =
1461  (_vt_uv_m != nullptr && _texture_type == VERTEX_TEXCOORDS2D);
1462 
1463  // std::cout << "---------> texture_corner_mode_on: " <<
1464  // texture_corner_mode_on << std::endl; std::cout << "--------->
1465  // texture_vertex_mode_on: " << texture_vertex_mode_on << std::endl;
1466 
1468  // if(m_RenderSuperimposedEdges)
1469  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw)) // NEW
1470  {
1471  const float MAGNITUDE = 0.0005;
1472  // std::cout << "---------> Adding edges (for superimpose)" << std::endl;
1473 
1474  using EdgeColorMap = typename FEVV::PMap_traits< FEVV::edge_color_t,
1475  HalfedgeGraph >::pmap_type;
1476  EdgeColorMap e_cm;
1477  EdgeColorMap *_e_cm = nullptr;
1478 
1479  if(has_map(*_pmaps, FEVV::edge_color))
1480  {
1481  e_cm = get_property_map(FEVV::edge_color, *_g, *_pmaps);
1482  _e_cm = &e_cm;
1483  }
1484 
1485  // ---
1486 
1487  vertex_descriptor vs, vt;
1488  halfedge_point ps, pt;
1489 
1490  edge_iterator eb, ee;
1491  for(boost::tie(eb, ee) = edges(*_g); eb != ee; ++eb)
1492  {
1493  // retrieve vertex (source)
1494  vs = source(*eb, *_g);
1495 
1496  // retrieve vertex-point (source)
1497  ps = (*_pm)[vs];
1498  vertexArrays_edges[mtl_id]->push_back( Helpers::VectorConverter< HalfedgeGraph >(ps) + Helpers::VectorConverter< HalfedgeGraph >(get(v_nm, vs)) * MAGNITUDE ); // ok because _vt_nm always true
1499 
1500  // retrieve vertex (target)
1501  vt = target(*eb, *_g);
1502 
1503  // retrieve vertex-point (target)
1504  pt = (*_pm)[vt];
1505  vertexArrays_edges[mtl_id]->push_back( Helpers::VectorConverter< HalfedgeGraph >(pt) + Helpers::VectorConverter< HalfedgeGraph >(get(v_nm, vt)) * MAGNITUDE ); // ok because _vt_nm always true
1506 
1507  sizeSLines++;
1508 
1509  // color
1510  if(_e_cm)
1511  {
1512  colorsArrays_edges[mtl_id]->push_back(
1513  Helpers::VectorColorConverter< HalfedgeGraph >(
1514  get(e_cm, *eb))); // user/filter/plugin colors
1515  colorsArrays_edges[mtl_id]->push_back(
1516  Helpers::VectorColorConverter< HalfedgeGraph >(
1517  get(e_cm, *eb))); // user/filter/plugin colors
1518  }
1519  else
1520  {
1521  colorsArrays_edges[mtl_id]->push_back(
1522  Helpers::ColorConverter(Color::Yellow())); // default color
1523  colorsArrays_edges[mtl_id]->push_back(
1524  Helpers::ColorConverter(Color::Yellow())); // default color
1525  }
1526 
1527  // normal (only for GEOMETRY shader)
1528  if(_vt_nm)
1529  {
1530  normalsArrays_edges[mtl_id]->push_back(
1531  Helpers::VectorConverter< HalfedgeGraph >(
1532  get(v_nm, vs)));
1533 
1534  normalsArrays_edges[mtl_id]->push_back(
1535  Helpers::VectorConverter< HalfedgeGraph >(
1536  get(v_nm, vt)));
1537  }
1538  }
1539 
1540  geometries_edges[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1541  osg::PrimitiveSet::LINES, 0, vertexArrays_edges[mtl_id]->size()));
1542 
1543  // NEW_HERE-01 (DEL)
1544 #if 0
1545  // set line width
1546  osg::ref_ptr< osg::LineWidth > linewidth = new osg::LineWidth();
1547  linewidth->setWidth(1.5f);
1548  geometries_edges[mtl_id]
1549  ->getOrCreateStateSet()
1550  ->setAttribute(linewidth, osg::StateAttribute::ON); // setAttributeAndModes (other function)
1551 
1552  // light
1553  geometries_edges[mtl_id]->getOrCreateStateSet()->setMode(
1554  GL_LIGHTING,
1555  osg::StateAttribute::OFF); // light always OFF for superimpose edges
1556 #endif
1557  }
1558  // NEW_HERE-01 (ADD)
1559  geometries_edges[mtl_id]->setStateSet(NULL);
1560  {
1561  // set line width
1562  osg::ref_ptr< osg::LineWidth > linewidth = new osg::LineWidth();
1563  linewidth->setWidth(1.5f);
1564  geometries_edges[mtl_id]
1565  ->getOrCreateStateSet()
1566  ->setAttribute(linewidth, osg::StateAttribute::ON); // setAttributeAndModes (other function)
1567 
1568  // light
1569  geometries_edges[mtl_id]->getOrCreateStateSet()->setMode(
1570  GL_LIGHTING,
1571  osg::StateAttribute::OFF); // light always OFF for superimpose edges
1572  }
1573 
1575  //size_t nb_faces = size_of_faces(*_g);
1576  // if(m_RenderSuperimposedVertices || m_RenderSuperimposedVertices_Big ||
1577  // (nb_faces==0)) // last test for 'only_pts' mode
1578  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw)) // NEW
1579  {
1580  const float MAGNITUDE_N = 0.08;
1581  // std::cout << "---------> Adding vertices (for superimpose and 'only_pts'
1582  // mode)" << std::endl;
1583 
1584  VertexColorMap *SAVE_vt_cm = _vt_cm;
1585 
1586  if(has_map(*_pmaps, FEVV::vertex_color))
1587  {
1588  v_cm = get_property_map(FEVV::vertex_color, *_g, *_pmaps);
1589  _vt_cm = &v_cm;
1590  }
1591 
1592  // ---
1593 
1594  for(vertex_iterator v_it = vertices(*_g).first;
1595  v_it != vertices(*_g).second;
1596  ++v_it)
1597  {
1598  // retrieve vertex
1599  vd0 = *v_it;
1600 
1601  // retrieve vertex-point
1602  p0 = (*_pm)[vd0];
1603  vertexArrays_vertices[mtl_id]->push_back(
1604  Helpers::VectorConverter< HalfedgeGraph >(p0));
1605 
1606  // [ normals
1607  vertexArrays_normals[mtl_id]->push_back( Helpers::VectorConverter< HalfedgeGraph >(p0) );
1608  vertexArrays_normals[mtl_id]->push_back( Helpers::VectorConverter< HalfedgeGraph >(p0) + Helpers::VectorConverter< HalfedgeGraph >(get(v_nm, *v_it)) * 0.5 * MAGNITUDE_N ); // ok because _vt_nm always true
1609  // ] normals
1610 
1611  // [ custom_vectors
1612  if(_vt_CVm)
1613  {
1614  float MAGNITUDE_CV = 0.08;
1615  float B_CV = 0.;
1616  float E_CV = 1.;
1617 
1618  if(_vt_CVPm)
1619  {
1620  using Vector = typename GeometryTraits::Vector;
1621  Vector _vector = get(v_CVPm, *v_it);
1622 
1623  B_CV = _vector[0];
1624  E_CV = _vector[1];
1625  MAGNITUDE_CV = _vector[2];
1626  }
1627 
1628  vertexArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorConverter< HalfedgeGraph >(p0) - Helpers::VectorConverter< HalfedgeGraph >(get(v_CVm, *v_it)) * B_CV * MAGNITUDE_CV );
1629  vertexArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorConverter< HalfedgeGraph >(p0) + Helpers::VectorConverter< HalfedgeGraph >(get(v_CVm, *v_it)) * E_CV * MAGNITUDE_CV );
1630  }
1631  // ] custom_vectors
1632 
1633  sizeSPoints++;
1634 
1635  // color
1636  if(_vt_cm)
1637  colorsArrays_vertices[mtl_id]->push_back(
1638  Helpers::VectorColorConverter< HalfedgeGraph >(
1639  get(v_cm, *v_it))); // user/filter/plugin colors
1640  else
1641  colorsArrays_vertices[mtl_id]->push_back(
1642  Helpers::ColorConverter(Color::Green())); // default color
1643 
1644  // normal (only for GEOMETRY shader)
1645  if(_vt_nm)
1646  normalsArrays_vertices[mtl_id]->push_back(
1647  Helpers::VectorConverter< HalfedgeGraph >(
1648  get(v_nm, *v_it)));
1649 
1650  // [ normals
1651  colorsArrays_normals[mtl_id]->push_back(Helpers::ColorConverter(Color::Red()));
1652  colorsArrays_normals[mtl_id]->push_back(Helpers::ColorConverter(Color::Red()));
1653  // ] normals
1654 
1655  // [ custom_vectors
1656  if(_vt_CVCm)
1657  {
1658  colorsArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorColorConverter< HalfedgeGraph >(get(v_CVCm, *v_it)) );
1659  colorsArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorColorConverter< HalfedgeGraph >(get(v_CVCm, *v_it)) );
1660  }
1661  else // white by default
1662  {
1663  colorsArrays_custom_vectors[mtl_id]->push_back(Helpers::ColorConverter(Color::White()));
1664  colorsArrays_custom_vectors[mtl_id]->push_back(Helpers::ColorConverter(Color::White()));
1665  }
1666  // ] custom_vectors
1667  }
1668 
1669  geometries_vertices[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1670  osg::PrimitiveSet::POINTS, 0, vertexArrays_vertices[mtl_id]->size()));
1671 
1672  // [ normals
1673  geometries_normals[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1674  osg::PrimitiveSet::LINES, 0, vertexArrays_normals[mtl_id]->size()));
1675  // ] normals
1676 
1677  // [ custom_vectors
1678  geometries_custom_vectors[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1679  osg::PrimitiveSet::LINES, 0, vertexArrays_custom_vectors[mtl_id]->size()));
1680  // ] custom_vectors
1681 
1682  // NEW_HERE-01 (DEL)
1683 #if 0
1684  if(m_RenderSuperimposedVertices || m_RenderSuperimposedVertices_Big)
1685  {
1686  // set point size
1687  osg::ref_ptr< osg::Point > pt = new osg::Point();
1688  if(m_RenderSuperimposedVertices_Big)
1689  pt->setSize(5.0f);
1690  else
1691  pt->setSize(3.0f);
1692  geometries_vertices[mtl_id]->getOrCreateStateSet()->setAttribute(
1693  pt, osg::StateAttribute::ON);
1694  }
1695 
1696  // light
1697  geometries_vertices[mtl_id]->getOrCreateStateSet()->setMode(
1698  GL_LIGHTING, osg::StateAttribute::OFF); // light always OFF for
1699  // superimpose vertices
1700 #endif
1701 
1702  // ---
1703 
1704  _vt_cm = SAVE_vt_cm;
1705  }
1706  // NEW_HERE-01 (ADD)
1707  geometries_vertices[mtl_id]->setStateSet(NULL);
1708  {
1709  // set point size
1710  osg::ref_ptr< osg::Point > pt = new osg::Point();
1711  if(m_RenderSuperimposedVertices_Big)
1712  pt->setSize(5.0f);
1713  else if(m_RenderSuperimposedVertices)
1714  pt->setSize(3.0f);
1715  else
1716  pt->setSize(1.0f);
1717  geometries_vertices[mtl_id]->getOrCreateStateSet()->setAttribute(
1718  pt, osg::StateAttribute::ON);
1719 
1720  // light
1721  geometries_vertices[mtl_id]->getOrCreateStateSet()->setMode(
1722  GL_LIGHTING, osg::StateAttribute::OFF); // light always OFF for
1723  // superimpose vertices
1724  }
1725  // [ normals
1726  geometries_normals[mtl_id]->setStateSet(NULL);
1727  {
1728  // set line width
1729  osg::ref_ptr< osg::LineWidth > linewidth = new osg::LineWidth();
1730  linewidth->setWidth(1.5f);
1731  geometries_normals[mtl_id]
1732  ->getOrCreateStateSet()
1733  ->setAttribute(linewidth, osg::StateAttribute::ON); // setAttributeAndModes (other function)
1734 
1735  // light
1736  geometries_normals[mtl_id]->getOrCreateStateSet()->setMode(
1737  GL_LIGHTING,
1738  osg::StateAttribute::OFF); // light always OFF for normals
1739  }
1740  // ] normals
1741  // [ custom_vectors
1742  geometries_custom_vectors[mtl_id]->setStateSet(NULL);
1743  {
1744  // set line width
1745  osg::ref_ptr< osg::LineWidth > linewidth = new osg::LineWidth();
1746  linewidth->setWidth(1.5f);
1747  geometries_custom_vectors[mtl_id]
1748  ->getOrCreateStateSet()
1749  ->setAttribute(linewidth, osg::StateAttribute::ON); // setAttributeAndModes (other function)
1750 
1751  // light
1752  geometries_custom_vectors[mtl_id]->getOrCreateStateSet()->setMode(
1753  GL_LIGHTING,
1754  osg::StateAttribute::OFF); // light always OFF for custom_vectors
1755  }
1756  // ] custom_vectors
1757 
1759  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw)) // NEW
1760  {
1761  // std::cout << "---------> Adding faces" << std::endl;
1762 
1763  for(boost::tie(fb, fe) = faces(*_g); fb != fe; ++fb)
1764  {
1765  // retrieve the material/texture ID of the current face (ONLY in
1766  // HALFEDGE_TEXCOORDS2D mode)
1767  if(texture_corner_mode_on || texture_vertex_mode_on)
1768  {
1769  mtl_id = get(*_f_mm, *fb);
1770  // std::cout << "---------> mtl_id for current face: " << mtl_id <<
1771  // std::endl;
1772  }
1773 
1774  halfedge_descriptor edg = halfedge(*fb, *_g);
1775  halfedge_descriptor edg_begin = edg;
1776 
1777  std::vector< halfedge_point > p;
1778  std::vector< vertex_descriptor > vd;
1779 
1780  // loop over halfedges of the face
1781  do
1782  {
1783  vd.push_back(target(edg, *_g));
1784  p.push_back((*_pm)[vd.back()]);
1785 
1786  vertexArrays[mtl_id]->push_back(
1787  Helpers::VectorConverter< HalfedgeGraph >(p.back()));
1788 
1789  if(_vt_cm != nullptr)
1790  {
1791  colorsArrays[mtl_id]->push_back(
1792  Helpers::VectorColorConverter< HalfedgeGraph >(
1793  (*_vt_cm)[vd.back()]));
1794  }
1795 
1796  if(_het_uv_m != nullptr && _texture_type == HALFEDGE_TEXCOORDS2D)
1797  {
1798  texcoordsArrays[mtl_id]->push_back(
1799  osg::Vec2((*_het_uv_m)[edg][0], (*_het_uv_m)[edg][1]));
1800  }
1801  else if(_vt_uv_m != nullptr && _texture_type == VERTEX_TEXCOORDS2D)
1802  {
1803  texcoordsArrays[mtl_id]->push_back(
1804  osg::Vec2((*_vt_uv_m)[vd.back()][0], (*_vt_uv_m)[vd.back()][1]));
1805  }
1806 
1807  if(_vt_nm != nullptr) // normal per vertex -> already calculated
1808  {
1809  // if(m_SmoothFlat_Shading) // NEW_HERE-02 (DEL)
1810  {
1811  normal = (*_vt_nm)[vd.back()];
1812  normalsArrays[mtl_id]->push_back(
1813  Helpers::VectorConverter< HalfedgeGraph >(
1814  normal)); // smooth mode
1815  }
1816  // else // NEW_HERE-02 (DEL)
1817  {
1818  normal = (*_f_nm)[*fb];
1819  normalsArraysF[mtl_id]->push_back(
1820  Helpers::VectorConverter< HalfedgeGraph >(
1821  normal)); // flat mode (caution, here, instead we take n x
1822  // the normal per face)
1823  }
1824 
1825  if(v_tan_m != nullptr)
1826  {
1827  // RM: push tangents
1828  // Note: shouldn't be added if no normal map available, causing
1829  // extra process
1830  tangentsArrays[mtl_id]->push_back(
1831  osg::Vec3((*v_tan_m)[vd.back()][0],
1832  (*v_tan_m)[vd.back()][1],
1833  (*v_tan_m)[vd.back()][2]));
1834  }
1835  }
1836 
1837  ++sizeVertex;
1838 
1839  edg = next(edg, *_g);
1840  } while(edg != edg_begin);
1841 
1842  // create and populate OSG face object
1843  uint num_vertices_in_face = static_cast< uint >(p.size());
1844 
1845  auto drawing_method =
1846  static_cast< osg::PrimitiveSet::Mode >(m_RenderMethod);
1847  if(m_RenderMethod ==
1848  RenderMethod::RENDER_FILL) // RENDER_FILL is set to POLYGON primitive
1849  {
1850  if(num_vertices_in_face == 3)
1851  drawing_method = osg::PrimitiveSet::TRIANGLES;
1852  else if(num_vertices_in_face == 4)
1853  {
1854  drawing_method = osg::PrimitiveSet::QUADS;
1855  // std::cout << "---> QUAD-QUAD-QUAD-QUAD-QUAD" << std::endl;
1856  }
1857  else
1858  {
1859  // std::cout << "---> POLY-POLY-POLY-POLY-POLY" << std::endl;
1860  }
1861  }
1862 
1863  geometries[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1864  drawing_method,
1865  vertexArrays[mtl_id]->size() - num_vertices_in_face,
1866  num_vertices_in_face));
1867  // NEW_HERE-03 (ADD)
1868  geometriesL[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1870  vertexArrays[mtl_id]->size() - num_vertices_in_face,
1871  num_vertices_in_face));
1872  geometriesP[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
1874  vertexArrays[mtl_id]->size() - num_vertices_in_face,
1875  num_vertices_in_face));
1876 
1877  // populate face normal array
1878  if(_vt_nm != nullptr) // normal per vertex (see above) -> already calculated
1879  {
1880  // do nothing
1881  // std::cout << "---> normal per vertex - normal per vertex - normal per
1882  // vertex" << std::endl;
1883  }
1884  else if(_f_nm != nullptr) // normal per face -> already calculated
1885  {
1886  std::cout << "---> normal per face - normal per face - normal per face --> MUST NEVER HAPPENS !!!"
1887  << std::endl; // TEMP
1888 
1889  normal = (*_f_nm)[*fb];
1890  normalsArrays[mtl_id]->push_back(
1891  Helpers::VectorConverter< HalfedgeGraph >(normal));
1892  }
1893  else // if none - BUT NEVER HAPPENS - re-compute normal for current face
1894  {
1895  std::cout << "---> NEVER HAPPENS - NEVER HAPPENS - NEVER HAPPENS"
1896  << std::endl; // TEMP
1897 
1898 #if 0
1899  if(num_vertices_in_face == 3) // TRIANGLE
1900  {
1901  normal = gt.unit_normal(p[1], p[2], p[0]);
1902  normalsArrays[mtl_id]->push_back(
1903  Helpers::VectorConverter< HalfedgeGraph >(normal));
1904  }
1905  else if(num_vertices_in_face == 4) // QUAD
1906  {
1907  normal = gt.NULL_VECTOR;
1908  normal = gt.normal(p[1], p[2], p[0]) + gt.normal(p[2], p[3], p[1]);
1909  normal = normal / gt.length(normal);
1910  normalsArrays[mtl_id]->push_back(
1911  Helpers::VectorConverter< HalfedgeGraph >(normal));
1912  }
1913  else // POLYGON
1914  {
1915  // TODO
1916  std::cerr << "-----> [SimpleViewer] Only re-computed normals for "
1917  "triangles/quads are implemented -> re-computed normals "
1918  "for other polygons are not yet implemented."
1919  << std::endl;
1920  }
1921 #endif
1922  }
1923 
1924  // populate face color array
1925  if(_f_cm != nullptr)
1926  {
1927  colorsArrays[mtl_id]->push_back(
1928  Helpers::VectorColorConverter< HalfedgeGraph >((*_f_cm)[*fb]));
1929  }
1930 
1931  ++sizeFace;
1932  }
1933 
1934  std::cout << "[SimpleViewer] I have drawn " << sizeFace << " faces (with "
1935  << sizeVertex << " vertices)." << std::endl;
1936  std::cout << "[SimpleViewer] I have also drawn " << sizeSPoints
1937  << " (superimpose) points and " << sizeSLines
1938  << " superimpose lines." << std::endl;
1939  }
1940 
1941  sw->statusBar()->showMessage(QObject::tr("") /*, 2000*/);
1942  QApplication::restoreOverrideCursor();
1943 
1944  // auto gui_props = get((*_m_gpm), 0);
1945  // geode->setNodeMask(gui_props.is_visible ? 0xffffffff : 0x0); // 19/03/19
1946 
1947  const auto loadingStartTime = std::chrono::system_clock::now();
1948 
1949  QApplication::setOverrideCursor(Qt::BusyCursor);
1950  sw->statusBar()->showMessage(QObject::tr("Render mesh...") /*, 2000*/);
1951 
1952  // NEW_HERE-02 (ADD)
1953  std::vector< osg::ref_ptr< osg::Vec3Array > > *_normalsArrays = nullptr;
1954  if(m_SmoothFlat_Shading)
1955  _normalsArrays = &normalsArrays;
1956  else
1957  _normalsArrays = &normalsArraysF;
1958 
1959  // NEW_HERE-03 (ADD)
1960  std::vector< osg::ref_ptr< osg::Geometry > > *_geometries = nullptr;
1961  if(m_RenderMethod == RenderMethod::RENDER_FILL)
1962  _geometries = &geometries;
1963  else if(m_RenderMethod == RenderMethod::RENDER_LINES)
1964  _geometries = &geometriesL;
1965  else
1966  _geometries = &geometriesP; // RenderMethod::RENDER_POINTS
1967 
1968  if(m_RenderMode == RenderMode::RENDER_SHADERS_DIRECT_LIGHTING ||
1970  {
1971  internal_loadShadedMesh(geode,
1972  _g,
1973  *_geometries,
1974  geometries_edges,
1975  geometries_vertices,
1976  geometries_normals,
1977  geometries_custom_vectors,
1978  vertexArrays,
1979  vertexArrays_edges,
1980  vertexArrays_vertices,
1981  vertexArrays_normals,
1982  vertexArrays_custom_vectors,
1983  *_normalsArrays,
1984  normalsArrays_edges,
1985  normalsArrays_vertices,
1986  tangentsArrays,
1987  texcoordsArrays,
1988  colorsArrays,
1989  colorsArrays_edges,
1990  colorsArrays_vertices,
1991  colorsArrays_normals,
1992  colorsArrays_custom_vectors,
1993  _m_mm_size,
1994  _vt_nm,
1995  v_tan_m,
1996  _vt_cm,
1997  _f_cm,
1998  _vt_uv_m,
1999  _het_uv_m,
2000  _m_mm,
2001  has_map(*_pmaps, FEVV::face_color));
2002 
2004  {
2005  std::cout << "[SimpleViewer] Rendering with indirect lighting."
2006  << std::endl;
2007  // RM: sends uniform as true if we set the mode to indirect lighting
2008  geode->getOrCreateStateSet()->addUniform(
2009  new osg::Uniform("uniUseIndirectLighting", true));
2010  }
2011  else
2012  {
2013  std::cout << "[SimpleViewer] Rendering with direct lighting."
2014  << std::endl;
2015  }
2016  }
2017  else
2018  {
2019  internal_loadLegacyMesh(geode,
2020  _g,
2021  *_geometries,
2022  geometries_edges,
2023  geometries_vertices,
2024  geometries_normals,
2025  geometries_custom_vectors,
2026  vertexArrays,
2027  vertexArrays_edges,
2028  vertexArrays_vertices,
2029  vertexArrays_normals,
2030  vertexArrays_custom_vectors,
2031  *_normalsArrays,
2032  normalsArrays_edges,
2033  normalsArrays_vertices,
2034  texcoordsArrays,
2035  colorsArrays,
2036  colorsArrays_edges,
2037  colorsArrays_vertices,
2038  colorsArrays_normals,
2039  colorsArrays_custom_vectors,
2040  _m_mm_size,
2041  _texture_type,
2042  _vt_nm,
2043  _vt_cm,
2044  _f_cm,
2045  _vt_uv_m,
2046  _het_uv_m,
2047  _m_mm,
2048  has_map(*_pmaps, FEVV::face_color));
2049  }
2050 
2051  sw->statusBar()->showMessage(QObject::tr("") /*, 2000*/);
2052  QApplication::restoreOverrideCursor();
2053 
2054  std::cout << "[SimpleViewer] Done 'loading' mesh (in graphic card) in "
2055  << std::chrono::duration_cast< std::chrono::duration< float > >(
2056  std::chrono::system_clock::now() - loadingStartTime)
2057  .count()
2058  << " seconds." << std::endl;
2059 
2060  gizmo->setNodeMask(m_ShowAxis ? 0xffffffff : 0x0);
2061  grid->setNodeMask(m_ShowGrid ? 0xffffffff : 0x0);
2062 
2063  BaseViewer *bv = dynamic_cast< BaseViewer * >(this);
2064  BaseAdapterVisuQt *bavQt =
2065  dynamic_cast< BaseAdapterVisuQt * >(bv->getAdapter());
2066  // geode->setName( std::string("Mesh ") +
2067  // std::to_string(Helpers::nbMeshDrawed++) + std::string(" [") +
2068  // bavQt->windowTitle().toStdString() + std::string("]") );
2069 
2070  std::string ds_name = FEVV::getDatastructureName(_g);
2071  geode->setName(_mesh_file + std::string(" [") + ds_name + " " +
2072  bavQt->windowTitle().left(bavQt->windowTitle().indexOf('>') + 1).toStdString() + std::string("]"));
2073  geode->addDescription("MESH");
2074 }
2075 
2076 
2077 template< typename PointCloud, typename PointMap >
2078 void
2080  osg::Geode *&geode,
2081  PointCloud *_g,
2082  PMapsContainer *_pmaps,
2083  std::vector< osg::ref_ptr< osg::Geometry > > &geometries,
2084  std::vector< osg::ref_ptr< osg::Geometry > > &geometriesL,
2085  std::vector< osg::ref_ptr< osg::Geometry > > &geometriesP,
2086  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_edges,
2087  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_vertices,
2088  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_normals,
2089  std::vector< osg::ref_ptr< osg::Geometry > > &geometries_custom_vectors,
2090  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays,
2091  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_edges,
2092  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_vertices,
2093  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_normals,
2094  std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_custom_vectors,
2095  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays,
2096  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArraysF,
2097  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_edges,
2098  std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_vertices,
2099  std::vector< osg::ref_ptr< osg::Vec3Array > > &tangentsArrays,
2100  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays,
2101  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_edges,
2102  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_vertices,
2103  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_normals,
2104  std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_custom_vectors,
2105  std::vector< osg::ref_ptr< osg::Vec2Array > > &texcoordsArrays,
2106  PointMap *_pm,
2107  std::string _mesh_file)
2108 {
2109  using GraphTraits = boost::graph_traits< PointCloud >;
2110  using GeometryTraits = FEVV::Geometry_traits< PointCloud >;
2112  using vertex_iterator = typename GraphTraits::vertex_iterator;
2113  using Point = typename GeometryTraits::Point;
2114  using Vector = typename GeometryTraits::Vector;
2115 
2116  // property maps stuff
2117  using VertexNormalMap =
2119  PointCloud >::pmap_type;
2120  using VertexColorMap = typename FEVV::PMap_traits< FEVV::vertex_color_t,
2121  PointCloud >::pmap_type;
2122 
2123  using VertexCustomVectorMap =
2125  PointCloud >::pmap_type;
2126 
2127  using VertexCustomVectorColorMap =
2129  PointCloud >::pmap_type;
2130 
2131  using VertexCustomVectorParamMap =
2133  PointCloud >::pmap_type;
2134 
2135  using MeshGuipropertiesMap =
2137  PointCloud >::pmap_type;
2138 
2139  VertexNormalMap v_nm;
2140  VertexColorMap v_cm;
2141 
2142  VertexCustomVectorMap v_CVm;
2143  VertexCustomVectorColorMap v_CVCm;
2144  VertexCustomVectorParamMap v_CVPm;
2145 
2146  MeshGuipropertiesMap m_gpm;
2147 
2148  VertexNormalMap *_vt_nm = nullptr;
2149  VertexColorMap *_vt_cm = nullptr;
2150 
2151  VertexCustomVectorMap *_vt_CVm = nullptr;
2152  VertexCustomVectorColorMap *_vt_CVCm = nullptr;
2153  VertexCustomVectorParamMap *_vt_CVPm = nullptr;
2154 
2155  size_t _m_mm_size = 0;
2156 
2157  // retrieve or create mesh gui-properties property map
2158  if(has_map(*_pmaps, FEVV::mesh_guiproperties))
2159  {
2160  m_gpm = get_property_map(FEVV::mesh_guiproperties, *_g, *_pmaps);
2161  }
2162  else
2163  {
2165  FEVV::Types::GuiProperties gui_props;
2166  put(m_gpm, 0, gui_props);
2167  put_property_map(FEVV::mesh_guiproperties, *_g, *_pmaps, m_gpm);
2168  }
2169 
2170  //MeshGuipropertiesMap *_m_gpm = &m_gpm;
2171 
2172  // --- vertex_normal
2173  if(has_map(*_pmaps, FEVV::vertex_normal))
2174  {
2175  if(!m_redraw)
2176  std::cout << "[SimpleViewer] using vertex normal" << std::endl;
2177  v_nm = get_property_map(FEVV::vertex_normal, *_g, *_pmaps);
2179  _vt_nm = &v_nm;
2180  }
2181 #if 0 //TODO-elo-restore-if-needed
2182  // compute vertex normals if not provided
2183  if(_vt_nm == nullptr || m_recomputeNT_if_redraw)
2184  {
2185  if(!m_redraw)
2186  std::cout << "[SimpleViewer] vertex normal missing, computing it"
2187  << std::endl;
2189  _vt_nm = &v_nm;
2190  FEVV::Filters::calculate_vertex_normals(*_g, *_pm, f_nm, v_nm);
2192  FEVV::vertex_normal, *_g, *_pmaps, v_nm); // MT add (for later redraw)
2193  }
2194 #endif
2195  // --- vertex_normal
2196 
2197  // --- vertex_color
2198  if(has_map(*_pmaps, FEVV::vertex_color))
2199  {
2200  if(!m_redraw)
2201  std::cout << "[SimpleViewer] using vertex color" << std::endl;
2202 
2203  v_cm = get_property_map(FEVV::vertex_color, *_g, *_pmaps);
2204  _vt_cm = &v_cm;
2205 
2206  if(!m_redraw)
2207  {
2208  m_UseVertexColor = true;
2209  m_UseFaceColor = false;
2210  m_UseTexture = false;
2211  }
2212  }
2213  // --- vertex_color
2214 
2215  // --- vertex_custom_vector
2216  if(has_map(*_pmaps, FEVV::vertex_custom_vector))
2217  {
2218  if(!m_redraw)
2219  std::cout << "[SimpleViewer] using vertex CUSTOM VECTOR" << std::endl;
2220  v_CVm = get_property_map(FEVV::vertex_custom_vector, *_g, *_pmaps);
2221  _vt_CVm = &v_CVm;
2222  }
2223  // TEMP for CUSTOM VECTOR
2224  if(0) // OFF, but it is normal so don't delete please...
2225  if(_vt_CVm == nullptr || m_recomputeNT_if_redraw)
2226  {
2227  if(!m_redraw)
2228  std::cout << "[SimpleViewer] vertex CUSTOM VECTOR missing, filling it with example values"
2229  << std::endl;
2231  _vt_CVm = &v_CVm;
2232 
2233  // HERE WE FORCE a full v(-1., 1., 1.) vertex-custom_vector map
2234  using Vector = typename GeometryTraits::Vector;
2235 
2236  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
2237  vertex_iterator vi = iterator_pair.first;
2238  vertex_iterator vi_end = iterator_pair.second;
2239  for (; vi != vi_end; ++vi)
2240  {
2241  v_CVm[*vi] = Vector(-1., 1., 1.);
2242  }
2243  // HERE WE FORCE a full v(-1., 1., 1.) vertex-custom_vector map
2244 
2246  FEVV::vertex_custom_vector, *_g, *_pmaps, v_CVm); // MT add (for later redraw)
2247  }
2248  // TEMP for CUSTOM VECTOR
2249  // --- vertex_custom_vector
2250 
2251  // --- vertex_custom_vector_color
2253  {
2254  if(!m_redraw)
2255  std::cout << "[SimpleViewer] using vertex CUSTOM VECTOR COLOR" << std::endl;
2256  v_CVCm = get_property_map(FEVV::vertex_custom_vector_color, *_g, *_pmaps);
2257  _vt_CVCm = &v_CVCm;
2258  }
2259  // TEMP for CUSTOM VECTOR COLOR
2260  if(0) // OFF, but it is normal so don't delete please...
2261  if(_vt_CVCm == nullptr || m_recomputeNT_if_redraw)
2262  {
2263  if(!m_redraw)
2264  std::cout << "[SimpleViewer] vertex CUSTOM VECTOR COLOR missing, filling it with example values"
2265  << std::endl;
2267  _vt_CVCm = &v_CVCm;
2268 
2269  // HERE WE FORCE a full GreenSea vertex-custom_vector_color map
2270  using Vector = typename GeometryTraits::Vector;
2271 
2272  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
2273  vertex_iterator vi = iterator_pair.first;
2274  vertex_iterator vi_end = iterator_pair.second;
2275  for (; vi != vi_end; ++vi)
2276  {
2277  v_CVCm[*vi] = Vector(22/255.0f, 160/255.0f, 133/255.0f); // GreenSea
2278  }
2279  // HERE WE FORCE a full GreenSea vertex-custom_vector_color map
2280 
2282  FEVV::vertex_custom_vector_color, *_g, *_pmaps, v_CVCm); // MT add (for later redraw)
2283  }
2284  // TEMP for CUSTOM VECTOR COLOR
2285  // --- vertex_custom_vector_color
2286 
2287  // --- vertex_custom_vector_param
2289  {
2290  if(!m_redraw)
2291  std::cout << "[SimpleViewer] using vertex CUSTOM VECTOR PARAM" << std::endl;
2292  v_CVPm = get_property_map(FEVV::vertex_custom_vector_param, *_g, *_pmaps);
2293  _vt_CVPm = &v_CVPm;
2294  }
2295  // TEMP for CUSTOM VECTOR PARAM
2296  if(0) // OFF, but it is normal so don't delete please...
2297  if(_vt_CVPm == nullptr || m_recomputeNT_if_redraw)
2298  {
2299  if(!m_redraw)
2300  std::cout << "[SimpleViewer] vertex CUSTOM VECTOR PARAM missing, filling it with example values"
2301  << std::endl;
2303  _vt_CVPm = &v_CVPm;
2304 
2305  // HERE WE FORCE a full B_CV, E_CV, M_CV vertex-custom_vector_param map with default values
2306  using Vector = typename GeometryTraits::Vector;
2307 
2308  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
2309  vertex_iterator vi = iterator_pair.first;
2310  vertex_iterator vi_end = iterator_pair.second;
2311  for (; vi != vi_end; ++vi)
2312  {
2313  v_CVPm[*vi] = Vector(0.1f, 0.1f, 0.08f); // B_CV, E_CV, M_CV
2314  }
2315  // HERE WE FORCE a full B_CV, E_CV, M_CV vertex-custom_vector_param map with default values
2316 
2318  FEVV::vertex_custom_vector_param, *_g, *_pmaps, v_CVPm); // MT add (for later redraw)
2319  }
2320  // TEMP for CUSTOM VECTOR PARAM
2321  // --- vertex_custom_vector_param
2322 
2323  if(m_redraw) // IMPORTANT -> ONLY IF REDRAW via GUI or CODE
2324  {
2325  if(m_UseVertexColor) // else automatic detection, as for a first DRAW
2326  if((!m_space_time) || (m_space_time && m_space_time_changeColorMode))
2327  {
2328  _vt_cm = nullptr;
2329 
2330  if(m_UseVertexColor)
2331  {
2332  if(has_map(*_pmaps, FEVV::vertex_color))
2333  {
2334  v_cm = get_property_map(FEVV::vertex_color, *_g, *_pmaps);
2335  _vt_cm = &v_cm;
2336  }
2337  /*else
2338  {
2339  // -- TODO MT - TEMP - HERE WE FORCE a full RED vertex-color map for the REDRAW
2340  using Vector = typename GeometryTraits::Vector;
2341 
2342  auto iterator_pair = vertices(*_g); // vertices() returns a vertex_iterator pair
2343  vertex_iterator vi = iterator_pair.first;
2344  vertex_iterator vi_end = iterator_pair.second;
2345  for (; vi != vi_end; ++vi)
2346  {
2347  v_cm[*vi] = Vector(1., 0., 0.); // RGB
2348  }
2349 
2350  _vt_cm = &v_cm;
2351  // -- TODO MT - TEMP - HERE WE FORCE a full RED vertex-color map for the REDRAW
2352  }*/
2353  else
2354  {
2355  //_vt_nm = nullptr;
2356  }
2357  }
2358  else
2359  {
2360  //_vt_nm = nullptr;
2361  //_f_nm = nullptr;
2362  }
2363  }
2364  }
2365 
2366  QApplication::setOverrideCursor(Qt::ForbiddenCursor);
2367  SimpleWindow *sw = static_cast< SimpleWindow * >(
2368  getWindow()); // here static_cast instead of dynamic_cast only for OSX and
2369  // because of plugins... don't understand why...
2370  sw->statusBar()->showMessage(
2371  QObject::tr("Create and populate OSG objects...") /*, 2000*/);
2372 
2373  GeometryTraits gt(*_g);
2374 
2375  if(geode == nullptr)
2376  {
2377  geode = new osg::Geode; // MT OSG_GEODE : bug from JL ? Ici geode devrait
2378  // être osg::ref_ptr<osg::Geode> ???
2379  }
2380  else
2381  {
2382  geode->removeDrawables(0, geode->getNumDrawables());
2383  }
2384 
2385  // we must handle one geometry per texture/material
2386  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2387  {
2388  geometries.push_back(new osg::Geometry());
2389  geometries[0]->setSupportsDisplayList(true);
2390  geometries[0]->setUseDisplayList(true);
2391  geometries[0]->setUseVertexBufferObjects(
2392  false); /*geometries[0]->setUseVertexArrayObject(false);*/
2393  }
2394  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2395  {
2396  geometriesL.push_back(new osg::Geometry());
2397  geometriesL[0]->setSupportsDisplayList(true);
2398  geometriesL[0]->setUseDisplayList(true);
2399  geometriesL[0]->setUseVertexBufferObjects(
2400  false); /*geometriesL[0]->setUseVertexArrayObject(false);*/
2401  }
2402  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2403  {
2404  geometriesP.push_back(new osg::Geometry());
2405  geometriesP[0]->setSupportsDisplayList(true);
2406  geometriesP[0]->setUseDisplayList(true);
2407  geometriesP[0]->setUseVertexBufferObjects(
2408  false); /*geometriesP[0]->setUseVertexArrayObject(false);*/
2409  }
2410  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2411  {
2412  geometries_edges.push_back(new osg::Geometry());
2413  geometries_edges[0]->setSupportsDisplayList(true);
2414  geometries_edges[0]->setUseDisplayList(true);
2415  geometries_edges[0]->setUseVertexBufferObjects(
2416  false); /*geometries_edges[0]->setUseVertexArrayObject(false);*/
2417  }
2418  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2419  {
2420  geometries_vertices.push_back(new osg::Geometry());
2421  geometries_vertices[0]->setSupportsDisplayList(true);
2422  geometries_vertices[0]->setUseDisplayList(true);
2423  geometries_vertices[0]->setUseVertexBufferObjects(
2424  false); /*geometries_vertices[0]->setUseVertexArrayObject(false);*/
2425  }
2426  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2427  {
2428  geometries_normals.push_back(new osg::Geometry());
2429  geometries_normals[0]->setSupportsDisplayList(true);
2430  geometries_normals[0]->setUseDisplayList(true);
2431  geometries_normals[0]->setUseVertexBufferObjects(
2432  false); /*geometries_normals[0]->setUseVertexArrayObject(false);*/
2433  }
2434  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2435  {
2436  geometries_custom_vectors.push_back(new osg::Geometry());
2437  geometries_custom_vectors[0]->setSupportsDisplayList(true);
2438  geometries_custom_vectors[0]->setUseDisplayList(true);
2439  geometries_custom_vectors[0]->setUseVertexBufferObjects(
2440  false); /*geometries_custom_vectors[0]->setUseVertexArrayObject(false);*/
2441  }
2442  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2443  {
2444  vertexArrays.push_back(new osg::Vec3Array);
2445  }
2446  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2447  {
2448  vertexArrays_edges.push_back(new osg::Vec3Array);
2449  }
2450  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2451  {
2452  vertexArrays_vertices.push_back(new osg::Vec3Array);
2453  }
2454  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2455  {
2456  vertexArrays_normals.push_back(new osg::Vec3Array);
2457  }
2458  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2459  {
2460  vertexArrays_custom_vectors.push_back(new osg::Vec3Array);
2461  }
2462  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2463  {
2464  normalsArrays.push_back(new osg::Vec3Array);
2465  }
2466  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2467  {
2468  normalsArraysF.push_back(new osg::Vec3Array);
2469  }
2470  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2471  {
2472  normalsArrays_edges.push_back(new osg::Vec3Array);
2473  }
2474  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2475  {
2476  normalsArrays_vertices.push_back(new osg::Vec3Array);
2477  }
2478  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2479  {
2480  tangentsArrays.push_back(new osg::Vec3Array);
2481  }
2482  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2483  {
2484  colorsArrays.push_back(new osg::Vec4Array);
2485  }
2486  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2487  {
2488  colorsArrays_edges.push_back(new osg::Vec4Array);
2489  }
2490  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2491  {
2492  colorsArrays_vertices.push_back(new osg::Vec4Array);
2493  }
2494  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2495  {
2496  colorsArrays_normals.push_back(new osg::Vec4Array);
2497  }
2498  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2499  {
2500  colorsArrays_custom_vectors.push_back(new osg::Vec4Array);
2501  }
2502  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw))
2503  {
2504  texcoordsArrays.push_back(new osg::Vec2Array);
2505  }
2506  // std::cout << "---------> geometries.push_back" << std::endl;
2507  size_t mtl_id = 0;
2508 
2509  //unsigned int sizeVertex = 0;
2510  unsigned int sizeSPoints = 0;
2511 
2512  Point p0;
2513  vertex_descriptor vd0;
2514 
2516  if((!m_redraw) || (m_redraw && m_recreateOSGobj_if_redraw)) // NEW
2517  {
2518  const float MAGNITUDE_N = 0.08;
2519  // std::cout << "---------> Adding vertices (for superimpose and 'only_pts'
2520  // mode)" << std::endl;
2521 
2522  VertexColorMap *SAVE_vt_cm = _vt_cm;
2523 
2524  if(has_map(*_pmaps, FEVV::vertex_color))
2525  {
2526  v_cm = get_property_map(FEVV::vertex_color, *_g, *_pmaps);
2527  _vt_cm = &v_cm;
2528  }
2529 
2530  // ---
2531 
2532  for(vertex_iterator v_it = vertices(*_g).first;
2533  v_it != vertices(*_g).second;
2534  ++v_it)
2535  {
2536  // retrieve vertex
2537  vd0 = *v_it;
2538 
2539  // retrieve vertex-point
2540  p0 = (*_pm)[vd0];
2541  vertexArrays_vertices[mtl_id]->push_back(
2542  Helpers::VectorConverter< PointCloud >(
2543  Vector(GeometryTraits::get_x(p0),
2544  GeometryTraits::get_y(p0),
2545  GeometryTraits::get_z(p0))));
2546  // [ normals
2547  if(_vt_nm)
2548  {
2549  vertexArrays_normals[mtl_id]->push_back( Helpers::VectorConverter< PointCloud >(p0) );
2550  vertexArrays_normals[mtl_id]->push_back( Helpers::VectorConverter< PointCloud >(p0) + Helpers::VectorConverter< PointCloud >(get(v_nm, *v_it)) * 0.5 * MAGNITUDE_N );
2551  }
2552  // ] normals
2553 
2554  // [ custom_vectors
2555  if(_vt_CVm)
2556  {
2557  float MAGNITUDE_CV = 0.08;
2558  float B_CV = 0.;
2559  float E_CV = 1.;
2560 
2561  if(_vt_CVPm)
2562  {
2563  using Vector = typename GeometryTraits::Vector;
2564  Vector _vector = get(v_CVPm, *v_it);
2565 
2566  B_CV = _vector[0];
2567  E_CV = _vector[1];
2568  MAGNITUDE_CV = _vector[2];
2569  }
2570 
2571  vertexArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorConverter< PointCloud >(p0) - Helpers::VectorConverter< PointCloud >(get(v_CVm, *v_it)) * B_CV * MAGNITUDE_CV );
2572  vertexArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorConverter< PointCloud >(p0) + Helpers::VectorConverter< PointCloud >(get(v_CVm, *v_it)) * E_CV * MAGNITUDE_CV );
2573  }
2574  // ] custom_vectors
2575 
2576  sizeSPoints++;
2577 
2578  // color
2579  if(_vt_cm)
2580  {
2581  auto color_uint8 = get(v_cm, *v_it);
2582  osg::Vec4 colorf((float)(color_uint8[0]/255.0f),
2583  (float)(color_uint8[1]/255.0f),
2584  (float)(color_uint8[2]/255.0f),
2585  1.0f);
2586  colorsArrays_vertices[mtl_id]->push_back(colorf);
2587  }
2588  else
2589  {
2590  colorsArrays_vertices[mtl_id]->push_back(
2591  Helpers::ColorConverter(Color::Green())); // default color
2592  }
2593 
2594  // normal (only for GEOMETRY shader)
2595  if(_vt_nm)
2596  normalsArrays_vertices[mtl_id]->push_back(
2597  Helpers::VectorConverter< PointCloud >(
2598  get(v_nm, *v_it)));
2599 
2600  // [ normals
2601  colorsArrays_normals[mtl_id]->push_back(Helpers::ColorConverter(Color::Red()));
2602  colorsArrays_normals[mtl_id]->push_back(Helpers::ColorConverter(Color::Red()));
2603  // ] normals
2604 
2605  // [ custom_vectors
2606  if(_vt_CVCm)
2607  {
2608  colorsArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorColorConverter< PointCloud >(get(v_CVCm, *v_it)) );
2609  colorsArrays_custom_vectors[mtl_id]->push_back( Helpers::VectorColorConverter< PointCloud >(get(v_CVCm, *v_it)) );
2610  }
2611  else // white by default
2612  {
2613  colorsArrays_custom_vectors[mtl_id]->push_back(Helpers::ColorConverter(Color::White()));
2614  colorsArrays_custom_vectors[mtl_id]->push_back(Helpers::ColorConverter(Color::White()));
2615  }
2616  // ] custom_vectors
2617  }
2618 
2619  geometries_vertices[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
2620  osg::PrimitiveSet::POINTS, 0, vertexArrays_vertices[mtl_id]->size()));
2621 
2622  // [ normals
2623  geometries_normals[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
2624  osg::PrimitiveSet::LINES, 0, vertexArrays_normals[mtl_id]->size()));
2625  // ] normals
2626 
2627  // [ custom_vectors
2628  geometries_custom_vectors[mtl_id]->addPrimitiveSet(new osg::DrawArrays(
2629  osg::PrimitiveSet::LINES, 0, vertexArrays_custom_vectors[mtl_id]->size()));
2630  // ] custom_vectors
2631 
2632  _vt_cm = SAVE_vt_cm;
2633 
2634  std::cout << "[SimpleViewer] I have drawn " << sizeSPoints << " points." << std::endl;
2635  }
2636 
2637  // NEW_HERE-01 (ADD)
2638  geometries_vertices[mtl_id]->setStateSet(NULL);
2639  {
2640  // set point size
2641  osg::ref_ptr< osg::Point > pt = new osg::Point();
2642  if(m_RenderSuperimposedVertices_Big)
2643  pt->setSize(5.0f);
2644  else if(m_RenderSuperimposedVertices)
2645  pt->setSize(3.0f);
2646  else
2647  pt->setSize(1.0f);
2648  geometries_vertices[mtl_id]->getOrCreateStateSet()->setAttribute(
2649  pt, osg::StateAttribute::ON);
2650 
2651  // light
2652  geometries_vertices[mtl_id]->getOrCreateStateSet()->setMode(
2653  GL_LIGHTING, osg::StateAttribute::OFF); // light always OFF for
2654  // superimpose vertices
2655  }
2656 
2657  // [ normals
2658  geometries_normals[mtl_id]->setStateSet(NULL);
2659  {
2660  // set line width
2661  osg::ref_ptr< osg::LineWidth > linewidth = new osg::LineWidth();
2662  linewidth->setWidth(1.5f);
2663  geometries_normals[mtl_id]
2664  ->getOrCreateStateSet()
2665  ->setAttribute(linewidth, osg::StateAttribute::ON); // setAttributeAndModes (other function)
2666 
2667  // light
2668  geometries_normals[mtl_id]->getOrCreateStateSet()->setMode(
2669  GL_LIGHTING,
2670  osg::StateAttribute::OFF); // light always OFF for normals
2671  }
2672  // ] normals
2673 
2674  // [ custom_vectors
2675  geometries_custom_vectors[mtl_id]->setStateSet(NULL);
2676  {
2677  // set line width
2678  osg::ref_ptr< osg::LineWidth > linewidth = new osg::LineWidth();
2679  linewidth->setWidth(1.5f);
2680  geometries_custom_vectors[mtl_id]
2681  ->getOrCreateStateSet()
2682  ->setAttribute(linewidth, osg::StateAttribute::ON); // setAttributeAndModes (other function)
2683 
2684  // light
2685  geometries_custom_vectors[mtl_id]->getOrCreateStateSet()->setMode(
2686  GL_LIGHTING,
2687  osg::StateAttribute::OFF); // light always OFF for custom_vectors
2688  }
2689  // ] custom_vectors
2690 
2691  sw->statusBar()->showMessage(QObject::tr("") /*, 2000*/);
2692  QApplication::restoreOverrideCursor();
2693 
2694  const auto loadingStartTime = std::chrono::system_clock::now();
2695 
2696  QApplication::setOverrideCursor(Qt::BusyCursor);
2697  sw->statusBar()->showMessage(QObject::tr("Render mesh...") /*, 2000*/);
2698 
2699  // NEW_HERE-02 (ADD)
2700  std::vector< osg::ref_ptr< osg::Vec3Array > > *_normalsArrays = nullptr;
2701  if(m_SmoothFlat_Shading)
2702  _normalsArrays = &normalsArrays;
2703  else
2704  _normalsArrays = &normalsArraysF;
2705 
2706  // NEW_HERE-03 (ADD)
2707  std::vector< osg::ref_ptr< osg::Geometry > > *_geometries = nullptr;
2708  _geometries = &geometriesP; // RenderMethod::RENDER_POINTS
2709 
2710  if(m_RenderMode == RenderMode::RENDER_SHADERS_DIRECT_LIGHTING ||
2712  {
2713  using VertexTangentMap =
2715  PointCloud >::pmap_type;
2716  using FaceColorMap =
2718  PointCloud >::pmap_type;
2719  using VertexUVMap =
2721  PointCloud >::pmap_type;
2722  using HalfedgeUVMap =
2724  PointCloud >::pmap_type;
2725  using MeshMaterialsMap =
2727  PointCloud >::pmap_type;
2728 
2729  VertexTangentMap *v_tan_m = nullptr;
2730  FaceColorMap *_f_cm = nullptr;
2731  VertexUVMap *_vt_uv_m = nullptr;
2732  HalfedgeUVMap *_het_uv_m = nullptr;
2733  MeshMaterialsMap *_m_mm = nullptr;
2734 
2735  internal_loadShadedMesh(geode,
2736  _g,
2737  *_geometries,
2738  geometries_edges,
2739  geometries_vertices,
2740  geometries_normals,
2741  geometries_custom_vectors,
2742  vertexArrays,
2743  vertexArrays_edges,
2744  vertexArrays_vertices,
2745  vertexArrays_normals,
2746  vertexArrays_custom_vectors,
2747  *_normalsArrays,
2748  normalsArrays_edges,
2749  normalsArrays_vertices,
2750  tangentsArrays,
2751  texcoordsArrays,
2752  colorsArrays,
2753  colorsArrays_edges,
2754  colorsArrays_vertices,
2755  colorsArrays_normals,
2756  colorsArrays_custom_vectors,
2757  _m_mm_size,
2758  _vt_nm,
2759  v_tan_m,
2760  _vt_cm,
2761  _f_cm,
2762  _vt_uv_m,
2763  _het_uv_m,
2764  _m_mm,
2765  has_map(*_pmaps, FEVV::face_color));
2766 
2768  {
2769  std::cout << "[SimpleViewer] Rendering with indirect lighting."
2770  << std::endl;
2771  // RM: sends uniform as true if we set the mode to indirect lighting
2772  geode->getOrCreateStateSet()->addUniform(
2773  new osg::Uniform("uniUseIndirectLighting", true));
2774  }
2775  else
2776  {
2777  std::cout << "[SimpleViewer] Rendering with direct lighting."
2778  << std::endl;
2779  }
2780  }
2781  else
2782  {
2783  using FaceColorMap =
2785  PointCloud >::pmap_type;
2786  using VertexUVMap =
2788  PointCloud >::pmap_type;
2789  using HalfedgeUVMap =
2791  PointCloud >::pmap_type;
2792  using MeshMaterialsMap =
2794  PointCloud >::pmap_type;
2795 
2796  FaceColorMap *_f_cm = nullptr;
2797  VertexUVMap *_vt_uv_m = nullptr;
2798  HalfedgeUVMap *_het_uv_m = nullptr;
2799  MeshMaterialsMap *_m_mm = nullptr;
2800  int _texture_type = NO_TEXCOORDS;
2801 
2802  internal_loadLegacyMesh(geode,
2803  _g,
2804  *_geometries,
2805  geometries_edges,
2806  geometries_vertices,
2807  geometries_normals,
2808  geometries_custom_vectors,
2809  vertexArrays,
2810  vertexArrays_edges,
2811  vertexArrays_vertices,
2812  vertexArrays_normals,
2813  vertexArrays_custom_vectors,
2814  *_normalsArrays,
2815  normalsArrays_edges,
2816  normalsArrays_vertices,
2817  texcoordsArrays,
2818  colorsArrays,
2819  colorsArrays_edges,
2820  colorsArrays_vertices,
2821  colorsArrays_normals,
2822  colorsArrays_custom_vectors,
2823  _m_mm_size,
2824  _texture_type,
2825  _vt_nm,
2826  _vt_cm,
2827  _f_cm,
2828  _vt_uv_m,
2829  _het_uv_m,
2830  _m_mm,
2831  has_map(*_pmaps, FEVV::face_color));
2832  }
2833 
2834  sw->statusBar()->showMessage(QObject::tr("") /*, 2000*/);
2835  QApplication::restoreOverrideCursor();
2836 
2837  std::cout << "[SimpleViewer] Done 'loading' mesh (in graphic card) in "
2838  << std::chrono::duration_cast< std::chrono::duration< float > >(
2839  std::chrono::system_clock::now() - loadingStartTime)
2840  .count()
2841  << " seconds." << std::endl;
2842 
2843  gizmo->setNodeMask(m_ShowAxis ? 0xffffffff : 0x0);
2844  grid->setNodeMask(m_ShowGrid ? 0xffffffff : 0x0);
2845 
2846  BaseViewer *bv = dynamic_cast< BaseViewer * >(this);
2847  BaseAdapterVisuQt *bavQt =
2848  dynamic_cast< BaseAdapterVisuQt * >(bv->getAdapter());
2849  // geode->setName( std::string("Mesh ") +
2850  // std::to_string(Helpers::nbMeshDrawed++) + std::string(" [") +
2851  // bavQt->windowTitle().toStdString() + std::string("]") );
2852 
2853  std::string ds_name = FEVV::getDatastructureName(_g);
2854  geode->setName(_mesh_file + std::string(" [") + ds_name + " " +
2855  bavQt->windowTitle().left(bavQt->windowTitle().indexOf('>') + 1).toStdString() + std::string("]"));
2856  geode->addDescription("MESH");
2857 }
2858 
2859 
2860 // osgManipulator
2861 class ScaleConstraint : public osgManipulator::Constraint
2862 {
2863 public:
2865 
2866  virtual bool constrain(osgManipulator::Scale1DCommand &command) const
2867  {
2868  command.setScale(1.0f);
2869  // OSG_NOTICE << "ScaleConstraint Scale1DCommand" << command.getScale() <<
2870  // std::endl;
2871  return true;
2872  }
2873  virtual bool constrain(osgManipulator::Scale2DCommand &command) const
2874  {
2875  command.setScale(osg::Vec2d(1.0, 1.0));
2876  // OSG_NOTICE << "ScaleConstraint Scale2DCommand " << command.getScale() <<
2877  // std::endl;
2878  return true;
2879  }
2880 };
2881 
2882 
2883 inline
2884 osgManipulator::Dragger *
2885 createDragger(const std::string &name)
2886 {
2887  osgManipulator::Dragger *dragger = 0;
2888 
2889  if(name == "TrackballDragger")
2890  {
2891  osgManipulator::TrackballDragger *d =
2892  new osgManipulator::TrackballDragger();
2893  d->setupDefaultGeometry();
2894 #if OSG_MIN_VERSION_REQUIRED(3, 4, 0)
2895  d->setAxisLineWidth(2.0f); // commented by default
2896  // d->setPickCylinderHeight(0.1f);
2897 #endif
2898  dragger = d;
2899  }
2900  else // TabBoxDragger (by default)
2901  {
2902  osgManipulator::TabBoxDragger *d = new osgManipulator::TabBoxDragger();
2903  // osgManipulator::TabBoxDragger2* d = new osgManipulator::TabBoxDragger2();
2904  d->setupDefaultGeometry();
2905  d->setPlaneColor(osg::Vec4(1.0f, 1.0f, 0.0f, 1.0f)); // yellow
2906  d->addConstraint(new ScaleConstraint());
2907  dragger = d;
2908  }
2909 
2910  dragger->setName(name);
2911 
2912  return dragger;
2913 }
2914 
2915 
2916 inline
2917 osg::Node *
2919  osg::Node *scene,
2920  const std::string &nameDrag1,
2921  float fScaleDrag1,
2922  char keyDrag1,
2923  const std::string &nameDrag2,
2924  float fScaleDrag2,
2925  char keyDrag2)
2926 {
2927  // scene->getOrCreateStateSet()->setMode(GL_NORMALIZE,
2928  // osg::StateAttribute::ON); // necessary ? // this ensures correct lighting
2929  // for scaled draggers
2930 
2931 
2932  // osg::Group "GroupRoot"
2933  // |
2934  // |__ osg::MatrixTransform "MatrixTransform"
2935  // | |
2936  // | |__ osg::Group "DraggerGrp2_rotate"
2937  // | |
2938  // | |__ osgManipulator::TrackballDragger "TrackballDragger"
2939  // |
2940  // |__ osg::Group "DraggerGrp1_translate"
2941  // |
2942  // |__ osgManipulator::TabBoxDragger "TabBoxDragger"
2943 
2944 
2945  osg::MatrixTransform *transform = new osg::MatrixTransform;
2946  transform->setName("MatrixTransform");
2947  transform->addChild(scene);
2948 
2949  osg::Group *root = new osg::Group;
2950  root->setName("GroupRoot");
2951  root->addChild(transform);
2952 
2953  float scale;
2954 
2955  osgManipulator::Dragger *dragger1 = createDragger(nameDrag1);
2956  // here, we create a group only for the DataVisitor
2957  osg::Group *draggergroup1 = new osg::Group;
2958  draggergroup1->setName("DraggerGrp1_translate");
2959  draggergroup1->addChild(dragger1);
2960  root->addChild(draggergroup1);
2961  scale = scene->getBound().radius() * fScaleDrag1;
2962  dragger1->setMatrix(osg::Matrix::scale(scale, scale, scale) *
2963  osg::Matrix::translate(scene->getBound().center()));
2964  dragger1->addTransformUpdating(transform);
2965  dragger1->setHandleEvents(true);
2966  dragger1->setActivationKeyEvent(keyDrag1);
2967  // dragger1->setDraggerActive(false); // not working ?
2968  dragger1->setNodeMask(m_ShowTranslateDragger ? 0xffffffff : 0x0);
2969  v_draggers1.push_back(dragger1);
2970 
2971  osgManipulator::Dragger *dragger2 = createDragger(nameDrag2);
2972  // here, we create a group only for the DataVisitor
2973  osg::Group *draggergroup2 = new osg::Group;
2974  draggergroup2->setName("DraggerGrp2_rotate");
2975  draggergroup2->addChild(dragger2);
2976  transform->addChild(
2977  draggergroup2); // IMPORTANT for the SECOND dragger -> NOT addChild from
2978  // 'root' here BUT from 'transform' !!!
2979  scale = scene->getBound().radius() * fScaleDrag2;
2980  dragger2->setMatrix(osg::Matrix::scale(scale, scale, scale) *
2981  osg::Matrix::translate(scene->getBound().center()));
2982  dragger2->addTransformUpdating(transform);
2983  dragger2->setHandleEvents(true);
2984  dragger2->setActivationKeyEvent(keyDrag2);
2985  // dragger2->setDraggerActive(false); // not working ?
2986  dragger2->setNodeMask(m_ShowRotateDragger ? 0xffffffff : 0x0);
2987  v_draggers2.push_back(dragger2);
2988 
2989  return root;
2990 }
2991 // osgManipulator
2992 
2993 
2994 template< typename HalfedgeGraph, typename PointMap >
2995 osg::ref_ptr< osg::Group >
2997  HalfedgeGraph *_g,
2998  PMapsContainer *_pmaps,
2999  PointMap *_pm,
3000  std::string _mesh_file,
3001  osg::ref_ptr< osg::Group > _group)
3002 {
3003  std::vector< osg::ref_ptr< osg::Geometry > > l_geometries, l_geometriesL,
3004  l_geometriesP, l_geometries_edges, l_geometries_vertices, l_geometries_normals, l_geometries_custom_vectors;
3005  std::vector< osg::ref_ptr< osg::Vec3Array > > l_vertexArrays,
3006  l_vertexArrays_edges, l_vertexArrays_vertices, l_vertexArrays_normals, l_vertexArrays_custom_vectors;
3007  std::vector< osg::ref_ptr< osg::Vec3Array > > l_normalsArrays,
3008  l_normalsArraysF, l_normalsArrays_edges, l_normalsArrays_vertices, l_tangentsArrays;
3009  std::vector< osg::ref_ptr< osg::Vec4Array > > l_colorsArrays,
3010  l_colorsArrays_edges, l_colorsArrays_vertices, l_colorsArrays_normals, l_colorsArrays_custom_vectors;
3011  std::vector< osg::ref_ptr< osg::Vec2Array > > l_texcoordsArrays;
3012 
3013  osg::Geode *geode = internal_createMesh(_g,
3014  _pmaps,
3015  l_geometries,
3016  l_geometriesL,
3017  l_geometriesP,
3018  l_geometries_edges,
3019  l_geometries_vertices,
3020  l_geometries_normals,
3021  l_geometries_custom_vectors,
3022  l_vertexArrays,
3023  l_vertexArrays_edges,
3024  l_vertexArrays_vertices,
3025  l_vertexArrays_normals,
3026  l_vertexArrays_custom_vectors,
3027  l_normalsArrays,
3028  l_normalsArraysF,
3029  l_normalsArrays_edges,
3030  l_normalsArrays_vertices,
3031  l_tangentsArrays,
3032  l_colorsArrays,
3033  l_colorsArrays_edges,
3034  l_colorsArrays_vertices,
3035  l_colorsArrays_normals,
3036  l_colorsArrays_custom_vectors,
3037  l_texcoordsArrays,
3038  _pm,
3039  _mesh_file);
3040 
3041 #ifdef MANIPULATOR
3042  _group->addChild(addDraggersToScene(
3043  geode, "TabBoxDragger", 2.0, 't', "TrackballDragger", 1.0, 'r'));
3044 #else
3045  _group->addChild(geode); //_group->setName("_group");
3046 #endif
3047 
3048  v_geometries.push_back(l_geometries);
3049  v_geometriesL.push_back(l_geometriesL);
3050  v_geometriesP.push_back(l_geometriesP);
3051  v_geometries_edges.push_back(l_geometries_edges);
3052  v_geometries_vertices.push_back(l_geometries_vertices);
3053  v_geometries_normals.push_back(l_geometries_normals);
3054  v_geometries_custom_vectors.push_back(l_geometries_custom_vectors);
3055  v_vertexArrays.push_back(l_vertexArrays);
3056  v_vertexArrays_edges.push_back(l_vertexArrays_edges);
3057  v_vertexArrays_vertices.push_back(l_vertexArrays_vertices);
3058  v_vertexArrays_normals.push_back(l_vertexArrays_normals);
3059  v_vertexArrays_custom_vectors.push_back(l_vertexArrays_custom_vectors);
3060  v_normalsArrays.push_back(l_normalsArrays);
3061  v_normalsArraysF.push_back(l_normalsArraysF);
3062  v_normalsArrays_edges.push_back(l_normalsArrays_edges);
3063  v_normalsArrays_vertices.push_back(l_normalsArrays_vertices);
3064  v_tangentsArrays.push_back(l_tangentsArrays);
3065  v_colorsArrays.push_back(l_colorsArrays);
3066  v_colorsArrays_edges.push_back(l_colorsArrays_edges);
3067  v_colorsArrays_vertices.push_back(l_colorsArrays_vertices);
3068  v_colorsArrays_normals.push_back(l_colorsArrays_normals);
3069  v_colorsArrays_custom_vectors.push_back(l_colorsArrays_custom_vectors);
3070  v_texcoordsArrays.push_back(l_texcoordsArrays);
3071 
3072  v_mixed_meshes.push_back(_g);
3073  v_meshes_names.push_back(_mesh_file);
3074  v_properties_maps.push_back(_pmaps);
3075  v_geodes.push_back(geode);
3076  v_meshIsSelected.push_back(false);
3077 
3078  // select newly created mesh
3079  setNodeSelected(geode, true);
3080 
3081  // time
3082  i_time++;
3083 
3084  /*if (m_space_time)
3085  {
3086  if (m_time)
3087  {
3088  current_i_time = i_time;
3089 
3090  //setNodeSelected(v_geodes[current_i_time], true); // UTILE ?
3091  }
3092  }*/
3093  // time
3094 
3095  return _group;
3096 }
3097 
3098 template< typename HalfedgeGraph, typename PointMap >
3099 void
3101  PMapsContainer *_pmaps,
3102  PointMap *_pm,
3103  std::string _mesh_file)
3104 {
3105  QApplication::setOverrideCursor(Qt::BusyCursor);
3106  SimpleWindow *sw = static_cast< SimpleWindow * >(
3107  getWindow()); // here static_cast instead of dynamic_cast ONLY to be
3108  // consistent with 2 others for statusBar() (only for OSX
3109  // and because of plugins... don't understand why...)
3110  sw->statusBar()->showMessage(
3111  QObject::tr("Draw : calculate normals & tangents...") /*, 2000*/);
3112 
3113  // ---
3114  m_redraw = false;
3115  m_recomputeNT_if_redraw = false;
3116  m_recreateOSGobj_if_redraw = true;
3117  // ---
3118 
3119  addGroup(createMesh(_g, _pmaps, _pm, _mesh_file));
3120 
3121  sw->statusBar()->showMessage(QObject::tr("") /*, 2000*/);
3122  QApplication::restoreOverrideCursor();
3123 }
3124 
3125 template< typename HalfedgeGraph, typename PointMap >
3126 void
3128  PMapsContainer *_pmaps,
3129  PointMap *_pm,
3130  std::string _mesh_file)
3131 {
3132  QApplication::setOverrideCursor(Qt::BusyCursor);
3133  SimpleWindow *sw = static_cast< SimpleWindow * >(
3134  getWindow()); // here static_cast instead of dynamic_cast only for OSX and
3135  // because of plugins... don't understand why...
3136  if(m_recomputeNT_if_redraw)
3137  sw->statusBar()->showMessage(
3138  QObject::tr("Redraw : recalculate normals & tangents...") /*, 2000*/);
3139  else
3140  sw->statusBar()->showMessage(QObject::tr(
3141  "Redraw : get already calculated normals & tangents...") /*, 2000*/);
3142 
3143  // std::cout << "redrawMesh redrawMesh redrawMesh" << std::endl;
3144 
3145  // ---
3146  m_redraw = true;
3147  m_step = 0.;
3148  // ---
3149 
3150  int position;
3151  position = getMeshId(static_cast< void * >(_g));
3152 
3153 #ifdef __GNUC__
3154 #pragma GCC diagnostic push
3155 #pragma GCC diagnostic warning "-Wsign-compare"
3156 #endif // __GNUC__
3157  if(! Assert::check(position != -1,
3158  "mesh was not found. Leaving...",
3159  "SimpleViewer::redrawMesh"))
3160  {
3161  return;
3162  }
3163 #ifdef __GNUC__
3164 #pragma GCC diagnostic pop
3165 #endif // __GNUC__
3166 
3167  // update mesh name during redraw if != ""
3168  if(_mesh_file != std::string(""))
3169  v_meshes_names[position] = _mesh_file;
3170 
3171  // MT - IMPORTANT : remove previous MATERIAL
3172  // v_geodes[position]->getOrCreateStateSet()->removeAttribute(osg::StateAttribute::MATERIAL);
3173 
3174  // MT - IMPORTANT and BETTER : reset StateSet
3175  v_geodes[position]->setStateSet(NULL);
3176 
3177  if(m_recreateOSGobj_if_redraw) // mesh
3178  {
3179  v_geometries[position].clear();
3180  v_geometriesL[position].clear();
3181  v_geometriesP[position].clear();
3182  v_vertexArrays[position].clear();
3183  v_colorsArrays[position].clear();
3184 
3185  v_normalsArrays[position].clear();
3186  v_normalsArraysF[position].clear();
3187  v_tangentsArrays[position].clear();
3188 
3189  v_texcoordsArrays[position].clear();
3190  }
3191  if(m_recreateOSGobj_if_redraw) // superimpose and 'only_pts' mode only
3192  {
3193  v_geometries_edges[position].clear();
3194  v_geometries_vertices[position].clear();
3195  v_geometries_normals[position].clear();
3196  v_geometries_custom_vectors[position].clear();
3197  v_vertexArrays_edges[position].clear();
3198  v_vertexArrays_vertices[position].clear();
3199  v_vertexArrays_normals[position].clear();
3200  v_vertexArrays_custom_vectors[position].clear();
3201  v_colorsArrays_edges[position].clear();
3202  v_colorsArrays_vertices[position].clear();
3203  v_colorsArrays_normals[position].clear();
3204  v_colorsArrays_custom_vectors[position].clear();
3205 
3206  v_normalsArrays_edges[position].clear();
3207  v_normalsArrays_vertices[position].clear();
3208  }
3209 
3210  internal_createMesh(v_geodes[position],
3211  _g,
3212  _pmaps,
3213  v_geometries[position],
3214  v_geometriesL[position],
3215  v_geometriesP[position],
3216  v_geometries_edges[position],
3217  v_geometries_vertices[position],
3218  v_geometries_normals[position],
3219  v_geometries_custom_vectors[position],
3220  v_vertexArrays[position],
3221  v_vertexArrays_edges[position],
3222  v_vertexArrays_vertices[position],
3223  v_vertexArrays_normals[position],
3224  v_vertexArrays_custom_vectors[position],
3225  v_normalsArrays[position],
3226  v_normalsArraysF[position],
3227  v_normalsArrays_edges[position],
3228  v_normalsArrays_vertices[position],
3229  v_tangentsArrays[position],
3230  v_colorsArrays[position],
3231  v_colorsArrays_edges[position],
3232  v_colorsArrays_vertices[position],
3233  v_colorsArrays_normals[position],
3234  v_colorsArrays_custom_vectors[position],
3235  v_texcoordsArrays[position],
3236  _pm,
3237  v_meshes_names[position]);
3238 
3239  sw->statusBar()->showMessage(QObject::tr("") /*, 2000*/);
3240  QApplication::restoreOverrideCursor();
3241 }
3242 
3243 template< typename HalfedgeGraph >
3244 void
3246 {
3247  int position;
3248  position = getMeshId(static_cast< void * >(_g));
3249 
3250 #ifdef __GNUC__
3251 #pragma GCC diagnostic push
3252 #pragma GCC diagnostic warning "-Wsign-compare"
3253 #endif // __GNUC__
3254  if(! Assert::check(position != -1,
3255  "mesh was not found. Leaving...",
3256  "SimpleViewer::centerMesh"))
3257  {
3258  return;
3259  }
3260 #ifdef __GNUC__
3261 #pragma GCC diagnostic pop
3262 #endif // __GNUC__
3263 
3264  // ---
3265 
3266  // std::cout << "getNumViews() : " << getNumViews() << std::endl;
3267  // osgViewer::View* _osgView = getView(0); // for osgViewer::CompositeViewer
3268  osgViewer::View *_osgView =
3269  dynamic_cast< osgViewer::View * >(this); // for osgViewer::Viewer
3270  // osgViewer::View* _osgView = getViewWithFocus();
3271 
3272 #if(FEVV_USE_QT5) // FOR_QT6
3273  BaseViewer *bv = dynamic_cast< BaseViewer * >(this);
3274  SimpleAdapterVisu *sav =
3275  dynamic_cast< SimpleAdapterVisu * >(bv->getAdapter());
3276 
3277  //_osgView = sav->my_osgQOpenGLWidget->getOsgViewer();
3278  _osgView = sav->my_osgQOpenGLWindow->getOsgViewer();
3279 #endif
3280 
3281  if(_osgView)
3282  {
3283 #ifdef MANIPULATOR
3284  _osgView->getCameraManipulator()->setNode(v_geodes[position]->getParent(0));
3285 
3286 
3287  // ELO-note: v_geodes[position]->getParent(0) is an osg::MatrixTransform
3288  // which is a group with an osg::Matrix
3289  // see
3290  // http://camlosg.sourceforge.net/osg/classosg_1_1MatrixTransform.html
3291 
3292 
3293  // std::cout << "centerMesh (MANIPULATOR) \"" <<
3294  // v_geodes[position]/*->getParent(0)*/->getName() << "\"" << std::endl;
3295 #else
3296  _osgView->getCameraManipulator()->setNode(v_geodes[position]);
3297  // std::cout << "centerMesh \"" << v_geodes[position]->getName() << "\"" <<
3298  // std::endl;
3299 #endif
3300  _osgView->getCameraManipulator()->computeHomePosition();
3301  _osgView->home();
3302 
3303 
3304  // FEVV::Debug::print_osg_tree_from_node(v_geodes[position]->getParent(0)->getParent(0));
3305  }
3306 }
3307 
3308 inline
3309 osg::Matrix
3311 {
3312  osg::Matrix matrix;
3313 
3314  // std::cout << "getNumViews() : " << getNumViews() << std::endl;
3315  // osgViewer::View* _osgView = getView(0); // for osgViewer::CompositeViewer
3316  osgViewer::View *_osgView =
3317  dynamic_cast< osgViewer::View * >(this); // for osgViewer::Viewer
3318  // osgViewer::View* _osgView = getViewWithFocus();
3319 
3320 #if(FEVV_USE_QT5) // FOR_QT6
3321  BaseViewer *bv = dynamic_cast< BaseViewer * >(this);
3322  SimpleAdapterVisu *sav =
3323  dynamic_cast< SimpleAdapterVisu * >(bv->getAdapter());
3324 
3325  //_osgView = sav->my_osgQOpenGLWidget->getOsgViewer();
3326  _osgView = sav->my_osgQOpenGLWindow->getOsgViewer();
3327 #endif
3328 
3329  if(_osgView)
3330  {
3331  matrix = _osgView->getCameraManipulator()->getMatrix();
3332  }
3333 
3334  return matrix;
3335 }
3336 
3337 inline
3338 void
3340 {
3341  // std::cout << "getNumViews() : " << getNumViews() << std::endl;
3342  // osgViewer::View* _osgView = getView(0); // for osgViewer::CompositeViewer
3343  osgViewer::View *_osgView =
3344  dynamic_cast< osgViewer::View * >(this); // for osgViewer::Viewer
3345  // osgViewer::View* _osgView = getViewWithFocus();
3346 
3347 #if(FEVV_USE_QT5) // FOR_QT6
3348  BaseViewer *bv = dynamic_cast< BaseViewer * >(this);
3349  SimpleAdapterVisu *sav =
3350  dynamic_cast< SimpleAdapterVisu * >(bv->getAdapter());
3351 
3352  //_osgView = sav->my_osgQOpenGLWidget->getOsgViewer();
3353  _osgView = sav->my_osgQOpenGLWindow->getOsgViewer();
3354 #endif
3355 
3356  if(_osgView)
3357  {
3358  _osgView->getCameraManipulator()->setByMatrix(matrix);
3359  }
3360 }
3361 
3362 inline
3363 osg::Matrix
3365  unsigned int position)
3366 {
3367  assert(position < v_geodes.size());
3368  osg::MatrixTransform *grp_MatrixTransform =
3369  dynamic_cast< osg::MatrixTransform * >(v_geodes[position]->getParent(0));
3370  assert(grp_MatrixTransform != nullptr);
3371  osg::Matrix matrix = grp_MatrixTransform->getMatrix();
3372 
3373  return matrix; // 4x4 homogeneous matrix
3374 }
3375 
3376 
3377 inline
3378 Eigen::Matrix4d
3380  unsigned int position)
3381 {
3382  osg::Matrix osg_mat = getTransformMatrixOsg(position);
3383 
3384  // convert OSG transform matrix to Eigen matrix
3385  // transposition needed!
3386  Eigen::Matrix4d eigen_mat;
3387  eigen_mat << osg_mat(0, 0), osg_mat(1, 0), osg_mat(2, 0), osg_mat(3, 0),
3388  osg_mat(0, 1), osg_mat(1, 1), osg_mat(2, 1), osg_mat(3, 1), osg_mat(0, 2),
3389  osg_mat(1, 2), osg_mat(2, 2), osg_mat(3, 2), osg_mat(0, 3), osg_mat(1, 3),
3390  osg_mat(2, 3), osg_mat(3, 3);
3391 
3392  // std::cout << "eigen_mat = \n" << eigen_mat << std::endl;
3393 
3394  return eigen_mat; // 4x4 homogeneous matrix
3395 }
3396 
3397 
3398 inline
3399 void
3401 {
3402  assert(position < v_geodes.size());
3403  osg::MatrixTransform *grp_MatrixTransform =
3404  dynamic_cast< osg::MatrixTransform * >(v_geodes[position]->getParent(0));
3405  assert(grp_MatrixTransform != nullptr);
3406 
3407  osg::Matrix identity;
3408  identity.makeIdentity();
3409  grp_MatrixTransform->setMatrix(identity);
3410 }
3411 
3412 
3413 template< typename HalfedgeGraph >
3414 void
3416  /*const */ HalfedgeGraph *_g,
3417  /*const */ PMapsContainer *_pmaps,
3418  bool _redraw,
3419  bool _recomputeNT_if_redraw,
3420  std::string _mesh_filename,
3421  bool _recreateOSGobj_if_redraw,
3422  float _step)
3423 {
3424  auto pm = get(boost::vertex_point, *_g);
3425 
3426  if(!_redraw)
3427  {
3428  m_step = _step;
3429 
3430  // draw mesh
3431  drawMesh(_g,
3432  _pmaps,
3433  &pm, /*point map*/
3434  _mesh_filename /*mesh filename*/
3435  );
3436 
3437  centerMesh(_g);
3438  }
3439  else
3440  {
3441  m_recomputeNT_if_redraw = _recomputeNT_if_redraw;
3442  m_recreateOSGobj_if_redraw = _recreateOSGobj_if_redraw;
3443 
3444  // redraw mesh
3445  redrawMesh(_g,
3446  _pmaps,
3447  &pm, /*point map*/
3448  _mesh_filename /*mesh filename*/
3449  );
3450  }
3451 }
3452 
3453 
3454 inline
3455 void
3457 {
3458  SimpleWindow *sw = static_cast< SimpleWindow * >(
3459  getWindow()); // here static_cast instead of dynamic_cast only for OSX and
3460  // because of plugins... don't understand why...
3461 
3462  sw->activate_time_mode();
3463 }
3464 
3465 
3466 inline
3467 void
3469 {
3470  SimpleWindow *sw = static_cast< SimpleWindow * >(
3471  getWindow()); // here static_cast instead of dynamic_cast only for OSX and
3472  // because of plugins... don't understand why...
3473 
3474  sw->activate_space_mode();
3475 }
3476 
3477 
3478 inline
3479 void
3481 {
3482  SimpleWindow *sw = static_cast< SimpleWindow * >(
3483  getWindow()); // here static_cast instead of dynamic_cast only for OSX and
3484  // because of plugins... don't understand why...
3485 
3486  sw->update();
3487 }
3488 
3489 
3490 inline
3491 void
3493  bool _isSelected)
3494 {
3495  osg::Geode *geode = dynamic_cast< osg::Geode * >(_geode);
3496  if(geode != nullptr)
3497  {
3498  unsigned int position = 0;
3499  for(osg::Geode *g : v_geodes)
3500  {
3501  if(g == geode)
3502  {
3503  v_meshIsSelected[position] = _isSelected;
3504 
3505  if(m_space_time)
3506  {
3507  if(_isSelected)
3508  {
3509  current_i_time = position; // IMPORTANT !!!
3510 
3511  if(m_time)
3512  {
3513  for(unsigned i = 0; i < v_geodes.size(); i++)
3514  v_geodes[i]->setNodeMask(0x0);
3515  for(unsigned i = 0; i < v_draggers1.size(); i++)
3516  v_draggers1[i]->setNodeMask(0x0);
3517  for(unsigned i = 0; i < v_draggers2.size(); i++)
3518  v_draggers2[i]->setNodeMask(0x0);
3519 
3520  v_geodes[position]->setNodeMask(0xffffffff);
3521  if(v_draggers1.size())
3522  v_draggers1[position]->setNodeMask(
3523  m_ShowTranslateDragger ? 0xffffffff : 0x0);
3524  if(v_draggers2.size())
3525  v_draggers2[position]->setNodeMask(
3526  m_ShowRotateDragger ? 0xffffffff : 0x0);
3527  }
3528  }
3529  }
3530 
3531  break;
3532  }
3533  ++position;
3534  }
3535  }
3536 
3537 #if 0
3538  osg::ref_ptr< osgFX::Outline > outline = new osgFX::Outline;
3539  if ( _isSelected )
3540  {
3541  outline->setWidth(3);
3542  outline->setColor(Helpers::ColorConverter(Color::Yellow()));
3543  outline->addChild(_geode);
3544  for( auto parent : _geode->getParents() )
3545  {
3546  if( parent == outline )
3547  {
3548  continue;
3549  }
3550  parent->replaceChild( _geode, outline );
3551  }
3552 
3553  return;
3554  }
3555  else
3556  {
3557  for( auto parent : _geode->getParents() )
3558  {
3559  if( parent->isSameKindAs( outline ))
3560  {
3561  for( auto grandpa : parent->getParents() )
3562  {
3563  grandpa->replaceChild( parent, _geode );
3564  }
3565  break;
3566  }
3567  }
3568  }
3569  return;
3570 #endif
3571 
3572 #if 0
3573  //DBG
3574  std::cout << "viewer " << this << " v_meshIsSelected =";
3575  for(bool b: v_meshIsSelected)
3576  std::cout << " " << b;
3577  std::cout << std::endl;
3578 #endif
3579 }
3580 
3581 
3582 inline
3583 bool
3585 {
3586  osg::Geode *geode = dynamic_cast< osg::Geode * >(_geode);
3587  if(geode != nullptr)
3588  {
3589  unsigned int position = 0;
3590  for(osg::Geode *g : v_geodes)
3591  {
3592  if(g == geode)
3593  {
3594  return v_meshIsSelected[position];
3595  }
3596  ++position;
3597  }
3598  }
3599 
3600  return false;
3601 }
3602 
3603 
3604 inline
3605 size_t
3606 FEVV::SimpleViewer::getMeshId(const void *mesh_ptr)
3607 {
3608  {
3609  for(size_t i_pos = 0; i_pos < v_mixed_meshes.size(); i_pos++)
3610  {
3611  if(v_mixed_meshes[i_pos].first == mesh_ptr)
3612  return i_pos;
3613  }
3614 
3615  return -1; // not found
3616  }
3617 }
FEVV::SimpleViewer::activate_time_mode
void activate_time_mode()
Definition: SimpleViewer.inl:3456
FEVV::DataStructures::AIF::vertices
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator > vertices(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the vertices of the mesh.
Definition: Graph_traits_aif.h:172
FEVV::vertex_custom_vector_param
@ vertex_custom_vector_param
Definition: properties.h:61
FEVV::put_property_map
void put_property_map(PropertyT p, const MeshT &, PMapsContainer &pmaps, const typename PMap_traits< PropertyT, MeshT >::pmap_type &pmap)
Definition: properties.h:664
FEVV::face_normal_t
face_normal_t
Definition: properties.h:77
FEVV::Filters::translate
void translate(const HalfedgeGraph &g, PointMap &pm, typename GeometryTraits::Scalar offset_x, typename GeometryTraits::Scalar offset_y, typename GeometryTraits::Scalar offset_z, const GeometryTraits &gt)
Translate a mesh.
Definition: translation.hpp:38
FEVV::SimpleViewer::changeBackgroundColor
bool changeBackgroundColor(const Color &_color) override
Definition: SimpleViewer.inl:285
FEVV::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
FEVV::mesh_materials_t
mesh_materials_t
Definition: properties.h:89
FEVV::RenderMode::RENDER_LEGACY
@ RENDER_LEGACY
OSGDebug.hpp
Vector
AIFMesh::Vector Vector
Definition: Graph_properties_aif.h:22
FEVV::SimpleViewer::addGroup
void addGroup(Group *_group) override
Definition: SimpleViewer.inl:348
FEVV::get_property_map
PMap_traits< PropertyT, MeshT >::pmap_type get_property_map(PropertyT p, const MeshT &, const PMapsContainer &pmaps)
Definition: properties.h:646
FEVV::CGALPointSet
CGAL::Point_set_3< CGALPointSetPoint > CGALPointSet
Definition: DataStructures_cgal_point_set.h:71
FEVV::vertex_texcoord
@ vertex_texcoord
Definition: properties.h:43
FEVV::SimpleViewer::getSelectedMeshes
MixedMeshesVector getSelectedMeshes()
Definition: SimpleViewer.inl:402
FEVV::face_color_t
face_color_t
Definition: properties.h:81
FEVV::mesh_materials
@ mesh_materials
Definition: properties.h:89
FEVV::SimpleViewer::getSelected_properties_maps
std::vector< PMapsContainer * > getSelected_properties_maps()
Definition: SimpleViewer.inl:456
FEVV::BaseViewer::getAdapter
Adapter * getAdapter()
Definition: BaseViewer.h:163
FEVV::Filters::normalize_vector_map_vertices
void normalize_vector_map_vertices(const HalfedgeGraph &g, PropertyMap &prop_map)
Normalize each vector of the vertex property map.
Definition: normalize_vector_map.h:55
FEVV::Filters::calculate_halfedges_tangent
void calculate_halfedges_tangent(const HalfedgeGraph &g, const PointMap &pm, const HalfedgeUVMap &hum, VertexTangentMap &vtm)
Calculate the mesh's tangents from its halfedges.
Definition: calculate_halfedges_tangent.hpp:38
FEVV::MeshLCC
CGAL::Linear_cell_complex_for_combinatorial_map< 2, 3, CGALLCCTraits, CGALItem > MeshLCC
Definition: DataStructures_cgal_linear_cell_complex.h:43
FEVV::BaseViewer
Definition: BaseViewer.h:43
FEVV::SimpleViewer::~SimpleViewer
~SimpleViewer()
Definition: SimpleViewer.inl:56
FEVV::Filters::normalize_vector_map_faces
void normalize_vector_map_faces(const HalfedgeGraph &g, PropertyMap &prop_map)
Normalize each vector of the face property map.
Definition: normalize_vector_map.h:75
tr
double tr(double &n)
Truncate a number to 1/1000 (only if BOOLEAN_OPERATIONS_DEBUG is enable)
Definition: boolops_definitions.hpp:127
FEVV::Color::Yellow
static Color Yellow(void)
Definition: Color.inl:407
FEVV::DataStructures::AIF::edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator > edges(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the edges of the mesh.
Definition: Graph_traits_aif.h:238
FEVV::SimpleViewer::getSelectedMeshesNames
std::vector< std::string > getSelectedMeshesNames()
Definition: SimpleViewer.inl:429
FEVV::edge_color_t
edge_color_t
Definition: properties.h:73
FEVV::has_map
bool has_map(const PMapsContainer &pmaps, const std::string &map_name)
(refer to Property Maps API)
Definition: properties.h:103
ScaleConstraint::constrain
virtual bool constrain(osgManipulator::Scale1DCommand &command) const
Definition: SimpleViewer.inl:2866
FEVV::SimpleAdapterVisu
SimpleAdapterVisu is a specialization of QWidget. This class is the widget added to a QMainWindow,...
Definition: SimpleAdapterVisu.h:51
FEVV::Helpers::changeBackgroundColor
void changeBackgroundColor(QWidget *_widget, const Color &_color)
Definition: QtHelpers.cpp:14
FEVV::SimpleViewer::getSelectedGeodes
std::vector< osg::Geode * > getSelectedGeodes()
Definition: SimpleViewer.inl:375
FEVV::BaseViewerOSG::Model
osg::Geode Model
Definition: BaseViewerOSG.h:51
FEVV::BaseViewerOSG
Definition: BaseViewerOSG.h:47
SimpleWindow.h
ScaleConstraint
Definition: SimpleViewer.inl:2862
FEVV::BaseViewerOSG::DataModelVector
DataVisitor::Output DataModelVector
Definition: BaseViewerOSG.h:50
FEVV::PCLPointCloud
pcl::PointCloud< PCLEnrichedPoint > PCLPointCloud
Definition: DataStructures_pcl_point_cloud.h:28
FEVV::vertex_tangent
@ vertex_tangent
Definition: properties.h:39
calculate_halfedges_tangent.hpp
FEVV::SimpleViewer::SimpleViewer
SimpleViewer()
Definition: SimpleViewer.inl:43
FEVV::SimpleViewer::saveScreenshot
bool saveScreenshot(const std::string &_name) override
Definition: SimpleViewer.inl:312
FEVV::SimpleViewer::createMesh
osg::ref_ptr< osg::Group > createMesh(HalfedgeGraph *_g, PMapsContainer *_pmaps, PointMap *_pm, std::string _mesh_file=std::string(""), osg::ref_ptr< osg::Group > _group=new osg::Group)
Definition: SimpleViewer.inl:2996
FEVV::Geometry_traits< HalfedgeGraph >
FEVV::MixedMeshesVector
Functions to retrieve the name of the datastructure according to the mesh type.
Definition: SimpleViewer.h:138
Point
AIFMesh::Point Point
Definition: Graph_properties_aif.h:21
FEVV::RENDER_LINES
@ RENDER_LINES
Definition: BaseViewer.h:29
FEVV::vertex_custom_vector_color_t
vertex_custom_vector_color_t
Definition: properties.h:57
FEVV::MeshSurface
CGAL::Surface_mesh< CGALPoint > MeshSurface
Definition: DataStructures_cgal_surface_mesh.h:23
FEVV::SimpleViewer::addDraggersToScene
osg::Node * addDraggersToScene(osg::Node *scene, const std::string &nameDrag1, float fScaleDrag1, char keyDrag1, const std::string &nameDrag2, float fScaleDrag2, char keyDrag2)
Definition: SimpleViewer.inl:2918
FEVV::face_material_t
face_material_t
Definition: properties.h:85
FEVV::SimpleViewer::resetTransformMatrix
void resetTransformMatrix(unsigned int position)
Definition: SimpleViewer.inl:3400
FEVV::SimpleViewer::init
void init() override
Definition: SimpleViewer.inl:184
FEVV::SimpleViewer::getDataModel
DataModelVector * getDataModel() override
Definition: SimpleViewer.inl:363
FEVV::DataStructures::AIF::source
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor source(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the source vertex of e.
Definition: Graph_traits_aif.h:387
calculate_face_normals.hpp
FEVV::SimpleViewer::activate_space_mode
void activate_space_mode()
Definition: SimpleViewer.inl:3468
FEVV::SimpleWindow
SimpleWindow is a specialization of QMainWindow. This class the Main Window.
Definition: SimpleWindow.h:80
normalize_vector_map.h
FEVV::PMapsContainer
std::map< std::string, boost::any > PMapsContainer
Definition: properties.h:99
FEVV::SimpleViewer::draw_or_redraw_mesh
void draw_or_redraw_mesh(HalfedgeGraph *_g, PMapsContainer *_pmaps, bool _redraw=false, bool _recomputeNT_if_redraw=false, std::string _mesh_filename=std::string(""), bool _recreateOSGobj_if_redraw=true, float _step=0.)
Definition: SimpleViewer.inl:3415
FEVV::vertex_normal_t
vertex_normal_t
Definition: properties.h:35
FEVV::halfedge_texcoord_t
halfedge_texcoord_t
Definition: properties.h:69
FEVV::SimpleViewer::setNodeSelected
void setNodeSelected(osg::Node *_geode, bool isSelected) override
Definition: SimpleViewer.inl:3492
FEVV::get
FEVV::PCLPointCloudPointMap::value_type get(const FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key)
Specialization of get(point_map, key) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:117
FEVV::vertex_tangent_t
vertex_tangent_t
Definition: properties.h:39
FEVV::SimpleViewer::updateSWModelList
void updateSWModelList()
Definition: SimpleViewer.inl:3480
calculate_vertex_normals.hpp
translation.hpp
FEVV::SimpleViewer
SimpleViewer is a specialization of osgViewer::CompositeViewer. This class is a widget where we are a...
Definition: SimpleViewer.h:180
FEVV::BaseViewerOSG::Group
osg::Group Group
Definition: BaseViewerOSG.h:52
FEVV::SimpleViewer::getDraggers2
std::vector< osg::Group * > getDraggers2()
Definition: SimpleViewer.inl:529
FEVV::SimpleViewer::getMeshes
MixedMeshesVector getMeshes()
Definition: SimpleViewer.inl:421
FEVV::vertex_color_t
vertex_color_t
Definition: properties.h:47
FEVV::SimpleWindow::activate_space_mode
void activate_space_mode()
Definition: SimpleWindow.inl:1461
FEVV::SimpleViewer::getSelectedDraggers2
std::vector< osg::Group * > getSelectedDraggers2()
Definition: SimpleViewer.inl:510
FEVV::DataStructures::AIF::faces
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::face_iterator > faces(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns an iterator range over all faces of the mesh.
Definition: Graph_traits_aif.h:679
FEVV::vertex_custom_vector_color
@ vertex_custom_vector_color
Definition: properties.h:57
FEVV::Color::WetAsphalt
static Color WetAsphalt(void)
Definition: Color.inl:500
FEVV::SimpleViewer::isValid
bool isValid() const override
Definition: SimpleViewer.inl:263
FEVV::DataStructures::AIF::halfedge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor halfedge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor v, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns a halfedge with target v.
Definition: Graph_traits_aif.h:296
FEVV::DataStructures::AIF::target
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_descriptor target(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor e, const FEVV::DataStructures::AIF::AIFMesh &)
Returns the target vertex of e.
Definition: Graph_traits_aif.h:400
FEVV::Color
Definition: Color.hpp:18
FEVV::vertex_custom_vector_param_t
vertex_custom_vector_param_t
Definition: properties.h:61
calculate_vertices_tangent.hpp
FEVV::edge_color
@ edge_color
Definition: properties.h:73
FEVV::SimpleViewer::isNodeSelected
bool isNodeSelected(osg::Node *_geode) override
Definition: SimpleViewer.inl:3584
FEVV::SimpleViewer::getMatrixVP
osg::Matrix getMatrixVP()
Definition: SimpleViewer.inl:3310
FEVV::vertex_color
@ vertex_color
Definition: properties.h:47
FEVV::face_material
@ face_material
Definition: properties.h:85
FEVV::Debug::createUnitGrid
osg::ref_ptr< osg::Group > createUnitGrid(osg::ref_ptr< osg::Group > _group=new osg::Group)
Definition: OSGDebug.inl:329
NO_TEXCOORDS
#define NO_TEXCOORDS
Definition: Texture.h:17
FEVV::SimpleViewer::redrawMesh
void redrawMesh(HalfedgeGraph *_g, PMapsContainer *_pmaps, PointMap *_pm=nullptr, std::string _mesh_file=std::string(""))
Definition: SimpleViewer.inl:3127
FEVV::vertex_custom_vector_t
vertex_custom_vector_t
Definition: properties.h:53
FEVV::MixedMeshesVector::push_back
void push_back(VoidMeshPtr &ptr)
Definition: SimpleViewer.h:142
FEVV::SimpleViewer::getGeodes
std::vector< osg::Geode * > getGeodes()
Definition: SimpleViewer.inl:394
createDragger
osgManipulator::Dragger * createDragger(const std::string &name)
Definition: SimpleViewer.inl:2885
FEVV::Filters::calculate_face_normals
void calculate_face_normals(const HalfedgeGraph &g, const PointMap &pm, FaceNormalMap fnm, const GeometryTraits &gt)
Calculate "some" normal of all the faces of the considered mesh and populate the argument provided Fa...
Definition: calculate_face_normals.hpp:40
FEVV::DataStructures::AIF::AIFVector
Definition: AIFProperties.h:173
FEVV::SimpleViewer::get_properties_maps
std::vector< PMapsContainer * > get_properties_maps()
Definition: SimpleViewer.inl:475
FEVV::Color::Red
static Color Red(void)
Definition: Color.inl:335
FEVV::Assert::check
static bool check(const bool _check, const std::string &_message, const std::string &_where="")
Definition: Assert.h:70
FEVV::Color::White
static Color White(void)
Definition: Color.inl:329
FEVV::RENDER_POINTS
@ RENDER_POINTS
Definition: BaseViewer.h:28
FEVV::SimpleViewer::setMatrixVP
void setMatrixVP(osg::Matrix matrix)
Definition: SimpleViewer.inl:3339
FEVV::SimpleViewer::getTransformMatrixOsg
osg::Matrix getTransformMatrixOsg(unsigned int position)
Definition: SimpleViewer.inl:3364
FEVV::SimpleViewer::getTransformMatrixEigen
Eigen::Matrix4d getTransformMatrixEigen(unsigned int position)
Definition: SimpleViewer.inl:3379
FEVV::RENDER_FILL
@ RENDER_FILL
Definition: BaseViewer.h:30
HALFEDGE_TEXCOORDS2D
#define HALFEDGE_TEXCOORDS2D
Definition: Texture.h:20
ScaleConstraint::ScaleConstraint
ScaleConstraint()
Definition: SimpleViewer.inl:2864
FEVV::Debug::createGizmo
osg::ref_ptr< osg::Group > createGizmo(osg::ref_ptr< osg::Group > _group=new osg::Group)
Definition: OSGDebug.inl:307
FEVV::Filters::calculate_vertex_normals
void calculate_vertex_normals(const HalfedgeGraph &g, const PointMap &pm, const FaceNormalMap &fnm, VertexNormalMap vnm, const GeometryTraits &gt)
Compute the respectice vertex normal for all the vertices of the considered mesh and populate the arg...
Definition: calculate_vertex_normals.hpp:41
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33
FEVV::SimpleViewer::isInit
bool isInit() const override
Definition: SimpleViewer.inl:255
FEVV::BaseAdapterVisuQt
Definition: BaseAdapterVisuQt.h:22
FEVV::SimpleViewer::internal_createMesh_pointcloud
void internal_createMesh_pointcloud(osg::Geode *&geode, PointCloud *_g, PMapsContainer *_pmaps, std::vector< osg::ref_ptr< osg::Geometry > > &geometries, std::vector< osg::ref_ptr< osg::Geometry > > &geometriesL, std::vector< osg::ref_ptr< osg::Geometry > > &geometriesP, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_edges, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_vertices, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_normals, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_custom_vectorss, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_edges, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_vertices, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_normals, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_custom_vectors, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArraysF, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_edges, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_vertices, std::vector< osg::ref_ptr< osg::Vec3Array > > &tangentsArrays, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_edges, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_vertices, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_normals, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_custom_vectors, std::vector< osg::ref_ptr< osg::Vec2Array > > &texcoordsArrays, PointMap *_pm, std::string _mesh_file=std::string(""))
Definition: SimpleViewer.inl:2079
FEVV::MeshOpenMesh
OpenMesh::PolyMesh_ArrayKernelT< MyTraits > MeshOpenMesh
Definition: DataStructures_openmesh.h:51
FEVV::put
void put(FEVV::PCLPointCloudPointMap &pm, FEVV::PCLPointCloudPointMap::key_type key, const FEVV::PCLPointCloudPointMap::value_type &value)
Specialization of put(point_map, key, value) for PCLPointCloud.
Definition: Graph_properties_pcl_point_cloud.h:126
FEVV::face_color
@ face_color
Definition: properties.h:81
FEVV::DataStructures::AIF::AIFMesh
This class represents an AIF structure. AIF structure can deal with both manifold and non-manifold su...
Definition: AIFMesh.hpp:47
FEVV::Types::GuiProperties
Definition: Gui_properties.h:27
FEVV::vertex_custom_vector
@ vertex_custom_vector
Definition: properties.h:53
FEVV::mesh_guiproperties_t
mesh_guiproperties_t
Definition: properties.h:93
ScaleConstraint::constrain
virtual bool constrain(osgManipulator::Scale2DCommand &command) const
Definition: SimpleViewer.inl:2873
FEVV::Filters::calculate_vertices_tangent
void calculate_vertices_tangent(const HalfedgeGraph &g, const PointMap &pm, const VertexUVMap &vum, VertexTangentMap &vtm)
Calculate the mesh's tangents from its vertices.
Definition: calculate_vertices_tangent.hpp:38
FEVV::_PMap_traits
Definition: properties.h:376
VERTEX_TEXCOORDS2D
#define VERTEX_TEXCOORDS2D
Definition: Texture.h:19
FEVV::SimpleViewer::getSelectedDraggers1
std::vector< osg::Group * > getSelectedDraggers1()
Definition: SimpleViewer.inl:483
FEVV::halfedge_texcoord
@ halfedge_texcoord
Definition: properties.h:69
FEVV::SimpleViewer::centerMesh
void centerMesh(HalfedgeGraph *_g)
Definition: SimpleViewer.inl:3245
FEVV::SimpleViewer::getMeshesNames
std::vector< std::string > getMeshesNames()
Definition: SimpleViewer.inl:448
FEVV::vertex_normal
@ vertex_normal
Definition: properties.h:35
FEVV::SimpleViewer::addModel
void addModel(Model *_geode) override
Definition: SimpleViewer.inl:333
FEVV::MeshPolyhedron
CGAL::Polyhedron_3< CGALKernel, CGAL::Polyhedron_items_with_id_3 > MeshPolyhedron
Definition: DataStructures_cgal_polyhedron_3.h:33
FEVV::SimpleWindow::activate_time_mode
void activate_time_mode()
Definition: SimpleWindow.inl:1442
FEVV::vertex_texcoord_t
vertex_texcoord_t
Definition: properties.h:43
FEVV::Helpers::ColorConverter
osg::Vec4 ColorConverter(const Color &_color)
Definition: OSGHelpers.h:59
FEVV::make_property_map
PMap_traits< PropertyT, MeshT >::pmap_type make_property_map(PropertyT, const MeshT &m)
Definition: properties.h:630
FEVV::SimpleWindow::update
void update(bool pick=false)
Definition: SimpleWindow.inl:676
FEVV::SimpleViewer::drawMesh
void drawMesh(HalfedgeGraph *_g, PMapsContainer *_pmaps, PointMap *_pm, std::string _mesh_file=std::string(""))
Definition: SimpleViewer.inl:3100
FEVV::Color::Green
static Color Green(void)
Definition: Color.inl:389
FEVV::DataStructures::AIF::AIFPoint
Definition: AIFProperties.h:31
FEVV::SimpleViewer::getMeshId
size_t getMeshId(const void *mesh_ptr)
Definition: SimpleViewer.inl:3606
FEVV::mesh_guiproperties
@ mesh_guiproperties
Definition: properties.h:93
FEVV::SimpleViewer::internal_createMesh
void internal_createMesh(osg::Geode *&geode, HalfedgeGraph *_g, PMapsContainer *_pmaps, std::vector< osg::ref_ptr< osg::Geometry > > &geometries, std::vector< osg::ref_ptr< osg::Geometry > > &geometriesL, std::vector< osg::ref_ptr< osg::Geometry > > &geometriesP, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_edges, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_vertices, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_normals, std::vector< osg::ref_ptr< osg::Geometry > > &geometries_custom_vectors, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_edges, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_vertices, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_normals, std::vector< osg::ref_ptr< osg::Vec3Array > > &vertexArrays_custom_vectors, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArraysF, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_edges, std::vector< osg::ref_ptr< osg::Vec3Array > > &normalsArrays_vertices, std::vector< osg::ref_ptr< osg::Vec3Array > > &tangentsArrays, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_edges, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_vertices, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_normals, std::vector< osg::ref_ptr< osg::Vec4Array > > &colorsArrays_custom_vectors, std::vector< osg::ref_ptr< osg::Vec2Array > > &texcoordsArrays, PointMap *_pm, std::string _mesh_file=std::string(""))
Definition: SimpleViewer.inl:616
FEVV::face_normal
@ face_normal
Definition: properties.h:77
FEVV::SimpleViewer::getDraggers1
std::vector< osg::Group * > getDraggers1()
Definition: SimpleViewer.inl:502