X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=e3236e8cfaf03d69877fdfe94f7a75dc8e9f811e;hb=44bd1d1ab256d397be4e2169c4ca5efdd0569d31;hp=7d363f246a8a48e25cbb07762e351f7f4dc58936;hpb=adb812a194961d542dcb0abd61258cbc8723ecd9;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 7d363f2..e3236e8 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -3,10 +3,9 @@ #include #include +#include #include -#include "ray.h" #include "shape.h" -#include "surfacepoint.h" namespace Msp { namespace Geometry { @@ -30,11 +29,11 @@ public: const LinAl::Vector &get_dimensions() const { return dimensions; } T get_dimension(unsigned) const; - virtual HyperBox get_axis_aligned_bounding_box() const { return *this; } + virtual BoundingBox get_axis_aligned_bounding_box(unsigned = 0) const; virtual bool contains(const LinAl::Vector &) const; - virtual bool check_intersection(const Ray &) const; virtual unsigned get_max_ray_intersections() const { return 2; } virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; + virtual Coverage get_coverage(const BoundingBox &) const; }; template @@ -47,7 +46,11 @@ inline HyperBox::HyperBox() template inline HyperBox::HyperBox(const LinAl::Vector &d): dimensions(d) -{ } +{ + for(unsigned i=0; i inline HyperBox *HyperBox::clone() const @@ -62,18 +65,21 @@ inline T HyperBox::get_dimension(unsigned i) const } template -inline bool HyperBox::contains(const LinAl::Vector &point) const +inline BoundingBox HyperBox::get_axis_aligned_bounding_box(unsigned) const { - for(unsigned i=0; idimensions[i]/2) - return false; - return true; + LinAl::Vector half_dim = dimensions/T(2); + return BoundingBox(-half_dim, half_dim); } template -inline bool HyperBox::check_intersection(const Ray &ray) const +inline bool HyperBox::contains(const LinAl::Vector &point) const { - return get_intersections(ray, 0, 1); + using std::abs; + + for(unsigned i=0; idimensions[i]/T(2)) + return false; + return true; } template @@ -81,18 +87,20 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP { using std::abs; + if(size>2) + size = 2; + LinAl::Vector half_dim = dimensions/T(2); unsigned n = 0; - T first_depth = T(); - for(unsigned i=0; i p = ray.get_start()+ray.get_direction()*x; @@ -101,22 +109,30 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP for(unsigned k=0; (inside && k(); - points[n].normal[i] = j; - if(n==0) - first_depth = x; - else if(n==1 && x0 && entry!=points[0].entry) + { + if(entry) + points[1] = points[0]; + else + ++k; + } + if(k(); + points[k].normal[i] = j; + points[k].distance = x; + points[k].entry = (T(j)*ray.get_direction()[i]::get_intersections(const Ray &ray, SurfaceP return n; } +template +inline Coverage HyperBox::get_coverage(const BoundingBox &bbox) const +{ + const LinAl::Vector &min_pt = bbox.get_minimum_point(); + const LinAl::Vector &max_pt = bbox.get_maximum_point(); + LinAl::Vector half_dim = dimensions/T(2); + + Coverage coverage = FULL_COVERAGE; + for(unsigned i=0; ihalf_dim[i]) + return NO_COVERAGE; + if(min_pt[i]<-half_dim[i] || max_pt[i]>half_dim[i]) + coverage = PARTIAL_COVERAGE; + } + + return coverage; +} + } // namespace Geometry } // namespace Msp