AGX Dynamics  2.35.0.1
PressureAtlas.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_ATLAS
18 #define AGXOSG_PRESSURE_ATLAS
19 
20 #include <agx/Referenced.h>
21 
22 #include <agxCollide/Trimesh.h>
23 
24 #include <agxOSG/export.h>
27 
28 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
29 #include <osg/Geometry>
30 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
31 
32 namespace agxOSG
33 {
34  class GeometryNode;
36 
37 
44  {
45  public:
46  PressureAtlas(const agxCollide::Trimesh* mesh, agx::Real texelsPerMeter);
47 
49 
59 
60 
77  void addPressure(const agx::Vec3& point, agx::UInt32 triangleIndex, agx::Real magnitude, agx::Real radius);
78 
83  void clearPressure();
84 
85 
93  bool isDirty() const;
94 
95 
102  bool isPressurized() const;
103 
104 
106 
107 
118 
119 
131 
132 
137 
144  osg::Image* getPressureMap();
145 
147 
152  osg::Geometry* getGraphicsMesh();
153 
158 
159 
161 
162 
164  size_t getNumTriangles() const;
165 
170  size_t getNumVertices() const;
171 
172  size_t getVertexIndex(size_t triangleIndex, size_t localVertexIndex) const;
173 
174  protected:
175  virtual ~PressureAtlas() {}
176 
177  private:
178  void createGraphicsMesh();
179  osg::Geometry* createOsgMesh(const agxCollide::Trimesh* mesh);
180  void createAtlas();
181  // Hiding assignment
182  PressureAtlas& operator=(const PressureAtlas&) {return *this;}
183 
184 
185  agx::UInt32 nextTriangle();
186  void queuePartnersInRange(agxCollide::Mesh::Triangle& triangle, const agx::Vec3& point, agx::Real radiusSquared);
187  bool isInRange(const agx::Vec3& point, const agxCollide::Mesh::Triangle& triangle, agx::Real radiusSquared);
188  bool colorTriangle(const agxCollide::Mesh::Triangle& triangle, const agx::Vec3& point,
189  const agx::Real radius, const agx::Real radiusSquared,
190  const agx::Real centerMagnitude);
191 
192 
193  private:
194 
196  const agxCollide::TrimeshConstRef m_physicsMesh;
197 
199  osg::ref_ptr<osg::Geometry> m_graphicsMesh;
200 
202  agx::Real m_texelsPerMeter;
203 
209  osg::ref_ptr<osg::Image> m_pressureMap;
210 
215  PressureGeneratorRefVector m_pressureGenerators;
216 
221  PressureToColorConverterRefVector m_colorGenerators;
222 
223 
225  agx::HashSet<agx::UInt32> m_consideredTriangles;
226 
228  agx::Vector<agx::UInt32> m_queuedTriangles;
229 
234  bool m_dirty;
235 
240  bool m_pressurized;
241  };
242 
243 }
244 
245 #endif
246 
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
Class for more intuitive access to the Mesh's mesh data.
Definition: Mesh.h:79
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:43
A node that can be associated with a collision geometry so that the transformation of this node is up...
Definition: GeometryNode.h:42
A pressure map for a single trimesh.
Definition: PressureAtlas.h:44
osg::Geometry * getGraphicsMesh()
Returns an OSG Geometry that can be used to render the collected pressure.
bool isDirty() const
Check if the pressure map is dirty.
PressureAtlas(const agxCollide::Trimesh *mesh, agx::Real texelsPerMeter)
osg::Image * getPressureMap()
Returns the pressure map.
void clearPressure()
Fill the pressure map with zeros.
bool registerPressureGenerator(agxOSG::PressureGenerator *generator)
Let this PressureAtlas take over overship of the given pressure generator.
agxOSG::GeometryNode * createAtlasRendering()
void updateColorImages()
Trigger a color conversion on all converters, if the pressure map is dirty.
bool registerColorConverter(agxOSG::PressureToColorConverter *colorConverter)
Make the given color converter perform color conversion on this atlas' pressure map when PressureAtla...
size_t getVertexIndex(size_t triangleIndex, size_t localVertexIndex) const
void addPressure(const agx::Vec3 &point, agx::UInt32 triangleIndex, agx::Real magnitude, agx::Real radius)
Add a pressure sphere centered at 'point', given in the mesh's coordinate system, The given 'magnitud...
const agxCollide::Trimesh * getPhysicsMesh()
size_t getNumVertices() const
bool unregisterColorConverter(agxOSG::PressureToColorConverter *colorConverter)
Cause the given color converter to no longer receive update calls from PressureAtlas::updateColorImag...
bool isPressurized() const
Check if the pressure map is pressurized.
size_t getNumTriangles() const
osg::Vec2Array & getTextureCoordinates()
Base class for types that want to supply force updates to a PressureAtlas.
Base class providing referencing counted objects.
Definition: Referenced.h:114
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
agx::Vector< PressureToColorConverterRef > PressureToColorConverterRefVector
agx::Vector< PressureGeneratorRef > PressureGeneratorRefVector
uint32_t UInt32
Definition: Integer.h:40
agxData::Array< agx::Vec2 > Vec2Array
double Real
Definition: Real.h:42