Moby
ConePrimitive.h
1 /****************************************************************************
2  * Copyright 2009 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 _CONE_PRIMITIVE_H
8 #define _CONE_PRIMITIVE_H
9 
10 #include <Moby/Primitive.h>
11 
12 namespace Moby {
13 
14 class OBB;
15 class SpherePrimitive;
16 
18 
22 class ConePrimitive : public Primitive
23 {
24  public:
25  ConePrimitive();
26  ConePrimitive(double radius, double height);
27  ConePrimitive(double radius, double height, unsigned npoints, unsigned nrings, const Ravelin::Pose3d& T);
28  ConePrimitive(double radius, double height, const Ravelin::Pose3d& T);
29  virtual bool is_convex() const { return true; }
30  void set_radius(double radius);
31  void set_height(double height);
32  void set_circle_points(unsigned n);
33  void set_num_rings(unsigned n);
34  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
35  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
37  virtual void get_vertices(boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& vertices) const;
38  virtual void set_pose(const Ravelin::Pose3d& T);
39  virtual double calc_dist_and_normal(const Point3d& point, std::vector<Ravelin::Vector3d>& normals) const;
40  virtual double calc_signed_dist(boost::shared_ptr<const Primitive> p, Point3d& pthis, Point3d& pp) const;
41  virtual boost::shared_ptr<const IndexedTriArray> get_mesh(boost::shared_ptr<const Ravelin::Pose3d> P);
42  virtual osg::Node* create_visualization();
43  virtual Point3d get_supporting_point(const Ravelin::Vector3d& d) const;
44  virtual double calc_signed_dist(const Point3d& p) const;
45  virtual double get_bounding_radius() const { return std::max(_radius, _height); }
46 
48  unsigned get_num_rings() const { return _nrings; }
49 
51  double get_radius() const { return _radius; }
52 
54  double get_height() const { return _height; }
55 
57  unsigned get_circle_points() const { return _npoints; }
58 
59  private:
60  bool intersect_seg(const LineSeg3& seg, double& t, Point3d& isect, Ravelin::Vector3d& normal) const;
61  double calc_dist(const SpherePrimitive* s, Point3d& pcone, Point3d& psph) const;
62  static double sqr(double x) { return x*x; }
63  virtual void calc_mass_properties();
64  double calc_penetration_depth(const Point3d& p) const;
65  Ravelin::Vector3d determine_normal(const Point3d& query) const;
66  bool point_inside(const Point3d& p, Ravelin::Vector3d& normal) const;
67 
69  std::map<CollisionGeometryPtr, OBBPtr> _obbs;
70 
72  double _radius;
73 
75  double _height;
76 
78  unsigned _npoints;
79 
81  unsigned _nrings;
82 };
83 
84 } // end namespace
85 
86 #endif
87 
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
virtual void load_from_xml(boost::shared_ptr< const XMLTree > node, std::map< std::string, BasePtr > &id_map)
Implements Base::load_from_xml() for serialization.
Definition: ConePrimitive.cpp:460
virtual double calc_dist_and_normal(const Point3d &point, std::vector< Ravelin::Vector3d > &normals) const
Computes the distance and normal from a point on the primitive.
Definition: ConePrimitive.cpp:117
virtual void set_pose(const Ravelin::Pose3d &T)
Transforms the primitive.
Definition: ConePrimitive.cpp:375
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)
Gets vertices from the primitive.
Definition: ConePrimitive.cpp:655
virtual double calc_signed_dist(boost::shared_ptr< const Primitive > p, Point3d &pthis, Point3d &pp) const
Computes the signed distance between this and another primitive.
unsigned get_circle_points() const
Gets the number of points in a circle on the cone.
Definition: ConePrimitive.h:57
void set_radius(double radius)
Sets the radius for this cone.
Definition: ConePrimitive.cpp:309
Defines a cone primitive.
Definition: ConePrimitive.h:22
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &vertices) const
Gets vertices from the primitive.
Definition: ConePrimitive.cpp:565
virtual void save_to_xml(XMLTreePtr node, std::list< boost::shared_ptr< const Base > > &shared_objects) const
Implements Base::save_to_xml() for serialization.
Definition: ConePrimitive.cpp:493
virtual osg::Node * create_visualization()
Creates the visualization for this primitive.
Definition: ConePrimitive.cpp:427
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: Primitive.h:41
ConePrimitive()
Constructs a cone centered at the origin, with the longitudinal axis aligned with the y-axis...
Definition: ConePrimitive.cpp:36
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)
Gets the triangle mesh for the cone, computing it if necessary.
Definition: ConePrimitive.cpp:391
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
void set_circle_points(unsigned n)
Sets the number of points in the rings of the cone.
Definition: ConePrimitive.cpp:359
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
void set_height(double height)
Sets the height for this cone.
Definition: ConePrimitive.cpp:334
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
unsigned get_num_rings() const
Gets the number of rings on the cone.
Definition: ConePrimitive.h:48
void set_num_rings(unsigned n)
Sets the number of rings in the cone.
Definition: ConePrimitive.cpp:367
std::pair< Point3d, Point3d > LineSeg3
Typedef to make specifying line segments easier.
Definition: Types.h:50
virtual Point3d get_supporting_point(const Ravelin::Vector3d &d) const
Gets a supporting point in a particular direction.
Definition: ConePrimitive.cpp:95
double get_radius() const
Gets the radius of this cone.
Definition: ConePrimitive.h:51
double get_height() const
Gets the height of this cone.
Definition: ConePrimitive.h:54
Represents a sphere primitive for inertia properties, collision detection, and visualization.
Definition: SpherePrimitive.h:18
virtual bool is_convex() const
Determines whether this primitive is convex.
Definition: ConePrimitive.h:29