chrono::collision::ChModelBullet Class Reference

Description

A wrapper to use the Bullet collision detection library.

#include <ChCModelBullet.h>

Inheritance diagram for chrono::collision::ChModelBullet:
Collaboration diagram for chrono::collision::ChModelBullet:

Public Member Functions

virtual int ClearModel ()
 Deletes all inserted geometries. More...
 
virtual int BuildModel ()
 Builds the BV hierarchy. More...
 
virtual bool AddSphere (double radius, const ChVector<> &pos=ChVector<>())
 Add a sphere shape to this model, for collision purposes.
 
virtual bool AddEllipsoid (double rx, double ry, double rz, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add an ellipsoid shape to this model, for collision purposes.
 
virtual bool AddBox (double hx, double hy, double hz, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a box shape to this model, for collision purposes.
 
virtual bool AddCylinder (double rx, double rz, double hy, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a cylinder to this model (default axis on Y direction), for collision purposes.
 
virtual bool AddCone (double rx, double rz, double hy, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a cylinder to this model (default axis on Y direction), for collision purposes.
 
virtual bool AddCapsule (double radius, double hlen, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a capsule to this model (default axis in Y direction), for collision purposes.
 
virtual bool AddRoundedBox (double hx, double hy, double hz, double sphere_r, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a rounded box shape to this model, for collision purposes.
 
virtual bool AddRoundedCylinder (double rx, double rz, double hy, double sphere_r, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a rounded cylinder to this model (default axis on Y direction), for collision purposes.
 
virtual bool AddRoundedCone (double rx, double rz, double hy, double sphere_r, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a rounded cone to this model (default axis on Y direction), for collision purposes.
 
virtual bool AddConvexHull (std::vector< ChVector< double >> &pointlist, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a convex hull to this model. More...
 
virtual bool AddTriangleMesh (const geometry::ChTriangleMesh &trimesh, bool is_static, bool is_convex, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1), double sphereswept_thickness=0.0)
 Add a triangle mesh to this model, passing a triangle mesh (do not delete the triangle mesh until the collision model, because depending on the implementation of inherited ChCollisionModel classes, maybe the triangle is referenced via a striding interface or just copied) Note: if possible, in sake of high performance, avoid triangle meshes and prefer simplified representations as compounds of convex shapes of boxes/spheres/etc. More...
 
virtual bool AddTriangleMeshConcave (const geometry::ChTriangleMesh &trimesh, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 CUSTOM for this class only: add a concave triangle mesh that will be managed by GImpact mesh-mesh algorithm. More...
 
virtual bool AddTriangleMeshConcaveDecomposed (ChConvexDecomposition &mydecomposition, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 CUSTOM for this class only: add a concave triangle mesh that will be decomposed into a compound of convex shapes. More...
 
virtual bool AddBarrel (double Y_low, double Y_high, double R_vert, double R_hor, double R_offset, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a barrel-like shape to this model (main axis on Y direction), for collision purposes. More...
 
virtual bool Add2Dpath (geometry::ChLinePath &mpath, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1), const double thickness=0.001)
 Add a 2D closed line, defined on the XY plane passing by pos and aligned as rot, that defines a 2D collision shape that will collide with another 2D line of the same type if aligned on the same plane. More...
 
virtual bool AddPoint (double radius=0, const ChVector<> &pos=ChVector<>())
 Add a point-like sphere, that will collide with other geometries, but won't ever create contacts between them. More...
 
virtual bool AddTriangleProxy (ChVector<> *p1, ChVector<> *p2, ChVector<> *p3, ChVector<> *ep1, ChVector<> *ep2, ChVector<> *ep3, bool mowns_vertex_1, bool mowns_vertex_2, bool mowns_vertex_3, bool mowns_edge_1, bool mowns_edge_2, bool mowns_edge_3, double msphereswept_rad=0)
 Add a triangle from mesh. More...
 
virtual bool AddCopyOfAnotherModel (ChCollisionModel *another)
 Add all shapes already contained in another model. More...
 
virtual void SetFamily (int mfamily)
 By default, all collision objects belong to family n.0, but you can set family in range 0..15. More...
 
virtual int GetFamily ()
 
virtual void SetFamilyMaskNoCollisionWithFamily (int mfamily)
 By default, family mask is all turned on, so all families can collide with this object, but you can turn on-off some bytes of this mask so that some families do not collide. More...
 
virtual void SetFamilyMaskDoCollisionWithFamily (int mfamily)
 
virtual bool GetFamilyMaskDoesCollisionWithFamily (int mfamily)
 Tells if the family mask of this collision object allows for the collision with another collision object belonging to a given family. More...
 
virtual void SetFamilyGroup (short group)
 Set the collision family group of this model. More...
 
virtual void SetFamilyMask (short mask)
 Set the collision mask for this model. More...
 
virtual void GetAABB (ChVector<> &bbmin, ChVector<> &bbmax) const
 Returns the axis aligned bounding box (AABB) of the collision model, i.e. More...
 
virtual void SyncPosition ()
 Sets the position and orientation of the collision model as the current position of the corresponding ChContactable.
 
bool SetSphereRadius (double coll_radius, double out_envelope)
 If the collision shape is a sphere, resize it and return true (if no sphere is found in this collision shape, return false). More...
 
virtual void ArchiveOUT (ChArchiveOut &marchive)
 Method to allow serialization of transient data to archives.
 
virtual void ArchiveIN (ChArchiveIn &marchive)
 Method to allow deserialization of transient data from archives.
 
btCollisionObject * GetBulletModel ()
 Return the pointer to the Bullet model.
 
- Public Member Functions inherited from chrono::collision::ChCollisionModel
virtual bool AddConvexHull (std::vector< ChVector< double > > &pointlist, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))=0
 Add a convex hull to this model. More...
 
virtual bool AddConvexHullsFromFile (ChStreamInAscii &mstream, const ChVector<> &pos=ChVector<>(), const ChMatrix33<> &rot=ChMatrix33<>(1))
 Add a cluster of convex hulls by a '.chulls' file description. More...
 
ChContactableGetContactable ()
 Gets the pointer to the contactable object.
 
virtual void SetContactable (ChContactable *mc)
 Sets the pointer to the contactable object. More...
 
virtual ChPhysicsItemGetPhysicsItem ()
 Gets the pointer to the client owner ChPhysicsItem. More...
 
virtual short int GetFamilyGroup () const
 Return the collision family group of this model. More...
 
virtual void SetFamilyGroup (short int group)
 Set the collision family group of this model. More...
 
virtual short int GetFamilyMask () const
 Return the collision mask for this model. More...
 
virtual void SetFamilyMask (short int mask)
 Set the collision mask for this model. More...
 
virtual void SetSafeMargin (double amargin)
 Sets the suggested collision 'inward safe margin' for the shapes to be added from now on, using the AddBox, AddCylinder etc (where, if this margin is too high for some thin or small shapes, it may be clamped). More...
 
virtual float GetSafeMargin ()
 Returns the inward safe margin (see SetSafeMargin() )
 
virtual void SetEnvelope (double amargin)
 Sets the suggested collision outward 'envelope' (used from shapes added, from now on, to this collision model). More...
 
virtual float GetEnvelope ()
 Returns the outward safe margin (see SetEnvelope() )
 

Protected Attributes

btCollisionObject * bt_collision_object
 
std::vector< std::shared_ptr< btCollisionShape > > shapes
 
- Protected Attributes inherited from chrono::collision::ChCollisionModel
float model_envelope
 
float model_safe_margin
 
ChContactablemcontactable
 
short int family_group
 
short int family_mask
 

Additional Inherited Members

- Static Public Member Functions inherited from chrono::collision::ChCollisionModel
static void SetDefaultSuggestedEnvelope (double menv)
 Using this function BEFORE you start creating collision shapes, it will make all following collision shapes to take this collision envelope (safe outward layer) as default. More...
 
static void SetDefaultSuggestedMargin (double mmargin)
 Using this function BEFORE you start creating collision shapes, it will make all following collision shapes to take this collision margin (inward penetration layer) as default. More...
 
static double GetDefaultSuggestedEnvelope ()
 
static double GetDefaultSuggestedMargin ()
 
- Protected Member Functions inherited from chrono::collision::ChCollisionModel
virtual float GetSuggestedFullMargin ()
 

Member Function Documentation

bool chrono::collision::ChModelBullet::Add2Dpath ( geometry::ChLinePath mpath,
const ChVector<> &  pos = ChVector<>(),
const ChMatrix33<> &  rot = ChMatrix33<>(1),
const double  thickness = 0.001 
)
virtual

Add a 2D closed line, defined on the XY plane passing by pos and aligned as rot, that defines a 2D collision shape that will collide with another 2D line of the same type if aligned on the same plane.

This is useful for mechanisms that work on a plane, and that require more precise collision that is not possible with current 3D shapes. For example, the line can contain concave or convex round fillets. Requirements:

  • the line must be clockwise for inner material, (counterclockwise=hollow, material outside)
  • the line must contain only ChLineSegment and ChLineArc sub-lines
  • the sublines must follow in the proper order, with coincident corners, and must be closed.

Reimplemented from chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::AddBarrel ( double  Y_low,
double  Y_high,
double  R_vert,
double  R_hor,
double  R_offset,
const ChVector<> &  pos = ChVector<>(),
const ChMatrix33<> &  rot = ChMatrix33<>(1) 
)
virtual

Add a barrel-like shape to this model (main axis on Y direction), for collision purposes.

The barrel shape is made by lathing an arc of an ellipse around the vertical Y axis. The center of the ellipse is on Y=0 level, and it is offsetted by R_offset from the Y axis in radial direction. The two radii of the ellipse are R_vert (for the vertical direction, i.e. the axis parallel to Y) and R_hor (for the axis that is perpendicular to Y). Also, the solid is clamped with two discs on the top and the bottom, at levels Y_low and Y_high.

Implements chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::AddConvexHull ( std::vector< ChVector< double >> &  pointlist,
const ChVector<> &  pos = ChVector<>(),
const ChMatrix33<> &  rot = ChMatrix33<>(1) 
)
virtual

Add a convex hull to this model.

A convex hull is simply a point cloud that describe a convex polytope. Connectivity between the vertexes, as faces/edges in triangle meshes is not necessary. Points are passed as a list, that is instantly copied into the model.

bool chrono::collision::ChModelBullet::AddCopyOfAnotherModel ( ChCollisionModel another)
virtual

Add all shapes already contained in another model.

Thank to the adoption of shared pointers, underlying shapes are shared (not copied) among the models; this will save memory when you must simulate thousands of objects with the same collision shape. The 'another' model must be of ChModelBullet subclass.

Implements chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::AddPoint ( double  radius = 0,
const ChVector<> &  pos = ChVector<>() 
)
virtual

Add a point-like sphere, that will collide with other geometries, but won't ever create contacts between them.

Parameters
radiusthe radius of the node
posthe position of the node in model coordinates

Reimplemented from chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::AddTriangleMesh ( const geometry::ChTriangleMesh trimesh,
bool  is_static,
bool  is_convex,
const ChVector<> &  pos = ChVector<>(),
const ChMatrix33<> &  rot = ChMatrix33<>(1),
double  sphereswept_thickness = 0.0 
)
virtual

Add a triangle mesh to this model, passing a triangle mesh (do not delete the triangle mesh until the collision model, because depending on the implementation of inherited ChCollisionModel classes, maybe the triangle is referenced via a striding interface or just copied) Note: if possible, in sake of high performance, avoid triangle meshes and prefer simplified representations as compounds of convex shapes of boxes/spheres/etc.

Add a triangle mesh to this model.

. type.

Implements chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::AddTriangleMeshConcave ( const geometry::ChTriangleMesh trimesh,
const ChVector<> &  pos = ChVector<>(),
const ChMatrix33<> &  rot = ChMatrix33<>(1) 
)
virtual

CUSTOM for this class only: add a concave triangle mesh that will be managed by GImpact mesh-mesh algorithm.

Note that, despite this can work with arbitrary meshes, there could be issues of robustness and precision, so when possible, prefer simplified representations as compounds of convex shapes of boxes/spheres/etc.. type.

bool chrono::collision::ChModelBullet::AddTriangleMeshConcaveDecomposed ( ChConvexDecomposition mydecomposition,
const ChVector<> &  pos = ChVector<>(),
const ChMatrix33<> &  rot = ChMatrix33<>(1) 
)
virtual

CUSTOM for this class only: add a concave triangle mesh that will be decomposed into a compound of convex shapes.

Decomposition could be more efficient than AddTriangleMeshConcave(), but preprocessing decomposition might take a while, and decomposition result is often approximate. Therefore, despite this can work with arbitrary meshes, there could be issues of robustness and precision, so when possible, prefer simplified representations as compounds of convex shapes of boxes/spheres/etc.. type.

bool chrono::collision::ChModelBullet::AddTriangleProxy ( ChVector<> *  p1,
ChVector<> *  p2,
ChVector<> *  p3,
ChVector<> *  ep1,
ChVector<> *  ep2,
ChVector<> *  ep3,
bool  mowns_vertex_1,
bool  mowns_vertex_2,
bool  mowns_vertex_3,
bool  mowns_edge_1,
bool  mowns_edge_2,
bool  mowns_edge_3,
double  msphereswept_rad = 0 
)
virtual

Add a triangle from mesh.

For efficiency, points are stored as pointers. Thus, the user must take care of memory management and of dangling pointers.

Parameters
p1points to vertex1 coords
p2points to vertex2 coords
p3points to vertex3 coords
ep1points to neighbouring vertex at edge1 if any
ep2points to neighbouring vertex at edge1 if any
ep3points to neighbouring vertex at edge1 if any
mowns_vertex_1vertex is owned by this triangle (otherwise, owned by neighbour)
mowns_vertex_2vertex is owned by this triangle (otherwise, owned by neighbour)
mowns_vertex_3vertex is owned by this triangle (otherwise, owned by neighbour)
mowns_edge_1edge is owned by this triangle (otherwise, owned by neighbour)
mowns_edge_2edge is owned by this triangle (otherwise, owned by neighbour)
mowns_edge_3edge is owned by this triangle (otherwise, owned by neighbour)
msphereswept_radsphere swept triangle ('fat' triangle, improves robustness)
int chrono::collision::ChModelBullet::BuildModel ( )
virtual

Builds the BV hierarchy.

Call this function AFTER adding the geometric description. MUST be inherited by child classes! (ex for building BV hierarchies)

Implements chrono::collision::ChCollisionModel.

int chrono::collision::ChModelBullet::ClearModel ( )
virtual

Deletes all inserted geometries.

Also, if you begin the definition of a model, AFTER adding the geometric description, remember to call the ClearModel(). MUST be inherited by child classes! (ex for resetting also BV hierarchies)

Implements chrono::collision::ChCollisionModel.

void chrono::collision::ChModelBullet::GetAABB ( ChVector<> &  bbmin,
ChVector<> &  bbmax 
) const
virtual

Returns the axis aligned bounding box (AABB) of the collision model, i.e.

max-min along the x,y,z world axes. Remember that SyncPosition() should be invoked before calling this.

Implements chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::GetFamilyMaskDoesCollisionWithFamily ( int  mfamily)
virtual

Tells if the family mask of this collision object allows for the collision with another collision object belonging to a given family.

NOTE: this function has NO effect if used before you add the body to a ChSystem, using AddBody(). Use after AddBody(). This default implementation uses the family mask.

Reimplemented from chrono::collision::ChCollisionModel.

void chrono::collision::ChModelBullet::SetFamily ( int  mfamily)
virtual

By default, all collision objects belong to family n.0, but you can set family in range 0..15.

This is used when the objects collided with another: the contact is created only if the family is within the 'family mask' of the other, and viceversa. NOTE: these functions have NO effect if used before you add the body to a ChSystem, using AddBody(). Use after AddBody(). These default implementations use the family group.

Reimplemented from chrono::collision::ChCollisionModel.

void chrono::collision::ChModelBullet::SetFamilyGroup ( short  group)
virtual

Set the collision family group of this model.

This is an alternative way of specifying the collision family for this object. The value family_group must have a single bit set (i.e. it must be a power of 2). The corresponding family is then the bit position.

void chrono::collision::ChModelBullet::SetFamilyMask ( short  mask)
virtual

Set the collision mask for this model.

Any set bit in the specified mask indicates that this model collides with all objects whose family is equal to the bit position.

void chrono::collision::ChModelBullet::SetFamilyMaskNoCollisionWithFamily ( int  mfamily)
virtual

By default, family mask is all turned on, so all families can collide with this object, but you can turn on-off some bytes of this mask so that some families do not collide.

When two objects collide, the contact is created only if the family is within the 'family mask' of the other, and viceversa. NOTE: these functions have NO effect if used before you add the body to a ChSystem, using AddBody(). Use after AddBody(). These default implementations use the family mask.

Reimplemented from chrono::collision::ChCollisionModel.

bool chrono::collision::ChModelBullet::SetSphereRadius ( double  coll_radius,
double  out_envelope 
)

If the collision shape is a sphere, resize it and return true (if no sphere is found in this collision shape, return false).

It can also change the outward envelope; the inward margin is automatically the radius of the sphere.