AGX Dynamics  2.37.3.2
CollisionGroupFilter.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2024. 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 
17 #ifndef AGXSDK_COLLISIONGROUPFILTER_H
18 #define AGXSDK_COLLISIONGROUPFILTER_H
19 
20 #include <agx/agxPhysics_export.h>
21 #include <agxSDK/agxSDK.h>
22 #include <agxCollide/Geometry.h>
23 #include <agxSDK/ExecuteFilter.h>
24 #include <agx/TimeStamp.h>
25 #include <agxCollide/Contacts.h>
26 
27 #include <agx/Vector.h>
28 
29 
30 namespace agxSDK
31 {
32 
35 
42  {
43  public:
44 
47 
55 
59  void setGeometry(agxCollide::Geometry* geometry);
60 
64  agxCollide::Geometry* getGeometry();
65  const agxCollide::Geometry* getGeometry() const;
66 
71  void addGroup(const agx::Name& group);
72  void addGroup(agx::UInt32 group);
73 
77  void removeGroup(const agx::Name& group);
78  void removeGroup(agx::UInt32 group);
79 
83  void removeAllGroups();
84 
88  bool hasGroup(const agx::Name& group);
89  bool hasGroup(agx::UInt32 group);
90 
94  agx::Vector<agx::Name> getNamedGroups();
95  const agx::Vector<agx::Name> getNamedGroups() const;
96 
100  agx::Vector<agx::UInt32> getUIntGroups();
101  const agx::Vector<agx::UInt32> getUIntGroups() const;
102 
103  bool match(const agxCollide::Geometry* geo0, const agxCollide::Geometry* geo1) const override;
104  using ExecuteFilter::match;
105 
106  protected:
107 
108  // Check if a geometry has one of the collision groups of this filter
109  bool hasMemberGroup( const agxCollide::Geometry* geom ) const;
110 
112  virtual ~CollisionGroupFilter();
113 
114 
115  protected:
119  };
120 
121  // Implementation
122 
123  // Had to switch to regular inline since compiler complains about AGX_FORCE_INLINE
124  inline bool CollisionGroupFilter::match(const agxCollide::Geometry* geo0, const agxCollide::Geometry* geo1) const
125  {
126 
127  if (m_geometry == nullptr || (geo0 == m_geometry || geo1 == m_geometry))
128  {
129  // Match all collisions if no collision groups are set
130  if (m_uintCollisiontGroups.size() <= 0 && m_namedCollisionGroups.size() <= 0)
131  return true;
132 
133  if (m_geometry == nullptr)
134  {
135  if (hasMemberGroup( geo0 )) return true;
136  if (hasMemberGroup( geo1 )) return true;
137  }
138  else // geo0 == m_geometry || geo1 == m_geometry
139  {
140  const agxCollide::Geometry* collider = (m_geometry == geo0) ? geo1 : geo0;
141  if (hasMemberGroup( collider )) return true;
142  }
143  }
144  return false;
145  }
146 
148  {
149  // Named collision groups
150  for (size_t i = 0; i < m_namedCollisionGroups.size(); i++)
151  {
152  if (geom->hasGroup( m_namedCollisionGroups[i] ))
153  return true;
154  }
155 
156  // UInt collision groups
157  for (size_t i = 0; i < m_uintCollisiontGroups.size(); i++)
158  {
159  if (geom->hasGroup( m_uintCollisiontGroups[i] ))
160  return true;
161  }
162  return false;
163  }
164 
167 
168  inline agx::Vector<agx::Name> CollisionGroupFilter::getNamedGroups() {return m_namedCollisionGroups; }
169  inline const agx::Vector<agx::Name> CollisionGroupFilter::getNamedGroups() const {return m_namedCollisionGroups;}
170 
171  inline agx::Vector<agx::UInt32> CollisionGroupFilter::getUIntGroups() {return m_uintCollisiontGroups; }
172  inline const agx::Vector<agx::UInt32> CollisionGroupFilter::getUIntGroups() const {return m_uintCollisiontGroups;}
173 }
174 
175 #endif /*AGXMODEL_COLLISIONGROUPFILTER_H*/
agx::Vector< agx::UInt32 > m_uintCollisiontGroups
agx::Vector< agx::Name > getNamedGroups()
Returns the named groups that the filter listens to.
agx::Vector< agx::Name > m_namedCollisionGroups
bool hasMemberGroup(const agxCollide::Geometry *geom) const
Abstract base class that implements a filter that selects which events should trigger a Listener...
Definition: ExecuteFilter.h:33
#define AGXPHYSICS_EXPORT
agxCollide::Geometry * m_geometry
bool match(const agxCollide::Geometry *geo0, const agxCollide::Geometry *geo1) const override
Called by the other two match functions if they are not overridden.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
#define AGX_FORCE_INLINE
Definition: Object.h:59
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
AGXPHYSICS_EXPORT void addGroup(const agx::RigidBody *body, unsigned id)
For the specified body, add the collision group ID to its geometries.
agxCollide::Geometry * getGeometry()
Gets the geometry of the filter.
bool hasGroup(agx::UInt32 id) const
This is performing a linear search among the collision group id for this Geometry.
Definition: Geometry.h:906
agx::Vector< agx::UInt32 > getUIntGroups()
Returns the uint groups that the filter listens to.
AGXPHYSICS_EXPORT void removeGroup(const agx::RigidBody *body, unsigned id)
For the specified body, remove the collision group ID to its geometries.
An ExecuteFilter that is used to filter out contacts matching a specified criteria based on Collision...
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
uint32_t UInt32
Definition: Integer.h:40