AGXDynamics  2.31.1.0
TerrainVoxelRenderer.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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>
38 #include <agx/Task.h>
39 
40 namespace agxOSG
41 {
42  AGX_DECLARE_POINTER_TYPES(TerrainVoxelRenderer);
43 
47  class AGXOSG_EXPORT TerrainVoxelRenderer : public agxSDK::StepEventListener
48  {
49  public:
54  static TerrainVoxelRenderer* find( const agxTerrain::Terrain* terrain, const agxSDK::Simulation* simulation );
55 
56  public:
57  enum RenderMode
58  {
59  DEPTH,
60  COMPACTION
61  };
62 
63  public:
70  TerrainVoxelRenderer( agxTerrain::Terrain* terrain, osg::Group* group );
71 
75  agxTerrain::Terrain* getTerrain() const;
76 
81 
86  void setRenderVoxelSolidMass(bool enable);
87 
91  bool getRenderVoxelSolidMass() const;
92 
97  void setRenderVoxelFluidMass(bool enable);
98 
102  bool getRenderVoxelFluidMass() const;
103 
108  void setRenderNodes(bool enable);
109 
113  bool getRenderNodes() const;
114 
119  void setRenderVoxelBoundingBox(bool enable);
120 
124  bool getRenderVoxelBoundingBox() const;
125 
130  void setRenderHeightField(bool enable);
131 
135  bool getRenderHeightField() const;
136 
141  void setRenderVoxelCompaction(bool enable);
142 
146  bool getRenderVoxelCompaction() const;
147 
152  void setRenderVelocityField(bool enable);
153 
157  bool getRenderVelocityField() const;
158 
163  void setRenderSoilParticles(bool enable);
164 
168  bool getRenderSoilParticles() const;
169 
174  void setRenderSoilParticlesMesh(bool enable);
175 
179  bool getRenderSoilParticlesMesh() const;
180 
186  void setSoilParticleMeshData( const agx::String& modelFilename, const agx::String& textureFilename = "" );
187 
191  const agx::String& getSoilParticleMeshModelFilename() const;
192 
196  const agx::String& getSoilParticleMeshTextureFilename() const;
197 
206  void setRenderHeights(bool enable, agx::RangeReal heightRange = agx::RangeReal());
207 
211  bool getRenderHeights() const;
212 
218  void setRenderCompaction(bool enable, agx::RangeReal compactionRange = agx::RangeReal( 0.75, 1.5 ));
219 
223  bool getRenderCompaction() const;
224 
229  void setColor(agx::Vec4f color);
230 
234  agx::Vec4f getColor() const;
235 
240  void setVelocityFieldLineColor(const agx::Vec4& lineColor);
241 
246  void setMaxVoxelValueColor(const agx::Vec4f& maxVoxelColor);
247 
248 #ifndef SWIG
249  public:
250  struct ContextData
251  {
252  ContextData();
253  ~ContextData();
254 
255  agx::Bool isValid() const;
256 
257  osg::ref_ptr<agxOSG::GeometryNode> node;
258  osg::observer_ptr<osg::Group> parent;
259  osg::ref_ptr<osg::Geometry> geometry;
260  osg::ref_ptr<osg::Geode> geode;
261  osg::StateSet* stateSet;
262 
263  osg::ref_ptr<osgSim::ColorRange> colorRange;
264  osg::ref_ptr<osg::Vec4Array> colorArray;
265  };
266 
267  struct SoilParticleMeshData
268  {
269  osg::ref_ptr<osg::Node> node;
270  osg::ref_ptr<osg::Group> group;
271  agx::String modelFilename;
272  agx::String textureFilename;
273  };
274 
275  public:
276  virtual void addNotification() override;
277  virtual void removeNotification() override;
278  virtual void last( const agx::TimeStamp& ) override;
279 #endif
280 
281  protected:
282  virtual ~TerrainVoxelRenderer();
283 
284  protected:
285  agxTerrain::TerrainObserver m_terrain;
286  ContextData m_surfaceContextData;
287  ContextData m_heightsContextData;
288  osg::Vec4 m_color;
289  osg::ref_ptr<TerrainVoxelDrawable> m_voxelDrawable;
290  osg::ref_ptr<SoilParticleSystemDrawable> m_soilParticleDrawable;
291  SoilParticleMeshData m_soilParticleMeshData;
292  };
293 }
294 #endif
#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
Smart pointer for observed objects, that automatically set pointers to them to null when they deleted...
Definition: observer_ptr.h:60
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
Vec4T< Real > Vec4
Definition: Vec4.h:25
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agx::Real TimeStamp
Definition: TimeStamp.h:26
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.
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:121