AGX Dynamics  2.37.2.0
LinkAlgorithms.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 <agxWire/Link.h>
20 
22 
23 #include <agx/LockJoint.h>
24 
25 namespace agxWire
26 {
37  {
38  public:
39  class LinkExecuteFilter;
40  class GeometryPropertyBoolFilter;
41  class RigidBodyPropertyBoolFilter;
42 
45 
46  public:
53 
58  void setTensionThreshold( agx::Real tensionThreshold );
59 
63  agx::Real getTensionThreshold() const;
64 
66  public:
68 
70 
71  protected:
75  LinkObjectStabilizingAlgorithm();
76 
80  virtual ~LinkObjectStabilizingAlgorithm();
81 
82  protected:
86  virtual void onLinkEnable( agx::Bool enable, agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy ) override;
87 
91  virtual void pre( agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy ) override;
92 
96  virtual void post( agxWire::Link* link, agxSDK::SimulationProxy* simulationProxy ) override;
97 
98  protected:
99  typedef agx::Vector< agx::LockJointRef > ConstraintContainer;
100 
101  protected:
102  agxSDK::ContactEventListenerRef m_contactListener;
103  ConstraintContainer m_constraints;
104  agx::Real m_tensionThreshold;
105  };
106 
115  class AGXPHYSICS_EXPORT LinkObjectStabilizingAlgorithm::LinkExecuteFilter : public agxSDK::ExecuteFilter, public agxStream::Serializable
116  {
117  public:
124  : m_link( link ) {}
125 
129  const agxWire::Link* getLink() const { return m_link; }
130 
132  public:
136  virtual void store( agxStream::OutputArchive& out ) const override;
137 
141  virtual void restore( agxStream::InputArchive& in ) override;
142 
144 
146 
147  protected:
154  virtual bool matchOther( const agxCollide::Geometry* otherGeometry ) const = 0;
155 
157 
161  virtual bool match( const agxCollide::Geometry* geometry1, const agxCollide::Geometry* geometry2 ) const override
162  {
163  // If the link has been deleted our contact event listener shouldn't still be in the simulation!
164 
165  // ^^ But if the link has been removed we will send a match to the internal contact event
166  // listener so that the listener can remove itself.
167  if ( m_link == nullptr )
168  return true;
169 
170  agx::Bool firstIsLink = m_link != nullptr && geometry1->getRigidBody() == m_link->getRigidBody();
171  agx::Bool secondIsLink = m_link != nullptr && geometry2->getRigidBody() == m_link->getRigidBody();
172  return firstIsLink ? matchOther( geometry2 ) : secondIsLink ? matchOther( geometry1 ) : false;
173  }
174 
175  private:
177  };
178 
189  class AGXPHYSICS_EXPORT LinkObjectStabilizingAlgorithm::GeometryPropertyBoolFilter : public LinkObjectStabilizingAlgorithm::LinkExecuteFilter
190  {
191  public:
197  GeometryPropertyBoolFilter( const agx::String& propertyName, const agxWire::Link* link )
198  : LinkExecuteFilter( link ), m_propertyName( propertyName ) {}
199 
201  public:
203 
205 
206  protected:
210  GeometryPropertyBoolFilter();
211 
215  virtual ~GeometryPropertyBoolFilter();
216 
221  virtual bool matchOther( const agxCollide::Geometry* otherGeometry ) const override
222  {
223  return matchT( otherGeometry );
224  }
225 
230  template< typename T >
231  agx::Bool matchT( const T* obj ) const
232  {
233  agx::Bool propertyValue = false;
234  return obj != nullptr &&
235  obj->hasPropertyContainer() &&
236  obj->getPropertyContainer()->getPropertyBool( m_propertyName, propertyValue ) &&
237  propertyValue;
238  }
239 
240  protected:
242  };
243 
254  class AGXPHYSICS_EXPORT LinkObjectStabilizingAlgorithm::RigidBodyPropertyBoolFilter : public LinkObjectStabilizingAlgorithm::GeometryPropertyBoolFilter
255  {
256  public:
262  RigidBodyPropertyBoolFilter( const agx::String& propertyName, const agxWire::Link* link )
263  : GeometryPropertyBoolFilter( propertyName, link ) {}
264 
266  public:
268 
270 
271  protected:
275  RigidBodyPropertyBoolFilter();
276 
280  virtual ~RigidBodyPropertyBoolFilter();
281 
286  virtual bool matchOther( const agxCollide::Geometry* otherGeometry ) const override
287  {
288  return matchT( otherGeometry->getRigidBody() );
289  }
290  };
291 }
292 
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
(Optional) Link algorithm that tries to stabilize the link when the link is in contact with an object...
agx::ref_ptr< GeometryPropertyBoolFilter > GeometryPropertyBoolFilterRef
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
bool Bool
Definition: Integer.h:48
GeometryPropertyBoolFilter(const agx::String &propertyName, const agxWire::Link *link)
Construct matching filter given property-bool name and the link.
#define AGXPHYSICS_EXPORT
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
RigidBodyPropertyBoolFilter()
Protected default constructor, used during restore.
ref_ptr< LockJoint > LockJointRef
Definition: LockJoint.h:102
GeometryPropertyBoolFilter()
Protected default constructor, used during restore.
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
const agxWire::Link * getLink() const
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
agx::ref_ptr< ContactEventListener > ContactEventListenerRef
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
virtual bool matchOther(const agxCollide::Geometry *otherGeometry) const override
Match function.
LinkExecuteFilter(const agxWire::Link *link)
Construct given link this algorithm belongs to.
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
virtual bool match(const agxCollide::Geometry *geometry1, const agxCollide::Geometry *geometry2) const override
Base match method which determines which geometry belongs to the link and who&#39;s not.
#define AGXSTREAM_DECLARE_SERIALIZABLE(T)
Use this in a Serializable class to add the required methods Important: Use full namespace in the dec...
Definition: Serializable.h:207
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
RigidBodyPropertyBoolFilter(const agx::String &propertyName, const agxWire::Link *link)
Construct matching filter given property-bool name and the link.
double Real
Definition: Real.h:42
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
agx::Bool matchT(const T *obj) const
Match function for either agxCollide::Geometry or agx::RigidBody.
agx::ref_ptr< RigidBodyPropertyBoolFilter > RigidBodyPropertyBoolFilterRef
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
agx::RigidBody * getRigidBody()
Definition: Geometry.h:865
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97