AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
Terrain.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>
24#include <agxTerrain/Grid.h>
41
43
44#include <agx/HashSet.h>
46#include <agx/BitState.h>
48
49#include <agxCollide/Plane.h>
50#include <agxCollide/Geometry.h>
53
55
56namespace agxTerrain
57{
58 class TerrainPager;
59
63 typedef std::pair<SoilParticlePtr, agx::Real> ParticleWeightPair;
70
73
92 {
93 public:
94 enum class MaterialType
95 {
96 TERRAIN,
97 PARTICLE,
98 AGGREGATE
99 };
100
101 enum class MassType
102 {
103 SOLID,
104 PARTICLE,
105 FLUID
106 };
107
108 public:
113
118
125
132 static Terrain* find( const agxSDK::Simulation* simulation, const agx::Name& name );
133
140 static Terrain* find( const agxSDK::Simulation* simulation, const agx::Uuid& uuid );
141
148 static TerrainPtrVector findAll( const agxSDK::Simulation* simulation, const agx::Name& name );
149
155 static TerrainPtrVector findAll( const agxSDK::Simulation* simulation );
156
157 public:
169 static Terrain* createFromHeightField(const agxCollide::HeightField* heightField, agx::Real maximumDepth);
170
181 Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize, agx::Real maximumDepth);
182
195 Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize,
196 const agx::RealVector& heights, bool flipY, agx::Real maximumDepth);
197
208 Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize,
209 const agx::RealVector& heights, const agx::RealVector& minimumHeights);
210
219 void setCompaction( agx::Real compaction, bool replaceCompactedSoil = true ) const;
220
225 void setTransform(const agx::AffineMatrix4x4& transform);
226
231
236
242 void setEnable( bool enable );
243
248 bool getEnable() const;
249
254 void setPosition(const agx::Vec3& position);
255
260
265 void setRotation(const agx::Quat& rotation);
266
271
279
287
295
303
311
317
318
323 virtual agxCollide::Geometry* getGeometry() const override;
324
332
338 void setDeformable( bool deformable );
339
345 inline bool getDeformable() const;
346
350 void setNoMergeEdgeMargin(size_t noMergeEdgeMargin);
351
355 void setNoMerge(bool noMerge);
356
361
374 const agxCollide::BoundingAABB& bound,
375 const agx::AffineMatrix4x4& localTransform );
376
377
387
393
399
404
410
415
420 size_t getResolutionX() const;
421
426 size_t getResolutionY() const;
427
433 agx::Real getElementSize() const;
434
439
445
449 bool getEnableMinimumHeights() const;
450
455 void setEnableMinimumHeights(bool enable);
456
457
464 agx::Vec3 getSurfacePosition(const agx::Vec2i& terrainIndex, bool includeSurfaceParticles = false) const;
465
472 agx::Vec3 getSurfacePositionWorld(const agx::Vec2i& terrainIndex, bool includeSurfaceParticles = false) const;
473
480 agx::Vec2i getClosestGridPoint(const agx::Vec3& worldPosition, bool clampToBound=false) const;
481
489 agx::Bool projectPointToSurface(const agx::Vec3& worldPosition, agx::Vec3& result) const;
490
498 agx::Bool projectPointToSurfaceInDirection( const agx::Vec3& worldPosition, const agx::Vec3& worldDirection, agx::Vec3& result ) const;
499
505 bool isBorderIndex(const agx::Vec2i& terrainIndex) const;
506
512 bool isIndexWithinBounds(const agx::Vec2i& terrainIndex) const;
513
519 bool isWorldPositionWithinBounds(const agx::Vec3& position) const;
520
526 bool isLocalPositionWithinBounds(const agx::Vec3& position) const;
527
533 void setHeight(const agx::Vec2i& terrainIndex, agx::Real height);
534
541 agx::Real getHeight(const agx::Vec2i& terrainIndex, bool includeSurfaceParticles = false) const;
542
547 void setMinimumHeight(const agx::Vec2i& terrainIndex, agx::Real minimumHeight);
548
549
553 agx::Real getMinimumHeight(const agx::Vec2i& terrainIndex) const;
554
559
564
569
574
579
580
585
590
591
596
600 bool hasOverlap(const agxCollide::Geometry* geometry) const;
601
612 agx::Material* getMaterial( Terrain::MaterialType type = Terrain::MaterialType::TERRAIN ) const;
613
614
628 void setMaterial(agx::Material* material, Terrain::MaterialType type = Terrain::MaterialType::TERRAIN);
629
630
637
638
647 bool setAssociatedMaterial(TerrainMaterial* terrainMaterial, agx::Material* material);
648
649
656 bool exchangeTerrainMaterial(TerrainMaterial* oldTerrainMaterial, TerrainMaterial* newTerrainMaterial);
657
662 bool removeTerrainMaterial(TerrainMaterial* terrainMaterialToRemove);
663
668 void clearTerrainMaterials(bool clearAddedMaterials = true);
669
670
682
688 TerrainMaterial* getDefaultTerrainMaterial() const;
689
694 TerrainMaterial* getTerrainMaterial() const;
695
696
703 TerrainMaterial* getTerrainMaterial(agx::Vec3 position) const;
704
711 void setTerrainMaterial( TerrainMaterial* terrainMaterial, agx::Material* material = nullptr );
712
718 bool addTerrainMaterial(TerrainMaterial* terrainMaterial);
719
720
729
737 bool loadLibraryMaterial( const agx::String& materialName );
738
746 static TerrainMaterial* getLibraryMaterial(const agx::String& materialName);
747
748
755
761 bool loadMaterialFile( const agx::String& filename );
762
769
779 bool setHeights( const agx::RealVector& heights, bool flipY = false, bool resetCompaction = true );
780
786 bool setMinimumHeights(const agx::RealVector& minimumHeights);
787
794
802
810
815
826 bool pointIsInsideForbiddenBounds(const agx::Vec3& positionWorld, bool onlyUserDefined = false );
827
838 bool indexIsInsideForbiddenBounds( const agx::Vec3i& terrainIndex, bool onlyUserDefined = false );
839
845
851
857
865 agx::RealVector getResizedHeightField(size_t factorX, size_t factorY) const;
866
874
882
887
892
897
899
901
906
911 void setProperties( TerrainProperties* properties );
912
917
922
929
935
946 agx::Vec3iVector& gridPoints ) const;
947
961 agx::Vec3iVector& gridPoints,
962 MassType massType,
963 bool onlyMidpoint=false) const;
964
974 float removeFluidMassInGeometry(agxCollide::Geometry* geometry, float fluidMass);
975
983
987 size_t getNumSoilParticles() const;
988
994
999
1004
1009
1014
1019
1020
1021 // --- DEPRECATED --- //
1022
1031 bool add(Shovel* shovel);
1032
1039 AGX_DEPRECATED_FOR(2.40.0.0, agxSDK::Simulation::remove)
1040 bool remove(Shovel* shovel);
1041
1046 AGX_DEPRECATED(2.40.0.0)
1047 deprecated::TerrainToolCollectionRefVector getToolCollections() const;
1048
1054 AGX_DEPRECATED(2.40.0.0)
1055 deprecated::TerrainToolCollection* getToolCollection(const Shovel* shovel) const;
1056
1057
1067 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getPenetrationForce)
1068 bool getPenetrationForce(const Shovel* shovel, agx::Vec3& force, agx::Vec3& torque) const;
1069
1078 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getSeparationContactForce)
1079 agx::Vec3 getSeparationContactForce(const Shovel* shovel) const;
1080
1088 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getSeparationNormalForce)
1089 agx::Vec3 getSeparationNormalForce(const Shovel* shovel) const;
1090
1098 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getSeparationFrictionForce)
1099 agx::Vec3 getSeparationFrictionForce(const Shovel * shovel) const;
1100
1110 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getDeformationContactForce)
1111 agx::Vec3 getDeformationContactForce(const Shovel* shovel) const;
1112
1122 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getExcavationModeContactForce)
1123 agx::Vec3 getExcavationModeContactForce(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1124
1135 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getContactForce)
1136 agx::Vec3 getContactForce(const Shovel* shovel) const;
1137
1145 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getShovelAggregateContacts)
1146 agxCollide::GeometryContactPtrVector getShovelAggregateContacts(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1147
1155 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getDeadLoadFraction)
1156 agx::Real getLastDeadLoadFraction(const Shovel* shovel) const;
1157
1162 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getInnerVolume)
1163 agx::Real getInnerVolume(const Shovel* shovel) const;
1164
1165
1172 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::isDigging)
1173 bool isDigging(const Shovel* shovel) const;
1174
1180 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getDynamicMass)
1181 agx::Real getDynamicMass(const Shovel* shovel) const;
1182
1192 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getSoilAggregateMass)
1193 agx::Real getSoilAggregateMass(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1194
1201 AGX_DEPRECATED_FOR(2.40.0.0, agxSDK::Simulation::contains)
1202 bool contains(const Shovel* shovel) const;
1203
1210 AGX_DEPRECATED_FOR(2.40.0.0, ShovelUtils::isRigidBodyShovel)
1211 bool isRigidBodyShovel(const agx::RigidBody* body) const;
1212
1219 AGX_DEPRECATED_FOR(2.40.0.0, ShovelUtils::isGeometryShovel)
1220 bool isGeometryShovel(const agxCollide::Geometry* geometry) const;
1221
1233 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::setShovelAggregateContactMaterial)
1234 bool setShovelAggregateContactMaterial(Shovel* shovel,
1235 agx::ContactMaterial* contactMaterial,
1236 Shovel::ExcavationMode mode = Shovel::ExcavationMode::PRIMARY);
1237
1248 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getShovelAggregateContactMaterial)
1249 agx::ContactMaterial* getShovelAggregateContactMaterial(const Shovel* shovel,
1250 Shovel::ExcavationMode mode = Shovel::ExcavationMode::PRIMARY) const;
1251
1252
1260 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getAggregateTerrainContactForce)
1261 agx::Vec3 getAggregateTerrainContactForce(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1262
1270 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getAggregateTerrainNormalForce)
1271 agx::Vec3 getAggregateTerrainNormalForce(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1272
1280 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getAggregateTerrainTangentialForce)
1281 agx::Vec3 getAggregateTerrainTangentialForce(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1282
1290 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getAggregateTerrainContactArea)
1291 agx::Real getAggregateTerrainContactArea(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1292
1300 AGX_DEPRECATED_FOR(2.40.0.0, Shovel::getAggregateTerrainContacts)
1301 agxCollide::GeometryContactPtrVector getAggregateTerrainContacts(const Shovel* shovel, Shovel::ExcavationMode excavationMode) const;
1302
1303
1305
1307
1309 size_t getNumActiveVoxels() const;
1310
1312 size_t getNumModifiedVoxels() const;
1313
1321 bool verifyMassColumnIntegrity(const agx::Vec2i& terrainIndex) const;
1322
1326 bool isVoxelIndexBelowMaximumDepth(const agx::Vec3i& index) const;
1327
1331 bool isBoundaryDepthVoxel(const agx::Vec3i& index) const;
1332
1339 agx::Line transformLineToTerrain(const agx::Line& line) const;
1340
1347 agx::Line transformLineToVoxelSpace( const agx::Line& line ) const;
1348
1355 agx::Line transformLineToWorld(const agx::Line& line) const;
1356
1360 bool isVoxelIndexInsideGeometryBound(const agx::Vec3i& index) const;
1361
1365 agx::AffineMatrix4x4 getVoxelSpaceTransform() const;
1366
1370 bool isBorderIndexAndBordersLocked(const agx::Vec2i& terrainIndex) const;
1371
1372 CompactionController* getCompactionController() const;
1373
1374 TerrainDataAtlas* getTerrainDataAtlas() const;
1375
1376 virtual void runBuildIslandsTask() override;
1377
1378 void clearAllSoilParticles();
1379
1383 agx::Real calculateTotalVoxelVolume() const;
1384
1385 agx::Vec3 getNormalFromTerrainIndex( const agx::Vec2i& terrainIndex ) const;
1386
1394 float addFluidMassToColumn(const agx::Vec2i& terrainIndex, float fluidMass) const;
1395
1403 float removeFluidMassFromColumn(const agx::Vec2i& terrainIndex, float fluidMass);
1404
1412 float addFluidMass(const agx::Vec3i& voxelIndex, float fluidMass) const;
1413
1421 float removeFluidMass(const agx::Vec3i& voxelIndex, float fluidMass);
1422
1429 agx::Real calculateFluidOccupancy() const;
1430
1437 agx::Real getTotalSoilParticleOccupancy() const;
1438
1444 agx::Vec3 getLocalPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const;
1445
1451 agx::Vec3 getWorldPositionFromVoxelIndex(const agx::Vec3i& voxelIndex) const;
1452
1458 agx::Vec3i getVoxelIndexFromLocalPosition(const agx::Vec3& position) const;
1459
1465 inline agx::Vec3i getVoxelIndexFromGridPosition(agx::Vec3 position) const
1466 {
1467 return VoxelGridUtils::getVoxelIndexFromGridPosition(position, m_voxelSize);
1468 }
1469
1475 inline agx::Vec2i getTerrainIndexFromGridPosition(agx::Vec3 position) const
1476 {
1477 agx::Vec3i vi = getVoxelIndexFromGridPosition(position);
1478 return agx::Vec2i(vi.x(), vi.y());
1479 }
1480
1486 agx::Vec3i getVoxelIndexFromWorldPosition(const agx::Vec3& position) const;
1487
1493 agx::Vec3i getSurfaceVoxelIndexFromTerrainIndex(const agx::Vec2i& terrainIndex) const;
1494
1501 void setForbiddenVoxelsForDynamicMass(const agx::Vec3iVector& voxelIndices);
1502
1508 bool getForbiddenVoxelsForDynamicMass(agx::Vec3iVector& voxelIndices) const;
1509
1516 bool isForbiddenVoxelsForDynamicMass(const agx::Vec3i& voxelIndex) const;
1517
1523 bool voxelContainsShovel(const agx::Vec3i& voxelIndex) const;
1524
1531 bool hasCreatedParticle( agx::Physics::ParticlePtr particle ) const;
1532
1540 bool hasSameParticleMaterial(agx::Physics::ParticlePtr particle) const;
1541
1547 TerrainMassOccupancyController* getMassOccupancyController() const;
1548
1554 TerrainMaterialController* getMaterialController() const;
1555
1556
1557 GroundCollapse::GroundCollapseController* getGroundCollapseController() const;
1558
1559
1560 void adjustFluidMassInGrid(agx::Vec3i binIndex, int binVoxels, float availableFluidMass, float remainingFluidMass);
1561
1562 agx::Vec3iVector getVoxelsOccupiedByShovel(Shovel* shovel) const;
1563
1564 agx::Vec3iVector getVoxelsOccupiedByDeformer(ExternalDeformer* deformer) const;
1565
1566 bool isPointSubmerged( const agx::Vec3& point ) const;
1567
1568 bool voxelHasParticles(const agx::Vec3i& voxelIndex) const;
1569
1570 bool isForbiddenIndex(const agx::Vec3i& index);
1571
1572 void addTerrainIndexToAvalanche(const agx::Vec2i& index);
1573
1574 /*Get the lowest z-index allowed in the height field*/
1575 int getLowestAllowableVoxelIndexZ() const;
1576
1577 /*Get the lowest z-index allowed at the specific index*/
1578 int getMinimumHeightVoxelIndexZ(const agx::Vec2i& index) const;
1579
1580
1581 agx::Vec3 constructVoxelFieldOffset() const;
1582
1583 void setTerrainPager(agxTerrain::TerrainPager* pager);
1584
1585 void setIsTerrainPagerTile(bool isPagerTile);
1586
1587 bool getIsTerrainPagerTile() const;
1588
1589 bool shouldUpdateTerrain() const;
1590
1591 bool hasEnabledShovels() const;
1592
1593 bool hasParticlesInTerrain() const;
1594
1595 void debugRenderFluidMass();
1596
1597 bool isSolidVoxel( const agx::Vec3i& index ) const;
1598
1599 bool isActiveSolidVoxel( const agx::Vec3i& index ) const;
1600
1601 void markIndexAsModified( const agx::Vec2i& terrainIndex );
1602
1603 bool isSurfaceVoxel(const agx::Vec3i& index) const;
1604
1605 const agx::AffineMatrix4x4& _getVoxelSpaceTransform() const;
1606
1607 const agx::AffineMatrix4x4& _getInvVoxelSpaceTransform() const;
1608
1609 const agx::AffineMatrix4x4& _getTransform() const;
1610
1611 const agx::AffineMatrix4x4& _getInverseTransform() const;
1612
1613 void debugRenderParticleHeightField( agx::Real sizeFactor = 0.8,
1614 const agxRender::Color& color = agxRender::Color::White() );
1615
1616 bool isEdgeSubmerged(const agx::Line& edge) const;
1617
1618 bool isEdgeSubmergedInSolid(const agx::Line& edge) const; //Is this method ever used?
1619
1620 bool isEdgeSubmergedInHeightfield(const agx::Line& edge, const agxCollide::HeightField* heightfield) const;
1621
1622 /*
1623 Updates the surface heightfield in the given indices.
1624
1625 HeightField heights are calculated from the underlying occupancy grid.
1626 \param indices - the column indices to update heights in.
1627 */
1628 void updateSurfaceHeightFieldFromTerrainIndices(const agx::Vec2iVector& indices);
1629
1631
1632 protected:
1637
1641 virtual void addNotification() override;
1642
1646 virtual void removeNotification() override;
1647
1652 virtual void preEveryStep() override;
1653
1657 virtual void preCollide() override;
1658
1662 virtual void pre() override;
1663
1667 virtual void post() override;
1668
1672 virtual void last() override;
1673
1674
1683 virtual void syncIfPager() override;
1684
1685 void resetIndices();
1686
1687 protected:
1688 typedef struct offsetIndexInfo
1689 {
1695 } offsetIndexInfo;
1696
1697 using GoToStopCondition = std::function<bool(const agx::Vec3i& index)>;
1699
1701 bool isSolidBoundaryVoxel(const agx::Vec3i& index) const;
1702 bool isSubmergedVoxel(const agx::Vec3i& index) const;
1703 bool isFilledSolidVoxel(const agx::Vec3i& index) const;
1704 bool hasVoxelCompaction(const agx::Vec3i& index) const;
1706 bool getSurfaceVoxel(const agx::Vec3i& voxelIndex, agx::Vec3i& result) const;
1707 bool findPathToSurfaceVoxel(const agx::Vec3i& startVoxel, std::deque<agx::Vec3i>& result);
1708 bool findSurfaceVoxel(const agx::Vec3i& index, agx::Vec3i& result) const;
1709 agx::Vec3i goToVoxelKernel(const agx::Vec3i& start, const GoToStopCondition& stopCondition) const;
1713 void updateSurfaceHeightFieldFromVoxelIndices(const agx::Vec3iVector& updateIndices, bool updateParticleHeightField=true);
1716 void updateSurfaceHeightFieldFromHeightsTable( agx::HashTable<agx::Vec2i, std::pair<agx::Vec3i, agx::Real> >& table );
1718
1719 void traceGridSurfaceVoxel(const agx::Vec2i& terrainIndex, agx::Vec3i& surfaceVoxel) const;
1721 /*
1722 Calculates height in the specified voxel from compaction data and voxel level.
1723 */
1726 void initVoxelStructureFromHeightField( bool adjustForCompaction = false );
1733 agx::Vec3 getValidParticlePosition(const agx::Real radius, const agx::Vec3i& index, const agx::Vec3& pos);
1737 void storeModifiedTerrainIndex( const agx::Vec2i& terrainVertex );
1741
1743
1745 BasicGrid* grid,
1746 agxCollide::Geometry* geometry,
1747 agx::Vec3iVector& gridPoints,
1748 bool isOccupied = true,
1749 bool onlyMidpoint = false) const;
1750
1753
1755
1756 /*
1757 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.
1758 If there is a collision, save the position for filtering later.
1759 */
1761 agx::HashTable <agx::Vec2i, agx::Vec4>& contactPositionTable,
1762 const TerrainIndexSet& columnTerrainIndices,
1763 bool parallelExecute);
1764
1765 /*
1766 Filter away particles so the remaining particles all are below that columns contact position voxel.
1767 This prevents merging through geometries.
1768 */
1769 void filterParticlesAboveContactGeometryVoxels( agx::HashTable <agx::Vec2i, agx::Vec4>& contactPositionTable,
1771
1773
1775
1778
1779 // Sampling method
1781
1785 bool isDirty();
1786 void markVoxelToAvalanche(const agx::Vec3i& changedVoxel);
1787 void updateOccupancyFromHeightChange(const agx::Vec2i& heightFieldIndex);
1794
1795 // Resize soil particles
1798 void growParticlesFromFluidMass(agx::Vec3i binIndex, int binVoxels, float availableFluidMass, ParticleDeltaVector& particles);
1799 void growSmallParticlesFromParticleMass(ParticleDeltaVector& particles, float particleRadiusUpperLimit);
1800 void growLargeParticlesFromParticleMass(ParticleDeltaVector& particles, float particleRadiusUpperLimit);
1801
1802 // Merge soil particles functions
1807 void mergeParticleIslands( const ParticleIslandVector& particleIslands, agxData::LocalVector<agx::Vec3i>& mergedParticleIndices );
1808 void resizeOrRemoveParticles( const agx::HashTable<SoilParticlePtr, std::array<agx::Real, 2>>& particlesToUpdate );
1810
1811 // Merge to excavation edge functions
1813 agx::Vec3iVector mergeSoilInColumnToVoxel(agx::Vec3i topVoxel, size_t numVoxelsToSurfaceThreshold, agx::Plane cuttingPlane);
1814 float convertParticlesToSolidMass(agx::Vec3i voxel, ParticleWeightPairVector particles, float occupancyToRemove, agx::Vec3iVector& changedIndices);
1815 void moveParticlesToSurface(agx::Vec3iVector changedVoxelIndices);
1816
1817 // Step fluid mass
1822 // \todo?
1823 //agx::Vec3f getVoxelVelocity(const agx::Vec3i& voxelIndex, agx::HashTable<agx::Vec3i, size_t>& shovelVoxels);
1824 void createFluidMassInVoxel(const agx::Vec3i& voxelIndex, agx::Real32 amount);
1825 void createFluidMassOnTerrainSurface(const agx::Vec2i& terrainIndex, int surfaceVoxelOffset, agx::Real32 amount);
1826
1827 // Conversion functions for particle radius and general occupancy
1828 float convertParticleRadiusToOccupancy(float radius) const;
1829 float convertOccupancyToParticleRadius(float occupancy) const;
1830 float getDynamicMassCompaction(const agx::Vec3i& voxelIndex) const;
1831 bool particleIslandShouldMerge(const agx::Vector<std::pair<agx::Vec3i, offsetIndexInfo>>& island);
1832 bool voxelColumnHasParticles(const agx::Vec2i& vertex) const;
1833
1838 template <class F>
1839 void iterateOverSolidVoxels( F&& func ) const;
1840
1841 // TerrainMaterial bookkeeping functions
1846
1848
1850
1853
1857
1859
1860 AvalancheController* getAvalancheController() const;
1861
1863
1865
1869
1871
1873
1875
1876 friend class AvalancheController;
1878 friend class TerrainMaterial;
1882 friend class TerrainMaterialController;
1884 friend class TerrainPhysics;
1885 friend class TerrainCache;
1887
1888 protected:
1889 virtual ~Terrain();
1890
1891 Terrain(agxCollide::HeightField* heightField, agx::Real maximumDepth);
1892
1893 private:
1896
1897 private:
1899 friend class agx::InternalData;
1903 agx::Referenced* getInternalData() const;
1904
1908 void setInternalData( agx::Referenced* data );
1910
1911 private:
1912 agxCollide::HeightFieldRef m_surfaceHeightField;
1913 agxCollide::HeightFieldRef m_particleHeightField;
1914 agx::Real m_voxelSize;
1915 TerrainPropertiesRef m_properties;
1916 agx::UniformRealGenerator m_generator;
1917 float m_nominalSoilParticleRadius;
1918
1919 agxCollide::GeometryRef m_surfaceGeometry;
1920 agx::AffineMatrix4x4 m_transform;
1921 agx::AffineMatrix4x4 m_invTransform;
1922 agx::AffineMatrix4x4 m_voxelSpaceTransform;
1923 agx::AffineMatrix4x4 m_invVoxelSpaceTransform;
1924 agx::Vec3 m_voxelFieldOffset;
1925
1926 TerrainDataAtlasRef m_terrainDataAtlas;
1927 TerrainMassOccupancyControllerRef m_massOccupancyController;
1928 TerrainMaterialControllerRef m_materialController;
1929 CompactionControllerRef m_compactionController;
1930 TerrainContactGeneratorRef m_terrainContactGenerator;
1931 AvalancheControllerRef m_avalancheController;
1932 SoilSimulationInterfaceRef m_soilSimulationInterface;
1933 TerrainGridControlRef m_terrainGridInterface;
1934 GroundCollapse::GroundCollapseControllerRef m_collapseController;
1935
1936 agx::MaterialRef m_particleMaterial;
1937 agx::MaterialRef m_aggregateMaterial;
1938
1939 agx::ContactMaterialRef m_terrainParticleContactMaterial;
1940 agx::ContactMaterialRef m_terrainAggregateContactMaterial;
1941 agx::ContactMaterialRef m_particleParticleContactMaterial;
1942
1943 AvalancheController::TerrainIndexSet m_terrainIndicesToAvalanche;
1944
1945 size_t m_noMergeEdgeMargin;
1946 bool m_noMerge;
1947 BoundingAABBVector m_forbiddenBounds;
1948 agx::HashTable<agx::Vec3i, Shovel*> m_voxelIndexToShovelPtr;
1949 agx::HashTable<agx::Vec3i, ExternalDeformer*> m_voxelIndexToExternalDeformerPtr;
1950 agx::HashTable<Shovel*, agx::Vec3iVector> m_voxelsInPrimaryActiveZoneLastTimeStep;
1951 agx::Vec3iVector m_dirtyVoxelIndices;
1952 agx::Real32Vector m_removedOccupancy;
1953 agx::Real m_lastRemovedVolume;
1954 VoxelIndexSet m_voxelHasCreatedParticle;
1955 VoxelIndexSet m_forbiddenVoxelsForDynamicMass;
1956 TerrainIndexSet m_mergedTerrainVertices;
1957 ModifiedVerticesSetVector m_modifiedVoxelColumns;
1958 ModifiedVerticesSetVector m_modifiedTerrainVertices;
1959 ModifiedVerticesSetVector m_modifiedParticleVertices;
1960 ModifiedVerticesSetVector m_particleTerrainVertices;
1961
1962 size_t m_numCreatedParticles;
1963 float m_averageSoilParticleRadius;
1964
1965 // Sort particles into voxels
1966 VoxelIndexOffsetIndexInfoTable m_voxelParticleOffsetTable;
1967 ParticleWeightPairVector m_voxelParticleWeightPairVector;
1968
1969 // Sort particles into columns
1970 agx::IndexVector m_particlesInContactWithSurface;
1971 agx::HashTable <agx::Vec2i, agx::Vec4> m_contactPositionTable;
1972
1973 VoxelIndexOffsetIndexInfoTable m_columnParticleOffsetTable;
1974 ParticleWeightPairVector m_columnParticleWeightPairVector;
1975
1976 agx::HashTable<agx::Vec2i, agx::Real> m_columnParticleHeight;
1977 agx::HighAccuracyTimer m_timer;
1978
1979 agx::IndexLambdaKernelRef m_indexKernel;
1980
1981 bool m_isTerrainPagerTile;
1982 agxTerrain::TerrainPager* m_terrainPager;
1983 bool m_enable;
1984
1985 agx::RealVector m_tanReposeAngles;
1986
1987 // !HACK! !BEWARE! Islands partitioning
1988 // The build islands task is not executed when using PPGS.
1989 // No island partitioning means no parallelization of solving the rigid body system.
1990 // However, we still need islands in Terrain to determine which particles are in contact with the ground.
1991 // Thus, we manually load and execute the task in Terrain.
1992 // The task is loaded and bound for each Terrain that is added but is only executed once by agxSDK::Simulation.
1993 // The task is executed using the runBuildIslandsTask() method.
1994 agx::TaskRef m_buildIslandsTask;
1995 agx::TaskGroupRef m_preCollideUpdateTask;
1996 agx::TaskRef m_sortParticlesToVoxelsTask;
1997 agx::TaskRef m_sortParticlesToColumnsTask;
1998 agx::TaskRef m_calculateShovelVoxelIntersection;
1999 agx::TaskRef m_convertSolidToDynamicMassTask;
2000
2001 agx::ParallelTaskRef m_updateHeightfieldsTask;
2002 agx::Job m_updateHeightfieldsJobs[2];
2003 agx::ParallelTaskRef m_voxelCollisionTask;
2004 agx::ParallelTaskRef m_geometryFilterTask;
2005
2006 agxTerrain::IForbiddenBoundRefVector m_userForbiddenBounds;
2007 agxTerrain::IForbiddenBoundRefVector m_tempForbiddenBounds;
2008
2009 bool m_enableFluidMerge; // Only used for testing. Should not be serialized.
2010
2011 agx::Vector<agxCollide::ShapeRef> m_userInputFailureShapes;
2012
2013 agx::ref_ptr<agx::Referenced> m_internalData;
2014
2015 ShovelRefVector m_restoredShovelsFromToolCollection; // Used for restoring old terrains. Should not be serialized.
2016 ShovelPtrVector m_restoredDisableFlagFromToolCollection; // Used for restoring old terrains. Should not be serialized.
2017 };
2018
2019
2020 inline TerrainDataAtlas* Terrain::getTerrainDataAtlas() const
2021 {
2022 return m_terrainDataAtlas;
2023 }
2024
2025 inline TerrainMaterial* Terrain::getDefaultTerrainMaterial() const
2026 {
2027 return m_materialController->getDefaultTerrainMaterial();
2028 }
2029
2030
2031 inline TerrainMaterial* Terrain::getTerrainMaterial() const
2032 {
2033 return m_materialController->getDefaultTerrainMaterial();
2034 }
2035
2036
2037 inline TerrainMaterial* Terrain::getTerrainMaterial(agx::Vec3 position) const
2038 {
2039 auto voxelIndex = getVoxelIndexFromWorldPosition(position);
2040 return m_materialController->getTerrainMaterial(voxelIndex);
2041 }
2042
2043
2044 inline size_t Terrain::getResolutionX() const
2045 {
2046 return m_surfaceHeightField->getResolutionX();
2047 }
2048
2049
2050 inline size_t Terrain::getResolutionY() const
2051 {
2052 return m_surfaceHeightField->getResolutionY();
2053 }
2054
2055
2056 inline agx::Real Terrain::getElementSize() const
2057 {
2058 return m_voxelSize;
2059 }
2060
2061
2062
2063 inline const agx::AffineMatrix4x4& Terrain::_getVoxelSpaceTransform() const
2064 {
2065 return m_voxelSpaceTransform;
2066 }
2067
2068
2069
2070 inline const agx::AffineMatrix4x4& Terrain::_getInvVoxelSpaceTransform() const
2071 {
2072 return m_invVoxelSpaceTransform;
2073 }
2074
2075
2076
2077 inline const agx::AffineMatrix4x4& Terrain::_getTransform() const
2078 {
2079 return m_transform;
2080 }
2081
2082
2083
2084 inline const agx::AffineMatrix4x4& Terrain::_getInverseTransform() const
2085 {
2086 return m_invTransform;
2087 }
2088
2089
2090 inline agx::Vec3i Terrain::getSurfaceVoxelIndexFromTerrainIndex(const agx::Vec2i& terrainIndex) const
2091 {
2092 auto solidGrid = static_cast<ColumnHeightGrid*>(m_terrainDataAtlas->getGridMassOccupancyData(TerrainDataAtlas::MassType::SOLID));
2093 int voxelHeight = solidGrid->getSurfaceHeightIndex(terrainIndex);
2094
2095 return agx::Vec3i( terrainIndex.x(), terrainIndex.y(), voxelHeight);
2096 }
2097
2098 inline bool Terrain::getIsTerrainPagerTile() const
2099 {
2100 return m_isTerrainPagerTile;
2101 }
2102
2103 inline bool Terrain::getDeformable() const
2104 {
2105 return m_properties->getEnableDeformation();
2106 }
2107
2108
2109
2110 inline bool Terrain::getEnableMinimumHeights() const
2111 {
2112 return m_terrainDataAtlas->getEnableMinimumHeights();
2113 }
2114
2115
2116 inline void Terrain::setEnableMinimumHeights(bool enable)
2117 {
2118 m_terrainDataAtlas->setEnableMinimumHeights(enable);
2119 }
2120}
#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...
Definition: Serializable.h:207
#define AGXTERRAIN_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
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:58
Local scope vector.
Definition: LocalVector.h:44
Utility color class with "common colors".
Definition: Color.h:48
static agxRender::Color White()
Definition: Color.h:224
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
bool add(agx::Material *material)
Add a material to the simulation.
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:81
Controller that handles compaction in the terrain from generated terrain contacts in TerrainContactGe...
ExternaDeformer is a TerrainToolInstance class that models deformer surfaces that are not attached to...
Class for specifying a 3D bound where terrain operations like merging and avalanching is forbbiden.
Base abstract class for specifying different types of bounds bound where terrain operations like merg...
Shovel object used to interact with a terrain via an active zone that converts solid terrain to dynam...
Definition: Shovel.h:63
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.
Definition: TerrainCache.h:58
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.
A pager that will dynamically handle terrain tiles in a agxSDK::Simulation.
Definition: TerrainPager.h:100
Utility class where most of the physics calculation used in agxTerrain is gathered.
Class for containing and managing the different agxTerrain::Terrain settings.
Class responsible for terrain deformation by the TerrainWheel.
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:92
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 mergeSoilToExcavationEdge()
bool removeVolumeInShape(agxCollide::Shape *shape)
Instantly removes a terrain volume in the speficied shape.
void initializeFromHeightField()
bool getIntersectingActiveGridElements(agxCollide::Geometry *geometry, agx::Vec3iVector &gridPoints, MassType massType, bool onlyMidpoint=false) const
Get intersecting 3D grid element with specified geometry that is active/occupied with a specified mas...
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.
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
float getParticleNominalRadius() const
Get the soil particle nominal radius from the simulation.
AvalancheController * getAvalancheController() const
agx::Bool projectPointToSurfaceInDirection(const agx::Vec3 &worldPosition, const agx::Vec3 &worldDirection, agx::Vec3 &result) const
Project a world point to the grid surface in a given direction.
void convertVoxelsInActiveZonesToDynamicMass()
agx::Real getTanReposeAngle(agx::Vec2i xy) const
Utility method for getting the tangent of the repose angle for a given terrain surface coordinate.
void moveParticlesToSurface(agx::Vec3iVector changedVoxelIndices)
agx::Vec3iVector mergeSoilInColumnToVoxel(agx::Vec3i topVoxel, size_t numVoxelsToSurfaceThreshold, agx::Plane cuttingPlane)
void setMinimumHeight(const agx::Vec2i &terrainIndex, agx::Real minimumHeight)
Set the minimum height allowed at the specified terrain index.
void convertToDynamicMassInShape(agxCollide::Shape *shape)
Converts the terrain occupancy that overlaps the specified shape into dynamic mass.
bool loadLibraryMaterial(const agx::String &materialName)
Loads a TerrainMaterial preset in the TerrainMaterialLibrary that contains calibrated bulk and contac...
bool hasMultipleTerrainMaterials() const
void sortParticlesIntoVoxels()
agx::HashVector< agx::Vec2i, agx::Int > getShovelHeightPerColumn()
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)
void initVoxelStructureFromHeightField(bool adjustForCompaction=false)
static agx::StringVector getAvailableLibraryMaterials()
Get the available TerrainMaterial presets from the TerrainMaterialLibrary that contains calibrated bu...
bool indexIsInsideForbiddenBounds(const agx::Vec3i &terrainIndex, bool onlyUserDefined=false)
Check if the specified index is inside the forbidden bounds in the terrain.
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.
bool _getIntersectingGridElements(BasicGrid *grid, agxCollide::Geometry *geometry, agx::Vec3iVector &gridPoints, bool isOccupied=true, bool onlyMidpoint=false) const
void calculateShovelVoxelIntersection()
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.
bool removeForbiddenBound(IForbiddenBound *bound)
Remove a ForbiddenBound from a terrain that prevents merging and avalanching for the indices and posi...
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.
void updateCachedMassProperties()
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)
Terrain(size_t resolutionX, size_t resolutionY, agx::Real elementSize, const agx::RealVector &heights, const agx::RealVector &minimumHeights)
Constructor.
bool pointIsInsideForbiddenBounds(const agx::Vec3 &positionWorld, bool onlyUserDefined=false)
Check if the specified points is inside the forbidden bounds in the terrain.
agx::Quat generateRandomSoilParticleRotation()
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 getVoxelArea() const
void initializeTanReposeAngles()
void preUpdateTerrainContacts()
bool isSolidBoundaryVoxel(const agx::Vec3i &index) const
voxel functions
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()
bool setMinimumHeights(const agx::RealVector &minimumHeights)
Set the minimum height values in the terrain grid.
void updateSurfaceHeightFieldFromIndicesAndHeights(agx::Vec2uVector &hfIndices, agx::RealVector &hfHeights)
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...
void updateSurfaceHeightFieldFromVoxelIndices(const agx::Vec3iVector &updateIndices, bool updateParticleHeightField=true)
void updateTanReposeAngles()
float getDynamicMassCompaction(const agx::Vec3i &voxelIndex) const
void moveEntityDataToCurrentThread()
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()
ForbiddenBound * addNoMergeZoneToGeometry(agxCollide::Geometry *geometry, const agxCollide::BoundingAABB &bound, const agx::AffineMatrix4x4 &localTransform)
Utility method for creating a forbidden bound that follow the transformation of a specified geometry.
agx::Real calculateTotalDynamicMass() const
void postUpdateGroundCollapse()
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 hasVoxelCompaction(const agx::Vec3i &index) const
size_t getMemoryUsage()
Returns the memory usage in bytes in agxTerrain.
agx::Real getVoxelVolume() const
const ModifiedVerticesVector & getModifiedParticleVertices() const
Returns the modified terrain height field (including particles) vertices during the last time step.
agx::Real calculateVolume() const
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()
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
Returns the associated material with the given terrainMaterial.
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.
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.
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()
void applyFluidMassChanges(agx::HashTable< agx::Vec3i, float > &fluidMassTable)
void computeForbiddenBounds()
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)
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()
ExternalDeformerPtrVector getExternalDeformers() const
Return the external deformers currently added in the simulation.
void updateOccupancyFromHeightChange(const agx::Vec2i &heightFieldIndex)
bool loadMaterialFile(const agx::String &filename)
Load a TerrainMaterial from a specification file in JSON data format.
TerrainProperties * getProperties()
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)
TerrainContactPtrVector getTerrainContactsPtrVector() const
void debugRenderForbiddenBounds()
agx::Real getMinimumHeight(const agx::Vec2i &terrainIndex) const
Gets the minimum height allowed at the specific terrain index.
agx::Real getAverageSoilParticleRadius() const
agx::Vec3 getSurfacePositionWorld(const agx::Vec2i &terrainIndex, bool includeSurfaceParticles=false) const
Finds the terrain surface world position for a specified terrain index.
std::function< bool(const agx::Vec3i &index)> GoToStopCondition
Definition: Terrain.h:1697
static Terrain * find(const agxSDK::Simulation *simulation, const agx::Uuid &uuid)
Find terrain with given UUID.
bool shouldPrimaryActiveZoneRemoveMass(Shovel *shovel)
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.
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)
Remove all traces of added terrain materials.
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.
void traceGridSurfaceVoxel(const agx::Vec2i &terrainIndex, agx::Vec3i &surfaceVoxel) const
void mergeSoilParticlesAndFluidMass()
void updateSurfaceHeightFieldFromVoxelIndex(const agx::Vec3i &voxelIndex)
static agx::Bool isTerrainGeometry(const agxCollide::Geometry *geometry)
bool shouldExternalDeformerActiveZoneRemoveMass(agx::RigidBody *deformerBody, DeformerCollection *deformerCollection)
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)
Remove an added terrain material, its assigned domain will also be removed along with it.
agx::Real generateRandomNumber()
bool shouldDeformerActiveZoneRemoveMass(Shovel *shovel, DeformerCollection *deformerCollection)
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.
TerrainContactRefVector * getTerrainContactsVector() const
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.
IForbiddenBoundPtrVector getForbiddenBounds()
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.
void setProperties(TerrainProperties *properties)
Set the TerrainProperties of the Terrian object.
void iterateOverSolidVoxels(F &&func) const
Traverses all solid voxels in the terrain and invokes the provided callable once per voxel with its i...
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)
Terrain(agxCollide::HeightField *heightField, agx::Real maximumDepth)
size_t getNumSoilParticles() const
Return the number of soil particles active in the simulation.
bool addForbiddenBound(IForbiddenBound *bound)
Add a ForbiddenBound to a terrain that prevents mergining and avalanching for the indices and positio...
void growLargeParticlesFromParticleMass(ParticleDeltaVector &particles, float particleRadiusUpperLimit)
agx::RealVector getMinimumHeights() const
Return row major array with dimension (resolutionX * resolutionY) with the minimum height allowed in ...
virtual agxCollide::Geometry * getGeometry() const override
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.
ShovelPtrVector getShovels() const
Return the shovels currently added in the simulation.
agx::Bool isIndexWithinBoundsIssueWarning(const agx::Vec2i &terrainIndex) const
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.
agx::AffineMatrix4x4 getTransform() const
This class store the combine material properties between two agx::Material's.
Definition: Material.h:518
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: agx/HashSet.h:670
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:41
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:378
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:49
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.
Definition: Vec4Template.h:35
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
#define AGX_DEPRECATED(since)
Definition: macros.h:81
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
#define AGX_DEPRECATED_FOR(since, replacement)
Definition: macros.h:82
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
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:66
agx::Physics::GranularBodyPtrVector SoilParticlePtrVector
std::pair< SoilParticlePtr, agx::Real > ParticleWeightPair
Definition: Terrain.h:63
agx::Vector< ParticleWeightPair > ParticleWeightPairVector
Definition: Terrain.h:64
agx::Vector< std::pair< SoilParticlePtr, float > > ParticleDeltaVector
Definition: Terrain.h:68
agx::HashTable< agx::Vec3i, ParticleWeightPairVector > IndexToParticleWeightPairVector
Definition: Terrain.h:65
agx::Physics::GranularBodyPtr SoilParticlePtr
agx::Vector< agx::Vec2i > ModifiedVerticesVector
Definition: Terrain.h:67
agx::HashSet< agx::Vec3i > VoxelIndexSet
Definition: Terrain.h:62
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:41
float Real32
Definition: Real.h:43