Moby
SSL.h
1 /****************************************************************************
2  * Copyright 2011 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 _MOBY_SSL_H_
8 #define _MOBY_SSL_H_
9 
10 #include <stack>
11 #include <iostream>
12 #include <queue>
13 #include <boost/tuple/tuple.hpp>
14 #include <boost/enable_shared_from_this.hpp>
15 #include <Ravelin/Vector3d.h>
16 #include <Ravelin/Pose3d.h>
17 #include <Ravelin/AAngled.h>
18 #include <Moby/BV.h>
19 #include <Moby/Constants.h>
20 #include <Moby/Types.h>
21 #include <Moby/CompGeom.h>
22 
23 namespace Moby {
24 
26 class SSL : public BV
27 {
28  public:
29  SSL();
30  SSL(const SSL& obb) { operator=(obb); }
31  SSL(const Point3d& p1, const Point3d& p2, double radius);
32  SSL(const SSL& s, const Ravelin::Vector3d& v);
33  SSL& operator=(const SSL& s);
34  virtual void transform(const Ravelin::Transform3d& T, BV* result) const;
35  virtual BVPtr calc_swept_BV(CollisionGeometryPtr g, const Ravelin::SVelocityd& v) const;
36  static double calc_dist(const SSL& o, const Point3d& p);
37  static double calc_dist(const SSL& a, const SSL& b, Point3d& cpa, Point3d& cpb);
38  static double calc_dist(const SSL& a, const SSL& b, const Ravelin::Transform3d& aTb, Point3d& cpa, Point3d& cpb);
39  static bool intersects(const SSL& a, const SSL& b);
40  static bool intersects(const SSL& a, const SSL& b, const Ravelin::Transform3d& aTb);
41  static bool intersects(const SSL& a, const LineSeg3& seg, double& tmin, double tmax, Point3d& q);
42  virtual bool intersects(const LineSeg3& seg, double& tmin, double tmax, Point3d& q) const { return SSL::intersects(*this, seg, tmin, tmax, q); }
43  static bool outside(const SSL& a, const Point3d& point, double tol = NEAR_ZERO);
44  virtual bool outside(const Point3d& point, double tol = NEAR_ZERO) const { return SSL::outside(*this, point, tol); }
45  boost::shared_ptr<SSL> get_this() { return boost::dynamic_pointer_cast<SSL>(shared_from_this()); }
46  boost::shared_ptr<const SSL> get_this() const { return boost::dynamic_pointer_cast<const SSL>(shared_from_this()); }
47  virtual std::ostream& to_vrml(std::ostream& out, const Ravelin::Pose3d& T) const;
48  unsigned calc_size() const;
49  virtual boost::shared_ptr<const Ravelin::Pose3d> get_relative_pose() const { return p1.pose; }
50  virtual Point3d get_lower_bounds() const;
51  virtual Point3d get_upper_bounds() const;
52 
54  virtual double calc_volume() const { return (p1 - p2).norm() * M_PI * radius * radius * radius; }
55 
58 
61 
63  double radius;
64 
65  private:
66  static double calc_sq_dist(const LineSeg3& seg, const Point3d& q, Point3d& cp);
67  static double calc_sq_dist(const LineSeg3& seg0, const LineSeg3& seg1, Point3d& cp0, Point3d& cp1);
68  static double calc_sq_dist(const Point3d& origin, const Ravelin::Vector3d& dir, const LineSeg3& seg, Point3d& cp_line, Point3d& cp_seg, double& line_param);
69 
70 }; // end class
71 
72 // include inline functions
73 #include "SSL.inl"
74 
75 } // end namespace
76 
77 #endif
78 
virtual BVPtr calc_swept_BV(CollisionGeometryPtr g, const Ravelin::SVelocityd &v) const
Calculates the velocity-expanded bounding volume.
Definition: SSL.cpp:65
boost::shared_ptr< BV > BVPtr
Bounding volume (BV) smart pointer.
Definition: Types.h:92
virtual bool intersects(const LineSeg3 &seg, double &tmin, double tmax, Point3d &q) const
Determines whether a line segment intersects the bounding volume.
Definition: SSL.h:42
virtual std::ostream & to_vrml(std::ostream &out, const Ravelin::Pose3d &T) const
Outputs the SSL to VRML (not yet implemented)
Definition: SSL.cpp:582
static double calc_dist(const SSL &o, const Point3d &p)
Calculates the distance of the sphere-swept line from a point.
Definition: SSL.cpp:72
An abstract bounding volume.
Definition: BV.h:38
Point3d p2
The second point of the line segment.
Definition: SSL.h:60
Point3d p1
The first point of the line segment.
Definition: SSL.h:57
SSL & operator=(const SSL &s)
Copies one SSL to another.
Definition: SSL.cpp:55
boost::shared_ptr< CollisionGeometry > CollisionGeometryPtr
Collision geometry smart pointer.
Definition: Types.h:77
virtual void transform(const Ravelin::Transform3d &T, BV *result) const
Transforms the SSL using the given transform.
Definition: SSL.cpp:41
A sphere-swept line (SSL) that optionally allows building an SSL tree.
Definition: SSL.h:26
virtual boost::shared_ptr< const Ravelin::Pose3d > get_relative_pose() const
Gets the associated pose for this bounding volume.
Definition: SSL.h:49
virtual Point3d get_upper_bounds() const
Gets the upper bounds of the SSL.
Definition: SSL.cpp:566
virtual Point3d get_lower_bounds() const
Gets the lower bounds of the SSL.
Definition: SSL.cpp:550
Ravelin::Vector3d Point3d
Typedef to distinguish between a 3D vector and a point.
Definition: Types.h:47
static bool outside(const SSL &a, const Point3d &point, double tol=NEAR_ZERO)
Determines whether a point is outside the SSL.
Definition: SSL.cpp:533
static bool intersects(const SSL &a, const SSL &b)
Determines whether two SSLs intersect.
Definition: SSL.cpp:477
std::pair< Point3d, Point3d > LineSeg3
Typedef to make specifying line segments easier.
Definition: Types.h:50
double radius
Radius of the spherical addition.
Definition: SSL.h:63
SSL()
Initializes an empty SSL.
Definition: SSL.cpp:15
unsigned calc_size() const
Calculates the size (number of elements in) a SSL tree.
Definition: SSL.cpp:540
virtual bool outside(const Point3d &point, double tol=NEAR_ZERO) const
Determines whether a point is outside the bounding volume.
Definition: SSL.h:44
virtual double calc_volume() const
Calculates (approximate?) volume of the SSL.
Definition: SSL.h:54