AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
TerrainMaterialController.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agx/config/AGX_USE_AGXTERRAIN.h>
20#include <agxTerrain/export.h>
21#include <agx/Referenced.h>
22#include <agx/Vec3.h>
25
26
27namespace agxTerrain
28{
29 class Terrain;
30 class TerrainDataAtlas;
32
33 AGX_DECLARE_POINTER_TYPES(TerrainMaterialController);
34 AGX_DECLARE_VECTOR_TYPES(TerrainMaterialController);
35
36 typedef std::pair<agx::Vec3iVector, agx::UInt32Vector> TerrainMaterialsInVoxels;
37 typedef agx::HashTable<TerrainMaterial*, agx::Vec3iVector> TerrainMaterialSort;
38
39
55 class AGXTERRAIN_EXPORT TerrainMaterialController : public agx::Referenced
56 {
57 public:
61 TerrainMaterialController(Terrain* terrain);
62
66 TerrainMaterialController();
67
68 /*
69 Set the default terrain material and it's corresponding default material.
70 */
71 void setDefaultTerrainMaterial(TerrainMaterial* defaultTerrainMaterial, agx::Material* defaultMaterial = nullptr);
72 /*
73 Get the default terrain material.
74 */
75 TerrainMaterial* getDefaultTerrainMaterial();
76 /*
77 Set only the default material.
78 */
79 void setDefaultMaterial(agx::Material* defaultMaterial);
80 /*
81 Get the default material.
82 */
83 agx::Material* getDefaultMaterial();
84
85 /*
86 Add a TerrainMaterial to the specified vector with voxel indices
87 \param terrainMaterial - The TerrainMaterial to set.
88 \param coords - The vector of voxel indices to set the terrain material in. NOTE: GridCoord is not terrainIndex and depth! It is voxel index.
89 \return num voxels assigned with new material.
90 */
91 int addTerrainMaterial(TerrainMaterial* terrainMaterial, const Grid::GridCoordVector& coords);
92
93 /*
94 Add a TerrainMaterial to the specified voxel index
95 \param terrainMaterial - The TerrainMaterial to set.
96 \param coords - Voxel index to set the terrain material in. NOTE: GridCoord is not terrainIndex and depth! It is voxel index.
97 \return true if the material was assigned, false otherwise.
98 */
99 bool addTerrainMaterial(TerrainMaterial* terrainMaterial, const Grid::GridCoord& coord);
100
101 /*
102 Add a TerrainMaterial to the data atlas. A new associated material will be created for it by default.
103 It is not assigned to any parts of the terrain.
104 \param terrainMaterial - The TerrainMaterial to add.
105 \return true if the material was added, false otherwise. If false, perhaps the terrainMaterial was already added?
106 */
107 bool addTerrainMaterial(TerrainMaterial* terrainMaterial);
108
109 /*
110 Associate a Material with an added TerrainMaterial. The given material is used to configure contact materials between
111 the terrain and shovel.
112 \param material - The material
113 \param terrainMaterial - The added TerrainMaterial the material should be associated with.
114 */
115 bool associateMaterialToTerrainMaterial(agx::Material* material, TerrainMaterial* terrainMaterial);
116
117 /*
118 Get the Terrainmaterial in the specified voxel index
119 */
120 TerrainMaterial* getTerrainMaterial(const Grid::GridCoord& coord) const;
121
122 /*
123 \return the Terrainmaterial in the terrain voxel given a world position.
124 */
125 TerrainMaterial* getTerrainMaterial(const agx::Vec3 worldPosition);
126
127 /*
128 Get the added terrain materials
129 */
130 agx::Vector<TerrainMaterial*> getTerrainMaterials() const;
131 /*
132 Get the terrainMaterialIndex for the specified terrainMaterial.
133 \param terrainMaterial - the TerrainMaterial you wish to get the index for.
134 \returns - the index for the given TerrainMaterial or agx::InvalidIndex if not added.
135 */
136 agx::UInt32 getTerrainMaterialIndex(TerrainMaterial* terrainMaterial);
137
138 /*
139 Get the solid voxels that intersects with the given geometry.
140 */
141 agx::Vec3iVector getIntersectingVoxels(agxCollide::Geometry* geometry);
142
143 /*
144 Set the added terrain materials. Clears previously added terrain materials.
145 */
146 bool setTerrainMaterials(agx::Vector<TerrainMaterial*> terrainMaterials);
147
148 /*
149 Exchange an already added TerrainMaterial with another TerrainMaterial without changing its associated agx::Material or assigned domain.
150 */
151 bool exchangeTerrainMaterial(TerrainMaterial* oldTerrainMaterial, TerrainMaterial* newTerrainMaterial);
152
153 /*
154 Remove an added terrain material, its assigned domain will also be removed along with it.
155 \note This method can not remove the default terrain material, just set the default terrain material instead!
156 */
157 bool removeTerrainMaterial(TerrainMaterial* terrainMaterialToRemove);
158
159
160 /*
161 Clear the voxel grid of added materials.
162 \param clearAddedMaterials - true to also clear the list of added materials, false to only clear the assigned domains.
163 */
164 void clearTerrainMaterialGrid(bool clearAddedMaterials);
165
166
167 /*
168 \return The corresponding agx::Material for the specified TerrainMaterial or nullptr if the TerrainMaterial isn't included in the terrain.
169 */
170 agx::Material* getMaterial(TerrainMaterial* terrainMaterial) const;
171
172 /*
173 Set the default agx::Material which corresponds to the default terrain material.
174 */
175 void setMaterial(agx::Material* defaultMaterial);
176
183 agxRender::Color getMaterialDebugColor(size_t index);
184
185 /*
186 Render the added terrain materials using the getMaterialDebugColors
187 /note Very slow function, take a look at TerrainVoxelRenderer for faster rendering.
188 */
189 void debugRenderMaterials();
190
191 /*
192 \return Pairs of vectors containing the voxel indices and corresponding terrain material indices.
193 */
194 TerrainMaterialsInVoxels getTerrainMaterialsInVoxels();
195
196
197 public:
198
199 MaterialPairVector getTerrainMaterialPairs();
200 void setTerrainMaterialPairs(MaterialPairVector materialPairs);
201
202 /*
203 Function used by pager to set terrain materials at specific voxel indices
204 \param terrainMaterialsInVoxels
205 \param resetTerrainMaterials - true to clear the grid before assignment, false to keep already assigned materials.
206 */
207 void pagerSetTerrainMaterialsInVoxels(TerrainMaterialsInVoxels terrainMaterialsInVoxels, bool resetTerrainMaterials);
208
209 /*
210 Function used by pager to set one terrain material at specific voxel indices
211 \param voxelIndices - The voxel indices to set at
212 \param terrainMaterialIndex - The terrain material index
213 \param resetTerrainMaterials - true to clear the grid before assignment, false to keep already assigned materials.
214 */
215 void pagerSetTerrainMaterialInVoxels(agx::Vec3iVector voxelIndices, agx::UInt32 terrainMaterialIndex, bool resetTerrainMaterials = true);
216
217 /*
218 Function used to remove empty voxels from the terrain material grid.
219 If there is no occupancy left, the information that it contains another material is also removed.
220 */
221 void removeEmptyVoxelsFromTable(Grid::GridCoordVector& coords, std::function<float(const agx::Vec3i&)> getOccupancy);
222
223 /*
224 Calculates the weigths of terrain materials in the specified voxel indices.
225 The weights are used to calculate an average property from the terrain materials, see for example TerrainMaterialController::getDensity(weights) etc.
226 \internal
227 Index 0 is defaultTerrainMaterial, the following indices map such that weights[i+1] <-> getData()->getTerrainMaterials[i].
228 \endinternal
229 */
230 agx::RealVector getWeights(const Grid::GridCoordVector& coords);
231
240 agx::RealVector getMaterialWeightsInFailureZone(ActiveZone* activeZone);
241
248 agx::RealVector getMaterialWeightsInPoints(const agx::Vec3Vector& points);
249
251 /*
252 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
253 */
254 agx::Real getDensity(const agx::RealVector& weights);
255 /*
256 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
257 */
258 agx::Real getYoungsModulus(const agx::RealVector& weights);
259 /*
260 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
261 */
262 agx::Real getSwellFactor(const agx::RealVector& weights);
263 /*
264 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
265 */
266 agx::Real getCohesion(const agx::RealVector& weights);
267 /*
268 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
269 */
270 agx::Real getHardeningConstantKE(const agx::RealVector& weights);
271 /*
272 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
273 */
274 agx::Real getHardeningConstantNE(const agx::RealVector& weights);
275 /*
276 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
277 */
278 agx::Real getAggregateStiffnessMultiplier(const agx::RealVector& weights);
279 /*
280 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
281 */
282 agx::Real getMaximumAggregateNormalForce(const agx::RealVector& weights);
283 /*
284 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
285 */
286 agx::Real getDepthAngleThreshold(const agx::RealVector& weights);
287 /*
288 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
289 */
290 agx::Real getMaximumDepth(const agx::RealVector& weights);
291 /*
292 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
293 */
294 agx::Real getDepthDecayFactor(const agx::RealVector& weights);
295 /*
296 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
297 */
298 agx::Real getDepthIncreaseFactor(const agx::RealVector& weights);
299 /*
300 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
301 */
302 agx::Real getFrictionAngle(const agx::RealVector& weights);
303 /*
304 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
305 */
306 agx::Real getDilatancyAngleScalingFactor(const agx::RealVector& weights);
307 /*
308 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
309 */
310 agx::Real getDilatancyAngle(const agx::RealVector& weights);
311 /*
312 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
313 */
314 agx::Real getPoissonsRatio(const agx::RealVector& weights);
315 /*
316 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
317 */
318 agx::Real getExcavationStiffnessMultiplier(const agx::RealVector& weights);
319
320 // CONTACT MATERIAL AVERAGING
321
327 agx::Real getSoilToolFrictionCoefficient(const agx::RealVector& weights, agx::Material* shovelMaterial);
328
334 agx::Real getSoilToolAdhesion(const agx::RealVector& weights, agx::Material* shovelMaterial);
335
341 agx::Real getSoilToolYoungsModulus(const agx::RealVector& weights, agx::Material* shovelMaterial);
342
348 agx::Real getSoilToolAdhesiveOverlap(const agx::RealVector& weights, agx::Material* shovelMaterial);
349
355 agx::Real getSoilToolDamping(const agx::RealVector& weights, agx::Material* shovelMaterial);
356
362 agx::Real getSoilToolRollingResistanceCoefficient(const agx::RealVector& weights, agx::Material* shovelMaterial);
363
369 agx::Real getSoilToolTwistingResistanceCoefficient(const agx::RealVector& weights, agx::Material* shovelMaterial);
370
371
372
374
375 protected:
376
377 virtual ~TerrainMaterialController();
378
379 TerrainDataAtlas* getData() const;
380
381 Grid::GridCoordVector voxelIndicesAlongLine(agx::Line line);
382
383 /*
384 /internal
385 Utility function used to average a property from the terrain materials in the terrain instance.
386 \param getPropertyFunc - a lambda that takes a TerrainMaterial and returns the property that should be averaged.
387 \param weights - weights for the different terrain materials. See getWeights(const Grid::GridCoordVector& coords).
388 /endinternal
389 */
390 agx::Real averageProperty(std::function<agx::Real(TerrainMaterial* terrainMaterial)> getPropertyFunc, const agx::RealVector& weights);
391
392 /*
393 /internal
394 Utility function used to average a property from the contact materials in the terrain instance.
395 Contact materials are retrieved or calculated implicitly between the given shovelMaterial and the
396 agx::Materials corresponding to the TerrainMaterials.
397 \param getPropertyFunc - a lambda that takes a ContactMaterial and returns the averaged property.
398 \param weights - weights for the different terrain materials. See getWeights(const Grid::GridCoordVector& coords).
399 \param shovelMaterial - the agx::Material of the shovel.
400 /endinternal
401 */
402 agx::Real averageTerrainToolProperty(std::function<agx::Real(agx::ContactMaterial* contactMaterial)> getPropertyFunc, const agx::RealVector& weights, agx::Material* shovelMaterial);
403
404
405 private:
406 Terrain* m_terrain;
407 };
409}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXTERRAIN_STORE_RESTORE_INTERFACE
#define AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition agx/Vector.h:34
The geometry representation used by the collision detection engine.
Definition Geometry.h:92
Utility color class with "common colors".
Definition Color.h:34
agx::Vec3i GridCoord
Definition Grid.h:75
agx::VectorPOD< GridCoord > GridCoordVector
Definition Grid.h:77
This class store the combine material properties between two agx::Material's.
Definition Material.h:516
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition Material.h:376
Vector containing 'raw' data.
Definition agx/Vector.h:246
Templated vector class.
Definition agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition macros.h:96
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition Geometry.h:59
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
uint32_t UInt32
Definition Integer.h:32
double Real
Definition Real.h:42
STL namespace.