AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Terrain.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>
24#include <agxTerrain/Grid.h>
39
41
42#include <agx/HashSet.h>
44#include <agx/BitState.h>
46
47#include <agxCollide/Plane.h>
48#include <agxCollide/Geometry.h>
51
52namespace agxTerrain
53{
57 typedef std::pair<SoilParticlePtr, agx::Real> ParticleWeightPair;
64
67
86 {
87 public:
88 enum class MaterialType
89 {
90 TERRAIN,
91 PARTICLE,
92 AGGREGATE
93 };
94
95 enum class MassType
96 {
97 SOLID,
98 PARTICLE,
99 FLUID
100 };
101
102 public:
107
114
121 static Terrain* find( const agxSDK::Simulation* simulation, const agx::Name& name );
122
129 static Terrain* find( const agxSDK::Simulation* simulation, const agx::Uuid& uuid );
130
137 static TerrainPtrVector findAll( const agxSDK::Simulation* simulation, const agx::Name& name );
138
144 static TerrainPtrVector findAll( const agxSDK::Simulation* simulation );
145
146 public:
158 static Terrain* createFromHeightField(const agxCollide::HeightField* heightField, agx::Real maximumDepth);
159
170 Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize, agx::Real maximumDepth);
171
185 size_t resolutionX, size_t resolutionY, agx::Real elementSize, const agx::RealVector& heights,
186 bool flipY, agx::Real maximumDepth);
187
196 void setCompaction( agx::Real compaction, bool replaceCompactedSoil=true ) const;
197
202 void setTransform(const agx::AffineMatrix4x4& transform);
203
208
213
219 void setEnable( bool enable );
220
225 bool getEnable() const;
226
231 void setPosition(const agx::Vec3& position);
232
237
242 void setRotation(const agx::Quat& rotation);
243
248
256
264
272
280
288
294
299 virtual agxCollide::Geometry* getGeometry() const override;
300
308
314 void setDeformable( bool deformable );
315
321 inline bool getDeformable() const;
322
326 void setNoMergeEdgeMargin(size_t noMergeEdgeMargin);
327
331 void setNoMerge(bool noMerge);
332
337
341 bool addNoMergeZoneToGeometry( agxCollide::Geometry* geometry, agx::Real extensionDistance);
342
347
353
359
364
370
375
380 size_t getResolutionX() const;
381
386 size_t getResolutionY() const;
387
393 agx::Real getElementSize() const;
394
399
404
411 agx::Vec3 getSurfacePosition(const agx::Vec2i& terrainIndex, bool includeSurfaceParticles = false) const;
412
419 agx::Vec3 getSurfacePositionWorld(const agx::Vec2i& terrainIndex, bool includeSurfaceParticles = false) const;
420
427 agx::Vec2i getClosestGridPoint(const agx::Vec3& worldPosition, bool clampToBound=false) const;
428
436 agx::Bool projectPointToSurface(const agx::Vec3& worldPosition, agx::Vec3& result) const;
437
443 bool isBorderIndex(const agx::Vec2i& terrainIndex) const;
444
450 bool isIndexWithinBounds(const agx::Vec2i& terrainIndex) const;
451
457 bool isWorldPositionWithinBounds(const agx::Vec3& position) const;
458
464 bool isLocalPositionWithinBounds(const agx::Vec3& position) const;
465
471 void setHeight(const agx::Vec2i& terrainIndex, agx::Real height);
472
479 agx::Real getHeight(const agx::Vec2i& terrainIndex, bool includeSurfaceParticles = false) const;
480
485
490
495
500
505
512 bool add(Shovel* shovel);
513
519 bool remove(Shovel* shovel);
520
525
531
536
545 bool getPenetrationForce(const Shovel* shovel, agx::Vec3& force, agx::Vec3& torque) const;
546
555
563
571
581
591
601 agx::Vec3 getContactForce( const Shovel* shovel ) const;
602
610
618
622 agx::Real getInnerVolume(const Shovel* shovel) const;
623
628
634 bool isDigging(const Shovel* shovel) const;
635
640 agx::Real getDynamicMass( const Shovel* shovel ) const;
641
650 agx::Real getSoilAggregateMass(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
651
657 bool contains(const Shovel* shovel) const;
658
664 bool isRigidBodyShovel(const agx::RigidBody* body) const;
665
671 bool isGeometryShovel(const agxCollide::Geometry* geometry) const;
672
676 bool hasOverlap(const agxCollide::Geometry* geometry) const;
677
688 agx::Material* getMaterial( Terrain::MaterialType type = Terrain::MaterialType::TERRAIN ) const;
689
690
704 void setMaterial(agx::Material* material, Terrain::MaterialType type = Terrain::MaterialType::TERRAIN);
705
706
707 /*
708 Returns the associated material with the given terrainMaterial. Use this material when configuring contact
709 materials between the given terrainMaterial and other materials, for example the shovelMaterial.
710 \returns the associated material with the given terrainMaterial.
711 */
713
714
723 bool setAssociatedMaterial(TerrainMaterial* terrainMaterial, agx::Material* material);
724
725
732 bool exchangeTerrainMaterial(TerrainMaterial* oldTerrainMaterial, TerrainMaterial* newTerrainMaterial);
733
734 /*
735 Remove an added terrain material, its assigned domain will also be removed along with it.
736 \param terrainMaterialToRemove - the terrain material to remove. Note that this can not be the default terrain material, instead try to swithc it with either setTerrainMaterial or exchangeTerrainMaterial!
737 */
738 bool removeTerrainMaterial(TerrainMaterial* terrainMaterialToRemove);
739
740 /*
741 Remove all traces of added terrain materials. Clears the underlying grid with voxel assignments as well as the list with added terrain materials.
742 \param clearAddedMaterials - true to also clear the list of added materials, false to only clear the assigned domains. Default: true.
743 */
744 void clearTerrainMaterials(bool clearAddedMaterials = true);
745
746
758
764 TerrainMaterial* getDefaultTerrainMaterial() const;
765
770 TerrainMaterial* getTerrainMaterial() const;
771
772
779 TerrainMaterial* getTerrainMaterial(agx::Vec3 position) const;
780
787 void setTerrainMaterial( TerrainMaterial* terrainMaterial, agx::Material* material = nullptr);
788
794 bool addTerrainMaterial(TerrainMaterial* terrainMaterial);
795
796
805
813 bool loadLibraryMaterial( const agx::String& materialName );
814
822 static TerrainMaterial* getLibraryMaterial(const agx::String& materialName);
823
824
831
837 bool loadMaterialFile( const agx::String& filename );
838
845
857 agx::ContactMaterial* contactMaterial,
858 Shovel::ExcavationMode mode = Shovel::ExcavationMode::PRIMARY );
859
870 Shovel::ExcavationMode mode = Shovel::ExcavationMode::PRIMARY ) const;
871
880 bool setHeights( const agx::RealVector& heights, bool flipY = false, bool resetCompaction = true );
881
887
888
894
902 agx::RealVector getResizedHeightField(size_t factorX, size_t factorY) const;
903
911
919
924
929
934
939
946
952
963 agx::Vec3iVector& gridPoints ) const;
964
977 agx::Vec3iVector& gridPoints,
978 MassType massType ) const;
979
989 float removeFluidMassInGeometry(agxCollide::Geometry* geometry, float fluidMass);
990
998
1002 size_t getNumSoilParticles() const;
1003
1009
1014
1019
1024
1029
1030 /*
1031 \return Whether the terrain consists of one homogeneous terrain material or not.
1032 */
1034
1042
1050
1058
1066
1074
1076
1078
1080 size_t getNumActiveVoxels() const;
1081
1083 size_t getNumModifiedVoxels() const;
1084
1092 bool verifyMassColumnIntegrity(const agx::Vec2i& terrainIndex) const;
1093
1097 bool isVoxelIndexBelowMaximumDepth(const agx::Vec3i& index) const;
1098
1105 agx::Line transformLineToTerrain(const agx::Line& line) const;
1106
1113 agx::Line transformLineToVoxelSpace( const agx::Line& line ) const;
1114
1121 agx::Line transformLineToWorld(const agx::Line& line) const;
1122
1126 bool isVoxelIndexInsideGeometryBound(const agx::Vec3i& index) const;
1127
1131 agx::AffineMatrix4x4 getVoxelSpaceTransform() const;
1132
1136 bool isBorderIndexAndBordersLocked(const agx::Vec2i& terrainIndex) const;
1137
1138 CompactionController* getCompactionController() const;
1139
1140 TerrainDataAtlas* getTerrainDataAtlas() const;
1141
1142
1143 virtual void runBuildIslandsTask() override;
1144
1145 void clearAllSoilParticles();
1146
1154 float addFluidMassToColumn(const agx::Vec2i& terrainIndex, float fluidMass) const;
1155
1163 float removeFluidMassFromColumn(const agx::Vec2i& terrainIndex, float fluidMass);
1164
1172 float addFluidMass(const agx::Vec3i& voxelIndex, float fluidMass) const;
1173
1181 float removeFluidMass(const agx::Vec3i& voxelIndex, float fluidMass);
1182
1189 agx::Real calculateFluidOccupancy() const;
1190
1197 agx::Real getTotalSoilParticleOccupancy() const;
1198
1204 agx::Vec3 getLocalPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const;
1205
1211 agx::Vec3 getWorldPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const;
1212
1218 agx::Vec3i getVoxelIndexFromLocalPosition(const agx::Vec3& position) const;
1219
1225 inline agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 position) const
1226 {
1227 return VoxelGridUtils::getVoxelIndexFromGridPosition(position, m_voxelSize);
1228 }
1229
1235 inline agx::Vec2i getTerrainIndexFromGridPosition(agx::Vec3 position) const
1236 {
1237 agx::Vec3i vi = getVoxelIndexFromGridPosition(position);
1238 return agx::Vec2i(vi.x(), vi.y());
1239 }
1240
1246 agx::Vec3i getVoxelIndexFromWorldPosition(const agx::Vec3& position) const;
1247
1253 agx::Vec3i getSurfaceVoxelIndexFromTerrainIndex(const agx::Vec2i& terrainIndex) const;
1254
1261 void setForbiddenVoxelsForDynamicMass(const agx::Vec3iVector& voxelIndices);
1262
1268 bool getForbiddenVoxelsForDynamicMass(agx::Vec3iVector& voxelIndices) const;
1269
1276 bool isForbiddenVoxelsForDynamicMass(const agx::Vec3i& voxelIndex) const;
1277
1283 bool voxelContainsShovel(const agx::Vec3i& voxelIndex) const;
1284
1291 bool hasCreatedParticle( agx::Physics::ParticlePtr particle ) const;
1292
1300 bool hasSameParticleMaterial(agx::Physics::ParticlePtr particle) const;
1301
1307 TerrainMassOccupancyController* getMassOccupancyController() const;
1308
1314 TerrainMaterialController* getMaterialController() const;
1315
1316 void adjustFluidMassInGrid(agx::Vec3i binIndex, int binVoxels, float availableFluidMass, float remainingFluidMass);
1317
1318 agx::Vec3iVector getVoxelsOccupiedByShovel(TerrainToolCollection *collection) const;
1319
1320 bool isPointSubmerged( const agx::Vec3& point ) const;
1321
1322 bool voxelHasParticles(const agx::Vec3i& voxelIndex) const;
1323
1324 bool isForbiddenIndex(const agx::Vec3i& index);
1325
1326 void addTerrainIndexToAvalanche(const agx::Vec2i& index);
1327
1328 int getLowestAllowableVoxelIndexZ() const;
1329
1330 agx::Vec3 constructVoxelFieldOffset() const;
1331
1332 void setIsTerrainPagerTile(bool isPagerTile);
1333
1334 bool getIsTerrainPagerTile() const;
1335
1336 bool hasEnabledToolCollections() const;
1337
1338 bool shouldUpdateTerrain() const;
1339
1340 bool hasParticlesInTerrain() const;
1341
1342 void debugRenderFluidMass();
1343
1344 void clampHeights(agx::Real minValue);
1345
1346 bool isSolidVoxel( const agx::Vec3i& index ) const;
1347
1348 bool isActiveSolidVoxel( const agx::Vec3i& index ) const;
1349
1350 void markIndexAsModified( const agx::Vec2i& terrainIndex );
1351
1353
1354 protected:
1359
1363 virtual void addNotification() override;
1364
1368 virtual void removeNotification() override;
1369
1373 virtual void preCollide() override;
1374
1378 virtual void pre() override;
1379
1383 virtual void post() override;
1384
1388 virtual void last() override;
1389
1390 protected:
1399
1400 using GoToStopCondition = std::function<bool(const agx::Vec3i& index)>;
1402
1404 bool isSurfaceVoxel(const agx::Vec3i& index) const;
1405 bool isSolidBoundaryVoxel(const agx::Vec3i& index) const;
1406 bool isSubmergedVoxel(const agx::Vec3i& index) const;
1407 bool isFilledSolidVoxel(const agx::Vec3i& index) const;
1408 bool hasVoxelCompaction(const agx::Vec3i& index) const;
1410 bool getSurfaceVoxel(const agx::Vec3i& voxelIndex, agx::Vec3i& result) const;
1411 bool findPathToSurfaceVoxel(const agx::Vec3i& startVoxel, std::deque<agx::Vec3i>& result);
1412 bool findSurfaceVoxel(const agx::Vec3i& index, agx::Vec3i& result) const;
1413 agx::Vec3i goToVoxelKernel(const agx::Vec3i& start, const GoToStopCondition& stopCondition) const;
1420 void updateSurfaceHeightFieldFromHeightsTable( agx::HashTable<agx::Vec2i, std::pair<agx::Vec3i, agx::Real> >& table );
1421 void traceGridSurfaceVoxel(const agx::Vec2i& terrainIndex, agx::Vec3i& surfaceVoxel) const;
1425 void initVoxelStructureFromHeightField( bool adjustForCompaction = false );
1431 agx::Vec3 getValidParticlePosition(const agx::Real radius, const agx::Vec3i& index, const agx::Vec3& pos);
1435 void storeModifiedTerrainIndex( const agx::Vec2i& terrainVertex );
1439
1441
1443 BasicGrid* grid,
1444 agxCollide::Geometry* geometry,
1445 agx::Vec3iVector& gridPoints,
1446 bool isOccupied = true) const;
1447
1450
1452
1453 /*
1454 For every column we have particles in, shoot a ray into space and find possible collisions with the geometries that are connected in the particle-surface graph.
1455 If there is a collision, save the position for filtering later.
1456 */
1458 agx::HashTable <agx::Vec2i, agx::Vec4>& contactPositionTable,
1459 const TerrainIndexSet& columnTerrainIndices,
1460 bool parallelExecute);
1461
1462 /*
1463 Filter away particles so the remaining particles all are below that columns contact position voxel.
1464 This prevents merging through geometries.
1465 */
1466 void filterParticlesAboveContactGeometryVoxels( agx::HashTable <agx::Vec2i, agx::Vec4>& contactPositionTable,
1468
1470
1472
1475
1476 // Sampling method
1478
1481 bool isDirty();
1482 void markVoxelToAvalanche(const agx::Vec3i& changedVoxel);
1484 void updateOccupancyFromHeightChange(const agx::Vec2i& heightFieldIndex);
1489
1490 // Resize soil particles
1493 void growParticlesFromFluidMass(agx::Vec3i binIndex, int binVoxels, float availableFluidMass, ParticleDeltaVector& particles);
1494 void growSmallParticlesFromParticleMass(ParticleDeltaVector& particles, float particleRadiusUpperLimit);
1495 void growLargeParticlesFromParticleMass(ParticleDeltaVector& particles, float particleRadiusUpperLimit);
1496
1497 // Merge soil particles functions
1502 void mergeParticleIslands( const ParticleIslandVector& particleIslands, agxData::LocalVector<agx::Vec3i>& mergedParticleIndices );
1503 void resizeOrRemoveParticles( const agx::HashTable<SoilParticlePtr, std::array<agx::Real, 2>>& particlesToUpdate );
1505
1506 // Merge to cutting edge functions
1508 agx::Vec3iVector mergeCuttingEdgeColumn(agx::Vec3i cuttingEdgeVoxel, size_t numVoxelsToSurfaceThreshold, agx::Plane cuttingPlane);
1509 float convertParticlesToSolidMass(agx::Vec3i voxel, ParticleWeightPairVector particles, float occupancyToRemove, agx::Vec3iVector& changedIndices);
1510 void moveParticlesToSurface(agx::Vec3iVector changedVoxelIndices);
1511
1512 // Step fluid mass
1518 void createFluidMassInVoxel(const agx::Vec3i& voxelIndex, agx::Real32 amount);
1519 void createFluidMassOnTerrainSurface(const agx::Vec2i& terrainIndex, int surfaceVoxelOffset, agx::Real32 amount);
1520
1521 // Conversion functions for particle radius and general occupancy
1522 float convertParticleRadiusToOccupancy(float radius) const;
1523 float convertOccupancyToParticleRadius(float occupancy) const;
1524 float getDynamicMassCompaction(const agx::Vec3i& voxelIndex) const;
1525 bool particleIslandShouldMerge(const agx::Vector<std::pair<agx::Vec3i, offsetIndexInfo>>& island);
1526 bool voxelColumnHasParticles(const agx::Vec2i& vertex) const;
1527
1528 // TerrainMaterial bookkeeping functions
1533
1534
1535
1537
1539
1542
1546
1549
1550 AvalancheController* getAvalancheController() const;
1551
1553
1555
1560
1561 const agx::AffineMatrix4x4& _getVoxelSpaceTransform() const;
1562 const agx::AffineMatrix4x4& _getInvVoxelSpaceTransform() const;
1563 const agx::AffineMatrix4x4& _getTransform() const;
1564 const agx::AffineMatrix4x4& _getInverseTransform() const;
1565
1567
1569
1570 friend class AvalancheController;
1572 friend class TerrainMaterial;
1576 friend class TerrainMaterialController;
1578 friend class TerrainPhysics;
1579 friend class TerrainCache;
1580
1581 protected:
1582 virtual ~Terrain();
1583
1584 Terrain(agxCollide::HeightField* heightField, agx::Real maximumDepth);
1585
1586 private:
1589
1590 private:
1591 agxCollide::HeightFieldRef m_surfaceHeightField;
1592 agxCollide::HeightFieldRef m_particleHeightField;
1593 agx::Real m_voxelSize;
1594 TerrainPropertiesRef m_properties;
1595 agx::UniformRealGenerator m_generator;
1596 float m_nominalSoilParticleRadius;
1597
1598 agxCollide::GeometryRef m_surfaceGeometry;
1599 agx::AffineMatrix4x4 m_transform;
1600 agx::AffineMatrix4x4 m_invTransform;
1601 agx::AffineMatrix4x4 m_voxelSpaceTransform;
1602 agx::AffineMatrix4x4 m_invVoxelSpaceTransform;
1603 agx::Vec3 m_voxelFieldOffset;
1604
1605 TerrainDataAtlasRef m_terrainDataAtlas;
1606 TerrainMassOccupancyControllerRef m_massOccupancyController;
1607 TerrainMaterialControllerRef m_materialController;
1608 CompactionControllerRef m_compactionController;
1609 TerrainContactGeneratorRef m_terrainContactGenerator;
1610 AvalancheControllerRef m_avalancheController;
1611 SoilSimulationInterfaceRef m_soilSimulationInterface;
1612 TerrainGridControlRef m_terrainGridInterface;
1613
1614 agx::MaterialRef m_particleMaterial;
1615 agx::MaterialRef m_aggregateMaterial;
1616
1617 agx::ContactMaterialRef m_terrainParticleContactMaterial;
1618 agx::ContactMaterialRef m_terrainAggregateContactMaterial;
1619 agx::ContactMaterialRef m_particleParticleContactMaterial;
1620
1621 TerrainToolCollectionRefVector m_toolCollections;
1622 AvalancheController::TerrainIndexSet m_terrainIndicesToAvalanche;
1623
1624 agx::HashTable<agxCollide::Geometry*, agx::Real> m_noMergeGeometryToDistance;
1625 size_t m_noMergeEdgeMargin;
1626 bool m_noMerge;
1627 BoundingAABBVector m_forbiddenBounds;
1628 agx::HashTable<agx::Vec3i, size_t> m_voxelIndexToShovelIndex;
1629 agx::HashTable<TerrainToolCollection*, agx::Vec3iVector> m_voxelsInPrimaryActiveZoneLastTimeStep;
1630 agx::Vec3iVector m_dirtyVoxelIndices;
1631 agx::Real32Vector m_removedOccupancy;
1632 agx::Real m_lastRemovedVolume;
1633 VoxelIndexSet m_voxelHasCreatedParticle;
1634 VoxelIndexSet m_forbiddenVoxelsForDynamicMass;
1635 TerrainIndexSet m_mergedTerrainVertices;
1636 ModifiedVerticesSetVector m_modifiedVoxelColumns;
1637 ModifiedVerticesSetVector m_modifiedTerrainVertices;
1638 ModifiedVerticesSetVector m_modifiedParticleVertices;
1639 ModifiedVerticesSetVector m_particleTerrainVertices;
1640
1641
1642 size_t m_numCreatedParticles;
1643 float m_averageSoilParticleRadius;
1644
1645 // Sort particles into voxels
1646 VoxelIndexOffsetIndexInfoTable m_voxelParticleOffsetTable;
1647 ParticleWeightPairVector m_voxelParticleWeightPairVector;
1648
1649 // Sort particles into columns
1650 agx::IndexVector m_particlesInContactWithSurface;
1651 agx::HashTable <agx::Vec2i, agx::Vec4> m_contactPositionTable;
1652
1653 VoxelIndexOffsetIndexInfoTable m_columnParticleOffsetTable;
1654 ParticleWeightPairVector m_columnParticleWeightPairVector;
1655
1656 agx::HashTable<agx::Vec2i, agx::Real> m_columnParticleHeight;
1657 agx::HighAccuracyTimer m_timer;
1658
1659 agx::IndexLambdaKernelRef m_indexKernel;
1660
1661 bool m_isTerrainPagerTile;
1662 bool m_enable;
1663
1664 // !HACK! !BEWARE! Islands partitioning
1665 // The build islands task is not executed when using PPGS.
1666 // No island partitioning means no parallelization of solving the rigid body system.
1667 // However, we still need islands in Terrain to determine which particles are in contact with the ground.
1668 // Thus, we manually load and execute the task in Terrain.
1669 // The task is loaded and bound for each Terrain that is added but is only executed once by agxSDK::Simulation.
1670 // The task is executed using the runBuildIslandsTask() method.
1671 agx::TaskRef m_buildIslandsTask;
1672 agx::TaskGroupRef m_preCollideUpdateTask;
1673 agx::TaskRef m_sortParticlesToVoxelsTask;
1674 agx::TaskRef m_sortParticlesToColumnsTask;
1675 agx::TaskRef m_calculateShovelVoxelIntersection;
1676 agx::TaskRef m_convertSolidToDynamicMassTask;
1677
1678 agx::ParallelTaskRef m_updateHeightfieldsTask;
1679 agx::Job m_updateHeightfieldsJobs[2];
1680 agx::ParallelTaskRef m_voxelCollisionTask;
1681 agx::ParallelTaskRef m_geometryFilterTask;
1682
1683 bool m_enableFluidMerge; // Only used for testing. Should not be serialized.
1684
1685 agx::Vector<agxCollide::ShapeRef> m_userInputFailureShapes;
1686 };
1687
1688
1689 inline TerrainDataAtlas* Terrain::getTerrainDataAtlas() const
1690 {
1691 return m_terrainDataAtlas;
1692 }
1693
1695 {
1696 return m_materialController->getDefaultTerrainMaterial();
1697 }
1698
1699
1701 {
1702 return m_materialController->getDefaultTerrainMaterial();
1703 }
1704
1705
1707 {
1708 auto voxelIndex = getVoxelIndexFromWorldPosition(position);
1709 return m_materialController->getTerrainMaterial(voxelIndex);
1710 }
1711
1712
1713 inline size_t Terrain::getResolutionX() const
1714 {
1715 return m_surfaceHeightField->getResolutionX();
1716 }
1717
1718
1719 inline size_t Terrain::getResolutionY() const
1720 {
1721 return m_surfaceHeightField->getResolutionY();
1722 }
1723
1724
1726 {
1727 return m_voxelSize;
1728 }
1729
1730
1731
1733 {
1734 return m_voxelSpaceTransform;
1735 }
1736
1737
1738
1740 {
1741 return m_invVoxelSpaceTransform;
1742 }
1743
1744
1745
1747 {
1748 return m_transform;
1749 }
1750
1751
1752
1754 {
1755 return m_invTransform;
1756 }
1757
1758
1759 inline agx::Vec3i Terrain::getSurfaceVoxelIndexFromTerrainIndex(const agx::Vec2i& terrainIndex) const
1760 {
1761 auto solidGrid = static_cast<ColumnHeightGrid*>(m_terrainDataAtlas->getGridMassOccupancyData(TerrainDataAtlas::MassType::SOLID));
1762 int voxelHeight = solidGrid->getSurfaceHeightIndex(terrainIndex);
1763
1764 return agx::Vec3i( terrainIndex.x(), terrainIndex.y(), voxelHeight);
1765 }
1766
1767 inline bool Terrain::getIsTerrainPagerTile() const
1768 {
1769 return m_isTerrainPagerTile;
1770 }
1771
1772 inline bool Terrain::getDeformable() const
1773 {
1774 return m_properties->getEnableDeformation();
1775 }
1776
1777}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
#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
A HeightField is a collision shape that can be created from a grid structure, like an image.
Base class for a shape.
Definition Shape.h:54
Only use as member allocated variable.
Definition Value.h:285
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition Simulation.h:126
agxTerrain::Terrain instance in a simulation, receiving step and contact callbacks in a controllable ...
Pure virtual interface class for the data storage grid classes we have.
Definition Grid.h:72
Class implementing the BasicGrid interface.
int getSurfaceHeightIndex(const agx::Vec2i terrainIndex)
Controller that handles compaction in the terrain from generated terrain contacts in TerrainContactGe...
ExcavationMode
Enum for describing the different excavation modes of a shovel: PRIMARY - The primary mode of excavat...
Definition Shovel.h:92
Interface class for accessing data and functions for the internal soil particle simulation used in ag...
The TerrainCache is used internally by the TerrainPager to provide requested terrain tiles.
Interface class for accessing and manipulating the underlying 3D grid data in the terrain using terra...
Class that handles and sanity checks the mass logic in the terrain.
This class is used to describe the general material properties of the Terrain.
Utility class where most of the physics calculation used in agxTerrain is gathered.
Class for containing and managing the different agxTerrain::Terrain settings.
Collection of terrain tool (currently Shovel) related objects which are terrain instance specific.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition Terrain.h:86
void triggerForceAvalancheAll()
Triggers initial avalanching on all indices in the terrain.
bool exchangeTerrainMaterial(TerrainMaterial *oldTerrainMaterial, TerrainMaterial *newTerrainMaterial)
Exchange an already added TerrainMaterial with another TerrainMaterial without changing its associate...
void addModifiedParticleTerrainIndex(const agx::Vec2i &terrainIndex)
float convertParticlesToSolidMass(agx::Vec3i voxel, ParticleWeightPairVector particles, float occupancyToRemove, agx::Vec3iVector &changedIndices)
bool getEnable() const
agx::ContactMaterial * getContactMaterial(Terrain::MaterialType type1, Terrain::MaterialType type2)
Returns one of the internal contact materials in agxTerrain.
void initializeFromHeightField()
float convertParticleRadiusToOccupancy(float radius) const
static TerrainPtrVector findAll(const agxSDK::Simulation *simulation)
Finds all terrains in the given simulation.
agx::Real convertFluidOccupancyToMass(agx::Real occupancy) const
agx::Vec3 getSurfacePosition(const agx::Vec2i &terrainIndex, bool includeSurfaceParticles=false) const
Finds the terrain surface position, given in local coordinate frame, for a specified terrain index.
bool getNoMerge()
Return whether this terrain is prevented from merging dynamic mass to it.
void sanitizeMaxDepthData(agx::Real maximumDepth)
const agx::AffineMatrix4x4 & _getTransform() const
Definition Terrain.h:1746
agx::Real convertFluidMassToOccupancy(agx::Real mass) const
void updateSurfaceHeightFieldFromVoxelIndices(const agxData::LocalVector< agx::Vec3i > &updateIndices)
void preSortSynchronizeParticleHeightField()
bool getSurfaceVoxel(const agx::Vec3i &voxelIndex, agx::Vec3i &result) const
bool addNoMergeZoneToGeometry(agxCollide::Geometry *geometry, agx::Real extensionDistance)
Add disable merge and avalanche inside geometry bound with added extension distance.
float getParticleNominalRadius() const
Get the soil particle nominal radius from the simulation.
AvalancheController * getAvalancheController() const
void convertVoxelsInActiveZonesToDynamicMass()
bool getDeformable() const
Gets whether or not deformations are enabled for this terrain.
Definition Terrain.h:1772
agx::Real getInnerVolume(const Shovel *shovel) const
void moveParticlesToSurface(agx::Vec3iVector changedVoxelIndices)
agx::Real getLastDeadLoadFraction(const Shovel *shovel) const
Get the last computed dead load fraction of the shovel, i.e how much of it's inner volume that is fil...
bool remove(Shovel *shovel)
Removes a shovel object in the terrain, if it exists.
void convertToDynamicMassInShape(agxCollide::Shape *shape)
Converts the terrain occupancy that overlaps the specified shape into dynamic mass.
bool contains(const Shovel *shovel) const
Check is a shovel object is registered in the terrain.
bool loadLibraryMaterial(const agx::String &materialName)
Loads a TerrainMaterial preset in the TerrainMaterialLibrary that contains calibrated bulk and contac...
void sortParticlesIntoVoxels()
agx::HashVector< agx::Vec2i, agx::Int > getShovelHeightPerColumn()
agx::Vec3 getAggregateTerrainTangentialForce(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Get the aggregate tangential force with the terrain given an excavation mode and a shovel.
agxCollide::GeometryContactPtrVector getShovelAggregateContacts(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Get the shovel <-> aggregate contacts with the terrain given an excavation mode and a shovel.
float convertOccupancyToParticleRadius(float occupancy) const
static TerrainMaterial * getMaterialFromFile(const agx::String &filename)
Load a TerrainMaterial from a specification file in JSON data format.
agx::HashTable< agx::Vec3i, agx::UInt64Vector > sortParticlesIntoBins(int binVoxels)
agx::ContactMaterial * getShovelAggregateContactMaterial(const Shovel *shovel, Shovel::ExcavationMode mode=Shovel::ExcavationMode::PRIMARY) const
Get the explicitly set contact material in a shovel-aggregate contact corresponding to a specified ex...
void initVoxelStructureFromHeightField(bool adjustForCompaction=false)
static agx::StringVector getAvailableLibraryMaterials()
Get the available TerrainMaterial presets from the TerrainMaterialLibrary that contains calibrated bu...
bool setHeights(const agx::RealVector &heights, bool flipY=false, bool resetCompaction=true)
Set height values of all sampled points.
agx::Real calculateTotalMass() const
agx::RealVector getMaterialWeightsInGridPoints(const agx::Vec3iVector &gridPoints) const
Get the material weights in the terrain of the specified grid points.
agx::Vec3 getDeformationContactForce(const Shovel *shovel) const
Given geometry contacts exists and the solver has solved them - calculates total contact force betwee...
void calculateShovelVoxelIntersection()
const agx::AffineMatrix4x4 & _getInverseTransform() const
Definition Terrain.h:1753
agx::Vec3i goToSurfaceVoxel(const agx::Vec3i &start) const
agx::Real getLastExcavatedVolume() const
agx::Vec3 transformPointToVoxelSpace(const agx::Vec3 point) const
Transform point given in world coordinate frame to local coordinate frame of this terrain.
void setHeight(const agx::Vec2i &terrainIndex, agx::Real height)
Sets Terrain height at a specific terrain grid node.
agx::Vec3 generateRandomSoilParticlePositionPerturbation(agx::Real maxDelta)
agx::Bool projectPointToSurface(const agx::Vec3 &worldPosition, agx::Vec3 &result) const
Project a world point to the grid surface.
void setTransform(const agx::AffineMatrix4x4 &transform)
Set the transform of this terrain.
float removeFluidMassInGeometry(agxCollide::Geometry *geometry, float fluidMass)
Remove fluid mass (in kg, NOT occupancy) in the intersecting 3D grid element with specified geometry.
agx::Real traceGridSurfaceHeightFromVoxelIndex(const agx::Vec3i &index)
SoilParticlePtrVector calculateParticlesInContactWithSurfaceGraph(agxCollide::GeometryPtrVector &contactGeometries)
agx::Vec3 getExcavationModeContactForce(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
calculates total contact force between the soil aggregate associated with the specified excavation mo...
void mergeSoilToCuttingEdge()
agx::Quat generateRandomSoilParticleRotation()
void toolCollectionsPreCollide()
SoilSimulationInterface * getSoilSimulationInterface() const
Get the soil particle system interface used to represent the dynamic mass in the terrain.
static TerrainPtrVector findAll(const agxSDK::Simulation *simulation, const agx::Name &name)
Find all terrains with given name.
agx::Real calculateVolume()
agx::Vec3 getSeparationFrictionForce(const Shovel *shovel) const
Given geometry contacts exists and the solver has solved them - calculates total contact friction for...
agx::Real getVoxelArea() const
void preUpdateTerrainContacts()
agx::Real getDynamicMass(const Shovel *shovel) const
bool isSolidBoundaryVoxel(const agx::Vec3i &index) const
agx::RealVector getMaterialWeightsInLine(const agx::Line &line) const
Get the material weights in the terrain of the voxels that intersect the specified line.
bool isBorderIndex(const agx::Vec2i &terrainIndex) const
Checks if the specified index is at the border of the terrain.
void setCompaction(agx::Real compaction, bool replaceCompactedSoil=true) const
Set a compaction for all current active solid grid elements in the Terrain object.
agx::Vec3 getPosition() const
void updateInternalTransforms()
const TerrainToolCollectionRefVector & getToolCollections() const
bool isSubmergedVoxel(const agx::Vec3i &index) const
const agxCollide::HeightField * getSoilParticleBoundedHeightField() const
Get the soil particle height field consisting of the highest point of either the terrain surface or t...
bool shouldPrimaryActiveZoneRemoveMass(TerrainToolCollection *toolCollection)
float getDynamicMassCompaction(const agx::Vec3i &voxelIndex) const
void debugRenderShovelForbiddenBounds()
bool removeNoMergeZoneToGeometry(agxCollide::Geometry *geometry)
remove disable merge and avalanche inside geometry bound with added extension distance
void moveEntityDataToCurrentThread()
agx::Real getAggregateTerrainContactArea(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Get the aggregate <-> terrain contact area given an excavation mode and a shovel.
void debugRenderContactGeometryVoxels()
agx::AffineMatrix4x4 getInverseTransform() const
agx::Vec3i goToBoundaryVoxel(const agx::Vec3i &start) const
bool hasOverlap(const agxCollide::Geometry *geometry) const
Return true if the specified geometry bounding volume overlaps the terrain geometry bounding volume.
bool voxelColumnHasParticles(const agx::Vec2i &vertex) const
void sanityCheckHeightFieldAgainstMaxDepth()
void addDirtyVoxelsToAvalanche()
agx::Real getElementSize() const
Returns the element size of a cell in agxTerrain, which is incidentally the distance between the cent...
Definition Terrain.h:1725
TerrainMaterial * getTerrainMaterial() const
Returns the default terrain material which is used to derive material and contact material parameters...
Definition Terrain.h:1700
bool shouldDeformerActiveZoneRemoveMass(TerrainToolCollection *toolCollection, DeformerCollection *deformerCollection)
void updateSurfaceHeightFieldFromVoxelIndices(const agx::Vec3iVector &updateIndices)
agx::Real calculateTotalDynamicMass() const
bool isGeometryShovel(const agxCollide::Geometry *geometry) const
Checks if the specified geometry's rigid body is contained in any of the terrain object's registered ...
void createFluidMassOnTerrainSurface(const agx::Vec2i &terrainIndex, int surfaceVoxelOffset, agx::Real32 amount)
agx::Real getMinimumAllowedHeight() const
agx::Vec3 getValidParticlePosition(const agx::Real radius, const agx::Vec3i &index, const agx::Vec3 &pos)
agx::Vec3 getUpDirection() const
Returns the world up direction of the terrain.
agx::Vec3 transformVectorToTerrain(const agx::Vec3 vector) const
Transform vector given in world coordinate frame to local coordinate frame of this terrain.
const agxCollide::HeightField * getHeightField() const
bool isFilledSolidVoxel(const agx::Vec3i &index) const
bool add(Shovel *shovel)
Adds a shovel object in the terrain.
bool hasVoxelCompaction(const agx::Vec3i &index) const
size_t getMemoryUsage()
Returns the memory usage in bytes in agxTerrain.
agx::Real getVoxelVolume() const
bool getPenetrationForce(const Shovel *shovel, agx::Vec3 &force, agx::Vec3 &torque) const
The result includes the active force and torque from the penetration resistance from the terrain on t...
const ModifiedVerticesVector & getModifiedParticleVertices() const
Returns the modified terrain height field (including particles) vertices during the last time step.
const agx::AffineMatrix4x4 & _getInvVoxelSpaceTransform() const
Definition Terrain.h:1739
void createParticleIslands(ParticleIslandVector &particleIslands)
void updateIndicesForAvalanche(TerrainIndexSet &forbiddenVertices)
agx::Real getMergeSpeedSquared() const
void resizeOrRemoveParticles(const agx::HashTable< SoilParticlePtr, std::array< agx::Real, 2 > > &particlesToUpdate)
void updateSurfaceHeightFieldFromDirtyVoxels()
bool isDigging(const Shovel *shovel) const
Check if the specified shovel is currently in digging mode with the terrain, i.e if the cutting edge ...
bool isOfHomogeneousTerrainMaterial() const
void removeEmptyTerrainMaterialVoxels()
Removes terrain material info from the empty voxels that was modified during this pre step.
bool isIndexWithinBounds(const agx::Vec2i &terrainIndex) const
Checks if the specified index is within bound of the terrain [(0,0) -> (resolutionX,...
void storeModifiedTerrainIndex(const agx::Vec2i &terrainVertex)
void updateTransformationFromParentBody()
agx::Material * getAssociatedMaterial(TerrainMaterial *terrainMaterial) const
void setTerrainMaterial(TerrainMaterial *terrainMaterial, agx::Material *material=nullptr)
Set the default terrain material for the bulk of the terrain which is used to derive material and con...
agx::Real findNewHeightFromVoxelIndex(const agx::Vec3i &index)
void removeModifiedParticleVertice(agx::Vec2i terrainIndex)
Removes a vertex from the vector with vertices that were modified during the last time step.
Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize, const agx::RealVector &heights, bool flipY, agx::Real maximumDepth)
Constructor.
agx::Real getSoilAggregateMass(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Returns the total soil aggregate mass in a terrain given a shovel and a specific excavation mode.
TerrainProperties * getProperties() const
TerrainIndexSet findTerrainIndices(agxTerrain::SoilParticlePtrVector &particles)
bool isWorldPositionWithinBounds(const agx::Vec3 &position) const
Checks whether the position is within terrain (x,y) position bounds in world space.
agx::Vec3 getAggregateTerrainContactForce(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Get the aggregate contact force with the terrain given an excavation mode and a shovel.
bool getIntersectingGridElements(agxCollide::Geometry *geometry, agx::Vec3iVector &gridPoints) const
Get intersecting 3D grid element with specified geometry.
void convertRemovedOccupancyToDynamicMass()
agx::Real calculateSurfaceHeightFromVoxelIndex(const agx::Vec3i &voxelIndex)
void postSortSynchronizeParticleHeightField()
agx::Real calculateTotalSolidMass() const
static agx::Real getTerrainParticlePackingRatio()
agx::Vec3 getContactForce(const Shovel *shovel) const
Given geometry contacts exists and the solver has solved them - calculates total shovel contact force...
void applyFluidMassChanges(agx::HashTable< agx::Vec3i, float > &fluidMassTable)
void computeForbiddenBounds()
agx::Vec3f getVoxelVelocity(const agx::Vec3i &voxelIndex, agx::HashTable< agx::Vec3i, size_t > &shovelVoxels)
bool isVoxelWithinTerrainIndexBounds(const agx::Vec3i &index) const
void updateSurfaceHeightFieldFromHeightsTable(agx::HashTable< agx::Vec2i, std::pair< agx::Vec3i, agx::Real > > &table)
bool addTerrainMaterial(TerrainMaterial *terrainMaterial)
Add a non default TerrainMaterial to the terrain instance, without designating its domain.
agx::Real getTotalSoilParticleMass() const
Get the total mass (kg) of the active soil particles in the simulation.
void calculateFluidMassTransport(agx::HashTable< agx::Vec3i, float > &fluidMassTable)
const agx::AffineMatrix4x4 & _getVoxelSpaceTransform() const
Definition Terrain.h:1732
void createFluidMassInVoxel(const agx::Vec3i &voxelIndex, agx::Real32 amount)
agx::Real calculateTotalFluidMass() const
int addTerrainMaterial(TerrainMaterial *terrainMaterial, agxCollide::Geometry *geometry)
Add a non default TerrainMaterial to the designated region bounded by the overlap between the terrain...
agx::TaskGroupRef createTask_preCollide()
void updateOccupancyFromHeightChange(const agx::Vec2i &heightFieldIndex)
bool loadMaterialFile(const agx::String &filename)
Load a TerrainMaterial from a specification file in JSON data format.
ShovelRefVector getShovels() const
Return the shovels currently added in the terrain.
size_t getNumCreatedParticles() const
Return the number of soil particles created during excavation this time step.
void renderVoxelAABB(agx::Vec3i index, agx::Vec4f color)
void setDeformable(bool deformable)
Sets if deformation should be enabled on this terrain.
void computeParticleGrowthTables(const agx::UInt64Vector &particleIndices, ParticleDeltaVector &particles)
agxCollide::GeometryContactPtrVector getAggregateTerrainContacts(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Get the aggregate <-> terrain geometry contacts given an excavation mode and a shovel.
void debugRenderForbiddenBounds()
agx::Vec3 getSurfacePositionWorld(const agx::Vec2i &terrainIndex, bool includeSurfaceParticles=false) const
Finds the terrain surface world position for a specified terrain index.
agx::Vec3 getSeparationContactForce(const Shovel *shovel) const
Given geometry contacts exists and the solver has solved them - calculates total contact force betwee...
std::function< bool(const agx::Vec3i &index)> GoToStopCondition
Definition Terrain.h:1400
static Terrain * find(const agxSDK::Simulation *simulation, const agx::Uuid &uuid)
Find terrain with given UUID.
static TerrainMaterial * getLibraryMaterial(const agx::String &materialName)
Loads a TerrainMaterial preset in the TerrainMaterialLibrary that contains calibrated bulk and contac...
SoilParticleStatistics getSoilParticleStatistics() const
Get basic statistics of the soil particles active in the simulation.
Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize, agx::Real maximumDepth)
Constructor.
const TerrainContactRefVector & getTerrainContacts() const
bool isLocalPositionWithinBounds(const agx::Vec3 &position) const
Checks whether the position is within terrain (x,y) position bounds in local space.
static Terrain * find(const agxSDK::Simulation *simulation, const agx::Name &name)
Find first terrain with given name.
void initializeSurfaceHeightFieldFromVoxelGrid()
void enforceIncompressibilityColumnwise()
void setNoMerge(bool noMerge)
Prevent merge of dynamic mass to this terrain.
bool getIntersectingActiveGridElements(agxCollide::Geometry *geometry, agx::Vec3iVector &gridPoints, MassType massType) const
Get intersecting 3D grid element with specified geometry that is active/occupied with a specified mas...
agx::Vec3 transformVectorToWorld(const agx::Vec3 vector) const
Transform vector given in local coordinate frame of this terrain, to world coordinate frame.
agx::Material * getMaterial(Terrain::MaterialType type=Terrain::MaterialType::TERRAIN) const
Returns one of the internal materials in agxTerrain: MaterialType::TERRAIN - The internal material us...
bool particleIslandShouldMerge(const agx::Vector< std::pair< agx::Vec3i, offsetIndexInfo > > &island)
bool findSurfaceVoxel(const agx::Vec3i &index, agx::Vec3i &result) const
void mergeParticleIslands(const ParticleIslandVector &particleIslands, agxData::LocalVector< agx::Vec3i > &mergedParticleIndices)
void sampleParticleMassVelocity()
void clearTerrainMaterials(bool clearAddedMaterials=true)
TerrainGridControl * getTerrainGridControl() const
Get control interface of the terrain grid data.
static agx::Bool getEnableKinematicForParticles(const agx::RigidBody *rb)
void removeSoilParticlesOutsideTerrainBounds()
void sortParticlesIntoColumns()
void markVoxelToAvalanche(const agx::Vec3i &changedVoxel)
agx::Quat getRotation() const
agx::Vec2 getSize() const
Returns the total surface size of he terrain in X Y coordinate system.
size_t getResolutionY() const
Definition Terrain.h:1719
agx::Vec3 getSeparationNormalForce(const Shovel *shovel) const
Given geometry contacts exists and the solver has solved them - calculates total contact normal force...
void traceGridSurfaceVoxel(const agx::Vec2i &terrainIndex, agx::Vec3i &surfaceVoxel) const
void mergeSoilParticlesAndFluidMass()
void updateSurfaceHeightFieldFromVoxelIndex(const agx::Vec3i &voxelIndex)
agx::Vec3iVector mergeCuttingEdgeColumn(agx::Vec3i cuttingEdgeVoxel, size_t numVoxelsToSurfaceThreshold, agx::Plane cuttingPlane)
void growSmallParticlesFromParticleMass(ParticleDeltaVector &particles, float particleRadiusUpperLimit)
static void setEnableKinematicForParticles(agx::RigidBody *rb, agx::Bool enable)
Enable/disable particles to see this rigid body as kinematic regardless of current motion control.
bool removeTerrainMaterial(TerrainMaterial *terrainMaterialToRemove)
agx::Real generateRandomNumber()
void setRotation(const agx::Quat &rotation)
Set the rotation of this terrain.
void growParticlesFromFluidMass(agx::Vec3i binIndex, int binVoxels, float availableFluidMass, ParticleDeltaVector &particles)
const ModifiedVerticesVector & getModifiedVertices() const
Returns the modified terrain height field vertices during the last time step.
void filterParticlesAboveContactGeometryVoxels(agx::HashTable< agx::Vec2i, agx::Vec4 > &contactPositionTable, agxTerrain::SoilParticlePtrVector &particles)
bool findPathToSurfaceVoxel(const agx::Vec3i &startVoxel, std::deque< agx::Vec3i > &result)
agx::Vec3i goToVoxelKernel(const agx::Vec3i &start, const GoToStopCondition &stopCondition) const
void setPosition(const agx::Vec3 &position)
Set the position of this terrain.
const ModifiedVerticesVector & getParticleVertices() const
Returns the terrain vertices that contains soil particles during the last time step.
void setEnable(bool enable)
Set if terrain computations should be enabled.
TerrainMaterial * getDefaultTerrainMaterial() const
Returns the default terrain material which is used to derive material and contact material parameters...
Definition Terrain.h:1694
bool isSurfaceVoxel(const agx::Vec3i &index) const
Surface voxel functions.
agx::Vec3 transformPointToTerrain(const agx::Vec3 point) const
Transform point given in world coordinate frame to local coordinate frame of this terrain.
bool setAssociatedMaterial(TerrainMaterial *terrainMaterial, agx::Material *material)
Set the associated material with the given TerrainMaterial.
agx::Vec3 transformPointToWorld(const agx::Vec3 point) const
Transform point given in local coordinate frame of this terrain, to world coordinate frame.
agx::RealVector getResizedHeightField(size_t factorX, size_t factorY) const
Calculate a reduced version of the height field structure.
static Terrain * createFromHeightField(const agxCollide::HeightField *heightField, agx::Real maximumDepth)
Creates a terrain object by using an existing height field as a basis.
void raytraceColumns(agxCollide::GeometryPtrVector geometries, agx::HashTable< agx::Vec2i, agx::Vec4 > &contactPositionTable, const TerrainIndexSet &columnTerrainIndices, bool parallelExecute)
void addNeighbours(agxData::LocalVector< agx::Vec3i > &indexQueue, agx::Vec3i index)
TerrainToolCollection * getToolCollection(const Shovel *shovel) const
Terrain(agxCollide::HeightField *heightField, agx::Real maximumDepth)
size_t getNumSoilParticles() const
Return the number of soil particles active in the simulation.
bool isRigidBodyShovel(const agx::RigidBody *body) const
Checks if a specified rigid body is contained in any of the terrain object's registered shovels.
void growLargeParticlesFromParticleMass(ParticleDeltaVector &particles, float particleRadiusUpperLimit)
virtual agxCollide::Geometry * getGeometry() const override
bool _getIntersectingGridElements(BasicGrid *grid, agxCollide::Geometry *geometry, agx::Vec3iVector &gridPoints, bool isOccupied=true) const
void setNoMergeEdgeMargin(size_t noMergeEdgeMargin)
Add disable merge and avalanche a number of indices from the terrain edge.
agx::Real getHeight(const agx::Vec2i &terrainIndex, bool includeSurfaceParticles=false) const
Gets the terrain height at a specific terrain grid node.
agx::Bool isIndexWithinBoundsIssueWarning(const agx::Vec2i &terrainIndex) const
size_t getResolutionX() const
Definition Terrain.h:1713
agx::Vec3 getAggregateTerrainNormalForce(const Shovel *shovel, Shovel::ExcavationMode excavationMode) const
Get the aggregate normal force with the terrain given an excavation mode and a shovel.
void setMaterial(agx::Material *material, Terrain::MaterialType type=Terrain::MaterialType::TERRAIN)
Assign new material to this terrain.
agx::Vec2i getClosestGridPoint(const agx::Vec3 &worldPosition, bool clampToBound=false) const
Finds the closes terrain grid point given any point in world.
bool setShovelAggregateContactMaterial(const Shovel *shovel, agx::ContactMaterial *contactMaterial, Shovel::ExcavationMode mode=Shovel::ExcavationMode::PRIMARY)
Explicitly set contact material properties in a shovel-aggregate contact for a specific excavation mo...
agx::AffineMatrix4x4 getTransform() const
This class store the combine material properties between two agx::Material's.
Definition Material.h:516
Inheritance with partial specialization due to bug with ref_ptr containers.
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition HashVector.h:41
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
An abstract job/workblock representation, which allows work threads to execute arbitrary tasks.
Definition Job.h:63
Inheritance with partial specialization due to bug with ref_ptr containers.
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition Material.h:376
Representation of a name string.
Definition Name.h:33
Pointer to a entity instance of type Physics.GranularBody.
Pointer to a entity instance of type Physics.Particle.
Class representing the mathematical concept of a plane, also called a half- space.
Definition agx/Plane.h:32
The rigid body class, combining a geometric model and a frame of reference.
Definition RigidBody.h:52
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition SetVector.h:38
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition Uuid.h:42
A class holding 4 dimensional vectors and providing basic arithmetic.
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
agx::SetVector< agx::Vec2i > ModifiedVerticesSetVector
Definition Terrain.h:60
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
std::pair< SoilParticlePtr, agx::Real > ParticleWeightPair
Definition Terrain.h:57
agx::Vector< ParticleWeightPair > ParticleWeightPairVector
Definition Terrain.h:58
agx::Vector< std::pair< SoilParticlePtr, float > > ParticleDeltaVector
Definition Terrain.h:62
agx::HashTable< agx::Vec3i, ParticleWeightPairVector > IndexToParticleWeightPairVector
Definition Terrain.h:59
agx::Physics::GranularBodyPtr SoilParticlePtr
agx::Vector< agx::Vec2i > ModifiedVerticesVector
Definition Terrain.h:61
agx::HashSet< agx::Vec3i > VoxelIndexSet
Definition Terrain.h:56
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition Integer.h:40
Vec2T< Int > Vec2i
Definition Vec2.h:40
uint64_t UInt
Definition Integer.h:27
Vec3T< Int > Vec3i
Definition agx/Vec3.h:43
double Real
Definition Real.h:42
float Real32
Definition Real.h:44