AGX Dynamics  2.37.3.2
Deformable1DGeometryFactory.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 AGXMODEL_DEFORMABLE1DGEOMETRYFACTORY_H
18 #define AGXMODEL_DEFORMABLE1DGEOMETRYFACTORY_H
19 
21 
22 #include <agxCollide/Sphere.h>
23 
25 #include <agxStream/InputArchive.h>
26 
27 namespace agxModel
28 {
34 
41  {
42  public:
48  virtual agxCollide::GeometryRef createGeometry(const agxModel::Deformable1DNode* node) = 0;
49 
53  virtual agx::Real getWidth(const agxModel::Deformable1DNode* node) const = 0;
54 
58  virtual agx::Real getHeight(const agxModel::Deformable1DNode* node) const = 0;
59 
64  virtual agx::Real getOverlappingDistance(const agxModel::Deformable1DNode* /*node*/) const;
65 
67 
68  protected:
72  virtual ~Deformable1DGeometryFactory();
73  };
74 
79  {
80  public:
87 
88  public:
92  virtual agxCollide::GeometryRef createGeometry(const agxModel::Deformable1DNode* node) override;
93 
97  virtual agx::Real getWidth(const agxModel::Deformable1DNode* node) const override;
98 
102  virtual agx::Real getHeight(const agxModel::Deformable1DNode* node) const override;
103 
105 
106  protected:
111 
116 
117  protected:
120  };
121 
125  template< typename T >
127  {
128  public:
134 
138  agx::Real getRadius() const;
139 
140  public:
146  virtual agxCollide::GeometryRef createGeometry(const agxModel::Deformable1DNode* node) override;
147 
151  virtual agx::Real getWidth(const agxModel::Deformable1DNode* node) const override;
152 
156  virtual agx::Real getHeight(const agxModel::Deformable1DNode* node) const override;
157 
158  void store( agxStream::OutputArchive& out ) const override;
159  void restore( agxStream::InputArchive& in ) override;
160 
161  protected:
166 
171 
172  protected:
174  };
175 
176 #ifdef SWIG
177  %template(Deformable1DRadiusGeometryFactoryCapsule) agxModel::Deformable1DRadiusGeometryFactory<agxCollide::Capsule>;
178  %template(Deformable1DRadiusGeometryFactoryCylinder) agxModel::Deformable1DRadiusGeometryFactory<agxCollide::Cylinder>;
179  %template(Deformable1DRadiusGeometryFactorySphere) agxModel::Deformable1DRadiusGeometryFactory<agxCollide::Sphere>;
180 #endif
181 
186  {
187  public:
193 
194  public:
198  virtual agx::Real getOverlappingDistance(const agxModel::Deformable1DNode* node) const override;
199 
201 
202  protected:
207 
212  };
213 
218  {
219  public:
225 
227 
228  protected:
233 
238  };
239 
244  {
245  public:
251 
252  public:
256  virtual agx::Real getOverlappingDistance(const agxModel::Deformable1DNode* node) const override;
257 
259 
260  protected:
265 
270  };
271 
272  template< typename T >
274  {
275  }
276 
277  template< typename T >
279  : m_radius( radius )
280  {
281  }
282 
283  template< typename T >
285  {
286  }
287 
288  template< typename T >
290  {
291  return m_radius;
292  }
293 
294  template< typename T >
296  {
297  return agx::Real( 2 ) * getRadius();
298  }
299 
300  template< typename T >
302  {
303  return agx::Real( 2 ) * getRadius();
304  }
305 
306  template<>
308  {
309  if ( node == nullptr )
310  return agxCollide::GeometryRef( nullptr );
311 
312  // Maybe input?
313  const agx::Real offset = getRadius();
314 
315  const agx::UInt numSpheres = std::max( agx::UInt( node->getLength() / offset + agx::Real( 0.5 ) ), agx::UInt( 1 ) );
316  const agx::Real dl = node->getLength() / agx::Real( numSpheres );
318  agx::Vec3 pos( 0, 0, 0 );
320  for ( agx::UInt i = 0; i < numSpheres; ++i ) {
321  geometry->add( new agxCollide::Sphere( getRadius() ), agx::AffineMatrix4x4::translate( pos ) );
322  pos += dl * dir;
323  }
324 
325  return geometry;
326  }
327 
328  template< typename T >
330  {
331  if ( node == nullptr )
332  return agxCollide::GeometryRef( nullptr );
333 
334  agxCollide::GeometryRef geometry = new agxCollide::Geometry( new T( getRadius(), node->getLength() ) );
335  geometry->setLocalTransform( agx::AffineMatrix4x4::rotate( agx::Vec3::Y_AXIS(), agx::Vec3::Z_AXIS() ) *
337 
338  return geometry;
339  }
340 
341  template< typename T >
343  {
344  out << agxStream::out( "radius", m_radius );
345  }
346 
347  template< typename T >
349  {
350  in >> agxStream::in( "radius", m_radius );
351  }
352 }
353 
354 #endif // AGXMODEL_DEFORMABLE1DGEOMETRYFACTORY_H
InputRef< T > in(const char *name, T &obj)
Create an object with a name and a reference to the object that should be restored (usually a pointer...
Definition: InputArchive.h:400
Geometry factor for boxes of given width and height.
OutputRef< Serializable > out(const char *name, const Serializable *obj)
Return an object that contain the name and the object that should be serialized to an archive...
static AffineMatrix4x4T< Real > translate(const Vec3T< Real > &dv)
Return a matrix which translates according to dv.
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:855
static AffineMatrix4x4T< Real > rotate(const Vec3T< Real > &from, const Vec3T< Real > &to)
Return a matrix which rotate a vector from from to to.
Deformable1DRadiusGeometryFactory()
Default constructor for serialization.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
Base class providing referencing counted objects.
Definition: Referenced.h:119
static Vec3T Z_AXIS()
Definition: Vec3Template.h:783
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
The geometry representation used by the collision detection engine.
Definition: Geometry.h:92
Geometry factory that creates Cylinders with given radius.
uint32_t UInt
Definition: Integer.h:34
static Vec3T Y_AXIS()
Definition: Vec3Template.h:777
A sphere class for geometric intersection tests.
Definition: Sphere.h:31
Class for reading a binary stream of serialized data.
Definition: InputArchive.h:51
Geometry factory that creates Capsules with given radius.
agx::Real getLength() const
#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
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Class for writing serialized data in binary format to a stream.
Definition: OutputArchive.h:56
Geometry factory that creates Spheres with given radius.
agx::ref_ptr< Geometry > GeometryRef
Definition: Geometry.h:78
#define AGXSTREAM_DECLARE_ABSTRACT_SERIALIZABLE(T)
Use this in a pure abstract Serializable class to add the required methods Important: Use full namesp...
Definition: Serializable.h:221
#define AGXMODEL_EXPORT
double Real
Definition: Real.h:42
Geometry factory is an object that spawns geometries for a Deformable1D object.
General geometry factory for shapes where width = height = radius.
Special node implementation of segments in e.g., a Deformable1D object.