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 | #include "CodePatterns/Cacheable.hpp"
|
---|
32 |
|
---|
33 |
|
---|
34 | class Shape_impl {
|
---|
35 | public:
|
---|
36 | Shape_impl(){};
|
---|
37 | virtual ~Shape_impl(){};
|
---|
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;
|
---|
41 | virtual Vector getCenter() const=0;
|
---|
42 | virtual double getRadius() const=0;
|
---|
43 | virtual double getVolume() const=0;
|
---|
44 | virtual double getSurfaceArea() const=0;
|
---|
45 | virtual LineSegmentSet getLineIntersections(const Line&) const=0;
|
---|
46 | virtual std::string toString() const =0;
|
---|
47 | virtual enum ShapeType getType() const =0;
|
---|
48 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const=0;
|
---|
49 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const=0;
|
---|
50 | };
|
---|
51 |
|
---|
52 | class Everywhere_impl : public Shape_impl {
|
---|
53 | public:
|
---|
54 | virtual bool isInside(const Vector &point) const{
|
---|
55 | return true;
|
---|
56 | }
|
---|
57 | virtual bool isOnSurface(const Vector &point) const{
|
---|
58 | return false;
|
---|
59 | }
|
---|
60 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
---|
61 | throw NotOnSurfaceException() << ShapeVector(&point);
|
---|
62 | }
|
---|
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 | }
|
---|
69 | virtual double getVolume() const
|
---|
70 | {
|
---|
71 | // TODO
|
---|
72 | return 0.;
|
---|
73 | }
|
---|
74 | virtual double getSurfaceArea() const
|
---|
75 | {
|
---|
76 | // TODO
|
---|
77 | return 0.;
|
---|
78 | }
|
---|
79 | virtual LineSegmentSet getLineIntersections(const Line &line) const{
|
---|
80 | LineSegmentSet res(line);
|
---|
81 | res.insert(LineSegment(line.negEndpoint(),line.posEndpoint()));
|
---|
82 | return res;
|
---|
83 | }
|
---|
84 | virtual std::string toString() const{
|
---|
85 | return "Everywhere()";
|
---|
86 | }
|
---|
87 | virtual enum ShapeType getType() const {
|
---|
88 | return EverywhereType;
|
---|
89 | }
|
---|
90 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
91 | std::vector<Vector> PointsOnSurface;
|
---|
92 | return PointsOnSurface;
|
---|
93 | }
|
---|
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 | }
|
---|
99 | };
|
---|
100 |
|
---|
101 | class Nowhere_impl : public Shape_impl {
|
---|
102 | virtual bool isInside(const Vector &point) const{
|
---|
103 | return false;
|
---|
104 | }
|
---|
105 | virtual bool isOnSurface(const Vector &point) const{
|
---|
106 | return false;
|
---|
107 | }
|
---|
108 | virtual Vector getNormal(const Vector &point) const throw(NotOnSurfaceException){
|
---|
109 | throw NotOnSurfaceException() << ShapeVector(&point);
|
---|
110 | }
|
---|
111 | virtual Vector getCenter() const {
|
---|
112 | return Vector(0.,0.,0.);
|
---|
113 | }
|
---|
114 | virtual double getRadius() const {
|
---|
115 | return 0.;
|
---|
116 | }
|
---|
117 | virtual double getVolume() const
|
---|
118 | {
|
---|
119 | return 0.;
|
---|
120 | }
|
---|
121 | virtual double getSurfaceArea() const
|
---|
122 | {
|
---|
123 | return 0.;
|
---|
124 | }
|
---|
125 | virtual LineSegmentSet getLineIntersections(const Line &line) const{
|
---|
126 | return LineSegmentSet(line);
|
---|
127 | }
|
---|
128 | virtual std::string toString() const{
|
---|
129 | return "Nowhere()";
|
---|
130 | }
|
---|
131 | virtual enum ShapeType getType() const {
|
---|
132 | return NowhereType;
|
---|
133 | }
|
---|
134 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const {
|
---|
135 | std::vector<Vector> PointsOnSurface;
|
---|
136 | return PointsOnSurface;
|
---|
137 | }
|
---|
138 | std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const {
|
---|
139 | return std::vector<Vector>();
|
---|
140 | }
|
---|
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();
|
---|
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);
|
---|
150 | virtual Vector getCenter() const
|
---|
151 | { return *center; }
|
---|
152 | virtual double getRadius() const
|
---|
153 | { return *radius; }
|
---|
154 | virtual double getVolume() const;
|
---|
155 | virtual double getSurfaceArea() const;
|
---|
156 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
157 | virtual std::string toString() const;
|
---|
158 | virtual enum ShapeType getType() const;
|
---|
159 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
160 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
161 | private:
|
---|
162 | double calculateRadius() const;
|
---|
163 | Vector calculateCenter() const;
|
---|
164 |
|
---|
165 | Shape::impl_ptr lhs;
|
---|
166 | Shape::impl_ptr rhs;
|
---|
167 | Cacheable<double> radius;
|
---|
168 | Cacheable<Vector> center;
|
---|
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();
|
---|
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);
|
---|
178 | virtual Vector getCenter() const
|
---|
179 | { return *center; }
|
---|
180 | virtual double getRadius() const
|
---|
181 | { return *radius; }
|
---|
182 | virtual double getVolume() const;
|
---|
183 | virtual double getSurfaceArea() const;
|
---|
184 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
185 | virtual std::string toString() const;
|
---|
186 | virtual enum ShapeType getType() const;
|
---|
187 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
188 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
189 | private:
|
---|
190 | double calculateRadius() const;
|
---|
191 | Vector calculateCenter() const;
|
---|
192 |
|
---|
193 | Shape::impl_ptr lhs;
|
---|
194 | Shape::impl_ptr rhs;
|
---|
195 | Cacheable<double> radius;
|
---|
196 | Cacheable<Vector> center;
|
---|
197 | };
|
---|
198 |
|
---|
199 | class NotShape_impl : public Shape_impl {
|
---|
200 | public:
|
---|
201 | NotShape_impl(const Shape::impl_ptr&);
|
---|
202 | virtual ~NotShape_impl();
|
---|
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);
|
---|
206 | virtual Vector getCenter() const;
|
---|
207 | virtual double getRadius() const;
|
---|
208 | virtual double getVolume() const;
|
---|
209 | virtual double getSurfaceArea() const;
|
---|
210 | virtual LineSegmentSet getLineIntersections(const Line&) const;
|
---|
211 | virtual std::string toString() const;
|
---|
212 | virtual enum ShapeType getType() const;
|
---|
213 | virtual std::vector<Vector> getHomogeneousPointsOnSurface(const size_t N) const;
|
---|
214 | virtual std::vector<Vector> getHomogeneousPointsInVolume(const size_t N) const;
|
---|
215 | private:
|
---|
216 | Shape::impl_ptr arg;
|
---|
217 | };
|
---|
218 |
|
---|
219 | Shape::impl_ptr getShapeImpl(const Shape&);
|
---|
220 |
|
---|
221 | #endif /* SHAPE_IMPL_HPP_ */
|
---|