AGXDynamics  2.31.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Geometry.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 #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 
42 namespace agx
43 {
44  class MergeSplitBodyStorage;
45  class Frame;
46  class InternalData;
47 }
48 
49 namespace agxCollide
50 {
51  class SweepAndPrune;
52  class LocalContactPoint;
53 
54 }
55 
56 namespace agxTerrain
57 {
58  class Terrain;
59 }
60 
61 namespace agxData
62 {
64 }
65 
67 
68 
69 namespace agxCollide
70 {
71  class Space;
72  class ContactPoint;
73 
74 
79 
89  {
90  public:
93 
94  public:
95 
100  Geometry( const agx::Name& name = "" );
101 
102 
107  Geometry( Shape* shape );
108 
114  Geometry( Shape* shape, const agx::AffineMatrix4x4& localShapeTransform );
115 
120  Geometry *clone() const;
121 
125  agx::Int64 getId() const;
126 
131  const agx::Name& getName() const;
132 
134  void setName( const agx::Name& name );
135 
139  agx::RigidBody *getRigidBody();
140 
144  const agx::RigidBody *getRigidBody() const;
145 
149  void setMaterial( agx::Material *material );
150 
154  agx::Material *getMaterial();
155 
159  const agx::Material *getMaterial() const;
160 
164  void removeMaterial();
165 
171  agx::Real calculateMass() const;
172 
178  agx::Real calculateVolume() const;
179 
185  agx::Vec3 calculateCenterOfMassOffset() const;
186 
192  agx::SPDMatrix3x3 calculateInertia( agx::Real mass ) const;
193 
198  void setEnable( bool flag );
199 
206  bool isEnabled() const;
207 
213  bool getEnable() const;
214 
229  void setSensor(bool flag, bool generateContactData = true);
230 
234  bool isSensor() const;
235 
240  bool isSensorGeneratingContactData() const;
241 
254  void addGroup( agx::UInt32 id, bool forceContactUpdate = false );
255 
268  void addGroup( const agx::Name& name, bool forceContactUpdate = false);
269 
275  void removeGroup( agx::UInt32 id, bool forceContactUpdate = false );
276 
282  void removeGroup( const agx::Name& name, bool forceContactUpdate = false);
283 
288  void removeAllGroups(bool forceContactUpdate = false);
289 
296  bool hasGroup( agx::UInt32 id ) const;
297 
304  bool hasGroup( const agx::Name& name ) const;
308  const agx::Physics::CollisionGroupSetPtr& getGroupSet() const;
309 
312  const GroupSet& getGroupIDs() const;
313 
317  void setEnableCollisions( const Geometry* otherGeometry, bool flag );
318 
322  bool getEnableCollisions( const Geometry* otherGeometry ) const;
323 
329  void setEnableCollisions(bool collide);
330 
334  bool getEnableCollisions() const;
335 
336 
347  bool canCollide( const Geometry *otherGeometry ) const;
348 
349 
358  virtual agx::Vec3f calculateSurfaceVelocity( const agxCollide::LocalContactPoint& point, size_t index ) const;
359 
364  virtual const BoundingAABB* getBoundingVolume() const;
365 
367  agx::PropertyContainer* getPropertyContainer();
368 
370  const agx::PropertyContainer* getPropertyContainer() const;
371 
373  bool hasPropertyContainer() const;
374 
379  void setPropertyContainer( agx::PropertyContainer *container );
380 
384  Space* getSpace();
385 
389  const Space* getSpace() const;
390 
391 
393 
394 
398  agx::Referenced* getCustomData();
399 
403  const agx::Referenced* getCustomData() const;
404 
408  void setCustomData( agx::Referenced* data );
409 
414  agx::RigidBody* getOriginalBody();
415 
420  const agx::RigidBody* getOriginalBody() const;
421 
428  void setSurfaceVelocity( const agx::Vec3f& surfaceVelocity );
429 
434  const agx::Vec3f& getSurfaceVelocity() const;
435 
436  agx::UInt32 getSweepAndPruneIndex() const;
437 
438  // Normally updated automatically
439  virtual void updateBoundingVolume();
440 
442 
443  // Normally handled automatically
444  virtual void shapeUpdated();
445 
449  agxCollide::GroupIdCollection findGroupIdCollection() const;
450 
451  public:
455  agx::Frame *getFrame();
456 
460  const agx::Frame *getFrame() const;
461 
467  void setTransform( const agx::AffineMatrix4x4& matrix );
468 
472  const agx::AffineMatrix4x4& getLocalTransform() const;
473 
478  void setLocalTransform( const agx::AffineMatrix4x4& matrix );
479 
483  agx::Vec3 getLocalPosition() const;
484 
489  void setLocalPosition( const agx::Vec3& p );
490 
497  void setLocalPosition( agx::Real x, agx::Real y, agx::Real z );
498 
503  void setRotation( const agx::Quat& q );
504 
509  void setRotation( const agx::EulerAngles& e);
510 
515  void setRotation( const agx::OrthoMatrix3x3& m );
516 
520  agx::Quat getLocalRotation() const;
521 
526  void setLocalRotation( const agx::Quat& q );
527 
532  void setLocalRotation( const agx::EulerAngles& e );
533 
537  agx::Frame* getParentFrame();
538 
542  const agx::Frame* getParentFrame() const;
543 
553  bool setParentFrame( agx::Frame* frame );
554 
559  void setPosition( const agx::Vec3& p );
560 
567  void setPosition( agx::Real x, agx::Real y, agx::Real z );
568 
572  agx::AffineMatrix4x4 getTransform() const;
573 
577  agx::Vec3 getPosition() const;
578 
582  agx::Quat getRotation() const;
583 
584 
585  public:
586  /* Old interface, use ShapeGroup instead */
587 
595  bool add( Shape *shape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4() );
596 
601  bool remove( Shape *shape );
602 
615  Shape *getShape();
616 
628  const Shape *getShape() const;
629 
635  bool setShape(Shape *shape);
637 
638 
643  bool remove( size_t index );
644 
648  const ShapeRefVector& getShapes() const;
649 
653  bool replace( size_t shapeIndex, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
654  bool replace( Shape *oldShape, Shape *newShape, const agx::AffineMatrix4x4& localTransform = agx::AffineMatrix4x4());
655 
662  bool replaceShapeTransform( size_t shapeIndex, const agx::AffineMatrix4x4& newTransform );
663 
670  bool replaceShapeTransform( Shape *shape, const agx::AffineMatrix4x4& newTransform );
671 
672 
673  public:
676  {
677  public:
684  MergeSplitProperties();
685 
687  void setEnableSplit( bool flag );
688 
690  bool getEnableSplit( ) const;
691 
695  void setEnableMerge( bool flag );
699  bool getEnableMerge( ) const;
700 
706  void setForceSplitInPreStep( bool flag );
710  bool getForceSplitInPreStep( ) const;
711 
712  private:
713  enum FLAGS {
714  ENABLE_SPLIT,
715  ENABLE_MERGE,
716  FORCE_SPLIT_IN_PRE,
717  NUM_ELEMENTS
718  };
719 
721  FlagVector m_flags;
722  };
723 
725  MergeSplitProperties& getMergeSplitProperties();
726 
728  const MergeSplitProperties& getMergeSplitProperties() const;
729 
730  protected:
732  virtual ~Geometry();
733 
734  private:
736  friend class agx::RigidBody;
737  friend class agx::Frame;
738  friend class GeometryGroup;
739  friend class agxCollide::Space;
741  friend class agxCollide::ShapeGroup;
742  friend class agxTerrain::Terrain;
743 
744  void propagateTransform();
745  void updateFrameStorage();
746  ShapeGroup *createWrapperGroup();
747 
748  void init(const agx::Name& name);
749 
750  mutable agx::PropertyContainerRef m_propertyContainer;
751 
752  void setBody( agx::RigidBody *body, const agx::AffineMatrix4x4& invBodyTransform );
753  void removeBody();
754 
761  bool setSpace( Space* space, agx::Int64 id );
762 
763  void setSweepAndPruneIndex( agx::UInt32 index );
764  void setEntity( agx::Physics::GeometryPtr entity );
765  // void transfer(Space *space);
766  void transfer( agxData::EntityStorage *storage );
767 
768  //void synchronizeShapeLocalTransformPointers();
769 
771  void setOriginalBody( agx::RigidBody * );
772 
773  size_t findShapeIndex(Shape *shape);
774 
775  void enableCollisionsWithGroup(agx::UInt32 groupId);
776  void disableCollisionsWithGroup(agx::UInt32 groupId);
777 
779  friend class agx::InternalData;
783  agx::Referenced* getInternalData() const;
784 
788  void setInternalData( agx::Referenced* data );
790 
791  private:
792  agx::Int64 m_id;
793  ShapeRef m_shape;
794  agx::Physics::GeometryRef m_entity;
795  agx::RigidBody * m_rigidBody;
796  Space * m_space;
797 
798  agx::MaterialRef m_material;
799 
800  mutable GeometryHashVector m_disabledCollisionsHash;
801 
802  agx::FrameRef m_frame;
803  agx::ref_ptr<agx::Referenced> m_customData;
804  agx::ref_ptr<agx::Referenced> m_internalData;
805  agx::observer_ptr<agx::RigidBody> m_originalBody;
806  MergeSplitProperties m_msProperties;
807 
808  // Backward compatibility
809  ShapeRefVector m_singleShapeVector;
810 
811  static ShapeRefVector s_defaultChildVector;
812  static GroupSet s_emptySet;
813  };
814 
815 
816  /* Implementation */
817 
818  AGX_FORCE_INLINE Shape *Geometry::getShape()
819  {
820  return m_shape;
821  }
822 
823  AGX_FORCE_INLINE const Shape *Geometry::getShape() const
824  {
825  return const_cast<Geometry *>( this )->getShape();
826  }
827 
829  {
830  return m_entity;
831  }
832  AGX_FORCE_INLINE agx::RigidBody *Geometry::getRigidBody()
833  {
834  return m_rigidBody;
835  }
836 
837  AGX_FORCE_INLINE const agx::RigidBody *Geometry::getRigidBody() const
838  {
839  return m_rigidBody;
840  }
841 
842  AGX_FORCE_INLINE agx::Int64 Geometry::getId() const
843  {
844  return m_id;
845  }
846 
847  AGX_FORCE_INLINE bool Geometry::isEnabled() const
848  {
849  return m_entity.state().enabled();
850  }
851 
852  AGX_FORCE_INLINE bool Geometry::isSensor() const
853  {
854  return m_entity.state().sensor();
855  }
856 
857  inline bool Geometry::isSensorGeneratingContactData() const
858  {
859  return !m_entity.state().booleanSensor();
860  }
861 
862  AGX_FORCE_INLINE agx::UInt32 Geometry::getSweepAndPruneIndex() const
863  {
864  return m_entity.sweepAndPruneIndex();
865  }
866 
867  AGX_FORCE_INLINE bool Geometry::hasGroup( agx::UInt32 id ) const
868  {
869  return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), id);
870  }
871 
872  AGX_FORCE_INLINE bool Geometry::hasGroup( const agx::Name& name ) const
873  {
874  return CollisionGroupManager::hasGroup(m_entity.collisionGroupSet(), name);
875  }
876 
877  AGX_FORCE_INLINE const agx::Physics::CollisionGroupSetPtr& Geometry::getGroupSet() const
878  {
879  return m_entity.collisionGroupSet();
880  }
881 
882  AGX_FORCE_INLINE const agx::Material *Geometry::getMaterial() const
883  {
884  return m_material;
885  }
886 
887  AGX_FORCE_INLINE agx::Material *Geometry::getMaterial()
888  {
889  return m_material;
890  }
891 
892  AGX_FORCE_INLINE void Geometry::setSurfaceVelocity( const agx::Vec3f& surfaceVelocity )
893  {
894  m_entity.surfaceVelocity() = surfaceVelocity;
895  }
896 
897  AGX_FORCE_INLINE const agx::Vec3f& Geometry::getSurfaceVelocity( ) const
898  {
899  return m_entity.surfaceVelocity();
900  }
901 
902  AGX_FORCE_INLINE void Geometry::setOriginalBody( agx::RigidBody *body )
903  {
904  m_originalBody = body;
905  }
906 
907  AGX_FORCE_INLINE agx::RigidBody* Geometry::getOriginalBody( )
908  {
909  return m_originalBody.get() ? m_originalBody.get() : m_rigidBody;
910  }
911 
912  AGX_FORCE_INLINE const agx::RigidBody* Geometry::getOriginalBody( ) const
913  {
914  return m_originalBody.get() ? m_originalBody.get() : m_rigidBody;
915  }
916 
917  AGX_FORCE_INLINE bool Geometry::getEnable() const
918  {
919  return m_entity.state().enabled();
920  }
921 
922  AGX_FORCE_INLINE Space* Geometry::getSpace()
923  {
924  return m_space;
925  }
926  AGX_FORCE_INLINE const Space* Geometry::getSpace() const
927  {
928  return m_space;
929  }
930 
931  AGX_FORCE_INLINE agx::Frame* Geometry::getFrame()
932  {
933  return m_frame.get();
934  }
935 
936  AGX_FORCE_INLINE const agx::Frame* Geometry::getFrame() const
937  {
938  return m_frame.get();
939  }
940 
941  AGX_FORCE_INLINE const BoundingAABB* Geometry::getBoundingVolume() const
942  {
943  return &m_entity.boundingAABB();
944  }
945 
946 
947  AGX_FORCE_INLINE agx::PropertyContainer* Geometry::getPropertyContainer()
948  {
949  if ( !m_propertyContainer )
950  m_propertyContainer = new agx::PropertyContainer;
951  return m_propertyContainer;
952  }
953 
954  AGX_FORCE_INLINE bool Geometry::hasPropertyContainer() const
955  {
956  return ( m_propertyContainer.isValid() );
957  }
958 
959  AGX_FORCE_INLINE const agx::PropertyContainer* Geometry::getPropertyContainer() const
960  {
961  if ( !m_propertyContainer )
962  m_propertyContainer = new agx::PropertyContainer;
963 
964  return m_propertyContainer;
965  }
966 
967  AGX_FORCE_INLINE agx::Vec3f Geometry::calculateSurfaceVelocity( const agxCollide::LocalContactPoint& /* point */, size_t /* index */) const
968  {
969  return getSurfaceVelocity();
970  }
971 
972  AGX_FORCE_INLINE Geometry::MergeSplitProperties& Geometry::getMergeSplitProperties()
973  {
974  return m_msProperties;
975  }
976  AGX_FORCE_INLINE const Geometry::MergeSplitProperties& Geometry::getMergeSplitProperties() const
977  {
978  return m_msProperties;
979  }
980 
981  AGX_FORCE_INLINE void Geometry::MergeSplitProperties::setEnableSplit( bool flag )
982  {
983  m_flags[ENABLE_SPLIT] = flag;
984  }
985  AGX_FORCE_INLINE bool Geometry::MergeSplitProperties::getEnableSplit( ) const
986  {
987  return m_flags[ENABLE_SPLIT];
988  }
989 
990  AGX_FORCE_INLINE void Geometry::MergeSplitProperties::setEnableMerge( bool flag )
991  {
992  m_flags[ENABLE_MERGE] = flag;
993  }
994 
995  AGX_FORCE_INLINE bool Geometry::MergeSplitProperties::getEnableMerge( ) const
996  {
997  return m_flags[ENABLE_MERGE];
998  }
999 
1000  AGX_FORCE_INLINE void Geometry::MergeSplitProperties::setForceSplitInPreStep( bool flag )
1001  {
1002  m_flags[FORCE_SPLIT_IN_PRE] = flag;
1003  }
1004 
1005  AGX_FORCE_INLINE bool Geometry::MergeSplitProperties::getForceSplitInPreStep( ) const
1006  {
1007  return m_flags[FORCE_SPLIT_IN_PRE];
1008  }
1009 
1010 
1011  AGX_FORCE_INLINE agx::AffineMatrix4x4 Geometry::getTransform() const
1012  {
1013  if (m_rigidBody)
1014  return m_entity.transform();
1015  else
1016  return m_frame->getMatrix();
1017 
1018  }
1019 
1020  AGX_FORCE_INLINE agx::Vec3 Geometry::getPosition() const
1021  {
1022  if (m_rigidBody)
1023  return m_entity.transform().getTranslate();
1024  else
1025  return m_frame->getTranslate();
1026  }
1027 
1028  AGX_FORCE_INLINE agx::Quat Geometry::getRotation() const
1029  {
1030  if (m_rigidBody)
1031  return m_entity.transform().getRotate();
1032  return m_frame->getRotate();
1033  }
1034 
1035  AGX_FORCE_INLINE void Geometry::updateFrameStorage()
1036  {
1038  }
1039 
1040  inline agx::Referenced* Geometry::getInternalData() const
1041  {
1042  return m_internalData;
1043  }
1044 } // namespace agxCollide
int64_t Int64
Definition: Integer.h:46
void AGXPHYSICS_EXPORT init()
Initialize agx.
Inheritance with partial specialization due to bug with ref_ptr containers.
Definition: HashSet.h:665
AffineMatrix4x4T< Real > AffineMatrix4x4
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:73
Base class for a shape.
Definition: Shape.h:53
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:63
#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:77
agx::ref_ptr< Frame > FrameRef
Definition: Frame.h:52
static agxData::ScalarAttributeT< agx::AffineMatrix4x4 > * localTransformAttribute
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
Representation of a name string.
Definition: Name.h:32
agx::Event1< Geometry * > ShapeChangeEvent
Definition: Geometry.h:91
#define AGX_FORCE_INLINE
Definition: Object.h:62
GLenum GLuint id
Definition: gl.h:5539
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:113
ShapeChangeEvent shapeChangeEvent
Definition: Geometry.h:92
The geometry representation used by the collision detection engine.
Definition: Geometry.h:88
This class is a combined container which has the find complexity of a HashTable, deterministic iterat...
Definition: HashVector.h:40
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:72
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
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
void getRotate(T &angle, T &x, T &y, T &z) const
Get the angle and vector components represented by the quaternion.
agx::HashSet< const Geometry * > GeometryHashSet
Definition: Geometry.h:78
Specify MergeSplit properties for a Geometry.
Definition: Geometry.h:675
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:52
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:384
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:206
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:311
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
Referenced()
Default constructor.
uint32_t UInt32
Definition: Integer.h:40
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:101
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:100
AGXCORE_EXPORT EntityModel * getEntity(const agx::Path &path)
Get a entity with a specified path.
Specialized types of matrices for holding orthogonal transformation matrices.