1 // This is gel/vsol/vsol_orient_box_3d.cxx
2 #include "vsol_orient_box_3d.h"
3 //:
4 // \file
5 
6 #include <vsol/vsol_point_3d.h>
7 #include <vsol/vsol_box_3d.h>
8 #include "vgl/vgl_point_3d.h"
9 #include <cassert>
10 #ifdef _MSC_VER
11 #  include "vcl_msvc_warnings.h"
12 #endif
13 
vsol_orient_box_3d(vgl_orient_box_3d<double> const & orient_box)14 vsol_orient_box_3d::vsol_orient_box_3d(vgl_orient_box_3d<double> const& orient_box)
15  : orient_box_(orient_box)
16 {
17   //create a bounding box from the 8 corner points of the oriented box
18   std::vector<vgl_point_3d<double> > corners = orient_box_.corners();
19   assert (corners.size() == 8);
20 
21   for (auto corner : corners) {
22     box_.update(corner.x(), corner.y(), corner.z());
23   }
24   this->set_bounding_box(new vsol_box_3d(box_));
25 }
26 
get_min_x() const27 double vsol_orient_box_3d::get_min_x() const
28 {
29   assert(!box_.empty());
30   return (box_.min())[0];
31 }
32 
get_max_x() const33 double vsol_orient_box_3d::get_max_x() const
34 {
35   assert(!box_.empty());
36   return (box_.max())[0];
37 }
38 
get_min_y() const39 double vsol_orient_box_3d::get_min_y() const
40 {
41   assert(!box_.empty());
42   return (box_.min())[1];
43 }
44 
get_max_y() const45 double vsol_orient_box_3d::get_max_y() const
46 {
47   assert(!box_.empty());
48   return (box_.max())[1];
49 }
50 
get_min_z() const51 double vsol_orient_box_3d::get_min_z() const
52 {
53   assert(!box_.empty());
54   return (box_.min())[2];
55 }
56 
get_max_z() const57 double vsol_orient_box_3d::get_max_z() const
58 {
59   assert(!box_.empty());
60   return (box_.max())[2];
61 }
62 
in(vsol_point_3d_sptr const & p) const63 bool vsol_orient_box_3d::in(vsol_point_3d_sptr const& p) const
64 {
65   // first test if the point inside the bounding box
66   if (box_.inside(p->x(), p->y(), p->z())) {
67     // now check if the rotated box contains the point
68     if (orient_box_.contains(p->x(), p->y(), p->z()))
69       return true;
70   }
71 
72   return false;
73 }
74 
add_point(double x,double y,double z)75 void vsol_orient_box_3d::add_point(double x, double y, double z)
76 {
77   box_.update(x, y, z);
78 }
79