Moby
Primitive.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 _PRIMITIVE_H
8 #define _PRIMITIVE_H
9 
10 #include <set>
11 #include <map>
12 #include <vector>
13 #include <boost/shared_ptr.hpp>
14 #include <Ravelin/Vector3d.h>
15 #include <Ravelin/Matrix3d.h>
16 #include <Ravelin/Pose3d.h>
17 #include <Moby/Base.h>
18 #include <Moby/Triangle.h>
19 #include <Moby/ThickTriangle.h>
20 #include <Moby/Constants.h>
21 #include <Moby/IndexedTriArray.h>
22 
23 namespace osg {
24  class MatrixTransform;
25  class Material;
26  class Node;
27  class Matrixd;
28 }
29 
30 namespace Moby {
31 
32 class CollisionGeometry;
33 
35 
41 class Primitive : public virtual Base
42 {
43  friend class CSG;
44 
45  public:
46  Primitive();
47  Primitive(const Ravelin::Pose3d& T);
48  virtual ~Primitive();
49  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
50  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
51  void update_visualization();
52  void set_mass(double mass);
53  void set_density(double density);
54  virtual void set_pose(const Ravelin::Pose3d& T);
55  virtual Point3d get_supporting_point(const Ravelin::Vector3d& d) const;
56  virtual double calc_signed_dist(const Point3d& p) const;
59  boost::shared_ptr<const Ravelin::Pose3d> get_pose(CollisionGeometryPtr g) const;
60  virtual double get_bounding_radius() const = 0;
61 
63  virtual double calc_max_dist(double lin_cont, double ang_cont, double dist, const Ravelin::Vector3d& d0, const Ravelin::Vector3d& w0, boost::shared_ptr<const Ravelin::Pose3d> P)
64  {
65  return lin_cont + ang_cont;
66  }
67 
69  virtual bool is_convex() const { return false; }
70 
72  virtual double calc_dist_and_normal(const Point3d& p, std::vector<Ravelin::Vector3d>& normals) const = 0;
73 
75  virtual double calc_signed_dist(boost::shared_ptr<const Primitive> p, Point3d& pthis, Point3d& pp) const = 0;
76 
78  virtual osg::Node* get_visualization();
79  virtual osg::Node* create_visualization() = 0;
80 
82  virtual BVPtr get_BVH_root(CollisionGeometryPtr geom) = 0;
83 
85  virtual void get_vertices(boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& vertices) const = 0;
86 
88  boost::shared_ptr<const Ravelin::Pose3d> get_inertial_pose() const { return _jF; }
89 
91  boost::shared_ptr<const Ravelin::Pose3d> get_pose() const { return _F; }
92 
94  virtual boost::shared_ptr<const IndexedTriArray> get_mesh(boost::shared_ptr<const Ravelin::Pose3d> P) = 0;
95 
97  const Ravelin::SpatialRBInertiad& get_inertia() const { return _J; }
98 
99  protected:
100  virtual void calc_mass_properties() = 0;
101 
103  boost::shared_ptr<Ravelin::Pose3d> _F;
104 
106  boost::shared_ptr<Ravelin::Pose3d> _jF;
107 
109  boost::shared_ptr<double> _density;
110 
112  Ravelin::SpatialRBInertiad _J;
113 
114  protected:
115 
117  std::map<boost::weak_ptr<CollisionGeometry>, boost::shared_ptr<Ravelin::Pose3d> > _cg_poses;
118 
120  std::set<boost::shared_ptr<Ravelin::Pose3d> > _poses;
121 
122  private:
123 
125  osg::MatrixTransform* _vtransform;
126 
128  osg::Material* _mat;
129 }; // end class
130 
131 } // end namespace
132 
133 #endif
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: Primitive.cpp:240
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)=0
Gets the root bounding volume for this primitive.
Primitive()
Constructs a primitive under the identity transformation.
Definition: Primitive.cpp:58
Class from which all Moby classes are derived.
Definition: Base.h:20
virtual bool is_convex() const
Determines whether this primitive is convex.
Definition: Primitive.h:69
virtual osg::Node * get_visualization()
Gets the visualization for this primitive.
Definition: Primitive.cpp:164
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: Primitive.h:41
boost::shared_ptr< const Ravelin::Pose3d > get_inertial_pose() const
Gets the inertial frame of this primitive.
Definition: Primitive.h:88
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: Primitive.cpp:322
virtual double calc_dist_and_normal(const Point3d &p, std::vector< Ravelin::Vector3d > &normals) const =0
Computes the distance between a point and this primitive.
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
void set_density(double density)
Sets the density of this primitive.
Definition: Primitive.cpp:232
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
boost::shared_ptr< const Ravelin::Pose3d > get_pose() const
Gets the pose of this primitive.
Definition: Primitive.h:91
void set_mass(double mass)
Sets the mass of this primitive.
Definition: Primitive.cpp:225
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &vertices) const =0
Get vertices corresponding to this primitive.
Definition: Primitive.inl:18
void remove_collision_geometry(CollisionGeometryPtr cg)
Removes a collision geometry.
Definition: Primitive.cpp:103
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
boost::shared_ptr< double > _density
The density of this primitive.
Definition: Primitive.h:109
boost::shared_ptr< Ravelin::Pose3d > _jF
The inertial pose of this primitive (relative to the global frame)
Definition: Primitive.h:106
virtual void set_pose(const Ravelin::Pose3d &T)
Sets the transform for this primitive – transforms mesh and inertial properties (if calculated) ...
Definition: Primitive.cpp:344
void add_collision_geometry(CollisionGeometryPtr cg)
Adds a collision geometry.
Definition: Primitive.cpp:91
virtual double calc_max_dist(double lin_cont, double ang_cont, double dist, const Ravelin::Vector3d &d0, const Ravelin::Vector3d &w0, boost::shared_ptr< const Ravelin::Pose3d > P)
Computes the maximum distance by a point on the geometry.
Definition: Primitive.h:63
void update_visualization()
Updates the visualization on the primitive.
Definition: Primitive.cpp:197
virtual Point3d get_supporting_point(const Ravelin::Vector3d &d) const
Gets a supporting point from a primitive.
Definition: Primitive.cpp:132
boost::shared_ptr< Ravelin::Pose3d > _F
The pose of this primitive (relative to the global frame)
Definition: Primitive.h:103
std::map< boost::weak_ptr< CollisionGeometry >, boost::shared_ptr< Ravelin::Pose3d > > _cg_poses
The poses of this primitive, relative to a collision geometry.
Definition: Primitive.h:117
std::set< boost::shared_ptr< Ravelin::Pose3d > > _poses
The poses, relative to a particular collision geometry.
Definition: Primitive.h:120
virtual double calc_signed_dist(const Point3d &p) const
Calculates the signed distance from this primitive.
Definition: Primitive.cpp:124
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)=0
Gets the underlying triangle mesh for this primitive.
const Ravelin::SpatialRBInertiad & get_inertia() const
Gets the inertia for this primitive.
Definition: Primitive.h:97
Ravelin::SpatialRBInertiad _J
The inertia of the primitive.
Definition: Primitive.h:112