AGX Dynamics 2.42.3.1
Loading...
Searching...
No Matches
LinkAlgorithms.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agxWire/Link.h>
20
22
23#include <agx/LockJoint.h>
24
25namespace 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
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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.
const agxWire::Link * getLink() const
agx::ref_ptr< GeometryPropertyBoolFilter > GeometryPropertyBoolFilterRef
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:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
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
This namespace contain classes for streaming classes into archives, ASCII, binary for storage (serial...
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
bool Bool
Definition: Integer.h:40
double Real
Definition: Real.h:41