1 | // This file is a part of the Framsticks GDK. |
---|
2 | // Copyright (C) 2002-2014 Maciej Komosinski and Szymon Ulatowski. See LICENSE.txt for details. |
---|
3 | // Refer to http://www.framsticks.com/ for further information. |
---|
4 | |
---|
5 | #ifndef _MESHBUILDER_H_ |
---|
6 | #define _MESHBUILDER_H_ |
---|
7 | |
---|
8 | #include <frams/model/model.h> |
---|
9 | #include <frams/model/modelparts.h> |
---|
10 | #include <frams/util/3d.h> |
---|
11 | #include <frams/util/list.h> |
---|
12 | #include "geometryutils.h" |
---|
13 | |
---|
14 | namespace MeshBuilder |
---|
15 | { |
---|
16 | class Callback |
---|
17 | { |
---|
18 | public: |
---|
19 | virtual void operator()(const Pt3D &point) = 0; |
---|
20 | }; |
---|
21 | |
---|
22 | class Iterator |
---|
23 | { |
---|
24 | protected: |
---|
25 | double density; |
---|
26 | public: |
---|
27 | Iterator(const double _density); |
---|
28 | double getDensity() const; |
---|
29 | double setDensity(const double _density); |
---|
30 | virtual bool tryGetNext(Pt3D &point) = 0; |
---|
31 | void forEach(Callback &callback); |
---|
32 | void addAllPointsToList(SListTempl<Pt3D> &list); |
---|
33 | }; |
---|
34 | |
---|
35 | class Segment: public Iterator |
---|
36 | { |
---|
37 | private: |
---|
38 | Pt3D point1, point2; |
---|
39 | int i, I, numberOfPoints; |
---|
40 | public: |
---|
41 | Segment(const double _density); |
---|
42 | void initialize(const Pt3D &point1, const Pt3D &point2, const bool skipFirst = false, const bool skipLast = false, const bool forceOddNumberOfPoints = false); |
---|
43 | bool tryGetNext(Pt3D &point); |
---|
44 | }; |
---|
45 | |
---|
46 | class RectangleSurface: public Iterator |
---|
47 | { |
---|
48 | private: |
---|
49 | Segment edge1, edge2, area; |
---|
50 | bool skipVerticalEdges, forceOddNumberOfPoints; |
---|
51 | public: |
---|
52 | RectangleSurface(const double _density); |
---|
53 | void initialize(const Part *part, const CuboidFaces::Face face, const bool skipVerticalEdges = false, const bool skipHorizontalEdges = false, const bool forceOddNumberOfPoints = false); |
---|
54 | void initialize(const double width, const double height, const Pt3D &position, const Orient &orient, const bool skipVerticalEdges = false, const bool skipHorizontalEdges = false, const bool forceOddNumberOfPoints = false); |
---|
55 | void initialize(const Pt3D &apex1, const Pt3D &apex2, const Pt3D &apex3, const Pt3D &apex4, const bool skipVerticalEdges = false, const bool skipHorizontalEdges = false, const bool forceOddNumberOfPoints = false); |
---|
56 | bool tryGetNext(Pt3D &point); |
---|
57 | }; |
---|
58 | |
---|
59 | class CuboidApices: public Iterator |
---|
60 | { |
---|
61 | private: |
---|
62 | Pt3D scale; |
---|
63 | Pt3D position; |
---|
64 | Orient orient; |
---|
65 | Octants::Octant octant; |
---|
66 | public: |
---|
67 | CuboidApices(); |
---|
68 | void initialize(const Part *part); |
---|
69 | void initialize(const Pt3D &scale, const Pt3D &position, const Orient &orient); |
---|
70 | bool tryGetNext(Pt3D &point); |
---|
71 | }; |
---|
72 | |
---|
73 | class CuboidSurface: public Iterator |
---|
74 | { |
---|
75 | private: |
---|
76 | CuboidApices apices; |
---|
77 | RectangleSurface rectangle; |
---|
78 | Iterator *iterator; |
---|
79 | const Part *part; |
---|
80 | CuboidFaces::Face face; |
---|
81 | public: |
---|
82 | CuboidSurface(const double _density); |
---|
83 | void initialize(const Part *part); |
---|
84 | bool tryGetNext(Pt3D &point); |
---|
85 | }; |
---|
86 | |
---|
87 | class EllipseSurface: public Iterator |
---|
88 | { |
---|
89 | private: |
---|
90 | RectangleSurface rectangle; |
---|
91 | Pt3D position; |
---|
92 | Orient orient; |
---|
93 | double inversedSquaredWidth, inversedSquaredHeight; |
---|
94 | public: |
---|
95 | EllipseSurface(const double _density); |
---|
96 | void initialize(const Part *part, const CylinderBases::Base base); |
---|
97 | void initialize(const double width, const double height, const Pt3D &position, const Orient &orient); |
---|
98 | bool tryGetNext(Pt3D &point); |
---|
99 | }; |
---|
100 | |
---|
101 | class Ellipse: public Iterator |
---|
102 | { |
---|
103 | private: |
---|
104 | enum Phase { yToZ, zToY, Done }; |
---|
105 | Phase phase; |
---|
106 | Pt3D position; |
---|
107 | Orient orient; |
---|
108 | double width, height, d, p, q, P, Q, D, a, b; |
---|
109 | QuadrantsYZ::QuadrantYZ quadrant; |
---|
110 | public: |
---|
111 | Ellipse(const double _density); |
---|
112 | void initialize(const Part *part, const CylinderBases::Base base); |
---|
113 | void initialize(const double width, const double height, const Pt3D &position, const Orient &orient); |
---|
114 | bool tryGetNext(Pt3D &point); |
---|
115 | private: |
---|
116 | void calculateAndSetSegmentationDistance(); |
---|
117 | void initializePhase(Phase ph); |
---|
118 | void setPoint(Pt3D &point); |
---|
119 | void findNextPQAndPhase(); |
---|
120 | int findLastPQOfPhase(Phase ph, double &lp, double &lq); |
---|
121 | }; |
---|
122 | |
---|
123 | class CylinderEdges: public Iterator |
---|
124 | { |
---|
125 | private: |
---|
126 | Ellipse ellipse; |
---|
127 | Pt3D edge, length; |
---|
128 | CylinderBases::Base base; |
---|
129 | public: |
---|
130 | CylinderEdges(const double _density); |
---|
131 | void initialize(const Part *part); |
---|
132 | void initialize(const Pt3D &scale, const Pt3D &position, const Orient &orient); |
---|
133 | void initialize(const double length, const double width, const double height, const Pt3D &position, const Orient &orient); |
---|
134 | bool tryGetNext(Pt3D &point); |
---|
135 | }; |
---|
136 | |
---|
137 | class CylinderWallSurface: public Iterator |
---|
138 | { |
---|
139 | private: |
---|
140 | Ellipse edge; |
---|
141 | Pt3D length; |
---|
142 | Segment area; |
---|
143 | public: |
---|
144 | CylinderWallSurface(const double _density); |
---|
145 | void initialize(const Part *part); |
---|
146 | void initialize(const Pt3D &scale, const Pt3D &position, const Orient &orient); |
---|
147 | void initialize(const double length, const double width, const double height, const Pt3D &position, const Orient &orient); |
---|
148 | bool tryGetNext(Pt3D &point); |
---|
149 | }; |
---|
150 | |
---|
151 | class CylinderSurface: public Iterator |
---|
152 | { |
---|
153 | private: |
---|
154 | CylinderWallSurface wall; |
---|
155 | EllipseSurface ellipse; |
---|
156 | Iterator *iterator; |
---|
157 | const Part *part; |
---|
158 | CylinderBases::Base base; |
---|
159 | public: |
---|
160 | CylinderSurface(const double _density); |
---|
161 | void initialize(const Part *part); |
---|
162 | bool tryGetNext(Pt3D &point); |
---|
163 | }; |
---|
164 | |
---|
165 | class EllipsoidSurface: public Iterator |
---|
166 | { |
---|
167 | private: |
---|
168 | enum Phase { X, Y, Z, Done }; |
---|
169 | Phase phase; |
---|
170 | Pt3D edge, area, scale, limit; |
---|
171 | double d; |
---|
172 | const Part *part; |
---|
173 | Octants::Octant octant; |
---|
174 | public: |
---|
175 | EllipsoidSurface(const double _density); |
---|
176 | void initialize(const Part *part); |
---|
177 | bool tryGetNext(Pt3D &point); |
---|
178 | private: |
---|
179 | void initializePhase(Phase ph); |
---|
180 | void setPoint(Pt3D &point); |
---|
181 | void proceedToNextOctant(); |
---|
182 | void findNextAreaEdgeAndPhase(); |
---|
183 | }; |
---|
184 | |
---|
185 | class PartSurface: public Iterator |
---|
186 | { |
---|
187 | private: |
---|
188 | CuboidSurface cuboid; |
---|
189 | CylinderSurface cylinder; |
---|
190 | EllipsoidSurface ellipsoid; |
---|
191 | Iterator *iterator; |
---|
192 | public: |
---|
193 | PartSurface(const double _density); |
---|
194 | void initialize(const Part *part); |
---|
195 | bool tryGetNext(Pt3D &point); |
---|
196 | }; |
---|
197 | |
---|
198 | class ModelSurface: public Iterator |
---|
199 | { |
---|
200 | private: |
---|
201 | PartSurface surface; |
---|
202 | const Model *model; |
---|
203 | int index; |
---|
204 | public: |
---|
205 | ModelSurface(const double _density); |
---|
206 | void initialize(const Model *model); |
---|
207 | bool tryGetNext(Pt3D &point); |
---|
208 | }; |
---|
209 | |
---|
210 | class PartApices: public Iterator |
---|
211 | { |
---|
212 | private: |
---|
213 | CuboidApices cuboid; |
---|
214 | CylinderEdges cylinder; |
---|
215 | EllipsoidSurface ellipsoid; |
---|
216 | Iterator *iterator; |
---|
217 | public: |
---|
218 | PartApices(const double _density); |
---|
219 | void initialize(const Part *part); |
---|
220 | bool tryGetNext(Pt3D &point); |
---|
221 | }; |
---|
222 | |
---|
223 | class ModelApices: public Iterator |
---|
224 | { |
---|
225 | private: |
---|
226 | PartApices surface; |
---|
227 | const Model *model; |
---|
228 | int index; |
---|
229 | public: |
---|
230 | ModelApices(const double _density); |
---|
231 | void initialize(const Model *model); |
---|
232 | bool tryGetNext(Pt3D &point); |
---|
233 | }; |
---|
234 | |
---|
235 | class BoundingBoxVolume: Iterator |
---|
236 | { |
---|
237 | private: |
---|
238 | Segment edge, area, volume; |
---|
239 | Pt3D length, width, height; |
---|
240 | public: |
---|
241 | BoundingBoxVolume(const double _density); |
---|
242 | bool initialize(const Model &model); |
---|
243 | bool initialize(const Pt3D &lowerBoundary, const Pt3D &upperBoundary); |
---|
244 | bool tryGetNext(Pt3D &point); |
---|
245 | }; |
---|
246 | }; |
---|
247 | |
---|
248 | #endif |
---|