X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fcompositeshape.h;h=5d0cd8c59532ed3b782c3cd60908c8ce96778b6c;hb=44bd1d1ab256d397be4e2169c4ca5efdd0569d31;hp=0c2c838ec7d13364e6408872cc8dfad113ce5914;hpb=4fc002747e8138501d08942be247e60cd99ac404;p=libs%2Fmath.git diff --git a/source/geometry/compositeshape.h b/source/geometry/compositeshape.h index 0c2c838..5d0cd8c 100644 --- a/source/geometry/compositeshape.h +++ b/source/geometry/compositeshape.h @@ -34,10 +34,11 @@ protected: public: virtual ~CompositeShape(); - virtual BoundingBox get_axis_aligned_bounding_box() const; + 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 max_isect; } virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const; + virtual Coverage get_coverage(const BoundingBox &) const; }; template @@ -99,8 +100,11 @@ inline CompositeShape::~CompositeShape() } template -inline BoundingBox CompositeShape::get_axis_aligned_bounding_box() const +inline BoundingBox CompositeShape::get_axis_aligned_bounding_box(unsigned detail) const { + if(detail) + return this->bisect_axis_aligned_bounding_box(detail); + BoundingBox aabb; for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) { @@ -179,6 +183,9 @@ inline unsigned CompositeShape::get_intersections(const Ray &ray, return 0; n = k; + + if(i!=shapes.begin()) + start_nesting = (start_nesting>!Ops::shortcircuit(true)); } if(buffer!=points) @@ -187,6 +194,23 @@ inline unsigned CompositeShape::get_intersections(const Ray &ray, return n; } +template +inline Coverage CompositeShape::get_coverage(const BoundingBox &bbox) const +{ + Coverage coverage = NO_COVERAGE; + for(typename ShapeArray::const_iterator i=shapes.begin(); i!=shapes.end(); ++i) + { + Coverage c = (*i)->get_coverage(bbox); + if(i==shapes.begin() || Ops::shortcircuit(c>coverage)) + coverage = c; + + if(coverage!=PARTIAL_COVERAGE && Ops::shortcircuit(coverage==FULL_COVERAGE)) + break; + } + + return coverage; +} + } // namespace Geometry } // namespace Msp