AGX Dynamics  2.38.0.2
FractureGenerator.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_FRACTURESIMULATOR_H
18 #define AGXMODEL_FRACTURESIMULATOR_H
19 
20 #include <agxModel/export.h>
21 #include <agx/Referenced.h>
25 #include <agxCollide/Geometry.h>
26 #include <agx/Random.h>
27 
28 namespace agxModel
29 {
75  {
76  public:
79 
80  public:
85 
86  public:
91 
97  bool addBreakable(agxCollide::Geometry* geometry);
98 
104  bool addBreakable(agx::RigidBody* body);
105 
111  bool removeBreakable(agxCollide::Geometry* geometry);
112 
118  bool removeBreakable(agx::RigidBody* body);
119 
123  bool isBreakable(const agxCollide::Geometry* geometry) const;
124 
129  void setFractureMinimumSize(agx::Real minsize);
130 
135  void setGlobalFractureEnable(bool enable);
136 
138  bool getGlobalBreakageEnable() const;
139 
141  void setAddFractureFragmentsToGenerator(bool enable);
142 
149  bool addBreaker(agxCollide::Geometry* geom);
150 
157  bool addBreaker(agx::RigidBody* body);
158 
164  bool removeBreaker(agxCollide::Geometry* geom);
165 
170  bool removeBreaker(agx::RigidBody* body);
171 
178  bool addBreakerFilter(agxSDK::ExecuteFilter* filter);
179 
186  bool setNumFractureFragmentsInterval(agx::UInt min, agx::UInt max);
187 
192  void setFractureAlgorithm(FractureAlgorithm* algorithm);
193 
197  void setResolution(agx::Real resolution);
198 
202  agx::Real getResolution() const;
203 
208  void setNewBodyCallback(NewBodyCallback callback);
209 
214  void setNewBodyCallbackWrapper(NewBodyCallbackWrapper* newBodyCallback);
215 
222  static bool extractFractureGenerators(
223  agxModel::FractureGeneratorPtrVector& fractureGenerators, agxSDK::Simulation* simulation);
224 
230  ConvexVector fractureShape( const agxCollide::Shape* shape );
231 
236  void addNotification() override;
237 
241  void removeNotification() override;
242 
248  virtual void preCollide(const agx::TimeStamp& time) override;
249 
255  virtual void pre(const agx::TimeStamp& time) override;
256 
262  virtual void post(const agx::TimeStamp& time) override;
263 
269  {
270  public:
272 
280  virtual void onNewBody(agxModel::FractureGenerator* fractureListener, agxCollide::Geometry* fractureGeomety, agx::RigidBody *body) = 0;
281 
282  protected:
284  };
285 
290  {
291  public:
292  NewBodyCallbackWrapperLambda(const NewBodyCallback& newBodyCallback) { m_newBodyCallback = newBodyCallback; }
293 
301  virtual void onNewBody(agxModel::FractureGenerator* fractureListener, agxCollide::Geometry* fractureGeomety, agx::RigidBody *body) override final
302  {
303  m_newBodyCallback(fractureListener, fractureGeomety, body);
304  }
305 
306  protected:
308 
309  private:
310  FractureGenerator::NewBodyCallback m_newBodyCallback;
311  };
312 
314 
315  protected:
316  virtual ~FractureGenerator();
317 
318  void handleContacts(const agxCollide::GeometryContactPtrVector& contacts);
319 
320  ConvexVector fractureShape(const agxCollide::Shape* shape, size_t numPoints);
321 
322  void updateContactListener();
323 
324  bool shapeSupportsFracture(const agxCollide::Shape* shape) const;
325 
326  bool isBreaker(agxCollide::Geometry* breaker) const;
327 
328  private:
329  bool addBreakerInternal(agxCollide::Geometry* geom);
330  bool removeBreakerInternal(agxCollide::Geometry* geom);
331 
332  protected:
336  {
337  public:
339 
340  virtual KeepContactPolicy impact(const agx::TimeStamp& t, agxCollide::GeometryContact* cd) override;
341  virtual KeepContactPolicy contact(const agx::TimeStamp& t, agxCollide::GeometryContact* cd) override;
342  virtual void separation(const agx::TimeStamp& t, agxCollide::GeometryPair& pair) override;
343 
344  void clearBreakageContacts();
345  agxCollide::GeometryContactPtrVector& getBreakageContacts();
346 
347  protected:
348  virtual ~FractureContactGatherer();
350  };
351 
355  {
356  public:
357  virtual bool match(const agxCollide::GeometryContact& contact) const override;
358  virtual bool match(const agxCollide::GeometryPair& geometryPair) const override;
360 
361  void addFilter(agxSDK::ExecuteFilter* filter);
362 
363  protected:
364  virtual ~ContactFilter() {}
365 
366  private:
368  };
369 
371  // Variables
373  private:
374  GeometryHashContainer m_breakableGeometries;
375  GeometryHashContainer m_breakerGeometries;
376  ExecuteFilterHashContainer m_breakerCollisionFilters;
377  bool m_enableGlobalFracture;
378  bool m_addFractureFragmentsToGenerator;
379  agx::Real m_minSizeToBreak;
380  agx::RangeUInt m_numFragmentsRange;
381  FractureAlgorithmRef m_fractureAlgorithm;
382  agx::UniformIntGenerator m_pointGenerator;
383  agxCollide::VoronoiGeneratorRef m_voronoiGenerator;
384  FractureContactGathererRef m_contactGatherer;
385  NewBodyCallbackWrapperRef m_newBodyCallbackWrapper;
386  };
387 
392  {
393  public:
403  virtual bool shouldFracture(agxModel::FractureGenerator* fractureListener,
405  agxCollide::Geometry* geometryToFracture);
406 
407 #ifndef SWIG
411 #endif //SWIG
412 
413  protected:
414  virtual ~FractureAlgorithm(){};
415  };
416 
422  {
423  public:
425 
434  virtual bool shouldFracture(agxModel::FractureGenerator* fractureListener,
436  agxCollide::Geometry* geometryToFracture) override;
437 
438 #ifndef SWIG
440 #endif
441  };
442 
448  {
449  public:
450  FractureAlgorithmBreakOnContactForce(agx::Real contactForceToBreak);
451 
460  virtual bool shouldFracture(agxModel::FractureGenerator* fractureListener,
462  agxCollide::Geometry* geometryToFracture) override;
463 
464 #ifndef SWIG
466 #endif
467 
468  protected:
470 
472  };
473 
479  {
480  public:
481  FractureAlgorithmBreakOnStress(agx::Real stressLevelToBreak);
482 
491  virtual bool shouldFracture(agxModel::FractureGenerator* fractureListener,
493  agxCollide::Geometry* geometryToFracture) override;
494 
495 #ifndef SWIG
497 #endif
498 
499  protected:
501 
503  };
504 
506  {
507  m_enableGlobalFracture = enable;
508  }
509 
511  {
512  return m_enableGlobalFracture;
513  }
514 
516  {
517  m_addFractureFragmentsToGenerator = enable;
518  }
519 
521  {
522  m_fractureAlgorithm = algorithm;
523  }
524 
526  {
527  return m_breakableGeometries.find(const_cast<agxCollide::Geometry*>(geometry)) != m_breakableGeometries.end();
528  }
529 
531  {
532  return m_breakageContacts;
533  }
534 
537  {
538  m_newBodyCallbackWrapper = newBodyCallback;
539  }
540 }
541 
542 
543 
544 #endif // AGXMODEL_FRACTURESIMULATOR_H
agxModel::FractureGenerator::getGlobalBreakageEnable
bool getGlobalBreakageEnable() const
Get true/false if ALL contacts in the simulation should trigger possible fractures of breakable geome...
Definition: FractureGenerator.h:510
agxModel::FractureAlgorithmBreakOnContact
Definition: FractureGenerator.h:421
agx::UInt
uint64_t UInt
Definition: Integer.h:27
Referenced.h
agx::Real
double Real
Definition: Real.h:42
agxModel::FractureGenerator::NewBodyCallbackWrapperLambda::onNewBody
virtual void onNewBody(agxModel::FractureGenerator *fractureListener, agxCollide::Geometry *fractureGeomety, agx::RigidBody *body) override final
Function that will be called in the fracture generator for each new rigid body fragment that are crea...
Definition: FractureGenerator.h:301
agxSDK::ExecuteFilter::match
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Definition: ExecuteFilter.h:109
agxModel
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:36
agxSDK::StepEventListener
Derive from this class to implement a listener for simulation step events.
Definition: StepEventListener.h:37
agxData::GeometryPair
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:65
agxModel::FractureAlgorithmBreakOnContactForce::m_contactForceToBreak
agx::Real m_contactForceToBreak
Definition: FractureGenerator.h:471
agx::Vector
Templated vector class.
Definition: Vector.h:52
agxModel::FractureGenerator::ContactFilter::~ContactFilter
virtual ~ContactFilter()
Definition: FractureGenerator.h:364
agx::RigidBody
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:51
agxModel::FractureGenerator::NewBodyCallbackWrapper
Base Abstract class for encapsulating a callback that is executed on new fragments that are created i...
Definition: FractureGenerator.h:268
agxStream::Serializable
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
export.h
agxModel::FractureGenerator::NewBodyCallbackWrapperLambda
Class for encapsulating a lambda that that will execute on new fragments created in the fracture gene...
Definition: FractureGenerator.h:289
DOXYGEN_END_INTERNAL_BLOCK
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
Geometry.h
agxModel::FractureAlgorithmBreakOnContact::FractureAlgorithmBreakOnContact
FractureAlgorithmBreakOnContact()
Definition: FractureGenerator.h:424
agxSDK::ExecuteFilter
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:33
DOXYGEN_START_INTERNAL_BLOCK
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
agxModel::FractureGenerator::NewBodyCallbackWrapper::NewBodyCallbackWrapper
NewBodyCallbackWrapper()
Definition: FractureGenerator.h:271
agxModel::FractureGenerator::FractureContactGatherer
FractureContactGatherer - Will gather relevant contact in the simulation, i.e. between breakers and b...
Definition: FractureGenerator.h:335
agxModel::FractureGenerator::NewBodyCallbackWrapperLambda::~NewBodyCallbackWrapperLambda
virtual ~NewBodyCallbackWrapperLambda()
Definition: FractureGenerator.h:307
agxModel::FractureGenerator::setFractureAlgorithm
void setFractureAlgorithm(FractureAlgorithm *algorithm)
Sets the FractureAlgorithm used in the fracture logic.
Definition: FractureGenerator.h:520
StepEventListener.h
AGXSTREAM_DECLARE_SERIALIZABLE
#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
agx::VectorPOD
Vector containing 'raw' data.
Definition: Vector.h:245
agxModel::FractureGenerator::GeometryHashContainer
agx::HashVector< agxCollide::GeometryRef > GeometryHashContainer
Definition: FractureGenerator.h:81
agxModel::FractureGenerator::setAddFractureFragmentsToGenerator
void setAddFractureFragmentsToGenerator(bool enable)
Set true/false if fragments generated by fracture should be included as breakable objects....
Definition: FractureGenerator.h:515
agxModel::FractureAlgorithm
Class for encapsulating fracture conditions for generating fractures in a breakable object.
Definition: FractureGenerator.h:391
AGX_DECLARE_VECTOR_TYPES
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
agx::ref_ptr< FractureAlgorithm >
agxSDK::Simulation
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:125
agxCollide::Shape
Base class for a shape.
Definition: Shape.h:53
agxModel::FractureGenerator
Definition: FractureGenerator.h:74
agx::min
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:861
agx::RandomGenerator
Definition: Random.h:30
agxSDK::ContactEventListener::KeepContactPolicy
KeepContactPolicy
Defines whether contact should be kept or removed after contact/impact methods returns.
Definition: ContactEventListener.h:59
agxModel::FractureGenerator::isBreakable
bool isBreakable(const agxCollide::Geometry *geometry) const
Returns true/false if the specified geometry is registered as a breakable object in the fracture logi...
Definition: FractureGenerator.h:525
agxCollide::Geometry
The geometry representation used by the collision detection engine.
Definition: Geometry.h:91
agxModel::FractureAlgorithm::FractureAlgorithm
FractureAlgorithm()
Definition: FractureGenerator.h:394
agxModel::FractureAlgorithm::~FractureAlgorithm
virtual ~FractureAlgorithm()
Definition: FractureGenerator.h:414
agxModel::FractureGenerator::ExecuteFilterHashContainer
agx::HashVector< agxSDK::ExecuteFilterRef > ExecuteFilterHashContainer
Definition: FractureGenerator.h:82
agxModel::FractureGenerator::setNewBodyCallbackWrapper
void setNewBodyCallbackWrapper(NewBodyCallbackWrapper *newBodyCallback)
Adds a class instance that holds a callback that will be called for every rigid body fragment created...
Definition: FractureGenerator.h:535
agxModel::FractureGenerator::FractureContactGatherer::m_breakageContacts
agxCollide::GeometryContactPtrVector m_breakageContacts
Definition: FractureGenerator.h:349
agxModel::FractureGenerator::setGlobalFractureEnable
void setGlobalFractureEnable(bool enable)
Set true/false if ALL contacts in the simulation should trigger possible fractures of breakable geome...
Definition: FractureGenerator.h:505
agxModel::FractureGenerator::ConvexVector
agx::Vector< agxCollide::Convex * > ConvexVector
Definition: FractureGenerator.h:83
agxModel::FractureGenerator::NewBodyCallbackWrapper::~NewBodyCallbackWrapper
virtual ~NewBodyCallbackWrapper()
Definition: FractureGenerator.h:283
agxModel::FractureGenerator::FractureContactGatherer::getBreakageContacts
agxCollide::GeometryContactPtrVector & getBreakageContacts()
Definition: FractureGenerator.h:530
agxModel::FractureGenerator::ContactFilter
Definition: FractureGenerator.h:354
agx::Referenced
Base class providing referencing counted objects.
Definition: Referenced.h:119
AGX_DECLARE_POINTER_TYPES
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
agxModel::FractureGenerator::NewBodyCallback
std::function< void(FractureGenerator *, agxCollide::Geometry *, agx::RigidBody *)> NewBodyCallback
Definition: FractureGenerator.h:84
ContactEventListener.h
agxCollide::GeometryContact
A contact between two geometries.
Definition: Contacts.h:270
agx::TimeStamp
agx::Real TimeStamp
Definition: TimeStamp.h:26
VoronoiGenerator.h
Random.h
AGXMODEL_EXPORT
#define AGXMODEL_EXPORT
Definition: agxModel/export.h:42
agxModel::FractureAlgorithmBreakOnStress
Definition: FractureGenerator.h:478
agxModel::FractureAlgorithmBreakOnStress::m_stressLevelToBreak
agx::Real m_stressLevelToBreak
Definition: FractureGenerator.h:502
agx::Range
A range object has a min and max value of a given type and provides services to tell whether a value ...
Definition: Range.h:79
agx::max
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:855
agxModel::FractureAlgorithmBreakOnContactForce
Definition: FractureGenerator.h:447
agx::HashVector< agxCollide::GeometryRef >
agxModel::FractureGenerator::NewBodyCallbackWrapperLambda::NewBodyCallbackWrapperLambda
NewBodyCallbackWrapperLambda(const NewBodyCallback &newBodyCallback)
Definition: FractureGenerator.h:292
AGX_FORCE_INLINE
#define AGX_FORCE_INLINE
Definition: macros.h:58
agxSDK::ContactEventListener
Derive from this class to implement a listener for Collision events.
Definition: ContactEventListener.h:44