AGX Dynamics  2.38.0.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 #include <agxSDK/TerrainInstance.h>
35 
36 namespace agxSDK
37 {
39 
40  class AssemblyVisitor;
41 
67  class AGXPHYSICS_EXPORT Assembly : public virtual agx::Referenced, public virtual agxStream::Serializable
68  {
69  public:
71  Assembly();
72 
78  bool add(agx::Constraint* constraint);
79 
85  bool remove(agx::Constraint* constraint);
86 
92  bool add(agx::Interaction* interaction);
93 
99  bool remove(agx::Interaction* interaction);
100 
106  bool add(agxSDK::EventListener* listener);
107 
113  bool remove(EventListener* listener);
114 
120  bool add(agx::RigidBody* body);
121 
129  bool remove(agx::RigidBody* body, bool removeAssociatedGeometries = false, bool resetParentFrame=true);
130 
136  bool add(agxCollide::Geometry* geometry);
137 
144  bool remove(agxCollide::Geometry* geometry, bool resetParentFrame = true);
145 
151  bool add(Assembly* assembly);
152 
159  bool remove(Assembly* assembly, bool resetParentFrame=true);
160 
166  bool add(agx::ContactMaterial* contactMaterial);
167 
173  bool remove(agx::ContactMaterial* contactMaterial);
174 
180  bool add(agx::Emitter* emitter);
181 
187  bool remove(agx::Emitter* emitter);
188 
194  bool add(agx::ObserverFrame* observerFrame);
195 
202  bool remove(agx::ObserverFrame* observerFrame, bool resetParentFrame=true);
203 
209  bool add(agx::MergedBody* mergedBody);
210 
216  bool remove(agx::MergedBody *mergedBody);
217 
222  bool add(agxSDK::TerrainInstance* terrainInstance);
223 
228  bool remove(agxSDK::TerrainInstance* terrainInstance);
229 
236  bool add(agxStream::Serializable* object);
237 
238 
240 
247  agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true);
248 
255  const agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true) const;
256 
263  agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true);
264 
271  const agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true) const;
272 
279  const agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true) const;
280 
287  agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true);
288 
295  const agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true) const;
296 
303  agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true);
304 
311  const agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true) const;
312 
319  agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true);
320 
327  const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true) const;
328 
335  agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true);
336 
346  template < typename T >
347  T* getConstraint(const agx::Name& name, bool recursive = true);
348 
358  template < typename T >
359  const T* getConstraint(const agx::Name& name, bool recursive = true) const;
360 
367  const agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true) const;
368 
375  agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true);
376 
383  const agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true) const;
384 
391  agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true);
392 
393 
400  const agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true) const;
401 
408  agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true);
409 
416  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true) const;
417 
424  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true);
425 
432  const agx::MergedBody* getMergedBody (const agx::Uuid& uuid, bool recursive = true) const;
433 
440  agx::MergedBody* getMergedBody(const agx::Uuid& uuid, bool recursive = true);
441 
442 
449  const agxSDK::TerrainInstance* getTerrainInstance(const agx::Uuid& uuid, bool recursive = true) const;
450 
457  agxSDK::TerrainInstance* getTerrainInstance(const agx::Uuid& uuid, bool recursive = true);
458 
459 
461 
465  virtual void traverse(AssemblyVisitor* visitor);
466  virtual void traverse(const AssemblyVisitor* visitor) const;
467 
471  const agx::RigidBodyRefSetVector& getRigidBodies() const;
475  const agxCollide::GeometryRefSetVector& getGeometries() const;
476 
480  const EventListenerRefSetVector& getEventListeners() const;
481 
485  const AssemblyRefSetVector& getAssemblies() const;
486 
490  const agx::ParticleSystemRefSetVector& getParticleSystems() const;
491 
495  const agx::EmitterRefSetVector& getEmitters() const;
496 
500  const agx::ConstraintRefSetVector& getConstraints() const;
501 
505  const agx::InteractionRefSetVector& getInteractions() const;
506 
510  const agx::ObserverFrameRefSetVector& getObserverFrames() const;
511 
515  const agx::MergedBodyRefSetVector& getMergedBodies() const;
516 
520  const agxSDK::TerrainInstanceRefSetVector& getTerrainInstances() const;
521 
526  virtual agx::Frame* getFrame();
527  virtual const agx::Frame* getFrame() const;
528 
532  Assembly* getParent();
533 
537  const Assembly* getParent() const;
538 
544  void setTransform( const agx::AffineMatrix4x4& matrix );
545 
549  const agx::AffineMatrix4x4& getLocalTransform() const;
550 
555  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
556 
560  agx::Vec3 getLocalPosition() const;
561 
566  void setLocalPosition( const agx::Vec3& p );
567 
574  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
575 
580  void setRotation( const agx::Quat& q );
581 
586  void setRotation( const agx::EulerAngles& e);
587 
592  void setRotation( const agx::OrthoMatrix3x3& m );
593 
597  agx::Quat getLocalRotation() const;
598 
603  void setLocalRotation( const agx::Quat& q );
604 
609  void setLocalRotation( const agx::EulerAngles& e );
610 
614  agx::Frame* getParentFrame();
615 
619  const agx::Frame* getParentFrame() const;
620 
630  bool setParentFrame( agx::Frame* frame );
631 
636  void setPosition( const agx::Vec3& p );
637 
644  void setPosition( agx::Real x, agx::Real y, agx::Real z );
645 
647 
648 
652  virtual void addNotification(agxSDK::Simulation*) {}
653 
658 
662  virtual void addNotification(Assembly*) {}
663 
667  virtual void removeNotification(Assembly*) { }
668 
670  agxSDK::Simulation* getSimulation();
671 
673  const agxSDK::Simulation* getSimulation() const;
674 
679  virtual void setVelocity(const agx::Vec3& velocity);
680 
685  virtual void setAngularVelocity(const agx::Vec3& velocity);
686 
688  enum Type {
690  COLLECTION
691  };
692 
694  Type getType() const;
695 
700  void setName(const agx::Name& name);
701 
703  agx::Name getName() const;
704 
705  agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint1DOF>(name, recursive); }
706  agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint2DOF>(name, recursive); }
707 
709  static Assembly* asAssembly(agxStream::Serializable *obj) { return dynamic_cast<Assembly *>(obj); }
710 
718  bool transfer(agxSDK::Assembly* target);
719 
728  bool reset(bool resetParentFrame = true);
729 
733  bool empty() const;
734 
735  public:
737 
738  protected:
739 
740 
745  bool addParticleSystem(agx::ParticleSystem* particleSystem);
746 
750  bool removeParticleSystem(agx::ParticleSystem* particleSystem);
751 
752 
753 #if !defined(SWIG)
754  Assembly(Type type);
755 #endif
756 
758  virtual ~Assembly();
759  friend class Simulation;
760 
761  void addToSimulation(Simulation* simulation);
762  void removeFromSimulation(Simulation* simulation);
763 
764  private:
765 
766  agx::FrameRef m_frame;
767 
770  agx::ConstraintRefSetVector m_constraints;
771  agx::EmitterRefSetVector m_emitters;
772  EventListenerRefSetVector m_listeners;
773  agxSDK::Simulation* m_simulation;
774  agx::InteractionRefSetVector m_interactions;
775 
776  agx::ContactMaterialRefSetVector m_contactMaterials;
777  agx::ParticleSystemRefSetVector m_particleSystems;
778 
779  AssemblyRefSetVector m_assemblies;
780  AssemblyObserver m_parent;
781 
782  agx::ObserverFrameRefSetVector m_observers;
783  agx::MergedBodyRefSetVector m_mergedBodies;
785 
786  Type m_type;
787  agx::Name m_name;
788  };
789 
790 
792  {
793  return m_frame.get();
794  }
795 
796  inline const agx::Frame* Assembly::getFrame() const
797  {
798  return m_frame.get();
799  }
800 
810  {
811  public:
812 
814  bool succeed() const;
815 
816  // Constructor
817  AssemblyVisitor();
818  virtual ~AssemblyVisitor();
819 
820  protected:
821 
822  friend class Assembly;
823  virtual void visit(agx::Constraint*) {}
824  virtual void visit(agx::Interaction*) {}
825  virtual void visit(agx::RigidBody*) {}
826  virtual void visit(agxCollide::Geometry*) {}
827  virtual void visit(Assembly*);
828  virtual void visit(EventListener*) {}
829  virtual void visit(agx::ContactMaterial*) {}
830  virtual void visit(agx::ParticleSystem*) {}
831  virtual void visit(agx::Emitter*) {}
832  virtual void visit(agx::ObserverFrame*) {}
833  virtual void visit(agx::MergedBody*) {}
834  virtual void visit(agxSDK::TerrainInstance*) {}
835 
836  virtual void visit(const agx::Constraint*) const {}
837  virtual void visit(const agx::Interaction*) const {}
838  virtual void visit(const agx::RigidBody*) const {}
839  virtual void visit(const agxCollide::Geometry*) const {}
840  virtual void visit(const Assembly*)const;
841  virtual void visit(const EventListener*) const {}
842  virtual void visit(const agx::ContactMaterial*) const {}
843  virtual void visit(const agx::ParticleSystem*) const {}
844  virtual void visit(const agx::Emitter*) const {}
845  virtual void visit(const agx::ObserverFrame*) const {}
846  virtual void visit(const agx::MergedBody*) const {}
847  virtual void visit(const agxSDK::TerrainInstance*) const {}
848 
849  void setSucceed(bool flag) {
850  m_succeed = flag;
851  }
852 
853  bool m_succeed;
854  };
855 
856 
857 
858  /* Implementation */
859 
860 
861  template< typename T >
862  T* Assembly::getConstraint(const agx::Name& name, bool recursive)
863  {
864  return dynamic_cast< T* >(this->getConstraint(name, recursive));
865  }
866 
867  template< typename T >
868  const T* Assembly::getConstraint(const agx::Name& name, bool recursive) const
869  {
870  return dynamic_cast< const T* >(this->getConstraint(name, recursive));
871  }
872 
873 
874 }
TerrainInstance.h
agxSDK::AssemblyVisitor::visit
virtual void visit(const EventListener *) const
Definition: Assembly.h:841
agx::Real
double Real
Definition: Real.h:42
agxSDK::AssemblyVisitor::visit
virtual void visit(agxSDK::TerrainInstance *)
Definition: Assembly.h:834
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:673
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
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 two degree of freedom such as Cylindrical.
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:667
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:826
agx::AffineMatrix4x4T< Real >
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::ObserverFrame *)
Definition: Assembly.h:832
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::ContactMaterial *) const
Definition: Assembly.h:842
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:830
agxSDK::AssemblyVisitor::m_succeed
bool m_succeed
Definition: Assembly.h:853
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::ObserverFrame *) const
Definition: Assembly.h:845
agxSDK::AssemblyVisitor::visit
virtual void visit(EventListener *)
Definition: Assembly.h:828
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:705
agx::observer_ptr< Assembly >
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::RigidBody *)
Definition: Assembly.h:825
agxSDK::AssemblyVisitor
Class for visiting all elements in a tree of Assemblies.
Definition: Assembly.h:809
agxSDK::AssemblyVisitor::visit
virtual void visit(const agxCollide::Geometry *) const
Definition: Assembly.h:839
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Constraint *)
Definition: Assembly.h:823
agxSDK::Assembly
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints,...
Definition: Assembly.h:67
agxSDK::Assembly::getFrame
virtual agx::Frame * getFrame()
Return a reference to the frame containing transformation and velocity information for this assembly.
Definition: Assembly.h:791
agx::ObserverFrame
With this class you can attach an ObserverFrame object relative to a RigidBody.
Definition: ObserverFrame.h:41
agxSDK::Assembly::Type
Type
Specifies the type an assembly is.
Definition: Assembly.h:688
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:125
agxSDK::Assembly::addNotification
virtual void addNotification(Assembly *)
Called when this assembly is added to another assembly.
Definition: Assembly.h:662
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:846
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::ContactMaterial *)
Definition: Assembly.h:829
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::ParticleSystem *) const
Definition: Assembly.h:843
agxSDK::AssemblyRefSetVector
agx::SetVector< agx::ref_ptr< agxSDK::Assembly > > AssemblyRefSetVector
Definition: Assembly.h:38
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
agxSDK::Assembly::ASSEMBLY
@ ASSEMBLY
This is a full fledged Assembly which uses Frame for the hierarchy.
Definition: Assembly.h:689
agx::ContactMaterial
This class store the combine material properties between two agx::Material's.
Definition: Material.h:515
agxSDK::AssemblyVisitor::visit
virtual void visit(const agxSDK::TerrainInstance *) const
Definition: Assembly.h:847
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::Interaction *) const
Definition: Assembly.h:837
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:844
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:836
agx::Interaction
The base class for interactions.
Definition: Interaction.h:31
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agxSDK::TerrainInstance
agxTerrain::Terrain instance in a simulation, receiving step and contact callbacks in a controllable ...
Definition: TerrainInstance.h:43
agxSDK::Assembly::asAssembly
static Assembly * asAssembly(agxStream::Serializable *obj)
Definition: Assembly.h:709
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::MergedBody *)
Definition: Assembly.h:833
agx::Constraint
The base class for a constraint.
Definition: Constraint.h:88
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Emitter *)
Definition: Assembly.h:831
agxSDK::AssemblyVisitor::visit
virtual void visit(const agx::RigidBody *) const
Definition: Assembly.h:838
ObserverFrame.h
agxSDK::AssemblyVisitor::setSucceed
void setSucceed(bool flag)
Definition: Assembly.h:849
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:706
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:657
agxSDK::AssemblyVisitor::visit
virtual void visit(agx::Interaction *)
Definition: Assembly.h:824
agxSDK.h
agx::ref_ptr::get
T * get() const
Definition: ref_ptr.h:256
SetVector.h