AGXDynamics  2.35.0.2
agxModel/Tree.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 #ifndef AGXMODEL_TREE_H
18 #define AGXMODEL_TREE_H
19 
20 #include <agxModel/export.h>
21 #include <agxSDK/Assembly.h>
24 
25 #include <agx/LockJoint.h>
26 #include <agx/HashVector.h>
27 
28 #include <agxCollide/Cylinder.h>
29 #include <agxCollide/Capsule.h>
30 
31 namespace agxModel
32 {
39  {
40  public:
41  class Branch;
42 
47  typedef BranchContainer::const_iterator BranchConstIterator;
50 
55  {
56  public:
57  enum MaxLoadType { TRANSLATIONAL = 0, ROTATIONAL };
58 
59  public:
66  Branch( const agx::Vec3& start, const agx::Vec3& end );
67 
74 
81  bool addBranch( agxModel::Tree::Branch* branch );
82 
88  bool removeBranch( agxModel::Tree::Branch* branch );
89 
95  bool removeBranch( size_t index );
96 
100  size_t getNumBranches() const;
101 
105  agxModel::Tree::Branch* getBranch( size_t i ) const;
106 
112  void setCustomData( agx::Referenced* customData );
113 
117  agx::Referenced* getCustomData() const;
118 
122  agxModel::Tree::Branch* getParent() const;
123 
127  agx::RigidBody* getRigidBody() const;
128 
132  agx::Constraint* getConstraint() const;
133 
137  agx::Vec3 getDirection() const;
138 
142  agx::Vec3 getLocalDirection() const;
143 
151  void setMaxLoad( agx::Real translational, agx::Real rotational );
152 
157  void setMaxTranslationalLoad( agx::Real maxLoad );
158 
163  void setMaxRotationalLoad( agx::Real maxLoad );
164 
169  agx::Vec2 getMaxLoad() const;
170 
174  agx::Real getMaxTranslationalLoad() const;
175 
179  agx::Real getMaxRotationalLoad() const;
180 
185  agx::Vec2 getCurrentLoad() const;
186 
190  agx::Real getCurrentTranslationalLoad() const;
191 
195  agx::Real getCurrentRotationalLoad() const;
196 
197  public:
204  virtual agx::Real getLength( const agxCollide::Geometry* geometry ) const;
205 
221  virtual agxCollide::Shape* splitShape( agxCollide::Shape* shapeInBranch, agx::Real shapePosition, agxModel::Tree::Branch* newBranch, agx::Real& newBelowLength, agx::Real& newAboveLength );
222 
227  virtual agx::ConstraintRef createConstraintWithParent() const;
228 
232  virtual agxModel::Tree::Branch* clone();
233 
234  protected:
235  virtual ~Branch();
236 
241  void setParent( agxModel::Tree::Branch* parent );
242 
243  friend class Tree;
248  void setConstraint( agx::Constraint* constraint );
249 
250  protected:
254 
258  };
259 
264  {
265  public:
271 
277  virtual void onCreate( agxModel::Tree::Branch* branch );
278 
283  virtual void onHighLoad( agxModel::Tree::Branch* branch );
284 
289  virtual agxModel::Tree::BranchEventListener* clone() = 0;
290 
291  protected:
292  virtual ~BranchEventListener();
293 
297  Tree* getTree() const;
298 
299  private:
300  friend class Tree;
301  void setTree( Tree* tree );
302 
303  private:
305  };
306 
308 
313  {
314  public:
317 
322  virtual bool match( const agxCollide::GeometryContact& contact ) const override;
323 
328  virtual bool match( const agxCollide::GeometryPair& pair ) const override;
330 
334  virtual agxModel::Tree::TreeExecuteFilter* clone();
335 
336  protected:
337  virtual ~TreeExecuteFilter();
338  agx::UInt32 getTreeID() const;
339 
340  private:
341  friend class Tree;
342  agx::UInt32 m_treeID;
343  };
344 
346 
347  enum State { INITIALIZED = (1<<0), STATIC = (1<<1), WAKE_ON_CONTACT = (1<<2) };
348 
349  public:
351  Tree();
352 
358  virtual Tree* clone();
359 
363  Branch* getRoot() const;
364 
368  bool initialized() const;
369 
375  virtual bool initialize();
376 
380  bool isStatic() const;
381 
385  bool wakeOnContact() const;
386 
399  bool makeStatic( bool wakeOnContactEvent, agxModel::Tree::TreeExecuteFilter* filter
400 #ifndef SWIG
401  // SWIG cannot handle default arguments with the new keyword, at the moment.
403 #endif
404  );
405 
411  bool makeDynamic();
412 
417  virtual void setBranchEventListener( agxModel::Tree::BranchEventListener* branchListener );
418 
422  agxModel::Tree::BranchEventListener* getBranchEventListener() const;
423 
431  virtual bool attach( agx::RigidBody* rb, agx::Frame* frame );
432 
438  bool addGroupID( agx::UInt32 id );
439 
445  bool removeGroupID( agx::UInt32 id );
446 
450  bool hasGroupID( agx::UInt32 id ) const;
451 
458  bool setEnableCollisions( agx::RigidBody* rb, bool flag );
459 
466  bool setEnableCollisions( agxCollide::Geometry* geometry, bool flag );
467 
471  bool getEnableCollisions( const agx::RigidBody* rb ) const;
472 
476  bool getEnableCollisions( const agxCollide::Geometry* geometry ) const;
477 
482  void setCustomData( agx::Referenced* customData );
483 
487  agx::Referenced* getCustomData() const;
488 
493  virtual void setMaterial( agx::Material* material );
494 
498  agx::Material* getMaterial() const;
499 
505  virtual void setConstraintSolveType( agx::Constraint::SolveType solveType );
506 
523  virtual Tree* cut( agxCollide::Geometry* geometry, const agx::Vec3& point, agx::Real minShapeHeight = agx::Real( 1E-2 ) );
524 
531  virtual Tree* cut( agxModel::Tree::Branch* branch );
532 
548  virtual Branch* split( agxCollide::Geometry* geometry, const agx::Vec3& point, agx::Real minShapeHeight = agx::Real( 1E-2 ) );
549 
553  static void setDefaultParameters( agx::Material* material );
554 
560  Branch* findBranch( const agx::RigidBody* rb ) const;
561 
568  Branch* findBranch( const agxModel::Tree::Branch* fromBranch, const agx::RigidBody* rb ) const;
569 
573  virtual void clear();
574 
584  static void setLinearVelocityDamping( agxModel::Tree::Branch* branch, const agx::Vec3& linearVelocityDamping );
585 
595  static void setAngularVelocityDamping( agxModel::Tree::Branch* branch, const agx::Vec3& angularVelocityDamping );
596 
597  protected:
599  virtual ~Tree();
600 
601  virtual void addNotification( agxSDK::Simulation* simulation );
603  virtual void removeNotification( agxSDK::Simulation* simulation );
605 
609  virtual void preCollide();
610 
614  virtual void pre();
615 
619  virtual void post();
620 
625  void configure( Branch* branch );
626 
632  void addGroupID( Branch* branch, agx::UInt32 id );
633 
639  void removeGroupID( Branch* branch, agx::UInt32 id );
640 
646  void simplify( Branch* branch, bool flag, agxSDK::Simulation* simulation );
647 
652  virtual void checkLoad( Branch* branch );
653 
657  void split( Branch* source, Branch* destination ) const;
658 
659  using agxSDK::Assembly::add;
661 
665  void remove( Branch* branch );
666 
671  void add( Branch* branch );
672 
678  void setMaterial( Branch* branch, agx::Material* material );
679 
685  void setConstraintSolveType( Branch* branch, agx::Constraint::SolveType solveType );
686 
690  void copyParameters( const Branch* source, Branch* destination ) const;
691 
695  void copyParameters( const agx::Constraint* source, agx::Constraint* destination ) const;
696 
701  Branch* guessConnectingChild( Branch* branch ) const;
702 
703  protected:
705  {
706  public:
708  : m_tree( tree ) { setMask( IMPACT ); }
709 
710  protected:
712 
713  virtual KeepContactPolicy impact( const agx::TimeStamp&, agxCollide::GeometryContact* );
714 
715  protected:
717  };
718 
720 
722  {
723  public:
725  : m_tree( tree ) { setMask( PRE_COLLIDE | PRE_STEP | POST_STEP ); }
726 
727  protected:
729 
730  virtual void preCollide( const agx::TimeStamp& ) override;
731  virtual void pre( const agx::TimeStamp& ) override;
732  virtual void post( const agx::TimeStamp& ) override;
733 
734  protected:
736  };
737 
739 
740  protected:
742  int m_state;
752  };
753 
755 
756  template< typename T >
757  T* cutShape( T* shape, agx::Real position, agx::Real& newBelowLength, agx::Real& newAboveLength )
758  {
759  agx::Real oldLength = shape->getHeight();
760  newBelowLength = agx::Real( 0.5 ) * oldLength + position;
761  newAboveLength = oldLength - newBelowLength;
762  if ( newBelowLength < 0 || newAboveLength < 0 )
763  return nullptr;
764  shape->setHeight( newBelowLength );
765  return new T( shape->getRadius(), newAboveLength );
766  }
767 
768  AGXMODEL_EXPORT agxCollide::Shape* cutShape( agxCollide::Shape* shape, agx::Real position, agx::Real& newBelowLength, agx::Real& newAboveLength );
771 }
772 
773 #endif // AGXMODEL_TREE_H
agxModel::Tree::BranchEventListener
BranchEventListener handles certain events happening to a Tree.
Definition: agxModel/Tree.h:263
agxModel::Tree::TreeContactEventListenerRef
agx::ref_ptr< TreeContactEventListener > TreeContactEventListenerRef
Definition: agxModel/Tree.h:719
agx::end
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)
Definition: LinearProbingHashSet.h:612
agxModel::Tree::TreeStepEventListenerRef
agx::ref_ptr< TreeStepEventListener > TreeStepEventListenerRef
Definition: agxModel/Tree.h:738
agxModel::cutShape
T * cutShape(T *shape, agx::Real position, agx::Real &newBelowLength, agx::Real &newAboveLength)
Definition: agxModel/Tree.h:757
Cylinder.h
agx::Real
double Real
Definition: Real.h:42
agxSDK::ExecuteFilter::match
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Definition: ExecuteFilter.h:110
agxModel::Tree::m_customData
agx::ref_ptr< agx::Referenced > m_customData
Definition: agxModel/Tree.h:747
agxModel
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
agxData::transform
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
agxData::GeometryPair
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:66
agxModel::Tree::DisabledCollisionsGeometryContainer
agx::HashVector< agxCollide::Geometry *, agx::observer_ptr< agxCollide::Geometry > > DisabledCollisionsGeometryContainer
Definition: agxModel/Tree.h:48
agx::Vector< BranchRef >
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agxModel::Tree::Branch::MaxLoadType
MaxLoadType
Definition: agxModel/Tree.h:57
agxModel::Tree::BranchConstIterator
BranchContainer::const_iterator BranchConstIterator
Definition: agxModel/Tree.h:47
export.h
HashVector.h
agx::AffineMatrix4x4T< Real >
agxSDK::ExecuteFilter
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:34
agxModel::Tree::Branch::m_customData
agx::ref_ptr< agx::Referenced > m_customData
Definition: agxModel/Tree.h:253
Assembly.h
agxModel::Tree::TreeContactEventListener::~TreeContactEventListener
virtual ~TreeContactEventListener()
Definition: agxModel/Tree.h:711
agxModel::Tree::BranchIterator
BranchContainer::iterator BranchIterator
Definition: agxModel/Tree.h:46
agx::Vector< BranchRef >::iterator
BranchRef * iterator
Definition: Vector.h:62
agxModel::Tree::GroupIdContainer
agx::SetVector< agx::UInt32 > GroupIdContainer
Definition: agxModel/Tree.h:49
agxModel::Tree::Branch::m_maxLoad
agx::Vec2 m_maxLoad
Definition: agxModel/Tree.h:257
StepEventListener.h
agxSDK::Assembly::remove
bool remove(agx::Constraint *constraint)
Remove a constraint from this assembly (does not recurse down in tree).
agx::observer_ptr< Branch >
agxModel::Tree::TreeStepEventListener::TreeStepEventListener
TreeStepEventListener(Tree *tree)
Definition: agxModel/Tree.h:724
agxModel::Tree::m_geometryIDs
GroupIdContainer m_geometryIDs
Definition: agxModel/Tree.h:746
agxModel::Tree::m_material
agx::MaterialRef m_material
Definition: agxModel/Tree.h:748
agxModel::Tree::TreeStepEventListener::~TreeStepEventListener
virtual ~TreeStepEventListener()
Definition: agxModel/Tree.h:728
agxModel::Tree::m_stepListener
TreeStepEventListenerRef m_stepListener
Definition: agxModel/Tree.h:751
agxModel::Tree::BranchEventListenerRef
agx::ref_ptr< BranchEventListener > BranchEventListenerRef
Definition: agxModel/Tree.h:307
agxSDK::Assembly
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:66
agx::ref_ptr< Branch >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
agx::SetVector< agx::UInt32 >
agxModel::Tree::TreeContactEventListener::TreeContactEventListener
TreeContactEventListener(Tree *tree)
Definition: agxModel/Tree.h:707
agxSDK::Assembly::add
bool add(agx::Constraint *constraint)
Add a constraint to the assembly.
agxModel::Tree::m_wakeOnContactListener
TreeContactEventListenerRef m_wakeOnContactListener
Definition: agxModel/Tree.h:750
agxModel::Tree
Tree is a structure of Branch objects in a mathematical Tree structure where a Branch can have severa...
Definition: agxModel/Tree.h:38
agxUtil::setEnableCollisions
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2.
agxModel::Tree::TreeStepEventListener
Definition: agxModel/Tree.h:721
agxModel::Tree::BranchObs
agx::observer_ptr< Branch > BranchObs
Definition: agxModel/Tree.h:44
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agxModel::Tree::m_disabledCollisionsID
agx::UInt32 m_disabledCollisionsID
Definition: agxModel/Tree.h:744
agx::Vec2T
Definition: Vec2Template.h:30
agxModel::getShapeRadius
AGXMODEL_EXPORT agx::Real getShapeRadius(const agxCollide::Shape *shape)
LockJoint.h
agxModel::Tree::TreeExecuteFilterRef
agx::ref_ptr< TreeExecuteFilter > TreeExecuteFilterRef
Definition: agxModel/Tree.h:345
agx::root
AGXCORE_EXPORT Component * root()
agxModel::Tree::State
State
Definition: agxModel/Tree.h:347
agxModel::Tree::m_root
BranchRef m_root
Definition: agxModel/Tree.h:741
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
ContactEventListener.h
agxModel::Tree::Branch
Branch is a part of the Tree, with a body and a constraint to its parent.
Definition: agxModel/Tree.h:54
agxModel::Tree::BranchRef
agx::ref_ptr< Branch > BranchRef
Definition: agxModel/Tree.h:41
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:269
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
agxModel::TreeRef
agx::ref_ptr< Tree > TreeRef
Definition: agxModel/Tree.h:754
agxModel::Tree::TreeExecuteFilter
TreeExecuteFilter allows to catch contacts with the Tree.
Definition: agxModel/Tree.h:312
agxModel::Tree::Branch::m_constraint
agx::ConstraintRef m_constraint
Definition: agxModel/Tree.h:256
agx::Constraint
The base class for a constraint.
Definition: Constraint.h:88
agxModel::Tree::TreeContactEventListener
Definition: agxModel/Tree.h:704
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agx::Constraint::SolveType
SolveType
Specifies in what solvers the constraint will be solved.
Definition: Constraint.h:92
agxModel::Tree::m_externalDisabledGeometries
DisabledCollisionsGeometryContainer m_externalDisabledGeometries
Definition: agxModel/Tree.h:745
agx::Material
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:387
agx::Vec3T< Real >
agxModel::Tree::TreeContactEventListener::m_tree
agx::observer_ptr< Tree > m_tree
Definition: agxModel/Tree.h:716
agxTerrain::Profiler::clear
AGXTERRAIN_EXPORT void clear()
agxModel::Tree::m_geometriesID
agx::UInt32 m_geometriesID
Definition: agxModel/Tree.h:743
agx::UInt32
uint32_t UInt32
Definition: Integer.h:40
agxModel::Tree::Branch::m_parent
BranchObs m_parent
Definition: agxModel/Tree.h:251
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
Capsule.h
agxModel::Tree::Branch::m_rb
agx::RigidBodyRef m_rb
Definition: agxModel/Tree.h:255
agx::HashVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
agxModel::Tree::m_state
int m_state
Definition: agxModel/Tree.h:742
agxModel::Tree::TreeStepEventListener::m_tree
agx::observer_ptr< Tree > m_tree
Definition: agxModel/Tree.h:735
agxSDK::Assembly::removeNotification
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:618
agxModel::Tree::m_branchListener
BranchEventListenerRef m_branchListener
Definition: agxModel/Tree.h:749
agxModel::getShapeLength
AGXMODEL_EXPORT agx::Real getShapeLength(const agxCollide::Shape *shape)
agxModel::Tree::Branch::m_branches
BranchContainer m_branches
Definition: agxModel/Tree.h:252
agxModel::Tree::BranchContainer
agx::Vector< BranchRef > BranchContainer
Definition: agxModel/Tree.h:45
agxSDK::ContactEventListener
Derive from this class to implement a listener for Collision events.
Definition: ContactEventListener.h:44
agxSDK::Assembly::addNotification
virtual void addNotification(agxSDK::Simulation *)
Called when this assembly is added to a simulation (given that it not already is in the simulation).
Definition: Assembly.h:613