AGX Dynamics  2.37.3.2
PressureRenderer.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 AGXOSG_PRESSURE_RENDERER_H
18 #define AGXOSG_PRESSURE_RENDERER_H
19 
20 #include <agxCollide/Trimesh.h>
23 
24 #include <agxOSG/export.h>
26 #include <agxOSG/Node.h>
27 #include <agxOSG/SceneDecorator.h>
28 
29 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
30 #include <osg/observer_ptr>
31 #include <osgSim/ColorRange>
32 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
33 
34 #include <agxRender/Color.h>
36 
37 namespace osg
38 {
39  class Group;
40 }
41 
42 
43 
44 namespace agxOSG
45 {
51  {
52  public:
64  osg::Group* root,
65  agxOSG::SceneDecorator* decorator,
66  agxSDK::Simulation* simulation,
67  osgSim::ColorRange* colorRange = new osgSim::ColorRange(0.0f, 1.0e5f),
68  const agx::Real texelsPerMeter = agx::Real(50),
69  const agx::Real rangeFactor = agx::Real(2.0e-5),
71  );
72 
86  osg::Group* root,
87  agxOSG::SceneDecorator* decorator,
88  agxSDK::Simulation* simulation,
89  const agx::Real minPressure,
90  const agx::Real maxPressure,
91  const agxRender::ColorVector& colors,
92  const agx::Real texelsPerMeter = agx::Real(50),
93  const agx::Real rangeFactor = agx::Real(2.0e-5),
95  );
96 
106  bool addTrimesh(agxCollide::Trimesh* trimesh, bool keepGeometryNode = false);
107 
118  bool addGeometry(agxCollide::Geometry* geometry, bool keepGeometryNode = false);
119 
120 
129  bool startMaxAvgRecording();
130 
140  size_t stopMaxAvgRecording();
141 
145  bool isRecording();
146 
150  size_t getNumRecordings();
151 
165  bool renderMaxPressure(size_t recording);
166 
180  bool renderAvgPressure(size_t recording);
181 
189  bool restoreRendering();
190 
192  void setEnableLegend(bool flag);
193 
195  agx::Vec2 getLegendPosition() const;
196 
198  void setLegendPosition(const agx::Vec2& pos);
199 
201  osgSim::ColorRange* getColorRange();
202 
204  agxOSG::PressureAtlasManager* getPressureAtlasManager();
205 
213  void addFilter(agxSDK::ExecuteFilter* filter);
214 
215 
216  protected:
217  virtual ~PressureRenderer();
218 
219  // Helper function used by render[Max|Avg]Pressure.
220  bool renderPressure(size_t recording, bool useMax);
221 
222  // Trigger a color conversion for the recording currently being recorded.
223  // Only valid between calls to startMaxAvgRecording() and
224  // stopMaxAvgRecording(). Called from stopMaxAvgRecording() right before
225  // copying color information to the recordings list.
226  void updateTextureData();
227 
228  // Remove the maximum- and average gatherers from their respective PressureAtlases.
229  void unregisterRecorders();
230 
231  protected:
233  osg::observer_ptr<osg::Group> m_root;
234  osg::observer_ptr<agxOSG::SceneDecorator> m_decorator;
236  osg::ref_ptr<osgSim::ColorRange> m_colorRange; // Holds min pressure, max pressure, and colors.
237  osg::ref_ptr<agxOSG::Transform> m_legendTransform; // Holding the transform to the HUD-legend.
241 
242 
243  /*
244  * Data used during recording. On per measured mesh.
245  */
246  struct MaxAvgData {
247  MaxAvgData(const agxCollide::TrimeshConstObserver mesh, GatherMaxPressureRef maxGatherer, GatherAvgPressureRef avgGatherer, osg::Group* root);
248  osg::Texture2D* getTexture(osg::Group* root);
249 
253  osg::ref_ptr<osg::Image> originalTextureImage; // Borrowed from the osg::Texture2D originaly used to render the mesh.
254  private:
255  // Hiding assignment
256  MaxAvgData& operator=(const MaxAvgData&) {return *this;}
257 
258  };
259 
260  // Non-empty while recording. One element per measured mesh.
262 
263 
264  /*
265  * Data held for each mesh for each finished recording.
266  */
268  MaxAvgRecording(const MaxAvgData& data);
269  osg::Texture2D* getTexture(osg::Group* root);
270 
272  osg::ref_ptr<osg::Image> maxPressure; // Copy of the color map generated by a MaxAvgData::maxGatherer.
273  osg::ref_ptr<osg::Image> avgPressure; // Copy of the color map generated by a MaxAvgData::avgGatherer.
274  osg::ref_ptr<osg::Image> originalTextureImage; // Given from MaxAvgData upon stopMaxAvgRecording().
275  private:
276  // Hiding assignment
277  MaxAvgRecording& operator=(const MaxAvgRecording&) {return *this;}
278  };
279 
280  // Vector holding all recorded data for a particular recording.
282 
283  // Vector holding all recordings. Recording IDs are indices into this vector.
285 
286  // The record ID that is currently being used for rendering.
288 
289  // The type of force to register. Normal, tangential or both.
291  private:
292  // Hiding assignment
293  PressureRenderer& operator=(const PressureRenderer&) {return *this;}
294  };
295 }
296 
297 
298 #endif
osg::ref_ptr< osg::Image > originalTextureImage
osg::observer_ptr< osg::Group > m_root
#define AGXOSG_EXPORT
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:60
const agxOSG::PressureFromContacts::ForceType m_forceType
Abstract base class that implements a filter that selects which events should trigger a Listener...
Definition: ExecuteFilter.h:33
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agx::Vector< MaxAvgData > m_maxAvgData
agx::Vector< MaxAvgRecording > MaxAvgRecordingVector
const agxCollide::TrimeshConstObserver mesh
Decorates a scene with a specific AGX Rendering Style.
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
ForceType
The type of force to add. Tangential (friction) only, normal only, or both.
agx::Vector< MaxAvgRecordingVector > m_maxAvgRecordings
agxOSG::PressureAtlasManagerRef m_atlasManager
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
const agxCollide::TrimeshConstObserver mesh
An utility class for handling of pressure rendering and legend.
osg::ref_ptr< osgSim::ColorRange > m_colorRange
agx::Vector< agxCollide::TrimeshRef > m_meshes
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
osg::ref_ptr< osg::Image > originalTextureImage
agx::Vector< agxSDK::ExecuteFilterRef > m_filters
double Real
Definition: Real.h:42
AGXCORE_EXPORT Component * root()
osg::ref_ptr< agxOSG::Transform > m_legendTransform
osg::observer_ptr< agxOSG::SceneDecorator > m_decorator
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:42