Moby
CollisionDetection.h
1 /****************************************************************************
2  * Copyright 2005 Evan Drumwright
3  * This library is distributed under the terms of the Apache V2.0
4  * License (obtainable from http://www.apache.org/licenses/LICENSE-2.0).
5  ****************************************************************************/
6 
7 #ifndef _COLLISION_DETECTION_H
8 #define _COLLISION_DETECTION_H
9 
10 #include <map>
11 #include <set>
12 #include <Ravelin/VectorNd.h>
13 #include <Ravelin/Pose3d.h>
14 #include <Ravelin/sorted_pair>
15 #include <Moby/Base.h>
16 #include <Moby/PairwiseDistInfo.h>
17 #include <Moby/CollisionGeometry.h>
18 #include <Moby/UnilateralConstraint.h>
19 #include <Moby/RigidBody.h>
20 
21 namespace Moby {
22 
23 class ConstraintSimulator;
24 class ArticulatedBody;
25 class CollisionGeometry;
26 class Triangle;
27 class IndexedTriArray;
28 
30 
38 class CollisionDetection : public virtual Base
39 {
40  public:
42  virtual ~CollisionDetection() {}
43  virtual void set_simulator(boost::shared_ptr<ConstraintSimulator> sim) {}
44  virtual void broad_phase(double dt, const std::vector<ControlledBodyPtr>& bodies, std::vector<std::pair<CollisionGeometryPtr, CollisionGeometryPtr> >& to_check);
45  virtual double calc_CA_Euler_step(const PairwiseDistInfo& pdi) = 0;
46  virtual void find_contacts(CollisionGeometryPtr cgA, CollisionGeometryPtr cgB, std::vector<UnilateralConstraint>& contacts, double TOL = NEAR_ZERO) = 0;
47 
50  {
51  return CollisionGeometry::calc_signed_dist(cg1, cg2, p1, p2);
52  }
53 
55  boost::shared_ptr<CollisionDetection> get_this() { return boost::dynamic_pointer_cast<CollisionDetection>(shared_from_this()); }
56 
57  protected:
58  virtual double calc_next_CA_Euler_step(const PairwiseDistInfo& pdi) = 0;
59  static UnilateralConstraint create_contact(CollisionGeometryPtr a, CollisionGeometryPtr b, const Point3d& point, const Ravelin::Vector3d& normal, double violation = 0.0);
60 
61  friend class ConstraintStabilization;
62 }; // end class
63 
64 } // end namespace Moby
65 
66 #endif
67 
Defines an abstract collision detection mechanism.
Definition: CollisionDetection.h:38
Class from which all Moby classes are derived.
Definition: Base.h:20
static UnilateralConstraint create_contact(CollisionGeometryPtr a, CollisionGeometryPtr b, const Point3d &point, const Ravelin::Vector3d &normal, double violation=0.0)
Creates a contact constraint given the bare-minimum info.
Definition: CollisionDetection.cpp:57
boost::shared_ptr< CollisionDetection > get_this()
Get the shared pointer for this.
Definition: CollisionDetection.h:55
virtual void broad_phase(double dt, const std::vector< ControlledBodyPtr > &bodies, std::vector< std::pair< CollisionGeometryPtr, CollisionGeometryPtr > > &to_check)
Default broad phase function (checks everything)
Definition: CollisionDetection.cpp:28
virtual double calc_signed_dist(CollisionGeometryPtr cg1, CollisionGeometryPtr cg2, Point3d &p1, Point3d &p2)
Calculates the signed distance between two geometries.
Definition: CollisionDetection.h:49
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
Projected constraint stabilization mechanism.
Definition: ConstraintStabilization.h:21
Container class for describing a unilateral constraint in the simulation.
Definition: UnilateralConstraint.h:27
static double calc_signed_dist(CollisionGeometryPtr a, CollisionGeometryPtr b, Point3d &cpa, Point3d &cpb)
Calculates the signed distances between two geometries and returns closest points if geometries are n...
Definition: CollisionGeometry.cpp:237
Structure for storing the pairwise distance between pointers to two CollisionGeometry objects...
Definition: PairwiseDistInfo.h:15