AGX Dynamics  2.37.2.0
WireContactUtils.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>
20 
21 #include <agxRender/Color.h>
22 
23 #include <agxCollide/Contacts.h>
24 
25 namespace agxCollide
26 {
27  class ContactPoint;
28 }
29 
30 namespace agx
31 {
32  typedef std::pair< agx::Real, agx::Real > RealPair;
33 }
34 
35 namespace agxWire
36 {
37  class WireDistanceCompositeConstraint;
38  class WireGeometryController;
39  class WireMaterialController;
40  class WireHandler;
41 
43 
45 
46 
47 
50  struct ContactPointDef
51  {
52  enum OnSegment { BEFORE = -1, UNKNOWN, AFTER };
53  ContactPointDef( const agx::Vec3& p, const agx::Vec3f& n, agx::Real d )
54  : point( p ), normal( n ), depth( d ), primary( true ), onSegment( UNKNOWN ) {}
55  ContactPointDef( const agx::Vec3& p, const agx::Vec3f& n, agx::Real d, agx::Bool isPrimaryPoint )
56  : point( p ), normal( n ), depth( d ), primary( isPrimaryPoint ), onSegment( UNKNOWN ) {}
57  agx::Vec3 point;
58  agx::Vec3f normal;
59  agx::Real depth;
60  agx::Bool primary;
61  OnSegment onSegment;
62 
63  typedef agx::VectorPOD< ContactPointDef > Container;
64  };
65 
66  namespace WireContactStatus
67  {
68  enum Enum { KEEP, REMOVE, RELEASE };
69  }
70 
71  // CONTACT SEGMENT
72  // |++++++++++++++++++++|
73  // begin *currIt point *nextIt end
74  // ----o------------o----------O+++++++++o---------------
75  // ^----------^---------^
76  // \/ \/
77  // dist to curr dist to next
78  class AGXPHYSICS_EXPORT WireContactSegment
79  {
80  public:
85  class AGXPHYSICS_EXPORT PointDef
86  {
87  public:
91  PointDef();
92 
96  PointDef( const agx::Vec3& p, const agx::Vec3f& n, agx::Real d );
97 
101  explicit PointDef( const agxCollide::ContactPoint& contactPoint );
102 
106  agx::Vec3& point() { return m_point; }
107  const agx::Vec3& point() const { return m_point; }
108 
112  agx::Vec3f& normal() { return m_normal; }
113  const agx::Vec3f& normal() const { return m_normal; }
114 
118  agx::Real& depth() { return m_depth; }
119  agx::Real depth() const { return m_depth; }
120 
121  operator agxWire::ContactPointDef() const { return ContactPointDef( m_point, m_normal, m_depth ); }
122 
123  private:
124  agx::Vec3 m_point;
125  agx::Vec3f m_normal;
126  agx::Real m_depth;
127  };
128 
129  public:
133  static bool isContactNode( const agxWire::Node* node );
134 
140  static void setContactNode( agxWire::Node* node, bool enable );
141 
148  static agx::RealPair getMinMaxSegmentRestLength( const agxWire::WireDistanceCompositeConstraint* wire );
149 
157  static agx::RealPair getMinMaxSegmentRestLength( const agxWire::WireDistanceCompositeConstraint* wire1, const agxWire::WireDistanceCompositeConstraint* wire2 );
158 
159  public:
167  WireContactSegment( agxWire::WireDistanceCompositeConstraint* wire, agxWire::WireGeometryController* geometryController, const agxWire::WireContactSegment::PointDef& p, const agxCollide::Geometry* wireGeometry );
168 
173  bool isValid() const;
174 
178  agx::Real getLength() const;
179 
183  agx::Real getRestLength() const;
184 
188  agx::Real getMinimumLength() const;
189 
195  void setMinimumLength( agx::Real minimumLength );
196 
200  agx::Real getDistanceToCurr() const;
201 
205  agx::Real getDistanceToNext() const;
206 
210  agx::Real getRadius() const;
211 
215  agx::Vec3 getPointOnWire() const;
216 
220  const agxWire::WireContactSegment::PointDef& getContactPoint() const;
221 
225  agxWire::WireContactSegment::PointDef& getContactPoint();
226 
232  bool requiresNewNodes( bool& ret_newCurr, bool& ret_newNext ) const;
233 
239  bool acquireNodes();
240 
244  agxWire::WireDistanceCompositeConstraint* getWire() const;
245 
249  const agxCollide::Geometry* getWireGeometry() const;
250 
254  agx::Vec3 getWorldDir() const;
255 
259  agxWire::NodeIterator getCurrIt() const;
260 
264  agxWire::NodeIterator getNextIt() const;
265 
269  agxWire::Node* getCurrNode() const;
270 
274  agxWire::Node* getNextNode() const;
275 
284  void setTransform( const agx::AffineMatrix4x4& transform );
285 
286  private:
287  enum RealData { SEGMENT_LENGTH, DIST_TO_CURR, DIST_TO_NEXT, SEGMENT_MINIMUM_LENGTH, NUM_PARAMS };
288 
289  private:
290  WireContactSegment();
291 
295  void initialize( agxWire::WireGeometryController* geometryController, const agxCollide::Geometry* wireGeometry );
296 
297  private:
298  WireDistanceCompositeConstraint* m_wire;
299  const agxCollide::Geometry* m_wireGeometry;
300  PointDef m_point;
301  agx::Vec3 m_pointOnWire;
302  NodeIterator m_currIt;
303  NodeIterator m_nextIt;
304  agx::Real m_params[ NUM_PARAMS ];
305  bool m_initialized;
306  };
307 
308  #define RENDER_DEBUG_POINT( p, color, reason, pos ) \
309  ::render( p, color ); \
310  agxRender::RenderSingleton::instance()->add( reason, pos, color )
311 
312 
313  AGXPHYSICS_EXPORT void render( const agx::Vec3& point, const agx::Vec3f& normal, const agxRender::Color& color );
314 
315  template< typename T >
316  void render( const T& point, const agxRender::Color& color ) { agxWire::render( point.point(), point.normal(), color ); }
317 
321  AGXPHYSICS_EXPORT void renderWireShape( const agx::Vec3& prevStart, const agx::Vec3& prevEnd, const agx::Vec3& currStart, const agx::Vec3& currEnd, agx::Real radius, const agx::Vec4f& color );
322 
327 
328  typedef std::pair< NodeConstIterator, NodeConstIterator > NodeConstIteratorPair;
329 
337  AGXPHYSICS_EXPORT NodeConstIteratorPair calculateToPrevToNextVectors( const agxWire::NodeConstIterator it, agx::Vec3& ret_toPrev, agx::Vec3& ret_toNext );
338 
346  AGXPHYSICS_EXPORT agx::Real findStabilityFactor( const agxWire::NodeConstIterator nodeIt, const agxWire::WireDistanceCompositeConstraint* wire );
347 
351  AGXPHYSICS_EXPORT agx::UInt reduceContacts( agxWire::ContactPointDef::Container& points, agx::Real32 threshold = 0.99f, agx::Bool reduceNegativeDotProducts = false, agx::Real32 negThreshold = -0.0f );
352 
354 
355 }
356 
std::pair< Real, Real > RealPair
float Real32
Definition: Real.h:44
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
bool Bool
Definition: Integer.h:48
This namespace consists of a set of classes for handling geometric intersection tests including boole...
A class holding 4 dimensional vectors and providing basic arithmetic.
Definition: Vec4Template.h:34
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
#define AGXPHYSICS_EXPORT
Utility color class with "common colors".
Definition: Color.h:33
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
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::SymmetricPair< agxWire::Node *> SymmetricNodePtrPair
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
double Real
Definition: Real.h:42
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97