AGXDynamics  2.35.0.2
SweepAndPrune.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. Algoryx Simulation AB.
3 
4 All AGX source code, intellectual property, documentation, sample code,
5 tutorials, scene files and technical white papers, are copyrighted, proprietary
6 and confidential material of Algoryx Simulation AB. You may not download, read,
7 store, distribute, publish, copy or otherwise disseminate, use or expose this
8 material unless having a written signed agreement with Algoryx Simulation AB, or having been
9 advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10 valid commercial license from Algoryx Simulation AB.
11 
12 Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13 from using this software, unless otherwise stated in written agreements with
14 Algoryx 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 
33 namespace agxCollide
34 {
37  {
38  public:
42 
43  public:
47  SweepAndPrune(Space *space);
48 
49  void add( Geometry* geometry );
50  void remove( Geometry* geometry );
51  void update();
52  void commitNewOverlaps( agxData::EntityStorage* pairStorage, ExternallyReportedPairsContainer& newPairs );
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 
67  agx::Task *createUpdateTask();
68  void print(); //DEBUG
69 
70 
71  public:
72  class UpdateTask : public agx::SerialTask
73  {
74  public:
75  UpdateTask(const agx::String& name, SweepAndPrune *sap);
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
agxCollide::SweepAndPrune::SymmetricGeometryPtrPair
agx::SymmetricPair< Geometry * > SymmetricGeometryPtrPair
Definition: SweepAndPrune.h:40
agx::SymmetricPair
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:31
agx::LinearProbingHashSet
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashSet.h:639
agxCollide::SweepAndPrune::ExternallyReportedPairsContainer
agx::HashVector< SymmetricGeometryPtrPair, SymmetricGeometryRefPair > ExternallyReportedPairsContainer
Definition: SweepAndPrune.h:41
agx::Vector
Templated vector class.
Definition: Vector.h:52
Task.h
LinearProbingHashTable.h
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
Geometry.h
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agx::SerialTask
SerialTask.
Definition: Task.h:469
agxData::EntityStorage
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
HashImplementationSwitcher.h
agxCollide::BoundingAABB
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
BroadPhasePairEntity.h
agx::Task
A representation of a generic task.
Definition: Task.h:57
agx::ref_ptr< ArrayParameter >
agx::SetVector< GeometryRef >
agxCollide::SweepAndPrune::SymmetricGeometryRefPair
agx::SymmetricPair< GeometryRef > SymmetricGeometryRefPair
Definition: SweepAndPrune.h:39
agx::LinearProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: LinearProbingHashTable.h:871
LinearProbingHashSet.h
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Component.h
agxCollide::Space
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
agx::HashSet< agx::UInt64 >
agx::Component
A component is an object containing other objects, enabling hierarchical structuring.
Definition: Component.h:38
agx::Physics::BroadPhasePairPtr
Pointer to a entity instance of type Physics.BroadPhasePair.
Definition: BroadPhasePairEntity.h:172
agxCollide::SweepAndPrune
Definition: SweepAndPrune.h:36
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agx::PointerT< agxData::EntityStorage >
agxCollide::AGX_DECLARE_POINTER_TYPES
AGX_DECLARE_POINTER_TYPES(SpaceListener)
agx::QuadraticProbingHashTable
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: QuadraticProbingHashTable.h:698
QuadraticProbingHashTable.h
agx::AgXString< std::string >
agxCollide::SweepAndPrune::UpdateTask::~UpdateTask
virtual ~UpdateTask()
Definition: SweepAndPrune.h:79
agxCollide::SweepAndPrune::UpdateTask
Definition: SweepAndPrune.h:72
agxCollide::SweepAndPrune::endpoint::m_index
agx::UInt32 m_index
Definition: SweepAndPrune.h:112
agxCollide::SweepAndPrune::endpoint::m_value
agx::UInt32 m_value
Definition: SweepAndPrune.h:113
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agx::HashVector< SymmetricGeometryPtrPair, SymmetricGeometryRefPair >
agxCollide::SweepAndPrune::endpoint
Definition: SweepAndPrune.h:111