forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEveQuadSet.cxx
488 lines (420 loc) · 14.7 KB
/
TEveQuadSet.cxx
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
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
// @(#)root/eve:$Id$
// Authors: Matevz Tadel & Alja Mrak-Tadel: 2006, 2007
/*************************************************************************
* Copyright (C) 1995-2007, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#include "TEveQuadSet.h"
#include "TEveManager.h"
#include "TColor.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TVirtualPad.h"
#include "TVirtualViewer3D.h"
#include "TROOT.h"
#include "TRandom.h"
/** \class TEveQuadSet
\ingroup TEve
Supports various internal formats that result in rendering of a
set of planar (lines, rectangles, hexagons with shared normal) objects.
Names of internal structures and their variables use A, B and C as
names for coordinate value-holders. Typical assignment is A->X,
B->Y, C->Z but each render mode can override this convention and
impose y or x as a fixed (third or C) coordinate. Alphabetic order
is obeyed in this correspondence.
For quad modes the deltas are expected to be positive.
For line modes negative deltas are ok.
*/
ClassImp(TEveQuadSet);
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveQuadSet::TEveQuadSet(const char* n, const char* t) :
TEveDigitSet (n, t),
fQuadType (kQT_Undef),
fDefWidth (1),
fDefHeight (1),
fDefCoord (0)
{
}
////////////////////////////////////////////////////////////////////////////////
/// Constructor.
TEveQuadSet::TEveQuadSet(EQuadType_e quadType, Bool_t valIsCol, Int_t chunkSize,
const char* n, const char* t) :
TEveDigitSet (n, t),
fQuadType (kQT_Undef),
fDefWidth (1),
fDefHeight (1),
fDefCoord (0)
{
Reset(quadType, valIsCol, chunkSize);
}
////////////////////////////////////////////////////////////////////////////////
/// Return size of given atom type.
Int_t TEveQuadSet::SizeofAtom(TEveQuadSet::EQuadType_e qt)
{
static const TEveException eH("TEveQuadSet::SizeofAtom ");
switch (qt) {
case kQT_Undef: return 0;
case kQT_FreeQuad: return sizeof(QFreeQuad_t);
case kQT_RectangleXY:
case kQT_RectangleXZ:
case kQT_RectangleYZ: return sizeof(QRect_t);
case kQT_RectangleXYFixedDim: return sizeof(QRectFixDim_t);
case kQT_RectangleXYFixedZ:
case kQT_RectangleXZFixedY:
case kQT_RectangleYZFixedX: return sizeof(QRectFixC_t);
case kQT_RectangleXYFixedDimZ:
case kQT_RectangleXZFixedDimY:
case kQT_RectangleYZFixedDimX: return sizeof(QRectFixDimC_t);
case kQT_LineXZFixedY:
case kQT_LineXYFixedZ: return sizeof(QLineFixC_t);
case kQT_HexagonXY:
case kQT_HexagonYX: return sizeof(QHex_t);
default: throw(eH + "unexpected atom type.");
}
return 0;
}
////////////////////////////////////////////////////////////////////////////////
/// Clear the quad-set and reset the basic parameters.
void TEveQuadSet::Reset(TEveQuadSet::EQuadType_e quadType, Bool_t valIsCol,
Int_t chunkSize)
{
fQuadType = quadType;
fValueIsColor = valIsCol;
fDefaultValue = valIsCol ? 0 : kMinInt;
if (fOwnIds)
ReleaseIds();
fPlex.Reset(SizeofAtom(fQuadType), chunkSize);
}
////////////////////////////////////////////////////////////////////////////////
/// Add a quad specified with 4 vertices.
void TEveQuadSet::AddQuad(Float_t verts[12])
{
static const TEveException eH("TEveQuadSet::AddQuad ");
if (fQuadType != kQT_FreeQuad)
throw(eH + "expect free quad-type.");
QFreeQuad_t* fq = (QFreeQuad_t*) NewDigit();
if (verts != 0)
memcpy(fq->fVertices, verts, sizeof(fq->fVertices));
}
////////////////////////////////////////////////////////////////////////////////
/// Add a quad with a and b coordinates. Defaults are applied for
/// c coordinate and sizes.
void TEveQuadSet::AddQuad(Float_t a, Float_t b)
{
AddQuad(a, b, fDefCoord, fDefWidth, fDefHeight);
}
////////////////////////////////////////////////////////////////////////////////
/// Add a quad with a, b and c coordinates. Defaults are applied
/// for sizes.
void TEveQuadSet::AddQuad(Float_t a, Float_t b, Float_t c)
{
AddQuad(a, b, c, fDefWidth, fDefHeight);
}
////////////////////////////////////////////////////////////////////////////////
/// Add a quad with a and b coordinates and sizes. Default is applied
/// for c coordinate.
void TEveQuadSet::AddQuad(Float_t a, Float_t b, Float_t w, Float_t h)
{
AddQuad(a, b, fDefCoord, w, h);
}
////////////////////////////////////////////////////////////////////////////////
/// Add a quad with a, b and c coordinates and sizes.
void TEveQuadSet::AddQuad(Float_t a, Float_t b, Float_t c, Float_t w, Float_t h)
{
static const TEveException eH("TEveQuadSet::AddAAQuad ");
QOrigin_t& fq = * (QOrigin_t*) NewDigit();
fq.fA = a; fq.fB = b;
switch (fQuadType)
{
case kQT_RectangleXY:
case kQT_RectangleXZ:
case kQT_RectangleYZ:
{
QRect_t& q = (QRect_t&) fq;
q.fC = c; q.fW = w; q.fH = h;
break;
}
case kQT_RectangleXYFixedDim:
{
QRectFixDim_t& q = (QRectFixDim_t&) fq;
q.fC = c;
break;
}
case kQT_RectangleXYFixedZ:
case kQT_RectangleXZFixedY:
case kQT_RectangleYZFixedX:
{
QRectFixC_t& q = (QRectFixC_t&) fq;
q.fW = w; q.fH = h;
break;
}
case kQT_RectangleXYFixedDimZ:
case kQT_RectangleXZFixedDimY:
case kQT_RectangleYZFixedDimX:
{
break;
}
default:
throw(eH + "expect axis-aligned quad-type.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Add a line with starting coordinates and displacements.
void TEveQuadSet::AddLine(Float_t a, Float_t b, Float_t w, Float_t h)
{
static const TEveException eH("TEveQuadSet::AddLine ");
QOrigin_t& fq = * (QOrigin_t*) NewDigit();
fq.fA = a; fq.fB = b;
switch (fQuadType)
{
case kQT_LineXZFixedY:
case kQT_LineXYFixedZ: {
QLineFixC_t& q = (QLineFixC_t&) fq;
q.fDx = w; q.fDy = h;
break;
}
default:
throw(eH + "expect line quad-type.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Add a hexagon with given center (a,b,c) and radius.
void TEveQuadSet::AddHexagon(Float_t a, Float_t b, Float_t c, Float_t r)
{
static const TEveException eH("TEveQuadSet::AddHexagon ");
QOrigin_t& fq = * (QOrigin_t*) NewDigit();
fq.fA = a; fq.fB = b;
switch (fQuadType)
{
case kQT_HexagonXY:
case kQT_HexagonYX: {
QHex_t& q = (QHex_t&) fq;
q.fC = c; q.fR = r;
break;
}
default:
throw(eH + "expect line quad-type.");
}
}
////////////////////////////////////////////////////////////////////////////////
/// Fill bounding-box information. Virtual from TAttBBox.
/// If member 'TEveFrameBox* fFrame' is set, frame's corners are
/// used as bbox.
void TEveQuadSet::ComputeBBox()
{
static const TEveException eH("TEveQuadSet::ComputeBBox ");
if (fFrame != 0)
{
BBoxInit();
Int_t n = fFrame->GetFrameSize() / 3;
Float_t *bbps = fFrame->GetFramePoints();
for (int i=0; i<n; ++i, bbps+=3)
BBoxCheckPoint(bbps);
}
else
{
if(fPlex.Size() == 0) {
BBoxZero();
return;
}
BBoxInit();
if (fQuadType == kQT_RectangleXYFixedZ ||
fQuadType == kQT_RectangleXYFixedDimZ)
{
fBBox[4] = fDefCoord;
fBBox[5] = fDefCoord;
}
else if (fQuadType == kQT_RectangleXZFixedY ||
fQuadType == kQT_RectangleXZFixedDimY)
{
fBBox[2] = fDefCoord;
fBBox[3] = fDefCoord;
}
else if (fQuadType == kQT_RectangleYZFixedX ||
fQuadType == kQT_RectangleYZFixedDimX)
{
fBBox[0] = fDefCoord;
fBBox[1] = fDefCoord;
}
TEveChunkManager::iterator qi(fPlex);
switch (fQuadType)
{
case kQT_FreeQuad:
{
while (qi.next()) {
const Float_t* p = ((QFreeQuad_t*) qi())->fVertices;
BBoxCheckPoint(p); p += 3;
BBoxCheckPoint(p); p += 3;
BBoxCheckPoint(p); p += 3;
BBoxCheckPoint(p);
}
break;
}
case kQT_RectangleXY:
{
while (qi.next()) {
QRect_t& q = * (QRect_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + q.fW > fBBox[1]) fBBox[1] = q.fA + q.fW;
if(q.fB < fBBox[2]) fBBox[2] = q.fB;
if(q.fB + q.fH > fBBox[3]) fBBox[3] = q.fB + q.fH;
if(q.fC < fBBox[4]) fBBox[4] = q.fC;
if(q.fC > fBBox[5]) fBBox[5] = q.fC;
}
break;
}
case kQT_RectangleXZ:
{
while (qi.next()) {
QRect_t& q = * (QRect_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + q.fW > fBBox[1]) fBBox[1] = q.fA + q.fW;
if(q.fB < fBBox[4]) fBBox[4] = q.fB;
if(q.fB + q.fH > fBBox[5]) fBBox[5] = q.fB + q.fH;
if(q.fC < fBBox[2]) fBBox[2] = q.fC;
if(q.fC > fBBox[3]) fBBox[3] = q.fC;
}
break;
}
case kQT_RectangleYZ:
{
while (qi.next()) {
QRect_t& q = * (QRect_t*) qi();
if(q.fA < fBBox[2]) fBBox[2] = q.fA;
if(q.fA + q.fW > fBBox[3]) fBBox[3] = q.fA + q.fW;
if(q.fB < fBBox[4]) fBBox[4] = q.fB;
if(q.fB + q.fH > fBBox[5]) fBBox[5] = q.fB + q.fH;
if(q.fC < fBBox[0]) fBBox[0] = q.fC;
if(q.fC > fBBox[1]) fBBox[1] = q.fC;
}
break;
}
case kQT_RectangleXYFixedDim:
{
const Float_t& w = fDefWidth;
const Float_t& h = fDefHeight;
while (qi.next()) {
QRectFixDim_t& q = * (QRectFixDim_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + w > fBBox[1]) fBBox[1] = q.fA + w;
if(q.fB < fBBox[2]) fBBox[2] = q.fB;
if(q.fB + h > fBBox[3]) fBBox[3] = q.fB + h;
if(q.fC < fBBox[4]) fBBox[4] = q.fC;
if(q.fC > fBBox[5]) fBBox[5] = q.fC;
}
break;
}
case kQT_RectangleXYFixedZ:
{
while (qi.next()) {
QRectFixC_t& q = * (QRectFixC_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + q.fW > fBBox[1]) fBBox[1] = q.fA + q.fW;
if(q.fB < fBBox[2]) fBBox[2] = q.fB;
if(q.fB + q.fH > fBBox[3]) fBBox[3] = q.fB + q.fH;
}
break;
}
case kQT_RectangleXZFixedY:
{
while (qi.next()) {
QRectFixC_t& q = * (QRectFixC_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + q.fW > fBBox[1]) fBBox[1] = q.fA + q.fW;
if(q.fB < fBBox[4]) fBBox[4] = q.fB;
if(q.fB + q.fH > fBBox[5]) fBBox[5] = q.fB + q.fH;
}
break;
}
case kQT_RectangleYZFixedX:
{
while (qi.next()) {
QRectFixC_t& q = * (QRectFixC_t*) qi();
if(q.fA < fBBox[2]) fBBox[2] = q.fA;
if(q.fA + q.fW > fBBox[3]) fBBox[3] = q.fA + q.fW;
if(q.fB < fBBox[4]) fBBox[4] = q.fB;
if(q.fB + q.fH > fBBox[5]) fBBox[5] = q.fB + q.fH;
}
break;
}
case kQT_RectangleXYFixedDimZ:
{
const Float_t& w = fDefWidth;
const Float_t& h = fDefHeight;
while (qi.next()) {
QRectFixDimC_t& q = * (QRectFixDimC_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + w > fBBox[1]) fBBox[1] = q.fA + w;
if(q.fB < fBBox[2]) fBBox[2] = q.fB;
if(q.fB + h > fBBox[3]) fBBox[3] = q.fB + h;
}
break;
}
case kQT_RectangleXZFixedDimY:
{
const Float_t& w = fDefWidth;
const Float_t& h = fDefHeight;
while (qi.next()) {
QRectFixDimC_t& q = * (QRectFixDimC_t*) qi();
if(q.fA < fBBox[0]) fBBox[0] = q.fA;
if(q.fA + w > fBBox[1]) fBBox[1] = q.fA + w;
if(q.fB < fBBox[4]) fBBox[4] = q.fB;
if(q.fB + h > fBBox[5]) fBBox[5] = q.fB + h;
}
break;
}
case kQT_RectangleYZFixedDimX:
{
const Float_t& w = fDefWidth;
const Float_t& h = fDefHeight;
while (qi.next()) {
QRectFixDimC_t& q = * (QRectFixDimC_t*) qi();
if(q.fA < fBBox[2]) fBBox[2] = q.fA;
if(q.fA + w > fBBox[3]) fBBox[3] = q.fA + w;
if(q.fB < fBBox[4]) fBBox[4] = q.fB;
if(q.fB + h > fBBox[5]) fBBox[5] = q.fB + h;
}
break;
}
// TEveLine modes
case kQT_LineXYFixedZ:
{
while (qi.next()) {
QLineFixC_t& q = * (QLineFixC_t*) qi();
BBoxCheckPoint(q.fA, q.fB, fDefCoord);
BBoxCheckPoint(q.fA + q.fDx, q.fB + q.fDy, fDefCoord);
}
break;
}
case kQT_LineXZFixedY:
{
while (qi.next()) {
QLineFixC_t& q = * (QLineFixC_t*) qi();
BBoxCheckPoint(q.fA, fDefCoord, q.fB);
BBoxCheckPoint(q.fA + q.fDx, fDefCoord, q.fB + q.fDy);
}
break;
}
// Hexagon modes
// Ignore 'slight' difference, assume square box for both cases.
case kQT_HexagonXY:
case kQT_HexagonYX:
{
while (qi.next()) {
QHex_t& q = * (QHex_t*) qi();
BBoxCheckPoint(q.fA-q.fR, q.fB-q.fR, q.fC);
BBoxCheckPoint(q.fA+q.fR, q.fB+q.fR, q.fC);
}
break;
}
default:
{
throw(eH + "unsupported quad-type.");
}
} // end switch quad-type
} // end if frame ... else ...
}