AGX Dynamics  2.37.3.2
TerrainDataSource.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
9 having been advised so by Algoryx Simulation AB for a time limited evaluation,
10 or having purchased a 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 #include <agx/Referenced.h>
21 #include <agxStream/Serializable.h>
23 
24 #include <agxTerrain/export.h>
26 
27 #include <agxCollide/Geometry.h>
28 #include <agxCollide/Line.h>
29 
30 
31 namespace agxTerrain
32 {
33 
35 
40  {
41  /*
42  The terrain materials are only identified by an Int index, see terrain->getTerrainMaterialIndex.
43  */
45 
46  public:
51  /*
52  Datatype used for returning terrain material values
53  */
55 
72  virtual TerrainHeightType fetchTerrainTile( const TileSpecification& ts, agxTerrain::TileId id ) = 0;
73 
82  virtual TerrainMaterialsType fetchTerrainMaterials(const TileSpecification& ts, agxTerrain::TileId id, agx::Real maxHeight);
83 
90  bool removeMaterialSourceGeometry( agxCollide::Geometry* geom );
91 
92  /*
93  Add a source geometry for a terrain material index.
94  \note The terrain material is only represented by a terrain material index. See Terrain::getTerrainMaterialIndex(TerrainMaterial*) for the relevant indices.
95  */
96  bool addTerrainMaterialSourceGeometry( agxCollide::Geometry* geom, agx::UInt32 terrainMaterialIndex );
97 
111  virtual bool raycast( agx::Vec3 start, agx::Vec3 end, agx::Vec3& raycastResult );
112 
113  // Serialization
115  virtual void store( agxStream::OutputArchive& out ) const override;
116  virtual void restore( agxStream::InputArchive& in ) override;
117 
118  private:
119  agxCollide::GeometryRefVector m_terrainMaterialSourceGeometry;
120  TerrainMaterialInGeometry m_terrainMaterial;
121 
122  protected:
124  };
125 
126 
127 
152  {
153  public:
154 
158  TerrainRasterizer( agx::Real sampleRayLength = 1000.0 );
159 
163  agx::Real getRayLength() const;
164 
165 
169  void setRayLength( agx::Real length );
170 
171 
182  bool addSourceGeometry( agxCollide::Geometry* geom );
183 
190  bool removeSourceGeometry( agxCollide::Geometry* geom );
191 
198  virtual TerrainHeightType fetchTerrainTile( const TileSpecification& ts, agxTerrain::TileId id ) override;
199 
208  virtual bool raycast( agx::Vec3 start, agx::Vec3 end, agx::Vec3& raycastResult ) override;
209 
210 
211  // Serialization methods
213 
214 
215  protected:
217 
218  private:
219  agxCollide::GeometryRefVector m_sourceGeometry;
220 
221  agxCollide::LineRef m_line;
222  agx::Real m_sampleLength;
223  };
224 
237  {
238  public:
243 
250  virtual TerrainHeightType fetchTerrainTile( const TileSpecification& ts, agxTerrain::TileId id ) override;
251 
260  virtual bool raycast( agx::Vec3 start, agx::Vec3 end, agx::Vec3& raycastResult ) override;
261 
262  // Serialization methods
264 
265  protected:
267 
268  private:
269  // When ExternalTerrainDataSource is loaded from the archive the base class is used by design. This means that
270  // ExternalTerrainDataSource::fetchTerrainTile/raycast will be called. This would normaly result in a warning.
271  // This flag keeps track of if this instance was loaded from an archive and, if so, supresses warnings.
272  bool m_loadedFromArchive;
273  };
274 
276  {
277  return m_sampleLength;
278  }
279 
281  {
282  m_sampleLength = length;
283  }
284 
285 }
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
A TileSpecification determines where in the world a 2D TileId is located and contains utility methods...
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
This class provides a concrete, serializable base class which classes written in other languages can ...
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGX_FORCE_INLINE
Definition: Object.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Templated vector class.
Definition: Vector.h:52
void setRayLength(agx::Real length)
Set the length of the ray.
agx::RealVector TerrainHeightType
Datatype used for returning height values.
#define AGXTERRAIN_EXPORT
agx::Vector< std::pair< agxCollide::Geometry *, agx::UInt32 > > TerrainMaterialsType
This class performs raycasting against the source geometry to get height data for tiles...
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Abstract interface for requesting height data for a Terrain tile.
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
double Real
Definition: Real.h:42
Inheritance with partial specialization due to bug with ref_ptr containers.
agx::ReaderWriterLock m_rwLock
ReaderWriterLock provides shared access for readers and exclusive access for writers.
uint32_t UInt32
Definition: Integer.h:40