AGX Dynamics  2.37.3.2
agxOSG/SimulationObject.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 #ifndef AGXOSG_SIMULATIONOBJECT_H
18 #define AGXOSG_SIMULATIONOBJECT_H
19 
20 #include <agxOSG/export.h>
21 
22 #include <agx/observer_ptr.h>
23 
24 #include <agx/PushDisableWarnings.h> // Disabling warnings. Include agx/PopDisableWarnings.h below!
25 #include <osg/Node>
26 #include <agx/PopDisableWarnings.h> // End of disabled warnings.
27 
29 #include <agx/Bound.h>
30 #include <agx/Material.h>
31 
32 #define DEFAULT_DETAIL_RATIO 1.0f
33 
35 
36 
37 namespace agxCollide {
38  class Geometry;
39  class Trimesh;
40 }
41 
42 namespace agx {
43  class RigidBody;
44 }
45 
46 namespace osg {
47  class Geode;
48 }
49 
50 
51 namespace agxOSG
52 {
53 
54 
55 
56 
66  class AGXOSG_EXPORT SimulationObject : public agxSDK::SimulationObject
67  {
68  public:
70  explicit SimulationObject( agxCollide::Geometry *geom, agx::RigidBody *body, osg::Node *node=nullptr ) : agxSDK::SimulationObject( geom, body), m_node( node )
71  {
72  // LOGGER_WARNING() << "SimulationObject( agxCollide::" << std::endl << LOGGER_END();
73  }
74  explicit SimulationObject( ) {
75  // LOGGER_WARNING() << "SimulationObject()" << std::endl << LOGGER_END();
76  }
77 
79 
80  ~SimulationObject() {
81  // LOGGER_WARNING() << "~SimulationObject()" << std::endl << LOGGER_END();
82  }
83 
85  SimulationObject( const SimulationObject& copy) : agxSDK::SimulationObject( copy ) {
86  m_node = copy.m_node;
87  // LOGGER_WARNING() << "SimulationObject( const SimulationObject& copy) " << std::endl << LOGGER_END();
88  }
89 
90  SimulationObject& operator= (const SimulationObject& copy )
91  {
92  if (this == &copy)
93  return *this;
94 
95 
96  this->m_geometry = copy.m_geometry;
97  this->m_body = copy.m_body;
98  m_node = copy.m_node;
99 
100  return *this;
101  }
102 
103 
104  osg::Node *getNode() { return m_node.get(); }
105 
107  operator const osg::Node *() const { return m_node.get(); }
109  operator osg::Node *() { return m_node.get(); }
110 
111  // virtual bool operator ==(const SimulationObject& obj)
112  // {
113  // return ( m_geometry.get() == obj.m_geometry.get() && m_body.get() == obj.m_body.get() && m_node.get() == obj.m_node.get());
114  // }
115 
140  static SimulationObject createBox( const agx::String& name,
142  const agx::Vec3& halfExtent,
143  osg::Group *root,
144  agxSDK::Simulation* simulation,
146  bool createGeometry=true,
147  bool createBody=true,
148  bool addAxes=false
149  );
150 
151 
177  static SimulationObject createPlane( const agx::String& name,
178  const agx::AffineMatrix4x4& transform,
179  osg::Group *root,
180  agxSDK::Simulation* simulation=nullptr,
182  bool createGeometry=true,
183  bool createBody=true
184  );
185 
214  static SimulationObject createHeightField( const agx::String& name,
215  const agx::AffineMatrix4x4& transform,
216  const agx::String& filename, const agx::Real& sizeX, const agx::Real& sizeY,
217  const agx::Real& low, const agx::Real& high,
218  osg::Group *root,
219  agxSDK::Simulation* simulation=nullptr,
221  bool createGeometry=true,
222  bool createBody=true
223  );
224 
256  static SimulationObject createHeightField( const agx::String& name,
257  const agx::AffineMatrix4x4& transform,
258  const agx::RealVector& heights,
259  size_t resolutionX,
260  size_t resolutionY,
261  agx::Real sizeX,
262  agx::Real sizeY,
263  agx::Real bottomMargin,
264  osg::Group *root,
265  agxSDK::Simulation* simulation=nullptr,
267  bool createGeometry=true,
268  bool createBody=true
269  );
270 
271 
272 
299  static SimulationObject createCylinder( const agx::String& name,
300  const agx::AffineMatrix4x4& transform,
301  agx::Real radius, agx::Real height,
302  osg::Group *root,
303  agxSDK::Simulation* simulation=nullptr,
305  bool createGeometry=true,
306  bool createBody=true,
307  bool addAxes=false
308  );
309 
335  static SimulationObject createCapsule( const agx::String& name,
336  const agx::AffineMatrix4x4& transform,
337  agx::Real radius, agx::Real height,
338  osg::Group *root,
339  agxSDK::Simulation* simulation=nullptr,
341  bool createGeometry=true,
342  bool createBody=true
343  );
344 
345 
370  static SimulationObject createSphere( const agx::String& name,
371  const agx::AffineMatrix4x4& transform,
372  agx::Real radius,
373  osg::Group *root,
374  agxSDK::Simulation* simulation=nullptr,
376  bool createGeometry=true,
377  bool createBody=true
378  );
379 
405  static SimulationObject createTrimesh( const agx::String& name,
406  const agx::AffineMatrix4x4& transform,
407  const agx::String& filename,
408  osg::Group *root,
409  agxSDK::Simulation* simulation=nullptr,
411  bool createGeometry=true,
412  bool createBody=true
413  );
414 
439  static SimulationObject createTrimesh( const agx::String& name,
440  const agx::AffineMatrix4x4& transform,
441  agxCollide::Trimesh* cloneTrimesh,
442  osg::Group *root,
443  agxSDK::Simulation* simulation=nullptr,
445  bool createGeometry=true,
446  bool createBody=true
447  );
448 
449 
475  static SimulationObject createTrimesh( const agx::String& name,
476  const agx::AffineMatrix4x4& transform,
477  const agx::String& filename,
478  agx::Real bottomMargin,
479  osg::Group *root,
480  agxSDK::Simulation* simulation=nullptr,
482  bool createGeometry=true,
483  bool createBody=true
484  );
485 
486 
487  // static agx::ParticleSystem *createParticleSystem(const agx::String& name, osg::Group *root, agxSDK::Simulation* simulation=nullptr);
488 
489  protected:
490  osg::ref_ptr<osg::Node> m_node;
491  };
492 
493 
494  AGXOSG_EXPORT agx::RigidBody *buildContainer(const agx::Bound3& bound, agx::Real thickness, agxSDK::Simulation* simulation, osg::Group *root, bool addCeiling = false, agx::Material *material = agx::Material::getDefaultMaterial(), osg::Vec4 color = osg::Vec4(0, 1, 0, 0.1f));
495 
496  // Create a osg Geode from a specified shape
497  AGXOSG_EXPORT osg::Geode* createGeode( osg::Shape *shape, const agx::String& name, float detailRatio = DEFAULT_DETAIL_RATIO );
498 
499 }
500 
502 
503 #endif /* _AGXOSG_SIMULATIONOBJECT_H_ */
#define AGXOSG_EXPORT
This namespace consists of a set of classes for handling geometric intersection tests including boole...
This body will never move.
Definition: RigidBody.h:67
Deprecated, used only for internal examples*.
Vec4T< Real > Vec4
Definition: Vec4.h:25
void AGXCORE_EXPORT transform(void *target, const Format *targetFormat, const void *source, const Format *sourceFormat, size_t numElements)
Transform data between two buffers.
AGXOSG_EXPORT agxCollide::Trimesh * createTrimesh(osg::Node *node)
Extracts mesh data from an osg::Node, creates an agxCollide::Trimesh from it and returns the result...
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
const Node * getNode(const IteratorCompatibleContainer &container, agx::Real distanceFromStart)
Finds the wire node given current distance from the start of the wire (wire defined to be iterator co...
Definition: WireUtils.h:392
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
static Material * getDefaultMaterial()
The agxOSG namespace provides functionality for visualizing AGX simulations with OpenSceneGraph.
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
This body moves from the influence of forces.
Definition: RigidBody.h:69
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
agxCollide::GeometryRef m_geometry
double Real
Definition: Real.h:42
MotionControl
The MotionControl enumeration indicates what makes a RigidBody move.
Definition: RigidBody.h:65
AGXCORE_EXPORT Component * root()
Triangle mesh for geometric intersection tests.
Definition: Trimesh.h:42
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
#define DEFAULT_DETAIL_RATIO