7 #ifndef _TESSELLATED_POLYHEDRON_H
8 #define _TESSELLATED_POLYHEDRON_H
14 #include <Moby/IndexedTriArray.h>
15 #include <Moby/Constants.h>
16 #include <Moby/Polyhedron.h>
17 #include <Moby/InvalidIndexException.h>
31 enum LocationType { eInside, eOutside, eOnVertex, eOnEdge, eOnFace };
39 void transform(
const Ravelin::Transform3d& T);
40 const std::vector<Ravelin::Origin3d>& get_vertices()
const {
return _mesh.
get_vertices(); }
41 const std::vector<IndexedTri>& get_facets()
const {
return _mesh.
get_facets(); }
42 bool inside(
const Ravelin::Origin3d& point,
double tol = NEAR_ZERO);
43 bool inside_or_on(
const Ravelin::Origin3d& point,
double tol = NEAR_ZERO);
44 LocationType
location(
const Ravelin::Origin3d& point,
double tol = NEAR_ZERO)
const;
45 static void to_vrml(std::ostream& out,
const TessellatedPolyhedron& p, Ravelin::Origin3d diffuse_color = Ravelin::Origin3d(1,1,1),
bool wireframe =
false);
55 template <
class InputIterator1,
class InputIterator2>
56 TessellatedPolyhedron(InputIterator1 verts_begin, InputIterator1 verts_end, InputIterator2 facets_begin, InputIterator2 facets_end);
80 double convexity() {
if (!_convexity_computed) determine_convexity();
return _convexity; }
83 static void replace_edge(
const std::vector<Ravelin::Origin3d>& v, std::vector<IndexedTri>& f,
unsigned a,
unsigned b,
unsigned c, std::vector<unsigned>& del_list);
84 static bool find_vertex(
const std::vector<Ravelin::Origin3d>& vertices,
const Ravelin::Origin3d& v);
85 void calc_bounding_box();
86 static void calc_subexpressions(
double w0,
double w1,
double w2,
double& f1,
double& f2,
double& f3,
double& g0,
double& g1,
double& g2);
87 void determine_convexity();
88 static Ravelin::Origin3d intersect_plane(
const Ravelin::Vector3d& normal,
double d,
const Ravelin::Origin3d& p1,
const Ravelin::Origin3d& p2);
92 static bool bisects(
const Triangle& a,
const Triangle& b);
93 static bool bisect(
const Triangle& tbi, std::vector<Ravelin::Origin3d>& v, std::vector<IndexedTri>& f,
unsigned i);
94 static unsigned add_vertex(std::vector<Ravelin::Origin3d>& vertices,
const Ravelin::Origin3d& v);
96 Ravelin::Origin3d _bb_min, _bb_max;
99 bool _convexity_computed;
102 std::ostream& operator<<(std::ostream& out,
const TessellatedPolyhedron& p);
105 #include "TessellatedPolyhedron.inl"
void to_polyhedron(Polyhedron &p) const
Creates a polyhedron from this tessellated polyhedron.
Definition: TessellatedPolyhedron.cpp:203
void transform(const Ravelin::Transform3d &T)
Transforms this polyhedron by the given transformation matrix.
Definition: TessellatedPolyhedron.cpp:728
const std::list< unsigned > & get_incident_facets(unsigned i) const
Gets the indices of facets incident to a vertex.
Definition: IndexedTriArray.h:56
const Ravelin::Origin3d & find_extreme_vertex(const Ravelin::Origin3d &direction)
Does an extremal point query for the Polyhedron; returns a vertex furthest along the given direction...
Definition: TessellatedPolyhedron.cpp:1423
bool inside(const Ravelin::Origin3d &point, double tol=NEAR_ZERO)
Determines whether the specified point is strictly inside this polyhedron.
Definition: TessellatedPolyhedron.cpp:574
bool is_convex()
Determines whether this polyhedron convex (to w/in floating point tolerance)
Definition: TessellatedPolyhedron.h:71
const std::list< unsigned > & get_incident_facets(unsigned i) const
Gets the list of facets coincident to the i'th facet.
Definition: TessellatedPolyhedron.h:59
LocationType location(const Ravelin::Origin3d &point, double tol=NEAR_ZERO) const
Determines the location of the specified point with respect to this polyhedron.
Definition: TessellatedPolyhedron.cpp:627
static TessellatedPolyhedronPtr minkowski(TessellatedPolyhedron &p1, boost::shared_ptr< const Ravelin::Pose3d > T1, TessellatedPolyhedron &p2, boost::shared_ptr< const Ravelin::Pose3d > T2, bool reflect_p2=true)
Computes the Minkowski sum of two convex polyhedra.
Definition: TessellatedPolyhedron.cpp:473
bool degenerate() const
Checks whether this polyhedron is degenerate.
Definition: TessellatedPolyhedron.cpp:503
static void to_vrml(std::ostream &out, const TessellatedPolyhedron &p, Ravelin::Origin3d diffuse_color=Ravelin::Origin3d(1, 1, 1), bool wireframe=false)
Sends this polyhedron to the specified stream using VRML.
Definition: TessellatedPolyhedron.cpp:827
A potentially-non-convex polyhedron of genus 0.
Definition: Polyhedron.h:28
An array of triangles indexed into shared vertices.
Definition: IndexedTriArray.h:25
boost::shared_ptr< TessellatedPolyhedron > TessellatedPolyhedronPtr
TessellatedPolyhedron smart pointer.
Definition: Types.h:56
double calc_signed_distance(const Ravelin::Origin3d &point)
Gets the signed distance from a point to the polyhedron.
Definition: TessellatedPolyhedron.h:65
std::pair< Ravelin::Origin3d, Ravelin::Origin3d > get_bounding_box_corners() const
Gets the corners of the axis-aligned bounding box of this polyhedron.
Definition: TessellatedPolyhedron.h:68
static IndexedTriArray construct_union(TessellatedPolyhedron &p1, TessellatedPolyhedron &p2)
Unions two non-convex polyhedra.
Definition: TessellatedPolyhedron.cpp:1357
const std::vector< IndexedTri > & get_facets() const
Gets the vector of facets.
Definition: IndexedTriArray.h:65
Represents a three-dimensional polyhedron.
Definition: TessellatedPolyhedron.h:28
double calc_signed_distance(const Ravelin::Origin3d &point, unsigned &closest_facet)
Gets the signed distance and closest facet to a point.
double calc_volume() const
Calculates the volume of this polyhedron.
Definition: TessellatedPolyhedron.cpp:871
bool consistent() const
Checks whether this polyhedron is consistent.
Definition: TessellatedPolyhedron.cpp:522
const std::vector< Ravelin::Origin3d > & get_vertices() const
Gets the vector of verties.
Definition: IndexedTriArray.h:68
void operator=(const TessellatedPolyhedron &p)
Copies a polyhedron.
Definition: TessellatedPolyhedron.cpp:193
static IndexedTriArray construct_difference(TessellatedPolyhedron &p1, TessellatedPolyhedron &p2)
Constructs the Boolean difference p1 - p2.
Definition: TessellatedPolyhedron.cpp:1374
static IndexedTriArray construct_intersection(TessellatedPolyhedron &p1, TessellatedPolyhedron &p2)
Intersects two non-convex polyhedra.
Definition: TessellatedPolyhedron.cpp:1333
bool inside_or_on(const Ravelin::Origin3d &point, double tol=NEAR_ZERO)
Determines whether the specified point is in or on this polyhedron.
Definition: TessellatedPolyhedron.cpp:598
double convexity()
Gets the convexity of this polyhedron.
Definition: TessellatedPolyhedron.h:80