AGX Dynamics 2.42.1.1
Loading...
Searching...
No Matches
DeformableObject.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
22
24
26
28
29namespace agxModel
30{
33
38 {
39 public:
40 using SingleTetrahedronPositions = std::array<agx::Vec3, 4u>;
41
42 public:
47 static constexpr agx::Real DefaultVertexMergeDistance = DTetrahedronMesh::DefaultVertexMergeDistance;
48
49 public:
53 struct TetrahedronType {};
54
58 struct BoxType {};
59
63 struct SphereType {};
64
68 struct CylinderType {};
69
73 struct CapsuleType {};
74
78 struct ConeType {};
79
83 struct TetGenType {};
84
89
93 struct SurfaceType {};
94
98 struct ConvexMeshType {};
99
110 static constexpr TetrahedronType Tetrahedron{};
111
117 static constexpr BoxType Box{};
118
126 static constexpr SphereType Sphere{};
127
136 static constexpr CylinderType Cylinder{};
137
146 static constexpr CapsuleType Capsule{};
147
157 static constexpr ConeType Cone{};
158
167 static constexpr TetGenType TetGen{};
168
180
189 static constexpr SurfaceType Surface{};
190
200 static constexpr ConvexMeshType ConvexMesh{};
201
202 public:
214 BeamModelProperties* properties = nullptr,
215 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
216
231 agx::Real radius,
232 agx::Real resolution,
233 BeamModelProperties* properties = nullptr,
234 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
235
246 agx::Vec3 halfExtents,
247 BeamModelProperties* properties = nullptr,
248 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
249
266 agx::Real radius,
267 agx::Real length,
268 agx::Real resolution,
269 BeamModelProperties* properties = nullptr,
270 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
271
288 agx::Real radius,
289 agx::Real length,
290 agx::Real resolution,
291 BeamModelProperties* properties = nullptr,
292 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
293
311 agx::Real topRadius,
312 agx::Real bottomRadius,
313 agx::Real height,
314 agx::Real resolution,
315 BeamModelProperties* properties = nullptr,
316 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
317
330 agx::String filename,
331 agx::Vec3 scale = agx::Vec3( 1.0, 1.0, 1.0 ),
332 BeamModelProperties* properties = nullptr,
333 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
334
350 agx::Vec3 startPosition,
351 agx::Vec3 endPosition,
352 agx::Real width,
353 agx::Real height,
354 size_t numSegments,
355 BeamModelProperties* properties = nullptr,
356 agx::Vec3 worldUpAxis = agx::Vec3::Z_AXIS() );
357
369 const agxCollide::HeightField* heightfield,
370 agx::Real baseThickness,
371 BeamModelProperties* properties = nullptr,
372 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
373
387 agx::String filename,
388 agx::Vec3 scale = agx::Vec3( 1.0, 1.0, 1.0 ),
389 BeamModelProperties* properties = nullptr,
390 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
391
403 agxCollide::Mesh* mesh,
404 BeamModelProperties* properties = nullptr,
405 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
406
419 const agx::Vec3Vector& convexVertices,
420 const agx::UInt32Vector& convexTriangles,
421 BeamModelProperties* properties = nullptr,
422 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
423
428
432 static const DeformableObject* get( const agxCollide::Geometry* geometry );
433
438
442 static const DeformableObject* get( const agx::RigidBody* rb );
443
450 static DeformableObject* find( const agxSDK::Simulation* simulation, const agx::Name& name );
451
458 static DeformableObject* find( const agxSDK::Simulation* simulation, const agx::Uuid& uuid );
459
466
474
475 public:
482 DeformableObject( BeamModelProperties* properties = nullptr,
483 agx::Real vertexMergeDistance = DefaultVertexMergeDistance );
484
489
493 const DTetrahedronMesh& getMesh() const;
494
498 bool isInitialized() const;
499
504
509
518 void setRigidVelocity( const agx::Vec3& linearVelocity, const agx::Vec3& angularVelocity );
519
525
530
536 bool add( IDeformableAlgorithm* algorithm );
537
543 bool remove( IDeformableAlgorithm* algorithm );
544
551
555 template<typename T>
556 T* getAlgorithm() const;
557
562
572 DVertexElement findClosestSurfaceVertex( const agx::Vec3& worldPoint, bool viaEdge = false ) const;
573
583 DVertexElement findClosestVertex( const agx::Vec3& worldPoint, bool viaEdge = false ) const;
584
590 DeformableObjectReferenceDataRef getReferenceData() const;
591
592 public:
598 virtual bool initialize();
599
603 virtual agx::Material* getMaterial() const;
604
609 virtual void setMaterial( agx::Material* material );
610
614 virtual agx::UInt32 getUniqueId() const;
615
620
626 virtual void setEnableCollisions( agx::RigidBody* rb, bool enable );
627
631 virtual bool getEnableCollisions( const agx::RigidBody* rb ) const;
632
638 virtual void setEnableCollisions( agxCollide::Geometry* geometry, bool enable );
639
643 virtual bool getEnableCollisions( const agxCollide::Geometry* geometry ) const;
644
649 virtual void addGroup( agx::UInt32 id );
650
655 virtual void removeGroup( agx::UInt32 id );
656
660 virtual bool hasGroup( agx::UInt32 id ) const;
661
666 virtual void addGroup( const agx::Name& name );
667
672 virtual void removeGroup( const agx::Name& name );
673
677 virtual bool hasGroup( const agx::Name& name ) const;
678
686
693
695
696 public:
697 using agxSDK::Assembly::add;
698 using agxSDK::Assembly::remove;
699
700 using agxSDK::Assembly::addNotification;
701 using agxSDK::Assembly::removeNotification;
702
703 virtual void addNotification( agxSDK::Simulation* simulation ) override;
704 virtual void removeNotification( agxSDK::Simulation* simulation ) override;
705
706 virtual void onPreCollideStep() override;
707 virtual void onPreStep() override;
708 virtual void onPostStep() override;
709 virtual void onLastStep() override;
710
712
713 protected:
714 using GroupId = IDeformableAlgorithm::GroupId;
715 using GroupIdVector = std::vector<GroupId>;
716
717 protected:
723 virtual void initialize( IDeformableAlgorithm& algorithm );
724
728 virtual void onMaterialNew() const;
729
733 virtual void onGroupAdd( const GroupId& group ) const;
734
738 virtual void onGroupRemove( const GroupId& group ) const;
739
743 virtual void onSetEnableCollisions( agxCollide::Geometry* geometry, bool enable ) const;
744
746
747 private:
748 struct InternalState
749 {
750 enum Flag : agx::UInt32
751 {
752 INITIALIZED = 1 << 0,
753 };
754 using Flags = agx::BitState<Flag, std::underlying_type_t<Flag>>;
755
756 inline bool initialized() const
757 {
758 return flags.Is( INITIALIZED );
759 }
760
761 Flags flags;
762 };
763
764 private:
765 friend class agx::InternalData;
769 agx::Referenced* getInternalData() const;
770
774 void setInternalData( agx::Referenced* data );
775
776 private:
777 InternalState m_state;
778 agx::Uuid m_uniqueId;
779 agx::Uuid m_disabledCollisionsId;
780 GroupIdVector m_collisionGroups;
781 agx::MaterialRef m_material;
782 BeamModelPropertiesRef m_properties;
783 DeformableObjectReferenceDataRef m_referenceData;
784 DTetrahedronMesh m_mesh;
786 agx::ref_ptr<agx::Referenced> m_internalData;
787 };
788
789 template<typename T>
791 {
792 for ( auto&& algorithm : m_algorithms )
793 if ( algorithm->template is<T>() )
794 return algorithm->template as<T>();
795 return nullptr;
796 }
797
798 inline agx::Referenced* DeformableObject::getInternalData() const
799 {
800 return m_internalData;
801 }
802}
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
#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
#define AGXMODEL_EXPORT
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: agx/Vector.h:34
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
A HeightField is a collision shape that can be created from a grid structure, like an image.
Mesh is a common base class for triangle meshes, such as Mesh or HeightField.
Definition: Mesh.h:70
Bulk beam model properties present in all agxModel::BeamModel instances, which in turn propagates the...
Deformable tetrahedron mesh representation, containing a data registry with the vertex position and c...
Vertex element with access to the initial and current position.
Deformable object containing a tetrahedron mesh and a set of algorithms.
static DeformableObject * get(agxCollide::Geometry *geometry)
const DTetrahedronMesh & getMesh() const
static DeformableObject * find(const agxSDK::Simulation *simulation, const agx::Uuid &uuid)
Find deformable instance given simulation and unique id.
DVertexElement findClosestSurfaceVertex(const agx::Vec3 &worldPoint, bool viaEdge=false) const
Linear search through all surface vertices of this deformable object to find the closest surface vert...
virtual agx::Vec2Vector calculateSurfaceTextureCoordinates2D() const
Calculates the texture coordinates u, v <-> [0, 1] for each surface vertex using object space box/pla...
virtual void removeGroup(const agx::Name &name)
Remove group name from this deformable object.
static DeformableObjectRef create(ConvexMeshType tag, agxCollide::Mesh *mesh, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create given mesh instance.
static DeformableObjectRef create(CapsuleType tag, agx::Real radius, agx::Real length, agx::Real resolution, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create deformable capsule of given radius, length and resolution.
DTetrahedronMesh & getMesh()
std::array< agx::Vec3, 4u > SingleTetrahedronPositions
static DeformableObjectRef create(ConvexMeshType tag, agx::String filename, agx::Vec3 scale=agx::Vec3(1.0, 1.0, 1.0), BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create given supported mesh file format (note that tetgen has its own overload).
static agxModel::DeformableObjectPtrVector findAll(const agxSDK::Simulation *simulation, const agx::Name &name)
Finds all deformable instances given simulation and name.
virtual bool hasGroup(const agx::Name &name) const
static DeformableObjectRef create(SurfaceType tag, const agxCollide::HeightField *heightfield, agx::Real baseThickness, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create given heightfield instance and additional thickness.
virtual agx::UInt32 getDisabledCollisionGroupId() const
static DeformableObject * get(agx::RigidBody *rb)
virtual void setEnableCollisions(agxCollide::Geometry *geometry, bool enable)
Enable/disable collisions between the geometry and this deformable object.
virtual agx::UInt32 getUniqueId() const
virtual bool hasGroup(agx::UInt32 id) const
DeformableObject(BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Construct given properties.
static DeformableObjectRef create(RectangularBeamType tag, agx::Vec3 startPosition, agx::Vec3 endPosition, agx::Real width, agx::Real height, size_t numSegments, BeamModelProperties *properties=nullptr, agx::Vec3 worldUpAxis=agx::Vec3::Z_AXIS())
Reflects the function agxModel::Beam::create to create a beam with resolution segments,...
virtual agx::Vec3Vector calculateSurfaceTextureCoordinates3D() const
Calculates the texture coordinates u, v, w <-> [0, 1] for each surface vertex.
void setRigidVelocity(const agx::Vec3 &linearVelocity, const agx::Vec3 &angularVelocity)
Calculates individual vertex velocities given input rigid linear- and angular velocity.
static const DeformableObject * get(const agxCollide::Geometry *geometry)
virtual void addGroup(agx::UInt32 id)
Add group id to this deformable object.
static DeformableObject * find(const agxSDK::Simulation *simulation, const agx::Name &name)
Find deformable instance given simulation and name.
bool add(IDeformableAlgorithm *algorithm)
Associate a deformable algorithm to this deformable object.
virtual bool getEnableCollisions(const agx::RigidBody *rb) const
DVertexElement findClosestVertex(const agx::Vec3 &worldPoint, bool viaEdge=false) const
Linear search through all vertices of this deformable object to find the closest vertex to the given ...
virtual void addGroup(const agx::Name &name)
Add group name to this deformable object.
static agxModel::DeformableObjectPtrVector findAll(const agxSDK::Simulation *simulation)
Finds all agxModel::DeformableObject instances in the given simulation.
virtual void setMaterial(agx::Material *material)
Assign new material to this deformable object.
BeamModelProperties * getProperties() const
agx::Real getCurrentVolume() const
virtual agx::Material * getMaterial() const
IDeformableAlgorithm * getAlgorithm(const agx::Name &name) const
Finds the algorithm by its name.
static DeformableObjectRef create(TetGenType tag, agx::String filename, agx::Vec3 scale=agx::Vec3(1.0, 1.0, 1.0), BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create given TetGen files.
agx::Real getRestVolume() const
agx::Real getMass() const
static DeformableObjectRef create(BoxType tag, agx::Vec3 halfExtents, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create deformable box given half extents.
virtual bool getEnableCollisions(const agxCollide::Geometry *geometry) const
static DeformableObjectRef create(ConeType tag, agx::Real topRadius, agx::Real bottomRadius, agx::Real height, agx::Real resolution, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create deformable cone of given top- and bottom radius, height and resolution.
virtual bool initialize()
Initialize all elements of this deformable object given the mesh is valid.
static DeformableObjectRef create(TetrahedronType tag, SingleTetrahedronPositions positions, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Creates a single deformable tetrahedron given four initial node positions.
static DeformableObjectRef create(SphereType tag, agx::Real radius, agx::Real resolution, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create deformable sphere given radius and resolution.
agx::Vec3 getCmPosition() const
Calculates, and returns the current center of mass of this deformable.
virtual void setEnableCollisions(agx::RigidBody *rb, bool enable)
Enable/disable collisions between the rigid body and this deformable object.
static DeformableObjectRef create(CylinderType tag, agx::Real radius, agx::Real length, agx::Real resolution, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create deformable cylinder of given radius, length and resolution.
static const DeformableObject * get(const agx::RigidBody *rb)
virtual void removeGroup(agx::UInt32 id)
Remove group id from this deformable object.
DeformableObjectReferenceDataRef getReferenceData() const
Objects (e.g., bodies, geometries) of this deformable should be associated to this instance via this ...
static DeformableObjectRef create(ConvexMeshType tag, const agx::Vec3Vector &convexVertices, const agx::UInt32Vector &convexTriangles, BeamModelProperties *properties=nullptr, agx::Real vertexMergeDistance=DefaultVertexMergeDistance)
Create given convex mesh vertices and triangles.
bool remove(IDeformableAlgorithm *algorithm)
Remove a deformable algorithm from this deformable object.
Interface for features of deformable objects, e.g., geometry, constraints, contact model etc.
Rectangular cross section beam model with a given width and height.
Definition: BeamModel.h:358
Representation of an implementation of a deformable object in agxSDK::Simulation.
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:131
Internal data for any object, ObjT, with methods: agx::Referenced* ObjT::getInternalData() const; voi...
Definition: InternalData.h:33
Main material class which acts as a holder of a Surface Material and a Bulk material.
Definition: Material.h:378
Representation of a name string.
Definition: Name.h:33
Base class providing referencing counted objects.
Definition: Referenced.h:120
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:49
A UUID, or Universally unique identifier, is intended to uniquely identify information in a distribut...
Definition: Uuid.h:42
static Vec3T Z_AXIS()
Definition: Vec3Template.h:783
Smart pointer for handling referenced counted objects.
Definition: ref_ptr.h:30
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:89
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:88
This namespace consists of a set of classes for handling geometric intersection tests including boole...
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: Space.h:63
The agxSDK namespace contain classes to bridge the collision detection system and the dynamical simul...
Definition: Constraint.h:31
uint32_t UInt32
Definition: Integer.h:32
double Real
Definition: Real.h:41
STL namespace.
Six tetrahedron mesh box type overload.
Capsule tetrahedron mesh type overload.
Cone tetrahedron mesh type overload.
Generic convex mesh type overload.
Cylindrical tetrahedron mesh type overload.
Rectangular beam model type overload.
Spherical tetrahedron mesh type overload.
Surface model type overload.
Single tetrahedron type overload.