X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=e3236e8cfaf03d69877fdfe94f7a75dc8e9f811e;hb=291c11cf66e7083dc21fffea1afbdeaaad96077d;hp=11c197e72ebb059814e0c92f685ac533b72acaa2;hpb=313e10c1dcf5504789cc145166aece93d8141212;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 11c197e..e3236e8 100644 --- a/source/geometry/hyperbox.h +++ b/source/geometry/hyperbox.h @@ -5,9 +5,7 @@ #include #include #include -#include "ray.h" #include "shape.h" -#include "surfacepoint.h" namespace Msp { namespace Geometry { @@ -31,10 +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 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 @@ -65,6 +64,13 @@ inline T HyperBox::get_dimension(unsigned i) const return dimensions[i]; } +template +inline BoundingBox HyperBox::get_axis_aligned_bounding_box(unsigned) const +{ + LinAl::Vector half_dim = dimensions/T(2); + return BoundingBox(-half_dim, half_dim); +} + template inline bool HyperBox::contains(const LinAl::Vector &point) const { @@ -107,13 +113,23 @@ inline unsigned HyperBox::get_intersections(const Ray &ray, SurfaceP { if(points) { - points[n].position = p; - points[n].normal = LinAl::Vector(); - points[n].normal[i] = j; - points[n].distance = x; - - 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