-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmeshobject.h
298 lines (249 loc) · 6.88 KB
/
meshobject.h
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
// (c) 2015 David Vyvlečka, AGPLv3
#ifndef MESHOBJECT_H
#define MESHOBJECT_H
#include <QGLFunctions>
#include <QGLShaderProgram>
#include "data.h"
/*!
* \brief Encapsulation of stl_file structure of ADMesh
*
* Stores one STL file and according vertex buffer object.
* stl_file structure allows directly only deprecated style of OpenGL drawing.
* This class enables to use modern drawing style via vertex buffer object.
*/
class MeshObject : protected QGLFunctions
{
public:
/*!
* \brief Constructor. Initializes new stl structure.
*/
MeshObject();
/*!
* \brief Constructor. Initializes with given stl structure.
*
* \param item Given stl_file item.
*/
MeshObject(stl_file* item, QString name);
/*!
* \brief Copy constructor. Creates deep copy of MeshObject.
*/
MeshObject(const MeshObject& m);
/*!
* \brief Read in given file.
*
* Checks if file exist/is proper STL file.
* Generates vertex buffer object.
*
* \param filename Input STL file.
* \return True upon successful load.
*/
bool loadGeometry(QString filename);
/*!
* \brief Append "_merged" to filename.
*/
void mergedFilename();
/*!
* \brief Set filename to "filename_part_index.stl".
*
* \param index Given index.
*/
void setSplitName(int index);
/*!
* \brief Set filename to "filename_duplicated.stl".
*/
void setDuplicatedName();
/*!
* \brief Update geometry (update VBO)
*
* Copies vertex and normal coordinates from stl_file structure into VBO.
*/
void updateGeometry();
/*!
* \brief Draw mesh.
* \param program Shader program used for drawing.
*/
void drawGeometry(QGLShaderProgram *program);
/*!
* \brief Get vector [min x, min y, max z] for camera purposes.
* \return vector of mininaml values.
*/
QVector3D getMin();
/*!
* \brief Get maximal diameter of last object in list. Maximal absolute value from all axes.
*
* \return diameter
*/
float getDiameter();
/*!
* \brief Get info about mesh.
* \return array containing info.
*/
float* getInfo();
QString getName();
/*!
* \brief Save mesh as STL.
* \param filename Output STL filename.
* \param type File type - ASCII or binary
*/
void saveAs(QString filename, int type);
/*!
* \brief Save mesh in its default format.
*/
void save();
/*!
* \brief True if stored filename is valid.
*/
bool hasValidName();
/*!
* \brief True if current state of mesh is saved.
*/
bool isSaved();
/*!
* \brief Export mesh as OFF, VRML, DXF or OBJ.
* \param filename Exported filename.
* \param type File File type.
*/
void exportSTL(QString, int type);
/*!
* \brief Scale stl file by versor.
* \param versor Scaling versor.
*/
void scale(float versor[3]);
/*!
* \brief Mirror model by XY plane.
*/
void mirrorXY();
/*!
* \brief Mirror model by YZ plane.
*/
void mirrorYZ();
/*!
* \brief Mirror model by XZ plane.
*/
void mirrorXZ();
/*!
* \brief Rotate stl file along X axis.
* \param angle Angle of rotation.
*/
void rotateX(float angle);
/*!
* \brief Rotate stl file along Y axis.
* \param angle Angle of rotation.
*/
void rotateY(float angle);
/*!
* \brief Rotate stl file along Z axis.
* \param angle Angle of rotation.
*/
void rotateZ(float angle);
/*!
* \brief Translate stl file. All axes together.
* \param relative Relative translation on/off.
* \param x_trans X axis translation factor.
* \param y_trans Y axis translation factor.
* \param z_trans Z axis translation factor.
*/
void translate(bool relative, float x_trans, float y_trans, float z_trans);
/*!
* \brief Translate stl file to be centered around origin.
*/
void center();
/*!
* \brief Snap stl file to zero Z coordinate.
*/
void snapZ();
/*!
* \brief Reverse all facets orientation.
*/
void reverseAll();
/*!
* \brief Repair stl file. Repair differs with parameters.
* \param fixall_flag Fix all errors in STL file.
* \param tolerance_flag Used tolerance for checking faces.
* \param tolerance Y Given tolerance.
* \param increment_flag Used tolerance increment in iterations.
* \param increment Given increment.
* \param nearby_flag Check for nearby faces.
* \param iterations Number of iterations used for checking.
* \param remove_unconnected_flag Remove unconnected vertices.
* \param fill_holes_flag Fill holes.
* \param normal_directions_flag Repair normal directions. All out.
* \param normal_values_flag Repair normal values. Normalization.
* \param reverse_all_flag Reverse all faces.
*/
void repair(int fixall_flag, int exact_flag, int tolerance_flag, float tolerance, int increment_flag, float increment, int nearby_flag, int iterations, int remove_unconnected_flag, int fill_holes_flag, int normal_directions_flag, int normal_values_flag, int reverse_all_flag);
/*!
* \brief Set selected.
*/
void setSelected();
/*!
* \brief Set deselected.
*/
void setDeselected();
/*!
* \brief Toggle selected.
*/
void toggleSelected();
/*!
* \brief Is selected?
*
* \return true upon selected
*/
bool isSelected();
/*!
* \brief Is active?
*
* \return true upon selected and visible
*/
bool isActive();
/*!
* \brief Hide item
*/
void setHidden();
/*!
* \brief Reveal hidden item
*/
void setVisible();
/*!
* \brief Is hidden?
*
* \return true upon hidden
*/
bool isHidden();
/*!
* \brief Destructor. Closes stl structure. Deletes vbo.
*/
virtual ~MeshObject();
/*!
* \brief Has references?
*
* return true upon references > 0
*/
bool hasReferences();
/*!
* \brief Raise references count by 1.
*/
void addReference();
/*!
* \brief Decrease references count by 1.
*/
void removeReference();
/*!
* \brief Get pointer to stl_file structure stored.
*
* return stored stl file structure
*/
stl_file* getStlPointer();
unsigned long getSize();
private:
void countSize();
stl_file* stl; ///< Stored STL file
GLuint vbo; ///< Vertex buffer object used to store STL file for drawing
bool selected; ///< Set active/inactive
bool hidden; ///< Is hidden/visible
bool saved; ///< Is saved/unsaved
QString file; ///< File name
unsigned int references; ///< Count if references - how many history items use this object.
unsigned long size;
};
#endif // MESHOBJECT_H