[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 |
|
---|
[997784] | 31 |
|
---|
| 32 | class Shape_impl {
|
---|
| 33 | public:
|
---|
[e09b70] | 34 | Shape_impl(){};
|
---|
| 35 | virtual ~Shape_impl(){};
|
---|
[735940] | 36 | virtual bool isInside(const Vector &point) const=0;
|
---|
| 37 | virtual bool isOnSurface(const Vector &point) const=0;
|
---|
| 38 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException)=0;
|
---|
[6acc2f3] | 39 | virtual Vector getCenter() const=0;
|
---|
| 40 | virtual double getRadius() const=0;
|
---|
[c67c65] | 41 | virtual double getVolume() const=0;
|
---|
| 42 | virtual double getSurfaceArea() const=0;
|
---|
[735940] | 43 | virtual LineSegmentSet getLineIntersections(const Line&) const=0;
|
---|
[b92e4a] | 44 | virtual std::string toString() const =0;
|
---|
| 45 | virtual enum ShapeType getType() const =0;
|
---|
[9c1c89] | 46 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
|
---|
[5a8d61] | 47 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const=0;
|
---|
[997784] | 48 | };
|
---|
| 49 |
|
---|
| 50 | class Everywhere_impl : public Shape_impl {
|
---|
| 51 | public:
|
---|
[735940] | 52 | virtual bool isInside(const Vector &point) const{
|
---|
[997784] | 53 | return true;
|
---|
| 54 | }
|
---|
[735940] | 55 | virtual bool isOnSurface(const Vector &point) const{
|
---|
[5de9da] | 56 | return false;
|
---|
| 57 | }
|
---|
[735940] | 58 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
---|
[b94634] | 59 | throw NotOnSurfaceException() << ShapeVector(&point);
|
---|
[5de9da] | 60 | }
|
---|
[6acc2f3] | 61 | virtual Vector getCenter() const {
|
---|
| 62 | return Vector(0.,0.,0.);
|
---|
| 63 | }
|
---|
| 64 | virtual double getRadius() const {
|
---|
| 65 | return std::numeric_limits<double>::infinity();
|
---|
| 66 | }
|
---|
[c67c65] | 67 | virtual double getVolume() const
|
---|
| 68 | {
|
---|
| 69 | // TODO
|
---|
| 70 | return 0.;
|
---|
| 71 | }
|
---|
| 72 | virtual double getSurfaceArea() const
|
---|
| 73 | {
|
---|
| 74 | // TODO
|
---|
| 75 | return 0.;
|
---|
| 76 | }
|
---|
[735940] | 77 | virtual LineSegmentSet getLineIntersections(const Line &line) const{
|
---|
[c6f395] | 78 | LineSegmentSet res(line);
|
---|
| 79 | res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
|
---|
| 80 | return res;
|
---|
| 81 | }
|
---|
[b92e4a] | 82 | virtual std::string toString() const{
|
---|
[cfda65] | 83 | return "Everywhere()";
|
---|
| 84 | }
|
---|
[b92e4a] | 85 | virtual enum ShapeType getType() const {
|
---|
| 86 | return EverywhereType;
|
---|
| 87 | }
|
---|
[9c1c89] | 88 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
[c5186e] | 89 | std::vector<Vector> PointsOnSurface;
|
---|
| 90 | return PointsOnSurface;
|
---|
| 91 | }
|
---|
[5a8d61] | 92 | std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const {
|
---|
| 93 | ASSERT(0,
|
---|
| 94 | "Everywhere_impl::getHomogeneousPointsInVolume() - not implemented.");
|
---|
| 95 | return std::vector<Vector>();
|
---|
| 96 | }
|
---|
[997784] | 97 | };
|
---|
| 98 |
|
---|
| 99 | class Nowhere_impl : public Shape_impl {
|
---|
[735940] | 100 | virtual bool isInside(const Vector &point) const{
|
---|
[997784] | 101 | return false;
|
---|
| 102 | }
|
---|
[735940] | 103 | virtual bool isOnSurface(const Vector &point) const{
|
---|
[5de9da] | 104 | return false;
|
---|
| 105 | }
|
---|
[735940] | 106 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
---|
[b94634] | 107 | throw NotOnSurfaceException() << ShapeVector(&point);
|
---|
[5de9da] | 108 | }
|
---|
[6acc2f3] | 109 | virtual Vector getCenter() const {
|
---|
| 110 | return Vector(0.,0.,0.);
|
---|
| 111 | }
|
---|
| 112 | virtual double getRadius() const {
|
---|
| 113 | return 0.;
|
---|
| 114 | }
|
---|
[c67c65] | 115 | virtual double getVolume() const
|
---|
| 116 | {
|
---|
| 117 | return 0.;
|
---|
| 118 | }
|
---|
| 119 | virtual double getSurfaceArea() const
|
---|
| 120 | {
|
---|
| 121 | return 0.;
|
---|
| 122 | }
|
---|
[735940] | 123 | virtual LineSegmentSet getLineIntersections(const Line &line) const{
|
---|
[c6f395] | 124 | return LineSegmentSet(line);
|
---|
| 125 | }
|
---|
[b92e4a] | 126 | virtual std::string toString() const{
|
---|
[cfda65] | 127 | return "Nowhere()";
|
---|
| 128 | }
|
---|
[b92e4a] | 129 | virtual enum ShapeType getType() const {
|
---|
| 130 | return NowhereType;
|
---|
| 131 | }
|
---|
[9c1c89] | 132 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
[c5186e] | 133 | std::vector<Vector> PointsOnSurface;
|
---|
| 134 | return PointsOnSurface;
|
---|
| 135 | }
|
---|
[5a8d61] | 136 | std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const {
|
---|
| 137 | return std::vector<Vector>();
|
---|
| 138 | }
|
---|
[997784] | 139 | };
|
---|
| 140 |
|
---|
| 141 | class AndShape_impl : public Shape_impl {
|
---|
| 142 | public:
|
---|
| 143 | AndShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
|
---|
| 144 | virtual ~AndShape_impl();
|
---|
[735940] | 145 | virtual bool isInside(const Vector &point) const;
|
---|
| 146 | virtual bool isOnSurface(const Vector &point) const;
|
---|
| 147 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
|
---|
[6acc2f3] | 148 | virtual Vector getCenter() const;
|
---|
| 149 | virtual double getRadius() const;
|
---|
[c67c65] | 150 | virtual double getVolume() const;
|
---|
| 151 | virtual double getSurfaceArea() const;
|
---|
[735940] | 152 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
[b92e4a] | 153 | virtual std::string toString() const;
|
---|
| 154 | virtual enum ShapeType getType() const;
|
---|
[9c1c89] | 155 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
[5a8d61] | 156 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
[997784] | 157 | private:
|
---|
| 158 | Shape::impl_ptr lhs;
|
---|
| 159 | Shape::impl_ptr rhs;
|
---|
| 160 | };
|
---|
| 161 |
|
---|
| 162 | class OrShape_impl : public Shape_impl {
|
---|
| 163 | public:
|
---|
| 164 | OrShape_impl(const Shape::impl_ptr&, const Shape::impl_ptr&);
|
---|
| 165 | virtual ~OrShape_impl();
|
---|
[735940] | 166 | virtual bool isInside(const Vector &point) const;
|
---|
| 167 | virtual bool isOnSurface(const Vector &point) const;
|
---|
| 168 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
|
---|
[6acc2f3] | 169 | virtual Vector getCenter() const;
|
---|
| 170 | virtual double getRadius() const;
|
---|
[c67c65] | 171 | virtual double getVolume() const;
|
---|
| 172 | virtual double getSurfaceArea() const;
|
---|
[735940] | 173 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
[b92e4a] | 174 | virtual std::string toString() const;
|
---|
| 175 | virtual enum ShapeType getType() const;
|
---|
[9c1c89] | 176 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
[5a8d61] | 177 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
[997784] | 178 | private:
|
---|
| 179 | Shape::impl_ptr lhs;
|
---|
| 180 | Shape::impl_ptr rhs;
|
---|
| 181 | };
|
---|
| 182 |
|
---|
| 183 | class NotShape_impl : public Shape_impl {
|
---|
| 184 | public:
|
---|
| 185 | NotShape_impl(const Shape::impl_ptr&);
|
---|
| 186 | virtual ~NotShape_impl();
|
---|
[735940] | 187 | virtual bool isInside(const Vector &point) const;
|
---|
| 188 | virtual bool isOnSurface(const Vector &point) const;
|
---|
| 189 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException);
|
---|
[6acc2f3] | 190 | virtual Vector getCenter() const;
|
---|
| 191 | virtual double getRadius() const;
|
---|
[c67c65] | 192 | virtual double getVolume() const;
|
---|
| 193 | virtual double getSurfaceArea() const;
|
---|
[735940] | 194 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
[b92e4a] | 195 | virtual std::string toString() const;
|
---|
| 196 | virtual enum ShapeType getType() const;
|
---|
[9c1c89] | 197 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
[5a8d61] | 198 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
[997784] | 199 | private:
|
---|
| 200 | Shape::impl_ptr arg;
|
---|
| 201 | };
|
---|
| 202 |
|
---|
[e09b70] | 203 | Shape::impl_ptr getShapeImpl(const Shape&);
|
---|
| 204 |
|
---|
[997784] | 205 | #endif /* SHAPE_IMPL_HPP_ */
|
---|