AGX Dynamics  2.35.0.1
TerrainVoxelDrawable.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 <agxOSG/export.h>
20 
21 #include <agxTerrain/Terrain.h>
22 
23 #include <agx/Task.h>
24 
25 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
26 #include <osg/Drawable>
27 #include <osg/Version>
28 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
29 
30 namespace osgSim
31 {
32  class ColorRange;
33 }
34 
35 
36 namespace agxOSG
37 {
41  class AGXOSG_EXPORT TerrainVoxelDrawable : public osg::Drawable
42  {
43  public:
45 
46  void setRenderVoxelSolidMass( bool enable );
48 
49  void setRenderVoxelFluidMass( bool enable );
51 
52  void setRenderVoxelBoundingBox( bool enable );
54 
55  void setRenderVoxelCompaction( bool enable );
57 
58  void setRenderVelocityField( bool enable );
59  bool getRenderVelocityField() const;
60 
61  void setVelocityFieldLineColor(const agx::Vec4& lineColor);
62 
63  void setMaxVoxelValueColor(const agx::Vec4f& maxVoxelColor);
64 
68  bool hasEnabledFeatures() const;
69 
73  bool isInitialized() const;
74 
75  virtual osg::Object* cloneType() const { return new TerrainVoxelDrawable(m_terrain); }
76  virtual osg::Object* clone(const osg::CopyOp&) const { return new TerrainVoxelDrawable(*this); }
77  virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const TerrainVoxelDrawable *>(obj) != nullptr; }
78  virtual const char* libraryName() const { return "agxOSG"; }
79  virtual const char* className() const { return "TerrainVoxelDrawable"; }
80 
82 #if OSG_VERSION_GREATER_OR_EQUAL(3,4,0)
83  virtual osg::BoundingSphere computeBound() const;
84  virtual osg::BoundingBox computeBoundingBox() const;
85 #else
86  virtual osg::BoundingBox computeBound() const;
87 #endif
88 
90  virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
91 
93 
94  public:
97 
98  protected:
100 
101 
103  const agxTerrain::BasicGrid* solid,
104  const agx::AffineMatrix4x4& terrainTransform,
105  const agx::HashTable< agx::Vec3i, agx::Vec3f >& velocityTable,
106  agx::Real elementSize,
107  bool enableVelocityFieldRendering,
108  agxData::Buffer* linePositions,
109  agxData::Buffer* lineOffsets);
110 
112  const agxTerrain::BasicGrid* solid,
113  const agxTerrain::BasicGrid* fluid,
114  const agxTerrain::BasicGrid* compaction,
115  const agx::AffineMatrix4x4& terrainTransform,
116  agx::Real elementSize,
117  bool enableRenderVoxelSolidMass,
118  bool enableRenderVoxelFluidMass,
119  bool enableRenderVoxelCompaction,
120  agxData::Buffer* verticesBuffer,
121  agxData::Buffer* colorBuffer,
122  agxData::Buffer* voxelSizeBuffer,
123  agxData::Buffer* enableRenderBuffer,
124  std::function<agx::Vec4f(float)> getColor);
125 
127  const agxTerrain::BasicGrid* solid,
128  const agx::AffineMatrix4x4& terrainTransform,
129  agxData::Buffer* nodesVertices,
130  agxData::Buffer* nodesColorBuffer,
131  agxData::Buffer* nodesFirstBuffer,
132  agxData::Buffer* nodesCountBuffer,
133  bool enableRenderVoxelBoundingBox);
134 
135 
137  // Variables
139  protected:
141  osg::Group* m_group;
143  osg::ref_ptr<osgSim::ColorRange> m_colorRange;
144  bool m_enable;
145  float m_rScaling;
151 
157 
158  // Bounding box data
163 
164  // Velocity field data
168  };
169 }
#define AGXOSG_EXPORT
Abstract representation of a data buffer.
Definition: Buffer.h:56
Internal drawable class for drawing the Voxel grid structure.
virtual osg::Object * clone(const osg::CopyOp &) const
TerrainVoxelDrawable(agxTerrain::Terrain *terrain)
bool getRenderVelocityField() const
osg::ref_ptr< osgSim::ColorRange > m_colorRange
void renderVelocityTableLines(const agxTerrain::BasicGrid *solid, const agx::AffineMatrix4x4 &terrainTransform, const agx::HashTable< agx::Vec3i, agx::Vec3f > &velocityTable, agx::Real elementSize, bool enableVelocityFieldRendering, agxData::Buffer *linePositions, agxData::Buffer *lineOffsets)
virtual osg::BoundingBox computeBound() const
Compute the bounding box around Drawables's geometry.
void renderVoxels(const agxTerrain::BasicGrid *solid, const agxTerrain::BasicGrid *fluid, const agxTerrain::BasicGrid *compaction, const agx::AffineMatrix4x4 &terrainTransform, agx::Real elementSize, bool enableRenderVoxelSolidMass, bool enableRenderVoxelFluidMass, bool enableRenderVoxelCompaction, agxData::Buffer *verticesBuffer, agxData::Buffer *colorBuffer, agxData::Buffer *voxelSizeBuffer, agxData::Buffer *enableRenderBuffer, std::function< agx::Vec4f(float)> getColor)
virtual const char * className() const
bool getRenderVoxelCompaction() const
void setRenderVoxelSolidMass(bool enable)
void setVelocityFieldLineColor(const agx::Vec4 &lineColor)
bool getRenderVoxelSolidMass() const
virtual bool isSameKindAs(const osg::Object *obj) const
bool getRenderVoxelFluidMass() const
agxTerrain::TerrainRef m_terrain
agxData::BufferRef m_voxelEnableRenderBuffer
void onRemoveNotification(agxSDK::Simulation *simulation)
void setMaxVoxelValueColor(const agx::Vec4f &maxVoxelColor)
virtual void drawImplementation(osg::RenderInfo &renderInfo) const
The actual draw method for the merged bodies.
void setRenderVoxelFluidMass(bool enable)
virtual osg::Object * cloneType() const
void onAddNotification(agxSDK::Simulation *simulation)
void setRenderVelocityField(bool enable)
void setRenderVoxelCompaction(bool enable)
bool getRenderVoxelBoundingBox() const
void setRenderVoxelBoundingBox(bool enable)
void renderInternalNodes(const agxTerrain::BasicGrid *solid, const agx::AffineMatrix4x4 &terrainTransform, agxData::Buffer *nodesVertices, agxData::Buffer *nodesColorBuffer, agxData::Buffer *nodesFirstBuffer, agxData::Buffer *nodesCountBuffer, bool enableRenderVoxelBoundingBox)
virtual const char * libraryName() const
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:71
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Inheritance with partial specialization due to bug with ref_ptr containers.
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:35
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
double Real
Definition: Real.h:42