7 #ifndef _BOX_PRIMITIVE_H
8 #define _BOX_PRIMITIVE_H
10 #include <Moby/Triangle.h>
11 #include <Moby/PolyhedralPrimitive.h>
12 #include <Moby/DummyBV.h>
16 class SpherePrimitive;
24 BoxPrimitive(
double xlen,
double ylen,
double zlen,
const Ravelin::Pose3d& T);
27 void set_size(
double xlen,
double ylen,
double zlen);
28 virtual unsigned num_facets()
const {
return 6; }
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;
35 virtual void set_pose(
const Ravelin::Pose3d& T);
37 virtual boost::shared_ptr<const IndexedTriArray>
get_mesh(boost::shared_ptr<const Ravelin::Pose3d> P);
39 double calc_signed_dist(boost::shared_ptr<const SpherePrimitive> s,
Point3d& pthis,
Point3d& psph)
const;
40 virtual double calc_signed_dist(boost::shared_ptr<const Primitive> p,
Point3d& pthis,
Point3d& pp)
const;
41 virtual void get_vertices(boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& p)
const;
42 virtual double calc_signed_dist(
const Point3d& p)
const;
44 virtual double get_bounding_radius()
const {
return std::sqrt(_xlen*_xlen + _ylen*_ylen + _zlen*_zlen); }
56 enum FaceID { ePOSX, eNEGX, ePOSY, eNEGY, ePOSZ, eNEGZ };
57 static double sqr(
double x) {
return x*x; }
59 virtual void calc_mass_properties();
60 void construct_polyhedron();
63 double _edge_sample_length;
66 std::map<CollisionGeometryPtr, std::vector<Point3d> > _vertices;
69 std::map<CollisionGeometryPtr, OBBPtr> _obbs;
72 double _xlen, _ylen, _zlen;
void set_edge_sample_length(double len)
Sets the edge sample length for this box.
Definition: BoxPrimitive.cpp:318
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
double get_x_len() const
Get the x-length of this box.
Definition: BoxPrimitive.h:47
virtual osg::Node * create_visualization()
Creates the visualization for this primitive.
Definition: BoxPrimitive.cpp:624
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &p) const
Gets the set of vertices for the BoxPrimitive.
Definition: BoxPrimitive.cpp:340
virtual double calc_dist_and_normal(const Point3d &point, std::vector< Ravelin::Vector3d > &normals) const
Tests whether a point is inside or on the box.
Definition: BoxPrimitive.cpp:840
A potentially-non-convex polyhedron of genus 0.
Definition: Polyhedron.h:28
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: BoxPrimitive.cpp:640
double get_z_len() const
Ge the z-length of this box.
Definition: BoxPrimitive.h:53
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
BoxPrimitive()
Constructs a unit cube centered at the origin.
Definition: BoxPrimitive.cpp:38
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
double get_y_len() const
Get the y-length of this box.
Definition: BoxPrimitive.h:50
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: BoxPrimitive.cpp:324
virtual bool is_convex() const
Determines whether the primitive is convex.
Definition: BoxPrimitive.h:29
virtual void set_polyhedron(const Polyhedron &p)
Overrides the PolyhedronPrimitive::set_polyhedron(.)
Definition: BoxPrimitive.cpp:279
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: BoxPrimitive.cpp:674
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)
Gets the bounding volume for this plane.
Definition: BoxPrimitive.cpp:715
double calc_closest_points(boost::shared_ptr< const SpherePrimitive > s, Point3d &pbox, Point3d &psph) const
Finds closest point between a box and a sphere; returns the closest point on/in the box to the center...
Definition: BoxPrimitive.cpp:184
double calc_closest_point(const Point3d &point, Point3d &closest) const
Computes the closest point on the box to a point (and returns the distance)
Definition: BoxPrimitive.cpp:788
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)
Gets the set of vertices for the BoxPrimitive (constructing, if necessary)
Definition: BoxPrimitive.cpp:583
Represents a solid box centered at the origin (by default)
Definition: BoxPrimitive.h:19
void set_size(double xlen, double ylen, double zlen)
Sets the size of this box.
Definition: BoxPrimitive.cpp:288