00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef SHAPE_HPP
00021 #define SHAPE_HPP
00022
00023 #include <ReferenceCounting.hpp>
00024 #include <Transform.hpp>
00025
00026 #include <vector>
00027
00035 class Shape
00036 {
00037 public:
00045 enum ShapeType {
00046 sphere = 1,
00047 cylinder = 2,
00048 cone = 3,
00049 cube = 4,
00050 plane = 5,
00051 torus = 6,
00052 union_ = 7,
00053 difference = 8,
00054 intersection = 9,
00055 not_ =10,
00056 infiniteCylinder=11,
00057 infiniteCone =12,
00058 analytic =13
00059 };
00060
00061 typedef std::vector<ConstReferenceCounting<Transform> > TransformationsList;
00062
00063 protected:
00064 const ShapeType __type;
00066 TransformationsList __trans;
00075 virtual bool __inShape(const TinyVector<3, real_t>& x) const = 0;
00076
00084 virtual std::ostream& __put(std::ostream& os) const = 0;
00085
00086
00092 virtual ReferenceCounting<Shape> __getCopy() const = 0;
00093
00094 public:
00100 ReferenceCounting<Shape> getCopy() const
00101 {
00102 ReferenceCounting<Shape> shape = this->__getCopy();
00103 TransformationsList transformationsList;
00104 for (TransformationsList::const_iterator i=__trans.begin();
00105 i != __trans.end(); ++i) {
00106 const ConstReferenceCounting<Transform>& t = *i;
00107 transformationsList.push_back(t->getCopy());
00108 }
00109 shape->setTransformationsList(transformationsList);
00110
00111 return shape;
00112 }
00113
00119 const TransformationsList& transformationsList() const
00120 {
00121 return __trans;
00122 }
00123
00128 void setTransformationsList(const TransformationsList& l)
00129 {
00130 __trans = l;
00131 }
00132
00140 inline bool inside(const TinyVector<3,real_t>& x) const
00141 {
00142 TinyVector<3,real_t> X = x;
00143 for (size_t i = numberOfTransformations()-1; i<numberOfTransformations(); --i)
00144 X = inverseTransformation(i, X);
00145 return this->__inShape(X);
00146 }
00147
00153 const ShapeType& type() const
00154 {
00155 return __type;
00156 }
00157
00163 inline size_t numberOfTransformations() const
00164 {
00165 return __trans.size();
00166 }
00167
00173 void setTransformation(const Transform& t);
00174
00183 TinyVector<3, real_t> inverseTransformation(const size_t& i,
00184 const TinyVector<3,real_t>& x) const
00185 {
00186 return __trans[i]->inverse(x);
00187 }
00188
00197 friend std::ostream& operator << (std::ostream& os,
00198 const Shape& shape);
00199
00205 void parseTransform(const parsetrans& trans);
00206
00212 Shape(const ShapeType& type)
00213 : __type(type)
00214 {
00215 ;
00216 }
00217
00223 Shape(const Shape& shape)
00224 : __type(shape.__type),
00225 __trans(shape.__trans)
00226 {
00227 ;
00228 }
00229
00234 virtual ~Shape()
00235 {
00236 ;
00237 }
00238 };
00239
00240 #endif // SHAPE_HPP