AGX Dynamics  2.37.3.2
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 
55  {
56  public:
58  {
59  HORIZONTAL = 0,
60  VERTICAL = 1
61  };
62 
67 
69  : legendScaleFactor{ 0.5 },
70  orientation { Orientation::HORIZONTAL },
71  enableAutoPlacement{ true },
72  position{ 0,0,0 }
73  {
74  }
75  };
76 
77  class QtAgxWrapper;
78 
84  {
85  public:
86  const agx::Vec3 BASE_NORMAL = agx::Vec3(0, 1, 0);
87 
88  public:
91 
92  void setPosition( agx::Vec3 position );
93 
94  void setRotation(const agx::Quat& quat );
95 
96  agx::Vec3 getPosition() const;
97 
98  agx::Quat getRotation() const;
99 
100  bool getEnable() const;
101 
102  void setEnable(bool enable);
103 
104  bool getEnableRendering() const;
105 
106  void setEnableRendering(bool enable);
107 
108  agx::Real getIncrement() const;
109 
110  void setIncrement(agx::Real increment);
111 
113  void incrementClipPlane();
114 
116  void decrementClipPlane();
117 
118  agxOSG::ClipPlane* getClipPlane() const;
119 
120  protected:
121  void updateClipPlaneFromIncrement( agx::Real increment );
122 
124  virtual ~ClipPlaneController();
125 
127  // Variables
129  protected:
134  };
135 
137 
139  // ParticleTrajectoryRenderer
142  {
144 
145  public:
147  osg::Group* root,
148  agx::ParticleSystem* ps );
149 
150  void setMaxPositionPoints( agx::UInt posPoints );
151 
152  agx::UInt getMaxPositionPoints();
153 
154  void setEnable( bool enable );
155 
156  bool getEnable() const;
157 
158  void setSampling( agx::Real enable );
159 
160  agx::Real getSampling() const;
161 
162  void reSample();
163 
164  void resetTrajectoires();
165 
166  void setColorMap(agxOSG::ScalarColorMap* colorMap);
167 
168  agxOSG::ScalarColorMap* getColorMap();
169 
170  protected:
171  virtual ~TrajectoryRenderer();
172 
174  // Variables
177  osg::observer_ptr<osg::Group> m_root;
178  osg::ref_ptr<osg::Geode> m_trajectoryGeode;
181  bool m_enable;
182 
183  osg::ref_ptr < agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable;
184  osg::ref_ptr < agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable;
185  };
186 
188 
189 
191  // ParticleContactGraphRenderer
194  {
195  public:
197 
198  void setEnable(bool enable);
199 
200  bool getEnable() const;
201 
202  agx::Real getMinNetworkForce() const;
203 
204  void setMinNetworkForce(agx::Real minForce);
205 
206  agx::Real getMaxNetworkForce() const;
207 
208  void setMaxNetworkForce(agx::Real minForce);
209 
210  protected:
211  virtual ~ParticleContactGraphRenderer();
212 
214  // Variables
216  osg::observer_ptr<osg::Group> m_root;
219  };
220 
221  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setEnable(bool enable) { m_graphDrawable->setEnable(enable); }
222 
223  AGX_FORCE_INLINE bool ParticleContactGraphRenderer::getEnable() const { return m_graphDrawable->getEnable(); }
224 
225  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setMaxNetworkForce(agx::Real maxForce) { m_graphDrawable->setMaxForce(maxForce); }
226 
227  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setMinNetworkForce(agx::Real minForce) { m_graphDrawable->setMinForce(minForce); }
228 
229  AGX_FORCE_INLINE agx::Real ParticleContactGraphRenderer::getMinNetworkForce() const { return m_graphDrawable->getMinForce(); }
230 
231  AGX_FORCE_INLINE agx::Real ParticleContactGraphRenderer::getMaxNetworkForce() const { return m_graphDrawable->getMaxForce(); }
232 
237  {
238  public:
240  agxQt::QtAgxWrapper* qtagxViewer,
241  osg::Group* root,
243  agx::ParticleSystem* system);
244 
245  void setParticleShaderMode(agxOSG::ParticleSystemDrawable::ParticleShaderMode mode);
246 
247  agxOSG::ParticleSystemDrawable::ParticleShaderMode getParticleShaderMode() const;
248 
249  void setAlphaValue(agx::Real alpha);
250 
251  agx::Real getAlphaValue() const;
252 
253  virtual void pre(const agx::TimeStamp& t);
254 
255  virtual void post(const agx::TimeStamp& t);
256 
257  void setParticleColorModeFromName(const agx::String& mode);
258 
259  ParticleColorMode getActiveParticleColorMode() const;
260 
261  ParticleColorModeVector getAvailableColorModes() const;
262 
263  ParticleRenderFilterManager* getParticleRenderFilterManager();
264 
265  void setMaxColorScalar(agx::Real maxVel);
266 
267  void setMinColorScalar(agx::Real minVel);
268 
269  agx::Real getMaxColorScalar() const;
270 
271  agx::Real getMinColorScalar() const;
272 
273  void setAnalysisBox(const agx::AnalysisBox* box);
274 
275  void setLimitColoringToAnalysisBound(bool enable);
276 
277  bool getLimitColoringToAnalysisBound() const;
278 
279  void setShowColorLegend(bool enable, int width, int height);
280 
281  void setShowColorLegend(bool enable);
282 
283  void updateColorLegend(int width, int height);
284 
285  void refreshColorLegend();
286 
287  bool getShowColorLegend() const;
288 
289  void setEnableParticleRendering(bool enable);
290 
291  bool getEnableParticleRendering() const;
292 
293  void preRenderParticles( agx::ParticleSystem * system );
294 
295  void preRenderBodies();
296 
297  ParticleContactGraphRendererRef getParticleContactGraphRenderer();
298 
299  GranularImpactsDrawable* getGranularImpactsDrawable();
300 
301  void addCustomColorers();
302 
303  bool hasOpenColorLegend() const;
304 
305  void resetParticleFilteredState();
306 
307  void setEnableRenderOnNSSBodies(const agx::RigidBodyRefVector& bodies, bool enable);
308 
309  void setEnableRenderingOnTemplateBodies(const agx::RigidBodyRefVector& bodies, bool enable);
310 
311  agxOSG::ParticleSystemDrawable* getParticleSystemDrawable();
312 
313  void setLegendScaleFactor( agx::Real scaleFactor );
314 
315  agx::Real getLegendScaleFactor() const;
316 
317  LegendSettings& getLegendSettings();
318 
319  protected:
320 
321  virtual ~ParticleSystemRenderUtility();
322 
323  void preRender();
324 
325  void resetAlphaOnColors();
326 
327  void setAlphaOnParticles(agx::Real alpha);
328 
329  void removeColorLegend();
330 
332  // Variables
334  protected:
336  osg::ref_ptr<agxOSG::ParticleSystemDrawable> m_psDrawable;
339 
340  // color renderer
341  osg::ref_ptr<osg::Group> m_hudGroup;
342  osg::observer_ptr<osg::Group> m_root;
344 
345 
349 
350  // Impacts drawable
351  osg::ref_ptr<agxQt::GranularImpactsDrawable> m_impactsDrawable;
353  };
354 
356 
357  /* Implementation */
358 
359  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getAlphaValue() const { return m_alpha; }
360 
361  AGX_FORCE_INLINE ParticleColorMode ParticleSystemRenderUtility::getActiveParticleColorMode() const { return m_particleColorerManager->getActiveParticleColorMode(); }
362 
363  AGX_FORCE_INLINE ParticleColorModeVector ParticleSystemRenderUtility::getAvailableColorModes() const { return m_particleColorerManager->getAvailableParticleColorModes(); }
364 
365  AGX_FORCE_INLINE void ParticleSystemRenderUtility::setLimitColoringToAnalysisBound(bool enable) { m_particleColorerManager->setLimitInBound(enable); }
366 
367  AGX_FORCE_INLINE bool ParticleSystemRenderUtility::getLimitColoringToAnalysisBound() const { return m_particleColorerManager->getLimitInBound(); }
368 
369  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getMinColorScalar() const
370  {
371  if (m_particleColorerManager)
372  return m_particleColorerManager->getMinScalar();
373  else
374  return 0;
375  }
376 
377  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getMaxColorScalar() const
378  {
379  if (m_particleColorerManager)
380  return m_particleColorerManager->getMaxScalar();
381  else
382  return 0;
383  }
384 
385  AGX_FORCE_INLINE bool ParticleSystemRenderUtility::getEnableParticleRendering() const { return m_enableParticleRendering; }
386 
387  AGX_FORCE_INLINE ParticleContactGraphRendererRef ParticleSystemRenderUtility::getParticleContactGraphRenderer() { return m_particleContactGraphRenderer; }
388 
389  AGX_FORCE_INLINE GranularImpactsDrawable* ParticleSystemRenderUtility::getGranularImpactsDrawable() { return m_impactsDrawable; }
390 
391  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getLegendScaleFactor() const { return m_legendSettings.legendScaleFactor; }
392 
393  AGX_FORCE_INLINE LegendSettings& ParticleSystemRenderUtility::getLegendSettings() { return m_legendSettings; }
394 
395  osg::Geode * createCube(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
396  osg::Geode * createCubeLines(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
397  osg::Geode * createPlaneLines(const agx::Vec3& position, const agx::Vec3& normal, agx::Real size);
398 
399 #if AGX_USE_KEYSHOT()
400 
403  class KeyShotParticleDumper
404  {
405  KeyShotParticleDumper();
406  public:
407 
408  static void dumpParticlesInSimulationToKeyShotFile(agxSDK::Simulation * simulation, agx::String filename);
409 
410  static void exportCurrentJournalFrameToBip(int frame,
411  const agx::String& journalFilename,
412  const agx::String& sessionName,
413  const agx::String& bipFile,
414  agxQt::CameraDescription* camera,
416 
417  protected:
419  // Variables
421  };
422 #endif
423 }
424 
425 #endif
agx::UInt m_numTrajectoryPositions
Definition: QtOSGUtils.h:179
agxOSG::ParticleContactGraphDrawable * m_graphDrawable
Definition: QtOSGUtils.h:218
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:337
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:236
agxQt::QtAgxWrapper * m_qtAgxWrapper
Definition: QtOSGUtils.h:335
osg::ref_ptr< agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable
Definition: QtOSGUtils.h:183
agx::ParticleSystem * m_particleSystem
Definition: QtOSGUtils.h:217
osg::ref_ptr< agxQt::GranularImpactsDrawable > m_impactsDrawable
Definition: QtOSGUtils.h:351
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:176
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:216
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:177
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:178
agx::Real legendScaleFactor
Definition: QtOSGUtils.h:63
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:347
osg::ref_ptr< agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable
Definition: QtOSGUtils.h:184
ParticleRenderFilterManagerRef m_particleRenderFilterManager
Definition: QtOSGUtils.h:348
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:83
ParticleContactGraphRendererRef m_particleContactGraphRenderer
Definition: QtOSGUtils.h:346
osg::ref_ptr< agxOSG::ParticleSystemDrawable > m_psDrawable
Definition: QtOSGUtils.h:336
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:341
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:342
Orientation orientation
Definition: QtOSGUtils.h:64
agxOSG::ClipPlane * m_clipPlane
Definition: QtOSGUtils.h:130