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
|
#include "qwt3d_axis.h"
using namespace Qwt3D;
Axis::Axis()
{
init();
};
Axis::~Axis()
{
}
Axis::Axis(Triple beg, Triple end)
{
init();
setPosition(beg,end);
}
void Axis::init()
{
detachAll();
scale_ = qwt3d_ptr<Scale>(new LinearScale);
beg_ = Triple(0.0, 0.0, 0.0);
end_ = beg_;
majorintervals_ = 0;
minorintervals_ = 0;
setMajors(1);
setMinors(1);
setLimits(0,0);
setTicOrientation(0.0, 0.0, 0.0);
setTicLength(0.0, 0.0);
setColor(0.0, 0.0, 0.0);
setLineWidth(1.0);
symtics_ = false;
drawNumbers_ = false;
drawLabel_ = false;
drawTics_ = false;
autoscale_ = true;
markerLabel_.clear();
numberfont_ = QFont("Courier",12);
setLabelFont(QFont("Courier",14));
numbercolor_ = RGBA(0,0,0,0);
setNumberAnchor(Center);
numbergap_ = 0;
labelgap_ = 0;
}
void Axis::setPosition(const Triple& beg, const Triple& end)
{
beg_ = beg;
end_ = end;
}
void Axis::setMajors(int val)
{
if (val == majorintervals_)
return;
majorintervals_ = (val<=0) ? 1 : val; // always >= 1
}
/*!
\see LogScale::setMinors().
*/
void Axis::setMinors(int val)
{
if (val == minorintervals_)
return;
minorintervals_ = (val<=0) ? 1 : val; // always >= 1
}
void Axis::setTicLength(double majorl, double minorl)
{
lmaj_ = majorl;
lmin_ = minorl;
}
void Axis::setTicOrientation(double tx, double ty, double tz)
{
setTicOrientation(Triple(tx,ty,tz));
}
void Axis::setTicOrientation(const Triple& val)
{
orientation_ = val;
orientation_.normalize();
}
/**
\param val thickness for axis base line
\param majfac relative thickness for axis major tics (majfac*val)
\param minfac relative thickness for axis minor tics (minfac*val)
*/
void Axis::setLineWidth(double val, double majfac, double minfac)
{
lineWidth_ = val;
majLineWidth_ = majfac * lineWidth_;
minLineWidth_ = minfac * lineWidth_;
}
void Axis::draw()
{
Drawable::draw();
saveGLState();
// GLStateBewarer sb(GL_LINE_SMOOTH, true);
// glBlendFunc(GL_ONE, GL_ZERO);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glColor4d(color.r,color.g,color.b,color.a);
drawBase();
drawTics();
drawLabel();
restoreGLState();
}
/**
Always use AFTER drawNumbers() ! (Needs length of number string)
*/
void Axis::drawLabel()
{
if (!drawLabel_)
return;
Triple diff = end() - begin();
Triple center = begin() + diff/2;
Triple bnumber = biggestNumberString();
// double fac = 6*(second()-first()).length() / 100;
switch (scaleNumberAnchor_)
{
case BottomLeft:
case TopLeft:
case CenterLeft:
bnumber.y = 0;
break;
case BottomRight:
case TopRight:
case CenterRight:
bnumber.x = -bnumber.x;
bnumber.y = 0;
break;
case TopCenter:
bnumber.x = 0;
bnumber.y = -bnumber.y;
break;
case BottomCenter:
bnumber.x = 0;
break;
default:
break;
}
Triple pos = ViewPort2World(World2ViewPort(center + ticOrientation() * lmaj_) + bnumber);
setLabelPosition(pos, scaleNumberAnchor_);
label_.adjust(labelgap_);
label_.draw();
}
void Axis::drawBase()
{
setDeviceLineWidth( lineWidth_ );
glBegin( GL_LINES );
glVertex3d( beg_.x, beg_.y, beg_.z);
glVertex3d( end_.x, end_.y, end_.z);
glEnd();
}
bool Axis::prepTicCalculation(Triple& startpoint)
{
if (isPracticallyZero(start_, stop_))
return false;
autostart_ = start_;
autostop_ = stop_;
if (autoScale())
{
setMajors(scale_->autoscale(autostart_, autostop_, start_, stop_, majors()));
if (isPracticallyZero(autostart_, autostop_))
return false;
}
scale_->setLimits(start_,stop_);
scale_->setMajors(majors());
scale_->setMinors(minors());
scale_->setMajorLimits(autostart_,autostop_);
scale_->calculate();
Triple normal = (end_ - beg_);
//normal.normalize();
Triple beg = beg_ + ((autostart_ - start_) / (stop_ - start_)) * normal;
Triple end = end_ - ((stop_ - autostop_) / (stop_ - start_))* normal;
startpoint = end_ - beg_;
majorpos_.clear();
minorpos_.clear();
return true;
}
void Axis::recalculateTics()
{
Triple runningpoint;
if (false==prepTicCalculation(runningpoint))
return;
unsigned int i;
for (i = 0; i != scale_->majors_p.size(); ++i)
{
double t = (scale_->majors_p[i] - start_) / (stop_-start_);
majorpos_.push_back(beg_ + t * runningpoint);
}
for (i = 0; i != scale_->minors_p.size(); ++i)
{
double t = (scale_->minors_p[i] - start_) / (stop_-start_);
minorpos_.push_back(beg_ + t * runningpoint);
}
}
void Axis::drawTics()
{
Triple runningpoint;
if (!drawTics_ || false==prepTicCalculation(runningpoint))
return;
unsigned int i;
Triple nadir;
markerLabel_.resize(scale_->majors_p.size());
setDeviceLineWidth(majLineWidth_);
for (i = 0; i != scale_->majors_p.size(); ++i)
{
double t = (scale_->majors_p[i] - start_) / (stop_-start_);
nadir = beg_ + t * runningpoint;
majorpos_.push_back(drawTic(nadir, lmaj_));
drawTicLabel(nadir + 1.2 * lmaj_ * orientation_, i);
}
setDeviceLineWidth(minLineWidth_);
for (i = 0; i != scale_->minors_p.size(); ++i)
{
double t = (scale_->minors_p[i] - start_) / (stop_-start_);
nadir = beg_ + t * runningpoint;
minorpos_.push_back(drawTic(nadir, lmin_));
}
}
void Axis::drawTicLabel(Triple pos, int mtic)
{
if (!drawNumbers_ || (mtic < 0))
return;
markerLabel_[mtic].setFont(numberfont_.family(), numberfont_.pointSize(), numberfont_.weight(), numberfont_.italic());
markerLabel_[mtic].setColor(numbercolor_);
markerLabel_[mtic].setString(scale_->ticLabel(mtic));
markerLabel_[mtic].setPosition(pos, scaleNumberAnchor_);
markerLabel_[mtic].adjust(numbergap_);
markerLabel_[mtic].draw();
}
Triple Axis::drawTic(Triple nadir, double length)
{
double ilength = (symtics_) ? -length : 0.0;
glBegin( GL_LINES );
glVertex3d( nadir.x + ilength * orientation_.x,
nadir.y + ilength * orientation_.y,
nadir.z + ilength * orientation_.z) ;
glVertex3d( nadir.x + length * orientation_.x,
nadir.y + length * orientation_.y,
nadir.z + length * orientation_.z);
glEnd();
return nadir;
}
void Axis::setNumberFont(QString const& family, int pointSize, int weight, bool italic)
{
numberfont_ = QFont(family, pointSize, weight, italic );
}
void Axis::setNumberFont(QFont const& font)
{
numberfont_ = font;
}
void Axis::setNumberColor(RGBA col)
{
numbercolor_ = col;
}
void Axis::setLabelFont(QString const& family, int pointSize, int weight, bool italic)
{
labelfont_ = QFont(family, pointSize, weight, italic );
label_.setFont(family, pointSize, weight, italic);
}
void Axis::setLabelFont(QFont const& font)
{
setLabelFont(font.family(), font.pointSize(), font.weight(), font.italic());
}
void Axis::setLabelString(QString const& name)
{
label_.setString(name);
}
/*!
Sets label position in conjunction with an anchoring strategy
*/
void Axis::setLabelPosition(const Triple& pos,Qwt3D::ANCHOR an)
{
label_.setPosition(pos, an);
}
//! Sets color for label
void Axis::setLabelColor(RGBA col)
{
label_.setColor(col);
}
Triple Axis::biggestNumberString()
{
Triple ret;
unsigned size = markerLabel_.size();
double width, height;
for (unsigned i=0; i!=size; ++i)
{
width = fabs( (World2ViewPort(markerLabel_[i].second())-World2ViewPort(markerLabel_[i].first())).x );
height = fabs( (World2ViewPort(markerLabel_[i].second())-World2ViewPort(markerLabel_[i].first())).y );
if (width > ret.x)
ret.x = width + markerLabel_[i].gap();
if (height > ret.y)
ret.y = height + markerLabel_[i].gap();;
}
return ret;
}
/*!
This variant sets a user-defined scale object.
Use with a heap based initialized pointer only.
The axis adopts ownership.
*/
void Axis::setScale(Scale* val)
{
scale_ = qwt3d_ptr<Scale>(val);
}
/*!
Sets one of the predefined scaling types.
\warning Too small intervals in logarithmic scales lead to
empty scales (or perhaps a scale only containing an isolated
major tic). Better switch to linear scales in such cases.
*/
void Axis::setScale(Qwt3D::SCALETYPE val)
{
switch(val) {
case Qwt3D::LINEARSCALE:
setScale(new LinearScale);
break;
case Qwt3D::LOG10SCALE:
setScale(new LogScale);
setMinors(9);
break;
default:
break;
}
}
|