contrib/gel/vsol/vsol_orient_box_3d.cxx
Go to the documentation of this file.
00001 // This is gel/vsol/vsol_orient_box_3d.cxx
00002 #include "vsol_orient_box_3d.h"
00003 //:
00004 // \file
00005 
00006 #include <vsol/vsol_point_3d.h>
00007 #include <vsol/vsol_box_3d.h>
00008 #include <vgl/vgl_point_3d.h>
00009 #include <vcl_cassert.h>
00010 
00011 vsol_orient_box_3d::vsol_orient_box_3d(vgl_orient_box_3d<double> const& orient_box)
00012  : orient_box_(orient_box)
00013 {
00014   //create a bounding box from the 8 corner points of the oriented box
00015   vcl_vector<vgl_point_3d<double> > corners = orient_box_.corners();
00016   assert (corners.size() == 8);
00017 
00018   for (unsigned int i=0; i < corners.size(); i++) {
00019     vgl_point_3d<double> corner = corners[i];
00020     box_.update(corner.x(), corner.y(), corner.z());
00021   }
00022   this->set_bounding_box(new vsol_box_3d(box_));
00023 }
00024 
00025 double vsol_orient_box_3d::get_min_x() const
00026 {
00027   assert(!box_.empty());
00028   return (box_.min())[0];
00029 }
00030 
00031 double vsol_orient_box_3d::get_max_x() const
00032 {
00033   assert(!box_.empty());
00034   return (box_.max())[0];
00035 }
00036 
00037 double vsol_orient_box_3d::get_min_y() const
00038 {
00039   assert(!box_.empty());
00040   return (box_.min())[1];
00041 }
00042 
00043 double vsol_orient_box_3d::get_max_y() const
00044 {
00045   assert(!box_.empty());
00046   return (box_.max())[1];
00047 }
00048 
00049 double vsol_orient_box_3d::get_min_z() const
00050 {
00051   assert(!box_.empty());
00052   return (box_.min())[2];
00053 }
00054 
00055 double vsol_orient_box_3d::get_max_z() const
00056 {
00057   assert(!box_.empty());
00058   return (box_.max())[2];
00059 }
00060 
00061 bool vsol_orient_box_3d::in(vsol_point_3d_sptr const& p) const
00062 {
00063   // first test if the point inside the bounding box
00064   if (box_.inside(p->x(), p->y(), p->z())) {
00065     // now check if the rotated box contains the point
00066     if (orient_box_.contains(p->x(), p->y(), p->z()))
00067       return true;
00068   }
00069 
00070   return false;
00071 }
00072 
00073 void vsol_orient_box_3d::add_point(double x, double y, double z)
00074 {
00075   box_.update(x, y, z);
00076 }