AGXDynamics  2.31.1.0
Assembly.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2021. 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 AGXSDK_ASSEMBLY_H
18 #define AGXSDK_ASSEMBLY_H
19 
20 #include <agx/agx.h>
21 #include <agx/RigidBody.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 <agx/agx_set_types.h>
33 #include <agxStream/Serializable.h>
34 #include <agx/SetVector.h>
35 #include <agx/DynamicsSystem.h>
36 
37 namespace agxSDK
38 {
45 
46  class AssemblyVisitor;
47 
73  class AGXPHYSICS_EXPORT Assembly : public virtual agx::Referenced, public virtual agxStream::Serializable
74  {
75  public:
77  Assembly();
78 
84  bool add(agx::Constraint* constraint);
85 
91  bool remove(agx::Constraint* constraint);
92 
98  bool add(agx::Interaction* interaction);
99 
105  bool remove(agx::Interaction* interaction);
106 
112  bool add(agxSDK::EventListener* listener);
113 
119  bool remove(EventListener* listener);
120 
126  bool add(agx::RigidBody* body);
127 
134  bool remove(agx::RigidBody* body, bool removeAssociatedGeometries = false);
135 
141  bool add(agxCollide::Geometry* geometry);
142 
148  bool remove(agxCollide::Geometry* geometry);
149 
155  bool add(Assembly* assembly);
156 
162  bool remove(Assembly* assembly);
163 
169  bool add(agx::ContactMaterial* contactMaterial);
170 
176  bool remove(agx::ContactMaterial* contactMaterial);
177 
183  bool add(agx::Emitter* emitter);
184 
190  bool remove(agx::Emitter* emitter);
191 
197  bool add(agx::ObserverFrame* observerFrame);
198 
204  bool remove(agx::ObserverFrame* observerFrame);
205 
212  bool add(agxStream::Serializable* object);
213 
215 
222  agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true);
223 
230  const agx::RigidBody* getRigidBody(const agx::Name& name, bool recursive = true) const;
231 
238  agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true);
239 
246  const agx::RigidBody* getRigidBody(const agx::Uuid& uuid, bool recursive = true) const;
247 
254  const agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true) const;
255 
262  agx::Constraint* getConstraint(const agx::Uuid& uuid, bool recursive = true);
263 
270  const agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true) const;
271 
278  agx::Constraint* getConstraint(const agx::Name& name, bool recursive = true);
279 
286  const agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true) const;
287 
294  agxSDK::Assembly* getAssembly(const agx::Name& name, bool recursive = true);
295 
302  const agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true) const;
303 
310  agxSDK::Assembly* getAssembly(const agx::Uuid& uuid, bool recursive = true);
311 
321  template < typename T >
322  T* getConstraint(const agx::Name& name, bool recursive = true);
323 
333  template < typename T >
334  const T* getConstraint(const agx::Name& name, bool recursive = true) const;
335 
342  const agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true) const;
343 
350  agxCollide::Geometry* getGeometry(const agx::Name& name, bool recursive = true);
351 
358  const agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true) const;
359 
366  agxCollide::Geometry* getGeometry(const agx::Uuid& uuid, bool recursive = true);
367 
368 
375  const agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true) const;
376 
383  agx::ObserverFrame* getObserverFrame(const agx::Name& name, bool recursive = true);
384 
391  const agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true) const;
392 
399  agx::ObserverFrame* getObserverFrame(const agx::Uuid& uuid, bool recursive = true);
400 
401 
403 
407  virtual void traverse(AssemblyVisitor* visitor);
408  virtual void traverse(const AssemblyVisitor* visitor) const;
409 
413  const agx::RigidBodyRefSet& getRigidBodies() const;
417  const agxCollide::GeometryRefSet& getGeometries() const;
418 
422  const AssemblyRefSet& getAssemblies() const;
423 
427  const agxSDK::ParticleSystemRefSet& getParticleSystems() const;
428 
432  const agx::EmitterRefSet& getEmitters() const;
433 
437  const agx::ConstraintRefSet& getConstraints() const;
438 
442  const InteractionRefSetVector& getInteractions() const;
443 
447  const ObserverFrameRefSetVector& getObserverFrames() const;
448 
453  virtual agx::Frame* getFrame();
454  virtual const agx::Frame* getFrame() const;
455 
459  Assembly* getParent();
460 
464  const Assembly* getParent() const;
465 
471  void setTransform( const agx::AffineMatrix4x4& matrix );
472 
476  const agx::AffineMatrix4x4& getLocalTransform() const;
477 
482  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
483 
487  agx::Vec3 getLocalPosition() const;
488 
493  void setLocalPosition( const agx::Vec3& p );
494 
501  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
502 
507  void setRotation( const agx::Quat& q );
508 
513  void setRotation( const agx::EulerAngles& e);
514 
519  void setRotation( const agx::OrthoMatrix3x3& m );
520 
524  agx::Quat getLocalRotation() const;
525 
530  void setLocalRotation( const agx::Quat& q );
531 
536  void setLocalRotation( const agx::EulerAngles& e );
537 
541  agx::Frame* getParentFrame();
542 
546  const agx::Frame* getParentFrame() const;
547 
557  bool setParentFrame( agx::Frame* frame );
558 
563  void setPosition( const agx::Vec3& p );
564 
571  void setPosition( agx::Real x, agx::Real y, agx::Real z );
572 
574 
575 
579  virtual void addNotification(agxSDK::Simulation*) {}
580 
585 
589  virtual void addNotification(Assembly*) {}
590 
594  virtual void removeNotification(Assembly*) { }
595 
597  agxSDK::Simulation* getSimulation();
598 
600  const agxSDK::Simulation* getSimulation() const;
601 
606  virtual void setVelocity(const agx::Vec3& velocity);
607 
612  virtual void setAngularVelocity(const agx::Vec3& velocity);
613 
615  enum Type {
617  COLLECTION
618  };
619 
621  Type getType() const;
622 
627  void setName(const agx::Name& name);
628 
630  agx::Name getName() const;
631 
632  agx::Constraint1DOF* getConstraint1DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint1DOF>(name, recursive); }
633  agx::Constraint2DOF* getConstraint2DOF(const agx::Name& name, bool recursive=true) { return this->getConstraint<agx::Constraint2DOF>(name, recursive); }
634 
636  static Assembly* asAssembly(agxStream::Serializable *obj) { return dynamic_cast<Assembly *>(obj); }
637 
638  public:
640 
641  protected:
642 
643 
648  bool addParticleSystem(agx::ParticleSystem* particleSystem);
649 
653  bool removeParticleSystem(agx::ParticleSystem* particleSystem);
654 
655 
656  Assembly(Type type);
657 
659  virtual ~Assembly();
660  friend class Simulation;
661 
662  void addToSimulation(Simulation* simulation);
663  void removeFromSimulation(Simulation* simulation);
664 
665  private:
666 
667  agx::FrameRef m_frame;
668 
669  agxCollide::GeometryRefSet m_geometries;
670  agx::RigidBodyRefSet m_bodies;
671  agx::ConstraintRefSet m_constraints;
672  agx::EmitterRefSet m_emitters;
673  EventListenerRefSet m_listeners;
674  agxSDK::Simulation* m_simulation;
675  InteractionRefSetVector m_interactions;
676 
677  ContactMaterialRefSet m_contactMaterials;
678  ParticleSystemRefSet m_particleSystems;
679 
680  AssemblyRefSet m_assemblies;
681  AssemblyObserver m_parent;
682 
683  ObserverFrameRefSetVector m_observers;
684 
685  Type m_type;
686  agx::Name m_name;
687  };
688 
689 
691  {
692  return m_frame.get();
693  }
694 
695  inline const agx::Frame* Assembly::getFrame() const
696  {
697  return m_frame.get();
698  }
699 
709  {
710  public:
711 
713  bool succeed() const;
714 
715  // Constructor
716  AssemblyVisitor();
717  virtual ~AssemblyVisitor();
718 
719  protected:
720 
721  friend class Assembly;
722  virtual void visit(agx::Constraint*) {}
723  virtual void visit(agx::Interaction*) {}
724  virtual void visit(agx::RigidBody*) {}
725  virtual void visit(agxCollide::Geometry*) {}
726  virtual void visit(Assembly*);
727  virtual void visit(EventListener*) {}
728  virtual void visit(agx::ContactMaterial*) {}
729  virtual void visit(agx::ParticleSystem*) {}
730  virtual void visit(agx::Emitter*) {}
731  virtual void visit(agx::ObserverFrame*) {}
732 
733  virtual void visit(const agx::Constraint*) const {}
734  virtual void visit(const agx::Interaction*) const {}
735  virtual void visit(const agx::RigidBody*) const {}
736  virtual void visit(const agxCollide::Geometry*) const {}
737  virtual void visit(const Assembly*)const;
738  virtual void visit(const EventListener*) const {}
739  virtual void visit(const agx::ContactMaterial*) const {}
740  virtual void visit(const agx::ParticleSystem*) const {}
741  virtual void visit(const agx::Emitter*) const {}
742  virtual void visit(const agx::ObserverFrame*) const {}
743 
744  void setSucceed(bool flag) {
745  m_succeed = flag;
746  }
747 
748  bool m_succeed;
749  };
750 
751 
752 
753  /* Implementation */
754 
755 
756  template< typename T >
757  T* Assembly::getConstraint(const agx::Name& name, bool recursive)
758  {
759  return dynamic_cast< T* >(this->getConstraint(name, recursive));
760  }
761 
762  template< typename T >
763  const T* Assembly::getConstraint(const agx::Name& name, bool recursive) const
764  {
765  return dynamic_cast< const T* >(this->getConstraint(name, recursive));
766  }
767 
768 
769 }
770 #endif
agx::SetVector< agx::InteractionRef > InteractionRefSetVector
Definition: Assembly.h:43
This class store the combine material properties between two agx::Material&#39;s.
Definition: Material.h:503
AGXCORE_EXPORT Type * getType(const agx::String &name)
agx::SetVector< agx::ref_ptr< agx::ContactMaterial > > ContactMaterialRefSet
Definition: Assembly.h:41
virtual void visit(const EventListener *) const
Definition: Assembly.h:738
#define AGX_ADD_FRAME_TRANSFORM_INTERFACE()
Definition: Frame.h:690
virtual void visit(const agx::Interaction *) const
Definition: Assembly.h:734
virtual void visit(const agx::Constraint *) const
Definition: Assembly.h:733
virtual void removeNotification(agxSDK::Simulation *)
Called when this assembly is removed from a simulation.
Definition: Assembly.h:584
virtual void visit(EventListener *)
Definition: Assembly.h:727
Type
Specifies the type an assembly is.
Definition: Assembly.h:615
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:759
virtual void visit(agx::Interaction *)
Definition: Assembly.h:723
virtual void visit(agx::ContactMaterial *)
Definition: Assembly.h:728
#define AGXPHYSICS_EXPORT
virtual void visit(const agxCollide::Geometry *) const
Definition: Assembly.h:736
The base class for a constraint.
Definition: Constraint.h:86
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Specialization for constraints that have only one degree of freedom such as Hinge and Prismatic...
Definition: Constraint.h:674
Representation of a name string.
Definition: Name.h:32
virtual void visit(agx::ObserverFrame *)
Definition: Assembly.h:731
virtual void addNotification(Assembly *)
Called when this assembly is added to another assembly.
Definition: Assembly.h:589
Spawns new bodys inside a given volume.
Definition: Emitter.h:37
virtual void visit(agx::RigidBody *)
Definition: Assembly.h:724
static Assembly * asAssembly(agxStream::Serializable *obj)
Definition: Assembly.h:636
Base class providing referencing counted objects.
Definition: Referenced.h:113
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
The base class for interactions.
Definition: Interaction.h:30
virtual void visit(agx::Emitter *)
Definition: Assembly.h:730
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:72
A basic particle system that contains all the storages and buffers required for basic operation and a...
agx::SetVector< agx::ref_ptr< agxSDK::Assembly > > AssemblyRefSet
Definition: Assembly.h:39
virtual void visit(const agx::Emitter *) const
Definition: Assembly.h:741
virtual agx::Frame * getFrame()
Return a reference to the frame containing transformation and velocity information for this assembly...
Definition: Assembly.h:690
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.
virtual void visit(agxCollide::Geometry *)
Definition: Assembly.h:725
virtual void visit(const agx::ParticleSystem *) const
Definition: Assembly.h:740
agx::Constraint2DOF * getConstraint2DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:633
void setSucceed(bool flag)
Definition: Assembly.h:744
virtual void visit(const agx::ObserverFrame *) const
Definition: Assembly.h:742
virtual void visit(const agx::RigidBody *) const
Definition: Assembly.h:735
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
agx::ObserverFrameRefSetVector ObserverFrameRefSetVector
Definition: Assembly.h:44
agx::Constraint1DOF * getConstraint1DOF(const agx::Name &name, bool recursive=true)
Definition: Assembly.h:632
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
agx::SetVector< agx::ref_ptr< agxSDK::EventListener > > EventListenerRefSet
Definition: Assembly.h:40
#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:206
virtual void visit(agx::ParticleSystem *)
Definition: Assembly.h:729
agx::SetVector< agx::ref_ptr< agx::ParticleSystem > > ParticleSystemRefSet
Definition: Assembly.h:42
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:37
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:121
This is a full fledged Assembly which uses Frame for the hierarchy.
Definition: Assembly.h:616
double Real
Definition: Real.h:42
virtual void visit(agx::Constraint *)
Definition: Assembly.h:722
Class for visiting all elements in a tree of Assemblies.
Definition: Assembly.h:708
virtual void visit(const agx::ContactMaterial *) const
Definition: Assembly.h:739
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:594
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:38
An assembly is a collection of basic simulation objects, such as rigid bodies, constraints, geometries.
Definition: Assembly.h:73
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:42
GLenum type
Definition: gl.h:5539