AGX Dynamics  2.37.2.0
TerrainVoxelRenderer.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 #pragma once
18 
19 #include <agx/config/AGX_USE_AGXTERRAIN.h>
20 #if defined(SWIG) || AGX_USE_AGXTERRAIN()
21 
22 #include <agxOSG/Node.h>
25 
26 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
27 #include <osg/Drawable>
28 #include <osgViewer/Viewer>
29 #include <osgSim/ColorRange>
30 #include <osgSim/ScalarsToColors>
31 #include <osg/Version>
32 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
33 
34 #include <agx/config/AGX_USE_AGXTERRAIN.h>
36 #include <agxTerrain/Terrain.h>
37 #include <agx/Task.h>
38 
39 namespace agxOSG
40 {
42 
47  {
48  public:
53  static TerrainVoxelRenderer* find( const agxTerrain::Terrain* terrain, const agxSDK::Simulation* simulation );
54 
55  public:
57  {
59  COMPACTION
60  };
61 
62  public:
69  TerrainVoxelRenderer( agxTerrain::Terrain* terrain, osg::Group* group );
70 
74  agxTerrain::Terrain* getTerrain() const;
75 
80 
85  void setRenderVoxelSolidMass(bool enable);
86 
90  bool getRenderVoxelSolidMass() const;
91 
96  void setRenderVoxelFluidMass(bool enable);
97 
101  bool getRenderVoxelFluidMass() const;
102 
107  void setRenderVoxelBoundingBox(bool enable);
108 
112  bool getRenderVoxelBoundingBox() const;
113 
118  void setRenderHeightField(bool enable);
119 
123  bool getRenderHeightField() const;
124 
129  void setRenderVoxelCompaction(bool enable);
130 
134  bool getRenderVoxelCompaction() const;
135 
140  void setRenderTerrainMaterials(bool enable);
141 
145  bool getRenderTerrainMaterials() const;
146 
147 
153  void setRenderDefaultTerrainMaterial(bool enable);
154 
158  bool getRenderDefaultTerrainMaterial() const;
159 
163  void setTerrainMaterialsColors(const agxRender::ColorVector& colors);
164 
168  agxRender::ColorVector getTerrainMaterialColors() const;
169 
174  void setRenderVelocityField(bool enable);
175 
179  bool getRenderVelocityField() const;
180 
185  void setRenderSoilParticles(bool enable);
186 
190  bool getRenderSoilParticles() const;
191 
196  void setRenderSoilParticlesMesh(bool enable);
197 
201  bool getRenderSoilParticlesMesh() const;
202 
208  void setSoilParticleMeshData( const agx::String& modelFilename, const agx::String& textureFilename = "" );
209 
213  const agx::String& getSoilParticleMeshModelFilename() const;
214 
218  const agx::String& getSoilParticleMeshTextureFilename() const;
219 
228  void setRenderHeights(bool enable, agx::RangeReal heightRange = agx::RangeReal());
229 
233  bool getRenderHeights() const;
234 
240  void setRenderCompaction(bool enable, agx::RangeReal compactionRange = agx::RangeReal( 0.75, 1.5 ));
241 
245  bool getRenderCompaction() const;
246 
251  void setColor(agx::Vec4f color);
252 
256  agx::Vec4f getColor() const;
257 
262  void setVelocityFieldLineColor(const agx::Vec4& lineColor);
263 
268  void setMaxVoxelValueColor(const agx::Vec4f& maxVoxelColor);
269 
270 #ifndef SWIG
271  public:
272  struct ContextData
273  {
274  ContextData();
275  ~ContextData();
276 
277  agx::Bool isValid() const;
278 
279  osg::ref_ptr<agxOSG::GeometryNode> node;
280  osg::observer_ptr<osg::Group> parent;
281  osg::ref_ptr<osg::Geometry> geometry;
282  osg::ref_ptr<osg::Geode> geode;
283  osg::StateSet* stateSet;
284 
285  osg::ref_ptr<osgSim::ColorRange> colorRange;
286  osg::ref_ptr<osg::Vec4Array> colorArray;
287  };
288 
290  {
291  osg::ref_ptr<osg::Node> node;
292  osg::ref_ptr<osg::Group> group;
295  };
296 
297  public:
298  virtual void addNotification() override;
299  virtual void removeNotification() override;
300  virtual void last( const agx::TimeStamp& ) override;
301 #endif
302 
303  protected:
304  virtual ~TerrainVoxelRenderer();
305 
306  protected:
311  osg::ref_ptr<TerrainVoxelDrawable> m_voxelDrawable;
312  osg::ref_ptr<SoilParticleSystemDrawable> m_soilParticleDrawable;
314  };
315 }
316 #endif
osg::ref_ptr< TerrainVoxelDrawable > m_voxelDrawable
osg::ref_ptr< osgSim::ColorRange > colorRange
#define AGXOSG_EXPORT
Derive from this class to implement a listener for simulation step events.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
bool Bool
Definition: Integer.h:48
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
agxTerrain::TerrainObserver m_terrain
Vec4T< Real > Vec4
Definition: Vec4.h:25
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
osg::ref_ptr< SoilParticleSystemDrawable > m_soilParticleDrawable
agx::Real TimeStamp
Definition: TimeStamp.h:26
Templated vector class.
Definition: Vector.h:52
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
Definition: WireUtils.h:392
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
osg::observer_ptr< osg::Group > parent
SoilParticleMeshData m_soilParticleMeshData
osg::ref_ptr< osg::Vec4Array > colorArray
A node that can be associated with a collision geometry so that the transformation of this node is up...
Definition: GeometryNode.h:41
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
Rendering class for the agxTerrain::Terrain.
osg::ref_ptr< agxOSG::GeometryNode > node