vgl_orient_box_3d_operators.hxx
Go to the documentation of this file.
1 // This is core/vgl/algo/vgl_orient_box_3d_operators.hxx
2 #ifndef vgl_orient_box_3d_operators_hxx_
3 #define vgl_orient_box_3d_operators_hxx_
4 //:
5 // \file
6 
8 #include <vnl/vnl_quaternion.h>
9 #include <vnl/vnl_vector_fixed.h>
10 #include <cassert>
11 #ifdef _MSC_VER
12 # include <vcl_msvc_warnings.h>
13 #endif
14 
15 template <class T>
18 {
19  if (plist.size() == 0)
20  return vgl_box_3d<T>(); // an empty box
21  else if (plist.size() == 1)
22  return vgl_orient_box_3d_operators<T>::minimal_box(plist.front());
23  else if (plist.size() == 2)
24  {
25  vgl_box_3d<T> bb; bb.add(plist.front());
26  vgl_vector_3d<T> dir = plist.back() - plist.front();
27  vgl_vector_3d<T> rot_dir = vgl_vector_3d<T>(T(dir.length()), T(0), T(0));
28  bb.add(plist.front() + rot_dir);
29  vnl_quaternion<double> orient(vnl_vector_fixed<double,3>(dir.x(), dir.y(), dir.z()), 0.0);
30  return vgl_orient_box_3d<T>(bb, orient);
31  }
32  else
33  assert(!"Not yet implemented minimal_box() for more than 2 points");
34  return vgl_box_3d<T>(); // return an empty box in case of error
35 }
36 
37 #undef VGL_ORIENT_BOX_3D_OPERATORS_INSTANTIATE
38 #define VGL_ORIENT_BOX_3D_OPERATORS_INSTANTIATE(T) \
39 template class vgl_orient_box_3d_operators<T >
40 
41 #endif // vgl_orient_box_3d_operators_hxx_
void add(vgl_point_3d< Type > const &p)
Add a point to this box.
Definition: vgl_box_3d.hxx:373
double length() const
Return the length of this vector.
T y() const
Definition: vgl_vector_3d.h:37
T x() const
Definition: vgl_vector_3d.h:36
T z() const
Definition: vgl_vector_3d.h:38
Direction vector in Euclidean 3D space, templated by type of element.
Definition: vgl_fwd.h:13
Represents a cartesian 3D box.
Definition: vgl_box_3d.h:65
Compute the minimal oriented bounding box for several 3D shapes.
static vgl_orient_box_3d< T > minimal_box(vgl_point_3d< T > const &p)