AGX Dynamics  2.37.3.2
Assembly.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 
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 
128  bool remove(agx::RigidBody* body, bool removeAssociatedGeometries = false, bool resetParentFrame=true);
129 
135  bool add(agxCollide::Geometry* geometry);
136 
143  bool remove(agxCollide::Geometry* geometry, bool resetParentFrame = true);
144 
150  bool add(Assembly* assembly);
151 
158  bool remove(Assembly* assembly, bool resetParentFrame=true);
159 
165  bool add(agx::ContactMaterial* contactMaterial);
166 
172  bool remove(agx::ContactMaterial* contactMaterial);
173 
179  bool add(agx::Emitter* emitter);
180 
186  bool remove(agx::Emitter* emitter);
187 
193  bool add(agx::ObserverFrame* observerFrame);
194 
201  bool remove(agx::ObserverFrame* observerFrame, bool resetParentFrame=true);
202 
208  bool add(agx::MergedBody* mergedBody);
209 
215  bool remove(agx::MergedBody *mergedBody);
216 
223  bool add(agxStream::Serializable* object);
224 
225 
227 
234  agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true);
235 
242  const agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true) const;
243 
250  agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true);
251 
258  const agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true) const;
259 
266  const agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true) const;
267 
274  agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true);
275 
282  const agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true) const;
283 
290  agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true);
291 
298  const agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true) const;
299 
306  agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true);
307 
314  const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true) const;
315 
322  agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true);
323 
333  template < typename T >
334  T* getConstraint(const agx::Name& name, bool recursive = true);
335 
345  template < typename T >
346  const T* getConstraint(const agx::Name& name, bool recursive = true) const;
347 
354  const agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true) const;
355 
362  agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true);
363 
370  const agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true) const;
371 
378  agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true);
379 
380 
387  const agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true) const;
388 
395  agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true);
396 
403  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true) const;
404 
411  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true);
412 
419  const agx::MergedBody* getMergedBody (const agx::Uuid& uuid, bool recursive = true) const;
420 
427  agx::MergedBody* getMergedBody(const agx::Uuid& uuid, bool recursive = true);
428 
430 
434  virtual void traverse(AssemblyVisitor* visitor);
435  virtual void traverse(const AssemblyVisitor* visitor) const;
436 
440  const agx::RigidBodyRefSetVector& getRigidBodies() const;
444  const agxCollide::GeometryRefSetVector& getGeometries() const;
445 
449  const EventListenerRefSetVector& getEventListeners() const;
450 
454  const AssemblyRefSetVector& getAssemblies() const;
455 
459  const agx::ParticleSystemRefSetVector& getParticleSystems() const;
460 
464  const agx::EmitterRefSetVector& getEmitters() const;
465 
469  const agx::ConstraintRefSetVector& getConstraints() const;
470 
474  const agx::InteractionRefSetVector& getInteractions() const;
475 
479  const agx::ObserverFrameRefSetVector& getObserverFrames() const;
480 
484  const agx::MergedBodyRefSetVector& getMergedBodies() const;
485 
490  virtual agx::Frame* getFrame();
491  virtual const agx::Frame* getFrame() const;
492 
496  Assembly* getParent();
497 
501  const Assembly* getParent() const;
502 
508  void setTransform( const agx::AffineMatrix4x4& matrix );
509 
513  const agx::AffineMatrix4x4& getLocalTransform() const;
514 
519  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
520 
524  agx::Vec3 getLocalPosition() const;
525 
530  void setLocalPosition( const agx::Vec3& p );
531 
538  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
539 
544  void setRotation( const agx::Quat& q );
545 
550  void setRotation( const agx::EulerAngles& e);
551 
556  void setRotation( const agx::OrthoMatrix3x3& m );
557 
561  agx::Quat getLocalRotation() const;
562 
567  void setLocalRotation( const agx::Quat& q );
568 
573  void setLocalRotation( const agx::EulerAngles& e );
574 
578  agx::Frame* getParentFrame();
579 
583  const agx::Frame* getParentFrame() const;
584 
594  bool setParentFrame( agx::Frame* frame );
595 
600  void setPosition( const agx::Vec3& p );
601 
608  void setPosition( agx::Real x, agx::Real y, agx::Real z );
609 
611 
612 
616  virtual void addNotification(agxSDK::Simulation*) {}
617 
622 
626  virtual void addNotification(Assembly*) {}
627 
631  virtual void removeNotification(Assembly*) { }
632 
634  agxSDK::Simulation* getSimulation();
635 
637  const agxSDK::Simulation* getSimulation() const;
638 
643  virtual void setVelocity(const agx::Vec3& velocity);
644 
649  virtual void setAngularVelocity(const agx::Vec3& velocity);
650 
652  enum Type {
654  COLLECTION
655  };
656 
658  Type getType() const;
659 
664  void setName(const agx::Name& name);
665 
667  agx::Name getName() const;
668 
669  agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint1DOF>(name, recursive); }
670  agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint2DOF>(name, recursive); }
671 
673  static Assembly* asAssembly(agxStream::Serializable *obj) { return dynamic_cast<Assembly *>(obj); }
674 
682  bool transfer(agxSDK::Assembly* target);
683 
692  bool reset(bool resetParentFrame = true);
693 
697  bool empty() const;
698 
699  public:
701 
702  protected:
703 
704 
709  bool addParticleSystem(agx::ParticleSystem* particleSystem);
710 
714  bool removeParticleSystem(agx::ParticleSystem* particleSystem);
715 
716 
717  Assembly(Type type);
718 
720  virtual ~Assembly();
721  friend class Simulation;
722 
723  void addToSimulation(Simulation* simulation);
724  void removeFromSimulation(Simulation* simulation);
725 
726  private:
727 
728  agx::FrameRef m_frame;
729 
732  agx::ConstraintRefSetVector m_constraints;
733  agx::EmitterRefSetVector m_emitters;
734  EventListenerRefSetVector m_listeners;
735  agxSDK::Simulation* m_simulation;
736  agx::InteractionRefSetVector m_interactions;
737 
738  agx::ContactMaterialRefSetVector m_contactMaterials;
739  agx::ParticleSystemRefSetVector m_particleSystems;
740 
741  AssemblyRefSetVector m_assemblies;
742  AssemblyObserver m_parent;
743 
744  agx::ObserverFrameRefSetVector m_observers;
745  agx::MergedBodyRefSetVector m_mergedBodies;
746 
747  Type m_type;
748  agx::Name m_name;
749  };
750 
751 
753  {
754  return m_frame.get();
755  }
756 
757  inline const agx::Frame* Assembly::getFrame() const
758  {
759  return m_frame.get();
760  }
761 
771  {
772  public:
773 
775  bool succeed() const;
776 
777  // Constructor
778  AssemblyVisitor();
779  virtual ~AssemblyVisitor();
780 
781  protected:
782 
783  friend class Assembly;
784  virtual void visit(agx::Constraint*) {}
785  virtual void visit(agx::Interaction*) {}
786  virtual void visit(agx::RigidBody*) {}
787  virtual void visit(agxCollide::Geometry*) {}
788  virtual void visit(Assembly*);
789  virtual void visit(EventListener*) {}
790  virtual void visit(agx::ContactMaterial*) {}
791  virtual void visit(agx::ParticleSystem*) {}
792  virtual void visit(agx::Emitter*) {}
793  virtual void visit(agx::ObserverFrame*) {}
794  virtual void visit(agx::MergedBody*) {}
795 
796  virtual void visit(const agx::Constraint*) const {}
797  virtual void visit(const agx::Interaction*) const {}
798  virtual void visit(const agx::RigidBody*) const {}
799  virtual void visit(const agxCollide::Geometry*) const {}
800  virtual void visit(const Assembly*)const;
801  virtual void visit(const EventListener*) const {}
802  virtual void visit(const agx::ContactMaterial*) const {}
803  virtual void visit(const agx::ParticleSystem*) const {}
804  virtual void visit(const agx::Emitter*) const {}
805  virtual void visit(const agx::ObserverFrame*) const {}
806  virtual void visit(const agx::MergedBody*) const {}
807 
808  void setSucceed(bool flag) {
809  m_succeed = flag;
810  }
811 
812  bool m_succeed;
813  };
814 
815 
816 
817  /* Implementation */
818 
819 
820  template< typename T >
821  T* Assembly::getConstraint(const agx::Name& name, bool recursive)
822  {
823  return dynamic_cast< T* >(this->getConstraint(name, recursive));
824  }
825 
826  template< typename T >
827  const T* Assembly::getConstraint(const agx::Name& name, bool recursive) const
828  {
829  return dynamic_cast< const T* >(this->getConstraint(name, recursive));
830  }
831 
832 
833 }
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:515
AGXCORE_EXPORT Type * getType(const agx::String &name)
virtual void visit(const EventListener *) const
Definition: Assembly.h:801
#define AGX_ADD_FRAME_TRANSFORM_INTERFACE()
Definition: Frame.h:690
virtual void visit(const agx::Interaction *) const
Definition: Assembly.h:797
virtual void visit(const agx::Constraint *) const
Definition: Assembly.h:796
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:621
virtual void visit(EventListener *)
Definition: Assembly.h:789
Type
Specifies the type an assembly is.
Definition: Assembly.h:652
Specialization for constraints that have two degree of freedom such as Cylindrical.
Definition: Constraint.h:761
virtual void visit(agx::Interaction *)
Definition: Assembly.h:785
virtual void visit(agx::ContactMaterial *)
Definition: Assembly.h:790
#define AGXPHYSICS_EXPORT
virtual void visit(const agxCollide::Geometry *) const
Definition: Assembly.h:799
The base class for a constraint.
Definition: Constraint.h:88
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:673
Representation of a name string.
Definition: Name.h:32
virtual void visit(agx::ObserverFrame *)
Definition: Assembly.h:793
virtual void addNotification(Assembly *)
Called when this assembly is added to another assembly.
Definition: Assembly.h:626
Spawns new bodys inside a given volume.
Definition: Emitter.h:44
virtual void visit(agx::RigidBody *)
Definition: Assembly.h:786
static Assembly * asAssembly(agxStream::Serializable *obj)
Definition: Assembly.h:673
Base class providing referencing counted objects.
Definition: Referenced.h:119
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
The base class for interactions.
Definition: Interaction.h:31
Structure holding several "normal" rigid bodies.
Definition: MergedBody.h:55
virtual void visit(agx::Emitter *)
Definition: Assembly.h:792
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
A basic particle system that contains all the storages and buffers required for basic operation and a...
virtual void visit(const agx::Emitter *) const
Definition: Assembly.h:804
virtual agx::Frame * getFrame()
Return a reference to the frame containing transformation and velocity information for this assembly...
Definition: Assembly.h:752
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.
agx::SetVector< agx::ref_ptr< agxSDK::Assembly > > AssemblyRefSetVector
Definition: Assembly.h:37
virtual void visit(agxCollide::Geometry *)
Definition: Assembly.h:787
virtual void visit(const agx::ParticleSystem *) const
Definition: Assembly.h:803
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:670
void setSucceed(bool flag)
Definition: Assembly.h:808
virtual void visit(const agx::ObserverFrame *) const
Definition: Assembly.h:805
virtual void visit(const agx::RigidBody *) const
Definition: Assembly.h:798
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:669
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:41
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
#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
virtual void visit(agx::ParticleSystem *)
Definition: Assembly.h:791
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
An EventListener can be associated to a Simulation and triggered upon various events.
Definition: EventListener.h:40
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
This is a full fledged Assembly which uses Frame for the hierarchy.
Definition: Assembly.h:653
virtual void visit(agx::MergedBody *)
Definition: Assembly.h:794
double Real
Definition: Real.h:42
virtual void visit(agx::Constraint *)
Definition: Assembly.h:784
virtual void visit(const agx::MergedBody *) const
Definition: Assembly.h:806
Class for visiting all elements in a tree of Assemblies.
Definition: Assembly.h:770
virtual void visit(const agx::ContactMaterial *) const
Definition: Assembly.h:802
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:30
virtual void removeNotification(Assembly *)
Called when this assembly is removed from another assembly.
Definition: Assembly.h:631
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:66
Specialized types of matrices for holding orthogonal transformation matrices.
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:43