AGXDynamics  2.31.1.0
WireShapeContactController.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 
49  class AGXPHYSICS_EXPORT WireShapeContactController : public agxWire::WireContactController
50  {
51  public:
52  WireShapeContactController( Wire* wire );
53 
54  static BodyFixedNode* changeToBodyFixed(ShapeContactNode* cn, Wire* wire);
55  static ShapeContactNode* changeToShapeContact(Node* node, Wire* wire, agxCollide::Shape* shape, const agx::Vec3& cPoint,
56  const agx::Vec3& cNormal, const agx::Real& cDepth, const agx::Bool removeOtherNode);
57 
58  void removeLumpedNodesTooClose();
59 
60  void findExtraLength();
61 
62  void analyzePossibleBodyFixReplacement();
63 
64  virtual agx::Bool handleGeometryContact(agxCollide::GeometryContact* geometryContact, agxCollide::Geometry* otherGeometry);
65 
66  virtual void preCollideUpdate();
67  virtual void preUpdate();
68  virtual void postUpdate();
69 
70  struct SurfacePointData
71  {
72  SurfacePointData( agx::Vec3 surfacePoint,
73  agx::Vec3 normal,
74  agxCollide::Shape* shape,
75  agxCollide::GeometryContact* geometryContact,
76  agx::UInt pointIndex,
77  agx::Bool isFaceContact )
78  : point( surfacePoint ),
79  normal( normal ),
80  shape( shape ),
81  geometryContact( geometryContact ),
82  pointIndex( pointIndex ),
83  isFaceContact( isFaceContact )
84  {
85  }
86 
87  agx::Vec3 point;
88  agx::Vec3 normal;
89  agxCollide::Shape* shape;
90  agxCollide::GeometryContact* geometryContact;
91  agx::UInt pointIndex;
92  agx::Bool isFaceContact;
93  };
94  typedef agx::Vector< SurfacePointData > SurfacePointVector;
95  typedef agx::Vector< agxCollide::MeshRef > MeshVector;
96 
97  protected:
98  virtual ~WireShapeContactController();
99 
100  void movePenetratingContactNodesBackAlongEdges(NodeShapeSetVector& nodesToShapeList);
101  void resetEdgeClamping(const ContactNodeDataList& nodes) const;
105  agx::Bool findSurfacePosition( ShapeContactNode* cn ) const;
106  void removeUnwantedNodes(const ContactNodeDataList& nodes);
107  void findSurfacePositions(ContactNodeDataList& nodes) const;
108  void removeNodesByAngle(ContactNodeDataList& nodes, const agx::Bool ignoreClampedPosition = false);
109  void chooseAndClampNodeEdges(ContactNodeDataList& nodes, NodeShapeSetVector& nodesToShapes);
110 
111 
112  agx::Real calculateAcceptedWireOverlap(const agx::Real& wireRadius) const;
113  agx::Bool getWorldPositionNormalAndEdgeOfNeighbour(NodeConstIterator it, agx::Vec3& pos, agx::Vec3& normal, agx::Vec3& edge, const agx::Bool before) const;
114 
115 
116  agx::Bool evaluateMiddleContact(const ShapeContactNode* prevContact, const ShapeContactNode* middleContact, const ShapeContactNode* nextContact, agx::Bool& dueToPrev) const;
117  agx::Bool shouldContactBecomeBodyFixed(ContactNodeDataList::iterator nodeDataIterator) const;
118  void analyzeContactState(ContactNodeDataList::iterator nodeDataIterator, ContactNodeDataList& nodeDataList) const;
119  void validateContact(ContactNodeDataList::iterator nodeDataIterator, const agx::Bool ignoreClampedPosition = false) const;
120  agx::Bool evaluateCloseContact( const ShapeContactNode* closeContact,
121  const agx::Vec3& nodePositionWorld,
122  const ShapeCurvature& worldCurvature,
123  agx::Real wireRadius ) const;
124  agx::Bool evaluateCloseContact( const ShapeContactNode* closeContact,
125  const agx::Vec3& nodePositionWorld,
126  const ShapeCurvature& worldCurvature,
127  agx::Real wireRadius,
128  agx::Real& dotNormals ) const;
129 
130  agxWire::ShapeContactNode* evaluateAndInsertNewContact( agxCollide::Geometry* wireGeom, const SurfacePointData& surfacePointData );
131 
132  void createNewContactNodes(NodeShapeSetVector& nodesToShapeList);
133 
134  void collectPossibleEdges(ShapeContactNode* scn, agxCollide::Shape* shape, ShapeContactEdgeVector& possibleEdges);
135 
136  agx::Bool clampEdgeToShape(ShapeContactNode* scn, ShapeContactEdge& edge, agxCollide::Shape* shape);
137 
138  agx::Bool clampEdgeToPlane(ShapeContactNode* cn, ShapeContactEdge& edge, const agx::Vec3& point, const agx::Vec3& clampNormal, const agx::Bool moveNode = false);
139 
140  void chooseAndClampNodeEdge(ContactNodeData& cnData, const NodeShapeSetVector& nodesToShapes);
141 
142  agx::Bool mergeCrossingEdgeNodes(const agx::Bool forwardInTime);
143  agx::Bool mergeCloseNodes();
144  agx::Bool mergeNodes(NodeMergePairHashVector& nodesToMerge);
145 
146  agx::Bool findWhichNodeToRemoveByMerge(ShapeContactNode* firstContact, ShapeContactNode* secondContact, const Node* prevNode, const Node* nextNode) const;
147 
148  agx::Bool isClamped(ShapeContactNode* cn);
149 
150  agx::Bool merge(ShapeContactNode* a, ShapeContactNode* b, Node* prevNode, Node* nextNode);
151 
152  void fixFreeEndContactPassings(WireDistanceCompositeConstraint* ldcc);
153  agx::Bool nearClampPosition(const ShapeContactNode* scn) const;
154  agx::Bool atClampPosition(const ShapeContactNode* scn) const;
155 
159  agx::Bool considerNewEdge(const ShapeContactNode* scn, const ShapeContactEdge& edge) const;
160 
167  void getNewNodeVelocities(agx::Bool integrate);
168 
169  void getAllContactNodes(WireDistanceCompositeConstraint* ldcc, agx::List<NodeIterator>& allContacts);
170  void getMovableContactNodes(const agx::List<NodeIterator>& allContacts, agx::List<NodeIterator>& contacts, agx::List<NodeIterator>& noMovementContacts);
171 
172  void analyzeCollision(NodeShapeSetVector& nodesToShapeList, agxCollide::GeometryContact& gc, agxCollide::Geometry* wireGeom, agxCollide::Geometry* otherGeom, SurfacePointVector& contactInfo );
173  void findRouteAroundMesh( agxCollide::Geometry* wireGeom, const agxCollide::GeometryContact& gc, const agx::Vector< agxCollide::MeshRef >& meshes);
174 
175  enum class EvaluationResult
176  {
177  IGNORE_POINT,
178  CREATE_NODE,
179  CREATE_GEOMETRY_CONTACT_PREV,
180  CREATE_GEOMETRY_CONTACT_NEXT
181  };
182 
183  EvaluationResult evaluate( const agxCollide::Shape* shape,
184  const agx::Vec3& nodePositionWorld,
185  const ShapeCurvature& worldCurvature,
186  const Node* prevNode,
187  const Node* nextNode,
188  const agx::Real& wireRadius,
189  const agx::Bool favorLumpSphereContacts = true ) const;
190  protected:
191  NodePtrGeometryContactVectorTable m_nodeGeometryContactTable;
193  agxCollide::LocalGeometryContactVector m_localGeometryContacts;
194  };
195 
196  typedef agx::ref_ptr< WireShapeContactController > WireShapeContactControllerRef;
197 }
198 
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:665
bool Bool
Definition: Integer.h:48
Base class for a shape.
Definition: Shape.h:53
agxCollide namespace consists of a set of classes for handling geometric intersection tests including...
A contact between two geometries.
Definition: Contacts.h:270
#define AGXPHYSICS_EXPORT
agx::Vector< GeometryContact > GeometryContactVector
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
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:102
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:101