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;
17 AffineTransformation<T, D> inverse_trans;
20 TransformedShape(const Shape<T, D> &, const AffineTransformation<T, D> &);
21 TransformedShape(const TransformedShape &);
22 TransformedShape &operator=(const TransformedShape &);
25 virtual TransformedShape *clone() const;
27 const Shape<T, D> &get_shape() const { return *shape; }
28 const AffineTransformation<T, D> &get_transformation() const { return transformation; }
30 virtual HyperBox<T, D> get_axis_aligned_bounding_box() const;
31 virtual bool check_intersection(const Ray<T, D> &) const;
34 template<typename T, unsigned D>
35 inline TransformedShape<T, D>::TransformedShape(const Shape<T, D> &s, const AffineTransformation<T, D> &t):
38 inverse_trans(invert(t))
41 template<typename T, unsigned D>
42 inline TransformedShape<T, D>::TransformedShape(const TransformedShape &other):
43 shape(other.shape->clone()),
44 transformation(other.transformation),
45 inverse_trans(other.inverse_trans)
48 template<typename T, unsigned D>
49 inline TransformedShape<T, D> &TransformedShape<T, D>::operator=(const TransformedShape<T, D> &other)
52 shape = other.shape->clone();
53 transformation = other.transformation;
54 inverse_trans = other.inverse_trans;
57 template<typename T, unsigned D>
58 inline TransformedShape<T, D>::~TransformedShape()
63 template<typename T, unsigned D>
64 inline TransformedShape<T, D> *TransformedShape<T, D>::clone() const
66 return new TransformedShape<T, D>(*this);
69 template<typename T, unsigned D>
70 inline HyperBox<T, D> TransformedShape<T, D>::get_axis_aligned_bounding_box() const
72 // XXX This is not correct for most shapes
73 return shape->get_axis_aligned_bounding_box();
76 template<typename T, unsigned D>
77 inline bool TransformedShape<T, D>::check_intersection(const Ray<T, D> &ray) const
79 Ray<T, D> local_ray(inverse_trans.transform(ray.get_start()),
80 inverse_trans.transform_linear(ray.get_direction()));
81 return shape->check_intersection(local_ray);
84 } // namespace Geometry