AGX Dynamics  2.38.0.2
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:
76 
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 
156  using agxSDK::ExecuteFilter::match;
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 
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 
agxWire::LinkObjectStabilizingAlgorithm::GeometryPropertyBoolFilterRef
agx::ref_ptr< GeometryPropertyBoolFilter > GeometryPropertyBoolFilterRef
Definition: LinkAlgorithms.h:41
agx::Real
double Real
Definition: Real.h:42
agx::Vector< agx::LockJointRef >
agxStream::out
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.
Definition: OutputArchive.h:412
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agxWire::LinkObjectStabilizingAlgorithm::GeometryPropertyBoolFilter
GeometryPropertyBoolFilter(const agx::String &propertyName, const agxWire::Link *link)
Construct matching filter given property-bool name and the link.
Definition: LinkAlgorithms.h:197
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE
#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
agx::LockJointRef
agx::ref_ptr< LockJoint > LockJointRef
Definition: LockJoint.h:24
agxWire::LinkObjectStabilizingAlgorithm::GeometryPropertyBoolFilter
GeometryPropertyBoolFilter()
Protected default constructor, used during restore.
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::observer_ptr< const Link >
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxStream::in
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:399
agxWire::LinkObjectStabilizingAlgorithm
(Optional) Link algorithm that tries to stabilize the link when the link is in contact with an object...
Definition: LinkAlgorithms.h:36
agx::ref_ptr
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
agxWire
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
agxWire::LinkObjectStabilizingAlgorithm::getLink
const agxWire::Link * getLink() const
Definition: LinkAlgorithms.h:129
agxWire::LinkObjectStabilizingAlgorithm::m_propertyName
agx::String m_propertyName
Definition: LinkAlgorithms.h:241
LockJoint.h
agxWire::LinkObjectStabilizingAlgorithm::LinkExecuteFilter
LinkExecuteFilter(const agxWire::Link *link)
Construct given link this algorithm belongs to.
Definition: LinkAlgorithms.h:123
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
ContactEventListener.h
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agx::Bool
bool Bool
Definition: Integer.h:40
agxStream
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Definition: ElementaryConstraint.h:31
agxWire::LinkObjectStabilizingAlgorithm::RigidBodyPropertyBoolFilter
RigidBodyPropertyBoolFilter(const agx::String &propertyName, const agxWire::Link *link)
Construct matching filter given property-bool name and the link.
Definition: LinkAlgorithms.h:262
agx::AgXString< std::string >
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
agxSDK::ContactEventListenerRef
agx::ref_ptr< ContactEventListener > ContactEventListenerRef
Definition: ContactEventListener.h:139
agxWire::LinkObjectStabilizingAlgorithm::matchT
agx::Bool matchT(const T *obj) const
Match function for either agxCollide::Geometry or agx::RigidBody.
Definition: LinkAlgorithms.h:231
agxWire::LinkObjectStabilizingAlgorithm::RigidBodyPropertyBoolFilterRef
agx::ref_ptr< RigidBodyPropertyBoolFilter > RigidBodyPropertyBoolFilterRef
Definition: LinkAlgorithms.h:44