Moby
PolyhedralPrimitive.h
1 /****************************************************************************
2  * Copyright 2014 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 _POLYHEDRAL_PRIMITIVE_H
8 #define _POLYHEDRAL_PRIMITIVE_H
9 
10 #include <Moby/Primitive.h>
11 #include <Moby/Polyhedron.h>
12 
13 namespace Moby {
14 
16 
23 {
24  public:
25 
27  PolyhedralPrimitive(const Ravelin::Pose3d& T) : Primitive(T) { }
28  virtual double calc_signed_dist(boost::shared_ptr<const Primitive> p, Point3d& pthis, Point3d& pp) const;
29  virtual double calc_dist_and_normal(const Point3d& p, std::vector<Ravelin::Vector3d>& normals) const;
30  virtual osg::Node* create_visualization();
32  virtual void set_polyhedron(const Polyhedron& p);
33  virtual void get_vertices(boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& vertices) const;
34  virtual boost::shared_ptr<const IndexedTriArray> get_mesh(boost::shared_ptr<const Ravelin::Pose3d> P);
35  virtual bool is_convex() const;
36  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
37  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
38  virtual void set_pose(const Ravelin::Pose3d& P);
39 
41  const Polyhedron& get_polyhedron() const { return _poly; }
42 
43  // Gets the number of facets in this primitive
44  virtual unsigned num_facets() const { return _poly.get_faces().size();}
45 
46  // Gets the bounding radius of this primitive
47  virtual double get_bounding_radius() const
48  {
49  // get the vertices
50  const std::vector<boost::shared_ptr<Polyhedron::Vertex> >& verts = _poly.get_vertices();
51  if (verts.empty())
52  return 0.0;
53 
54  // find which point is closest
55  double max_dist = 0.0;
56  for (unsigned i=0; i< verts.size(); i++)
57  max_dist = std::max(max_dist, verts[i]->o.norm());
58 
59  return max_dist;
60  }
61 
62  template <class OutputIterator>
63  static OutputIterator get_halfspaces(const Polyhedron& poly, boost::shared_ptr<const Ravelin::Pose3d> pose, const Ravelin::Transform3d& wTpose, OutputIterator output_begin);
64 
65  protected:
66  void calc_mass_properties();
67  double calc_signed_dist(boost::shared_ptr<const PolyhedralPrimitive> p, Point3d& pthis, Point3d& pp) const;
68  Polyhedron _poly;
69 }; // end class
70 
71 #include "PolyhedralPrimitive.inl"
72 
73 } // end namespace
74 
75 #endif
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
Primitive()
Constructs a primitive under the identity transformation.
Definition: Primitive.cpp:58
virtual void set_pose(const Ravelin::Pose3d &P)
Sets the pose of this primitive.
Definition: PolyhedralPrimitive.cpp:214
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.
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &vertices) const
Get vertices corresponding to this primitive.
Definition: PolyhedralPrimitive.cpp:193
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)
Gets the root bounding volume for this primitive.
Definition: PolyhedralPrimitive.cpp:187
virtual double calc_dist_and_normal(const Point3d &p, std::vector< Ravelin::Vector3d > &normals) const
Computes the distance between a point and this primitive.
Definition: PolyhedralPrimitive.cpp:39
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: Primitive.h:41
A potentially-non-convex polyhedron of genus 0.
Definition: Polyhedron.h:28
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)
Gets the underlying triangle mesh for this primitive.
Definition: PolyhedralPrimitive.cpp:207
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
void calc_mass_properties()
Calculates mass properties for the polyhedron.
Definition: PolyhedralPrimitive.cpp:251
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: PolyhedralPrimitive.h:22
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: PolyhedralPrimitive.cpp:385
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
virtual bool is_convex() const
Determines whether the primitive is convex.
Definition: PolyhedralPrimitive.cpp:32
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: PolyhedralPrimitive.cpp:446
virtual void set_polyhedron(const Polyhedron &p)
Sets the polyhedron corresponding to this primitive.
Definition: PolyhedralPrimitive.cpp:233
virtual osg::Node * create_visualization()
creates the visualization for the primitive
Definition: PolyhedralPrimitive.cpp:111
const Polyhedron & get_polyhedron() const
Gets the polyhedron corresponding to this primitive (in its transformed state)
Definition: PolyhedralPrimitive.h:41