13 #include <boost/shared_ptr.hpp>
14 #include <Ravelin/sorted_pair>
16 #include <Moby/SpherePrimitive.h>
17 #include <Moby/TorusPrimitive.h>
18 #include <Moby/PolyhedralPrimitive.h>
19 #include <Moby/PairwiseDistInfo.h>
20 #include <Moby/HeightmapPrimitive.h>
21 #include <Moby/PlanePrimitive.h>
22 #include <Moby/BoxPrimitive.h>
23 #include <Moby/CylinderPrimitive.h>
24 #include <Moby/CollisionDetection.h>
27 #include <Moby/Polyhedron.h>
41 virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
42 virtual void save_to_xml(
XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects)
const;
43 virtual void broad_phase(
double dt,
const std::vector<ControlledBodyPtr>& bodies, std::vector<std::pair<CollisionGeometryPtr, CollisionGeometryPtr> >& to_check);
47 find_contacts(cgA, cgB, std::back_inserter(contacts), TOL);
49 static unsigned constrain_unsigned(
int ii,
int maxi){
50 return (
unsigned) std::min(std::max(ii,0),maxi);
53 template <
class OutputIterator>
65 virtual double calc_next_CA_Euler_step(
const PairwiseDistInfo& pdi) {
return calc_next_CA_Euler_step_generic(pdi); }
69 enum AxisType { eXAxis, eYAxis, eZAxis };
71 static double sqr(
double x) {
return x*x; }
72 double calc_next_CA_Euler_step_polyhedron_plane(boost::shared_ptr<PolyhedralPrimitive> p,
const Ravelin::SVelocityd& rv, boost::shared_ptr<const Ravelin::Pose3d> P,
const Ravelin::Vector3d& normal,
double offset);
73 double calc_next_CA_Euler_step_polyhedron_polyhedron(boost::shared_ptr<PolyhedralPrimitive> pA, boost::shared_ptr<PolyhedralPrimitive> pB, boost::shared_ptr<const Ravelin::Pose3d> poseA, boost::shared_ptr<const Ravelin::Pose3d> poseB,
const Ravelin::SVelocityd& rvA,
const Ravelin::SVelocityd& rvB,
const Ravelin::Vector3d& n0,
double offset);
74 virtual double calc_next_CA_Euler_step_generic(
const PairwiseDistInfo& pdi);
75 virtual double calc_CA_Euler_step_generic(
const PairwiseDistInfo& pdi);
76 virtual double calc_CA_Euler_step_sphere(
const PairwiseDistInfo& pdi);
78 static double calc_max_dist(
RigidBodyPtr rb,
const Ravelin::Vector3d& n,
double rmax);
79 static double calc_max_step(
RigidBodyPtr rbA,
RigidBodyPtr rbB,
const Ravelin::Vector3d& n,
double rmaxA,
double rmaxB,
double dist);
87 bool operator<(
const BoundsStruct& bs)
const {
return (!end && bs.end); }
91 std::map<CollisionGeometryPtr, double> _rmax;
94 bool _rebuild_bounds_vecs;
97 std::map<CollisionGeometryPtr, BVPtr> _bounding_spheres;
100 std::vector<std::pair<double, BoundsStruct> > _x_bounds;
103 std::vector<std::pair<double, BoundsStruct> > _y_bounds;
106 std::vector<std::pair<double, BoundsStruct> > _z_bounds;
109 std::map<CollisionGeometryPtr, BVPtr> _swept_BVs;
112 std::map<Ravelin::sorted_pair<CollisionGeometryPtr>,
double> _min_dist_observed;
115 void sort_AABBs(
const std::vector<RigidBodyPtr>& rigid_bodies,
double dt);
116 void update_bounds_vector(std::vector<std::pair<double, BoundsStruct> >& bounds, AxisType axis,
double dt,
bool recreate_bvs);
117 void build_bv_vector(
const std::vector<RigidBodyPtr>& rigid_bodies, std::vector<std::pair<double, BoundsStruct> >& bounds);
122 template <
class OutputIterator>
125 template <
class OutputIterator>
128 template <
class OutputIterator>
131 template <
class OutputIterator>
134 template <
class OutputIterator>
137 template <
class OutputIterator>
140 template <
class OutputIterator>
143 template <
class OutputIterator>
146 template <
class OutputIterator>
149 template <
class OutputIterator>
152 template <
class OutputIterator>
155 template <
class OutputIterator>
158 template <
class RandomAccessIterator>
159 void insertion_sort(RandomAccessIterator begin, RandomAccessIterator end);
161 template <
class OutputIterator>
162 OutputIterator find_contacts_vertex_vertex(
CollisionGeometryPtr cgA,
CollisionGeometryPtr cgB, boost::shared_ptr<Polyhedron::Vertex> v1, boost::shared_ptr<Polyhedron::Vertex> v2,
double signed_dist, OutputIterator output_begin);
164 template <
class OutputIterator>
165 OutputIterator find_contacts_vertex_edge(
CollisionGeometryPtr cgA,
CollisionGeometryPtr cgB, boost::shared_ptr<Polyhedron::Vertex> v, boost::shared_ptr<Polyhedron::Edge> e,
double signed_dist, OutputIterator output_begin);
167 template <
class OutputIterator>
168 OutputIterator find_contacts_vertex_face(
CollisionGeometryPtr cgA,
CollisionGeometryPtr cgB, boost::shared_ptr<Polyhedron::Vertex> vA, boost::shared_ptr<Polyhedron::Face> fB,
double signed_dist, OutputIterator output_begin);
170 template <
class OutputIterator>
171 OutputIterator find_contacts_edge_edge(
CollisionGeometryPtr cgA,
CollisionGeometryPtr cgB, boost::shared_ptr<Polyhedron::Edge> e1, boost::shared_ptr<Polyhedron::Edge> e2,
double signed_dist, OutputIterator output_begin);
173 template <
class OutputIterator>
174 OutputIterator find_contacts_edge_face(
CollisionGeometryPtr cgA,
CollisionGeometryPtr cgB, boost::shared_ptr<Polyhedron::Edge> eA, boost::shared_ptr<Polyhedron::Face> fB,
double signed_dist, OutputIterator output_begin);
176 template <
class OutputIterator>
177 OutputIterator find_contacts_face_face(
CollisionGeometryPtr cgA,
CollisionGeometryPtr cgB, boost::shared_ptr<Polyhedron::Face> fA, boost::shared_ptr<Polyhedron::Face> fB,
double signed_dist, OutputIterator output_begin);
Defines an abstract collision detection mechanism.
Definition: CollisionDetection.h:38
Abstract class for articulated bodies.
Definition: ArticulatedBody.h:26
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
std::set< Ravelin::sorted_pair< CollisionGeometryPtr > > disabled_pairs
Pairs of collision geometries that aren't checked for contact/collision.
Definition: CCD.h:62
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: CCD.cpp:702
Represents a single rigid body.
Definition: RigidBody.h:43
virtual double calc_CA_Euler_step(const PairwiseDistInfo &pdi)
Computes a conservative advancement step between two collision geometries assuming that velocity is c...
Definition: CCD.cpp:122
boost::shared_ptr< RigidBody > RigidBodyPtr
Rigid body smart pointer.
Definition: Types.h:62
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
Defines collision geometry that may be used (in principle) many ways: for rigid bodies, non-rigid bodies, ...
Definition: CollisionGeometry.h:36
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Implements Base::load_from_xml()
Definition: CCD.cpp:674
Implements the CollisionDetection abstract class to perform exact contact finding using abstract shap...
Definition: CCD.h:36
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Implements Base::save_to_xml()
Definition: CCD.cpp:690
boost::shared_ptr< ArticulatedBody > ArticulatedBodyPtr
Articulated body smart pointer.
Definition: Types.h:65
CCD()
Constructs a collision detector with default tolerances.
Definition: CCD.cpp:55
Structure for storing the pairwise distance between pointers to two CollisionGeometry objects...
Definition: PairwiseDistInfo.h:15