Moby
SpherePrimitive.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 _SPHERE_PRIMITIVE_H
8 #define _SPHERE_PRIMITIVE_H
9 
10 #include <Moby/Primitive.h>
11 
12 namespace Moby {
13 
14 class BoxPrimitive;
15 class BoundingSphere;
16 
18 class SpherePrimitive : public Primitive
19 {
20  public:
22  SpherePrimitive(double radius);
23  SpherePrimitive(const Ravelin::Pose3d& T);
24  SpherePrimitive(double radius, unsigned n);
25  SpherePrimitive(double radius, const Ravelin::Pose3d& T);
26  SpherePrimitive(double radius, unsigned n, const Ravelin::Pose3d& T);
27  void set_radius(double radius);
28  void set_num_points(unsigned n);
29  virtual bool is_convex() const { return true; }
30  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
31  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
32  virtual void set_pose(const Ravelin::Pose3d& T);
33  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  double calc_signed_dist(boost::shared_ptr<const SpherePrimitive> s, Point3d& pthis, Point3d& psph) const;
40  virtual Point3d get_supporting_point(const Ravelin::Vector3d& d) const;
41  virtual double calc_signed_dist(const Point3d& p) const;
42  virtual double get_bounding_radius() const { return _radius; }
43 
45  double get_radius() const { return _radius; }
46 
48  unsigned get_num_points() const { return _npoints; }
49 
50  private:
51  virtual void calc_mass_properties();
52  static double calc_f(const Ravelin::VectorNd&, void*);
53  static void calc_gradient(const Ravelin::VectorNd&, void*, Ravelin::VectorNd&);
54  static void calc_hessian(const Ravelin::VectorNd&, void*, Ravelin::MatrixNd&);
55 
57  std::map<CollisionGeometryPtr, boost::shared_ptr<BoundingSphere> > _bsphs;
58 
60  double _radius;
61 
63  unsigned _npoints;
64 }; // end class
65 
66 } // end namespace
67 
68 #endif
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
void set_num_points(unsigned n)
Sets the number of points used in this sphere.
Definition: SpherePrimitive.cpp:180
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: SpherePrimitive.cpp:359
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &vertices) const
Gets vertices for the primitive.
Definition: SpherePrimitive.cpp:245
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: Primitive.h:41
void set_radius(double radius)
Sets the radius for this sphere (forces redetermination of the mesh)
Definition: SpherePrimitive.cpp:158
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: SpherePrimitive.cpp:382
unsigned get_num_points() const
Gets the number of points used to create the sphere for visualization / collision checking...
Definition: SpherePrimitive.h:48
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
virtual osg::Node * create_visualization()
Creates the visualization for this primitive.
Definition: SpherePrimitive.cpp:345
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)
Gets the root bounding volume.
Definition: SpherePrimitive.cpp:398
double get_radius() const
Gets the radius for this sphere.
Definition: SpherePrimitive.h:45
virtual double calc_dist_and_normal(const Point3d &point, std::vector< Ravelin::Vector3d > &normals) const
Finds the signed distance betwen the sphere and a point.
Definition: SpherePrimitive.cpp:332
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
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.
SpherePrimitive()
Creates a sphere with radius 1.0 and 100 points.
Definition: SpherePrimitive.cpp:37
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)
Gets the mesh, computing it if necessary.
Definition: SpherePrimitive.cpp:202
virtual bool is_convex() const
Determines whether this primitive is convex.
Definition: SpherePrimitive.h:29
virtual void set_pose(const Ravelin::Pose3d &T)
Transforms the primitive.
Definition: SpherePrimitive.cpp:186
virtual Point3d get_supporting_point(const Ravelin::Vector3d &d) const
Gets the supporting point.
Definition: SpherePrimitive.cpp:88
Represents a sphere primitive for inertia properties, collision detection, and visualization.
Definition: SpherePrimitive.h:18