Moby
CollisionGeometry.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_GEOMETRY_H
8 #define _COLLISION_GEOMETRY_H
9 
10 #include <stack>
11 #include <list>
12 #include <vector>
13 #include <map>
14 #include <Ravelin/Pose3d.h>
15 #include <boost/foreach.hpp>
16 #include <boost/shared_ptr.hpp>
17 #include <boost/weak_ptr.hpp>
18 #include <Moby/Constants.h>
19 #include <Moby/Base.h>
20 #include <Moby/Triangle.h>
21 #include <Moby/Primitive.h>
22 
23 namespace Ravelin {
24 class SingleBodyd;
25 }
26 
27 namespace Moby {
28 
30 
36 class CollisionGeometry : public virtual Base
37 {
38  friend class GeneralizedCCD;
39 
40  public:
42  void set_relative_pose(const Ravelin::Pose3d& pose);
43  void write_vrml(const std::string& filename) const;
45  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
46  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
47  void set_single_body(boost::shared_ptr<Ravelin::SingleBodyd> s);
49  double calc_signed_dist(const Point3d& p);
50  double calc_dist_and_normal(const Point3d& p, std::vector<Ravelin::Vector3d>& n) const;
51  void get_vertices(std::vector<Point3d>& p) const;
52  Point3d get_supporting_point(const Ravelin::Vector3d& d) const;
53  double get_farthest_point_distance() const;
54 
57 
59  CollisionGeometryPtr get_this() { return boost::dynamic_pointer_cast<CollisionGeometry>(shared_from_this()); }
60 
62  boost::shared_ptr<CollisionGeometry> get_parent() const { return (_parent.expired()) ? CollisionGeometryPtr() : CollisionGeometryPtr(_parent); }
63 
65  void set_parent(boost::weak_ptr<CollisionGeometry> parent) { _parent = parent; }
66 
68  boost::shared_ptr<const Ravelin::Pose3d> get_pose() const { return _F; }
69 
71  boost::shared_ptr<Ravelin::SingleBodyd> get_single_body() const { return (_single_body.expired()) ? boost::shared_ptr<Ravelin::SingleBodyd>() : boost::shared_ptr<Ravelin::SingleBodyd>(_single_body); }
72 
74  PrimitivePtr get_geometry() const { return _geometry; }
75 
76  protected:
78  boost::shared_ptr<Ravelin::Pose3d> _F;
79 
82 
83  private:
84  boost::weak_ptr<Ravelin::SingleBodyd> _single_body;
85  boost::weak_ptr<CollisionGeometry> _parent;
86 }; // end class
87 
88 } // end namespace
89 
90 #endif
boost::shared_ptr< Primitive > PrimitivePtr
Primitive smart pointer.
Definition: Types.h:80
void get_vertices(std::vector< Point3d > &p) const
Gets vertices for a primitive.
Definition: CollisionGeometry.cpp:113
double get_farthest_point_distance() const
Gets the farthest point from this geometry.
Definition: CollisionGeometry.cpp:53
boost::shared_ptr< Ravelin::Pose3d > _F
The pose of the CollisionGeometry (relative to the rigid body)
Definition: CollisionGeometry.h:78
Class from which all Moby classes are derived.
Definition: Base.h:20
boost::shared_ptr< Ravelin::SingleBodyd > get_single_body() const
Gets the single body associated with this CollisionGeometry (if any)
Definition: CollisionGeometry.h:71
void set_relative_pose(const Ravelin::Pose3d &pose)
Sets the relative pose of this geometry.
Definition: CollisionGeometry.cpp:193
CollisionGeometryPtr get_this()
Gets the shared pointer for this.
Definition: CollisionGeometry.h:59
double calc_dist_and_normal(const Point3d &p, std::vector< Ravelin::Vector3d > &n) const
Calculates the (unsigned) distance of a point from this collision geometry.
Definition: CollisionGeometry.cpp:204
Point3d get_supporting_point(const Ravelin::Vector3d &d) const
Gets a supporting point for this geometry in a particular direction.
Definition: CollisionGeometry.cpp:33
void set_parent(boost::weak_ptr< CollisionGeometry > parent)
Sets the parent of this CollisionGeometry (or NULL to indicate no parent)
Definition: CollisionGeometry.h:65
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
void write_vrml(const std::string &filename) const
Writes the collision geometry mesh to the specified VRML file.
Definition: CollisionGeometry.cpp:134
boost::shared_ptr< const Ravelin::Pose3d > get_pose() const
Gets the relative transform for this CollisionGeometry.
Definition: CollisionGeometry.h:68
CollisionGeometry()
Constructs a CollisionGeometry with no triangle mesh, identity transformation and relative transforma...
Definition: CollisionGeometry.cpp:26
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
PrimitivePtr _geometry
The underlying geometry.
Definition: CollisionGeometry.h:81
double compliant_layer_depth
The compliant layer around this geometry.
Definition: CollisionGeometry.h:56
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Implements Base::load_from_xml()
Definition: CollisionGeometry.cpp:315
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Implements Base::save_to_xml()
Definition: CollisionGeometry.cpp:370
PrimitivePtr get_geometry() const
Gets the geometry for this primitive.
Definition: CollisionGeometry.h:74
void set_single_body(boost::shared_ptr< Ravelin::SingleBodyd > s)
Sets the single body associated with this CollisionGeometry.
Definition: CollisionGeometry.cpp:72
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
boost::shared_ptr< CollisionGeometry > get_parent() const
Gets the parent of this CollisionGeometry (or NULL if there is no parent)
Definition: CollisionGeometry.h:62
PrimitivePtr set_geometry(PrimitivePtr primitive)
Sets the collision geometry via a primitive.
Definition: CollisionGeometry.cpp:86