AGXDynamics  2.35.0.2
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 
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:
133  using UInt32Set = agx::HashSet<agx::UInt32>;
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 }
agxStream::Serializable::getUuid
agx::Uuid getUuid() const
Definition: Serializable.h:269
agxSDK::UuidHashCollisionFilter::MATCH_ALL
@ MATCH_ALL
Any object results in a match.
Definition: UuidHashCollisionFilter.h:62
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
agxSDK::ExecuteFilter
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:34
agxSDK::UuidHashCollisionFilter::findCorrespondingUuid
static agx::UInt32 findCorrespondingUuid(const agxCollide::Geometry *geometry)
Searches for corresponding object's (e.g., Wire, Cable, Track etc.) UUID given geometry.
agxSDK::UuidHashCollisionFilter::contains
agx::Bool contains(agx::UInt32 hash) const
agxSDK::UuidHashCollisionFilter::MATCH_AND
@ MATCH_AND
Both objects must match our UUID set.
Definition: UuidHashCollisionFilter.h:64
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxSDK::UuidHashCollisionFilter
Contact event filter matching UUID of instances, such as agxCollide::Geometry, agx::RigidBody,...
Definition: UuidHashCollisionFilter.h:57
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agx::hash
AGXCORE_EXPORT UInt32 hash(const T &key)
Definition: HashFunction.h:65
agx::HashSet< agx::UInt32 >
agxSDK::UuidHashCollisionFilter::MATCH_OR
@ MATCH_OR
At least one of the two objects must match our UUIDs.
Definition: UuidHashCollisionFilter.h:63
agx::Uuid::hash
UInt32 hash() const
Definition: Uuid.h:213
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
agx::Bool
bool Bool
Definition: Integer.h:48
agxCollide::Geometry::getRigidBody
agx::RigidBody * getRigidBody()
Definition: Geometry.h:850
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxSDK::UuidHashCollisionFilter::Mode
Mode
Definition: UuidHashCollisionFilter.h:60
ExecuteFilter.h
agxSDK::UuidHashCollisionFilter::match
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.
Definition: UuidHashCollisionFilter.h:140
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40