AGXDynamics  2.31.1.0
QtOSGUtils.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
23 #include <agxQt/ui_RenderController.h>
24 #include <QWidget>
25 #include <osgViewer/ViewerEventHandlers>
26 #include <osg/Group>
27 #include <osgViewer/Renderer>
28 #include <osgSim/ColorRange>
29 #include <osgSim/ScalarsToColors>
30 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
31 
34 #include <agxQt/ParticleFilters.h>
35 #include <agxQt/CameraViewSet.h>
36 #include <agx/Referenced.h>
41 #include <agxOSG/ClipPlane.h>
44 
45 namespace agxOSG
46 {
47  class SceneDecorator;
48  class Node;
49  class Group;
50 }
51 
52 namespace agxQt
53 {
54  class QtAgxWrapper;
55 
61  {
62  public:
63  const agx::Vec3 BASE_NORMAL = agx::Vec3(0, 1, 0);
64 
65  public:
68 
69  void setPosition( agx::Vec3 position );
70 
71  void setRotation(const agx::Quat& quat );
72 
73  agx::Vec3 getPosition() const;
74 
75  agx::Quat getRotation() const;
76 
77  bool getEnable() const;
78 
79  void setEnable(bool enable);
80 
81  bool getEnableRendering() const;
82 
83  void setEnableRendering(bool enable);
84 
85  agx::Real getIncrement() const;
86 
87  void setIncrement(agx::Real increment);
88 
90  void incrementClipPlane();
91 
93  void decrementClipPlane();
94 
95  protected:
96  void updateClipPlaneFromIncrement( agx::Real increment );
97 
99  virtual ~ClipPlaneController();
100 
102  // Variables
104  protected:
109  };
110 
112 
114  // ParticleTrajectoryRenderer
117  {
119 
120  public:
122  osg::Group* root,
123  agx::ParticleSystem* ps );
124 
125  void setMaxPositionPoints( agx::UInt posPoints );
126 
127  agx::UInt getMaxPositionPoints();
128 
129  void setEnable( bool enable );
130 
131  bool getEnable() const;
132 
133  void setSampling( agx::Real enable );
134 
135  agx::Real getSampling() const;
136 
137  void reSample();
138 
139  void resetTrajectoires();
140 
141  protected:
142  virtual ~TrajectoryRenderer();
143 
145  // Variables
148  osg::observer_ptr<osg::Group> m_root;
149  osg::ref_ptr<osg::Geode> m_trajectoryGeode;
152  bool m_enable;
153 
154  osg::ref_ptr < agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable;
155  osg::ref_ptr < agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable;
156  };
157 
159 
160 
162  // ParticleContactGraphRenderer
165  {
166  public:
168 
169  void setEnable(bool enable);
170 
171  bool getEnable() const;
172 
173  agx::Real getMinNetworkForce() const;
174 
175  void setMinNetworkForce(agx::Real minForce);
176 
177  agx::Real getMaxNetworkForce() const;
178 
179  void setMaxNetworkForce(agx::Real minForce);
180 
181  protected:
182  virtual ~ParticleContactGraphRenderer();
183 
185  // Variables
187  osg::observer_ptr<osg::Group> m_root;
190  };
191 
192  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setEnable(bool enable) { m_graphDrawable->setEnable(enable); }
193 
194  AGX_FORCE_INLINE bool ParticleContactGraphRenderer::getEnable() const { return m_graphDrawable->getEnable(); }
195 
196  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setMaxNetworkForce(agx::Real maxForce) { m_graphDrawable->setMaxForce(maxForce); }
197 
198  AGX_FORCE_INLINE void ParticleContactGraphRenderer::setMinNetworkForce(agx::Real minForce) { m_graphDrawable->setMinForce(minForce); }
199 
200  AGX_FORCE_INLINE agx::Real ParticleContactGraphRenderer::getMinNetworkForce() const { return m_graphDrawable->getMinForce(); }
201 
202  AGX_FORCE_INLINE agx::Real ParticleContactGraphRenderer::getMaxNetworkForce() const { return m_graphDrawable->getMaxForce(); }
203 
208  {
209  public:
211  agxQt::QtAgxWrapper* qtagxViewer,
212  osg::Group* root,
214  agx::ParticleSystem* system);
215 
216  void setParticleShaderMode(agxOSG::ParticleSystemDrawable::ParticleShaderMode mode);
217 
218  agxOSG::ParticleSystemDrawable::ParticleShaderMode getParticleShaderMode() const;
219 
220  void setAlphaValue(agx::Real alpha);
221 
222  agx::Real getAlphaValue() const;
223 
224  virtual void pre(const agx::TimeStamp& t);
225 
226  virtual void post(const agx::TimeStamp& t);
227 
228  void setParticleColorModeFromName(const agx::String& mode);
229 
230  ParticleColorMode getActiveParticleColorMode() const;
231 
232  ParticleColorModeVector getAvailableColorModes() const;
233 
234  ParticleRenderFilterManager* getParticleRenderFilterManager();
235 
236  void setMaxColorScalar(agx::Real maxVel);
237 
238  void setMinColorScalar(agx::Real minVel);
239 
240  agx::Real getMaxColorScalar() const;
241 
242  agx::Real getMinColorScalar() const;
243 
244  void setAnalysisBox(const agx::AnalysisBox* box);
245 
246  void setLimitColoringToAnalysisBound(bool enable);
247 
248  bool getLimitColoringToAnalysisBound() const;
249 
250  void setShowColorLegend(bool enable, int width, int height);
251 
252  void setShowColorLegend(bool enable);
253 
254  void updateColorLegend(int width, int height);
255 
256  void refreshColorLegend();
257 
258  bool getShowColorLegend() const;
259 
260  void setEnableParticleRendering(bool enable);
261 
262  bool getEnableParticleRendering() const;
263 
264  void colorParticlesWithActivePostProcess(agx::ParticleSystem * system);
265 
266  ParticleContactGraphRendererRef getParticleContactGraphRenderer();
267 
268  GranularImpactsDrawable* getGranularImpactsDrawable();
269 
270  void addCustomColorers();
271 
272  bool hasOpenColorLegend() const;
273 
274  void resetParticleFilteredState();
275 
276  protected:
277 
278  virtual ~ParticleSystemRenderUtility();
279 
280  void preRender();
281 
282  void resetAlphaOnColors();
283 
284  void setAlphaOnParticles(agx::Real alpha);
285 
286  void removeColorLegend();
287 
289  // Variables
291  protected:
296 
297  // color renderer
298  osg::ref_ptr<osg::Group> m_hudGroup;
299  osg::observer_ptr<osg::Group> m_root;
300 
304 
305  // Impacts drawable
306  osg::ref_ptr<agxQt::GranularImpactsDrawable> m_impactsDrawable;
307  };
308 
310 
311  /* Implementation */
312 
313  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getAlphaValue() const { return m_alpha; }
314 
315  AGX_FORCE_INLINE ParticleColorMode ParticleSystemRenderUtility::getActiveParticleColorMode() const { return m_particleColorerManager->getActiveParticleColorMode(); }
316 
317  AGX_FORCE_INLINE ParticleColorModeVector ParticleSystemRenderUtility::getAvailableColorModes() const { return m_particleColorerManager->getAvailableParticleColorModes(); }
318 
319  AGX_FORCE_INLINE void ParticleSystemRenderUtility::setLimitColoringToAnalysisBound(bool enable) { m_particleColorerManager->setLimitInBound(enable); }
320 
321  AGX_FORCE_INLINE bool ParticleSystemRenderUtility::getLimitColoringToAnalysisBound() const { return m_particleColorerManager->getLimitInBound(); }
322 
323  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getMinColorScalar() const
324  {
325  if (m_particleColorerManager)
326  return m_particleColorerManager->getMinScalar();
327  else
328  return 0;
329  }
330 
331  AGX_FORCE_INLINE agx::Real ParticleSystemRenderUtility::getMaxColorScalar() const
332  {
333  if (m_particleColorerManager)
334  return m_particleColorerManager->getMaxScalar();
335  else
336  return 0;
337  }
338 
339  AGX_FORCE_INLINE bool ParticleSystemRenderUtility::getEnableParticleRendering() const { return m_psDrawable != nullptr && m_psDrawable->getEnable(); }
340 
341  AGX_FORCE_INLINE void ParticleSystemRenderUtility::setEnableParticleRendering(bool enable) { if( m_psDrawable != nullptr ) m_psDrawable->setEnable(enable); }
342 
343  AGX_FORCE_INLINE ParticleContactGraphRendererRef ParticleSystemRenderUtility::getParticleContactGraphRenderer() { return m_particleContactGraphRenderer; }
344 
345  AGX_FORCE_INLINE GranularImpactsDrawable* ParticleSystemRenderUtility::getGranularImpactsDrawable() { return m_impactsDrawable; }
346 
347  osg::Geode * createCube(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
348  osg::Geode * createCubeLines(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
349  osg::Geode * createPlaneLines(const agx::Vec3& position, const agx::Vec3& normal, agx::Real size);
350 
351 #if AGX_USE_KEYSHOT()
352 
355  class KeyShotParticleDumper
356  {
357  KeyShotParticleDumper();
358  public:
359 
360  static void dumpParticlesInSimulationToKeyShotFile(agxSDK::Simulation * simulation, agx::String filename);
361 
362  static void exportCurrentJournalFrameToBip(int frame,
363  const agx::String& journalFilename,
364  const agx::String& sessionName,
365  const agx::String& bipFile,
366  agxQt::CameraDescription* camera,
368 
369  protected:
371  // Variables
373  };
374 #endif
375 }
376 
377 #endif
agx::UInt m_numTrajectoryPositions
Definition: QtOSGUtils.h:150
agxOSG::ParticleContactGraphDrawable * m_graphDrawable
Definition: QtOSGUtils.h:189
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:294
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:207
agxQt::QtAgxWrapper * m_qtAgxWrapper
Definition: QtOSGUtils.h:292
osg::ref_ptr< agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable
Definition: QtOSGUtils.h:154
agx::ParticleSystem * m_particleSystem
Definition: QtOSGUtils.h:188
osg::ref_ptr< agxQt::GranularImpactsDrawable > m_impactsDrawable
Definition: QtOSGUtils.h:306
Contains classes/utility functions for connecting AGX to QT with OSG.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGX_FORCE_INLINE
Definition: Object.h:63
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:147
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:187
Base class providing referencing counted objects.
Definition: Referenced.h:113
Templated vector class.
Definition: Vector.h:52
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:148
agxOSG::ParticleSystemDrawable * m_psDrawable
Definition: QtOSGUtils.h:293
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:149
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:302
osg::ref_ptr< agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable
Definition: QtOSGUtils.h:155
ParticleRenderFilterManagerRef m_particleRenderFilterManager
Definition: QtOSGUtils.h:303
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:121
Class that is used to manipulate the clip plane in the scene.
Definition: QtOSGUtils.h:60
ParticleContactGraphRendererRef m_particleContactGraphRenderer
Definition: QtOSGUtils.h:301
double Real
Definition: Real.h:42
AGXCORE_EXPORT Component * root()
Class that wraps SimulationController with an interface that enables QT Gui signals to control the si...
Definition: QtAgxWrapper.h:71
osg::Geode * createCube(const agx::Vec3 &position, const agx::Vec3 &boxhalfVec3)
osg::ref_ptr< osg::Group > m_hudGroup
Definition: QtOSGUtils.h:298
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:299
agxOSG::ClipPlane * m_clipPlane
Definition: QtOSGUtils.h:105