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
|
#include "qwt3d_surfaceplot.h"
using namespace std;
using namespace Qwt3D;
/**
Initializes with dataNormals()==false, NOFLOOR, resolution() == 1
*/
#if QT_VERSION < 0x040000
SurfacePlot::SurfacePlot( QWidget* parent, const char* name )
: Plot3D( parent, name )
#else
SurfacePlot::SurfacePlot( QWidget * parent, const QGLWidget * shareWidget)
: Plot3D( parent, shareWidget)
#endif
{
datanormals_p = false;
normalLength_p = 0.02;
normalQuality_p = 3;
resolution_p = 1;
actualDataG_ = new GridData();
actualDataC_ = new CellData();
actualData_p = actualDataG_;
floorstyle_ = NOFLOOR;
}
SurfacePlot::~SurfacePlot()
{
delete actualDataG_;
delete actualDataC_;
}
void SurfacePlot::showNormals(bool b)
{
datanormals_p = b;
}
/**
Values < 0 or > 1 are ignored
*/
void SurfacePlot::setNormalLength(double val)
{
if (val<0 || val>1)
return;
normalLength_p = val;
}
/**
Values < 3 are ignored
*/
void SurfacePlot::setNormalQuality(int val)
{
if (val<3)
return;
normalQuality_p = val;
}
/**
Calculates the smallest x-y-z parallelepiped enclosing the data.
It can be accessed by hull();
*/
void SurfacePlot::calculateHull()
{
if (actualData_p->empty())
return;
setHull(actualData_p->hull());
}
/*!
Sets data resolution (res == 1 original resolution) and updates widget
If res < 1, the function does nothing
*/
void SurfacePlot::setResolution( int res )
{
if (!actualData_p || actualData_p->datatype == Qwt3D::POLYGON)
return;
if ((resolution_p == res) || res < 1)
return;
resolution_p = res;
updateNormals();
updateData();
if (initializedGL())
updateGL();
emit resolutionChanged(res);
}
void SurfacePlot::updateNormals()
{
SaveGlDeleteLists(displaylists_p[NormalObject], 1);
if (plotStyle() == NOPLOT && !normals() || !actualData_p)
return;
displaylists_p[NormalObject] = glGenLists(1);
glNewList(displaylists_p[NormalObject], GL_COMPILE);
if (actualData_p->datatype == Qwt3D::POLYGON)
createNormalsC();
else if (actualData_p->datatype == Qwt3D::GRID)
createNormalsG();
glEndList();
}
void SurfacePlot::createData()
{
if (!actualData_p)
return;
if (actualData_p->datatype == Qwt3D::POLYGON)
createDataC();
else if (actualData_p->datatype == Qwt3D::GRID)
createDataG();
}
void SurfacePlot::createFloorData()
{
if (!actualData_p)
return;
if (actualData_p->datatype == Qwt3D::POLYGON)
createFloorDataC();
else if (actualData_p->datatype == Qwt3D::GRID)
createFloorDataG();
}
/**
The returned value is not affected by resolution(). The pair gives (columns,rows) for grid data
, (number of cells,1) for free formed data (datatype() == POLYGON) and (0,0) else
*/
pair<int,int> SurfacePlot::facets() const
{
if (!hasData())
return pair<int,int>(0,0);
if (actualData_p->datatype == Qwt3D::POLYGON)
return pair<int,int>(int(actualDataC_->cells.size()), 1);
else if (actualData_p->datatype == Qwt3D::GRID)
return pair<int,int>(actualDataG_->columns(), actualDataG_->rows());
else
return pair<int,int>(0,0);
}
void SurfacePlot::createPoints()
{
Dot pt;
createEnrichment(pt);
}
void SurfacePlot::createEnrichment(Enrichment& p)
{
if (!actualData_p)
return;
//todo future work
if (p.type() != Enrichment::VERTEXENRICHMENT)
return;
p.assign(*this);
p.drawBegin();
VertexEnrichment* ve = (VertexEnrichment*)&p;
if (actualData_p->datatype == Qwt3D::POLYGON)
{
for (unsigned i = 0; i != actualDataC_->normals.size(); ++i)
ve->draw(actualDataC_->nodes[i]);
}
else if (actualData_p->datatype == Qwt3D::GRID)
{
int step = resolution();
for (int i = 0; i <= actualDataG_->columns() - step; i += step)
for (int j = 0; j <= actualDataG_->rows() - step; j += step)
ve->draw(Triple(actualDataG_->vertices[i][j][0],
actualDataG_->vertices[i][j][1],
actualDataG_->vertices[i][j][2]));
}
p.drawEnd();
}
|