MEPP2 Project
BaseViewerOSG.h
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.
11 #pragma once
12 
14 
15 #include <osg/Version>
16 
17 
18 #if __GNUC__ >= 9
19 #pragma GCC diagnostic push
20 #pragma GCC diagnostic ignored "-Wdeprecated-copy"
21 #endif
22 
23 //#include <osgViewer/CompositeViewer>
24 #include <osgViewer/Viewer>
25 
26 #if __GNUC__ >= 9
27 #pragma GCC diagnostic pop
28 #endif
29 
30 #include <osgText/Text>
31 
32 #include "Base/Color.hpp"
34 
35 // Generic mesh iterators
36 #include <boost/graph/graph_traits.hpp>
37 #include <boost/graph/properties.hpp>
39 
40 namespace FEVV {
41 
42 #if(FEVV_USE_QT5) // FOR_QT6
43 class BaseViewerOSG : public BaseViewer
44 #else
45 class BaseViewerOSG : public osgViewer::Viewer, public BaseViewer
46 #endif
47 {
48 public:
51  using Model = osg::Geode;
52  using Group = osg::Group;
53 
56 
57 public:
58 public:
63 #if(FEVV_USE_QT5) // FOR_QT6
64  : BaseViewer(),
65 #else
66  : osgViewer::Viewer(), BaseViewer(),
67 #endif
68  root_node(new osg::Group), visitor(new DataVisitor(this))
69  {
70 #ifdef DEBUG_VISU2
71  std::cout << "*** this=" << this << " entering " << __func__ << std::endl;
72 #endif
73 
74 #if(FEVV_USE_QT5)
75  // Qt5 is currently crashing and reporting "Cannot make QOpenGLContext
76  // current in a different thread" when the viewer is run multi-threaded,
77  // this is regression from Qt4
78 #if OSG_MIN_VERSION_REQUIRED(3, 4, 0)
79  // setThreadingModel(osgViewer::ViewerBase::AutomaticSelection); // maybe
80  // one day this PB will be fixed either by OSG or by Qt...
81  #if(FEVV_USE_QT5) // FOR_QT6
82  // empty
83  #else
84  setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
85  #endif
86 #else
87  #if(FEVV_USE_QT5) // FOR_QT6
88  // empty
89  #else
90  setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
91  #endif
92 #endif
93 #else
94 #if defined(Q_WS_X11) // X Window System -> Linux
95  // setThreadingModel(osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext);
96  // // PB with osgFX/Outline -> video driver freeze/crash
97  // setThreadingModel(osgViewer::ViewerBase::AutomaticSelection); // PB with
98  // some intel graphic cards
99  setThreadingModel(osgViewer::ViewerBase::SingleThreaded);
100 #elif defined(Q_WS_MACX) // Mac OS X
101  // setThreadingModel(osgViewer::ViewerBase::CullThreadPerCameraDrawThreadPerContext);
102  // // PB with osgFX/Outline -> video driver freeze/crash
103  setThreadingModel(osgViewer::ViewerBase::AutomaticSelection);
104 #else // Windows
105  // setThreadingModel(osgViewer::ViewerBase::CullDrawThreadPerContext);
106  setThreadingModel(osgViewer::ViewerBase::AutomaticSelection);
107 #endif
108 #endif
109 
110  root_node->setName("Root");
111 
112 #ifdef DEBUG_VISU2
113  std::cout << "*** this=" << this << " leaving " << __func__ << std::endl;
114 #endif
115  }
116 
117  virtual ~BaseViewerOSG()
118  {
119 #ifdef DEBUG_VISU2
120  std::cout << "*** this=" << this << " entering " << __func__ << std::endl;
121 #endif
122 
123  delete visitor;
124  root_node->removeChildren(0, root_node->getNumChildren());
125  //delete root_node;
126  //ELO-note: osg::Group destructor is protected ;
127  // can not be called directly!
128  // error: calling a protected destructor of class 'osg::Group'
129 
130 #ifdef DEBUG_VISU2
131  std::cout << "*** this=" << this << " leaving " << __func__ << std::endl;
132 #endif
133  }
134 
140  Group *getRootNode() { return root_node; }
141 
149  virtual void addModel(Model *_geode) = 0;
150 
158  virtual void addGroup(Group *_group) = 0;
159 
160  virtual void setNodeSelected(osg::Node *_node, bool isSelected) = 0;
161  virtual bool isNodeSelected(osg::Node *_node) = 0;
162 
164 
165 protected:
166  osg::Group *root_node = nullptr;
167  DataVisitor *visitor = nullptr;
168 };
169 
170 } // namespace FEVV
FEVV::DataVisitor
Definition: DataVisitor.h:26
FEVV::BaseViewerOSG::root_node
osg::Group * root_node
Definition: BaseViewerOSG.h:166
FEVV::DataVisitor::Output
std::vector< Data > Output
Definition: DataVisitor.h:29
FEVV::BaseViewer::BaseViewer
BaseViewer()
Definition: BaseViewer.h:52
FEVV::Helpers::Model
Definition: DataStructures.h:29
FEVV::BaseViewer
Definition: BaseViewer.h:43
FEVV::BaseViewerOSG::setNodeSelected
virtual void setNodeSelected(osg::Node *_node, bool isSelected)=0
FEVV::BaseViewerOSG::Model
osg::Geode Model
Definition: BaseViewerOSG.h:51
FEVV::BaseViewerOSG
Definition: BaseViewerOSG.h:47
DataVisitor.h
FEVV::BaseViewerOSG::DataModelVector
DataVisitor::Output DataModelVector
Definition: BaseViewerOSG.h:50
FEVV::DataVisitor::Data
Helpers::Model< osg::Node > Data
Definition: DataVisitor.h:28
FEVV::BaseViewerOSG::~BaseViewerOSG
virtual ~BaseViewerOSG()
Definition: BaseViewerOSG.h:117
BaseViewer.h
FEVV::BaseViewerOSG::Group
osg::Group Group
Definition: BaseViewerOSG.h:52
FEVV
Interfaces for plugins These interfaces will be used for different plugins.
Definition: Assert.h:16
FEVV::BaseViewerOSG::visitor
DataVisitor * visitor
Definition: BaseViewerOSG.h:167
FEVV::BaseViewerOSG::getDataModel
virtual DataModelVector * getDataModel()=0
Geometry_traits.h
FEVV::BaseViewer::setSelected
virtual void setSelected(const bool _isSelected)
Definition: BaseViewer.h:120
FEVV::BaseViewerOSG::isSelected
virtual bool isSelected() const
Definition: BaseViewer.h:118
Color.hpp
FEVV::BaseViewerOSG::isNodeSelected
virtual bool isNodeSelected(osg::Node *_node)=0
FEVV::BaseViewerOSG::BaseViewerOSG
BaseViewerOSG()
Definition: BaseViewerOSG.h:62
FEVV::BaseViewerOSG::addModel
virtual void addModel(Model *_geode)=0
FEVV::BaseViewer::isSelected
virtual bool isSelected() const
Definition: BaseViewer.h:118
FEVV::BaseViewerOSG::getRootNode
Group * getRootNode()
Definition: BaseViewerOSG.h:140
FEVV::BaseViewerOSG::addGroup
virtual void addGroup(Group *_group)=0