X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fshape.h;h=bbe255f9054f919792ca748a7c25468b62bfabc8;hb=09cc3a8648dd20e9a07d669b353c4a120b67c1c4;hp=528a77ca6d97d42e748bb4a47a17f88508394bfa;hpb=6ff13022b53830d35283905d562c2ef3af198cc1;p=libs%2Fmath.git diff --git a/source/geometry/shape.h b/source/geometry/shape.h index 528a77c..bbe255f 100644 --- a/source/geometry/shape.h +++ b/source/geometry/shape.h @@ -1,15 +1,26 @@ #ifndef MSP_GEOMETRY_SHAPE_H_ #define MSP_GEOMETRY_SHAPE_H_ +#include +#include + namespace Msp { namespace Geometry { template -class HyperBox; +class BoundingBox; template class Ray; +template +class SurfacePoint; + +/** +Base class and interface for geometric shapes. Shapes may be bounded or +unbounded. They are always considered to be solid, i.e. have a distinct inside +and an outside. +*/ template class Shape { @@ -20,10 +31,30 @@ public: virtual Shape *clone() const = 0; - virtual HyperBox get_axis_aligned_bounding_box() const = 0; - virtual bool check_intersection(const Ray &) const = 0; + virtual BoundingBox get_axis_aligned_bounding_box() const = 0; + virtual bool contains(const LinAl::Vector &) const = 0; + bool check_intersection(const Ray &) const; + virtual unsigned get_max_ray_intersections() const = 0; + virtual unsigned get_intersections(const Ray &, SurfacePoint *, unsigned) const = 0; + std::vector > get_intersections(const Ray &) const; }; +template +inline bool Shape::check_intersection(const Ray &ray) const +{ + return get_intersections(ray, 0, 1); +} + +template +inline std::vector > Shape::get_intersections(const Ray &ray) const +{ + unsigned max_isect = get_max_ray_intersections(); + std::vector > points(max_isect); + unsigned count = get_intersections(ray, &points[0], max_isect); + points.resize(count); + return points; +} + } // namespace Geometry } // namespace Msp