AGX Dynamics  2.35.0.1
PressureRenderer.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, is 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 
130 
141 
145  bool isRecording();
146 
151 
165  bool renderMaxPressure(size_t recording);
166 
180  bool renderAvgPressure(size_t recording);
181 
190 
192  void setEnableLegend(bool flag);
193 
196 
198  void setLegendPosition(const agx::Vec2& pos);
199 
201  osgSim::ColorRange* getColorRange();
202 
205 
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.
227 
228  // Remove the maximum- and average gatherers from their respective PressureAtlases.
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 {
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  */
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:43
ForceType
The type of force to add. Tangential (friction) only, normal only, or both.
An utility class for handling of pressure rendering and legend.
agxOSG::PressureAtlasManagerRef m_atlasManager
agx::Vector< agxCollide::TrimeshRef > m_meshes
osg::ref_ptr< osgSim::ColorRange > m_colorRange
size_t stopMaxAvgRecording()
Stop the current recording.
agx::Vector< agxSDK::ExecuteFilterRef > m_filters
agx::Vector< MaxAvgRecordingVector > m_maxAvgRecordings
PressureRenderer(osg::Group *root, agxOSG::SceneDecorator *decorator, agxSDK::Simulation *simulation, const agx::Real minPressure, const agx::Real maxPressure, const agxRender::ColorVector &colors, const agx::Real texelsPerMeter=agx::Real(50), const agx::Real rangeFactor=agx::Real(2.0e-5), agxOSG::PressureFromContacts::ForceType forceType=agxOSG::PressureFromContacts::TOTAL_FORCE)
Constructor using agx data.
agx::Vector< MaxAvgRecording > MaxAvgRecordingVector
const agxOSG::PressureFromContacts::ForceType m_forceType
PressureRenderer(osg::Group *root, agxOSG::SceneDecorator *decorator, agxSDK::Simulation *simulation, osgSim::ColorRange *colorRange=new osgSim::ColorRange(0.0f, 1.0e5f), const agx::Real texelsPerMeter=agx::Real(50), const agx::Real rangeFactor=agx::Real(2.0e-5), agxOSG::PressureFromContacts::ForceType forceType=agxOSG::PressureFromContacts::TOTAL_FORCE)
Constructor using osg color range directly.
bool renderPressure(size_t recording, bool useMax)
osgSim::ColorRange * getColorRange()
Gets the color range.
bool renderMaxPressure(size_t recording)
Replace the texture data for measured geometries with a recorded maximum pressure.
agx::Vector< MaxAvgData > m_maxAvgData
bool startMaxAvgRecording()
Start recording of maximum and average pressure for each pressure atlas currently owned by this Press...
agxOSG::PressureAtlasManager * getPressureAtlasManager()
Gets the pressure atlas manager.
bool addGeometry(agxCollide::Geometry *geometry, bool keepGeometryNode=false)
Adds all shapes in a geometry to the pressure rendering.
bool restoreRendering()
Disable rendering of recorded maximum or average data.
void setEnableLegend(bool flag)
Enables/disables legend in HUD.
osg::observer_ptr< agxOSG::SceneDecorator > m_decorator
osg::observer_ptr< osg::Group > m_root
osg::ref_ptr< agxOSG::Transform > m_legendTransform
void addFilter(agxSDK::ExecuteFilter *filter)
Add a contact filter.
bool renderAvgPressure(size_t recording)
Replace the texture data for measured geometries with a recorded average pressure.
agx::Vec2 getLegendPosition() const
Returns the legend center position in relative screen space (0 to 1).
void setLegendPosition(const agx::Vec2 &pos)
Sets the legend center position in relative screen space (0 to 1).
bool addTrimesh(agxCollide::Trimesh *trimesh, bool keepGeometryNode=false)
Adds a trimesh to the pressure rendering.
Decorates a scene with a specific AGX Rendering Style.
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:35
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Base class providing referencing counted objects.
Definition: Referenced.h:114
Templated vector class.
Definition: agx/Vector.h:53
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:61
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
AGXCORE_EXPORT Component * root()
double Real
Definition: Real.h:42
const agxCollide::TrimeshConstObserver mesh
osg::Texture2D * getTexture(osg::Group *root)
MaxAvgData(const agxCollide::TrimeshConstObserver mesh, GatherMaxPressureRef maxGatherer, GatherAvgPressureRef avgGatherer, osg::Group *root)
osg::ref_ptr< osg::Image > originalTextureImage
MaxAvgRecording(const MaxAvgData &data)
osg::Texture2D * getTexture(osg::Group *root)
const agxCollide::TrimeshConstObserver mesh
osg::ref_ptr< osg::Image > originalTextureImage