AGX Dynamics  2.37.2.0
WireShapeContactController.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 
20 #include <agx/Vec3.h>
21 #include <agxWire/Node.h>
23 #include <agxWire/WireUtils.h>
26 
28 
29 namespace agxCollide
30 {
31  class Shape;
32  class GeometryContactPtr;
33  class Geometry;
34 }
35 
36 namespace agxWire
37 {
38  class Wire;
39  class WireDistanceCompositeConstraint;
40 
42  typedef agx::HashVector< Node*, GeometryContactVector > NodePtrGeometryContactVectorTable;
43  typedef agx::Vector< std::pair< ShapeContactNode*, agx::Real> > ShapeContactRealPairVector;
44  typedef agx::HashVector<ShapeContactNodeRef, ShapeContactNodeRef> NodeMergePairHashVector;
45 
46  typedef agx::HashSet<agxCollide::Shape*> ShapeSet;
47  typedef agx::HashTable<ShapeContactNode*, ShapeSet > NodeShapeSetVector;
48  typedef agx::List< agxWire::NodeConstIterator > NodeIteratorList;
49 
50  class AGXPHYSICS_EXPORT WireShapeContactController : public agxWire::WireContactController
51  {
52  public:
53  WireShapeContactController( Wire* wire );
54 
55  static BodyFixedNode* changeToBodyFixed(ShapeContactNode* cn, Wire* wire);
56  static ShapeContactNode* changeToShapeContact(Node* node, Wire* wire, agxCollide::Shape* shape, const agx::Vec3& cPoint,
57  const agx::Vec3& cNormal, const agx::Real& cDepth, const agx::Bool removeOtherNode);
58 
59  void removeLumpedNodesTooClose();
60 
61  void findExtraLength();
62 
63  void analyzePossibleBodyFixReplacement();
64 
65  virtual agx::Bool handleGeometryContact(agxCollide::GeometryContact* geometryContact, agxCollide::Geometry* otherGeometry);
66 
67  virtual void preCollideUpdate();
68  virtual void preUpdate();
69  virtual void postUpdate();
70 
71  struct SurfacePointData
72  {
73  SurfacePointData( agx::Vec3 surfacePoint,
74  agx::Vec3 normal,
75  agxCollide::Shape* shape,
76  agxCollide::GeometryContact* geometryContact,
77  agx::UInt pointIndex,
78  agx::Bool isFaceContact )
79  : point( surfacePoint ),
80  normal( normal ),
81  shape( shape ),
82  geometryContact( geometryContact ),
83  pointIndex( pointIndex ),
84  isFaceContact( isFaceContact )
85  {
86  }
87 
88  agx::Vec3 point;
89  agx::Vec3 normal;
90  agxCollide::Shape* shape;
91  agxCollide::GeometryContact* geometryContact;
92  agx::UInt pointIndex;
93  agx::Bool isFaceContact;
94  };
95  typedef agx::Vector< SurfacePointData > SurfacePointVector;
96  typedef agx::Vector< agxCollide::MeshRef > MeshVector;
97 
98  protected:
99  virtual ~WireShapeContactController();
100 
101  void movePenetratingContactNodesBackAlongEdges(NodeShapeSetVector& nodesToShapeList);
102  void resetEdgeClamping(const ContactNodeDataList& nodes) const;
106  agx::Bool findSurfacePosition( ShapeContactNode* cn ) const;
107  void removeUnwantedNodes(const ContactNodeDataList& nodes);
108  void findSurfacePositions(ContactNodeDataList& nodes) const;
109  void removeNodesByAngle(ContactNodeDataList& nodes, const agx::Bool ignoreClampedPosition = false);
110  void chooseAndClampNodeEdges(ContactNodeDataList& nodes, NodeShapeSetVector& nodesToShapes);
111 
112 
113  agx::Real calculateAcceptedWireOverlap(const agx::Real& wireRadius) const;
114  agx::Bool getWorldPositionNormalAndEdgeOfNeighbour(NodeConstIterator it, agx::Vec3& pos, agx::Vec3& normal, agx::Vec3& edge, const agx::Bool before) const;
115 
116 
117  agx::Bool evaluateMiddleContact(const ShapeContactNode* prevContact, const ShapeContactNode* middleContact, const ShapeContactNode* nextContact, agx::Bool& dueToPrev) const;
118  agx::Bool shouldContactBecomeBodyFixed(ContactNodeDataList::iterator nodeDataIterator) const;
119  void analyzeContactState(ContactNodeDataList::iterator nodeDataIterator, ContactNodeDataList& nodeDataList) const;
120  void validateContact(ContactNodeDataList::iterator nodeDataIterator, const agx::Bool ignoreClampedPosition = false) const;
121  agx::Bool evaluateCloseContact( const ShapeContactNode* closeContact,
122  const agx::Vec3& nodePositionWorld,
123  const ShapeCurvature& worldCurvature,
124  agx::Real wireRadius ) const;
125  agx::Bool evaluateCloseContact( const ShapeContactNode* closeContact,
126  const agx::Vec3& nodePositionWorld,
127  const ShapeCurvature& worldCurvature,
128  agx::Real wireRadius,
129  agx::Real& dotNormals ) const;
130 
131  agxWire::ShapeContactNode* evaluateAndInsertNewContact( agxCollide::Geometry* wireGeom, const SurfacePointData& surfacePointData, const ContactNodePtrVector& newNodes);
132 
133  void createNewContactNodes(NodeShapeSetVector& nodesToShapeList);
134 
135  void collectPossibleEdges(ShapeContactNode* scn, agxCollide::Shape* shape, ShapeContactEdgeVector& possibleEdges);
136 
137  agx::Bool clampEdgeToShape(ShapeContactNode* scn, ShapeContactEdge& edge, agxCollide::Shape* shape);
138 
139  agx::Bool clampEdgeToPlane(ShapeContactNode* cn, ShapeContactEdge& edge, const agx::Vec3& point, const agx::Vec3& clampNormal, const agx::Bool moveNode = false);
140 
141  void chooseAndClampNodeEdge(ContactNodeData& cnData, const NodeShapeSetVector& nodesToShapes);
142 
143  agx::Bool mergeCrossingEdgeNodes(const agx::Bool forwardInTime);
144  agx::Bool mergeCloseNodes();
145  agx::Bool mergeNodes(NodeMergePairHashVector& nodesToMerge);
146 
147  agx::Bool findWhichNodeToRemoveByMerge(ShapeContactNode* firstContact, ShapeContactNode* secondContact, const Node* prevNode, const Node* nextNode) const;
148 
149  agx::Bool isClamped(ShapeContactNode* cn);
150 
151  agx::Bool merge(ShapeContactNode* a, ShapeContactNode* b, Node* prevNode, Node* nextNode);
152 
153  void fixFreeEndContactPassings(WireDistanceCompositeConstraint* ldcc);
154  agx::Bool nearClampPosition(const ShapeContactNode* scn) const;
155  agx::Bool atClampPosition(const ShapeContactNode* scn) const;
156 
160  agx::Bool considerNewEdge(const ShapeContactNode* scn, const ShapeContactEdge& edge) const;
161 
168  void getNewNodeVelocities(agx::Bool integrate);
169 
170  void getAllContactNodes(WireDistanceCompositeConstraint* ldcc, agx::List<NodeIterator>& allContacts);
171  void getMovableContactNodes(const agx::List<NodeIterator>& allContacts, agx::List<NodeIterator>& contacts, agx::List<NodeIterator>& noMovementContacts);
172 
173  void analyzeCollision(NodeShapeSetVector& nodesToShapeList, agxCollide::GeometryContact& gc, agxCollide::Geometry* wireGeom, agxCollide::Geometry* otherGeom, SurfacePointVector& contactInfo );
174  void findRouteAroundMesh( agxCollide::Geometry* wireGeom, const agxCollide::GeometryContact& gc, const agx::Vector< agxCollide::MeshRef >& meshes);
175 
176  enum class EvaluationResult
177  {
178  IGNORE_POINT,
179  CREATE_NODE,
180  CREATE_GEOMETRY_CONTACT_PREV,
181  CREATE_GEOMETRY_CONTACT_NEXT
182  };
183 
184  bool verifyBothAreNeeded(const ShapeContactNode* otherContact,
185  const Node* behindOtherContact,
186  const Node* behindNewNode,
187  const agx::Vec3& newWorldPosition,
188  const agx::Real& wireRadius) const;
189 
190  EvaluationResult evaluate( const agxCollide::Shape* shape,
191  const agx::Vec3& nodePositionWorld,
192  const ShapeCurvature& worldCurvature,
193  const NodeContainer& wireNodes,
194  NodeIterator prevIt,
195  NodeIterator nextIt,
196  const agx::Real& wireRadius,
197  const agx::Vector<ShapeContactNode*>& newNodes,
198  const agx::Bool favorLumpSphereContacts = true ) const;
199  protected:
200  NodePtrGeometryContactVectorTable m_nodeGeometryContactTable;
202  agxCollide::LocalGeometryContactVector m_localGeometryContacts;
203  };
204 
205  typedef agx::ref_ptr< WireShapeContactController > WireShapeContactControllerRef;
206 }
207 
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
NodeRefListA NodeContainer
Definition: agxWire/Node.h:53
bool Bool
Definition: Integer.h:48
Base class for a shape.
Definition: Shape.h:53
This namespace consists of a set of classes for handling geometric intersection tests including boole...
A contact between two geometries.
Definition: Contacts.h:270
NodeContainer::iterator NodeIterator
Definition: agxWire/Node.h:54
#define AGXPHYSICS_EXPORT
agx::Vector< GeometryContact > GeometryContactVector
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
Templated vector class.
Definition: Vector.h:52
uint32_t UInt
Definition: Integer.h:34
Implements a Wire model with adaptive resolution.
Definition: MergedBody.h:39
agx::List< ContactNodeData > ContactNodeDataList
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:29
NodeContainer::const_iterator NodeConstIterator
Definition: agxWire/Node.h:57
double Real
Definition: Real.h:42
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