AGX Dynamics  2.35.0.1
FractureGenerator.h
Go to the documentation of this file.
1 /*
2 Copyright 2007-2022. 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 
98 
105 
112 
119 
123  bool isBreakable(const agxCollide::Geometry* geometry) const;
124 
130 
135  void setGlobalFractureEnable(bool enable);
136 
138  bool getGlobalBreakageEnable() const;
139 
141  void setAddFractureFragmentsToGenerator(bool enable);
142 
150 
158 
165 
171 
179 
187 
192  void setFractureAlgorithm(FractureAlgorithm* algorithm);
193 
197  void setResolution(agx::Real resolution);
198 
203 
209 
214  void setNewBodyCallbackWrapper(NewBodyCallbackWrapper* newBodyCallback);
215 
223  agxModel::FractureGeneratorPtrVector& fractureGenerators, agxSDK::Simulation* simulation);
224 
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:
317 
319 
320  ConvexVector fractureShape(const agxCollide::Shape* shape, size_t numPoints);
321 
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 
342  virtual void separation(const agx::TimeStamp& t, agxCollide::GeometryPair& pair) override;
343 
345  agxCollide::GeometryContactPtrVector& getBreakageContacts();
346 
347  protected:
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 
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:
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:
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
#define AGX_DECLARE_POINTER_TYPES(type)
Definition: Referenced.h:248
#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
A contact between two geometries.
Definition: Contacts.h:270
The geometry representation used by the collision detection engine.
Definition: Geometry.h:93
Base class for a shape.
Definition: Shape.h:54
virtual bool shouldFracture(agxModel::FractureGenerator *fractureListener, agxCollide::GeometryContact *gc, agxCollide::Geometry *geometryToFracture) override
Function that is overridden by child classes to evaluate if a contact fulfills the condition for crea...
FractureAlgorithmBreakOnContactForce(agx::Real contactForceToBreak)
virtual bool shouldFracture(agxModel::FractureGenerator *fractureListener, agxCollide::GeometryContact *gc, agxCollide::Geometry *geometryToFracture) override
Function that is overridden by child classes to evaluate if a contact fulfills the condition for crea...
FractureAlgorithmBreakOnStress(agx::Real stressLevelToBreak)
virtual bool shouldFracture(agxModel::FractureGenerator *fractureListener, agxCollide::GeometryContact *gc, agxCollide::Geometry *geometryToFracture) override
Function that is overridden by child classes to evaluate if a contact fulfills the condition for crea...
Class for encapsulating fracture conditions for generating fractures in a breakable object.
virtual bool shouldFracture(agxModel::FractureGenerator *fractureListener, agxCollide::GeometryContact *gc, agxCollide::Geometry *geometryToFracture)
Function that is overridden by child classes to evaluate if a contact fulfills the condition for crea...
virtual bool match(const agxCollide::GeometryPair &geometryPair) const override
Called once when narrow phase no longer finds overlaps between the two geometries.
void addFilter(agxSDK::ExecuteFilter *filter)
virtual bool match(const agxCollide::GeometryContact &contact) const override
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
FractureContactGatherer - Will gather relevant contact in the simulation, i.e. between breakers and b...
agxCollide::GeometryContactPtrVector m_breakageContacts
virtual void separation(const agx::TimeStamp &t, agxCollide::GeometryPair &pair) override
Called upon separation event if getFilter() contain SEPARATION.
virtual KeepContactPolicy impact(const agx::TimeStamp &t, agxCollide::GeometryContact *cd) override
Called upon impact event if getFilter() contain IMPACT.
agxCollide::GeometryContactPtrVector & getBreakageContacts()
virtual KeepContactPolicy contact(const agx::TimeStamp &t, agxCollide::GeometryContact *cd) override
Called upon contact event if getFilter() contain CONTACT.
Class for encapsulating a lambda that that will execute on new fragments created in the fracture gene...
NewBodyCallbackWrapperLambda(const NewBodyCallback &newBodyCallback)
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...
Base Abstract class for encapsulating a callback that is executed on new fragments that are created i...
virtual void onNewBody(agxModel::FractureGenerator *fractureListener, agxCollide::Geometry *fractureGeomety, agx::RigidBody *body)=0
Function that will be called in the fracture generator for each new rigid body fragment that are crea...
bool removeBreaker(agx::RigidBody *body)
Removes all the rigid body's geometries as a 'breakers' from the fracture logic.
bool isBreaker(agxCollide::Geometry *breaker) const
bool removeBreaker(agxCollide::Geometry *geom)
Removes a geometry as a 'breaker' in the fracture logic.
std::function< void(FractureGenerator *, agxCollide::Geometry *, agx::RigidBody *)> NewBodyCallback
ConvexVector fractureShape(const agxCollide::Shape *shape)
Utility function to fracture an arbitrary shape with existing FractureGenerator settings.
agx::HashVector< agxCollide::GeometryRef > GeometryHashContainer
bool addBreaker(agx::RigidBody *body)
Adds the specified rigid body's geometries as a 'breakers' in the fracture logic.
bool getGlobalBreakageEnable() const
Get true/false if ALL contacts in the simulation should trigger possible fractures of breakable geome...
void handleContacts(const agxCollide::GeometryContactPtrVector &contacts)
agx::Real getResolution() const
Get resolution for plane tessellation in Voronoi diagram of basic primitives such as Spheres,...
agx::HashVector< agxSDK::ExecuteFilterRef > ExecuteFilterHashContainer
void removeNotification() override
Called when this listener is removed from the simulation.
void setAddFractureFragmentsToGenerator(bool enable)
Set true/false if fragments generated by fracture should be included as breakable objects....
void setResolution(agx::Real resolution)
Set resolution for plane tessellation in Voronoi diagram of basic primitives such as Spheres,...
void setFractureAlgorithm(FractureAlgorithm *algorithm)
Sets the FractureAlgorithm used in the fracture logic.
bool isBreakable(const agxCollide::Geometry *geometry) const
Returns true/false if the specified geometry is registered as a breakable object in the fracture logi...
bool addBreakable(agx::RigidBody *body)
Adds all the geometries inside the rigid body as breakable objects.
void addNotification() override
Called when this listener is added to the simulation.
bool removeBreakable(agxCollide::Geometry *geometry)
Removes a geometry as a breakable object from the fracture logic.
bool addBreaker(agxCollide::Geometry *geom)
Adds a geometry as a 'breaker' in the fracture logic.
static bool extractFractureGenerators(agxModel::FractureGeneratorPtrVector &fractureGenerators, agxSDK::Simulation *simulation)
Utility function to extract all FractureGeneratos from an simulation (and its sub-simulation).
bool shapeSupportsFracture(const agxCollide::Shape *shape) const
bool addBreakerFilter(agxSDK::ExecuteFilter *filter)
Adds a contact filter that governs what types of contacts that should trigger a fracture.
void setGlobalFractureEnable(bool enable)
Set true/false if ALL contacts in the simulation should trigger possible fractures of breakable geome...
virtual void pre(const agx::TimeStamp &time) override
Called before a step is taken in the simulation Implement this method in the derived class to get cal...
void setNewBodyCallbackWrapper(NewBodyCallbackWrapper *newBodyCallback)
Adds a class instance that holds a callback that will be called for every rigid body fragment created...
void setNewBodyCallback(NewBodyCallback callback)
Adds a callback that will be called for every rigid body fragment created in a fracture event.
bool addBreakable(agxCollide::Geometry *geometry)
Adds a geometry as a breakable object to the fracture listener.
bool removeBreakable(agx::RigidBody *body)
Removes all the geometries inside the rigid body as breakable objects in the fracture logic.
agx::Vector< agxCollide::Convex * > ConvexVector
ConvexVector fractureShape(const agxCollide::Shape *shape, size_t numPoints)
virtual void post(const agx::TimeStamp &time) override
Called after a step is taken in the simulation Implement this method in the derived class to get call...
void setFractureMinimumSize(agx::Real minsize)
Sets the minimum size that allows fracture of an object, derived from it's bounding box.
virtual void preCollide(const agx::TimeStamp &time) override
Called before collision detection is performed in the simulation Implement this method in the derived...
FractureGenerator()
Default constructor.
bool setNumFractureFragmentsInterval(agx::UInt min, agx::UInt max)
Sets the interval of possible fragments that can be created when a geometry is fractured.
Derive from this class to implement a listener for Collision events.
KeepContactPolicy
Defines whether contact should be kept or removed after contact/impact methods returns.
Abstract base class that implements a filter that selects which events should trigger a Listener.
Definition: ExecuteFilter.h:35
virtual bool match(const agxCollide::GeometryContact &gc) const
Called when narrow phase tests have determined overlap (when we have detailed intersection between th...
Simulation is a class that bridges the collision space agxCollide::Space and the dynamic simulation s...
Definition: Simulation.h:127
Derive from this class to implement a listener for simulation step events.
This class is an abstract base class for all classes that can be stored and retrieved from an Archive...
Definition: Serializable.h:45
A range object has a min and max value of a given type and provides services to tell whether a value ...
Definition: Range.h:80
Base class providing referencing counted objects.
Definition: Referenced.h:114
The rigid body class, combining a geometric model and a frame of reference.
Definition: RigidBody.h:55
Vector containing 'raw' data.
Definition: agx/Vector.h:246
Templated vector class.
Definition: agx/Vector.h:53
#define DOXYGEN_END_INTERNAL_BLOCK()
Definition: macros.h:97
#define DOXYGEN_START_INTERNAL_BLOCK()
Definition: macros.h:96
#define AGX_FORCE_INLINE
Definition: macros.h:58
agx::SymmetricPair< agx::Physics::GeometryPtr > GeometryPair
Definition: Geometry.h:66
Contain classes for higher level modeling primitives, such as Tree, Terrain etc.
Definition: FlowUnit.h:37
Vec3T< T > min(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:880
uint32_t UInt
Definition: Integer.h:34
double Real
Definition: Real.h:42
Vec3T< T > max(const Vec3T< T > &lhs, const Vec3T< T > &rhs)
Definition: Vec3Template.h:874
agx::Real TimeStamp
Definition: TimeStamp.h:26