2 #ifndef vgl_box_3d_hxx_ 3 #define vgl_box_3d_hxx_ 14 # include <vcl_msvc_warnings.h> 22 min_pos_[0]=min_pos_[1]=min_pos_[2]=(Type)1;
23 max_pos_[0]=max_pos_[1]=max_pos_[2]=(Type)0;
28 Type
const corner2[3])
30 min_pos_[0]=max_pos_[0]=corner1[0];
31 min_pos_[1]=max_pos_[1]=corner1[1];
32 min_pos_[2]=max_pos_[2]=corner1[2];
40 min_pos_[0]=max_pos_[0]=corner1.
x();
41 min_pos_[1]=max_pos_[1]=corner1.
y();
42 min_pos_[2]=max_pos_[2]=corner1.
z();
48 Type xmax, Type ymax, Type zmax)
50 min_pos_[0]=max_pos_[0]=xmin;
51 min_pos_[1]=max_pos_[1]=ymin;
52 min_pos_[2]=max_pos_[2]=zmin;
54 if (xmin > xmax || ymin > ymax || zmin > zmax) this->empty();
59 Type w, Type h, Type d,
64 min_pos_[0]=Type(ref_point[0]-0.5*w);
65 min_pos_[1]=Type(ref_point[1]-0.5*h);
66 min_pos_[2]=Type(ref_point[2]-0.5*d);
67 max_pos_[0]=Type(ref_point[0]+0.5*w);
68 max_pos_[1]=Type(ref_point[1]+0.5*h);
69 max_pos_[2]=Type(ref_point[2]+0.5*d);
73 min_pos_[0]=ref_point[0];
74 min_pos_[1]=ref_point[1];
75 min_pos_[2]=ref_point[2];
76 max_pos_[0]=ref_point[0]+w;
77 max_pos_[1]=ref_point[1]+h;
78 max_pos_[2]=ref_point[2]+d;
82 min_pos_[0]=ref_point[0]-w;
83 min_pos_[1]=ref_point[1]-h;
84 min_pos_[2]=ref_point[2]-d;
85 max_pos_[0]=ref_point[0];
86 max_pos_[1]=ref_point[1];
87 max_pos_[2]=ref_point[2];
90 assert(!
"point_type should be one of: centre, min_pos, max_pos");
95 Type w, Type h, Type d,
100 min_pos_[0]=Type(ref_point.
x()-0.5*w);
101 min_pos_[1]=Type(ref_point.
y()-0.5*h);
102 min_pos_[2]=Type(ref_point.
z()-0.5*d);
103 max_pos_[0]=Type(ref_point.
x()+0.5*w);
104 max_pos_[1]=Type(ref_point.
y()+0.5*h);
105 max_pos_[2]=Type(ref_point.
z()+0.5*d);
109 min_pos_[0]=ref_point.
x();
110 min_pos_[1]=ref_point.
y();
111 min_pos_[2]=ref_point.
z();
112 max_pos_[0]=ref_point.
x()+w;
113 max_pos_[1]=ref_point.
y()+h;
114 max_pos_[2]=ref_point.
z()+d;
118 min_pos_[0]=ref_point.
x()-w;
119 min_pos_[1]=ref_point.
y()-h;
120 min_pos_[2]=ref_point.
z()-d;
121 max_pos_[0]=ref_point.
x();
122 max_pos_[1]=ref_point.
y();
123 max_pos_[2]=ref_point.
z();
126 assert(!
"point_type should be one of: centre, min_pos, max_pos");
129 template <
class Type>
132 return (max_pos_[0] > min_pos_[0]) ? max_pos_[0] - min_pos_[0] : 0;
135 template <
class Type>
138 return (max_pos_[1] > min_pos_[1]) ? max_pos_[1] - min_pos_[1] : 0;
141 template <
class Type>
144 return (max_pos_[2] > min_pos_[2]) ? max_pos_[2] - min_pos_[2] : 0;
147 template <
class Type>
153 template <
class Type>
157 return Type(0.5*(min_pos_[0]+max_pos_[0]));
160 template <
class Type>
164 return Type(0.5*(min_pos_[1]+max_pos_[1]));
167 template <
class Type>
171 return Type(0.5*(min_pos_[2]+max_pos_[2]));
174 template <
class Type>
178 Type delta = cx - centroid_x();
179 min_pos_[0]= min_pos_[0] + delta;
180 max_pos_[0]= max_pos_[0] + delta;
183 template <
class Type>
187 Type delta = cy - centroid_y();
188 min_pos_[1]= min_pos_[1] + delta;
189 max_pos_[1]= max_pos_[1] + delta;
192 template <
class Type>
196 Type delta = cz - centroid_z();
197 min_pos_[2]= min_pos_[2] + delta;
198 max_pos_[2]= max_pos_[2] + delta;
202 inline void set_dim_3d(T& minv, T& maxv, T spread);
208 int sum = minv + maxv;
209 sum = sum | (spread&1);
210 minv = int(std::floor((sum-spread)/2.0));
218 minv = T( (x-spread)*0.5 );
219 maxv = minv + spread;
222 template <
class Type>
229 template <
class Type>
236 template <
class Type>
245 template <
class Type>
249 set_dim_3d(min_pos_[0], max_pos_[0], width() + expand );
250 set_dim_3d(min_pos_[1], max_pos_[1], height() + expand );
251 set_dim_3d(min_pos_[2], max_pos_[2], depth() + expand );
255 template <
class Type>
259 set_dim_3d(min_pos_[0], max_pos_[0], static_cast<Type>(width()*s));
260 set_dim_3d(min_pos_[1], max_pos_[1], static_cast<Type>(height()*s));
261 set_dim_3d(min_pos_[2], max_pos_[2], static_cast<Type>(depth()*s));
265 template <
class Type>
268 min_pos_[0] = static_cast<Type>(min_pos_[0] * s);
269 min_pos_[1] = static_cast<Type>(min_pos_[1] * s);
270 min_pos_[2] = static_cast<Type>(min_pos_[2] * s);
271 max_pos_[0] = static_cast<Type>(max_pos_[0] * s);
272 max_pos_[1] = static_cast<Type>(max_pos_[1] * s);
273 max_pos_[2] = static_cast<Type>(max_pos_[2] * s);
276 template <
class Type>
279 min_pos_[0]=min_position[0];
280 min_pos_[1]=min_position[1];
281 min_pos_[2]=min_position[2];
282 if (max_pos_[0] < min_pos_[0]) max_pos_[0]=min_pos_[0];
283 if (max_pos_[1] < min_pos_[1]) max_pos_[1]=min_pos_[1];
284 if (max_pos_[2] < min_pos_[2]) max_pos_[2]=min_pos_[2];
287 template <
class Type>
290 max_pos_[0]=max_position[0];
291 max_pos_[1]=max_position[1];
292 max_pos_[2]=max_position[2];
293 if (max_pos_[0] < min_pos_[0]) min_pos_[0]=max_pos_[0];
294 if (max_pos_[1] < min_pos_[1]) min_pos_[1]=max_pos_[1];
295 if (max_pos_[2] < min_pos_[2]) min_pos_[2]=max_pos_[2];
298 template <
class Type>
301 min_pos_[0]=min_pt.
x();
if (max_pos_[0]<min_pos_[0]) max_pos_[0]=min_pos_[0];
302 min_pos_[1]=min_pt.
y();
if (max_pos_[1]<min_pos_[1]) max_pos_[1]=min_pos_[1];
303 min_pos_[2]=min_pt.
z();
if (max_pos_[2]<min_pos_[2]) max_pos_[2]=min_pos_[2];
306 template <
class Type>
309 max_pos_[0]=max_pt.
x();
if (max_pos_[0]<min_pos_[0]) min_pos_[0]=max_pos_[0];
310 max_pos_[1]=max_pt.
y();
if (max_pos_[1]<min_pos_[1]) min_pos_[1]=max_pos_[1];
311 max_pos_[2]=max_pt.
z();
if (max_pos_[2]<min_pos_[2]) min_pos_[2]=max_pos_[2];
314 template <
class Type>
318 return s <<
"<vgl_box_3d (empty)>";
320 return s<<
"<vgl_box_3d " 321 << min_pos_[0] <<
',' << min_pos_[1] <<
',' << min_pos_[2] <<
" to " 322 << max_pos_[0] <<
',' << max_pos_[1] <<
',' << max_pos_[2] <<
'>';
325 template <
class Type>
332 template <
class Type>
339 template <
class Type>
343 std::vector<vgl_point_3d<Type> > vertices;
355 template <
class Type>
358 return s << min_pos_[0] <<
' ' << min_pos_[1] <<
' ' << min_pos_[2] <<
' ' 359 << max_pos_[0] <<
' ' << max_pos_[1] <<
' ' << max_pos_[2] <<
'\n';
362 template <
class Type>
365 return s >> min_pos_[0] >> min_pos_[1] >> min_pos_[2]
366 >> max_pos_[0] >> max_pos_[1] >> max_pos_[2];
372 template <
class Type>
377 min_pos_[0] = max_pos_[0] = p.
x();
378 min_pos_[1] = max_pos_[1] = p.
y();
379 min_pos_[2] = max_pos_[2] = p.
z();
383 if (p.
x() > max_pos_[0]) max_pos_[0] = p.
x();
384 if (p.
x() < min_pos_[0]) min_pos_[0] = p.
x();
385 if (p.
y() > max_pos_[1]) max_pos_[1] = p.
y();
386 if (p.
y() < min_pos_[1]) min_pos_[1] = p.
y();
387 if (p.
z() > max_pos_[2]) max_pos_[2] = p.
z();
388 if (p.
z() < min_pos_[2]) min_pos_[2] = p.
z();
396 template <
class Type>
405 template <
class Type>
408 return contains(p.
x(), p.
y(), p.
z());
412 template <
class Type>
421 template <
class Type>
424 min_pos_[0]=min_pos_[1]=min_pos_[2]=(Type)1;
425 max_pos_[0]=max_pos_[1]=max_pos_[2]=(Type)0;
429 template <
class Type>
436 template <
class Type>
442 #undef VGL_BOX_3D_INSTANTIATE 443 #define VGL_BOX_3D_INSTANTIATE(Type) \ 444 template class vgl_box_3d<Type >;\ 445 template std::ostream& operator<<(std::ostream&, vgl_box_3d<Type > const& p);\ 446 template std::istream& operator>>(std::istream&, vgl_box_3d<Type >& p) 448 #endif // vgl_box_3d_hxx_ void set_min_position(Type const m[3])
Modify min corner point. Max corner point only changed if necessary to avoid empty box.
void set_dim_3d(T &minv, T &maxv, T spread)
bool is_empty() const
Return true if this box is empty.
Type centroid_y() const
Get y component of centroid.
void set_depth(Type depth)
Set depth (z), centroid unchanged.
void set_width(Type width)
Set width (x), centroid unchanged.
Type min_z() const
Get min z.
Contains class to represent a cartesian 3D bounding box.
Represents a cartesian 3D point.
std::ostream & write(std::ostream &) const
Write "x0 y0 z0 x1 y1 z1(endl)" to stream.
void expand_about_centroid(Type expand)
Add to width and height, centroid unchanged.
std::ostream & operator<<(std::ostream &s, vgl_orient_box_3d< Type > const &p)
Write box to stream.
Type max_z() const
Get max z.
void set_max_position(Type const m[3])
Modify max corner point. Min corner point only changed if necessary to avoid empty box.
void set_max_point(vgl_point_3d< Type > const &max_pt)
Modify max corner point. Min corner point only changed if necessary to avoid empty box.
Type max_y() const
Get max y.
void set_height(Type height)
Set height (y), centroid unchanged.
void add(vgl_point_3d< Type > const &p)
Add a point to this box.
vgl_point_3d< Type > min_point() const
Return lower left corner of box.
vgl_box_3d()
Default constructor (creates empty box).
Type min_x() const
Get min x.
void set_centroid_x(Type cx)
Move box so centroid lies at cx (size unchanged).
Type centroid_z() const
Get z component of centroid.
void scale_about_centroid(double s)
Scale width, height and depth, centroid unchanged.
a point in 3D nonhomogeneous space
void set_min_point(vgl_point_3d< Type > const &min_pt)
Modify min corner point. Max corner point only changed if necessary to avoid empty box.
std::ostream & print(std::ostream &) const
Write "<vgl_box_3d x0,y0,z0 to x1,y1,z1>" to stream.
std::istream & read(std::istream &)
Read x0,y0,z0,x1,y1,z1 from stream.
void set_centroid_y(Type cy)
Move box so centroid lies at cy (size unchanged).
Type depth() const
Get depth of this box (= z dimension).
void empty()
Make the box empty.
Type centroid_x() const
Get x component of centroid.
vgl_point_3d< Type > centroid() const
Get the centroid point.
std::vector< vgl_point_3d< Type > > vertices() const
Return the 8 vertices of the box.
Type height() const
Get height of this box (= y dimension).
bool contains(vgl_point_3d< Type > const &p) const
Return true iff the point p is inside this box.
void set_centroid_z(Type cz)
Move box so centroid lies at cz (size unchanged).
vgl_point_3d< Type > max_point() const
Return upper right corner of box.
std::istream & operator>>(std::istream &is, vgl_orient_box_3d< Type > &p)
Read box from stream.
Type min_y() const
Get min y.
Type width() const
Get width of this box (= x dimension).
Represents a cartesian 3D box.
void scale_about_origin(double s)
Scale width, height and depth, keeping scaled position of origin unchanged.
Type max_x() const
Get max x.