AGX Dynamics  2.35.0.1
LinkAlgorithms.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 <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 
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 
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
#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
#define AGXPHYSICS_EXPORT
(Optional) Link algorithm that tries to stabilize the link when the link is in contact with an object...
agx::ref_ptr< RigidBodyPropertyBoolFilter > RigidBodyPropertyBoolFilterRef
RigidBodyPropertyBoolFilter(const agx::String &propertyName, const agxWire::Link *link)
Construct matching filter given property-bool name and the link.
LinkExecuteFilter(const agxWire::Link *link)
Construct given link this algorithm belongs to.
agx::Bool matchT(const T *obj) const
Match function for either agxCollide::Geometry or agx::RigidBody.
void setTensionThreshold(agx::Real tensionThreshold)
Assign new tension threshold defining the moment the stabilizing constraints should be applied.
agx::ref_ptr< GeometryPropertyBoolFilter > GeometryPropertyBoolFilterRef
const agxWire::Link * getLink() const
GeometryPropertyBoolFilter()
Protected default constructor, used during restore.
GeometryPropertyBoolFilter(const agx::String &propertyName, const agxWire::Link *link)
Construct matching filter given property-bool name and the link.
LinkObjectStabilizingAlgorithm(agxWire::LinkObjectStabilizingAlgorithm::LinkExecuteFilter *filter, agx::Real tensionThreshold=agx::Real(1E4))
Construct given filter to filter out which objects should have this feature.
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
agx::ref_ptr< ContactEventListener > ContactEventListenerRef
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
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
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.
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:40
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:48
ref_ptr< LockJoint > LockJointRef
Definition: LockJoint.h:102
double Real
Definition: Real.h:42