AGX Dynamics  2.37.2.0
WireHandler.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/Node.h>
21 
22 #include <agxUtil/agxUtil.h>
23 
24 #include <agx/agxPhysics_export.h>
25 
27 
29 
30 
31 namespace agxWire
32 {
33  class WireDistanceCompositeConstraint;
34  class WireGeometryController;
35  class WireWireContactConstraint;
36  typedef WireWireContactConstraint* WireWireContactConstraintPtr;
37  class WireContactConstraint;
38  typedef WireContactConstraint* WireContactConstraintPtr;
39  class WireSegmentContactConstraint;
40  typedef WireSegmentContactConstraint* WireSegmentContactConstraintPtr;
41  class WireContactSegment;
42 
43  struct ContactMode
44  {
45  enum Enum {
46  UNKNOWN = 0,
47  FACE_CONTACT = (1<<0),
48  EDGE_SAFE = (1<<1),
49  SPHERE_CONTACT = (1<<2),
50  SPHERE_CONTACT_BEGIN = (1<<3),
51  SPHERE_CONTACT_END = (1<<4),
52  OLD_CONTACT_MODEL = (1<<5)
53  };
54 
55  static agx::UInt find( const agxCollide::ContactPoint& point, const agx::AffineMatrix4x4& invWireShapeTransform, const WireContactSegment* segment, bool useKinematicContactNodes );
56  };
57 
61  class AGXPHYSICS_EXPORT WireHandler : public agxSDK::StepEventListener
62  {
63  public:
64  typedef agx::VectorPOD< WireWireContactConstraintPtr > WireWireContactConstraintPtrContainer;
65  typedef agx::VectorPOD< WireContactConstraintPtr > WireContactConstraintPtrContainer;
66  typedef agx::VectorPOD< WireSegmentContactConstraintPtr > WireSegmentContactConstraintPtrContainer;
67  typedef agx::List< WireContactConstraintPtr > WireContactConstraintPtrList;
68  typedef agx::List< WireSegmentContactConstraintPtr > WireSegmentContactConstraintPtrList;
69 
72 
74 #if HASH_FOR_WIRE == HASH_NEW
79 #elif HASH_FOR_WIRE == HASH_OLD
81  typedef agx::QuadraticProbingHashTable< WireWireKey, WireWireContactConstraintPtr > WireWireKeyWireWireContactConstraintPtrTable;
82  typedef agx::QuadraticProbingHashTable< Node*, WireContactConstraintPtrList > NodePtrWireContactConstraintPtrTable;
83  typedef agx::QuadraticProbingHashTable< SymmetricNodePtrPair, WireSegmentContactConstraintPtrList > NodePtrPairWireSegmentContactConstraintPtrTable;
84 #endif
85 
86  public:
90  WireHandler();
91 
103  bool handle( agxWire::WireDistanceCompositeConstraint* wire1, agxWire::WireGeometryController* wire1GeometryController, const agxCollide::Geometry* wire1Geometry, agxWire::WireDistanceCompositeConstraint* wire2, agxWire::WireGeometryController* wire2GeometryController, const agxCollide::Geometry* wire2Geometry, agxCollide::GeometryContact* geometryContact );
104 
108  bool handle( agxWire::WireDistanceCompositeConstraint* wire, agxWire::WireGeometryController* geometryController, agxCollide::Geometry* otherGeometry, agxCollide::GeometryContact* geometryContact, bool onlySphereContact );
109 
115  void onRemoveNotification( agxWire::WireDistanceCompositeConstraint* wire );
116 
120  agx::UInt getNodeCount( const agxWire::Node* node ) const;
121 
125  void executeCallback( agxWire::WireParallelCallbacksHandler::CallbackTypes type );
126 
127  protected:
128  virtual ~WireHandler();
129 
133  void clear( agxSDK::Simulation* simulation );
134 
135  friend class WireContactSegment;
142  void remove( agxWire::Node* node, agxWire::WireDistanceCompositeConstraint* wire );
143 
149  bool removeContactConstraints( agxWire::Node* node );
150 
151 
157  void release( agxWire::Node* node );
158 
165  agx::UInt updateCounter( const agxWire::Node* node, int increment );
166 
170  agxWire::WireWireContactConstraintPtr getConstraint( agxWire::WireHandler::WireWireKey key ) const;
171 
175  agxWire::WireContactConstraintPtr getConstraint( agxWire::Node* node, const agxCollide::Geometry* geometry ) const;
176 
180  agxWire::WireSegmentContactConstraintPtr getConstraint( const agxWire::WireContactSegment& segment, const agxCollide::Geometry* geometry ) const;
181 
185  WireContactConstraintPtrList* getConstraints( agxWire::Node* node ) const;
186 
191  void add( agxWire::WireWireContactConstraintPtr constraint );
192 
197  void add( agxWire::WireContactConstraintPtr constraint );
198 
203  void add( agxWire::WireSegmentContactConstraintPtr constraint );
204 
208  void remove( agxWire::WireWireContactConstraintPtr constraint );
209 
213  void remove( agxWire::WireContactConstraintPtr constraint );
214 
218  void remove( agxWire::WireSegmentContactConstraintPtr constraint );
219 
224  void collide( agxWire::WireContactSegment& contactSegment1, agxWire::WireContactSegment& contactSegment2, agx::Real32 normalScale );
225 
229  bool collide( agxWire::WireContactSegment& contactSegment, const agxCollide::Geometry* wireGeometry, agxCollide::Geometry* otherGeometry, agx::UInt contactModeMask, agx::Real32 normalScale );
230 
231  void createOrUpdateConstraint( agxWire::WireContactSegment& contactSegment1, agxWire::WireContactSegment& contactSegment2, agx::Real32 normalScale );
232  void createOrUpdateConstraint( agxWire::Node* node, agxWire::WireContactSegment& contactSegment, agxCollide::Geometry* otherGeometry, agx::Real32 normalScale, bool changeNodeType = true );
233  void createOrUpdateConstraint( agxWire::WireContactSegment& contactSegment, agxCollide::Geometry* otherGeometry, agx::Real32 normalScale, bool changeNodeType = true );
234 
235  virtual void addNotification() override;
236  virtual void removeNotification() override;
237 
238  virtual void preCollide( const agx::TimeStamp& ) override;
239  virtual void pre( const agx::TimeStamp& ) override;
240  virtual void post( const agx::TimeStamp& ) override;
241 
242  typedef int (*WireContactUpdateCallback)( agxWire::WireContactConstraintPtr, agxSDK::Simulation*, agxCollide::LocalGeometryContactVector& );
243  typedef int (*WireSegmentContactUpdateCallback)( agxWire::WireSegmentContactConstraintPtr, agxSDK::Simulation*, agxCollide::LocalGeometryContactVector& );
244  typedef int (*WireWireContactUpdateCallback)( agxWire::WireWireContactConstraintPtr, agxSDK::Simulation*, agxCollide::LocalGeometryContactVector& );
245  void handleCallback( WireContactUpdateCallback wireContactUpdater, WireSegmentContactUpdateCallback wireSegmentContactUpdater, WireWireContactUpdateCallback wireWireContactUpdater );
246 
247  agxWire::WireWireContactConstraintPtr getNewWireWireContactConstraint();
248  void returnConstraint( agxWire::WireWireContactConstraintPtr constraint );
249 
250  agxWire::WireContactConstraintPtr getNewWireContactConstraint();
251  void returnConstraint( agxWire::WireContactConstraintPtr constraint );
252 
253  agxWire::WireSegmentContactConstraintPtr getNewWireSegmentContactConstraint();
254  void returnConstraint( agxWire::WireSegmentContactConstraintPtr constraint );
255 
256  void expand( WireWireContactConstraintPtrContainer& constraints, agx::UInt numElements ) const;
257  void expand( WireContactConstraintPtrContainer& constraints, agx::UInt numElements ) const;
258  void expand( WireSegmentContactConstraintPtrContainer& constraints, agx::UInt numElements ) const;
259 
260  AGXSTREAM_DECLARE_SERIALIZABLE( agxWire::WireHandler );
261 
262  protected:
263  WireWireContactConstraintPtrContainer m_wireWireContactConstraintPool;
264  WireContactConstraintPtrContainer m_wireContactConstraintPool;
265  WireSegmentContactConstraintPtrContainer m_wireSegmentContactConstraintPool;
266  WireWireKeyWireWireContactConstraintPtrTable m_nodesToWireWireContactConstraint;
267  NodePtrWireContactConstraintPtrTable m_nodeToWireContactConstraint;
268  NodePtrPairWireSegmentContactConstraintPtrTable m_nodesToWireSegmentContactConstraint;
269  agxUtil::ConstraintHolderRef m_wireWireContactConstraints;
270  agxUtil::ConstraintHolderRef m_wireContactConstraints;
271  agxUtil::ConstraintHolderRef m_wireSegmentContactConstraints;
272  NodePtrUIntTable m_nodeCounter;
273  agx::PropertyContainerRef m_tempPropertyContainer;
274  agx::Mutex m_mutex;
275  };
276 
277  typedef agx::ref_ptr< WireHandler > WireHandlerRef;
278 }
279 
float Real32
Definition: Real.h:44
AGXTERRAIN_EXPORT void clear()
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
Derive from this class to implement a listener for simulation step events.
A contact between two geometries.
Definition: Contacts.h:270
Inheritance with partial specialization due to bug with ref_ptr containers.
#define AGXPHYSICS_EXPORT
agx::Real TimeStamp
Definition: TimeStamp.h:26
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
uint32_t UInt
Definition: Integer.h:34
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
agx::SymmetricPair< agxWire::Node *> SymmetricNodePtrPair
#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
std::mutex Mutex
Definition: Referenced.h:99
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
A contact point in a contact data.
Definition: Contacts.h:55
Class defining a node that is part of a wire.
Definition: agxWire/Node.h:511
Inheritance with partial specialization due to bug with ref_ptr containers.
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97