VR-Engage  2.2
Loading...
Searching...
No Matches
pagedTerrainRequest.h
Go to the documentation of this file.
1/*******************************************************************************
2** Copyright (c) 2020 MAK Technologies
3** All rights reserved.
4*******************************************************************************/
5
6//! \file pagedTerrainRequest.h
7//! \brief Classes for handling terrain triangle data and requests for the Vortex physics engine.
8//!
9//! \ingroup vreVrfVortex
10
11#pragma once
12
13#include <vreVrfVortex/export.h>
14
15#include <terrainInterface/terrainProcessPolygonsBox.h>
16
18
19#include <vector>
20#include <tbb/spin_mutex.h>
21
22#include <chrono>
23
24//! \brief High-resolution clock type used for timing operations
25using HiResClock = std::chrono::high_resolution_clock;
26
27namespace makVre
28{
29class DtSurfaceToVxMaterialMapper;
30
31//! \brief Triangle structure optimized for Vortex physics engine
32//!
33//! A lightweight structure containing only the necessary data for physics calculations:
34//! three vertex points and the surface type. Derived from DtTerrainTriangleStruct but
35//! with reduced memory footprint.
37{
38 //! \brief Default constructor
39 //!
40 //! Creates an empty triangle structure.
42
43 //! \brief Conversion constructor
44 //!
45 //! Creates a Vortex triangle structure from a terrain triangle structure.
46 //!
47 //! \param triStruct The source terrain triangle structure
48 DtVortexTriangleStructure(const DtTerrainTriangleStruct& triStruct)
49 {
50 points[0] = triStruct.points[0];
51 points[1] = triStruct.points[1];
52 points[2] = triStruct.points[2];
53 surface = triStruct.surface;
54 }
55
56 //! \brief Sets the triangle vertices and surface
57 //!
58 //! Initializes all properties of the triangle in one call.
59 //!
60 //! \param pt0 First vertex point
61 //! \param pt1 Second vertex point
62 //! \param pt2 Third vertex point
63 //! \param surf Surface type identifier
64 void set(DtPoint pt0, DtPoint pt1, DtPoint pt2, DtSurface surf)
65 {
66 points[0] = pt0;
67 points[1] = pt1;
68 points[2] = pt2;
69 surface = surf;
70 }
71
72 DtPoint points[3]; //!< Array of three vertex points defining the triangle
73 DtSurface surface; //!< Surface type identifier for material properties
74};
75
76//! \brief Interface for collecting and processing terrain triangles for Vortex
77//!
78//! This class extends DtTriangleOutputInterface to provide specialized handling of
79//! terrain triangles for the Vortex physics engine. It collects triangles, filters them
80//! based on surface type, handles coordinate conversions, and provides timing metrics
81//! for performance analysis.
82class VREVRFVORTEX_DLL DtVortexTriangleOutputInterface : public DtTriangleOutputInterface
83{
84public:
85 //! \brief Type definition for a collection of triangles
86 using TerrainTriangleStructList = std::vector<DtVortexTriangleStructure>;
87
88 //! \brief Constructor with bounding box and capacity specification
89 //!
90 //! Initializes the triangle output interface with a given bounding box and
91 //! pre-allocates memory for triangles to improve performance.
92 //!
93 //! \param bb Bounding box defining the terrain area to process
94 //! \param reserveSize Number of triangles to pre-allocate memory for
95 DtVortexTriangleOutputInterface(DtTerrainProcessPolygonsBox bb, const unsigned int reserveSize);
96
97 //! \brief Destructor
98 //!
99 //! Cleans up resources by clearing the triangle list.
101
102 //! \brief Processes a terrain triangle and adds it to the collection
103 //!
104 //! Filters triangles based on surface type, performs coordinate conversion
105 //! if needed, and adds valid triangles to the internal collection. This method
106 //! is thread-safe.
107 //!
108 //! \param triangle The terrain triangle to process
109 virtual void processTriangle(const DtTerrainTriangleStruct& triangle) override;
110
111 //! \brief Checks if triangles should be processed
112 //!
113 //! \return True if triangle processing is enabled, false otherwise
114 virtual bool processTriangles() const override;
115
116 //! \brief Sets whether triangles should be processed
117 //!
118 //! \param value True to enable triangle processing, false to disable
119 void setProcessTriangles(bool value);
120
121 //! \brief Sets whether to force paging of terrain data
122 //!
123 //! \param page True to force paging, false otherwise
124 void setForcePaging(bool page);
125
126 //! \brief Checks if paging is forced
127 //!
128 //! \return True if paging is forced, false otherwise
129 virtual bool forcePaging() const override;
130
131 //! \brief Gets the request identifier
132 //!
133 //! \return The current request identifier
134 int requestId() const;
135
136 //! \brief Sets the request identifier
137 //!
138 //! \param id The new request identifier
139 void setRequestId(int id);
140
141 //! \brief Gets the source identifier
142 //!
143 //! \return The current source identifier
144 int sourceId() const;
145
146 //! \brief Sets the source identifier
147 //!
148 //! \param id The new source identifier
149 void setSourceId(int id);
150
151 //! \brief Sets the material mapper for surface filtering
152 //!
153 //! \param mapper The material mapper to use for filtering triangles
154 void setMaterialMap(std::shared_ptr<DtSurfaceToVxMaterialMapper> mapper);
155
156 //! \brief Sets the coordinate conversion object
157 //!
158 //! \param coordConv The coordinate converter to use for geocentric conversions
160
161 //! \brief Sets whether the terrain is in geocentric coordinates
162 //!
163 //! \param isGeo True if terrain is in geocentric coordinates, false if it's in local coordinates
164 void setGeocentricTerrain(bool isGeo);
165
166 //! \brief Sets whether this represents dynamic terrain
167 //!
168 //! \param dynamic True if this represents dynamic terrain, false for static terrain
169 void setIsDynamicTerrain(bool dynamic = false);
170
171 //! \brief Checks if this represents dynamic terrain
172 //!
173 //! \return True if this represents dynamic terrain, false for static terrain
174 bool isDynamicTerrain() const;
175
176 //! \brief Gets the bounding box
177 //!
178 //! \return The bounding box defining the terrain area
179 DtTerrainProcessPolygonsBox boundingBox() const;
180
181 //! \brief Starts timing the triangle collection process
183
184 //! \brief Ends timing the triangle collection process
186
187 //! \brief Gets the time taken to collect triangles in milliseconds
188 //!
189 //! \return The time taken to collect triangles in milliseconds
190 double getTrianglesTime() const;
191
192 //! \brief Starts timing the collision geometry generation process
194
195 //! \brief Ends timing the collision geometry generation process
197
198 //! \brief Gets the time taken to generate collision geometry in milliseconds
199 //!
200 //! \return The time taken to generate collision geometry in milliseconds
201 double collisionGeometryTime() const;
202
203 //! \brief Starts timing the triangle mesh generation process
205
206 //! \brief Ends timing the triangle mesh generation process
208
209 //! \brief Gets the time taken to generate triangle mesh in milliseconds
210 //!
211 //! \return The time taken to generate triangle mesh in milliseconds
212 double triangleMeshTime() const;
213
214 //! \brief Gets the collected triangles
215 //!
216 //! \return Constant reference to the list of collected triangles
217 virtual const TerrainTriangleStructList& triangles() const;
218
219 //! \brief Gets the number of collected triangles
220 //!
221 //! \return The number of triangles collected
222 virtual unsigned triangleCount() const;
223
224 //! \brief Clears the triangle list
225 //!
226 //! Removes all collected triangles from memory.
227 virtual void clearTriangleList();
228
229protected:
230 bool myIsDynamicTerrain; //!< Flag indicating if this represents dynamic terrain
231 bool myIsGeocentric; //!< Flag indicating if terrain is in geocentric coordinates
232 bool myRequestFinished; //!< Flag indicating if the request has been completed
233 bool myForcePaging; //!< Flag indicating if paging should be forced
234 bool myProcessTriangles; //!< Flag indicating if triangles should be processed
235
236 HiResClock::time_point myGetTrianglesStartTime; //!< Start time for triangle collection
237 HiResClock::time_point myGetTrianglesEndTime; //!< End time for triangle collection
238
239 HiResClock::time_point myCollisionGeometryStartTime; //!< Start time for collision geometry generation
240 HiResClock::time_point myCollisionGeometryEndTime; //!< End time for collision geometry generation
241
242 HiResClock::time_point myTriangleMeshStartTime; //!< Start time for triangle mesh generation
243 HiResClock::time_point myTriangleMeshEndTime; //!< End time for triangle mesh generation
244
245 int myRequestId; //!< Identifier for this request
246 int mySourceId; //!< Source identifier for this terrain data
247
248 DtTerrainProcessPolygonsBox myBoundingBox; //!< Bounding box defining the terrain area
249
250 DtCoordinateConvert* myCoordConvert; //!< Converter for geocentric coordinates
251
252 std::shared_ptr<DtSurfaceToVxMaterialMapper> myMaterialMapper; //!< Mapper for filtering surfaces
253
254 unsigned int myTriangleCount; //!< Number of triangles collected
255 TerrainTriangleStructList myTriangleList; //!< List of collected triangles
256 tbb::spin_mutex myProcessTriangleMutex; //!< Mutex for thread-safe triangle processing
257};
258} // namespace makVre
Class for converting between different coordinate systems.
Definition coordConverter.h:31
double collisionGeometryTime() const
Gets the time taken to generate collision geometry in milliseconds.
HiResClock::time_point myGetTrianglesEndTime
End time for triangle collection.
Definition pagedTerrainRequest.h:237
DtTerrainProcessPolygonsBox myBoundingBox
Bounding box defining the terrain area.
Definition pagedTerrainRequest.h:248
virtual bool processTriangles() const override
Checks if triangles should be processed.
double getTrianglesTime() const
Gets the time taken to collect triangles in milliseconds.
HiResClock::time_point myGetTrianglesStartTime
Start time for triangle collection.
Definition pagedTerrainRequest.h:236
HiResClock::time_point myTriangleMeshStartTime
Start time for triangle mesh generation.
Definition pagedTerrainRequest.h:242
void startGetTrianglesProcessTime()
Starts timing the triangle collection process.
void endCollisionGeometryProcessTime()
Ends timing the collision geometry generation process.
std::vector< DtVortexTriangleStructure > TerrainTriangleStructList
Type definition for a collection of triangles.
Definition pagedTerrainRequest.h:86
bool myIsGeocentric
Flag indicating if terrain is in geocentric coordinates.
Definition pagedTerrainRequest.h:231
void setForcePaging(bool page)
Sets whether to force paging of terrain data.
bool isDynamicTerrain() const
Checks if this represents dynamic terrain.
DtCoordinateConvert * myCoordConvert
Converter for geocentric coordinates.
Definition pagedTerrainRequest.h:250
HiResClock::time_point myCollisionGeometryStartTime
Start time for collision geometry generation.
Definition pagedTerrainRequest.h:239
void setMaterialMap(std::shared_ptr< DtSurfaceToVxMaterialMapper > mapper)
Sets the material mapper for surface filtering.
virtual void processTriangle(const DtTerrainTriangleStruct &triangle) override
Processes a terrain triangle and adds it to the collection.
void setProcessTriangles(bool value)
Sets whether triangles should be processed.
tbb::spin_mutex myProcessTriangleMutex
Mutex for thread-safe triangle processing.
Definition pagedTerrainRequest.h:256
void endTriangleMeshProcessTime()
Ends timing the triangle mesh generation process.
void startCollisionGeometryProcessTime()
Starts timing the collision geometry generation process.
virtual ~DtVortexTriangleOutputInterface()
Destructor.
virtual unsigned triangleCount() const
Gets the number of collected triangles.
HiResClock::time_point myCollisionGeometryEndTime
End time for collision geometry generation.
Definition pagedTerrainRequest.h:240
virtual void clearTriangleList()
Clears the triangle list.
int myRequestId
Identifier for this request.
Definition pagedTerrainRequest.h:245
virtual bool forcePaging() const override
Checks if paging is forced.
bool myIsDynamicTerrain
Flag indicating if this represents dynamic terrain.
Definition pagedTerrainRequest.h:230
bool myRequestFinished
Flag indicating if the request has been completed.
Definition pagedTerrainRequest.h:232
DtVortexTriangleOutputInterface(DtTerrainProcessPolygonsBox bb, const unsigned int reserveSize)
Constructor with bounding box and capacity specification.
HiResClock::time_point myTriangleMeshEndTime
End time for triangle mesh generation.
Definition pagedTerrainRequest.h:243
void setSourceId(int id)
Sets the source identifier.
DtTerrainProcessPolygonsBox boundingBox() const
Gets the bounding box.
virtual const TerrainTriangleStructList & triangles() const
Gets the collected triangles.
std::shared_ptr< DtSurfaceToVxMaterialMapper > myMaterialMapper
Mapper for filtering surfaces.
Definition pagedTerrainRequest.h:252
void setGeocentricTerrain(bool isGeo)
Sets whether the terrain is in geocentric coordinates.
TerrainTriangleStructList myTriangleList
List of collected triangles.
Definition pagedTerrainRequest.h:255
void setIsDynamicTerrain(bool dynamic=false)
Sets whether this represents dynamic terrain.
bool myProcessTriangles
Flag indicating if triangles should be processed.
Definition pagedTerrainRequest.h:234
bool myForcePaging
Flag indicating if paging should be forced.
Definition pagedTerrainRequest.h:233
void setRequestId(int id)
Sets the request identifier.
int mySourceId
Source identifier for this terrain data.
Definition pagedTerrainRequest.h:246
void setCoordinateConversion(DtCoordinateConvert *coordConv)
Sets the coordinate conversion object.
void endGetTrianglesProcessTime()
Ends timing the triangle collection process.
void startTriangleMeshProcessTime()
Starts timing the triangle mesh generation process.
int requestId() const
Gets the request identifier.
double triangleMeshTime() const
Gets the time taken to generate triangle mesh in milliseconds.
int sourceId() const
Gets the source identifier.
unsigned int myTriangleCount
Number of triangles collected.
Definition pagedTerrainRequest.h:254
Provides coordinate conversion functionality between different coordinate systems.
Export macros for the VR-Forces Vortex extension library.
#define VREVRFVORTEX_DLL
Export macro for non-Windows platforms.
Definition export.h:30
Include export definitions for this library.
Definition glsVreMessageUtil.h:49
std::chrono::high_resolution_clock HiResClock
High-resolution clock type used for timing operations.
Definition pagedTerrainRequest.h:25
DtPoint points[3]
Array of three vertex points defining the triangle.
Definition pagedTerrainRequest.h:72
DtVortexTriangleStructure()
Default constructor.
Definition pagedTerrainRequest.h:41
DtVortexTriangleStructure(const DtTerrainTriangleStruct &triStruct)
Conversion constructor.
Definition pagedTerrainRequest.h:48
DtSurface surface
Surface type identifier for material properties.
Definition pagedTerrainRequest.h:73
void set(DtPoint pt0, DtPoint pt1, DtPoint pt2, DtSurface surf)
Sets the triangle vertices and surface.
Definition pagedTerrainRequest.h:64