AGX Dynamics  2.37.3.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:
84  typedef std::function<void(FractureGenerator*,agxCollide::Geometry*, agx::RigidBody*)> NewBodyCallback;
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
FractureContactGatherer - Will gather relevant contact in the simulation, i.e. between breakers and b...
Class for encapsulating fracture conditions for generating fractures in a breakable object...
Base Abstract class for encapsulating a callback that is executed on new fragments that are created i...
Derive from this class to implement a listener for Collision events.
Derive from this class to implement a listener for simulation step events.
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:861
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:855
Base class for a shape.
Definition: Shape.h:53
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:66
Abstract base class that implements a filter that selects which events should trigger a Listener...
Definition: ExecuteFilter.h:33
agx::HashVector< agxCollide::GeometryRef > GeometryHashContainer
agxCollide::GeometryContactPtrVector m_breakageContacts
A contact between two geometries.
Definition: Contacts.h:270
agxCollide::GeometryContactPtrVector & getBreakageContacts()
void setFractureAlgorithm(FractureAlgorithm *algorithm)
Sets the FractureAlgorithm used in the fracture logic.
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:254
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...
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
#define AGX_FORCE_INLINE
Definition: Object.h:59
agx::Real TimeStamp
Definition: TimeStamp.h:26
Base class providing referencing counted objects.
Definition: Referenced.h:119
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
Templated vector class.
Definition: Vector.h:52
agx::HashVector< agxSDK::ExecuteFilterRef > ExecuteFilterHashContainer
uint32_t UInt
Definition: Integer.h:34
Vector containing &#39;raw&#39; data.
Definition: Vector.h:245
void setAddFractureFragmentsToGenerator(bool enable)
Set true/false if fragments generated by fracture should be included as breakable objects...
agx::Vector< agxCollide::Convex * > ConvexVector
void setGlobalFractureEnable(bool enable)
Set true/false if ALL contacts in the simulation should trigger possible fractures of breakable geome...
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
KeepContactPolicy
Defines whether contact should be kept or removed after contact/impact methods returns.
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:54
bool isBreakable(const agxCollide::Geometry *geometry) const
Returns true/false if the specified geometry is registered as a breakable object in the fracture logi...
#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
void setNewBodyCallbackWrapper(NewBodyCallbackWrapper *newBodyCallback)
Adds a class instance that holds a callback that will be called for every rigid body fragment created...
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:44
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:126
#define AGXMODEL_EXPORT
std::function< void(FractureGenerator *, agxCollide::Geometry *, agx::RigidBody *)> NewBodyCallback
double Real
Definition: Real.h:42
#define AGX_DECLARE_VECTOR_TYPES(type)
Definition: Vector.h:34
NewBodyCallbackWrapperLambda(const NewBodyCallback &newBodyCallback)
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: Object.h:98
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: Object.h:97
bool getGlobalBreakageEnable() const
Get true/false if ALL contacts in the simulation should trigger possible fractures of breakable geome...
Class for encapsulating a lambda that that will execute on new fragments created in the fracture gene...