Moby
CylinderPrimitive.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 _CYLINDER_PRIMITIVE_H
8 #define _CYLINDER_PRIMITIVE_H
9 
10 #include <Moby/Primitive.h>
11 
12 namespace Moby {
13 
14 class OBB;
15 class SpherePrimitive;
16 
19 {
20  public:
22  CylinderPrimitive(double radius, double height);
23  CylinderPrimitive(double radius, double height, unsigned n, unsigned nrings, const Ravelin::Pose3d& T);
24  CylinderPrimitive(double radius, double height, const Ravelin::Pose3d& T);
25  virtual bool is_convex() const { return true; }
26  void set_radius(double radius);
27  void set_height(double height);
28  void set_num_circle_points(unsigned n);
29  void set_num_rings(unsigned n);
30  virtual void set_pose(const Ravelin::Pose3d& T);
31  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
32  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
34  virtual void get_vertices(boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& vertices) const;
35  virtual double calc_dist_and_normal(const Point3d& point, std::vector<Ravelin::Vector3d>& normals) const;
36  virtual double calc_signed_dist(boost::shared_ptr<const Primitive> p, Point3d& pthis, Point3d& pp) const;
37  virtual boost::shared_ptr<const IndexedTriArray> get_mesh(boost::shared_ptr<const Ravelin::Pose3d> P);
38  virtual osg::Node* create_visualization();
39  virtual Point3d get_supporting_point(const Ravelin::Vector3d& d) const;
40  virtual double calc_signed_dist(const Point3d& p) const;
41  virtual double get_bounding_radius() const { return std::max(_radius, _height); }
42 
44  double get_radius() const { return _radius; }
45 
47  double get_height() const { return _height; }
48 
50  unsigned get_circle_points() const { return _npoints; }
51 
52  private:
53  bool intersect_seg(const LineSeg3& seg, double& t, Point3d& isect, Ravelin::Vector3d& normal) const;
54  bool point_inside(const Point3d& p, Ravelin::Vector3d& normal) const;
55  double calc_dist(const SpherePrimitive* s, Point3d& pcyl, Point3d& psph) const;
56  double calc_penetration_depth(const Point3d& p) const;
57  unsigned intersect_line(const Point3d& origin, const Ravelin::Vector3d& dir, double& t0, double& t1) const;
58  virtual void calc_mass_properties();
59 
61  double _radius;
62 
64  double _height;
65 
67  unsigned _npoints;
68 
70  unsigned _nrings;
71 
73  std::map<CollisionGeometryPtr, OBBPtr> _obbs;
74 };
75 
76 } // end namespace
77 
78 #endif
virtual bool is_convex() const
Determines whether this primitive is convex.
Definition: CylinderPrimitive.h:25
virtual osg::Node * create_visualization()
Creates the visualization for this primitive.
Definition: CylinderPrimitive.cpp:436
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
unsigned get_circle_points() const
Gets the number of points in a circle on the cylinder.
Definition: CylinderPrimitive.h:50
virtual double calc_dist_and_normal(const Point3d &point, std::vector< Ravelin::Vector3d > &normals) const
Computes the signed distance between the cylinder and a point.
Definition: CylinderPrimitive.cpp:148
void set_num_circle_points(unsigned n)
Sets the number of points in the circles of the cylinder.
Definition: CylinderPrimitive.cpp:387
double get_height() const
Gets the height of this cylinder.
Definition: CylinderPrimitive.h:47
CylinderPrimitive()
Constructs a cylinder centered at the origin, with the longitudinal axis aligned with the y-axis...
Definition: CylinderPrimitive.cpp:37
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: Primitive.h:41
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: CylinderPrimitive.cpp:486
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)
Gets the triangle mesh for the cylinder, computing it if necessary.
Definition: CylinderPrimitive.cpp:403
double get_radius() const
Gets the radius of this cylinder.
Definition: CylinderPrimitive.h:44
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
void set_radius(double radius)
Sets the radius for this cylinder.
Definition: CylinderPrimitive.cpp:339
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &vertices) const
Gets vertices from the primitive.
Definition: CylinderPrimitive.cpp:581
virtual Point3d get_supporting_point(const Ravelin::Vector3d &d) const
Gets the supporting point in a particular direction.
Definition: CylinderPrimitive.cpp:126
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
virtual void set_pose(const Ravelin::Pose3d &T)
Transforms the primitive.
Definition: CylinderPrimitive.cpp:508
Defines a cylinder primitive.
Definition: CylinderPrimitive.h:18
std::pair< Point3d, Point3d > LineSeg3
Typedef to make specifying line segments easier.
Definition: Types.h:50
void set_num_rings(unsigned n)
Sets the number of rings for determining "virtual points" (points on the tube of the cylinder) ...
Definition: CylinderPrimitive.cpp:395
void set_height(double height)
Sets the height for this cylinder.
Definition: CylinderPrimitive.cpp:363
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)
Gets the OBB.
Definition: CylinderPrimitive.cpp:550
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.
Represents a sphere primitive for inertia properties, collision detection, and visualization.
Definition: SpherePrimitive.h:18
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: CylinderPrimitive.cpp:453