AGXDynamics  2.35.0.3
Assembly.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 #pragma once
18 
19 #include <agx/agx.h>
20 #include <agx/RigidBody.h>
21 #include <agx/MergedBody.h>
22 #include <agxCollide/agxCollide.h>
23 #include <agxSDK/agxSDK.h>
24 
25 #include <agx/Frame.h>
26 #include <agxSDK/EventListener.h>
27 #include <agx/Constraint.h>
28 #include <agxCollide/Geometry.h>
29 #include <agx/ObserverFrame.h>
30 #include <agx/ParticleSystem.h>
31 #include <agxStream/Serializable.h>
32 #include <agx/SetVector.h>
33 #include <agx/DynamicsSystem.h>
34 
35 namespace agxSDK
36 {
38 
39  class AssemblyVisitor;
40 
66  class AGXPHYSICS_EXPORT Assembly : public virtual agx::Referenced, public virtual agxStream::Serializable
67  {
68  public:
70  Assembly();
71 
77  bool add(agx::Constraint* constraint);
78 
84  bool remove(agx::Constraint* constraint);
85 
91  bool add(agx::Interaction* interaction);
92 
98  bool remove(agx::Interaction* interaction);
99 
105  bool add(agxSDK::EventListener* listener);
106 
112  bool remove(EventListener* listener);
113 
119  bool add(agx::RigidBody* body);
120 
127  bool remove(agx::RigidBody* body, bool removeAssociatedGeometries = false);
128 
134  bool add(agxCollide::Geometry* geometry);
135 
141  bool remove(agxCollide::Geometry* geometry);
142 
148  bool add(Assembly* assembly);
149 
155  bool remove(Assembly* assembly);
156 
162  bool add(agx::ContactMaterial* contactMaterial);
163 
169  bool remove(agx::ContactMaterial* contactMaterial);
170 
176  bool add(agx::Emitter* emitter);
177 
183  bool remove(agx::Emitter* emitter);
184 
190  bool add(agx::ObserverFrame* observerFrame);
191 
197  bool remove(agx::ObserverFrame* observerFrame);
198 
199 
205  bool add(agx::MergedBody* mergedBody);
206 
212  bool remove(agx::MergedBody *mergedBody);
213 
220  bool add(agxStream::Serializable* object);
221 
222 
224 
231  agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true);
232 
239  const agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true) const;
240 
247  agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true);
248 
255  const agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true) const;
256 
263  const agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true) const;
264 
271  agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true);
272 
279  const agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true) const;
280 
287  agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true);
288 
295  const agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true) const;
296 
303  agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true);
304 
311  const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true) const;
312 
319  agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true);
320 
330  template < typename T >
331  T* getConstraint(const agx::Name& name, bool recursive = true);
332 
342  template < typename T >
343  const T* getConstraint(const agx::Name& name, bool recursive = true) const;
344 
351  const agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true) const;
352 
359  agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true);
360 
367  const agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true) const;
368 
375  agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true);
376 
377 
384  const agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true) const;
385 
392  agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true);
393 
400  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true) const;
401 
408  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true);
409 
416  const agx::MergedBody* getMergedBody (const agx::Uuid& uuid, bool recursive = true) const;
417 
424  agx::MergedBody* getMergedBody(const agx::Uuid& uuid, bool recursive = true);
425 
427 
431  virtual void traverse(AssemblyVisitor* visitor);
432  virtual void traverse(const AssemblyVisitor* visitor) const;
433 
437  const agx::RigidBodyRefSetVector& getRigidBodies() const;
441  const agxCollide::GeometryRefSetVector& getGeometries() const;
442 
446  const EventListenerRefSetVector& getEventListeners() const;
447 
451  const AssemblyRefSetVector& getAssemblies() const;
452 
456  const agx::ParticleSystemRefSetVector& getParticleSystems() const;
457 
461  const agx::EmitterRefSetVector& getEmitters() const;
462 
466  const agx::ConstraintRefSetVector& getConstraints() const;
467 
471  const agx::InteractionRefSetVector& getInteractions() const;
472 
476  const agx::ObserverFrameRefSetVector& getObserverFrames() const;
477 
481  const agx::MergedBodyRefSetVector& getMergedBodies() const;
482 
487  virtual agx::Frame* getFrame();
488  virtual const agx::Frame* getFrame() const;
489 
493  Assembly* getParent();
494 
498  const Assembly* getParent() const;
499 
505  void setTransform( const agx::AffineMatrix4x4& matrix );
506 
510  const agx::AffineMatrix4x4& getLocalTransform() const;
511 
516  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
517 
521  agx::Vec3 getLocalPosition() const;
522 
527  void setLocalPosition( const agx::Vec3& p );
528 
535  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
536 
541  void setRotation( const agx::Quat& q );
542 
547  void setRotation( const agx::EulerAngles& e);
548 
553  void setRotation( const agx::OrthoMatrix3x3& m );
554 
558  agx::Quat getLocalRotation() const;
559 
564  void setLocalRotation( const agx::Quat& q );
565 
570  void setLocalRotation( const agx::EulerAngles& e );
571 
575  agx::Frame* getParentFrame();
576 
580  const agx::Frame* getParentFrame() const;
581 
591  bool setParentFrame( agx::Frame* frame );
592 
597  void setPosition( const agx::Vec3& p );
598 
605  void setPosition( agx::Real x, agx::Real y, agx::Real z );
606 
608 
609 
613  virtual void addNotification(agxSDK::Simulation*) {}
614 
619 
623  virtual void addNotification(Assembly*) {}
624 
628  virtual void removeNotification(Assembly*) { }
629 
631  agxSDK::Simulation* getSimulation();
632 
634  const agxSDK::Simulation* getSimulation() const;
635 
640  virtual void setVelocity(const agx::Vec3& velocity);
641 
646  virtual void setAngularVelocity(const agx::Vec3& velocity);
647 
649  enum Type {
651  COLLECTION
652  };
653 
655  Type getType() const;
656 
661  void setName(const agx::Name& name);
662 
664  agx::Name getName() const;
665 
666  agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint1DOF>(name, recursive); }
667  agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint2DOF>(name, recursive); }
668 
670  static Assembly* asAssembly(agxStream::Serializable *obj) { return dynamic_cast<Assembly *>(obj); }
671 
672  public:
674 
675  protected:
676 
677 
682  bool addParticleSystem(agx::ParticleSystem* particleSystem);
683 
687  bool removeParticleSystem(agx::ParticleSystem* particleSystem);
688 
689 
690  Assembly(Type type);
691 
693  virtual ~Assembly();
694  friend class Simulation;
695 
696  void addToSimulation(Simulation* simulation);
697  void removeFromSimulation(Simulation* simulation);
698 
699  private:
700 
701  agx::FrameRef m_frame;
702 
705  agx::ConstraintRefSetVector m_constraints;
706  agx::EmitterRefSetVector m_emitters;
707  EventListenerRefSetVector m_listeners;
708  agxSDK::Simulation* m_simulation;
709  agx::InteractionRefSetVector m_interactions;
710 
711  agx::ContactMaterialRefSetVector m_contactMaterials;
712  agx::ParticleSystemRefSetVector m_particleSystems;
713 
714  AssemblyRefSetVector m_assemblies;
715  AssemblyObserver m_parent;
716 
717  agx::ObserverFrameRefSetVector m_observers;
718  agx::MergedBodyRefSetVector m_mergedBodies;
719 
720  Type m_type;
721  agx::Name m_name;
722  };
723 
724 
726  {
727  return m_frame.get();
728  }
729 
730  inline const agx::Frame* Assembly::getFrame() const
731  {
732  return m_frame.get();
733  }
734 
744  {
745  public:
746 
748  bool succeed() const;
749 
750  // Constructor
751  AssemblyVisitor();
752  virtual ~AssemblyVisitor();
753 
754  protected:
755 
756  friend class Assembly;
757  virtual void visit(agx::Constraint*) {}
758  virtual void visit(agx::Interaction*) {}
759  virtual void visit(agx::RigidBody*) {}
760  virtual void visit(agxCollide::Geometry*) {}
761  virtual void visit(Assembly*);
762  virtual void visit(EventListener*) {}
763  virtual void visit(agx::ContactMaterial*) {}
764  virtual void visit(agx::ParticleSystem*) {}
765  virtual void visit(agx::Emitter*) {}
766  virtual void visit(agx::ObserverFrame*) {}
767  virtual void visit(agx::MergedBody*) {}
768 
769  virtual void visit(const agx::Constraint*) const {}
770  virtual void visit(const agx::Interaction*) const {}
771  virtual void visit(const agx::RigidBody*) const {}
772  virtual void visit(const agxCollide::Geometry*) const {}
773  virtual void visit(const Assembly*)const;
774  virtual void visit(const EventListener*) const {}
775  virtual void visit(const agx::ContactMaterial*) const {}
776  virtual void visit(const agx::ParticleSystem*) const {}
777  virtual void visit(const agx::Emitter*) const {}
778  virtual void visit(const agx::ObserverFrame*) const {}
779  virtual void visit(const agx::MergedBody*) const {}
780 
781  void setSucceed(bool flag) {
782  m_succeed = flag;
783  }
784 
785  bool m_succeed;
786  };
787 
788 
789 
790  /* Implementation */
791 
792 
793  template< typename T >
794  T* Assembly::getConstraint(const agx::Name& name, bool recursive)
795  {
796  return dynamic_cast< T* >(this->getConstraint(name, recursive));
797  }
798 
799  template< typename T >
800  const T* Assembly::getConstraint(const agx::Name& name, bool recursive) const
801  {
802  return dynamic_cast< const T* >(this->getConstraint(name, recursive));
803  }
804 
805 
806 }
agxSDK::AssemblyVisitor::visit
virtual void visit(const EventListener *) const
Definition: Assembly.h:774
agx::Real
double Real
Definition: Real.h:42
EventListener.h
agx::OrthoMatrix3x3
Specialized types of matrices for holding orthogonal transformation matrices.
Definition: OrthoMatrix3x3.h:33
agx::Constraint1DOF
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:676
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
agx::Constraint2DOF
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:761
agxData::getType
AGXCORE_EXPORT Type * getType(const agx::String &name)
agxSDK::Assembly::removeNotification
virtual void removeNotification(Assembly *)
Called when this assembly is removed from another assembly.
Definition: Assembly.h:628
agxSDK::EventListener
An EventListener can be associated to a Simulation and triggered upon various events.
Definition: EventListener.h:40
Constraint.h
Geometry.h
agxSDK::AssemblyVisitor::visit
virtual void visit(agxCollide::Geometry *)
Definition: Assembly.h:760
agx::AffineMatrix4x4T< Real >
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::ObserverFrame *)
Definition: Assembly.h:766
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::ContactMaterial *) const
Definition: Assembly.h:775
agxSDK::Assembly::getConstraint
const agx::Constraint * getConstraint(const agx::Uuid &uuid, bool recursive=true) const
Find (linear search) and return a pointer to a Constraint with the given uuid.
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::ParticleSystem *)
Definition: Assembly.h:764
agxSDK::AssemblyVisitor::m_succeed
bool m_succeed
Definition: Assembly.h:785
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::ObserverFrame *) const
Definition: Assembly.h:778
agxSDK::AssemblyVisitor::visit
virtual void visit(EventListener *)
Definition: Assembly.h:762
ParticleSystem.h
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agxSDK::Assembly::getConstraint1DOF
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:666
agx::observer_ptr< Assembly >
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::RigidBody *)
Definition: Assembly.h:759
agxSDK::AssemblyVisitor
Class for visiting all elements in a tree of Assemblies.
Definition: Assembly.h:743
agxSDK::AssemblyVisitor::visit
virtual void visit(const agxCollide::Geometry *) const
Definition: Assembly.h:772
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Constraint *)
Definition: Assembly.h:757
agxSDK::Assembly
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:66
agxSDK::Assembly::getFrame
virtual agx::Frame * getFrame()
Return a reference to the frame containing transformation and velocity information for this assembly.
Definition: Assembly.h:725
agx::ObserverFrame
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:43
agxSDK::Assembly::Type
Type
Specifies the type an assembly is.
Definition: Assembly.h:649
agx::ParticleSystem
A basic particle system that contains all the storages and buffers required for basic operation and a...
Definition: ParticleSystem.h:67
agx::ref_ptr< Frame >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agxSDK::Assembly::addNotification
virtual void addNotification(Assembly *)
Called when this assembly is added to another assembly.
Definition: Assembly.h:623
agx::SetVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
MergedBody.h
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::MergedBody *) const
Definition: Assembly.h:779
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::ContactMaterial *)
Definition: Assembly.h:763
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::ParticleSystem *) const
Definition: Assembly.h:776
agxSDK::AssemblyRefSetVector
agx::SetVector< agx::ref_ptr< agxSDK::Assembly > > AssemblyRefSetVector
Definition: Assembly.h:37
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
agxSDK::Assembly::ASSEMBLY
@ ASSEMBLY
This is a full fledged Assembly which uses Frame for the hierarchy.
Definition: Assembly.h:650
agx::ContactMaterial
This class store the combine material properties between two agx::Material's.
Definition: Material.h:527
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::Interaction *) const
Definition: Assembly.h:770
agx::Name
Representation of a name string.
Definition: Name.h:32
Frame.h
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::Emitter *) const
Definition: Assembly.h:777
Serializable.h
agx::EulerAngles
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
agx::QuatT< Real >
agxCollide.h
agx.h
RigidBody.h
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::Constraint *) const
Definition: Assembly.h:769
agx::Interaction
The base class for interactions.
Definition: Interaction.h:31
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:113
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
agxSDK::Assembly::asAssembly
static Assembly * asAssembly(agxStream::Serializable *obj)
Definition: Assembly.h:670
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::MergedBody *)
Definition: Assembly.h:767
agx::Constraint
The base class for a constraint.
Definition: Constraint.h:88
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Emitter *)
Definition: Assembly.h:765
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::RigidBody *) const
Definition: Assembly.h:771
ObserverFrame.h
agxSDK::AssemblyVisitor::setSucceed
void setSucceed(bool flag)
Definition: Assembly.h:781
agxSDK
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
AGX_ADD_FRAME_TRANSFORM_INTERFACE
#define AGX_ADD_FRAME_TRANSFORM_INTERFACE()
Definition: Frame.h:690
agx::Vec3T< Real >
agx::Uuid
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
DynamicsSystem.h
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agx::MergedBody
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:55
agx::Emitter
Spawns new bodys inside a given volume.
Definition: Emitter.h:44
agxSDK::Assembly::getConstraint2DOF
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:667
agxStream::ElementTypes::Type
Type
Definition: Types.h:37
agxSDK::Assembly::removeNotification
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:618
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Interaction *)
Definition: Assembly.h:758
agxSDK.h
agx::ref_ptr::get
T * get() const
Definition: ref_ptr.h:256
SetVector.h