AGXDynamics  2.35.0.2
CollisionGroupFilter.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 
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
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 
170 
173 }
174 
175 #endif /*AGXMODEL_COLLISIONGROUPFILTER_H*/
agxPhysics_export.h
agxSDK::ExecuteFilter::match
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Definition: ExecuteFilter.h:110
Vector.h
agx::Vector< agx::Name >
agx::Container::size
size_t size() const
Definition: Container.h:134
Geometry.h
agxSDK::ExecuteFilter
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:34
agxUtil::addGroup
AGXPHYSICS_EXPORT void addGroup(const agx::RigidBody *body, unsigned id)
For the specified body, add the collision group ID to its geometries.
agxSDK::CollisionGroupFilter::match
bool match(const agxCollide::Geometry *geo0, const agxCollide::Geometry *geo1) const override
Called by the other two match functions if they are not overridden.
Definition: CollisionGroupFilter.h:124
agxSDK::CollisionGroupFilter::m_namedCollisionGroups
agx::Vector< agx::Name > m_namedCollisionGroups
Definition: CollisionGroupFilter.h:116
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxSDK::CollisionGroupFilter::getGeometry
agxCollide::Geometry * getGeometry()
Gets the geometry of the filter.
Definition: CollisionGroupFilter.h:165
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agxSDK::CollisionGroupFilter::m_uintCollisiontGroups
agx::Vector< agx::UInt32 > m_uintCollisiontGroups
Definition: CollisionGroupFilter.h:117
agxSDK::CollisionGroupFilter::m_geometry
agxCollide::Geometry * m_geometry
Definition: CollisionGroupFilter.h:118
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agxCollide::Geometry::hasGroup
bool hasGroup(agx::UInt32 id) const
This is performing a linear search among the collision group id for this Geometry.
Definition: Geometry.h:885
agx::Name
Representation of a name string.
Definition: Name.h:32
agxSDK::CollisionGroupFilter::getNamedGroups
agx::Vector< agx::Name > getNamedGroups()
Returns the named groups that the filter listens to.
Definition: CollisionGroupFilter.h:168
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxUtil::removeGroup
AGXPHYSICS_EXPORT void removeGroup(const agx::RigidBody *body, unsigned id)
For the specified body, remove the collision group ID to its geometries.
Contacts.h
agxSDK::CollisionGroupFilter
An ExecuteFilter that is used to filter out contacts matching a specified criteria based on Collision...
Definition: CollisionGroupFilter.h:41
agxSDK::CollisionGroupFilter::hasMemberGroup
bool hasMemberGroup(const agxCollide::Geometry *geom) const
Definition: CollisionGroupFilter.h:147
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxSDK::CollisionGroupFilter::getUIntGroups
agx::Vector< agx::UInt32 > getUIntGroups()
Returns the uint groups that the filter listens to.
Definition: CollisionGroupFilter.h:171
ExecuteFilter.h
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
TimeStamp.h
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxSDK.h