vgl_frustum_3d.h
Go to the documentation of this file.
1 // This is core/vgl/vgl_frustum_3d.h
2 #ifndef vgl_frustum_3d_h
3 #define vgl_frustum_3d_h
4 //:
5 // \file
6 // \brief A polygonal cone truncated by parallel planes
7 // \author J.L. Mundy
8 // \date December 1, 2013
9 //
10 // \verbatim
11 // Modifications
12 // None
13 // \endverbatim
14 
15 #include <iosfwd>
16 #include <vector>
17 #include <map>
18 #ifdef _MSC_VER
19 # include <vcl_msvc_warnings.h>
20 #endif
21 #include <vgl/vgl_plane_3d.h>
22 #include <vgl/vgl_point_3d.h> // forward declare vgl datatypes
23 
24 //: A 3D frustum is the portion of a solid (normally a cone or pyramid)
25 // that lies between two parallel planes cutting it.
26 //
27 template <class Type>
29 {
30  public:
31  //: default constructor
33 
34  //: Construct the frustum from rays
35  // the corner rays intersect in a common origin point, i.e., the apex
36  // of the frustum cone. It is assumed the rays are in sorted order
37  // around the cone surface, so that sequential rays are coplanar
38  // with a cone surface plane and the cross product r[i].dir X r[i+1].dir
39  // defines an outward-pointing normal. norm is the vector
40  // perpendicular to the parallel frustum faces. d0 is the distance in
41  // the norm vector dirction from the apex to the closest parallel face.
42  // d1 the distance in the norm direction from the apex to the far face.
43  //
44  vgl_frustum_3d(std::vector<vgl_ray_3d<Type> > const& corner_rays,
45  vgl_vector_3d<Type> const& norm, Type d0, Type d1);
46 
47 
48  //: Equality test
49  inline bool operator==(vgl_frustum_3d<Type> const& other) const;
50 
51  // Data Access---------------------------------------------------------------
52  const vgl_point_3d<Type>& apex() const{
53  return apex_;}
54 
55  const std::vector<vgl_plane_3d<Type> >& surface_planes() const
56  {return surface_planes_;}
57 
59  {return surface_planes_[near_plane_];}
60 
62  {return surface_planes_[far_plane_];}
63 
64  const std::vector<vgl_point_3d<Type> >& verts() const
65  {return verts_;}
66 
67  const std::map<int, std::vector<int> >& faces() const
68  {return faces_;}
69 
71 
72  //: Get the centroid point
74 
75  //: test if the frustum is convex
76  bool is_convex() const;
77 
78  // Data Control--------------------------------------------------------------
79 
80  //: Return true iff the point p is inside this frustum
81  // assumes that the frustum is a convex solid
82  bool contains(vgl_point_3d<Type> const& p) const;
83 
84  //: Return true if \a (x,y,z) is inside this frustum
85  // assumes that the frustum is a convex solid
86  bool contains(Type const& x, Type const& y, Type const& z) const;
87 
88  // I/O-----------------------------------------------------------------------
89 
90 
91  // INTERNALS-----------------------------------------------------------------
92  protected:
93  // Data Members--------------------------------------------------------------
96  //: planes bounding the frustum volume including near and far plane
97  std::vector<vgl_plane_3d<Type> > surface_planes_;
100  std::vector<vgl_point_3d<Type> > verts_;
101  //: the number of verts in the top or bottom face
103  // key corresponds to plane index, value is clockwise verts on face boundary
104  // clockwise with respect the the face normal
105  std::map<int, std::vector<int> > faces_;
106 };
107 
108 //: Write frustum to stream
109 // \relatesalso vgl_frustum_3d
110 template <class Type>
111 std::ostream& operator<<(std::ostream& s, vgl_frustum_3d<Type> const& p);
112 
113 
114 
115 #define VGL_FRUSTUM_3D_INSTANTIATE(T) extern "please include vgl/vgl_frustum_3d.hxx first"
116 
117 #endif // vgl_frustum_3d_h
int n_top_bot_face_verts_
the number of verts in the top or bottom face.
const std::vector< vgl_plane_3d< Type > > & surface_planes() const
const vgl_plane_3d< Type > & near_plane() const
A 3D frustum is the portion of a solid (normally a cone or pyramid).
bool contains(vgl_point_3d< Type > const &p) const
Return true iff the point p is inside this frustum.
std::vector< vgl_point_3d< Type > > verts_
Represents a cartesian 3D point.
Definition: vgl_fwd.h:11
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
vgl_box_3d< Type > bounding_box() const
a point in 3D nonhomogeneous space
bool operator==(vgl_frustum_3d< Type > const &other) const
Equality test.
const std::vector< vgl_point_3d< Type > > & verts() const
Represents a Euclidean 3D plane.
Definition: vgl_fwd.h:23
const vgl_point_3d< Type > & apex() const
Represents a 3-d ray.
Definition: vgl_fwd.h:21
bool is_convex() const
test if the frustum is convex.
std::map< int, std::vector< int > > faces_
vgl_vector_3d< Type > norm_
vgl_point_3d< Type > centroid() const
Get the centroid point.
vgl_frustum_3d()
default constructor.
const std::map< int, std::vector< int > > & faces() const
a plane in 3D nonhomogeneous space
std::vector< vgl_plane_3d< Type > > surface_planes_
planes bounding the frustum volume including near and far plane.
Represents a cartesian 3D box.
Definition: vgl_box_3d.h:65
const vgl_plane_3d< Type > & far_plane() const
vgl_point_3d< Type > apex_