AGX Dynamics  2.37.3.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 MergeSplitBodyStorage;
47  class Frame;
48  class InternalData;
49  class Emitter;
50 }
51 
52 namespace agxCollide
53 {
54  class SweepAndPrune;
55  class LocalContactPoint;
56 
57 }
58 
59 namespace agxTerrain
60 {
61  class Terrain;
62 }
63 
64 namespace agxData
65 {
67 }
68 
70 
71 
72 namespace agxCollide
73 {
74  class Space;
75  class ContactPoint;
76 
77 
83 
93  {
94  public:
96  ShapeChangeEvent shapeChangeEvent;
97 
98  public:
99 
104  Geometry( const agx::Name& name = "" );
105 
106 
111  Geometry( Shape* shape );
112 
118  Geometry( Shape* shape, const agx::AffineMatrix4x4& localShapeTransform );
119 
124  Geometry *clone( bool shallowCopyRenderData=false ) const;
125 
129  agx::Int64 getId() const;
130 
135  const agx::Name& getName() const;
136 
138  void setName( const agx::Name& name );
139 
143  agx::RigidBody *getRigidBody();
144 
148  const agx::RigidBody *getRigidBody() const;
149 
153  void setMaterial( agx::Material *material );
154 
158  agx::Material *getMaterial();
159 
163  const agx::Material *getMaterial() const;
164 
168  void removeMaterial();
169 
175  agx::Real calculateMass() const;
176 
182  agx::Real calculateVolume() const;
183 
189  agx::Vec3 calculateCenterOfMassOffset() const;
190 
196  agx::SPDMatrix3x3 calculateInertia( agx::Real mass ) const;
197 
202  void setEnable( bool flag );
203 
210  bool isEnabled() const;
211 
217  bool getEnable() const;
218 
233  void setSensor(bool flag, bool generateContactData = true);
234 
238  bool isSensor() const;
239 
244  bool isSensorGeneratingContactData() const;
245 
251  void setEnableMassProperties(bool enableMassProperties);
252 
256  bool getEnableMassProperties() const;
257 
270  void addGroup( agx::UInt32 id, bool forceContactUpdate = false );
271 
284  void addGroup( const agx::Name& name, bool forceContactUpdate = false);
285 
291  void removeGroup( agx::UInt32 id, bool forceContactUpdate = false );
292 
298  void removeGroup( const agx::Name& name, bool forceContactUpdate = false);
299 
304  void removeAllGroups(bool forceContactUpdate = false);
305 
312  bool hasGroup( agx::UInt32 id ) const;
313 
320  bool hasGroup( const agx::Name& name ) const;
321 
326  void setGroupSet( agx::Physics::CollisionGroupSetPtr set );
327 
331  const agx::Physics::CollisionGroupSetPtr& getGroupSet() const;
332 
335  const GroupSet& getGroupIDs() const;
336 
340  void setEnableCollisions( const Geometry* otherGeometry, bool flag );
341 
348  bool getEnableCollisions( const Geometry* otherGeometry ) const;
349 
355  void setEnableCollisions(bool collide);
356 
360  bool getEnableCollisions() const;
361 
362 
373  bool canCollide( const Geometry *otherGeometry ) const;
374 
375 
384  virtual agx::Vec3f calculateSurfaceVelocity( const agxCollide::LocalContactPoint& point, size_t index ) const;
385 
390  virtual const BoundingAABB* getBoundingVolume() const;
391 
393  agx::PropertyContainer* getPropertyContainer();
394 
396  const agx::PropertyContainer* getPropertyContainer() const;
397 
399  bool hasPropertyContainer() const;
400 
405  void setPropertyContainer( agx::PropertyContainer *container );
406 
410  Space* getSpace();
411 
415  const Space* getSpace() const;
416 
417 
419 
420 
424  agx::Referenced* getCustomData();
425 
429  const agx::Referenced* getCustomData() const;
430 
434  void setCustomData( agx::Referenced* data );
435 
440  agx::RigidBody* getOriginalBody();
441 
446  const agx::RigidBody* getOriginalBody() const;
447 
454  void setSurfaceVelocity( const agx::Vec3f& surfaceVelocity );
455 
460  const agx::Vec3f& getSurfaceVelocity() const;
461 
462  agx::UInt32 getSweepAndPruneIndex() const;
463 
464  // Normally updated automatically
465  virtual void updateBoundingVolume();
466 
468 
469  // Normally handled automatically
470  virtual void shapeUpdated();
471 
475  agxCollide::GroupIdCollection findGroupIdCollection() const;
476 
477  public:
481  agx::Frame *getFrame();
482 
486  const agx::Frame *getFrame() const;
487 
493  void setTransform( const agx::AffineMatrix4x4& matrix );
494 
498  const agx::AffineMatrix4x4& getLocalTransform() const;
499 
504  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
505 
509  agx::Vec3 getLocalPosition() const;
510 
515  void setLocalPosition( const agx::Vec3& p );
516 
523  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
524 
529  void setRotation( const agx::Quat& q );
530 
535  void setRotation( const agx::EulerAngles& e);
536 
541  void setRotation( const agx::OrthoMatrix3x3& m );
542 
546  agx::Quat getLocalRotation() const;
547 
552  void setLocalRotation( const agx::Quat& q );
553 
558  void setLocalRotation( const agx::EulerAngles& e );
559 
563  agx::Frame* getParentFrame();
564 
568  const agx::Frame* getParentFrame() const;
569 
579  bool setParentFrame( agx::Frame* frame );
580 
585  void setPosition( const agx::Vec3& p );
586 
593  void setPosition( agx::Real x, agx::Real y, agx::Real z );
594 
598  agx::AffineMatrix4x4 getTransform() const;
599 
603  agx::Vec3 getPosition() const;
604 
608  agx::Quat getRotation() const;
609 
610 
611  public:
612  /* Old interface, use ShapeGroup instead */
613 
621  bool add( Shape *shape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4() );
622 
627  bool remove( Shape *shape );
628 
641  Shape *getShape();
642 
654  const Shape *getShape() const;
655 
661  bool setShape(Shape *shape);
663 
664 
669  bool remove( size_t index );
670 
674  const ShapeRefVector& getShapes() const;
675 
679  bool replace( size_t shapeIndex, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
680  bool replace( Shape *oldShape, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
681 
688  bool replaceShapeTransform( size_t shapeIndex, const agx::AffineMatrix4x4& newTransform );
689 
696  bool replaceShapeTransform( Shape *shape, const agx::AffineMatrix4x4& newTransform );
697 
703  void cloneShapeRenderData(agxCollide::Shape* target, bool shallowCopy) const;
704 
705  public:
708  {
709  public:
716  MergeSplitProperties();
717 
719  void setEnableSplit( bool flag );
720 
722  bool getEnableSplit( ) const;
723 
727  void setEnableMerge( bool flag );
731  bool getEnableMerge( ) const;
732 
738  void setForceSplitInPreStep( bool flag );
742  bool getForceSplitInPreStep( ) const;
743 
744  private:
745  enum FLAGS {
746  ENABLE_SPLIT,
747  ENABLE_MERGE,
748  FORCE_SPLIT_IN_PRE,
749  NUM_ELEMENTS
750  };
751 
753  FlagVector m_flags;
754  };
755 
757  MergeSplitProperties& getMergeSplitProperties();
758 
760  const MergeSplitProperties& getMergeSplitProperties() const;
761 
762  protected:
764  virtual ~Geometry();
765 
766  private:
768  friend class agx::Emitter;
769  friend class agx::RigidBody;
770  friend class agx::Frame;
771  friend class GeometryGroup;
772  friend class agxCollide::Space;
774  friend class agxCollide::ShapeGroup;
775  friend class agxTerrain::Terrain;
776 
777  void propagateTransform();
778  void updateFrameStorage();
779  ShapeGroup *createWrapperGroup();
780 
781  void init(const agx::Name& name);
782 
783  mutable agx::PropertyContainerRef m_propertyContainer;
784 
785  void setBody( agx::RigidBody *body, const agx::AffineMatrix4x4& invBodyTransform );
786  void removeBody();
787 
794  bool setSpace( Space* space, agx::Int64 id );
795 
796  void setSweepAndPruneIndex( agx::UInt32 index );
797  void setEntity( agx::Physics::GeometryPtr entity );
798  // void transfer(Space *space);
799  void transfer( agxData::EntityStorage *storage );
800 
801  //void synchronizeShapeLocalTransformPointers();
802 
804  void setOriginalBody( agx::RigidBody * );
805 
806  size_t findShapeIndex(Shape *shape);
807 
808  void enableCollisionsWithGroup(agx::UInt32 groupId);
809  void disableCollisionsWithGroup(agx::UInt32 groupId);
810 
812  friend class agx::InternalData;
816  agx::Referenced* getInternalData() const;
817 
821  void setInternalData( agx::Referenced* data );
823 
824  private:
825  agx::Int64 m_id;
826  ShapeRef m_shape;
827  agx::Physics::GeometryRef m_entity;
828  agx::RigidBody * m_rigidBody;
829  Space * m_space;
830 
831  agx::MaterialRef m_material;
832 
833  mutable GeometryHashVector m_disabledCollisionsHash;
834 
835  agx::FrameRef m_frame;
836  agx::ref_ptr<agx::Referenced> m_customData;
837  agx::ref_ptr<agx::Referenced> m_internalData;
838  agx::observer_ptr<agx::RigidBody> m_originalBody;
839  MergeSplitProperties m_msProperties;
840 
841  // Backward compatibility
842  ShapeRefVector m_singleShapeVector;
843 
844  static ShapeRefVector s_defaultChildVector;
845  static GroupSet s_emptySet;
846  };
847 
848 
849  /* Implementation */
850 
851  AGX_FORCE_INLINE Shape *Geometry::getShape()
852  {
853  return m_shape;
854  }
855 
856  AGX_FORCE_INLINE const Shape *Geometry::getShape() const
857  {
858  return const_cast<Geometry *>( this )->getShape();
859  }
860 
862  {
863  return m_entity;
864  }
865  AGX_FORCE_INLINE agx::RigidBody *Geometry::getRigidBody()
866  {
867  return m_rigidBody;
868  }
869 
870  AGX_FORCE_INLINE const agx::RigidBody *Geometry::getRigidBody() const
871  {
872  return m_rigidBody;
873  }
874 
875  AGX_FORCE_INLINE agx::Int64 Geometry::getId() const
876  {
877  return m_id;
878  }
879 
880  AGX_FORCE_INLINE bool Geometry::isEnabled() const
881  {
882  return m_entity.state().enabled();
883  }
884 
885  AGX_FORCE_INLINE bool Geometry::isSensor() const
886  {
887  return m_entity.state().sensor();
888  }
889 
890  AGX_FORCE_INLINE bool Geometry::getEnableMassProperties() const
891  {
892  return m_entity.state().enableMassProperties();
893  }
894 
895 
896  inline bool Geometry::isSensorGeneratingContactData() const
897  {
898  return !m_entity.state().booleanSensor();
899  }
900 
901  AGX_FORCE_INLINE agx::UInt32 Geometry::getSweepAndPruneIndex() const
902  {
903  return m_entity.sweepAndPruneIndex();
904  }
905 
906  AGX_FORCE_INLINE bool Geometry::hasGroup( agx::UInt32 id ) const
907  {
908  return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), id);
909  }
910 
911  AGX_FORCE_INLINE bool Geometry::hasGroup( const agx::Name& name ) const
912  {
913  return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), name);
914  }
915 
916  AGX_FORCE_INLINE const agx::Physics::CollisionGroupSetPtr& Geometry::getGroupSet() const
917  {
918  return m_entity.collisionGroupSet();
919  }
920 
921  AGX_FORCE_INLINE void Geometry::setGroupSet( agx::Physics::CollisionGroupSetPtr set )
922  {
923  m_entity.collisionGroupSet() = set;
924  }
925 
926  AGX_FORCE_INLINE const agx::Material *Geometry::getMaterial() const
927  {
928  return m_material;
929  }
930 
931  AGX_FORCE_INLINE agx::Material *Geometry::getMaterial()
932  {
933  return m_material;
934  }
935 
936  AGX_FORCE_INLINE void Geometry::setSurfaceVelocity( const agx::Vec3f& surfaceVelocity )
937  {
938  m_entity.surfaceVelocity() = surfaceVelocity;
939  }
940 
941  AGX_FORCE_INLINE const agx::Vec3f& Geometry::getSurfaceVelocity( ) const
942  {
943  return m_entity.surfaceVelocity();
944  }
945 
946  AGX_FORCE_INLINE void Geometry::setOriginalBody( agx::RigidBody *body )
947  {
948  m_originalBody = body;
949  }
950 
951  AGX_FORCE_INLINE agx::RigidBody* Geometry::getOriginalBody( )
952  {
953  return m_originalBody.get() ? m_originalBody.get() : m_rigidBody;
954  }
955 
956  AGX_FORCE_INLINE const agx::RigidBody* Geometry::getOriginalBody( ) const
957  {
958  return m_originalBody.get() ? m_originalBody.get() : m_rigidBody;
959  }
960 
961  AGX_FORCE_INLINE bool Geometry::getEnable() const
962  {
963  return m_entity.state().enabled();
964  }
965 
966  AGX_FORCE_INLINE Space* Geometry::getSpace()
967  {
968  return m_space;
969  }
970  AGX_FORCE_INLINE const Space* Geometry::getSpace() const
971  {
972  return m_space;
973  }
974 
975  AGX_FORCE_INLINE agx::Frame* Geometry::getFrame()
976  {
977  return m_frame.get();
978  }
979 
980  AGX_FORCE_INLINE const agx::Frame* Geometry::getFrame() const
981  {
982  return m_frame.get();
983  }
984 
985  AGX_FORCE_INLINE const BoundingAABB* Geometry::getBoundingVolume() const
986  {
987  return &m_entity.boundingAABB();
988  }
989 
990 
991  AGX_FORCE_INLINE agx::PropertyContainer* Geometry::getPropertyContainer()
992  {
993  if ( !m_propertyContainer )
994  m_propertyContainer = new agx::PropertyContainer;
995  return m_propertyContainer;
996  }
997 
998  AGX_FORCE_INLINE bool Geometry::hasPropertyContainer() const
999  {
1000  return ( m_propertyContainer.isValid() );
1001  }
1002 
1003  AGX_FORCE_INLINE const agx::PropertyContainer* Geometry::getPropertyContainer() const
1004  {
1005  if ( !m_propertyContainer )
1006  m_propertyContainer = new agx::PropertyContainer;
1007 
1008  return m_propertyContainer;
1009  }
1010 
1011  AGX_FORCE_INLINE agx::Vec3f Geometry::calculateSurfaceVelocity( const agxCollide::LocalContactPoint& /* point */, size_t /* index */) const
1012  {
1013  return getSurfaceVelocity();
1014  }
1015 
1016  AGX_FORCE_INLINE Geometry::MergeSplitProperties& Geometry::getMergeSplitProperties()
1017  {
1018  return m_msProperties;
1019  }
1020  AGX_FORCE_INLINE const Geometry::MergeSplitProperties& Geometry::getMergeSplitProperties() const
1021  {
1022  return m_msProperties;
1023  }
1024 
1025  AGX_FORCE_INLINE void Geometry::MergeSplitProperties::setEnableSplit( bool flag )
1026  {
1027  m_flags[ENABLE_SPLIT] = flag;
1028  }
1029  AGX_FORCE_INLINE bool Geometry::MergeSplitProperties::getEnableSplit( ) const
1030  {
1031  return m_flags[ENABLE_SPLIT];
1032  }
1033 
1034  AGX_FORCE_INLINE void Geometry::MergeSplitProperties::setEnableMerge( bool flag )
1035  {
1036  m_flags[ENABLE_MERGE] = flag;
1037  }
1038 
1039  AGX_FORCE_INLINE bool Geometry::MergeSplitProperties::getEnableMerge( ) const
1040  {
1041  return m_flags[ENABLE_MERGE];
1042  }
1043 
1044  AGX_FORCE_INLINE void Geometry::MergeSplitProperties::setForceSplitInPreStep( bool flag )
1045  {
1046  m_flags[FORCE_SPLIT_IN_PRE] = flag;
1047  }
1048 
1049  AGX_FORCE_INLINE bool Geometry::MergeSplitProperties::getForceSplitInPreStep( ) const
1050  {
1051  return m_flags[FORCE_SPLIT_IN_PRE];
1052  }
1053 
1054 
1055  AGX_FORCE_INLINE agx::AffineMatrix4x4 Geometry::getTransform() const
1056  {
1057  if (m_rigidBody)
1058  return m_entity.transform();
1059  else
1060  return m_frame->getMatrix();
1061 
1062  }
1063 
1064  AGX_FORCE_INLINE agx::Vec3 Geometry::getPosition() const
1065  {
1066  if (m_rigidBody)
1067  return m_entity.transform().getTranslate();
1068  else
1069  return m_frame->getTranslate();
1070  }
1071 
1072  AGX_FORCE_INLINE agx::Quat Geometry::getRotation() const
1073  {
1074  if (m_rigidBody)
1075  return m_entity.transform().getRotate();
1076  return m_frame->getRotate();
1077  }
1078 
1079  AGX_FORCE_INLINE void Geometry::updateFrameStorage()
1080  {
1082  }
1083 
1084  inline agx::Referenced* Geometry::getInternalData() const
1085  {
1086  return m_internalData;
1087  }
1088 } // namespace agxCollide
int64_t Int64
Definition: Integer.h:46
void getRotate(T &angle, T &x, T &y, T &z) const
Get the angle and vector components represented by the quaternion.
void AGXPHYSICS_EXPORT init()
Initialize AGX Dynamics API including thread resources and must be executed before using the AGX API...
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:669
AffineMatrix4x4T< Real > AffineMatrix4x4
A std::pair, with both elements of the same type, and symmetric so (a, b) == (b, a) ...
Definition: SymmetricPair.h:31
A terrain model based a 3D grid model with overlapping height field that can be deformed by interacti...
Data storage for a collection of entity instances of a specified EntityModel.
Definition: EntityStorage.h:72
Base class for a shape.
Definition: Shape.h:53
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:66
This namespace consists of a set of classes for handling geometric intersection tests including boole...
The agxTerrain namespace contains a 3D model for a dynamic deformable Terrain and related classes...
Definition: Geometry.h:59
#define AGX_TYPE_BINDING(_Type, _Name)
Definition: Type.h:179
#define AGXPHYSICS_EXPORT
agx::HashVector< const Geometry *, agx::observer_ptr< const Geometry > > GeometryHashVector
Definition: Geometry.h:80
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * localTransformAttribute
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Representation of a name string.
Definition: Name.h:32
agx::Event1< Geometry * > ShapeChangeEvent
Definition: Geometry.h:95
#define AGX_FORCE_INLINE
Definition: Object.h:59
Spawns new bodys inside a given volume.
Definition: Emitter.h:44
Pointer to a entity instance of type Physics.CollisionGroupSet.
agx::ref_ptr< Material > MaterialRef
Definition: Material.h:59
Base class providing referencing counted objects.
Definition: Referenced.h:119
ShapeChangeEvent shapeChangeEvent
Definition: Geometry.h:96
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
agx::SetVector< agx::ref_ptr< agxCollide::Geometry > > GeometryRefSetVector
Definition: Geometry.h:82
AGXPHYSICS_EXPORT void addGroup(const agx::RigidBody *body, unsigned id)
For the specified body, add the collision group ID to its geometries.
This class provides conversion services between Euler angles in any of the 24 conventions and corresp...
Definition: EulerAngles.h:69
Class that is a container of named properties.
Definition: Property.h:158
This class contains all Geometries and performs Broad Phase and Narrow Phase collision detection to c...
Definition: Space.h:81
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
Pointer to a entity instance of type Physics.Geometry.
Collection of geometry group names and id&#39;s.
Specialized type of matrices for holding symmetric positive definite matrices.
Definition: SPDMatrix3x3.h:48
Contains classes for low level data storage for AGX.
Definition: Container.h:23
agx::HashSet< const Geometry *> GeometryHashSet
Definition: Geometry.h:81
Specify MergeSplit properties for a Geometry.
Definition: Geometry.h:707
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:375
Book keeping of a body which can be merged with other bodies.
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...
The object defining a frame of reference and providing transformations operations.
Definition: Frame.h:67
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * transformAttribute
#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
AGXPHYSICS_EXPORT void removeGroup(const agx::RigidBody *body, unsigned id)
For the specified body, remove the collision group ID to its geometries.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
CollisionGroupManager::GroupIdHash GroupSet
Deprecated: Only for backward compatibility.
Definition: Geometry.h:334
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
Axis aligned bounding box implementation.
Definition: BoundingAABB.h:37
bool isValid() const
Definition: ref_ptr.h:268
Referenced()
Default constructor.
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: SetVector.h:37
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
Specialized types of matrices for holding orthogonal transformation matrices.