AGX Dynamics  2.35.0.1
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:
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 
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 
442 
447 
452 
457 
462 
467 
472 
477 
482 
487  virtual agx::Frame* getFrame();
488  virtual const agx::Frame* getFrame() const;
489 
494 
498  const Assembly* getParent() const;
499 
505  void setTransform( const agx::AffineMatrix4x4& matrix );
506 
511 
517 
522 
527  void setLocalPosition( const agx::Vec3& p );
528 
536 
541  void setRotation( const agx::Quat& q );
542 
547  void setRotation( const agx::EulerAngles& e);
548 
554 
559 
564  void setLocalRotation( const agx::Quat& q );
565 
571 
576 
580  const agx::Frame* getParentFrame() const;
581 
591  bool setParentFrame( agx::Frame* frame );
592 
597  void setPosition( const agx::Vec3& p );
598 
606 
608 
609 
613  virtual void addNotification(agxSDK::Simulation*) {}
614 
619 
623  virtual void addNotification(Assembly*) {}
624 
628  virtual void removeNotification(Assembly*) { }
629 
632 
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 
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 
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
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 }
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
#define AGXPHYSICS_EXPORT
#define AGX_ADD_FRAME_TRANSFORM_INTERFACE()
Definition: agx/Frame.h:690
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Class for visiting all elements in a tree of Assemblies.
Definition: Assembly.h:744
virtual void visit(const agx::Constraint *) const
Definition: Assembly.h:769
virtual void visit(const agx::ParticleSystem *) const
Definition: Assembly.h:776
virtual void visit(agxCollide::Geometry *)
Definition: Assembly.h:760
virtual void visit(agx::ContactMaterial *)
Definition: Assembly.h:763
virtual void visit(const agx::MergedBody *) const
Definition: Assembly.h:779
virtual void visit(const agxCollide::Geometry *) const
Definition: Assembly.h:772
virtual void visit(const EventListener *) const
Definition: Assembly.h:774
virtual void visit(agx::Emitter *)
Definition: Assembly.h:765
virtual void visit(const agx::ContactMaterial *) const
Definition: Assembly.h:775
virtual void visit(agx::ParticleSystem *)
Definition: Assembly.h:764
virtual void visit(const agx::Emitter *) const
Definition: Assembly.h:777
virtual void visit(const agx::Interaction *) const
Definition: Assembly.h:770
virtual void visit(agx::ObserverFrame *)
Definition: Assembly.h:766
virtual void visit(agx::Interaction *)
Definition: Assembly.h:758
virtual void visit(const Assembly *) const
virtual void visit(const agx::ObserverFrame *) const
Definition: Assembly.h:778
virtual void visit(agx::Constraint *)
Definition: Assembly.h:757
virtual void visit(const agx::RigidBody *) const
Definition: Assembly.h:771
virtual void visit(Assembly *)
void setSucceed(bool flag)
Definition: Assembly.h:781
virtual void visit(agx::MergedBody *)
Definition: Assembly.h:767
virtual void visit(agx::RigidBody *)
Definition: Assembly.h:759
virtual void visit(EventListener *)
Definition: Assembly.h:762
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
virtual agx::Frame * getFrame()
Return a reference to the frame containing transformation and velocity information for this assembly.
Definition: Assembly.h:725
virtual void setVelocity(const agx::Vec3 &velocity)
Set the linear velocity (in world frame) recursively for all rigid bodies stored in assembly.
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:666
static Assembly * asAssembly(agxStream::Serializable *obj)
Definition: Assembly.h:670
const agxCollide::Geometry * getGeometry(const agx::Uuid &uuid, bool recursive=true) const
Find (linear search) and return a Geometry matching the given uuid.
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:667
const agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid, bool recursive=true) const
Find (linear search) and return an ObserverFrame matching the given uuid.
bool remove(EventListener *listener)
Remove an EventListener from the assembly.
bool removeParticleSystem(agx::ParticleSystem *particleSystem)
Remove a particle system from this assembly.
agx::Vec3 getLocalPosition() const
bool add(agxSDK::EventListener *listener)
Add a listener to the assembly.
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:618
const agxCollide::Geometry * getGeometry(const agx::Name &name, bool recursive=true) const
Find (linear search) and return named collision Geometry.
void setPosition(agx::Real x, agx::Real y, agx::Real z)
Set the position of the frame in world coordinates.
virtual void traverse(const AssemblyVisitor *visitor) const
bool add(agxCollide::Geometry *geometry)
Add a geometry to the assembly.
const agx::ParticleSystemRefSetVector & getParticleSystems() const
const agxCollide::GeometryRefSetVector & getGeometries() const
void removeFromSimulation(Simulation *simulation)
agx::RigidBody * getRigidBody(const agx::Name &name, bool recursive=true)
Find (linear search) and return named RigidBody.
agxCollide::Geometry * getGeometry(const agx::Name &name, bool recursive=true)
Find (linear search) and return named collision Geometry.
const agx::MergedBody * getMergedBody(const agx::Uuid &uuid, bool recursive=true) const
Find (linear search) and return an MergedBody matching the given uuid.
bool add(agx::ObserverFrame *observerFrame)
Add an ObserverFrame to this assembly.
Assembly()
Default constructor.
agxSDK::Assembly * getAssembly(const agx::Name &name, bool recursive=true)
Find (linear search) and return named Assembly.
void setRotation(const agx::EulerAngles &e)
Set the rotation of the assembly relative to world frame.
const AssemblyRefSetVector & getAssemblies() const
agx::MergedBody * getMergedBody(const agx::Uuid &uuid, bool recursive=true)
Find (linear search) and return an MergedBody matching the given uuid.
void setPosition(const agx::Vec3 &p)
Set the position of the frame in world coordinates.
const agx::ObserverFrame * getObserverFrame(const agx::Name &name, bool recursive=true) const
Find (linear search) and return an ObserverFrame matching the given uuid.
bool remove(agx::MergedBody *mergedBody)
Remove a MergedBody from this assembly.
void setLocalPosition(agx::Real x, agx::Real y, agx::Real z)
Set the position of the assembly relative to its frame's parent frame.
bool remove(agxCollide::Geometry *geometry)
Remove a geometry from this assembly (does not recurse down in tree).
const agxSDK::Assembly * getAssembly(const agx::Uuid &uuid, bool recursive=true) const
Find (linear search) and return an Assembly matching the given uuid.
bool add(agxStream::Serializable *object)
Add an object of type serialized.
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.
agxCollide::Geometry * getGeometry(const agx::Uuid &uuid, bool recursive=true)
Find (linear search) and return a Geometry matching the given uuid.
agx::Name getName() const
const Assembly * getParent() const
virtual ~Assembly()
Destructor.
void setName(const agx::Name &name)
Set the name of this Assembly.
agx::ObserverFrame * getObserverFrame(const agx::Name &name, bool recursive=true)
Find (linear search) and return an ObserverFrame matching the given uuid.
virtual void setAngularVelocity(const agx::Vec3 &velocity)
Set the angular velocity (in world frame) recursively for all rigid bodies stored in assembly.
bool addParticleSystem(agx::ParticleSystem *particleSystem)
Add a particle system to this assembly.
bool add(agx::RigidBody *body)
Add a rigid body to the assembly.
bool add(agx::Constraint *constraint)
Add a constraint to the assembly.
bool remove(agx::RigidBody *body, bool removeAssociatedGeometries=false)
Remove a rigid body from this assembly (does not recurse down in tree).
agx::Frame * getParentFrame()
virtual void traverse(AssemblyVisitor *visitor)
Traverse the assembly tree recursively using a visitor.
void setLocalTransform(const agx::AffineMatrix4x4 &matrix)
Assign the local transformation matrix for this assembly, ignoring any eventual parent transformation...
bool remove(agx::Emitter *emitter)
Remove an emitter from this assembly.
const agx::AffineMatrix4x4 & getLocalTransform() const
void setLocalRotation(const agx::EulerAngles &e)
Set the rotation of the assembly relative to its frame's parent frame.
bool add(agx::ContactMaterial *contactMaterial)
Add a contact material to this assembly.
agxSDK::Assembly * getAssembly(const agx::Uuid &uuid, bool recursive=true)
Find (linear search) and return an Assembly matching the given uuid.
const agx::Frame * getParentFrame() const
const agx::Constraint * getConstraint(const agx::Name &name, bool recursive=true) const
Find (linear search) and return named Constraint.
Type getType() const
const agx::ObserverFrameRefSetVector & getObserverFrames() const
const agxSDK::Simulation * getSimulation() const
const agx::RigidBody * getRigidBody(const agx::Uuid &uuid, bool recursive=true) const
Find (linear search) and return a pointer to a RigidBody with the given uuid.
agx::RigidBody * getRigidBody(const agx::Uuid &uuid, bool recursive=true)
Find (linear search) and return a pointer to a RigidBody with the given uuid.
agx::Constraint * getConstraint(const agx::Uuid &uuid, bool recursive=true)
Find and return a pointer to a Constraint with the given uuid.
const agx::ConstraintRefSetVector & getConstraints() const
const agx::InteractionRefSetVector & getInteractions() const
bool remove(agx::Interaction *interaction)
Remove an interaction from this assembly.
void setLocalPosition(const agx::Vec3 &p)
Set the position of the assembly relative to its frame's parent frame.
agx::Quat getLocalRotation() const
bool remove(Assembly *assembly)
Remove a child assembly from a parent.
const agx::RigidBodyRefSetVector & getRigidBodies() const
virtual void addNotification(Assembly *)
Called when this assembly is added to another assembly.
Definition: Assembly.h:623
virtual void removeNotification(Assembly *)
Called when this assembly is removed from another assembly.
Definition: Assembly.h:628
void addToSimulation(Simulation *simulation)
bool remove(agx::Constraint *constraint)
Remove a constraint from this assembly (does not recurse down in tree).
bool add(agx::Interaction *interaction)
Add an interaction to this assembly.
bool remove(agx::ObserverFrame *observerFrame)
Remove an ObserverFrame from this assembly.
Type
Specifies the type an assembly is.
Definition: Assembly.h:649
@ ASSEMBLY
This is a full fledged Assembly which uses Frame for the hierarchy.
Definition: Assembly.h:650
Assembly(Type type)
agxSDK::Simulation * getSimulation()
agx::Constraint * getConstraint(const agx::Name &name, bool recursive=true)
Find (linear search) and return named Constraint.
bool remove(agx::ContactMaterial *contactMaterial)
Remove a contact material from this assembly.
const agx::MergedBodyRefSetVector & getMergedBodies() const
bool add(Assembly *assembly)
Add another assembly as child to this assembly.
void setRotation(const agx::OrthoMatrix3x3 &m)
Set the rotation of the assembly relative to world frame.
agx::ObserverFrame * getObserverFrame(const agx::Uuid &uuid, bool recursive=true)
Find (linear search) and return an ObserverFrame matching the given uuid.
const EventListenerRefSetVector & getEventListeners() const
bool add(agx::MergedBody *mergedBody)
Add a MergedBody to this assembly.
const agxSDK::Assembly * getAssembly(const agx::Name &name, bool recursive=true) const
Find (linear search) and return named Assembly.
void setTransform(const agx::AffineMatrix4x4 &matrix)
Set the transform of the assembly.
Assembly * getParent()
void setLocalRotation(const agx::Quat &q)
Set the rotation of the assembly relative to its frame's parent frame.
const agx::RigidBody * getRigidBody(const agx::Name &name, bool recursive=true) const
Find (linear search) and return named RigidBody.
const agx::EmitterRefSetVector & getEmitters() const
bool add(agx::Emitter *emitter)
Add an emitter to this assembly.
void setRotation(const agx::Quat &q)
Set the rotation of the assembly relative to world frame.
bool setParentFrame(agx::Frame *frame)
Set the parent frame of this assembly's frame.
An EventListener can be associated to a Simulation and triggered upon various events.
Definition: EventListener.h:41
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:677
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic.
Definition: Constraint.h:762
The base class for a constraint.
Definition: Constraint.h:89
This class store the combine material properties between two agx::Material's.
Definition: Material.h:528
Spawns new bodys inside a given volume.
Definition: Emitter.h:45
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:70
The object defining a frame of reference and providing transformations operations.
Definition: agx/Frame.h:68
The base class for interactions.
Definition: Interaction.h:32
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:56
Representation of a name string.
Definition: Name.h:33
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:44
Specialized types of matrices for holding orthogonal transformation matrices.
A basic particle system that contains all the storages and buffers required for basic operation and a...
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
T * get() const
Definition: ref_ptr.h:256
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
agx::SetVector< agx::ref_ptr< agxSDK::Assembly > > AssemblyRefSetVector
Definition: Assembly.h:37
double Real
Definition: Real.h:42