AGX Dynamics  2.38.0.2
Geometry.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 <agxCollide/agxCollide.h>
20 #include <agx/agx.h>
21 #include <agx/observer_ptr.h>
23 #include <agxCollide/Shape.h>
25 #include <agx/Material.h>
26 #include <agx/Event.h>
27 
28 #include <agxStream/Serializable.h>
29 
30 #include <agx/Property.h>
31 
33 #include <agx/RigidBody.h>
34 #include <agx/HashSet.h>
35 #include <agx/AffineMatrix4x4.h>
36 #include <agx/BitArray.h>
37 #include <agx/SymmetricPair.h>
41 #include <agx/SetVector.h>
42 
43 
44 namespace agx
45 {
46  class Frame;
47  class InternalData;
48  class Emitter;
49 }
50 
51 namespace agxCollide
52 {
53  class SweepAndPrune;
54  class LocalContactPoint;
55 
56 }
57 
58 namespace agxTerrain
59 {
60  class Terrain;
61 }
62 
63 namespace agxData
64 {
66 }
67 
69 
70 
71 namespace agxCollide
72 {
73  class Space;
74  class ContactPoint;
75 
76 
82 
92  {
93  public:
96 
97  public:
98 
103  Geometry( const agx::Name& name = "" );
104 
105 
110  Geometry( Shape* shape );
111 
117  Geometry( Shape* shape, const agx::AffineMatrix4x4& localShapeTransform );
118 
123  Geometry *clone( bool shallowCopyRenderData=false ) const;
124 
128  agx::Int64 getId() const;
129 
134  const agx::Name& getName() const;
135 
137  void setName( const agx::Name& name );
138 
142  agx::RigidBody *getRigidBody();
143 
147  const agx::RigidBody *getRigidBody() const;
148 
152  void setMaterial( agx::Material *material );
153 
157  agx::Material *getMaterial();
158 
162  const agx::Material *getMaterial() const;
163 
167  void removeMaterial();
168 
174  agx::Real calculateMass() const;
175 
181  agx::Real calculateVolume() const;
182 
188  agx::Vec3 calculateCenterOfMassOffset() const;
189 
195  agx::SPDMatrix3x3 calculateInertia( agx::Real mass ) const;
196 
201  void setEnable( bool flag );
202 
209  bool isEnabled() const;
210 
216  bool getEnable() const;
217 
232  void setSensor(bool flag, bool generateContactData = true);
233 
237  bool isSensor() const;
238 
243  bool isSensorGeneratingContactData() const;
244 
250  void setEnableMassProperties(bool enableMassProperties);
251 
255  bool getEnableMassProperties() const;
256 
269  void addGroup( agx::UInt32 id, bool forceContactUpdate = false );
270 
283  void addGroup( const agx::Name& name, bool forceContactUpdate = false);
284 
290  void removeGroup( agx::UInt32 id, bool forceContactUpdate = false );
291 
297  void removeGroup( const agx::Name& name, bool forceContactUpdate = false);
298 
303  void removeAllGroups(bool forceContactUpdate = false);
304 
311  bool hasGroup( agx::UInt32 id ) const;
312 
319  bool hasGroup( const agx::Name& name ) const;
320 
325  void setGroupSet( agx::Physics::CollisionGroupSetPtr set );
326 
330  const agx::Physics::CollisionGroupSetPtr& getGroupSet() const;
331 
334  const GroupSet& getGroupIDs() const;
335 
339  void setEnableCollisions( const Geometry* otherGeometry, bool flag );
340 
347  bool getEnableCollisions( const Geometry* otherGeometry ) const;
348 
354  void setEnableCollisions(bool collide);
355 
359  bool getEnableCollisions() const;
360 
361 
372  bool canCollide( const Geometry *otherGeometry ) const;
373 
374 
383  virtual agx::Vec3f calculateSurfaceVelocity( const agxCollide::LocalContactPoint& point, size_t index ) const;
384 
389  virtual const BoundingAABB* getBoundingVolume() const;
390 
392  agx::PropertyContainer* getPropertyContainer();
393 
395  const agx::PropertyContainer* getPropertyContainer() const;
396 
398  bool hasPropertyContainer() const;
399 
404  void setPropertyContainer( agx::PropertyContainer *container );
405 
409  Space* getSpace();
410 
414  const Space* getSpace() const;
415 
416 
418 
419 
423  agx::Referenced* getCustomData();
424 
428  const agx::Referenced* getCustomData() const;
429 
433  void setCustomData( agx::Referenced* data );
434 
441  void setSurfaceVelocity( const agx::Vec3f& surfaceVelocity );
442 
447  const agx::Vec3f& getSurfaceVelocity() const;
448 
449  agx::UInt32 getSweepAndPruneIndex() const;
450 
451  // Normally updated automatically
452  virtual void updateBoundingVolume();
453 
455 
456  // Normally handled automatically
457  virtual void shapeUpdated();
458 
462  agxCollide::GroupIdCollection findGroupIdCollection() const;
463 
464  public:
468  agx::Frame *getFrame();
469 
473  const agx::Frame *getFrame() const;
474 
480  void setTransform( const agx::AffineMatrix4x4& matrix );
481 
485  const agx::AffineMatrix4x4& getLocalTransform() const;
486 
491  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
492 
496  agx::Vec3 getLocalPosition() const;
497 
502  void setLocalPosition( const agx::Vec3& p );
503 
510  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
511 
516  void setRotation( const agx::Quat& q );
517 
522  void setRotation( const agx::EulerAngles& e);
523 
528  void setRotation( const agx::OrthoMatrix3x3& m );
529 
533  agx::Quat getLocalRotation() const;
534 
539  void setLocalRotation( const agx::Quat& q );
540 
545  void setLocalRotation( const agx::EulerAngles& e );
546 
550  agx::Frame* getParentFrame();
551 
555  const agx::Frame* getParentFrame() const;
556 
566  bool setParentFrame( agx::Frame* frame );
567 
572  void setPosition( const agx::Vec3& p );
573 
580  void setPosition( agx::Real x, agx::Real y, agx::Real z );
581 
585  agx::AffineMatrix4x4 getTransform() const;
586 
590  agx::Vec3 getPosition() const;
591 
595  agx::Quat getRotation() const;
596 
597 
598  public:
599  /* Old interface, use ShapeGroup instead */
600 
608  bool add( Shape *shape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4() );
609 
614  bool remove( Shape *shape );
615 
628  Shape *getShape();
629 
641  const Shape *getShape() const;
642 
648  bool setShape(Shape *shape);
650 
651 
656  bool remove( size_t index );
657 
661  const ShapeRefVector& getShapes() const;
662 
666  bool replace( size_t shapeIndex, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
667  bool replace( Shape *oldShape, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
668 
675  bool replaceShapeTransform( size_t shapeIndex, const agx::AffineMatrix4x4& newTransform );
676 
683  bool replaceShapeTransform( Shape *shape, const agx::AffineMatrix4x4& newTransform );
684 
690  void cloneShapeRenderData(agxCollide::Shape* target, bool shallowCopy) const;
691 
692  public:
693 
694  protected:
696  virtual ~Geometry();
697 
698  private:
699  friend class agx::Emitter;
700  friend class agx::RigidBody;
701  friend class agx::Frame;
702  friend class GeometryGroup;
703  friend class agxCollide::Space;
704  friend class agxCollide::SweepAndPrune;
705  friend class agxCollide::ShapeGroup;
706  friend class agxTerrain::Terrain;
707 
708  void propagateTransform();
709  void updateFrameStorage();
710  ShapeGroup *createWrapperGroup();
711 
712  void init(const agx::Name& name);
713 
714  mutable agx::PropertyContainerRef m_propertyContainer;
715 
716  void setBody( agx::RigidBody *body, const agx::AffineMatrix4x4& invBodyTransform );
717  void removeBody();
718 
725  bool setSpace( Space* space, agx::Int64 id );
726 
727  void setSweepAndPruneIndex( agx::UInt32 index );
728  void setEntity( agx::Physics::GeometryPtr entity );
729  // void transfer(Space *space);
730  void transfer( agxData::EntityStorage *storage );
731 
732  size_t findShapeIndex(Shape *shape);
733 
734  void enableCollisionsWithGroup(agx::UInt32 groupId);
735  void disableCollisionsWithGroup(agx::UInt32 groupId);
736 
738  friend class agx::InternalData;
742  agx::Referenced* getInternalData() const;
743 
747  void setInternalData( agx::Referenced* data );
749 
750  private:
751  agx::Int64 m_id;
752  ShapeRef m_shape;
753  agx::Physics::GeometryRef m_entity;
754  agx::RigidBody * m_rigidBody;
755  Space * m_space;
756 
757  agx::MaterialRef m_material;
758 
759  mutable GeometryHashVector m_disabledCollisionsHash;
760 
761  agx::FrameRef m_frame;
762  agx::ref_ptr<agx::Referenced> m_customData;
763  agx::ref_ptr<agx::Referenced> m_internalData;
764  agx::observer_ptr<agx::RigidBody> m_originalBody;
765 
766  // Backward compatibility
767  ShapeRefVector m_singleShapeVector;
768 
769  static ShapeRefVector s_defaultChildVector;
770  static GroupSet s_emptySet;
771  };
772 
773 
774  /* Implementation */
775 
776  AGX_FORCE_INLINE Shape *Geometry::getShape()
777  {
778  return m_shape;
779  }
780 
781  AGX_FORCE_INLINE const Shape *Geometry::getShape() const
782  {
783  return const_cast<Geometry *>( this )->getShape();
784  }
785 
787  {
788  return m_entity;
789  }
790  AGX_FORCE_INLINE agx::RigidBody *Geometry::getRigidBody()
791  {
792  return m_rigidBody;
793  }
794 
795  AGX_FORCE_INLINE const agx::RigidBody *Geometry::getRigidBody() const
796  {
797  return m_rigidBody;
798  }
799 
800  AGX_FORCE_INLINE agx::Int64 Geometry::getId() const
801  {
802  return m_id;
803  }
804 
805  AGX_FORCE_INLINE bool Geometry::isEnabled() const
806  {
807  return m_entity.state().enabled();
808  }
809 
810  AGX_FORCE_INLINE bool Geometry::isSensor() const
811  {
812  return m_entity.state().sensor();
813  }
814 
815  AGX_FORCE_INLINE bool Geometry::getEnableMassProperties() const
816  {
817  return m_entity.state().enableMassProperties();
818  }
819 
820 
821  inline bool Geometry::isSensorGeneratingContactData() const
822  {
823  return !m_entity.state().booleanSensor();
824  }
825 
826  AGX_FORCE_INLINE agx::UInt32 Geometry::getSweepAndPruneIndex() const
827  {
828  return m_entity.sweepAndPruneIndex();
829  }
830 
831  AGX_FORCE_INLINE bool Geometry::hasGroup( agx::UInt32 id ) const
832  {
833  return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), id);
834  }
835 
836  AGX_FORCE_INLINE bool Geometry::hasGroup( const agx::Name& name ) const
837  {
838  return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), name);
839  }
840 
841  AGX_FORCE_INLINE const agx::Physics::CollisionGroupSetPtr& Geometry::getGroupSet() const
842  {
843  return m_entity.collisionGroupSet();
844  }
845 
846  AGX_FORCE_INLINE void Geometry::setGroupSet( agx::Physics::CollisionGroupSetPtr set )
847  {
848  m_entity.collisionGroupSet() = set;
849  }
850 
851  AGX_FORCE_INLINE const agx::Material *Geometry::getMaterial() const
852  {
853  return m_material;
854  }
855 
856  AGX_FORCE_INLINE agx::Material *Geometry::getMaterial()
857  {
858  return m_material;
859  }
860 
861  AGX_FORCE_INLINE void Geometry::setSurfaceVelocity( const agx::Vec3f& surfaceVelocity )
862  {
863  m_entity.surfaceVelocity() = surfaceVelocity;
864  }
865 
866  AGX_FORCE_INLINE const agx::Vec3f& Geometry::getSurfaceVelocity( ) const
867  {
868  return m_entity.surfaceVelocity();
869  }
870 
871  AGX_FORCE_INLINE bool Geometry::getEnable() const
872  {
873  return m_entity.state().enabled();
874  }
875 
876  AGX_FORCE_INLINE Space* Geometry::getSpace()
877  {
878  return m_space;
879  }
880  AGX_FORCE_INLINE const Space* Geometry::getSpace() const
881  {
882  return m_space;
883  }
884 
885  AGX_FORCE_INLINE agx::Frame* Geometry::getFrame()
886  {
887  return m_frame.get();
888  }
889 
890  AGX_FORCE_INLINE const agx::Frame* Geometry::getFrame() const
891  {
892  return m_frame.get();
893  }
894 
895  AGX_FORCE_INLINE const BoundingAABB* Geometry::getBoundingVolume() const
896  {
897  return &m_entity.boundingAABB();
898  }
899 
900 
901  AGX_FORCE_INLINE agx::PropertyContainer* Geometry::getPropertyContainer()
902  {
903  if ( !m_propertyContainer )
904  m_propertyContainer = new agx::PropertyContainer;
905  return m_propertyContainer;
906  }
907 
908  AGX_FORCE_INLINE bool Geometry::hasPropertyContainer() const
909  {
910  return ( m_propertyContainer.isValid() );
911  }
912 
913  AGX_FORCE_INLINE const agx::PropertyContainer* Geometry::getPropertyContainer() const
914  {
915  if ( !m_propertyContainer )
916  m_propertyContainer = new agx::PropertyContainer;
917 
918  return m_propertyContainer;
919  }
920 
921  AGX_FORCE_INLINE agx::Vec3f Geometry::calculateSurfaceVelocity( const agxCollide::LocalContactPoint& /* point */, size_t /* index */) const
922  {
923  return getSurfaceVelocity();
924  }
925 
926  AGX_FORCE_INLINE agx::AffineMatrix4x4 Geometry::getTransform() const
927  {
928  if (m_rigidBody)
929  return m_entity.transform();
930  else
931  return m_frame->getMatrix();
932 
933  }
934 
935  AGX_FORCE_INLINE agx::Vec3 Geometry::getPosition() const
936  {
937  if (m_rigidBody)
938  return m_entity.transform().getTranslate();
939  else
940  return m_frame->getTranslate();
941  }
942 
943  AGX_FORCE_INLINE agx::Quat Geometry::getRotation() const
944  {
945  if (m_rigidBody)
946  return m_entity.transform().getRotate();
947  return m_frame->getRotate();
948  }
949 
950  AGX_FORCE_INLINE void Geometry::updateFrameStorage()
951  {
953  }
954 
955  inline agx::Referenced* Geometry::getInternalData() const
956  {
957  return m_internalData;
958  }
959 } // namespace agxCollide
Shape.h
agx::SymmetricPair
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a)
Definition: SymmetricPair.h:31
agxcollide_vector_types.h
BoundingAABB.h
agxTerrain::Terrain
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Definition: Terrain.h:85
agx::Real
double Real
Definition: Real.h:42
agxData::GeometryPair
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:65
agx::OrthoMatrix3x3
Specialized types of matrices for holding orthogonal transformation matrices.
Definition: OrthoMatrix3x3.h:33
agx::Vector< agx::ref_ptr< Shape > >
agxCollide::GeometryRefSetVector
agx::SetVector< agx::ref_ptr< agxCollide::Geometry > > GeometryRefSetVector
Definition: Geometry.h:81
agxTerrain
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes.
Definition: Geometry.h:58
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
agxCollide::LocalContactPoint
Definition: LocalContactPoint.h:40
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
agx::AffineMatrix4x4T< Real >
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxData::AttributePtr
Definition: AttributePtr.h:27
agxUtil::addGroup
AGXPHYSICS_EXPORT void addGroup(const agx::RigidBody *body, unsigned id)
For the specified body, add the collision group ID to its geometries.
agx::FrameRef
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
agxCollide::Geometry::shapeChangeEvent
ShapeChangeEvent shapeChangeEvent
Definition: Geometry.h:95
agxCollide::BoundingAABB
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
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
agx
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Definition: AddedMassInteraction.h:22
AGXPHYSICS_EXPORT
#define AGXPHYSICS_EXPORT
agxData
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::PropertyContainer
Class that is a container of named properties.
Definition: Property.h:128
AffineMatrix4x4.h
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agx::MaterialRef
agx::ref_ptr< Material > MaterialRef
Definition: Material.h:59
agxCollide::GeometryHashSet
agx::HashSet< const Geometry * > GeometryHashSet
Definition: Geometry.h:80
agx::ref_ptr< Shape >
SymmetricPair.h
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
Property.h
agx::SetVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
agx::AffineMatrix4x4
AffineMatrix4x4T< Real > AffineMatrix4x4
Definition: AffineMatrix4x4.h:390
GeometryEntity.h
GeometryState.h
agxCollide::GeometryHashVector
agx::HashVector< const Geometry *, agx::observer_ptr< const Geometry > > GeometryHashVector
Definition: Geometry.h:79
GroupIdCollection.h
agxUtil::setEnableCollisions
AGXPHYSICS_EXPORT bool setEnableCollisions(agx::RigidBody *rb1, agx::RigidBody *rb2, bool enable)
Enable or disable the collision between all geometries in RigidBody rb1 and RigidBody rb2.
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
Event.h
observer_ptr.h
agx::Name
Representation of a name string.
Definition: Name.h:32
agx::SPDMatrix3x3
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
Serializable.h
agxCollide::Space
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
agx::EulerAngles
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
agx::HashSet
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
agx::QuatT< Real >
agxCollide.h
agx::Physics::GeometryPtr
Pointer to a entity instance of type Physics.Geometry.
Definition: GeometryEntity.h:269
agx.h
RigidBody.h
HashSet.h
agxCollide::SweepAndPrune
Definition: SweepAndPrune.h:36
agx::Event1< Geometry * >
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
agxUtil::removeGroup
AGXPHYSICS_EXPORT void removeGroup(const agx::RigidBody *body, unsigned id)
For the specified body, remove the collision group ID to its geometries.
agxCollide
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Definition: ContactForceFilterParticipant.h:22
agx::Int64
int64_t Int64
Definition: Integer.h:38
CollisionGroupManager.h
agxCollide::GroupIdCollection
Collection of geometry group names and id's.
Definition: GroupIdCollection.h:29
AGX_TYPE_BINDING
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
agx::init
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API.
agx::Material
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
agx::Vec3T< Real >
agxCollide::Geometry::ShapeChangeEvent
agx::Event1< Geometry * > ShapeChangeEvent
Definition: Geometry.h:94
agx::Physics::GeometryModel::transformAttribute
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * transformAttribute
Definition: GeometryEntity.h:109
agx::QuatT::getRotate
void getRotate(T &angle, T &x, T &y, T &z) const
Get the angle and vector components represented by the quaternion.
agx::UInt32
uint32_t UInt32
Definition: Integer.h:32
agxCollide::Geometry::GroupSet
CollisionGroupManager::GroupIdHash GroupSet
Deprecated: Only for backward compatibility.
Definition: Geometry.h:333
agx::Frame
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
agx::HashVector
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
BitArray.h
agx::Physics::CollisionGroupSetPtr
Pointer to a entity instance of type Physics.CollisionGroupSet.
Definition: CollisionGroupSetEntity.h:175
agx::PropertyContainerRef
agx::ref_ptr< PropertyContainer > PropertyContainerRef
Definition: Property.h:211
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
Material.h
agx::Physics::GeometryModel::localTransformAttribute
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * localTransformAttribute
Definition: GeometryEntity.h:110
SetVector.h
agxData::getEntity
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.