AGX Dynamics  2.38.0.2
SceneDecorator.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx Simulation AB.
15 */
16 
17 #pragma once
18 
19 #include <agxOSG/export.h>
20 
21 
22 #include <agx/Vec3.h>
23 #include <agx/Vec4.h>
24 
25 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
26 #include <osg/Referenced>
27 #include <osg/Group>
28 #include <osg/Texture2D>
29 #include <osg/MatrixTransform>
30 #include <osg/Projection>
31 #include <osg/StateSet>
32 #include <osg/PositionAttitudeTransform>
33 #include <osg/Switch>
34 #include <osg/Material>
35 #include <osgShadow/ShadowedScene>
36 #include <osgShadow/ShadowTechnique>
37 #include <osg/LightSource>
38 #include <osg/Geometry>
39 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
40 #include <agxOSG/LightSource.h>
41 
42 
43 namespace agxRender
44 {
45  class Color;
46 }
47 
48 namespace osgText
49 {
50  class Text;
51 }
52 
54 namespace agxOSG
55 {
57 
62  class AGXOSG_EXPORT SceneDecorator : public osg::Group
63  {
64  public:
65 
72  SceneDecorator( int windowSizeX, int windowSizeY, int enabledLights = LIGHT0 | LIGHT1 );
73 
75  void setEnableShadows( bool flag );
76 
78  bool getEnableShadows() const;
79 
81  void setEnable( bool flag );
82 
84  bool getEnable() const;
85 
87  bool isEnabled() const;
88 
90  enum LogoLocation {
91  UPPER_LEFT = 0x1,
92  LOWER_LEFT = 0x2,
93  UPPER_RIGHT = 0x3,
94  LOWER_RIGHT = 0x4,
95  FREE
96  };
97 
102  void setLogoLocation( LogoLocation l );
103 
105  LogoLocation getLogoLocation() const;
106 
111  void setLogoPosition(float x, float y);
112 
114  void setEnableLogo( bool flag );
115 
117  bool getEnableLogo() const;
118 
120  bool setLogoFile(const std::string& filename, float density = 1.0);
121 
123  void setText( int row, const agx::String& text );
124  void setText( int row, const agx::String& text, const agx::Vec4f& color );
125 
129  void setEnableShaderState( bool flag, bool lock=false );
130 
132  bool getEnableShaderState( ) const;
133 
135  void clearText();
140  bool setBaseTexture(const std::string& imagePath);
141 
145  const osg::Vec2& getLogoDimension();
146 
150  osg::Vec2 getMaximumLogoDimension();
151 
156  void setMaximumLogoDimension(float x, float y);
157 
161  static osg::Vec2 getDefaultLogoPosition();
162 
169  osg::MatrixTransform* getHud() { return m_hudRoot.get(); }
170 
171  // Overriding add/remove child methods
172  virtual bool insertChild( unsigned int index, osg::Node *child ) { return m_currentRoot->insertChild(index, child); }
173  virtual bool addChild(osg::Node *child) { return m_currentRoot->addChild(child); }
174  inline bool removeChild( osg::Node *child ) { return m_currentRoot->removeChild(child); }
175  inline bool removeChild( unsigned int pos, unsigned int numChildrenToRemove=1 ) { return m_currentRoot->removeChild(pos, numChildrenToRemove); }
176  virtual bool replaceChild( osg::Node *origChild, osg::Node* newChild ) { return m_currentRoot->replaceChild(origChild, newChild); }
177  virtual bool setChild( unsigned int i, osg::Node* node ) { return m_currentRoot->setChild(i, node); }
178  virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove) { return m_currentRoot->removeChildren(pos, numChildrenToRemove); }
179 
184  void calculateLightPositions(osg::Node* bound_node = nullptr);
185 
186  void calculateLightPositions( const osg::BoundingBox& boundingBox );
187 
188  void calculateLightPositions( const osg::BoundingSphere& boundingSphere );
189 
191  std::string getFontName() const;
192 
194  void setFontName(const std::string& fontName);
195 
197  void updateWindowSize(int sizeX, int sizeY);
198 
200  void setScreenPixelScale(float scale);
201 
203  float getFontSize() const;
204 
206  void setFontSize(const float& fontSize);
207 
209  osg::LightSource* getShadowLightSource();
210 
211  enum Lights {
212  LIGHT0 = 0x1,
213  LIGHT1 = 0x2,
214  LIGHT2 = 0x4,
215  ALL = LIGHT0 | LIGHT1 | LIGHT2
216  };
217 
218 
219  static size_t lightToIndex(Lights l);
220 
221  void setEnableCalculateLightPositions( Lights l, bool f );
222 
223  bool getEnableCalculateLightPositions(Lights l) const;
224 
226  bool setShadowLightSource( Lights l);
227 
228  osg::StateSet* getDecoratorStateSet() { return m_decoratorStateSet; }
229 
230  osg::LightSource* getOSGLight(Lights l);
231 
233  agxOSG::LightSource getLightSource(Lights l);
234 
242  NO_SHADOWS
243  };
244 
246  void setShadowMethod(ShadowMethod m);
247 
249  ShadowMethod getShadowMethod() const { return m_shadowMethod; }
250 
252  void setBackgroundColor(const agx::Vec4f& color);
253 
259  void setBackgroundColor(const agx::Vec4f& color1, const agx::Vec4f& color2);
260 
268  void setBackgroundColor(const agx::Vec4f& colorUL, const agx::Vec4f& colorUR, const agx::Vec4f& colorLL, const agx::Vec4f& colorLR);
269 
270 
272  void setBackgroundColor(agx::Vec3 color);
273 
279  void setBackgroundColor(agx::Vec3 upper, agx::Vec3 lower);
280 
288  void setBackgroundColor(agx::Vec3 colorUL, agx::Vec3 colorUR, agx::Vec3 colorLL, agx::Vec3 colorLR);
289 
294  void setEnableLights(int lightMask = ALL);
295 
300  void setEnableRenderedCursor( bool enable );
301  bool getEnableRenderedCursor() const;
302  void updateCursorPosition( float x, float y );
303 
304  osg::Texture2D* getLogo();
305 
307  void setLogo(osg::Texture2D* logo, float density = 1.0);
308 
309  // Will reset the rendering HUD.
310  void resetHUD();
311 
315  osg::Group* getShadowedScene() const;
316 
320  osg::Group* getNonShadowedScene() const;
321 
322  static const osg::Material* getDefaultDecoratorMaterial();
323 
324  protected:
328  void updateLogo();
329  void createHUD();
330 
331  void createLogo();
332  void createBackground();
333 
334  void init(Lights l);
335 
336  osg::ref_ptr<osg::Group> m_enabledRoot;
337  osg::ref_ptr<osg::Group> m_enabledNonShadowRoot;
338  osg::ref_ptr<osg::Group> m_currentRoot;
339  osg::ref_ptr<osg::Group> m_disabledRoot;
340  osg::ref_ptr<osg::Group> m_disabledNonShadowRoot;
341  osg::ref_ptr<osg::Switch> m_backgroundRoot;
342  osg::observer_ptr<osg::Geometry> m_backgroundQuad;
344  osg::ref_ptr<osg::Texture2D> m_logoTexture;
345  osg::ref_ptr<osg::PositionAttitudeTransform> m_logoTransform;
346  osg::ref_ptr<osg::Switch> m_logoSwitch;
347  osg::ref_ptr<osg::MatrixTransform> m_hudRoot;
348  osg::ref_ptr<osg::StateSet> m_logoStateSet;
351  bool m_enabled;
354  std::string m_baseTexturePath;
356  std::string m_fontName;
357  float m_fontSize;
365 
366  osg::ref_ptr<osgShadow::ShadowedScene> m_shadowedScene;
367  osg::ref_ptr<osgShadow::ShadowTechnique> m_shadowTechnique;
368 
369  osg::ref_ptr<osg::StateSet> m_decoratorStateSet;
370 
372  osg::ref_ptr<osg::LightSource> m_ShadowlightSource;
373  osg::ref_ptr<osg::Vec3Array> m_backgroundColors;
374 
375  void createDecoratorState();
376 
377  virtual ~SceneDecorator();
378 
379  bool m_calculateLightPosition[3];
380 
381  osg::ref_ptr<osg::Node> m_cursorTransform;
382  osg::ref_ptr<osg::Camera> m_hudCamera;
383  osg::ref_ptr<osg::Projection> m_hudProjection;
384 
387 
388  static osg::ref_ptr<osg::Material> s_decoratorMaterial;
389  };
390 }
agxOSG::SceneDecorator::LogoLocation
LogoLocation
Specifies the location of the logo.
Definition: SceneDecorator.h:90
agxOSG::SceneDecorator::m_backgroundRoot
osg::ref_ptr< osg::Switch > m_backgroundRoot
Definition: SceneDecorator.h:341
agxRender
Namespace containing classes for handling debug rendering of collision geometries,...
Definition: Constraint.h:35
agxOSG::SceneDecorator::getDecoratorStateSet
osg::StateSet * getDecoratorStateSet()
Definition: SceneDecorator.h:228
agxOSG::SceneDecorator::m_shadowMethod
ShadowMethod m_shadowMethod
Definition: SceneDecorator.h:353
agx::Vector< osgText::Text * >
agxOSG::SceneDecorator::m_logoTransform
osg::ref_ptr< osg::PositionAttitudeTransform > m_logoTransform
Definition: SceneDecorator.h:345
agxOSG::SceneDecorator::removeChild
bool removeChild(unsigned int pos, unsigned int numChildrenToRemove=1)
Definition: SceneDecorator.h:175
agxOSG::SceneDecorator::m_logoLocation
LogoLocation m_logoLocation
Definition: SceneDecorator.h:343
agxOSG::SceneDecorator::m_enabledShadows
bool m_enabledShadows
Definition: SceneDecorator.h:350
agxOSG::SceneDecorator::addChild
virtual bool addChild(osg::Node *child)
Definition: SceneDecorator.h:173
agxOSG::SceneDecorator::m_text
agx::Vector< osgText::Text * > m_text
Definition: SceneDecorator.h:355
agxOSG::SceneDecorator::SHADOWMAP
@ SHADOWMAP
Definition: SceneDecorator.h:237
agxOSG::SceneDecorator::m_logoTexture
osg::ref_ptr< osg::Texture2D > m_logoTexture
Definition: SceneDecorator.h:344
agxOSG::SceneDecorator::insertChild
virtual bool insertChild(unsigned int index, osg::Node *child)
Definition: SceneDecorator.h:172
agxOSG::SceneDecorator::m_fontName
std::string m_fontName
Definition: SceneDecorator.h:356
agxOSG::SceneDecorator::m_shadowTechnique
osg::ref_ptr< osgShadow::ShadowTechnique > m_shadowTechnique
Definition: SceneDecorator.h:367
agx::Vec4T
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
agxOSG::SceneDecorator::m_shadowedScene
osg::ref_ptr< osgShadow::ShadowedScene > m_shadowedScene
Definition: SceneDecorator.h:366
agxOSG::SceneDecorator::replaceChild
virtual bool replaceChild(osg::Node *origChild, osg::Node *newChild)
Definition: SceneDecorator.h:176
agxOSG::SceneDecorator::getShadowMethod
ShadowMethod getShadowMethod() const
Definition: SceneDecorator.h:249
Vec4.h
agxOSG::SceneDecorator::SHADOWVOLUME
@ SHADOWVOLUME
Definition: SceneDecorator.h:238
agxOSG::SceneDecorator::m_logoPixelDensity
float m_logoPixelDensity
Definition: SceneDecorator.h:363
agxOSG::SceneDecorator::m_backgroundColors
osg::ref_ptr< osg::Vec3Array > m_backgroundColors
Definition: SceneDecorator.h:373
agxOSG::SceneDecorator::m_logoStateSet
osg::ref_ptr< osg::StateSet > m_logoStateSet
Definition: SceneDecorator.h:348
agxOSG::SceneDecorator::m_enabledNonShadowRoot
osg::ref_ptr< osg::Group > m_enabledNonShadowRoot
Definition: SceneDecorator.h:337
agxOSG::SceneDecorator::m_disabledRoot
osg::ref_ptr< osg::Group > m_disabledRoot
Definition: SceneDecorator.h:339
LightSource.h
agxOSG::SceneDecorator
Decorates a scene with a specific AGX Rendering Style.
Definition: SceneDecorator.h:62
agxOSG::SceneDecorator::SHADOWTEXTURE
@ SHADOWTEXTURE
Definition: SceneDecorator.h:241
agxOSG::SceneDecorator::m_windowSizeY
int m_windowSizeY
Definition: SceneDecorator.h:359
Vec3.h
agxOSG::SceneDecorator::m_logoEnabled
bool m_logoEnabled
Definition: SceneDecorator.h:352
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
PushDisableWarnings.h
agxOSG::SceneDecorator::m_windowSizeX
int m_windowSizeX
Definition: SceneDecorator.h:358
agxOSG::SceneDecorator::m_ShadowlightSource
osg::ref_ptr< osg::LightSource > m_ShadowlightSource
Definition: SceneDecorator.h:372
agxOSG::SceneDecorator::m_fontSize
float m_fontSize
Definition: SceneDecorator.h:357
agxOSG::SceneDecorator::m_enabledRoot
osg::ref_ptr< osg::Group > m_enabledRoot
Definition: SceneDecorator.h:336
agxOSG::SceneDecorator::m_logoSize
osg::Vec2 m_logoSize
Definition: SceneDecorator.h:362
agxOSG::SceneDecorator::m_disabledNonShadowRoot
osg::ref_ptr< osg::Group > m_disabledNonShadowRoot
Definition: SceneDecorator.h:340
agxOSG::SceneDecorator::m_decoratorStateSet
osg::ref_ptr< osg::StateSet > m_decoratorStateSet
Definition: SceneDecorator.h:369
agxOSG::SceneDecorator::m_lightSources
agx::Vector< osg::ref_ptr< osg::LightSource > > m_lightSources
Definition: SceneDecorator.h:371
agxOSG::SceneDecorator::s_decoratorMaterial
static osg::ref_ptr< osg::Material > s_decoratorMaterial
Definition: SceneDecorator.h:388
agxOSG::SceneDecorator::LIGHTSPACEPERSPECTIVE_SHADOWMAP
@ LIGHTSPACEPERSPECTIVE_SHADOWMAP
Definition: SceneDecorator.h:240
agxOSG::SceneDecorator::m_hudRoot
osg::ref_ptr< osg::MatrixTransform > m_hudRoot
Definition: SceneDecorator.h:347
agxOSG::SceneDecorator::removeChild
bool removeChild(osg::Node *child)
Definition: SceneDecorator.h:174
agxOSG::SceneDecorator::m_currentRoot
osg::ref_ptr< osg::Group > m_currentRoot
Definition: SceneDecorator.h:338
agxOSG::SceneDecorator::m_backgroundQuad
osg::observer_ptr< osg::Geometry > m_backgroundQuad
Definition: SceneDecorator.h:342
agxOSG::SceneDecorator::m_shaderSupportAvailable
bool m_shaderSupportAvailable
Definition: SceneDecorator.h:386
agxOSG::SceneDecorator::m_maximumLogoDimensionX
float m_maximumLogoDimensionX
Definition: SceneDecorator.h:360
agxOSG::SceneDecorator::PARALLELLSPLIT_SHADOWMAP
@ PARALLELLSPLIT_SHADOWMAP
Deprecated.
Definition: SceneDecorator.h:239
agxOSG::SceneDecorator::m_maximumLogoDimensionY
float m_maximumLogoDimensionY
Definition: SceneDecorator.h:361
agxOSG::SceneDecorator::m_baseTexturePath
std::string m_baseTexturePath
Definition: SceneDecorator.h:354
export.h
agxOSG::SceneDecorator::m_screenPixelScale
float m_screenPixelScale
Definition: SceneDecorator.h:364
agxOSG::SceneDecorator::m_cursorTransform
osg::ref_ptr< osg::Node > m_cursorTransform
Definition: SceneDecorator.h:381
agxOSG::SceneDecorator::m_hudCamera
osg::ref_ptr< osg::Camera > m_hudCamera
Definition: SceneDecorator.h:382
agxOSG::SceneDecorator::m_useShaderState
bool m_useShaderState
Definition: SceneDecorator.h:385
agxOSG::SceneDecorator::removeChildren
virtual bool removeChildren(unsigned int pos, unsigned int numChildrenToRemove)
Definition: SceneDecorator.h:178
agx::AgXString< std::string >
agx::init
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
agxOSG::SceneDecorator::m_hudProjection
osg::ref_ptr< osg::Projection > m_hudProjection
Definition: SceneDecorator.h:383
agx::Vec3T< Real >
agxOSG::SceneDecorator::SOFT_SHADOWMAP
@ SOFT_SHADOWMAP
Definition: SceneDecorator.h:236
agxOSG::LightSource
Definition: LightSource.h:32
agxOSG::SceneDecorator::ShadowMethod
ShadowMethod
Definition: SceneDecorator.h:235
agxOSG::SceneDecorator::Lights
Lights
Definition: SceneDecorator.h:211
agxOSG::SceneDecorator::m_enabled
bool m_enabled
Definition: SceneDecorator.h:351
agxOSG::SceneDecorator::setChild
virtual bool setChild(unsigned int i, osg::Node *node)
Definition: SceneDecorator.h:177
agx::Vec2
Vec2T< Real > Vec2
The object holding 2 dimensional vectors and providing basic arithmetic.
Definition: Vec2.h:35
agxOSG::SceneDecorator::m_logoPosition
osg::Vec2 m_logoPosition
Definition: SceneDecorator.h:349
agxOSG::SceneDecorator::m_logoSwitch
osg::ref_ptr< osg::Switch > m_logoSwitch
Definition: SceneDecorator.h:346
agxOSG::SceneDecorator::getHud
osg::MatrixTransform * getHud()
Return a pointer to the hud group.
Definition: SceneDecorator.h:169
AGXOSG_EXPORT
#define AGXOSG_EXPORT
PopDisableWarnings.h