-
Notifications
You must be signed in to change notification settings - Fork 890
Expand file tree
/
Copy pathml_shared_data_context.h
More file actions
461 lines (375 loc) · 18.6 KB
/
ml_shared_data_context.h
File metadata and controls
461 lines (375 loc) · 18.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
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
/****************************************************************************
* MeshLab o o *
* A versatile mesh processing toolbox o o *
* _ O _ *
* Copyright(C) 2005 \/)\/ *
* Visual Computing Lab /\/| *
* ISTI - Italian National Research Council | *
* \ *
* All rights reserved. *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
* This program 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 General Public License (http://www.gnu.org/licenses/gpl.txt) *
* for more details. *
* *
****************************************************************************/
#ifndef __ML_SHARED_DATA_CONTEXT_H
#define __ML_SHARED_DATA_CONTEXT_H
#include "gl_defs.h"
#include <QTimer>
#include "ml_mesh_type.h"
#include <wrap/qt/qt_thread_safe_mesh_attributes_multi_viewer_bo_manager.h>
#include <QGLWidget>
#include <QMap>
class MeshModel;
class MeshDocument;
struct MLPerViewGLOptions : public vcg::RenderingModalityGLOptions
{
/*IN THIS MOMENT IT'S IGNORED! for the rendering process we use the flag contained in the meshmodel class*/
bool _visible;
/*****************************/
bool _perbbox_quoted_info_enabled;
bool _peredge_extra_enabled;
bool _peredge_edgeboundary_enabled;
bool _peredge_faceboundary_enabled;
bool _peredge_edgemanifold_enabled;
bool _peredge_vertmanifold_enabled;
bool _peredge_text_boundary_enabled;
/*DIRTY THING IN ORDER TO AVOID GUI PROBLEMS WiTH FAUX EDGES RENDERING*/
bool _peredge_wire_enabled;
bool _peredge_fauxwire_enabled;
bool _back_face_cull;
bool _single_side_lighting;
bool _double_side_lighting;
bool _fancy_lighting;
vcg::Color4b _base_light_ambient_color;
vcg::Color4b _base_light_diffuse_color;
vcg::Color4b _base_light_specular_color;
bool _fancy_lighting_enabled;
vcg::Color4b _fancy_f_light_diffuse_color;
vcg::Color4b _fancy_b_light_diffuse_color;
bool _sel_enabled;
bool _vertex_sel;
bool _face_sel;
MLPerViewGLOptions()
:vcg::RenderingModalityGLOptions()
{
_visible = true;
_perbbox_quoted_info_enabled = false;
_peredge_extra_enabled = false;
_peredge_edgeboundary_enabled = false;
_peredge_faceboundary_enabled = false;
_peredge_edgemanifold_enabled = false;
_peredge_vertmanifold_enabled = false;
_peredge_text_boundary_enabled = false;
_peredge_fauxwire_enabled = false;
_peredge_wire_enabled = false;
_back_face_cull = false;
_single_side_lighting = true;
_double_side_lighting = false;
_fancy_lighting = false;
_sel_enabled = false;
_vertex_sel = true;
_face_sel = true;
_base_light_ambient_color = vcg::Color4b(32, 32, 32, 255);
_base_light_diffuse_color = vcg::Color4b(204, 204, 204, 255);
_base_light_specular_color = vcg::Color4b(255, 255, 255, 255);
_fancy_lighting_enabled = false;
_fancy_f_light_diffuse_color = vcg::Color4b(255, 204, 204, 255);
_fancy_b_light_diffuse_color = vcg::Color4b(204, 204, 255, 255);
}
~MLPerViewGLOptions()
{
}
MLPerViewGLOptions(const MLPerViewGLOptions& opts)
:vcg::RenderingModalityGLOptions(opts)
{
copyData(opts);
}
MLPerViewGLOptions& operator=(const MLPerViewGLOptions& opts)
{
vcg::RenderingModalityGLOptions::operator=(opts);
copyData(opts);
return (*this);
}
size_t serialize(std::string& str) const
{
str.append(((_visible) ? "1" : "0"));
str.append(((_perbbox_quoted_info_enabled) ? "1" : "0"));
str.append(((_peredge_extra_enabled) ? "1" : "0"));
str.append(((_peredge_edgeboundary_enabled) ? "1" : "0"));
str.append(((_peredge_faceboundary_enabled) ? "1" : "0"));
str.append(((_peredge_edgemanifold_enabled) ? "1" : "0"));
str.append(((_peredge_vertmanifold_enabled) ? "1" : "0"));
str.append(((_peredge_text_boundary_enabled) ? "1" : "0"));
str.append(((_peredge_fauxwire_enabled) ? "1" : "0"));
str.append(((_peredge_wire_enabled) ? "1" : "0"));
str.append(((_back_face_cull) ? "1" : "0"));
str.append(((_single_side_lighting) ? "1" : "0"));
str.append(((_double_side_lighting) ? "1" : "0"));
str.append(((_fancy_lighting) ? "1" : "0"));
str.append(((_sel_enabled) ? "1" : "0"));
str.append(((_vertex_sel) ? "1" : "0"));
str.append(((_face_sel) ? "1" : "0"));
str.append(((_perbbox_enabled) ? "1" : "0"));
str.append(((_perbbox_fixed_color_enabled) ? "1" : "0"));
str.append(((_perpoint_fixed_color_enabled) ? "1" : "0"));
str.append(((_perwire_fixed_color_enabled) ? "1" : "0"));
str.append(((_persolid_fixed_color_enabled) ? "1" : "0"));
str.append(((_perbbox_mesh_color_enabled) ? "1" : "0"));
str.append(((_perpoint_mesh_color_enabled) ? "1" : "0"));
str.append(((_perwire_mesh_color_enabled) ? "1" : "0"));
str.append(((_persolid_mesh_color_enabled) ? "1" : "0"));
str.append(((_perpoint_dot_enabled) ? "1" : "0"));
str.append(((_perpoint_noshading) ? "1" : "0"));
str.append(((_perwire_noshading) ? "1" : "0"));
str.append(((_persolid_noshading) ? "1" : "0"));
str.append(((_perpoint_pointsmooth_enabled) ? "1" : "0"));
str.append(((_perpoint_pointattenuation_enabled) ? "1" : "0"));
return str.size();
}
void deserialize(std::string& str)
{
std::string s(str.rbegin(), str.rend());
std::bitset<32> bset(s);
_visible = bset[0];
_perbbox_quoted_info_enabled = bset[1];
_peredge_extra_enabled = bset[2];
_peredge_edgeboundary_enabled = bset[3];
_peredge_faceboundary_enabled = bset[4];
_peredge_edgemanifold_enabled = bset[5];
_peredge_vertmanifold_enabled = bset[6];
_peredge_text_boundary_enabled = bset[7];
_peredge_fauxwire_enabled = bset[8];
_peredge_wire_enabled = bset[9];
_back_face_cull = bset[10];
_single_side_lighting = bset[11];
_double_side_lighting = bset[12];
_fancy_lighting = bset[13];
_sel_enabled = bset[14];
_vertex_sel = bset[15];
_face_sel = bset[16];
_perbbox_enabled = bset[17];
_perbbox_fixed_color_enabled = bset[18];
_perpoint_fixed_color_enabled = bset[19];
_perwire_fixed_color_enabled = bset[20];
_persolid_fixed_color_enabled = bset[21];
_perbbox_mesh_color_enabled = bset[22];
_perpoint_mesh_color_enabled = bset[23];
_perwire_mesh_color_enabled = bset[24];
_persolid_mesh_color_enabled = bset[25];
_perpoint_dot_enabled = bset[26];
_perpoint_noshading = bset[27];
_perwire_noshading = bset[28];
_persolid_noshading = bset[29];
_perpoint_pointsmooth_enabled = bset[30];
_perpoint_pointattenuation_enabled = bset[31];
}
static float minPointSize()
{
return 1.0f;
}
static float maxPointSize()
{
return 15.0f;
}
static float maxLineWidth()
{
return 5.0f;
}
private:
void copyData(const MLPerViewGLOptions& opts)
{
_visible = opts._visible;
_perbbox_quoted_info_enabled = opts._perbbox_quoted_info_enabled;
_peredge_extra_enabled = opts._peredge_extra_enabled;
_peredge_edgeboundary_enabled = opts._peredge_edgeboundary_enabled;
_peredge_faceboundary_enabled = opts._peredge_faceboundary_enabled;
_peredge_edgemanifold_enabled = opts._peredge_edgemanifold_enabled;
_peredge_vertmanifold_enabled = opts._peredge_vertmanifold_enabled;
_peredge_text_boundary_enabled = opts._peredge_text_boundary_enabled;
_peredge_fauxwire_enabled = opts._peredge_fauxwire_enabled;
_peredge_wire_enabled = opts._peredge_wire_enabled;
_back_face_cull = opts._back_face_cull;
_single_side_lighting = opts._single_side_lighting;
_double_side_lighting = opts._double_side_lighting;
_fancy_lighting = opts._fancy_lighting;
_sel_enabled = opts._sel_enabled;
_face_sel = opts._face_sel;
_vertex_sel = opts._vertex_sel;
_base_light_ambient_color = opts._base_light_ambient_color;
_base_light_diffuse_color = opts._base_light_diffuse_color;
_base_light_specular_color = opts._base_light_specular_color;
_fancy_lighting_enabled = opts._fancy_lighting_enabled;
_fancy_f_light_diffuse_color = opts._fancy_f_light_diffuse_color;
_fancy_b_light_diffuse_color = opts._fancy_b_light_diffuse_color;
}
};
class MLRenderingData : public vcg::PerViewData<MLPerViewGLOptions>
{
public:
MLRenderingData();
MLRenderingData(const MLRenderingData& dt);
bool set(MLRenderingData::PRIMITIVE_MODALITY pm, const MLRenderingData::RendAtts& atts);
bool set(MLRenderingData::PRIMITIVE_MODALITY pm, MLRenderingData::ATT_NAMES att, bool onoff);
bool set(MLRenderingData::PRIMITIVE_MODALITY pm, bool onoff);
void set(const MLPerViewGLOptions& opts);
typedef vcg::GLMeshAttributesInfo::RendAtts RendAtts;
typedef vcg::GLMeshAttributesInfo::ATT_NAMES ATT_NAMES;
typedef vcg::GLMeshAttributesInfo::PRIMITIVE_MODALITY PRIMITIVE_MODALITY;
typedef vcg::QtThreadSafeTextureNamesContainer MLTextureID;
};
/*{
MLRenderingData::PRIMITIVE_MODALITY_MASK _mask;
MLRenderingData::RendAtts _atts;
MLPerViewGLOptions _opts;
MLRenderingData()
:_mask((unsigned int) MLRenderingData::PR_NONE),_atts(),_opts()
{
}
MLRenderingData(MLRenderingData::PRIMITIVE_MODALITY_MASK mask,const MLRenderingData::RendAtts& atts,const MLPerViewGLOptions& opts)
:_mask(mask),_atts(atts),_opts(opts)
{
}
static void all(MLRenderingData& dt)
{
for(unsigned int ii = 0;ii < MLRenderingData::ATT_NAMES::enumArity();++ii)
dt._atts[ii] = true;
dt._mask = MLRenderingData::PR_BBOX | MLRenderingData::PR_POINTS | MLRenderingData::PR_WIREFRAME_EDGES | MLRenderingData::PR_WIREFRAME_TRIANGLES | MLRenderingData::PR_SOLID;
}
};*/
struct MLPoliciesStandAloneFunctions
{
/*WARNING!!!!! TEMPORARY!!! TO BE DELETED*/
static void computeRequestedRenderingDataCompatibleWithMeshSameGLOpts(MeshModel * meshmodel, const MLRenderingData & inputdt, MLRenderingData & outputdt);
static void computeRequestedRenderingDataCompatibleWithMesh(MeshModel* meshmodel, const MLRenderingData& inputdt, MLRenderingData& outputdt);
static void computeRequestedRenderingDataCompatibleWithMeshCommonCode(MeshModel * meshmodel, const MLRenderingData & inputdt, MLRenderingData & outputdt);
static void fromMeshModelMaskToMLRenderingAtts(int meshmodelmask, MLRenderingData::RendAtts& atts);
static void updatedRendAttsAccordingToPriorities(const MLRenderingData::PRIMITIVE_MODALITY pm, const MLRenderingData::RendAtts& updated, const MLRenderingData::RendAtts& current, MLRenderingData::RendAtts& result);
static void maskMeaninglessAttributesPerPrimitiveModality(MLRenderingData::PRIMITIVE_MODALITY pm, MLRenderingData::RendAtts& atts);
static void setAttributePriorities(MLRenderingData::RendAtts& atts);
static void setPerViewGLOptionsPriorities(MLRenderingData& dt);
//static void setPerViewRenderingDataPriorities(MeshModel* mm,MLRenderingData& dt);
static void suggestedDefaultPerViewGLOptions(MLPerViewGLOptions& tmp);
static void suggestedDefaultPerViewRenderingData(MeshModel* meshmodel, MLRenderingData& dt,size_t minpolnumpersmoothshading = 0);
static void disableRedundatRenderingDataAccordingToPriorities(MLRenderingData& dt);
static bool isPrimitiveModalityCompatibleWithMesh(MeshModel* m, const MLRenderingData::PRIMITIVE_MODALITY pm);
static bool isPrimitiveModalityCompatibleWithMeshInfo(bool validvert, bool validfaces, bool validedges, int meshmask, const MLRenderingData::PRIMITIVE_MODALITY pm);
static bool isPrimitiveModalityWorthToBeActivated(MLRenderingData::PRIMITIVE_MODALITY pm, bool wasvisualized, bool wasmeanigful, bool ismeaningful);
static MLRenderingData::PRIMITIVE_MODALITY bestPrimitiveModalityAccordingToMesh(MeshModel* m);
static void filterUselessUdpateAccordingToMeshMask(MeshModel* m, MLRenderingData::RendAtts& atts);
static void setBestWireModality(MeshModel* mm, MLRenderingData& dt);
static void setPerViewGLOptionsAccordindToWireModality(MeshModel* mm, MLRenderingData& dt);
};
class MLSceneGLSharedDataContext : public QGLWidget
{
Q_OBJECT
public:
//parent is set to NULL in order to avoid QT bug on MAC (business as usual...).
//The QGLWidget are destroyed by hand in the MainWindow destructor...
MLSceneGLSharedDataContext(MeshDocument& md, vcg::QtThreadSafeMemoryInfo& gpumeminfo, bool highprecision, size_t perbatchtriangles, size_t minfacespersmoothrendering = 0);
~MLSceneGLSharedDataContext();
void setMinFacesForSmoothRendering(size_t fcnum);
vcg::QtThreadSafeMemoryInfo& memoryInfoManager() const
{
return _gpumeminfo;
}
inline bool highPrecisionRendering() const
{
return _highprecision;
}
//Given a QGLContext the PerMeshRenderingDataMap contains the rendering data per each mesh contained in the MeshDocument (eg. flat/smooth shading? pervertex/perface/permesh color?)
//and the 'meaningful' gl parameters used by the rendering system
typedef QMap<int, MLRenderingData> PerMeshRenderingDataMap;
MeshDocument& meshDoc() { return _md; }
void initializeGL();
void deAllocateGPUSharedData();
void draw(int mmid, QGLContext* viewid) const;
void drawAllocatedAttributesSubset(int mmid, QGLContext* viewid, const MLRenderingData& dt);
void setSceneTransformationMatrix(const Matrix44m& m);
void setMeshTransformationMatrix(int mmid, const Matrix44m& m);
GLuint allocateTexturePerMesh(int mmid, const QImage& img, size_t maxdimtextmb);
void deAllocateTexturesPerMesh(int mmid);
GLuint getTextureId(int meshid, size_t position) const;
void getRenderInfoPerMeshView(QGLContext* ctx, PerMeshRenderingDataMap& map);
void getRenderInfoPerMeshView(int mmid, QGLContext* ctx, MLRenderingData& dt);
void meshInserted(int mmid);
void meshRemoved(int mmid);
bool manageBuffers(int mmid);
void setDebugMode(int mmid, bool activatedebugmodality);
void getLog(int mmid, MLRenderingData::DebugInfo& debug);
bool isBORenderingAvailable(int mmid);
/*functions intended for the plugins (they emit different signals according if the calling thread is different from the one where the MLSceneGLSharedDataContext object lives)*/
void requestInitPerMeshView(QThread* callingthread, int meshid, QGLContext* cont, const MLRenderingData& dt);
void requestRemovePerMeshView(QThread* callingthread, QGLContext* cont);
void requestSetPerMeshViewRenderingData(QThread* callingthread, int meshid, QGLContext* cont, const MLRenderingData& dt);
void requestMeshAttributesUpdated(QThread* callingthread, int meshid, bool connectivitychanged, const MLRenderingData::RendAtts& dt);
/***************************************/
public slots:
void meshDeallocated(int mmid);
void setRenderingDataPerMeshView(int mmid, QGLContext* viewerid, const MLRenderingData& perviewdata);
void setRenderingDataPerAllMeshViews(int mmid, const MLRenderingData& perviewdata);
void setGLOptions(int mmid, QGLContext* viewid, const MLPerViewGLOptions& opts);
void addView(QGLContext* viewerid);
void addView(QGLContext* viewerid, MLRenderingData& dt);
void removeView(QGLContext* viewerid);
void meshAttributesUpdated(int mmid, bool conntectivitychanged, const MLRenderingData::RendAtts& dt);
void updateGPUMemInfo();
//void updateRequested(int meshid,MLRenderingData::ATT_NAMES name);
private slots:
/*slots intended for the plugins living in another thread*/
void initPerMeshViewRequested(int meshid, QGLContext* cont, const MLRenderingData& dt);
void removePerMeshViewRequested(QGLContext* cont);
void setPerMeshViewRenderingDataRequested(int meshid, QGLContext* cont, const MLRenderingData& dt);
void meshAttributesUpdatedRequested(int meshid, bool connectivitychanged, const MLRenderingData::RendAtts& dt);
/***************************************/
private:
typedef vcg::QtThreadSafeGLMeshAttributesMultiViewerBOManager<CMeshO, QGLContext*, MLPerViewGLOptions> PerMeshMultiViewManager;
PerMeshMultiViewManager* meshAttributesMultiViewerManager(int mmid) const;
QGLContext* makeCurrentGLContext();
void doneCurrentGLContext(QGLContext* oldone = NULL);
MeshDocument& _md;
typedef QMap<int, PerMeshMultiViewManager*> MeshIDManMap;
MeshIDManMap _meshboman;
vcg::QtThreadSafeMemoryInfo& _gpumeminfo;
size_t _perbatchtriangles;
size_t _minfacessmoothrendering;
bool _highprecision;
QTimer* _timer;
signals:
void currentAllocatedGPUMem(int nv_all, int nv_current, int ati_tex, int ati_vbo);
///*signals intended for the plugins living in the same thread*/
//void initPerMeshViewRequestST(int,QGLContext*,const MLRenderingData&);
//void removePerMeshViewRequestST(QGLContext*);
//void setPerMeshViewRenderingDataRequestST(int,QGLContext*,const MLRenderingData&);
///***************************************/
/*signals intended for the plugins living in another thread*/
void initPerMeshViewRequestMT(int, QGLContext*, const MLRenderingData&);
void removePerMeshViewRequestMT(QGLContext*);
void setPerMeshViewRenderingDataRequestMT(int, QGLContext*, const MLRenderingData&);
void meshAttributesUpdatedRequestMT(int, bool, const MLRenderingData::RendAtts&);
/***************************************/
};
class MLPluginGLContext : public QGLContext
{
public:
MLPluginGLContext(const QGLFormat& frmt, QPaintDevice* dvc, MLSceneGLSharedDataContext& shared);
~MLPluginGLContext();
void initPerViewRenderingData(int meshid, MLRenderingData& dt);
void removePerViewRenderindData();
void setRenderingData(int meshid, MLRenderingData& dt);
void drawMeshModel(int meshid) const;
void meshAttributesUpdated(int meshid, bool conntectivitychanged, const MLRenderingData::RendAtts& dt);
static void smoothModalitySuggestedRenderingData(MLRenderingData& dt);
static void pointModalitySuggestedRenderingData(MLRenderingData& dt);
private:
MLSceneGLSharedDataContext& _shared;
};
#endif