OpenCOVER
VRSceneGraph.h
Go to the documentation of this file.
1/* This file is part of COVISE.
2
3 You can use it under the terms of the GNU Lesser General Public License
4 version 2.1 or later, see lgpl-2.1.txt.
5
6 * License: LGPL 2+ */
7
8#ifndef VR_SCENE_GRAPH_H
9#define VR_SCENE_GRAPH_H
10
25#include <util/common.h>
26#include <osg/Node>
27#include <osg/Matrix>
28#include <osg/Group>
29#include <osg/MatrixTransform>
30#include <osg/ref_ptr>
31#include <osg/Multisample>
32#include <osg/Material>
33#include <osg/ClipNode>
34#include <osgFX/Scribe>
35
36#include "ui/Owner.h"
37
38namespace opencover {
39namespace ui {
40class Menu;
41class Action;
42class Button;
43class SelectionList;
44}
45}
46
47namespace osg
48{
49class StateSet;
50class ClipNode;
51}
52
53namespace vrui
54{
55class coCombinedButtonInteraction;
56}
57
58namespace opencover
59{
60class COVEREXPORT VRSceneGraph: public ui::Owner
61{
62public:
69 };
71 virtual ~VRSceneGraph();
73
74 bool saveScenegraph(const std::string &filename, bool withMenu=false);
75#ifdef PHANTOM_TRACKER
76 static void manipulateCallback(void *sceneGraph, buttonSpecCell *spec);
77#endif
78
79 osg::MatrixTransform *loadAxisGeode(float scale);
80 osg::Node *loadHandIcon(const char *name);
81 osg::Node *loadHandLine();
82
83 void addMenuItem(osg::Group *itemGroup);
84 osg::Group *getMenuGroup()
85 {
86 return m_menuGroupNode.get();
87 }
89 {
90 return m_alwaysVisibleGroupNode.get();
91 }
92 bool menuVisible() const;
93 void toggleMenu();
94 void setMenu(bool state);
95 void setMenuMode(bool state);
97 void toggleHeadTracking(bool state);
98 void setObjects(bool state);
99
100 // process key events
101 bool keyEvent(int type, int keySym, int mod);
102 osg::Group *getScene()
103 {
104 return m_scene.get();
105 };
106
107 osg::Group *getObjectsScene()
108 {
109 return m_objectsScene.get();
110 }
111
112 void config();
113 void init();
114 void update();
115
116 osg::MatrixTransform *getTransform() const
117 {
118 return m_objectsTransform.get();
119 }
120 osg::MatrixTransform *getScaleTransform() const
121 {
122 return (m_scaleTransform);
123 }
124 osg::MatrixTransform *getHandTransform() const
125 {
126 return (m_handTransform.get());
127 }
128 osg::Vec3 getWorldPointOfInterest() const;
129 void getHandWorldPosition(float *, float *, float *);
130 void addPointerIcon(osg::Node *node);
131 void removePointerIcon(osg::Node *node);
132
133 osg::StateSet *loadDefaultGeostate(osg::Material::ColorMode mode = osg::Material::OFF);
134 osg::StateSet *loadGlobalGeostate();
135 osg::StateSet *loadUnlightedGeostate(osg::Material::ColorMode mode = osg::Material::OFF);
136 osg::StateSet *loadTransparentGeostate(osg::Material::ColorMode mode = osg::Material::OFF);
137
139 void setPointerType(int pointerType);
141 {
142 return (m_pointerType);
143 }
144
145 osg::BoundingSphere getBoundingSphere();
146
147 void setNodeBounds(osg::Node *node, const osg::BoundingSphere *bs);
148
149 bool highQuality() const;
150
151 template <class T>
152 T *findFirstNode(const char *name, bool startsWith = false, osg::Node * rootNode = NULL)
153 {
154 if (!rootNode)
155 rootNode = m_objectsRoot;
156
157 if (!rootNode)
158 return NULL;
159
160 if (!name)
161 return NULL;
162
163 if (!(startsWith ? strncmp(rootNode->getName().c_str(), name, strlen(name)) : strcmp(rootNode->getName().c_str(), name)))
164 {
165 T *node = dynamic_cast<T *>(rootNode);
166 if (node)
167 return node;
168 }
169
170 osg::Group *group = dynamic_cast<osg::Group *>(rootNode);
171 if (group)
172 {
173 for (unsigned int i = 0; i < group->getNumChildren(); i++)
174 {
175 T *node = findFirstNode<T>(name, startsWith, group->getChild(i));
176 if (node)
177 {
178 return node;
179 }
180 }
181 return NULL;
182 }
183 else
184 {
185 return NULL;
186 }
187 }
188
189 float scaleMode()
190 {
191 return m_scaleMode;
192 }
193 void setScaleMode(float scaleMode)
194 {
195 m_scaleMode = scaleMode;
196 }
198 {
199 return m_scaleFactor;
200 }
201 void setScaleFactor(float scaleFactor, bool sync = true);
202 void scaleAllObjects(bool resetView = false);
204 {
205 return m_scalingAllObjects;
206 }
207 void boundingSphereToMatrices(const osg::BoundingSphere &boundingSphere,
208 bool resetView, osg::Matrix *currentMatrix, float *scaleFactor) const;
210
211 void toggleAxis(bool state);
212 void toggleHighQuality(bool state);
213 void viewAll(bool resetView = false);
215 {
216 return m_floorHeight;
217 }
218 osg::ClipNode *objectsRoot()
219 {
220 return m_objectsRoot;
221 }
222
223 osg::ref_ptr<osg::Node> getHandSphere()
224 {
225 return m_handSphere;
226 }
227
228 void setMultisampling(osg::Multisample::Mode);
229
230 void setScaleFromButton(float direction);
231 void setScaleFactorButton(float f);
232 void setScaleRestrictFactor(float min, float max);
233
234 void setRestrictBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ);
235
236 //Coloring
237 void setColor(const char *nodeName, int *color, float transparency);
238 void setColor(osg::Geode *geode, int *color, float transparency);
239 void setTransparency(const char *nodeName, float transparency);
240 void setTransparency(osg::Geode *geode, float transparency);
241 void setShader(const char *nodeName, const char *shaderName, const char *paraFloat, const char *paraVec2, const char *paraVec3, const char *paraVec4, const char *paraInt, const char *paraBool, const char *paraMat2, const char *paraMat3, const char *paraMat4);
242 void setShader(osg::Geode *geode, const char *shaderName, const char *paraFloat, const char *paraVec2, const char *paraVec3, const char *paraVec4, const char *paraInt, const char *paraBool, const char *paraMat2, const char *paraMat3, const char *paraMat4);
243 void setMaterial(const char *nodeName, int *ambient, int *diffuse, int *specular, float shininess, float transparency);
244 void setMaterial(osg::Geode *geode, int *ambient, int *diffuse, int *specular, float shininess, float transparency);
245
246 // disables "store scenegraph"
248
249 int m_vectorInteractor; //< don't use - for COVISE plugin only
250
251 bool isHighQuality() const;
252
253private:
254 static VRSceneGraph *s_instance;
255 int readConfigFile();
256 void initAxis();
257 void initHandDeviceGeometry();
258 void initMatrices();
259 void initSceneGraph();
260 bool saveScenegraph(bool withMenu);
261
262#ifdef PHANTOM_TRACKER
263 int m_forceFeedbackON;
264 int m_forceFeedbackMode;
265 float m_forceScale;
266#endif
267
268 osg::ref_ptr<osg::Group> m_scene, m_objectsScene;
269 osg::ref_ptr<osgFX::Scribe> m_lineHider;
270 osg::ref_ptr<osg::MatrixTransform> m_handTransform;
271 osg::ref_ptr<osg::MatrixTransform> m_handAxisTransform, m_viewerAxisTransform, m_smallSceneAxisTransform;
272 osg::ref_ptr<osg::MatrixTransform> m_worldAxis, m_handAxis, m_viewerAxis, m_objectAxis, m_smallSceneAxis;
273 osg::ref_ptr<osg::Group> m_menuGroupNode;
274 osg::ref_ptr<osg::Group> m_alwaysVisibleGroupNode;
275 osg::ref_ptr<osg::MatrixTransform> m_pointerDepthTransform;
276 float m_pointerDepth;
277 osg::ref_ptr<osg::Node> m_handPlane;
278 osg::ref_ptr<osg::Node> m_handLine;
279 osg::ref_ptr<osg::Node> m_handNormal;
280 osg::ref_ptr<osg::Node> m_handCube;
281 osg::ref_ptr<osg::Node> m_handFly;
282 osg::ref_ptr<osg::Node> m_handDrive;
283 osg::ref_ptr<osg::Node> m_handWalk;
284 osg::ref_ptr<osg::Node> m_handPyramid;
285 osg::ref_ptr<osg::Node> m_handProbe;
286 osg::ref_ptr<osg::Node> m_handAnchor;
287 osg::ref_ptr<osg::Node> m_handSphere;
288
289 bool showSmallSceneAxis_;
290 bool transparentPointer_;
291
292 osg::StateSet *m_rootStateSet, *m_objectsStateSet;
293 osg::ClipNode *m_objectsRoot;
294
295 float m_floorHeight;
296 WireframeMode m_wireframe;
297 bool m_textured = true; /* =true: textures are drawn as intended */
298 bool m_shaders = true; /* =true: shaders are applied */
299 bool m_coordAxis = false; /* =true: coord Axis will be drawn */
300 bool m_showMenu = true;
301 bool m_showObjects = true;
302 bool m_firstTime = true;
303 bool m_pointerVisible = false;
304
305 osg::Matrix m_invBaseMatrix;
306 osg::Matrix m_oldInvBaseMatrix;
307
308 int m_pointerType;
309
310 // attribute SCALE attached to PerformerScene objects:
311 // SCALE viewAll : scaleMode=1.0
312 // SCALE keep : scaleMode=0.0
313 // SCALE <pos number eg. 2.0 or 0.5> : scaleMode=<number>
314 // no SCALE attribute : scaleMode=-1.0
315 float m_scaleMode, m_scaleFactor;
316 float m_scaleFactorButton;
317 float m_scaleRestrictFactorMin, m_scaleRestrictFactorMax;
318 float m_transRestrictMinX, m_transRestrictMinY, m_transRestrictMinZ;
319 float m_transRestrictMaxX, m_transRestrictMaxY, m_transRestrictMaxZ;
320 bool m_scaleAllOn;
321 bool m_scalingAllObjects;
322 osg::MatrixTransform *m_scaleTransform, *m_handIconScaleTransform, *m_handAxisScaleTransform;
323 float m_handIconSize;
324 float m_handIconOffset;
325
326 float wiiPos;
327
328 osg::ref_ptr<osg::MatrixTransform> m_objectsTransform;
329 osg::ref_ptr<osg::Multisample> m_Multisample;
330 typedef std::set<osg::Node *> NodeSet;
331 NodeSet m_specialBoundsNodeList;
332 void dirtySpecialBounds();
333
334 bool menusAreHidden;
335 osg::ref_ptr<osg::Program> emptyProgram_;
336
337 bool isScenegraphProtected_;
338
339 typedef std::map<osg::Drawable *, osg::ref_ptr<osg::Material> > StoredMaterialsMap;
340 StoredMaterialsMap storedMaterials;
341 void storeMaterial(osg::Drawable *drawable);
342 bool m_enableHighQualityOption, m_switchToHighQuality, m_highQuality;
343 vrui::coCombinedButtonInteraction *m_interactionHQ;
344
345 ui::Menu *m_miscMenu=nullptr;
346 ui::SelectionList *m_drawStyle=nullptr;
347 ui::Button *m_trackHead=nullptr;
348 ui::SelectionList *m_showStats=nullptr;
349 ui::Button *m_showAxis=nullptr, *m_allowHighQuality=nullptr;
350 ui::Button *m_useTextures=nullptr, *m_useShaders=nullptr;
351};
352}
353#endif
double OSGVRUIEXPORT mod(double a, double b)
Definition: ARToolKit.h:33
Definition: coClusterStat.h:29
collaborative interface manager
Definition: coVRCommunication.h:41
Definition: VRSceneGraph.h:61
bool keyEvent(int type, int keySym, int mod)
void setMenu(bool state)
bool isScalingAllObjects() const
Definition: VRSceneGraph.h:203
bool saveScenegraph(const std::string &filename, bool withMenu=false)
void setMaterial(osg::Geode *geode, int *ambient, int *diffuse, int *specular, float shininess, float transparency)
void toggleHeadTracking(bool state)
void setShader(const char *nodeName, const char *shaderName, const char *paraFloat, const char *paraVec2, const char *paraVec3, const char *paraVec4, const char *paraInt, const char *paraBool, const char *paraMat2, const char *paraMat3, const char *paraMat4)
osg::MatrixTransform * loadAxisGeode(float scale)
void setTransparency(osg::Geode *geode, float transparency)
void setColor(const char *nodeName, int *color, float transparency)
osg::ref_ptr< osg::Node > getHandSphere()
Definition: VRSceneGraph.h:223
void addMenuItem(osg::Group *itemGroup)
float floorHeight()
Definition: VRSceneGraph.h:214
bool menuVisible() const
void toggleAxis(bool state)
osg::Group * getAlwaysVisibleGroup()
Definition: VRSceneGraph.h:88
void toggleHighQuality(bool state)
void setScaleFactorButton(float f)
void setMenuMode(bool state)
osg::MatrixTransform * getHandTransform() const
Definition: VRSceneGraph.h:124
osg::StateSet * loadGlobalGeostate()
osg::Vec3 getWorldPointOfInterest() const
void setMultisampling(osg::Multisample::Mode)
void setWireframe(WireframeMode mode)
void addPointerIcon(osg::Node *node)
void setPointerType(int pointerType)
int getPointerType()
Definition: VRSceneGraph.h:140
osg::Group * getScene()
Definition: VRSceneGraph.h:102
WireframeMode
Definition: VRSceneGraph.h:63
@ Disabled
Definition: VRSceneGraph.h:64
@ HiddenLineBlack
Definition: VRSceneGraph.h:66
@ HiddenLineWhite
Definition: VRSceneGraph.h:67
@ Points
Definition: VRSceneGraph.h:68
@ Enabled
Definition: VRSceneGraph.h:65
int m_vectorInteractor
Definition: VRSceneGraph.h:249
void setScaleMode(float scaleMode)
Definition: VRSceneGraph.h:193
osg::MatrixTransform * getTransform() const
Definition: VRSceneGraph.h:116
osg::BoundingSphere getBoundingSphere()
osg::StateSet * loadDefaultGeostate(osg::Material::ColorMode mode=osg::Material::OFF)
osg::ClipNode * objectsRoot()
Definition: VRSceneGraph.h:218
osg::Node * loadHandIcon(const char *name)
void setShader(osg::Geode *geode, const char *shaderName, const char *paraFloat, const char *paraVec2, const char *paraVec3, const char *paraVec4, const char *paraInt, const char *paraBool, const char *paraMat2, const char *paraMat3, const char *paraMat4)
void setColor(osg::Geode *geode, int *color, float transparency)
void setMaterial(const char *nodeName, int *ambient, int *diffuse, int *specular, float shininess, float transparency)
osg::MatrixTransform * getScaleTransform() const
Definition: VRSceneGraph.h:120
void viewAll(bool resetView=false)
void setObjects(bool state)
osg::Node * loadHandLine()
bool isHighQuality() const
osg::StateSet * loadTransparentGeostate(osg::Material::ColorMode mode=osg::Material::OFF)
void setTransparency(const char *nodeName, float transparency)
static VRSceneGraph * instance()
void setScaleFromButton(float direction)
void setScaleRestrictFactor(float min, float max)
void removePointerIcon(osg::Node *node)
void scaleAllObjects(bool resetView=false)
osg::Group * getObjectsScene()
Definition: VRSceneGraph.h:107
void getHandWorldPosition(float *, float *, float *)
float scaleFactor()
Definition: VRSceneGraph.h:197
bool highQuality() const
void setNodeBounds(osg::Node *node, const osg::BoundingSphere *bs)
void setRestrictBox(float minX, float maxX, float minY, float maxY, float minZ, float maxZ)
osg::StateSet * loadUnlightedGeostate(osg::Material::ColorMode mode=osg::Material::OFF)
float scaleMode()
Definition: VRSceneGraph.h:189
osg::Group * getMenuGroup()
Definition: VRSceneGraph.h:84
void boundingSphereToMatrices(const osg::BoundingSphere &boundingSphere, bool resetView, osg::Matrix *currentMatrix, float *scaleFactor) const
void setScaleFactor(float scaleFactor, bool sync=true)
T * findFirstNode(const char *name, bool startsWith=false, osg::Node *rootNode=NULL)
Definition: VRSceneGraph.h:152
Definition: coCombinedButtonInteraction.h:22