AGX Dynamics  2.35.0.1
TerrainVoxelRenderer.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 #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 {
41  AGX_DECLARE_POINTER_TYPES(TerrainVoxelRenderer);
42 
46  class AGXOSG_EXPORT TerrainVoxelRenderer : public agxSDK::StepEventListener
47  {
48  public:
53  static TerrainVoxelRenderer* find( const agxTerrain::Terrain* terrain, const agxSDK::Simulation* simulation );
54 
55  public:
56  enum RenderMode
57  {
58  DEPTH,
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 setRenderVelocityField(bool enable);
141 
145  bool getRenderVelocityField() const;
146 
151  void setRenderSoilParticles(bool enable);
152 
156  bool getRenderSoilParticles() const;
157 
162  void setRenderSoilParticlesMesh(bool enable);
163 
167  bool getRenderSoilParticlesMesh() const;
168 
174  void setSoilParticleMeshData( const agx::String& modelFilename, const agx::String& textureFilename = "" );
175 
179  const agx::String& getSoilParticleMeshModelFilename() const;
180 
184  const agx::String& getSoilParticleMeshTextureFilename() const;
185 
194  void setRenderHeights(bool enable, agx::RangeReal heightRange = agx::RangeReal());
195 
199  bool getRenderHeights() const;
200 
206  void setRenderCompaction(bool enable, agx::RangeReal compactionRange = agx::RangeReal( 0.75, 1.5 ));
207 
211  bool getRenderCompaction() const;
212 
217  void setColor(agx::Vec4f color);
218 
222  agx::Vec4f getColor() const;
223 
228  void setVelocityFieldLineColor(const agx::Vec4& lineColor);
229 
234  void setMaxVoxelValueColor(const agx::Vec4f& maxVoxelColor);
235 
236 #ifndef SWIG
237  public:
238  struct ContextData
239  {
240  ContextData();
241  ~ContextData();
242 
243  agx::Bool isValid() const;
244 
245  osg::ref_ptr<agxOSG::GeometryNode> node;
246  osg::observer_ptr<osg::Group> parent;
247  osg::ref_ptr<osg::Geometry> geometry;
248  osg::ref_ptr<osg::Geode> geode;
249  osg::StateSet* stateSet;
250 
251  osg::ref_ptr<osgSim::ColorRange> colorRange;
252  osg::ref_ptr<osg::Vec4Array> colorArray;
253  };
254 
255  struct SoilParticleMeshData
256  {
257  osg::ref_ptr<osg::Node> node;
258  osg::ref_ptr<osg::Group> group;
259  agx::String modelFilename;
260  agx::String textureFilename;
261  };
262 
263  public:
264  virtual void addNotification() override;
265  virtual void removeNotification() override;
266  virtual void last( const agx::TimeStamp& ) override;
267 #endif
268 
269  protected:
270  virtual ~TerrainVoxelRenderer();
271 
272  protected:
273  agxTerrain::TerrainObserver m_terrain;
274  ContextData m_surfaceContextData;
275  ContextData m_heightsContextData;
276  osg::Vec4 m_color;
277  osg::ref_ptr<TerrainVoxelDrawable> m_voxelDrawable;
278  osg::ref_ptr<SoilParticleSystemDrawable> m_soilParticleDrawable;
279  SoilParticleMeshData m_soilParticleMeshData;
280  };
281 }
282 #endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#define AGXOSG_EXPORT
A node that can be associated with a collision geometry so that the transformation of this node is up...
Definition: GeometryNode.h:42
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.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
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.
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
bool Bool
Definition: Integer.h:48
Vec4T< Real > Vec4
Definition: Vec4.h:25
agx::Real TimeStamp
Definition: TimeStamp.h:26