AGXDynamics  2.35.0.3
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 );
47  bool getRenderVoxelSolidMass() const;
48 
49  void setRenderVoxelFluidMass( bool enable );
50  bool getRenderVoxelFluidMass() const;
51 
52  void setRenderVoxelBoundingBox( bool enable );
53  bool getRenderVoxelBoundingBox() const;
54 
55  void setRenderVoxelCompaction( bool enable );
56  bool getRenderVoxelCompaction() const;
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 
92  void updateDrawable();
93 
94  public:
95  void onAddNotification( agxSDK::Simulation* simulation );
96  void onRemoveNotification( agxSDK::Simulation* simulation );
97 
98  protected:
99  virtual ~TerrainVoxelDrawable();
100 
101 
102  void renderVelocityTableLines(
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 
111  void renderVoxels(
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 
126  void renderInternalNodes(
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 }
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: agxTerrain/Terrain.h:85
agx::Real
double Real
Definition: Real.h:42
agxOSG::TerrainVoxelDrawable::m_voxelEnableRenderBuffer
agxData::BufferRef m_voxelEnableRenderBuffer
Definition: TerrainVoxelDrawable.h:155
Task.h
agxOSG::TerrainVoxelDrawable::libraryName
virtual const char * libraryName() const
Definition: TerrainVoxelDrawable.h:78
agxOSG::TerrainVoxelDrawable::m_enableRenderVoxelSolidMass
bool m_enableRenderVoxelSolidMass
Definition: TerrainVoxelDrawable.h:146
agx::AffineMatrix4x4T< Real >
agxOSG::TerrainVoxelDrawable::m_colorBuffer
agxData::BufferRef m_colorBuffer
Definition: TerrainVoxelDrawable.h:153
agx::Vec4T
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
agxOSG::TerrainVoxelDrawable::m_lineOffsets
agxData::BufferRef m_lineOffsets
Definition: TerrainVoxelDrawable.h:166
agxOSG::TerrainVoxelDrawable::m_lineKernel
agx::TaskRef m_lineKernel
Definition: TerrainVoxelDrawable.h:167
agxOSG::TerrainVoxelDrawable::m_group
osg::Group * m_group
Definition: TerrainVoxelDrawable.h:141
agxOSG::TerrainVoxelDrawable::isSameKindAs
virtual bool isSameKindAs(const osg::Object *obj) const
Definition: TerrainVoxelDrawable.h:77
agxOSG::TerrainVoxelDrawable::m_enableRenderVoxelBoundingBox
bool m_enableRenderVoxelBoundingBox
Definition: TerrainVoxelDrawable.h:149
agx::ref_ptr< Terrain >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agxOSG
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
PushDisableWarnings.h
agxOSG::TerrainVoxelDrawable::clone
virtual osg::Object * clone(const osg::CopyOp &) const
Definition: TerrainVoxelDrawable.h:76
agxOSG::TerrainVoxelDrawable::m_renderTask
agx::TaskGroupRef m_renderTask
Definition: TerrainVoxelDrawable.h:142
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:871
agxData::Buffer
Abstract representation of a data buffer.
Definition: Buffer.h:55
agxOSG::TerrainVoxelDrawable::m_colorRange
osg::ref_ptr< osgSim::ColorRange > m_colorRange
Definition: TerrainVoxelDrawable.h:143
agxOSG::TerrainVoxelDrawable::m_terrain
agxTerrain::TerrainRef m_terrain
Definition: TerrainVoxelDrawable.h:140
agxTerrain::BasicGrid
Pure virtual interface class for the data storage grid classes we have.
Definition: Grid.h:70
agxOSG::TerrainVoxelDrawable::cloneType
virtual osg::Object * cloneType() const
Definition: TerrainVoxelDrawable.h:75
agxOSG::TerrainVoxelDrawable::m_enableVelocityFieldRendering
bool m_enableVelocityFieldRendering
Definition: TerrainVoxelDrawable.h:150
agxOSG::TerrainVoxelDrawable::m_voxelSizeBuffer
agxData::BufferRef m_voxelSizeBuffer
Definition: TerrainVoxelDrawable.h:154
agxOSG::TerrainVoxelDrawable::m_enableRenderVoxelFluidMass
bool m_enableRenderVoxelFluidMass
Definition: TerrainVoxelDrawable.h:147
agxOSG::TerrainVoxelDrawable::m_nodesCountBuffer
agxData::BufferRef m_nodesCountBuffer
Definition: TerrainVoxelDrawable.h:161
agxOSG::TerrainVoxelDrawable
Internal drawable class for drawing the Voxel grid structure.
Definition: TerrainVoxelDrawable.h:41
agxOSG::TerrainVoxelDrawable::m_verticesBuffer
agxData::BufferRef m_verticesBuffer
Definition: TerrainVoxelDrawable.h:152
agxBrick::isInitialized
AGXBRICK_EXPORT bool isInitialized()
agxOSG::TerrainVoxelDrawable::m_nodesVertices
agxData::BufferRef m_nodesVertices
Definition: TerrainVoxelDrawable.h:159
export.h
agxOSG::TerrainVoxelDrawable::m_nodesColorBuffer
agxData::BufferRef m_nodesColorBuffer
Definition: TerrainVoxelDrawable.h:160
agxOSG::TerrainVoxelDrawable::m_enable
bool m_enable
Definition: TerrainVoxelDrawable.h:144
agxOSG::TerrainVoxelDrawable::m_rScaling
float m_rScaling
Definition: TerrainVoxelDrawable.h:145
agxOSG::TerrainVoxelDrawable::m_linePositions
agxData::BufferRef m_linePositions
Definition: TerrainVoxelDrawable.h:165
agxOSG::TerrainVoxelDrawable::m_nodesFirstBuffer
agxData::BufferRef m_nodesFirstBuffer
Definition: TerrainVoxelDrawable.h:162
Terrain.h
agxOSG::TerrainVoxelDrawable::m_enableRenderVoxelCompaction
bool m_enableRenderVoxelCompaction
Definition: TerrainVoxelDrawable.h:148
agxOSG::TerrainVoxelDrawable::m_maxVoxelColor
agx::Vec4f m_maxVoxelColor
Definition: TerrainVoxelDrawable.h:156
agxOSG::TerrainVoxelDrawable::className
virtual const char * className() const
Definition: TerrainVoxelDrawable.h:79
AGXOSG_EXPORT
#define AGXOSG_EXPORT
PopDisableWarnings.h