AGX Dynamics  2.37.2.0
QtOSGUtils.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 #ifndef AGXQT_QTOSGUTILS_H
18 #define AGXQT_QTOSGUTILS_H
19 
20 #include <agx/config/AGX_USE_KEYSHOT.h>
21 #include <agxQt/export.h>
22 
25 #include <agxQt/ParticleFilters.h>
26 #include <agxQt/CameraViewSet.h>
27 #include <agx/Referenced.h>
32 #include <agxOSG/ClipPlane.h>
35 
36 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
37 #include <osgViewer/ViewerEventHandlers>
38 #include <osg/Group>
39 #include <osgViewer/Renderer>
40 #include <osgSim/ColorRange>
41 #include <osgSim/ScalarsToColors>
42 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
43 
44 namespace agxOSG
45 {
46  class SceneDecorator;
47  class Node;
48  class Group;
49 }
50 
51 namespace agxQt
52 {
53  class QtAgxWrapper;
54 
60  {
61  public:
62  const agx::Vec3 BASE_NORMAL = agx::Vec3(0, 1, 0);
63 
64  public:
67 
68  void setPosition( agx::Vec3 position );
69 
70  void setRotation(const agx::Quat& quat );
71 
72  agx::Vec3 getPosition() const;
73 
74  agx::Quat getRotation() const;
75 
76  bool getEnable() const;
77 
78  void setEnable(bool enable);
79 
80  bool getEnableRendering() const;
81 
82  void setEnableRendering(bool enable);
83 
84  agx::Real getIncrement() const;
85 
86  void setIncrement(agx::Real increment);
87 
89  void incrementClipPlane();
90 
92  void decrementClipPlane();
93 
94  agxOSG::ClipPlane* getClipPlane() const;
95 
96  protected:
97  void updateClipPlaneFromIncrement( agx::Real increment );
98 
100  virtual ~ClipPlaneController();
101 
103  // Variables
105  protected:
110  };
111 
113 
115  // ParticleTrajectoryRenderer
118  {
120 
121  public:
123  osg::Group* root,
124  agx::ParticleSystem* ps );
125 
126  void setMaxPositionPoints( agx::UInt posPoints );
127 
128  agx::UInt getMaxPositionPoints();
129 
130  void setEnable( bool enable );
131 
132  bool getEnable() const;
133 
134  void setSampling( agx::Real enable );
135 
136  agx::Real getSampling() const;
137 
138  void reSample();
139 
140  void resetTrajectoires();
141 
142  void setColorMap(agxOSG::ScalarColorMap* colorMap);
143 
144  agxOSG::ScalarColorMap* getColorMap();
145 
146  protected:
147  virtual ~TrajectoryRenderer();
148 
150  // Variables
153  osg::observer_ptr<osg::Group> m_root;
154  osg::ref_ptr<osg::Geode> m_trajectoryGeode;
157  bool m_enable;
158 
159  osg::ref_ptr < agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable;
160  osg::ref_ptr < agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable;
161  };
162 
164 
165 
167  // ParticleContactGraphRenderer
170  {
171  public:
173 
174  void setEnable(bool enable);
175 
176  bool getEnable() const;
177 
178  agx::Real getMinNetworkForce() const;
179 
180  void setMinNetworkForce(agx::Real minForce);
181 
182  agx::Real getMaxNetworkForce() const;
183 
184  void setMaxNetworkForce(agx::Real minForce);
185 
186  protected:
187  virtual ~ParticleContactGraphRenderer();
188 
190  // Variables
192  osg::observer_ptr<osg::Group> m_root;
195  };
196 
197  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setEnable(bool enable) { m_graphDrawable->setEnable(enable); }
198 
199  AGX_FORCE_INLINE bool ParticleContactGraphRenderer::getEnable() const { return m_graphDrawable->getEnable(); }
200 
201  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setMaxNetworkForce(agx::Real maxForce) { m_graphDrawable->setMaxForce(maxForce); }
202 
203  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setMinNetworkForce(agx::Real minForce) { m_graphDrawable->setMinForce(minForce); }
204 
205  AGX_FORCE_INLINE agx::Real ParticleContactGraphRenderer::getMinNetworkForce() const { return m_graphDrawable->getMinForce(); }
206 
207  AGX_FORCE_INLINE agx::Real ParticleContactGraphRenderer::getMaxNetworkForce() const { return m_graphDrawable->getMaxForce(); }
208 
213  {
214  public:
216  agxQt::QtAgxWrapper* qtagxViewer,
217  osg::Group* root,
219  agx::ParticleSystem* system);
220 
221  void setParticleShaderMode(agxOSG::ParticleSystemDrawable::ParticleShaderMode mode);
222 
223  agxOSG::ParticleSystemDrawable::ParticleShaderMode getParticleShaderMode() const;
224 
225  void setAlphaValue(agx::Real alpha);
226 
227  agx::Real getAlphaValue() const;
228 
229  virtual void pre(const agx::TimeStamp& t);
230 
231  virtual void post(const agx::TimeStamp& t);
232 
233  void setParticleColorModeFromName(const agx::String& mode);
234 
235  ParticleColorMode getActiveParticleColorMode() const;
236 
237  ParticleColorModeVector getAvailableColorModes() const;
238 
239  ParticleRenderFilterManager* getParticleRenderFilterManager();
240 
241  void setMaxColorScalar(agx::Real maxVel);
242 
243  void setMinColorScalar(agx::Real minVel);
244 
245  agx::Real getMaxColorScalar() const;
246 
247  agx::Real getMinColorScalar() const;
248 
249  void setAnalysisBox(const agx::AnalysisBox* box);
250 
251  void setLimitColoringToAnalysisBound(bool enable);
252 
253  bool getLimitColoringToAnalysisBound() const;
254 
255  void setShowColorLegend(bool enable, int width, int height);
256 
257  void setShowColorLegend(bool enable);
258 
259  void updateColorLegend(int width, int height);
260 
261  void refreshColorLegend();
262 
263  bool getShowColorLegend() const;
264 
265  void setEnableParticleRendering(bool enable);
266 
267  bool getEnableParticleRendering() const;
268 
269  void preRenderParticles( agx::ParticleSystem * system );
270 
271  void preRenderBodies();
272 
273  ParticleContactGraphRendererRef getParticleContactGraphRenderer();
274 
275  GranularImpactsDrawable* getGranularImpactsDrawable();
276 
277  void addCustomColorers();
278 
279  bool hasOpenColorLegend() const;
280 
281  void resetParticleFilteredState();
282 
283  void setEnableRenderOnNSSBodies(const agx::RigidBodyRefVector& bodies, bool enable);
284 
285  void setEnableRenderingOnTemplateBodies(const agx::RigidBodyRefVector& bodies, bool enable);
286 
287  agxOSG::ParticleSystemDrawable* getParticleSystemDrawable();
288 
289  protected:
290 
291  virtual ~ParticleSystemRenderUtility();
292 
293  void preRender();
294 
295  void resetAlphaOnColors();
296 
297  void setAlphaOnParticles(agx::Real alpha);
298 
299  void removeColorLegend();
300 
302  // Variables
304  protected:
306  osg::ref_ptr<agxOSG::ParticleSystemDrawable> m_psDrawable;
309 
310  // color renderer
311  osg::ref_ptr<osg::Group> m_hudGroup;
312  osg::observer_ptr<osg::Group> m_root;
313 
317 
318  // Impacts drawable
319  osg::ref_ptr<agxQt::GranularImpactsDrawable> m_impactsDrawable;
321  };
322 
324 
325  /* Implementation */
326 
327  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getAlphaValue() const { return m_alpha; }
328 
329  AGX_FORCE_INLINE ParticleColorMode ParticleSystemRenderUtility::getActiveParticleColorMode() const { return m_particleColorerManager->getActiveParticleColorMode(); }
330 
331  AGX_FORCE_INLINE ParticleColorModeVector ParticleSystemRenderUtility::getAvailableColorModes() const { return m_particleColorerManager->getAvailableParticleColorModes(); }
332 
333  AGX_FORCE_INLINE void ParticleSystemRenderUtility::setLimitColoringToAnalysisBound(bool enable) { m_particleColorerManager->setLimitInBound(enable); }
334 
335  AGX_FORCE_INLINE bool ParticleSystemRenderUtility::getLimitColoringToAnalysisBound() const { return m_particleColorerManager->getLimitInBound(); }
336 
337  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getMinColorScalar() const
338  {
339  if (m_particleColorerManager)
340  return m_particleColorerManager->getMinScalar();
341  else
342  return 0;
343  }
344 
345  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getMaxColorScalar() const
346  {
347  if (m_particleColorerManager)
348  return m_particleColorerManager->getMaxScalar();
349  else
350  return 0;
351  }
352 
353  AGX_FORCE_INLINE bool ParticleSystemRenderUtility::getEnableParticleRendering() const { return m_enableParticleRendering; }
354 
355  AGX_FORCE_INLINE ParticleContactGraphRendererRef ParticleSystemRenderUtility::getParticleContactGraphRenderer() { return m_particleContactGraphRenderer; }
356 
357  AGX_FORCE_INLINE GranularImpactsDrawable* ParticleSystemRenderUtility::getGranularImpactsDrawable() { return m_impactsDrawable; }
358 
359  osg::Geode * createCube(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
360  osg::Geode * createCubeLines(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
361  osg::Geode * createPlaneLines(const agx::Vec3& position, const agx::Vec3& normal, agx::Real size);
362 
363 #if AGX_USE_KEYSHOT()
364 
367  class KeyShotParticleDumper
368  {
369  KeyShotParticleDumper();
370  public:
371 
372  static void dumpParticlesInSimulationToKeyShotFile(agxSDK::Simulation * simulation, agx::String filename);
373 
374  static void exportCurrentJournalFrameToBip(int frame,
375  const agx::String& journalFilename,
376  const agx::String& sessionName,
377  const agx::String& bipFile,
378  agxQt::CameraDescription* camera,
380 
381  protected:
383  // Variables
385  };
386 #endif
387 }
388 
389 #endif
agx::UInt m_numTrajectoryPositions
Definition: QtOSGUtils.h:155
agxOSG::ParticleContactGraphDrawable * m_graphDrawable
Definition: QtOSGUtils.h:194
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: Vec3.h:36
osg::Geode * createCubeLines(const agx::Vec3 &position, const agx::Vec3 &boxhalfVec3)
agx::ParticleSystem * m_system
Definition: QtOSGUtils.h:307
Derive from this class to implement a listener for simulation step events.
This utility class is used for post processing of the particle system drawable representation, such as alpha rendering and velocity color.
Definition: QtOSGUtils.h:212
agxQt::QtAgxWrapper * m_qtAgxWrapper
Definition: QtOSGUtils.h:305
osg::ref_ptr< agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable
Definition: QtOSGUtils.h:159
agx::ParticleSystem * m_particleSystem
Definition: QtOSGUtils.h:193
osg::ref_ptr< agxQt::GranularImpactsDrawable > m_impactsDrawable
Definition: QtOSGUtils.h:319
Contains classes/utility functions for connecting AGX to QT with OSG.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
This class wraps the ClipPlane functionality of osg together with a clip node and a clip plane...
Definition: ClipPlane.h:43
agx::Real TimeStamp
Definition: TimeStamp.h:26
agx::ParticleSystem * m_particleSystem
Definition: QtOSGUtils.h:152
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:192
Base class providing referencing counted objects.
Definition: Referenced.h:119
Templated vector class.
Definition: Vector.h:52
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:153
A basic particle system that contains all the storages and buffers required for basic operation and a...
uint32_t UInt
Definition: Integer.h:34
osg::Geode * createPlaneLines(const agx::Vec3 &position, const agx::Vec3 &normal, agx::Real size)
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::ref_ptr< osg::Geode > m_trajectoryGeode
Definition: QtOSGUtils.h:154
Class that can be used to extract data from elements in a simulation within a specified bound...
Definition: AnalysisBox.h:31
ParticleColorerManagerRef m_particleColorerManager
Definition: QtOSGUtils.h:315
osg::ref_ptr< agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable
Definition: QtOSGUtils.h:160
ParticleRenderFilterManagerRef m_particleRenderFilterManager
Definition: QtOSGUtils.h:316
Class that describes an abstract camera and it&#39;s properties.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
Class that is used to manipulate the clip plane in the scene.
Definition: QtOSGUtils.h:59
ParticleContactGraphRendererRef m_particleContactGraphRenderer
Definition: QtOSGUtils.h:314
osg::ref_ptr< agxOSG::ParticleSystemDrawable > m_psDrawable
Definition: QtOSGUtils.h:306
double Real
Definition: Real.h:42
Class that represents a linear scalar color map that converts a scalar interval to a specified color ...
AGXCORE_EXPORT Component * root()
Class that wraps SimulationController with an interface that enables QT Gui signals to control the si...
Definition: QtAgxWrapper.h:70
osg::Geode * createCube(const agx::Vec3 &position, const agx::Vec3 &boxhalfVec3)
osg::ref_ptr< osg::Group > m_hudGroup
Definition: QtOSGUtils.h:311
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:312
agxOSG::ClipPlane * m_clipPlane
Definition: QtOSGUtils.h:106