AGX Dynamics  2.35.0.1
QtOSGUtils.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
74 
76 
77  bool getEnable() const;
78 
79  void setEnable(bool enable);
80 
81  bool getEnableRendering() const;
82 
83  void setEnableRendering(bool enable);
84 
86 
87  void setIncrement(agx::Real increment);
88 
91 
94 
95  protected:
97 
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 
128 
129  void setEnable( bool enable );
130 
131  bool getEnable() const;
132 
133  void setSampling( agx::Real enable );
134 
136 
137  void reSample();
138 
140 
142 
144 
145  protected:
147 
149  // Variables
152  osg::observer_ptr<osg::Group> m_root;
153  osg::ref_ptr<osg::Geode> m_trajectoryGeode;
156  bool m_enable;
157 
158  osg::ref_ptr < agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable;
159  osg::ref_ptr < agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable;
160  };
161 
163 
164 
166  // ParticleContactGraphRenderer
169  {
170  public:
172 
173  void setEnable(bool enable);
174 
175  bool getEnable() const;
176 
178 
179  void setMinNetworkForce(agx::Real minForce);
180 
182 
183  void setMaxNetworkForce(agx::Real minForce);
184 
185  protected:
187 
189  // Variables
191  osg::observer_ptr<osg::Group> m_root;
194  };
195 
197 
199 
201 
203 
205 
207 
212  {
213  public:
215  agxQt::QtAgxWrapper* qtagxViewer,
216  osg::Group* root,
218  agx::ParticleSystem* system);
219 
221 
223 
225 
226  agx::Real getAlphaValue() const;
227 
228  virtual void pre(const agx::TimeStamp& t);
229 
230  virtual void post(const agx::TimeStamp& t);
231 
233 
235 
237 
239 
241 
243 
245 
247 
249 
250  void setLimitColoringToAnalysisBound(bool enable);
251 
252  bool getLimitColoringToAnalysisBound() const;
253 
254  void setShowColorLegend(bool enable, int width, int height);
255 
256  void setShowColorLegend(bool enable);
257 
258  void updateColorLegend(int width, int height);
259 
261 
262  bool getShowColorLegend() const;
263 
264  void setEnableParticleRendering(bool enable);
265 
266  bool getEnableParticleRendering() const;
267 
269 
271 
273 
275 
277 
278  bool hasOpenColorLegend() const;
279 
281 
282  void setEnableRenderOnNSSBodies(const agx::RigidBodyRefVector& bodies, bool enable);
283 
285 
287 
288  protected:
289 
291 
292  void preRender();
293 
295 
297 
299 
301  // Variables
303  protected:
305  osg::ref_ptr<agxOSG::ParticleSystemDrawable> m_psDrawable;
308 
309  // color renderer
310  osg::ref_ptr<osg::Group> m_hudGroup;
311  osg::observer_ptr<osg::Group> m_root;
312 
316 
317  // Impacts drawable
318  osg::ref_ptr<agxQt::GranularImpactsDrawable> m_impactsDrawable;
320  };
321 
323 
324  /* Implementation */
325 
327 
329 
331 
333 
335 
337  {
339  return m_particleColorerManager->getMinScalar();
340  else
341  return 0;
342  }
343 
345  {
347  return m_particleColorerManager->getMaxScalar();
348  else
349  return 0;
350  }
351 
353 
355 
357 
358  osg::Geode * createCube(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
359  osg::Geode * createCubeLines(const agx::Vec3& position, const agx::Vec3& boxhalfVec3);
360  osg::Geode * createPlaneLines(const agx::Vec3& position, const agx::Vec3& normal, agx::Real size);
361 
362 #if AGX_USE_KEYSHOT()
366  class KeyShotParticleDumper
367  {
368  KeyShotParticleDumper();
369  public:
370 
371  static void dumpParticlesInSimulationToKeyShotFile(agxSDK::Simulation * simulation, agx::String filename);
372 
373  static void exportCurrentJournalFrameToBip(int frame,
374  const agx::String& journalFilename,
375  const agx::String& sessionName,
376  const agx::String& bipFile,
377  agxQt::CameraDescription* camera,
379 
380  protected:
382  // Variables
384  };
385 #endif
386 }
387 
388 #endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
This class wraps the ClipPlane functionality of osg together with a clip node and a clip plane.
Definition: ClipPlane.h:44
Class that represents a linear scalar color map that converts a scalar interval to a specified color ...
Class that describes an abstract camera and it's properties.
Class that is used to manipulate the clip plane in the scene.
Definition: QtOSGUtils.h:61
void updateClipPlaneFromIncrement(agx::Real increment)
void decrementClipPlane()
Decrements the Near plane of the scene in the coupled agxViewer.
agxOSG::ClipPlane * m_clipPlane
Definition: QtOSGUtils.h:105
void setIncrement(agx::Real increment)
void setEnableRendering(bool enable)
void setPosition(agx::Vec3 position)
void setRotation(const agx::Quat &quat)
agx::Real getIncrement() const
void incrementClipPlane()
Increments the Near plane of the scene in the coupled agxViewer.
agx::Quat getRotation() const
virtual ~ClipPlaneController()
Destructor.
bool getEnableRendering() const
const agx::Vec3 BASE_NORMAL
Definition: QtOSGUtils.h:63
void setEnable(bool enable)
agx::Vec3 getPosition() const
ClipPlaneController(agxOSG::ClipPlane *clipPlane)
Constructor.
agx::Real getMinNetworkForce() const
Definition: QtOSGUtils.h:204
agx::ParticleSystem * m_particleSystem
Definition: QtOSGUtils.h:192
void setMinNetworkForce(agx::Real minForce)
Definition: QtOSGUtils.h:202
agxOSG::ParticleContactGraphDrawable * m_graphDrawable
Definition: QtOSGUtils.h:193
agx::Real getMaxNetworkForce() const
Definition: QtOSGUtils.h:206
ParticleContactGraphRenderer(osg::Group *root, agx::ParticleSystem *ps)
void setMaxNetworkForce(agx::Real minForce)
Definition: QtOSGUtils.h:200
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:191
This utility class is used for post processing of the particle system drawable representation,...
Definition: QtOSGUtils.h:212
void setEnableRenderingOnTemplateBodies(const agx::RigidBodyRefVector &bodies, bool enable)
void updateColorLegend(int width, int height)
virtual void post(const agx::TimeStamp &t)
Called after a step is taken in the simulation Implement this method in the derived class to get call...
void setShowColorLegend(bool enable, int width, int height)
agx::Real getMaxColorScalar() const
Definition: QtOSGUtils.h:344
virtual void pre(const agx::TimeStamp &t)
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
ParticleColorMode getActiveParticleColorMode() const
Definition: QtOSGUtils.h:328
osg::ref_ptr< agxQt::GranularImpactsDrawable > m_impactsDrawable
Definition: QtOSGUtils.h:318
void setEnableRenderOnNSSBodies(const agx::RigidBodyRefVector &bodies, bool enable)
ParticleColorModeVector getAvailableColorModes() const
Definition: QtOSGUtils.h:330
void setParticleColorModeFromName(const agx::String &mode)
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:311
ParticleSystemRenderUtility(agxQt::QtAgxWrapper *qtagxViewer, osg::Group *root, agxOSG::ParticleSystemDrawable *psdraw, agx::ParticleSystem *system)
agx::Real getMinColorScalar() const
Definition: QtOSGUtils.h:336
void setEnableParticleRendering(bool enable)
agxOSG::ParticleSystemDrawable * getParticleSystemDrawable()
agx::ParticleSystem * m_system
Definition: QtOSGUtils.h:306
void setShowColorLegend(bool enable)
ParticleRenderFilterManagerRef m_particleRenderFilterManager
Definition: QtOSGUtils.h:315
void preRenderParticles(agx::ParticleSystem *system)
osg::ref_ptr< agxOSG::ParticleSystemDrawable > m_psDrawable
Definition: QtOSGUtils.h:305
ParticleColorerManagerRef m_particleColorerManager
Definition: QtOSGUtils.h:314
void setParticleShaderMode(agxOSG::ParticleSystemDrawable::ParticleShaderMode mode)
void setAnalysisBox(const agx::AnalysisBox *box)
void setAlphaValue(agx::Real alpha)
void setLimitColoringToAnalysisBound(bool enable)
Definition: QtOSGUtils.h:332
osg::ref_ptr< osg::Group > m_hudGroup
Definition: QtOSGUtils.h:310
void setMinColorScalar(agx::Real minVel)
GranularImpactsDrawable * getGranularImpactsDrawable()
Definition: QtOSGUtils.h:356
ParticleContactGraphRendererRef m_particleContactGraphRenderer
Definition: QtOSGUtils.h:313
bool getLimitColoringToAnalysisBound() const
Definition: QtOSGUtils.h:334
void setMaxColorScalar(agx::Real maxVel)
ParticleRenderFilterManager * getParticleRenderFilterManager()
void setAlphaOnParticles(agx::Real alpha)
ParticleContactGraphRendererRef getParticleContactGraphRenderer()
Definition: QtOSGUtils.h:354
agxQt::QtAgxWrapper * m_qtAgxWrapper
Definition: QtOSGUtils.h:304
agxOSG::ParticleSystemDrawable::ParticleShaderMode getParticleShaderMode() const
Class that wraps SimulationController with an interface that enables QT Gui signals to control the si...
Definition: QtAgxWrapper.h:73
agxOSG::ScalarColorMap * getColorMap()
agx::UInt m_numTrajectoryPositions
Definition: QtOSGUtils.h:154
agx::UInt getMaxPositionPoints()
void setMaxPositionPoints(agx::UInt posPoints)
osg::ref_ptr< agxOSG::ParticleTrajectoriesDrawable > m_particleTrajectoryDrawable
Definition: QtOSGUtils.h:158
TrajectoryRenderer(agxSDK::Simulation *simulation, osg::Group *root, agx::ParticleSystem *ps)
agx::ParticleSystem * m_particleSystem
Definition: QtOSGUtils.h:151
osg::ref_ptr< osg::Geode > m_trajectoryGeode
Definition: QtOSGUtils.h:153
void setEnable(bool enable)
osg::ref_ptr< agxOSG::RigidBodyTrajectoryDrawable > m_RBTrajectorydrawable
Definition: QtOSGUtils.h:159
void setSampling(agx::Real enable)
osg::observer_ptr< osg::Group > m_root
Definition: QtOSGUtils.h:152
agx::Real getSampling() const
void setColorMap(agxOSG::ScalarColorMap *colorMap)
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Derive from this class to implement a listener for simulation step events.
Class that can be used to extract data from elements in a simulation within a specified bound.
Definition: AnalysisBox.h:32
A basic particle system that contains all the storages and buffers required for basic operation and a...
Base class providing referencing counted objects.
Definition: Referenced.h:114
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
Contains classes/utility functions for connecting AGX to QT with OSG.
osg::Geode * createCubeLines(const agx::Vec3 &position, const agx::Vec3 &boxhalfVec3)
osg::Geode * createPlaneLines(const agx::Vec3 &position, const agx::Vec3 &normal, agx::Real size)
osg::Geode * createCube(const agx::Vec3 &position, const agx::Vec3 &boxhalfVec3)
Vec3T< Real > Vec3
The object holding 3 dimensional vectors and providing basic arithmetic.
Definition: agx/Vec3.h:36
AGXCORE_EXPORT Component * root()
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
agx::Real TimeStamp
Definition: TimeStamp.h:26