AGX Dynamics  2.37.3.2
UuidHashCollisionFilter.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 #pragma once
18 
19 #include <agxSDK/ExecuteFilter.h>
20 
21 namespace agxSDK
22 {
58  {
59  public:
60  enum Mode
61  {
64  MATCH_AND
65  };
66 
67  public:
77  static agx::UInt32 findUuid( const agx::Referenced* instance );
78 
83  static agx::UInt32 findCorrespondingUuid( const agxCollide::Geometry* geometry );
84 
85  public:
90 
95  void setMode( Mode mode );
96 
100  Mode getMode() const;
101 
106  void add( agx::UInt32 hash );
107 
112  void remove( agx::UInt32 hash );
113 
118  agx::Bool contains( agx::UInt32 hash ) const;
119 
120  public:
121  virtual bool match( const agxCollide::Geometry* geometry1,
122  const agxCollide::Geometry* geometry2 ) const override;
123 
124  using ExecuteFilter::match;
125 
126  protected:
127  virtual ~UuidHashCollisionFilter();
128 
129  private:
130  agx::Bool isMatch( const agxCollide::Geometry* geometry ) const;
131 
132  private:
134 
135  private:
136  Mode m_mode;
137  UInt32Set m_uuids;
138  };
139 
141  const agxCollide::Geometry* geometry2 ) const
142  {
143  return m_mode == MATCH_ALL ||
144  ( m_mode == MATCH_OR && ( isMatch( geometry1 ) || isMatch( geometry2 ) ) ) ||
145  ( m_mode == MATCH_AND && ( isMatch( geometry1 ) && isMatch( geometry2 ) ) );
146  }
147 
148  inline agx::Bool UuidHashCollisionFilter::isMatch( const agxCollide::Geometry* geometry ) const
149  {
150  const auto rbUuid = geometry->getRigidBody() != nullptr ?
151  geometry->getRigidBody()->getUuid().hash() :
152  0u;
153  return contains( findCorrespondingUuid( geometry ) ) ||
154  contains( rbUuid );
155  }
156 }
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
bool Bool
Definition: Integer.h:48
Abstract base class that implements a filter that selects which events should trigger a Listener...
Definition: ExecuteFilter.h:33
#define AGXPHYSICS_EXPORT
At least one of the two objects must match our UUIDs.
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::Uuid getUuid() const
Definition: Serializable.h:269
UInt32 hash() const
Definition: Uuid.h:213
Contact event filter matching UUID of instances, such as agxCollide::Geometry, agx::RigidBody, agxWire::Wire, agxCable::Cable, agxVehicle::Track and/or agxTerrain::Terrain.
virtual bool match(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2) const override
Called by the other two match functions if they are not overridden.
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
agx::RigidBody * getRigidBody()
Definition: Geometry.h:865