-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBuilder3D.h
More file actions
343 lines (313 loc) · 12.6 KB
/
Builder3D.h
File metadata and controls
343 lines (313 loc) · 12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
/***************************************************************************
* Copyright (c) 2011 Jürgen Riegel <juergen.riegel@web.de> *
* *
* This file is part of the FreeCAD CAx development system. *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of the GNU Library General Public *
* License as published by the Free Software Foundation; either *
* version 2 of the License, or (at your option) any later version. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU Library General Public License for more details. *
* *
* You should have received a copy of the GNU Library General Public *
* License along with this library; see the file COPYING.LIB. If not, *
* write to the Free Software Foundation, Inc., 59 Temple Place, *
* Suite 330, Boston, MA 02111-1307, USA *
* *
***************************************************************************/
#ifndef BASE_BUILDER3D_H
#define BASE_BUILDER3D_H
// Std. configurations
#include <sstream>
#include <vector>
#include "Vector3D.h"
#ifndef FC_GLOBAL_H
#include <FCGlobal.h>
#endif
namespace Base
{
class Matrix4D;
/** A Builder class for 3D representations on App level
* On the application level nothing is known of the visual representation of data.
* Nevertheless it's often needed to see some 3D information, e.g. points, directions,
* when you program or debug an algorithm. Builder3D was made for this specific purpose.
* This class allows you to easily build up a 3D representation of some mathematical and
* algorithm internals. You can save this representation to a file and view it in an
* Inventor viewer, or send it to the log. In the case of using the log and a debug
* FreeCAD the representation will be loaded into the active viewer.
* \par
* The workflow goes as follows: Create the a Builder3D object and call the methods
* to insert the graphical elements. After that call either saveToLog() or saveToFile().
* \par
* Usage:
* \code
Base::Builder3D log3D;
for ( unsigned long i=0; i<pMesh->CountPoints(); i++ )
{
log3D.addSinglePoint(pMesh->GetPoint(i));
log3D.addText(pMesh->GetPoint(i),"Point");
...
}
log3D.saveToLog();
* \endcode
* \see Base::ConsoleSingleton
*/
class BaseExport Builder3D
{
public:
/// Construction
Builder3D();
/// Destruction
virtual ~Builder3D();
/** @name point set handling */
//@{
/// starts a point set
void startPoints(short pointSize=2, float color_r=1.0,float color_g=0.0,float color_b=0.0);
/// insert a point in an point set
void addPoint(float x, float y, float z);
/// add a vector to a point set
void addPoint(const Vector3f &vec);
/// ends the points set operation
void endPoints(void);
/// add a singular point (without startPoints() & endPoints() )
void addSinglePoint(float x, float y, float z, short pointSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0);
/// add a singular point (without startPoints() & endPoints() )
void addSinglePoint(const Base::Vector3f &vec, short pointSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0);
//@}
/** @name line/direction handling */
//@{
/// add a line defined by 2 Vector3D
void addSingleLine(Vector3f pt1, Vector3f pt2, short lineSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
/// add a arrow (directed line) by 2 Vector3D. The arrow shows in direction of point 2.
void addSingleArrow(Vector3f pt1, Vector3f pt2, short lineSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
//@}
/** @name triangle handling */
//@{
/// add a (filled) triangle defined by 3 vectors
void addSingleTriangle(Vector3f pt0, Vector3f pt1, Vector3f pt2, bool filled = true, short lineSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0);
//@}
/** @name Transformation */
//@{
/// adds a transformation
void addTransformation(const Base::Matrix4D&);
void addTransformation(const Base::Vector3f& translation, const Base::Vector3f& rotationaxis, float fAngle);
//@}
/** @name text handling */
//@{
/// add a text
void addText(float pos_x, float pos_y , float pos_z,const char * text, float color_r=1.0,float color_g=1.0,float color_b=1.0);
/// add a text
void addText(const Base::Vector3f &vec,const char * text, float color_r=1.0,float color_g=1.0,float color_b=1.0);
//@}
/// clear the string buffer
void clear (void);
/** @name write the result */
//@{
/// sends the result to the log and gui
void saveToLog(void);
/// save the result to a file (*.iv)
void saveToFile(const char* FileName);
//@}
private:
/// the result string
std::stringstream result;
bool bStartEndOpen;
};
/**
* This class does basically the same as Builder3D except that it writes the data
* directly into a given stream without buffering the output data in a string stream.
* Compared to file streams, string streams are quite slow when writing data with more
* than a few hundred lines. Due to performance reasons the user should use a file
* stream in this case.
* @author Werner Mayer
*/
class BaseExport InventorBuilder
{
public:
/*!
* \brief Construction of an InventorBuilder instance.
* This automatically opens a separator node.
* \param str - stream to write the content into
*/
InventorBuilder(std::ostream& str);
/*!
* \brief Destruction of an InventorBuilder instance
*/
virtual ~InventorBuilder();
/*!
* \brief If needed closes the first opened separator node.
* This method must not be used more than one time for an instance.
*/
void close();
/*!
* \brief Sets a separator node.
*/
void beginSeparator();
/*!
* \brief Closes the last added separator node.
*/
void endSeparator();
/*!
* \brief Sets an info node.
* \param str - text set to the info node
*/
void addInfo(const char* str);
/*!
* \brief Sets a label node.
* \param str - text set to the label node
*/
void addLabel(const char* str);
/** @name Appearance handling */
//@{
/*!
* \brief Sets a base color node. The colors are in the range [0, 1].
* \param color_r - red color
* \param color_g - green color
* \param color_b - blue color
*/
void addBaseColor(float color_r,float color_g,float color_b);
/*!
* \brief Sets a material node. The colors are in the range [0, 1].
* \param color_r - red color
* \param color_g - green color
* \param color_b - blue color
* \param color_a - transparency
*/
void addMaterial(float color_r,float color_g,float color_b,float color_a=0);
/*!
* \brief Starts a material node. The node must be closed with \ref endMaterial
* and the colors must be added with \ref addColor().
*/
void beginMaterial();
/*!
* \brief Closes a material node.
*/
void endMaterial();
/*!
* \brief Adds a color to a material node. The colors are in the range [0, 1].
* \param color_r - red color
* \param color_g - green color
* \param color_b - blue color
*/
void addColor(float color_r,float color_g,float color_b);
/*!
* \brief Sets a material binding node.
* \param binding - binding of the material. Allowed values are:
* OVERALL, PER_PART, PER_PART_INDEXED, PER_FACE, PER_FACE_INDEXED, PER_VERTEX,
* PER_VERTEX_INDEXED and DEFAULT.
*/
void addMaterialBinding(const char* binding = "OVERALL");
/*!
* \brief Sets a draw style node.
* \param pointSize - the point size
* \param lineWidth - the line width
* \param linePattern - the line pattern
* \param style - the draw style
*/
void addDrawStyle(short pointSize, short lineWidth,
unsigned short linePattern = 0xffff, const char* style="FILLED");
/*!
* \brief Sets a shape hints node.
* \param crease - the crease angle in radians
*/
void addShapeHints(float crease=0.0f);
/*!
* \brief Sets a polygon offset node.
* \param factor - Offset multiplication factor.
* \param units - Offset translation multiplication factor.
* \param styles - Can be FILLED, LINES or POINTS.
* \param on - Whether the offset is on or off.
*/
void addPolygonOffset(float factor=1.0f, float units=1.0f, const char* styles="FILLED", bool on=true);
//@}
/** @name Add coordinates */
//@{
/// add a single point
void addPoint(float x, float y, float z);
/// add a single point
void addPoint(const Vector3f &vec);
/// add a list of points
void addPoints(const std::vector<Vector3f> &vec);
//@}
/** @name Point set handling */
//@{
/// starts a point set
void beginPoints();
/// ends the points set operation
void endPoints();
/// add an SoPointSet node
void addPointSet();
//@}
/** @name Normal handling */
//@{
/// starts a point set
void beginNormal();
/// ends the points set operation
void endNormal();
/// add normal binding node
void addNormalBinding(const char*);
//@}
/** @name Line/Direction handling */
//@{
/// add a line defined by 2 Vector3D
void addSingleLine(const Vector3f& pt1, const Vector3f& pt2, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
/// add a arrow (directed line) by 2 Vector3D. The arrow shows in direction of point 2.
void addSingleArrow(const Vector3f& pt1, const Vector3f& pt2, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
/// add a line defined by a list of points whereat always a pair (i.e. a point and the following point) builds a line.
void addLineSet(const std::vector<Vector3f>& points, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0, unsigned short linePattern = 0xffff);
/// add an SoLineSet node
void addLineSet();
//@}
/** @name Triangle handling */
//@{
/// add a (filled) triangle defined by 3 vectors
void addSingleTriangle(const Vector3f& pt0, const Vector3f& pt1, const Vector3f& pt2, bool filled = true, short lineSize=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0);
void addSinglePlane(const Vector3f& base, const Vector3f& eX, const Vector3f& eY, float length, float width, bool filled = true,
short lineSize=2, float color_r=1.0,float color_g=1.0,float color_b=1.0);
void addIndexedFaceSet(const std::vector<int>& indices);
void addFaceSet(const std::vector<int>& vertices);
//@}
/** @name Surface handling */
//@{
void addNurbsSurface(const std::vector<Base::Vector3f>& controlPoints,
int numUControlPoints, int numVControlPoints,
const std::vector<float>& uKnots, const std::vector<float>& vKnots);
void addCylinder(float radius, float height);
void addSphere(float radius);
//@}
/** @name Bounding Box handling */
//@{
void addBoundingBox(const Vector3f& pt1, const Vector3f& pt2, short lineWidth=2,
float color_r=1.0,float color_g=1.0,float color_b=1.0);
//@}
/** @name Transformation */
//@{
/// adds a transformation
void addTransformation(const Matrix4D&);
void addTransformation(const Vector3f& translation, const Vector3f& rotationaxis, float fAngle);
//@}
/** @name Text handling */
//@{
/// add a text
void addText(float pos_x, float pos_y , float pos_z,const char * text,
float color_r=1.0,float color_g=1.0,float color_b=1.0);
/// add a text
void addText(const Vector3f &vec,const char * text, float color_r=1.0,float color_g=1.0,float color_b=1.0);
//@}
private:
InventorBuilder (const InventorBuilder&);
void operator = (const InventorBuilder&);
private:
std::ostream& result;
int indent;
};
} //namespace Base
#endif // BASE_BUILDER3D_H