core/vgl/algo/vgl_orient_box_3d_operators.txx
Go to the documentation of this file.
00001 // This is core/vgl/algo/vgl_orient_box_3d_operators.txx
00002 #ifndef vgl_orient_box_3d_operators_txx_
00003 #define vgl_orient_box_3d_operators_txx_
00004 //:
00005 // \file
00006 
00007 #include "vgl_orient_box_3d_operators.h"
00008 #include <vnl/vnl_quaternion.h>
00009 #include <vnl/vnl_vector_fixed.h>
00010 #include <vcl_cassert.h>
00011 
00012 template <class T>
00013 vgl_orient_box_3d<T>
00014 vgl_orient_box_3d_operators<T>::minimal_box(vcl_vector<vgl_point_3d<T> > const& plist)
00015 {
00016   if (plist.size() == 0)
00017     return vgl_box_3d<T>(); // an empty box
00018   else if (plist.size() == 1)
00019     return vgl_orient_box_3d_operators<T>::minimal_box(plist.front());
00020   else if (plist.size() == 2)
00021   {
00022     vgl_box_3d<T> bb; bb.add(plist.front());
00023     vgl_vector_3d<T> dir = plist.back() - plist.front();
00024     vgl_vector_3d<T> rot_dir = vgl_vector_3d<T>(T(dir.length()), T(0), T(0));
00025     bb.add(plist.front() + rot_dir);
00026     vnl_quaternion<double> orient(vnl_vector_fixed<double,3>(dir.x(), dir.y(), dir.z()), 0.0);
00027     return vgl_orient_box_3d<T>(bb, orient);
00028   }
00029   else
00030     assert(!"Not yet implemented minimal_box() for more than 2 points");
00031   return vgl_box_3d<T>(); // return an empty box in case of error
00032 }
00033 
00034 #undef VGL_ORIENT_BOX_3D_OPERATORS_INSTANTIATE
00035 #define VGL_ORIENT_BOX_3D_OPERATORS_INSTANTIATE(T) \
00036 template class vgl_orient_box_3d_operators<T >
00037 
00038 #endif // vgl_orient_box_3d_operators_txx_