AGX Dynamics 2.42.3.0
Loading...
Searching...
No Matches
SweepAndPrune.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#ifndef AGXCOLLIDE_SWEEPANDPRUNE_H
17#define AGXCOLLIDE_SWEEPANDPRUNE_H
18
19#include <agxCollide/Geometry.h>
20
21#include <agx/Component.h>
22#include <agx/Task.h>
23
25#include <queue>
26
27
32
33namespace agxCollide
34{
37 {
38 public:
42
43 public:
48
49 void add( Geometry* geometry );
50 void remove( Geometry* geometry );
51 void update();
53 virtual bool testOverlap( agxCollide::GeometryPtrVector& testGeometries, agxCollide::GeometryPairVector& result, bool skip );
54
60 void removePair( const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2 );
61
65 agx::Physics::BroadPhasePairPtr getPair( const Geometry* geometry1, const Geometry* geometry2 ) const;
66
68 void print(); //DEBUG
69
70
71 public:
73 {
74 public:
76 virtual void run() override;
77
78 protected:
79 virtual ~UpdateTask() {}
80
81 private:
82 SweepAndPrune *m_sap;
83
84 agx::ArrayParameterRef m_boundingVolumes; //agx::Arg<agx::Bound3> m_boundingVolumes;
85 agx::ArrayParameterRef m_geometries; //agx::Arg<agxData::EntityPtr> m_geometries;
86 // agx::Arg<agx::Physics::RigidBodyPtr> m_bodies;
87 // agx::Arg<agxCollide::BroadPhasePair> m_overlapPairs;
89 agx::PointerT<agxData::EntityStorage> *m_separationStorage;
90 // agx::Ptr<agxData::EntityStorage> m_cellBlockPairStorage;
91 // agx::Arg<agx::Physics::GeometryPtr> m_pairGeometries1;
92 // agx::Arg<agx::Physics::GeometryPtr> m_pairGeometries2;
93 };
94
95 protected:
96 virtual ~SweepAndPrune( void );
97
98 private:
99 void insertNewGeometries();
100 void encodeBounds();
101 void tagRemovedBounds();
102 void sortAxis(int axis);
103 void removeGeometries();
104 void reportOverlapsAndSeparations(agxData::EntityStorage *pairStorage, agxData::EntityStorage *separationStorage);
105
106 void addPair( agx::UInt32 i1, agx::UInt32 i2 );
107 void removePair( agx::UInt32 i1, agx::UInt32 i2 );
108
109 public:
110 // 8 bytes
111 struct endpoint {
112 agx::UInt32 m_index; // bounding box index | isMax
113 agx::UInt32 m_value; // bounding box value encoded as uint
114 };
115
117 // 28 or 32 bytes
118 struct bbox {
119 agx::UInt32 m_epi[2][3];
120 Geometry* m_geometry;
121 };
123 private:
124 BoundingAABB m_totalAABB;
125
126#if HASH_FOR_SWEEP == HASH_NEW
128#elif HASH_FOR_SWEEP == HASH_OLD
129 typedef agx::HashSet< agx::UInt64 > saptable;
130#else
131 #error
132#endif
133
134 class queuecmp {
135 public:
136 bool operator()(agx::UInt32 a, agx::UInt32 b) { return a > b; }
137 };
138
139 std::priority_queue<agx::UInt32, std::deque<agx::UInt32>, queuecmp> m_holes;
140
141 typedef agx::SetVector< GeometryRef > GeometryRefSet;
142
143 typedef std::pair<GeometryRef, agx::UInt32> RemovedGeometry;
144 typedef agx::SetVector< RemovedGeometry > RemovedGeometrySet;
145
146
147 saptable m_contactTable;
148 saptable m_impactTable;
149 saptable m_separationTable;
150
151
152 void insertNewGeometry( Geometry* geom, agx::UInt32 axis, size_t insertIndex, size_t endpointIndex );
153 bool boxOverlap( agx::UInt32 i1, agx::UInt32 i2, const agx::UInt32 axes[2] );
154
155 GeometryRefSet m_addGeometries;
156 RemovedGeometrySet m_removeGeometries;
157
158 size_t m_numBoxes;
159
160 size_t m_numBoxesAvailable;
161 size_t m_numEndpointsAvailable;
162
163 agx::Vector<bbox> m_boxes;
164
165 agx::Vector<endpoint> m_endpoints[3];
166 agx::TaskRef m_updateTask;
167 Space *m_space;
168
169#if HASH_FOR_SWEEP == HASH_NEW
171#elif HASH_FOR_SWEEP == HASH_OLD
173#else
174 #error
175#endif
176 ActivePairTable m_activePairs;
177
178 agxData::EntityPtrVector m_pairRemovalList;
179 };
180}
181
182#endif
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#define AGXPHYSICS_EXPORT
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:38
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:86
virtual void run() override
Execution callback.
UpdateTask(const agx::String &name, SweepAndPrune *sap)
void add(Geometry *geometry)
virtual bool testOverlap(agxCollide::GeometryPtrVector &testGeometries, agxCollide::GeometryPairVector &result, bool skip)
void removePair(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2)
Remove broad phase overlap given two geometries.
agx::Physics::BroadPhasePairPtr getPair(const Geometry *geometry1, const Geometry *geometry2) const
agx::SymmetricPair< GeometryRef > SymmetricGeometryRefPair
Definition: SweepAndPrune.h:39
void remove(Geometry *geometry)
agx::HashVector< SymmetricGeometryPtrPair, SymmetricGeometryRefPair > ExternallyReportedPairsContainer
Definition: SweepAndPrune.h:41
virtual ~SweepAndPrune(void)
agx::Task * createUpdateTask()
SweepAndPrune(Space *space)
Default constructor.
void commitNewOverlaps(agxData::EntityStorage *pairStorage, ExternallyReportedPairsContainer &newPairs)
agx::SymmetricPair< Geometry * > SymmetricGeometryPtrPair
Definition: SweepAndPrune.h:40
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:73
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:39
Inheritance with partial specialization due to bug with ref_ptr containers.
Inheritance with partial specialization due to bug with ref_ptr containers.
Pointer to a entity instance of type Physics.BroadPhasePair.
Inheritance with partial specialization due to bug with ref_ptr containers.
SerialTask.
Definition: Task.h:469
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:32
A representation of a generic task.
Definition: Task.h:57
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
This namespace consists of a set of classes for handling geometric intersection tests including boole...
uint32_t UInt32
Definition: Integer.h:32