| [997784] | 1 | /*
 | 
|---|
 | 2 |  * Shape_impl.hpp
 | 
|---|
 | 3 |  *
 | 
|---|
 | 4 |  *  Created on: Jun 18, 2010
 | 
|---|
 | 5 |  *      Author: crueger
 | 
|---|
 | 6 |  */
 | 
|---|
 | 7 | 
 | 
|---|
 | 8 | #ifndef SHAPE_IMPL_HPP_
 | 
|---|
 | 9 | #define SHAPE_IMPL_HPP_
 | 
|---|
 | 10 | 
 | 
|---|
| [56f73b] | 11 | // include config.h
 | 
|---|
 | 12 | #ifdef HAVE_CONFIG_H
 | 
|---|
 | 13 | #include <config.h>
 | 
|---|
 | 14 | #endif
 | 
|---|
 | 15 | 
 | 
|---|
 | 16 | 
 | 
|---|
| [6acc2f3] | 17 | #include <limits>
 | 
|---|
| [c5186e] | 18 | #include <vector>
 | 
|---|
 | 19 | 
 | 
|---|
| [5a8d61] | 20 | #include "CodePatterns/Assert.hpp"
 | 
|---|
 | 21 | 
 | 
|---|
| [997784] | 22 | #include "Shapes/Shape.hpp"
 | 
|---|
| [b94634] | 23 | #include "Shapes/ShapeExceptions.hpp"
 | 
|---|
| [b92e4a] | 24 | #include "Shapes/ShapeType.hpp"
 | 
|---|
| [6c438f] | 25 | #include "LinearAlgebra/Line.hpp"
 | 
|---|
| [7672551] | 26 | #include "LinearAlgebra/LinePoint.hpp"
 | 
|---|
| [6c438f] | 27 | #include "LinearAlgebra/LineSegment.hpp"
 | 
|---|
 | 28 | #include "LinearAlgebra/LineSegmentSet.hpp"
 | 
|---|
 | 29 | #include "LinearAlgebra/Vector.hpp"
 | 
|---|
| [c6f395] | 30 | 
 | 
|---|
| [f06cbb] | 31 | #include "CodePatterns/Cacheable.hpp"
 | 
|---|
 | 32 | 
 | 
|---|
| [997784] | 33 | 
 | 
|---|
 | 34 | class Shape_impl {
 | 
|---|
 | 35 | public:
 | 
|---|
| [e09b70] | 36 |   Shape_impl(){};
 | 
|---|
 | 37 |   virtual ~Shape_impl(){};
 | 
|---|
| [735940] | 38 |   virtual bool isInside(const Vector &point) const=0;
 | 
|---|
 | 39 |   virtual bool isOnSurface(const Vector &point) const=0;
 | 
|---|
 | 40 |   virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException)=0;
 | 
|---|
| [6acc2f3] | 41 |   virtual Vector getCenter() const=0;
 | 
|---|
 | 42 |   virtual double getRadius() const=0;
 | 
|---|
| [c67c65] | 43 |   virtual double getVolume() const=0;
 | 
|---|
 | 44 |   virtual double getSurfaceArea() const=0;
 | 
|---|
| [735940] | 45 |   virtual LineSegmentSet getLineIntersections(const Line&) const=0;
 | 
|---|
| [b92e4a] | 46 |   virtual std::string toString() const =0;
 | 
|---|
 | 47 |   virtual enum ShapeType getType() const =0;
 | 
|---|
| [9c1c89] | 48 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
 | 
|---|
| [5a8d61] | 49 |   virtual   std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const=0;
 | 
|---|
| [997784] | 50 | };
 | 
|---|
 | 51 | 
 | 
|---|
 | 52 | class Everywhere_impl : public Shape_impl {
 | 
|---|
 | 53 | public:
 | 
|---|
| [735940] | 54 |   virtual bool isInside(const Vector &point) const{
 | 
|---|
| [997784] | 55 |     return true;
 | 
|---|
 | 56 |   }
 | 
|---|
| [735940] | 57 |   virtual bool isOnSurface(const Vector &point) const{
 | 
|---|
| [5de9da] | 58 |     return false;
 | 
|---|
 | 59 |   }
 | 
|---|
| [735940] | 60 |   virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
 | 
|---|
| [b94634] | 61 |     throw NotOnSurfaceException() << ShapeVector(&point);
 | 
|---|
| [5de9da] | 62 |   }
 | 
|---|
| [6acc2f3] | 63 |   virtual Vector getCenter() const {
 | 
|---|
 | 64 |     return Vector(0.,0.,0.);
 | 
|---|
 | 65 |   }
 | 
|---|
 | 66 |   virtual double getRadius() const {
 | 
|---|
 | 67 |     return std::numeric_limits<double>::infinity();
 | 
|---|
 | 68 |   }
 | 
|---|
| [c67c65] | 69 |   virtual double getVolume() const
 | 
|---|
 | 70 |   {
 | 
|---|
 | 71 |         // TODO
 | 
|---|
 | 72 |         return 0.;
 | 
|---|
 | 73 |   }
 | 
