1 #ifndef MSP_GEOMETRY_TRANSFORMEDSHAPE_H_
2 #define MSP_GEOMETRY_TRANSFORMEDSHAPE_H_
4 #include "affinetransformation.h"
11 template<typename T, unsigned D>
12 class TransformedShape: public Shape<T, D>
16 AffineTransformation<T, D> transformation;
19 TransformedShape(const Shape<T, D> &, const AffineTransformation<T, D> &);
20 TransformedShape(const TransformedShape &);
21 TransformedShape &operator=(const TransformedShape &);
24 virtual TransformedShape *clone() const;
26 const Shape<T, D> &get_shape() const { return *shape; }
27 const AffineTransformation<T, D> &get_transformation() const { return transformation; }
29 virtual HyperBox<T, D> get_axis_aligned_bounding_box() const;
30 virtual bool check_intersection(const Ray<T, D> &) const;
33 template<typename T, unsigned D>
34 inline TransformedShape<T, D>::TransformedShape(const Shape<T, D> &s, const AffineTransformation<T, D> &t):
39 template<typename T, unsigned D>
40 inline TransformedShape<T, D>::TransformedShape(const TransformedShape &other):
41 shape(other.shape->clone()),
42 transformation(other.transformation)
45 template<typename T, unsigned D>
46 inline TransformedShape<T, D> &TransformedShape<T, D>::operator=(const TransformedShape<T, D> &other)
49 shape = other.shape->clone();
50 transformation = other.transformation();
53 template<typename T, unsigned D>
54 inline TransformedShape<T, D>::~TransformedShape()
59 template<typename T, unsigned D>
60 inline TransformedShape<T, D> *TransformedShape<T, D>::clone() const
62 return new TransformedShape<T, D>(*this);
65 template<typename T, unsigned D>
66 inline HyperBox<T, D> TransformedShape<T, D>::get_axis_aligned_bounding_box() const
68 // XXX This is not correct for most shapes
69 return shape->get_axis_aligned_bounding_box();
72 template<typename T, unsigned D>
73 inline bool TransformedShape<T, D>::check_intersection(const Ray<T, D> &ray) const
75 // TODO cache the inverse transformation for performance
76 LinAl::SquareMatrix<T, D+1> inverse_trans = LinAl::invert(transformation.get_matrix());
77 Ray<T, D> trans_ray(reduce_vector(inverse_trans*augment_vector(ray.get_start(), T(1))),
78 reduce_vector(inverse_trans*augment_vector(ray.get_direction(), T(0))));
79 return shape->check_intersection(trans_ray);
82 } // namespace Geometry