AGX Dynamics  2.35.0.1
UuidHashCollisionFilter.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 #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 
84 
85  public:
90 
95  void setMode( Mode mode );
96 
100  Mode getMode() const;
101 
107 
113 
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:
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 }
#define AGXPHYSICS_EXPORT
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
agx::RigidBody * getRigidBody()
Definition: Geometry.h:850
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:35
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Contact event filter matching UUID of instances, such as agxCollide::Geometry, agx::RigidBody,...
UuidHashCollisionFilter()
Default constructor, default mode is MATCH_ALL.
agx::Bool contains(agx::UInt32 hash) const
void setMode(Mode mode)
Set mode how the filtering is performed.
static agx::UInt32 findUuid(const agx::Referenced *instance)
Finds UUID hash of the given instance.
void remove(agx::UInt32 hash)
Remove hash from the matching set.
static agx::UInt32 findCorrespondingUuid(const agxCollide::Geometry *geometry)
Searches for corresponding object's (e.g., Wire, Cable, Track etc.) UUID given geometry.
void add(agx::UInt32 hash)
Add UUID hash to the matching set.
@ MATCH_AND
Both objects must match our UUID set.
@ MATCH_OR
At least one of the two objects must match our UUIDs.
@ MATCH_ALL
Any object results in a match.
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
agx::Uuid getUuid() const
Definition: Serializable.h:269
Base class providing referencing counted objects.
Definition: Referenced.h:114
UInt32 hash() const
Definition: Uuid.h:213
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
uint32_t UInt32
Definition: Integer.h:40
bool Bool
Definition: Integer.h:48
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65