AGX Dynamics 2.42.2.1
Loading...
Searching...
No Matches
TerrainMaterialController.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. 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
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
198 /*
199 Update terrain if TerrainMaterial is dirty.
200 */
201 void syncTerrainWithTerrainMaterials();
202
203 public:
204
205 MaterialPairVector getTerrainMaterialPairs();
206 void setTerrainMaterialPairs(MaterialPairVector materialPairs);
207
208 /*
209 Function used by pager to set terrain materials at specific voxel indices
210 \param terrainMaterialsInVoxels
211 \param resetTerrainMaterials - true to clear the grid before assignment, false to keep already assigned materials.
212 */
213 void pagerSetTerrainMaterialsInVoxels(TerrainMaterialsInVoxels terrainMaterialsInVoxels, bool resetTerrainMaterials);
214
215 /*
216 Function used by pager to set one terrain material at specific voxel indices
217 \param voxelIndices - The voxel indices to set at
218 \param terrainMaterialIndex - The terrain material index
219 \param resetTerrainMaterials - true to clear the grid before assignment, false to keep already assigned materials.
220 */
221 void pagerSetTerrainMaterialInVoxels(agx::Vec3iVector voxelIndices, agx::UInt32 terrainMaterialIndex, bool resetTerrainMaterials = true);
222
223 /*
224 Function used to remove empty voxels from the terrain material grid.
225 If there is no occupancy left, the information that it contains another material is also removed.
226 */
227 void removeEmptyVoxelsFromTable(Grid::GridCoordVector& coords, std::function<float(const agx::Vec3i&)> getOccupancy);
228
229 /*
230 Calculates the weigths of terrain materials in the specified voxel indices.
231 The weights are used to calculate an average property from the terrain materials, see for example TerrainMaterialController::getDensity(weights) etc.
232 \internal
233 Index 0 is defaultTerrainMaterial, the following indices map such that weights[i+1] <-> getData()->getTerrainMaterials[i].
234 \endinternal
235 */
236 agx::RealVector getWeights(const Grid::GridCoordVector& coords);
237
246 agx::RealVector getMaterialWeightsInFailureZone(ActiveZone* activeZone);
247
254 agx::RealVector getMaterialWeightsInPoints(const agx::Vec3Vector& points);
255
257 /*
258 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
259 */
260 agx::Real getDensity(const agx::RealVector& weights);
261 /*
262 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
263 */
264 agx::Real getYoungsModulus(const agx::RealVector& weights);
265 /*
266 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
267 */
268 agx::Real getSwellFactor(const agx::RealVector& weights);
269 /*
270 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
271 */
272 agx::Real getCohesion(const agx::RealVector& weights);
273 /*
274 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
275 */
276 agx::Real getTangentialCohesion(const agx::RealVector& weights);
277 /*
278 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
279 */
280 agx::Real getHardeningConstantKE(const agx::RealVector& weights);
281 /*
282 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
283 */
284 agx::Real getHardeningConstantNE(const agx::RealVector& weights);
285 /*
286 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
287 */
288 agx::Real getAggregateStiffnessMultiplier(const agx::RealVector& weights);
289 /*
290 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
291 */
292 agx::Real getMaximumAggregateNormalForce(const agx::RealVector& weights);
293 /*
294 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
295 */
296 agx::Real getDepthAngleThreshold(const agx::RealVector& weights);
297 /*
298 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
299 */
300 agx::Real getMaximumDepth(const agx::RealVector& weights);
301 /*
302 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
303 */
304 agx::Real getDepthDecayFactor(const agx::RealVector& weights);
305 /*
306 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
307 */
308 agx::Real getDepthIncreaseFactor(const agx::RealVector& weights);
309 /*
310 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
311 */
312 agx::Real getFrictionAngle(const agx::RealVector& weights);
313 /*
314 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
315 */
316 agx::Real getDilatancyAngleScalingFactor(const agx::RealVector& weights);
317 /*
318 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
319 */
320 agx::Real getDilatancyAngle(const agx::RealVector& weights);
321 /*
322 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
323 */
324 agx::Real getPoissonsRatio(const agx::RealVector& weights);
325 /*
326 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
327 */
328 agx::Real getExcavationStiffnessMultiplier(const agx::RealVector& weights);
329
330 // TERRAMECHANICS PROPERTIES AVERAGING
331
332 /*
333 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
334 */
335 agx::Real getSinkageExponentParameterA(const agx::RealVector& weights);
336 /*
337 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
338 */
339 agx::Real getSinkageExponentParameterB(const agx::RealVector& weights);
340 /*
341 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
342 */
343 agx::Real getShearModulusTangentialParameterA(const agx::RealVector& weights);
344 /*
345 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
346 */
347 agx::Real getShearModulusTangentialParameterB(const agx::RealVector& weights);
348 /*
349 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
350 */
351 agx::Real getShearModulusLateralParameterA(const agx::RealVector& weights);
352 /*
353 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
354 */
355 agx::Real getShearModulusLateralParameterB(const agx::RealVector& weights);
356 /*
357 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
358 */
359 agx::Real getCohesiveModulusBekker(const agx::RealVector& weights);
360 /*
361 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
362 */
363 agx::Real getFrictionalModulusBekker(const agx::RealVector& weights);
364 /*
365 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
366 */
367 agx::Real getCohesiveModulusReece(const agx::RealVector& weights);
368 /*
369 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
370 */
371 agx::Real getFrictionalModulusReece(const agx::RealVector& weights);
372 /*
373 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
374 */
375 agx::Real getMaximumNormalStressAngleParameterA(const agx::RealVector& weights);
376 /*
377 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
378 */
379 agx::Real getMaximumNormalStressAngleParameterB(const agx::RealVector& weights);
380 /*
381 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
382 */
383 agx::Real getRearAngleParameterA(const agx::RealVector& weights);
384 /*
385 \param weights - Weight vector for the parameter used to perform averaging. Use getWeights to get the correct weights.
386 */
387 agx::Real getRearAngleParameterB(const agx::RealVector& weights);
388
389 // CONTACT MATERIAL AVERAGING
390
396 agx::Real getSoilToolFrictionCoefficient(const agx::RealVector& weights, agx::Material* shovelMaterial);
397
403 agx::Real getSoilToolAdhesion(const agx::RealVector& weights, agx::Material* shovelMaterial);
404
410 agx::Real getSoilToolYoungsModulus(const agx::RealVector& weights, agx::Material* shovelMaterial);
411
417 agx::Real getSoilToolAdhesiveOverlap(const agx::RealVector& weights, agx::Material* shovelMaterial);
418
424 agx::Real getSoilToolDamping(const agx::RealVector& weights, agx::Material* shovelMaterial);
425
431 agx::Real getSoilToolRollingResistanceCoefficient(const agx::RealVector& weights, agx::Material* shovelMaterial);
432
438 agx::Real getSoilToolTwistingResistanceCoefficient(const agx::RealVector& weights, agx::Material* shovelMaterial);
439
440
441
443
444 protected:
445
446 virtual ~TerrainMaterialController();
447
448 TerrainDataAtlas* getData() const;
449
450 Grid::GridCoordVector voxelIndicesAlongLine(agx::Line line);
451
452 /*
453 /internal
454 Utility function used to average a property from the terrain materials in the terrain instance.
455 \param getPropertyFunc - a lambda that takes a TerrainMaterial and returns the property that should be averaged.
456 \param weights - weights for the different terrain materials. See getWeights(const Grid::GridCoordVector& coords).
457 /endinternal
458 */
459 agx::Real averageProperty(std::function<agx::Real(TerrainMaterial* terrainMaterial)> getPropertyFunc, const agx::RealVector& weights);
460
461 /*
462 /internal
463 Utility function used to average a property from the contact materials in the terrain instance.
464 Contact materials are retrieved or calculated implicitly between the given shovelMaterial and the
465 agx::Materials corresponding to the TerrainMaterials.
466 \param getPropertyFunc - a lambda that takes a ContactMaterial and returns the averaged property.
467 \param weights - weights for the different terrain materials. See getWeights(const Grid::GridCoordVector& coords).
468 \param shovelMaterial - the agx::Material of the shovel.
469 /endinternal
470 */
471 agx::Real averageTerrainToolProperty(std::function<agx::Real(agx::ContactMaterial* contactMaterial)> getPropertyFunc, const agx::RealVector& weights, agx::Material* shovelMaterial);
472
473
474 private:
475 Terrain* m_terrain;
476 };
478}
#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:48
agx::Vec3i GridCoord
Definition: Grid.h:84
agx::VectorPOD< GridCoord > GridCoordVector
Definition: Grid.h:86
This class store the combine material properties between two agx::Material's.
Definition: Material.h:518
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:378
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:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
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:41
STL namespace.