X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fhyperbox.h;h=e3236e8cfaf03d69877fdfe94f7a75dc8e9f811e;hb=44bd1d1ab256d397be4e2169c4ca5efdd0569d31;hp=9a161f35fb0fdbc5ff604735d51eb6e1d060eeaf;hpb=827b227ae53884109b6885ccd1424dda8c0b3725;p=libs%2Fmath.git diff --git a/source/geometry/hyperbox.h b/source/geometry/hyperbox.h index 9a161f3..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,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 @@ -66,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 { @@ -77,12 +82,6 @@ inline bool HyperBox::contains(const LinAl::Vector &point) const return true; } -template -inline bool HyperBox::check_intersection(const Ray &ray) const -{ - return get_intersections(ray, 0, 1); -} - template inline unsigned HyperBox::get_intersections(const Ray &ray, SurfacePoint *points, unsigned size) const { @@ -114,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