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 |
|
---|
11 | // include config.h
|
---|
12 | #ifdef HAVE_CONFIG_H
|
---|
13 | #include <config.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 |
|
---|
17 | #include <limits>
|
---|
18 | #include <vector>
|
---|
19 |
|
---|
20 | #include "CodePatterns/Assert.hpp"
|
---|
21 |
|
---|
22 | #include "Shapes/Shape.hpp"
|
---|
23 | #include "Shapes/ShapeExceptions.hpp"
|
---|
24 | #include "Shapes/ShapeType.hpp"
|
---|
25 | #include "LinearAlgebra/Line.hpp"
|
---|
26 | #include "LinearAlgebra/LinePoint.hpp"
|
---|
27 | #include "LinearAlgebra/LineSegment.hpp"
|
---|
28 | #include "LinearAlgebra/LineSegmentSet.hpp"
|
---|
29 | #include "LinearAlgebra/Vector.hpp"
|
---|
30 |
|
---|
31 |
|
---|
32 | class Shape_impl {
|
---|
33 | public:
|
---|
34 | Shape_impl(){};
|
---|
35 | virtual ~Shape_impl(){};
|
---|
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;
|
---|
39 | virtual Vector getCenter() const=0;
|
---|
40 | virtual double getRadius() const=0;
|
---|
41 | virtual double getVolume() const=0;
|
---|
42 | virtual double getSurfaceArea() const=0;
|
---|
43 | virtual LineSegmentSet getLineIntersections(const Line&) const=0;
|
---|
44 | virtual std::string toString() const =0;
|
---|
45 | virtual enum ShapeType getType() const =0;
|
---|
46 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
|
---|
47 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const=0;
|
---|
48 | };
|
---|
49 |
|
---|
50 | class Everywhere_impl : public Shape_impl {
|
---|
51 | public:
|
---|
52 | virtual bool isInside(const Vector &point) const{
|
---|
53 | return true;
|
---|
54 | }
|
---|
55 | virtual bool isOnSurface(const Vector &point) const{
|
---|
56 | return false;
|
---|
57 | }
|
---|
58 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
---|
59 | throw NotOnSurfaceException() << ShapeVector(&point);
|
---|
60 | }
|
---|
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 | }
|
---|
67 | virtual double getVolume() const
|
---|
68 | {
|
---|
69 | // TODO
|
---|
70 | return 0.;
|
---|
71 | }
|
---|
72 | virtual double getSurfaceArea() const
|
---|
73 | {
|
---|
74 | // TODO
|
---|
75 | return 0.;
|
---|
76 | }
|
---|
77 | virtual LineSegmentSet getLineIntersections(const Line &line) const{
|
---|
78 | LineSegmentSet res(line);
|
---|
79 | res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
|
---|
80 | return res;
|
---|
81 | }
|
---|
82 | virtual std::string toString() const{
|
---|
83 | return "Everywhere()";
|
---|
84 | }
|
---|
85 | virtual enum ShapeType getType() const {
|
---|
86 | return EverywhereType;
|
---|
87 | }
|
---|
88 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
89 | std::vector<Vector> PointsOnSurface;
|
---|
90 | return PointsOnSurface;
|
---|
91 | }
|
---|
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 | }
|
---|
97 | };
|
---|
98 |
|
---|
99 | class Nowhere_impl : public Shape_impl {
|
---|
100 | virtual bool isInside(const Vector &point) const{
|
---|
101 | return false;
|
---|
102 | }
|
---|
103 | virtual bool isOnSurface(const Vector &point) const{
|
---|
104 | return false;
|
---|
105 | }
|
---|
106 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
---|
107 | throw NotOnSurfaceException() << ShapeVector(&point);
|
---|
108 | }
|
---|
109 | virtual Vector getCenter() const {
|
---|
110 | return Vector(0.,0.,0.);
|
---|
111 | }
|
---|
112 | virtual double getRadius() const {
|
---|
113 | return 0.;
|
---|
114 | }
|
---|
115 | virtual double getVolume() const
|
---|
116 | {
|
---|
117 | return 0.;
|
---|
118 | }
|
---|
119 | virtual double getSurfaceArea() const
|
---|
120 | {
|
---|
121 | return 0.;
|
---|
122 | }
|
---|
123 | virtual LineSegmentSet getLineIntersections(const Line &line) const{
|
---|
124 | return LineSegmentSet(line);
|
---|
125 | }
|
---|
126 | virtual std::string toString() const{
|
---|
127 | return "Nowhere()";
|
---|
128 | }
|
---|
129 | virtual enum ShapeType getType() const {
|
---|
130 | return NowhereType;
|
---|
131 | }
|
---|
132 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
133 | std::vector<Vector> PointsOnSurface;
|
---|
134 | return PointsOnSurface;
|
---|
135 | }
|
---|
136 | std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const {
|
---|
137 | return std::vector<Vector>();
|
---|
138 | }
|
---|
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();
|
---|
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);
|
---|
148 | virtual Vector getCenter() const;
|
---|
149 | virtual double getRadius() const;
|
---|
150 | virtual double getVolume() const;
|
---|
151 | virtual double getSurfaceArea() const;
|
---|
152 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
153 | virtual std::string toString() const;
|
---|
154 | virtual enum ShapeType getType() const;
|
---|
155 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
156 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
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();
|
---|
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);
|
---|
169 | virtual Vector getCenter() const;
|
---|
170 | virtual double getRadius() const;
|
---|
171 | virtual double getVolume() const;
|
---|
172 | virtual double getSurfaceArea() const;
|
---|
173 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
174 | virtual std::string toString() const;
|
---|
175 | virtual enum ShapeType getType() const;
|
---|
176 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
177 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
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();
|
---|
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);
|
---|
190 | virtual Vector getCenter() const;
|
---|
191 | virtual double getRadius() const;
|
---|
192 | virtual double getVolume() const;
|
---|
193 | virtual double getSurfaceArea() const;
|
---|
194 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
195 | virtual std::string toString() const;
|
---|
196 | virtual enum ShapeType getType() const;
|
---|
197 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
198 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
199 | private:
|
---|
200 | Shape::impl_ptr arg;
|
---|
201 | };
|
---|
202 |
|
---|
203 | Shape::impl_ptr getShapeImpl(const Shape&);
|
---|
204 |
|
---|
205 | #endif /* SHAPE_IMPL_HPP_ */
|
---|