1 #ifndef vgl_frustum_3d_hxx_ 2 #define vgl_frustum_3d_hxx_ 12 # include <vcl_msvc_warnings.h> 24 int nc = static_cast<int>(corner_rays.size());
26 n_top_bot_face_verts_= nc;
34 double er = std::fabs(
cos_angle(norm, dir));
40 if(dp>0) snorm = -norm;
41 double dp_mag = std::fabs(dp);
42 double tau_near = d0/dp_mag;
45 near_plane_ = static_cast<int>(surface_planes_.size());
46 surface_planes_.push_back(pln_near);
49 verts_.push_back(p_near);
50 for(
int i = 1; i<nc; ++i){
53 bool good = vgl_intersection<Type>(corner_rays[i], pln_near, pint);
55 verts_.push_back(pint);
63 for(
int i = 0; i<nc; ++i)
64 faces_[near_plane_].push_back(i);
66 for(
int i = nc-1; i>=0; --i)
67 faces_[near_plane_].push_back(i);
69 assert(this->is_convex());
71 double tau_far = d1/dp_mag;
73 int far_indx = static_cast<int>(verts_.size());
74 verts_.push_back(p_far);
77 far_plane_ = static_cast<int>(surface_planes_.size());
78 surface_planes_.push_back(pln_far);
80 for(
int i = 1; i<nc; ++i){
83 bool good = vgl_intersection<Type>(corner_rays[i], pln_far, pi);
89 for(
int i = nc-1; i>=0; --i)
90 faces_[far_plane_].push_back(i+far_indx);
92 for(
int i = 0; i<nc; ++i)
93 faces_[near_plane_].push_back(i+far_indx);
98 std::vector<int>& top_verts = faces_[near_plane_];
99 for(
int i = 0; i<nc; ++i){
100 int j = top_verts[i];
101 int j_next = top_verts[(i+1)%nc];
105 int pln_index = static_cast<int>(surface_planes_.size());
106 surface_planes_.push_back(pln);
107 faces_[pln_index].push_back(j); faces_[pln_index].push_back(j_next);
108 faces_[pln_index].push_back(j_next+far_indx);
109 faces_[pln_index].push_back(j+far_indx);
113 template <
class Type>
119 if(!(apex_ == other.
apex()))
121 int n = static_cast<int>(verts_.size());
122 const std::vector<vgl_point_3d<Type> >& o_verts = other.
verts();
124 for(
int i = 0; i<n; ++i){
125 double dif = (verts_[i] - o_verts[i]).
length();
131 template <
class Type>
134 int n = static_cast<int>(verts_.size());
135 for(
int i = 0; i<n; ++i)
139 template <
class Type>
141 int n = static_cast<int>(verts_.size());
142 double x_sum = 0.0, y_sum = 0.0, z_sum = 0.0;
143 for(
int i = 0; i<n; ++i){
144 x_sum += static_cast<double>(verts_[i].x());
145 y_sum += static_cast<double>(verts_[i].y());
146 z_sum += static_cast<double>(verts_[i].z());
148 x_sum /= n; y_sum /= n; z_sum /= n;
149 Type x = static_cast<Type>(x_sum);
150 Type y = static_cast<Type>(y_sum);
151 Type z = static_cast<Type>(z_sum);
156 template <
class Type>
158 int n = n_top_bot_face_verts_;
159 if(n<3)
return false;
160 if(n==3)
return true;
163 std::map<int, std::vector<int> >::const_iterator vit;
164 vit = faces_.find(near_plane_);
165 if(vit==faces_.end())
return false;
166 const std::vector<int>& vindx = (*vit).second;
172 for(
int i = 2; i<n; ++i){
173 int j = (vindx[i]+1)%n;
178 if(pos_i != pos)
return false;
184 template <
class Type>
186 contains(Type
const& x, Type
const& y, Type
const& z)
const{
190 int n = static_cast<int>(surface_planes_.size());
192 for(
int i = 0; i<n&&inside; ++i){
193 Type a = surface_planes_[i].a(), b = surface_planes_[i].b();
194 Type c = surface_planes_[i].c(), d = surface_planes_[i].d();
195 Type sign = a*x + b*y + c*z +d;
196 inside = sign < vgl_tolerance<Type>::position;
201 template <
class Type>
203 return contains(p.
x(), p.
y(), p.
z());
206 template <
class Type>
208 s <<
"<vgl_frustum_3d [\n";
209 const std::vector<vgl_point_3d<Type> >& verts = f.
verts();
210 int n = static_cast<int>(verts.size());
211 for(
int i = 0; i<n; ++i)
212 s << verts[i] <<
'\n';
216 #undef VGL_FRUSTUM_3D_INSTANTIATE 217 #define VGL_FRUSTUM_3D_INSTANTIATE(Type) \ 218 template class vgl_frustum_3d<Type >;\ 219 template std::ostream& operator<<(std::ostream&, vgl_frustum_3d<Type > const& f) 221 #endif //vgl_frustum_3d_hxx_ Set of intersection functions.
T dot_product(v const &a, v const &b)
dot product or inner product of two vectors.
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.
Represents a cartesian 3D point.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
A 3-d ray defined by an origin and a direction vector.
double length(v const &a)
Return the length of a vector.
void add(vgl_point_3d< Type > const &p)
Add a point to this box.
vgl_box_3d< Type > bounding_box() const
bool operator==(vgl_frustum_3d< Type > const &other) const
Equality test.
const std::vector< vgl_point_3d< Type > > & verts() const
T cross_product(v const &a, v const &b)
cross product of two vectors (area of enclosed parallellogram).
Represents a Euclidean 3D plane.
const vgl_point_3d< Type > & apex() const
bool is_convex() const
test if the frustum is convex.
vgl_point_3d< Type > origin() const
Accessors.
vgl_point_3d< Type > centroid() const
Get the centroid point.
vgl_frustum_3d()
default constructor.
a plane in 3D nonhomogeneous space
Represents a cartesian 3D box.
double cos_angle(v const &a, v const &b)
cosine of the angle between two vectors.
vgl_vector_3d< Type > direction() const
A polygonal cone truncated by parallel planes.