Moby
HeightmapPrimitive.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 _HEIGHTMAP_PRIMITIVE_H
8 #define _HEIGHTMAP_PRIMITIVE_H
9 
10 #include <Moby/Primitive.h>
11 #include <Moby/OBB.h>
12 
13 namespace Moby {
14 
15 class SpherePrimitive;
16 
19 {
20  friend class CCD;
21 
22  public:
24  HeightmapPrimitive(const Ravelin::Pose3d& T);
25  virtual void set_pose(const Ravelin::Pose3d& T);
26  virtual void get_vertices(boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& vertices) const;
27  void get_vertices(BVPtr bv, boost::shared_ptr<const Ravelin::Pose3d> P, std::vector<Point3d>& vertices) const;
28  virtual double calc_dist_and_normal(const Point3d& point, std::vector<Ravelin::Vector3d>& normals) const;
29  virtual double calc_signed_dist(boost::shared_ptr<const Primitive> p, Point3d& pthis, Point3d& pp) const;
30  double calc_signed_dist(boost::shared_ptr<const SpherePrimitive> s, Point3d& pthis, Point3d& psph) const;
31  virtual Point3d get_supporting_point(const Ravelin::Vector3d& d) const;
32  virtual double calc_signed_dist(const Point3d& p) const;
33  virtual osg::Node* create_visualization();
34  virtual boost::shared_ptr<const IndexedTriArray> get_mesh(boost::shared_ptr<const Ravelin::Pose3d> P);
35  virtual void calc_mass_properties() { _density.reset(); _J.set_zero(); }
37  virtual void load_from_xml(boost::shared_ptr<const XMLTree> node, std::map<std::string, BasePtr>& id_map);
38  virtual void save_to_xml(XMLTreePtr node, std::list<boost::shared_ptr<const Base> >& shared_objects) const;
39  const Ravelin::MatrixNd& get_heights() const { return _heights; }
40  double get_width() const { return _width; }
41  double get_depth() const { return _depth; }
42  virtual double get_bounding_radius() const { return 0.0; }
43 
44  protected:
45  virtual double calc_height(const Point3d& p) const;
46  void calc_gradient(const Point3d& p, double& gx, double& gz) const;
47 
49  double _width;
50 
52  double _depth;
53 
54  // heights
55  Ravelin::MatrixNd _heights;
56 
58  std::map<CollisionGeometryPtr, boost::shared_ptr<OBB> > _obbs;
59 
60 }; // end class
61 
62 } // end namespace
63 
64 #endif
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
virtual void set_pose(const Ravelin::Pose3d &T)
Transforms the primitive.
Definition: HeightmapPrimitive.cpp:418
Represents a heightmap with height zero on the xz plane (primitive can be transformed) ...
Definition: HeightmapPrimitive.h:18
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.
HeightmapPrimitive()
Initializes the heightmap primitive.
Definition: HeightmapPrimitive.cpp:37
double _width
width of the heightmap
Definition: HeightmapPrimitive.h:49
virtual osg::Node * create_visualization()
Computes the OSG visualization.
Definition: HeightmapPrimitive.cpp:251
Defines a triangle-mesh-based primitive type used for inertial property calculation and geometry prov...
Definition: Primitive.h:41
virtual void get_vertices(boost::shared_ptr< const Ravelin::Pose3d > P, std::vector< Point3d > &vertices) const
Get vertices corresponding to this primitive.
virtual Point3d get_supporting_point(const Ravelin::Vector3d &d) const
Gets the supporting point.
Definition: HeightmapPrimitive.cpp:49
std::map< CollisionGeometryPtr, boost::shared_ptr< OBB > > _obbs
The bounding volumes for the heightmap.
Definition: HeightmapPrimitive.h:58
virtual boost::shared_ptr< const IndexedTriArray > get_mesh(boost::shared_ptr< const Ravelin::Pose3d > P)
Gets the mesh of the heightmap.
Definition: HeightmapPrimitive.cpp:105
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
virtual double calc_dist_and_normal(const Point3d &point, std::vector< Ravelin::Vector3d > &normals) const
Finds the signed distance betwen the heightmap and a point.
Definition: HeightmapPrimitive.cpp:464
boost::shared_ptr< XMLTree > XMLTreePtr
XML tree smart pointer.
Definition: Types.h:104
double _depth
depth of the heightmap
Definition: HeightmapPrimitive.h:52
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: HeightmapPrimitive.cpp:488
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: HeightmapPrimitive.cpp:531
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
Implements the CollisionDetection abstract class to perform exact contact finding using abstract shap...
Definition: CCD.h:36
void calc_gradient(const Point3d &p, double &gx, double &gz) const
Computes the gradient at a particular point.
Definition: HeightmapPrimitive.cpp:199
virtual double calc_height(const Point3d &p) const
Computes the height at a particular point.
Definition: HeightmapPrimitive.cpp:166
Ravelin::SpatialRBInertiad _J
The inertia of the primitive.
Definition: Primitive.h:112
virtual BVPtr get_BVH_root(CollisionGeometryPtr geom)
Gets the BVH root for the heightmap.
Definition: HeightmapPrimitive.cpp:65