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