|---|
 | 74 |   virtual double getSurfaceArea() const
 | 
|---|
 | 75 |   {
 | 
|---|
 | 76 |         // TODO
 | 
|---|
 | 77 |         return 0.;
 | 
|---|
 | 78 |   }
 | 
|---|
| [735940] | 79 |   virtual LineSegmentSet getLineIntersections(const Line &line) const{
 | 
|---|
| [c6f395] | 80 |     LineSegmentSet res(line);
 | 
|---|
 | 81 |     res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
 | 
|---|
 | 82 |     return res;
 | 
|---|
 | 83 |   }
 | 
|---|
| [b92e4a] | 84 |   virtual std::string toString() const{
 | 
|---|
| [cfda65] | 85 |     return "Everywhere()";
 | 
|---|
 | 86 |   }
 | 
|---|
| [b92e4a] | 87 |   virtual enum ShapeType getType() const {
 | 
|---|
 | 88 |         return EverywhereType;
 | 
|---|
 | 89 |   }
 | 
|---|
| [9c1c89] | 90 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
 | 
|---|
| [c5186e] | 91 |     std::vector<Vector> PointsOnSurface;
 | 
|---|
 | 92 |     return PointsOnSurface;
 | 
|---|
 | 93 |   }
 | 
|---|
| [5a8d61] | 94 |   std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const {
 | 
|---|
 | 95 |         ASSERT(0,
 | 
|---|
 | 96 |                         "Everywhere_impl::getHomogeneousPointsInVolume() - not implemented.");
 | 
|---|
 | 97 |         return std::vector<Vector>();
 | 
|---|
 | 98 |   }
 | 
|---|
| [997784] | 99 | };
 | 
|---|
 | 100 | 
 | 
|---|
 | 101 | class Nowhere_impl : public Shape_impl {
 | 
|---|
| [735940] | 102 |   virtual bool isInside(const Vector &point) const{
 | 
|---|
| [997784] | 103 |     return false;
 | 
|---|
 | 104 |   }
 | 
|---|
| [735940] | 105 |   virtual bool isOnSurface(const Vector &point) const{
 | 
|---|
| [5de9da] | 106 |     return false;
 | 
|---|
 | 107 |   }
 | 
|---|
| [735940] | 108 |   virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
 | 
|---|
| [b94634] | 109 |     throw NotOnSurfaceException() << ShapeVector(&point);
 | 
|---|
| [5de9da] | 110 |   }
 | 
|---|
| [6acc2f3] | 111 |   virtual Vector getCenter() const {
 | 
|---|
 | 112 |     return Vector(0.,0.,0.);
 | 
|---|
 | 113 |   }
 | 
|---|
 | 114 |   virtual double getRadius() const {
 | 
|---|
 | 115 |     return 0.;
 | 
|---|
 | 116 |   }
 | 
|---|
| [c67c65] | 117 |   virtual double getVolume() const
 | 
|---|
 | 118 |   {
 | 
|---|
 | 119 |         return 0.;
 | 
|---|
 | 120 |   }
 | 
|---|
 | 121 |   virtual double getSurfaceArea() const
 | 
|---|
 | 122 |   {
 | 
|---|
 | 123 |         return 0.;
 | 
|---|
 | 124 |   }
 | 
|---|
| [735940] | 125 |   virtual LineSegmentSet getLineIntersections(const Line &line) const{
 | 
|---|
| [c6f395] | 126 |     return LineSegmentSet(line);
 | 
|---|
 | 127 |   }
 | 
|---|
| [b92e4a] | 128 |   virtual std::string toString() const{
 | 
|---|
| [cfda65] | 129 |     return "Nowhere()";
 | 
|---|
 | 130 |   }
 | 
|---|
| [b92e4a] | 131 |   virtual enum ShapeType getType() const {
 | 
|---|
 | 132 |         return NowhereType;
 | 
|---|
 | 133 |   }
 | 
|---|
| [9c1c89] | 134 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
 | 
|---|
| [c5186e] | 135 |     std::vector<Vector> PointsOnSurface;
 | 
|---|
 | 136 |     return PointsOnSurface;
 | 
|---|
 | 137 |   }
 | 
|---|
| [5a8d61] | 138 |   std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const {
 | 
|---|
 | 139 |         return std::vector<Vector>();
 | 
|---|
 | 140 |   }
 | 
|---|
| [997784] | 141 | };
 | 
|---|
 | 142 | 
 | 
|---|
 | 143 | class AndShape_impl : public Shape_impl {
 | 
|---|
 | 144 | public:
 | 
|---|
 | 145 |   AndShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
 | 
|---|
 | 146 |   virtual ~AndShape_impl();
 | 
|---|
| [735940] | 147 |   virtual bool isInside(const Vector &point) const;
 | 
|---|
 | 148 |   virtual bool isOnSurface(const Vector &point) const;
 | 
|---|
 | 149 |   virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
 | 
|---|
| [f06cbb] | 150 |   virtual Vector getCenter() const
 | 
|---|
 | 151 |   { return *center; }
 | 
|---|
 | 152 |   virtual double getRadius() const
 | 
|---|
 | 153 |   { return *radius; }
 | 
|---|
| [c67c65] | 154 |   virtual double getVolume() const;
 | 
|---|
 | 155 |   virtual double getSurfaceArea() const;
 | 
|---|
| [735940] | 156 |   virtual LineSegmentSet getLineIntersections(const Line&) const;
 | 
|---|
| [b92e4a] | 157 |   virtual std::string toString() const;
 | 
|---|
 | 158 |   virtual enum ShapeType getType() const;
 | 
|---|
| [9c1c89] | 159 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
 | 
|---|
| [5a8d61] | 160 |   virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
 | 
|---|
| [997784] | 161 | private:
 | 
|---|
| [f06cbb] | 162 |   double calculateRadius() const;
 | 
|---|
 | 163 |   Vector calculateCenter() const;
 | 
|---|
 | 164 | 
 | 
|---|
| [997784] | 165 |   Shape::impl_ptr lhs;
 | 
|---|
 | 166 |   Shape::impl_ptr rhs;
 | 
|---|
| [f06cbb] | 167 |   Cacheable<double> radius;
 | 
|---|
 | 168 |   Cacheable<Vector> center;
 | 
|---|
| [997784] | 169 | };
 | 
|---|
 | 170 | 
 | 
|---|
 | 171 | class OrShape_impl : public Shape_impl {
 | 
|---|
 | 172 | public:
 | 
|---|
 | 173 |   OrShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
 | 
|---|
 | 174 |   virtual ~OrShape_impl();
 | 
|---|
| [735940] | 175 |   virtual bool isInside(const Vector &point) const;
 | 
|---|
 | 176 |   virtual bool isOnSurface(const Vector &point) const;
 | 
|---|
 | 177 |   virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
 | 
|---|
| [f06cbb] | 178 |   virtual Vector getCenter() const
 | 
|---|
 | 179 |   { return *center; }
 | 
|---|
 | 180 |   virtual double getRadius() const
 | 
|---|
 | 181 |   { return *radius; }
 | 
|---|
| [c67c65] | 182 |   virtual double getVolume() const;
 | 
|---|
 | 183 |   virtual double getSurfaceArea() const;
 | 
|---|
| [735940] | 184 |   virtual LineSegmentSet getLineIntersections(const Line&) const;
 | 
|---|
| [b92e4a] | 185 |   virtual std::string toString() const;
 | 
|---|
 | 186 |   virtual enum ShapeType getType() const;
 | 
|---|
| [9c1c89] | 187 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
 | 
|---|
| [5a8d61] | 188 |   virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
 | 
|---|
| [997784] | 189 | private:
 | 
|---|
| [f06cbb] | 190 |   double calculateRadius() const;
 | 
|---|
 | 191 |   Vector calculateCenter() const;
 | 
|---|
 | 192 | 
 | 
|---|
| [997784] | 193 |   Shape::impl_ptr lhs;
 | 
|---|
 | 194 |   Shape::impl_ptr rhs;
 | 
|---|
| [f06cbb] | 195 |   Cacheable<double> radius;
 | 
|---|
 | 196 |   Cacheable<Vector> center;
 | 
|---|
| [997784] | 197 | };
 | 
|---|
 | 198 | 
 | 
|---|
 | 199 | class NotShape_impl : public Shape_impl {
 | 
|---|
 | 200 | public:
 | 
|---|
 | 201 |   NotShape_impl(const Shape::impl_ptr&);
 | 
|---|
 | 202 |   virtual ~NotShape_impl();
 | 
|---|
| [735940] | 203 |   virtual bool isInside(const Vector &point) const;
 | 
|---|
 | 204 |   virtual bool isOnSurface(const Vector &point) const;
 | 
|---|
 | 205 |   virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
 | 
|---|
| [6acc2f3] | 206 |   virtual Vector getCenter() const;
 | 
|---|
 | 207 |   virtual double getRadius() const;
 | 
|---|
| [c67c65] | 208 |   virtual double getVolume() const;
 | 
|---|
 | 209 |   virtual double getSurfaceArea() const;
 | 
|---|
| [735940] | 210 |   virtual LineSegmentSet getLineIntersections(const Line&) const;
 | 
|---|
| [b92e4a] | 211 |   virtual std::string toString() const;
 | 
|---|
 | 212 |   virtual enum ShapeType getType() const;
 | 
|---|
| [9c1c89] | 213 |   virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
 | 
|---|
| [5a8d61] | 214 |   virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
 | 
|---|
| [997784] | 215 | private:
 | 
|---|
 | 216 |   Shape::impl_ptr arg;
 | 
|---|
 | 217 | };
 | 
|---|
 | 218 | 
 | 
|---|
| [e09b70] | 219 | Shape::impl_ptr getShapeImpl(const Shape&);
 | 
|---|
 | 220 | 
 | 
|---|
| [997784] | 221 | #endif /* SHAPE_IMPL_HPP_ */
 | 
|---|