forked from root-project/root
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TGLUtil.h
1376 lines (1128 loc) · 44.9 KB
/
TGLUtil.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
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
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// @(#)root/gl:$Id$
// Author: Richard Maunder 25/05/2005
/*************************************************************************
* Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
* All rights reserved. *
* *
* For the licensing terms see $ROOTSYS/LICENSE. *
* For the list of contributors see $ROOTSYS/README/CREDITS. *
*************************************************************************/
#ifndef ROOT_TGLUtil
#define ROOT_TGLUtil
#include "Rtypes.h"
#include "TError.h"
#include <vector>
#include <cmath>
#include <cassert>
#include <utility>
class TString;
class TGLBoundingBox;
class TGLCamera;
class TAttMarker;
class TAttLine;
class GLUtesselator;
namespace Rgl
{
enum EOverlap
{
kInside = 0,
kPartial,
kOutside
};
}
enum EGLCoordType
{
kGLCartesian,
kGLPolar,
kGLCylindrical,
kGLSpherical
};
enum EGLPlotType
{
kGLLegoPlot,
kGLSurfacePlot,
kGLBoxPlot,
kGLTF3Plot,
kGLStackPlot,
kGLParametricPlot,
kGLIsoPlot,
kGL5D,
kGLTH3Composition,
kGLVoxel,
kGLDefaultPlot
};
// TODO: Split these into own h/cxx files - too long now!
//////////////////////////////////////////////////////////////////////////
// //
// TGLVertex3 //
// //
// 3 component (x/y/z) vertex class //
// //
// This is part of collection of utility classes for GL in TGLUtil.h/cxx//
// These provide const and non-const accessors Arr() / CArr() to a GL //
// compatible internal field - so can be used directly with OpenGL C API//
// calls. They are not intended to be fully featured just provide //
// minimum required. //
//////////////////////////////////////////////////////////////////////////
class TGLVector3; // Forward declare for Shift()
class TGLVertex3
{
protected:
// Fields
Bool_t ValidIndex(UInt_t index) const { return (index < 3); }
Double_t fVals[3];
public:
TGLVertex3();
TGLVertex3(Double_t x, Double_t y, Double_t z);
TGLVertex3(Double_t* v);
TGLVertex3(const TGLVertex3 & other);
~TGLVertex3();
Bool_t operator == (const TGLVertex3 & rhs) const;
TGLVertex3 & operator = (const TGLVertex3 & rhs);
TGLVertex3 & operator *= (Double_t f);
TGLVertex3 operator - () const;
const TGLVertex3 & operator -= (const TGLVector3 & val);
const TGLVertex3 & operator += (const TGLVector3 & val);
// Manipulators
void Fill(Double_t val);
void Set(Double_t x, Double_t y, Double_t z);
void Set(const Double_t* xyz);
void Set(const TGLVertex3 & other);
void Shift(TGLVector3 & shift);
void Shift(Double_t xDelta, Double_t yDelta, Double_t zDelta);
void Negate();
void Minimum(const TGLVertex3 & other);
void Maximum(const TGLVertex3 & other);
// Accessors
Double_t & operator [] (Int_t index);
const Double_t & operator [] (Int_t index) const;
Double_t X() const { return fVals[0]; }
Double_t & X() { return fVals[0]; }
Double_t Y() const { return fVals[1]; }
Double_t & Y() { return fVals[1]; }
Double_t Z() const { return fVals[2]; }
Double_t & Z() { return fVals[2]; }
const Double_t * CArr() const { return fVals; }
Double_t * Arr() { return fVals; }
void Dump() const;
ClassDefNV(TGLVertex3,1); // GL 3 component vertex helper/wrapper class
};
//______________________________________________________________________________
inline TGLVertex3 operator*(Double_t f, const TGLVertex3& v)
{
return TGLVertex3(f*v.X(), f*v.Y(), f*v.Z());
}
//______________________________________________________________________________
inline void TGLVertex3::Negate()
{
fVals[0] = -fVals[0];
fVals[1] = -fVals[1];
fVals[2] = -fVals[2];
}
//______________________________________________________________________________
inline Bool_t TGLVertex3::operator == (const TGLVertex3 & rhs) const
{
return (fVals[0] == rhs.fVals[0] && fVals[1] == rhs.fVals[1] && fVals[2] == rhs.fVals[2]);
}
//______________________________________________________________________________
inline TGLVertex3 & TGLVertex3::operator = (const TGLVertex3 & rhs)
{
// Check for self-assignment
if (this != &rhs) {
Set(rhs);
}
return *this;
}
// operator -= & operator += inline needs to be defered until full TGLVector3 definition
//______________________________________________________________________________
inline TGLVertex3 TGLVertex3::operator - () const
{
return TGLVertex3(-fVals[0], -fVals[1], -fVals[2]);
}
//______________________________________________________________________________
inline TGLVertex3& TGLVertex3::operator *= (Double_t f)
{
fVals[0] *= f;
fVals[1] *= f;
fVals[2] *= f;
return *this;
}
//______________________________________________________________________________
inline Double_t & TGLVertex3::operator [] (Int_t index)
{
/*if (!ValidIndex(index)) {
assert(kFALSE);
return fVals[0];
} else {*/
return fVals[index];
//}
}
//______________________________________________________________________________
inline const Double_t& TGLVertex3::operator [] (Int_t index) const
{
/*if (!ValidIndex(index)) {
assert(kFALSE);
return fVals[0];
} else {*/
return fVals[index];
//}
}
//______________________________________________________________________________
inline void TGLVertex3::Fill(Double_t val)
{
Set(val,val,val);
}
//______________________________________________________________________________
inline void TGLVertex3::Set(Double_t x, Double_t y, Double_t z)
{
fVals[0]=x;
fVals[1]=y;
fVals[2]=z;
}
//______________________________________________________________________________
inline void TGLVertex3::Set(const Double_t* xyz)
{
fVals[0]=xyz[0];
fVals[1]=xyz[1];
fVals[2]=xyz[2];
}
//______________________________________________________________________________
inline void TGLVertex3::Set(const TGLVertex3 & other)
{
fVals[0]=other.fVals[0];
fVals[1]=other.fVals[1];
fVals[2]=other.fVals[2];
}
//////////////////////////////////////////////////////////////////////////
// //
// TGLVector3 //
// //
// 3 component (x/y/z) vector class //
// //
// This is part of collection of utility classes for GL in TGLUtil.h/cxx//
// These provide const and non-const accessors Arr() / CArr() to a GL //
// compatible internal field - so can be used directly with OpenGL C API//
// calls. They are not intended to be fully featured just provide //
// minimum required. //
//////////////////////////////////////////////////////////////////////////
class TGLVector3 : public TGLVertex3
{
public:
TGLVector3() = default;
TGLVector3(Double_t x, Double_t y, Double_t z);
TGLVector3(const Double_t *src);
TGLVector3& operator = (const TGLVertex3& v)
{ fVals[0] = v[0]; fVals[1] = v[1]; fVals[2] = v[2]; return *this; }
TGLVector3 & operator /= (Double_t val);
TGLVector3 operator - () const;
Double_t Mag() const;
void Normalise();
ClassDefNV(TGLVector3,1); // GL 3 component vector helper/wrapper class
};
// Inline for TGLVertex3 requiring full TGLVector definition
//______________________________________________________________________________
inline const TGLVertex3 & TGLVertex3::operator -= (const TGLVector3 & vec)
{
fVals[0] -= vec[0]; fVals[1] -= vec[1]; fVals[2] -= vec[2];
return *this;
}
// Inline for TGLVertex3 requiring full TGLVector definition
//______________________________________________________________________________
inline const TGLVertex3 & TGLVertex3::operator += (const TGLVector3 & vec)
{
fVals[0] += vec[0]; fVals[1] += vec[1]; fVals[2] += vec[2];
return *this;
}
//______________________________________________________________________________
inline TGLVector3 & TGLVector3::operator /= (Double_t val)
{
fVals[0] /= val;
fVals[1] /= val;
fVals[2] /= val;
return *this;
}
//______________________________________________________________________________
inline TGLVector3 TGLVector3::operator - () const
{
return TGLVector3(-fVals[0], -fVals[1], -fVals[2]);
}
//______________________________________________________________________________
inline Double_t TGLVector3::Mag() const
{
return std::sqrt(fVals[0]*fVals[0] + fVals[1]*fVals[1] + fVals[2]*fVals[2]);
}
//______________________________________________________________________________
inline void TGLVector3::Normalise()
{
Double_t mag = Mag();
if ( mag == 0.0 ) {
Error("TGLVector3::Normalise", "vector has zero magnitude");
return;
}
fVals[0] /= mag;
fVals[1] /= mag;
fVals[2] /= mag;
}
//______________________________________________________________________________
inline Double_t Dot(const TGLVector3 & v1, const TGLVector3 & v2)
{
return v1[0]*v2[0] + v1[1]*v2[1] + v1[2]*v2[2];
}
//______________________________________________________________________________
inline TGLVector3 Cross(const TGLVector3 & v1, const TGLVector3 & v2)
{
return TGLVector3(v1[1]*v2[2] - v2[1]*v1[2],
v1[2]*v2[0] - v2[2]*v1[0],
v1[0]*v2[1] - v2[0]*v1[1]);
}
//______________________________________________________________________________
inline const TGLVector3 operator / (const TGLVector3 & vec, Double_t val)
{
return TGLVector3(vec[0] / val, vec[1] / val, vec[2] / val);
}
//______________________________________________________________________________
inline const TGLVector3 operator * (const TGLVector3 & vec, Double_t val)
{
return TGLVector3(vec[0] * val, vec[1] * val, vec[2] * val);
}
//______________________________________________________________________________
// Vertex + Vector => Vertex
inline TGLVertex3 operator + (const TGLVertex3 & vertex1, const TGLVector3 & vertex2)
{
return TGLVertex3(vertex1[0] + vertex2[0], vertex1[1] + vertex2[1], vertex1[2] + vertex2[2]);
}
//______________________________________________________________________________
// Vertex - Vertex => Vector
inline TGLVector3 operator - (const TGLVertex3 & vertex1, const TGLVertex3 & vertex2)
{
return TGLVector3(vertex1[0] - vertex2[0], vertex1[1] - vertex2[1], vertex1[2] - vertex2[2]);
}
//______________________________________________________________________________
// Vector + Vector => Vector
inline TGLVector3 operator + (const TGLVector3 & vector1, const TGLVector3 & vector2)
{
return TGLVector3(vector1[0] + vector2[0], vector1[1] + vector2[1], vector1[2] + vector2[2]);
}
//______________________________________________________________________________
// Vector - Vector => Vector
inline TGLVector3 operator - (const TGLVector3 & vector1, const TGLVector3 & vector2)
{
return TGLVector3(vector1[0] - vector2[0], vector1[1] - vector2[1], vector1[2] - vector2[2]);
}
//______________________________________________________________________________
// Dot-product
inline Double_t operator * (const TGLVector3 & a, const TGLVector3 & b)
{
return a[0]*b[0] + a[1]*b[1] + a[2]*b[2];
}
//////////////////////////////////////////////////////////////////////////
// //
// TGLLine3 //
// //
// 3D space, fixed length, line class, with direction / length 'vector',//
// passing through point 'vertex'. Just wraps a TGLVector3 / TGLVertex3 //
// pair. //
//////////////////////////////////////////////////////////////////////////
class TGLLine3
{
private:
// Fields
TGLVertex3 fVertex; //! Start vertex of line
TGLVector3 fVector; //! Vector of line from fVertex
public:
TGLLine3(const TGLVertex3 & start, const TGLVertex3 & end);
TGLLine3(const TGLVertex3 & start, const TGLVector3 & vector);
~TGLLine3() = default;
void Set(const TGLVertex3 & start, const TGLVertex3 & end);
void Set(const TGLVertex3 & start, const TGLVector3 & vector);
// Bitwise copy constructor and = operator are fine
// Accessors
const TGLVertex3 & Start() const { return fVertex; }
const TGLVertex3 End() const { return fVertex + fVector; }
const TGLVector3 & Vector() const { return fVector; }
// Debug
void Draw() const;
ClassDefNV(TGLLine3,0); // GL line wrapper class
};
//////////////////////////////////////////////////////////////////////////
// //
// TGLRect //
// //
// Viewport (pixel base) 2D rectangle class //
//////////////////////////////////////////////////////////////////////////
class TGLRect
{
private:
// Fields
Int_t fX, fY; //! Corner
Int_t fWidth, fHeight; //! Positive width/height
public:
TGLRect();
TGLRect(Int_t x, Int_t y, Int_t width, Int_t height);
TGLRect(Int_t x, Int_t y, UInt_t width, UInt_t height);
virtual ~TGLRect();
// Bitwise copy const & =op are ok at present
// Manipulators
void Set(Int_t x, Int_t y, Int_t width, Int_t height);
void SetCorner(Int_t x, Int_t y);
void Offset(Int_t dX, Int_t dY);
void Expand(Int_t x, Int_t y);
// Accessors
const Int_t* CArr() const { return &fX; }
Int_t* CArr() { return &fX; }
Int_t X() const { return fX; }
Int_t & X() { return fX; }
Int_t Y() const { return fY; }
Int_t & Y() { return fY; }
Int_t Width() const { return fWidth; }
Int_t & Width() { return fWidth; }
Int_t Height() const { return fHeight; }
Int_t & Height() { return fHeight; }
Int_t CenterX() const { return fX + fWidth/2; }
Int_t CenterY() const { return fY + fHeight/2; }
Int_t Left() const { return fX; }
Int_t Right() const { return fX + fWidth; }
Int_t Top() const { return fY; }
Int_t Bottom() const { return fY + fHeight; }
Int_t Diagonal() const;
Int_t Longest() const;
Double_t Aspect() const;
Rgl::EOverlap Overlap(const TGLRect & other) const;
ClassDef(TGLRect,0); // GL rect helper/wrapper class
};
//______________________________________________________________________________
inline void TGLRect::Set(Int_t x, Int_t y, Int_t width, Int_t height)
{
fX = x;
fY = y;
fWidth = width;
fHeight = height;
}
//______________________________________________________________________________
inline void TGLRect::SetCorner(Int_t x, Int_t y)
{
fX = x;
fY = y;
}
//______________________________________________________________________________
inline void TGLRect::Offset(Int_t dX, Int_t dY)
{
fX += dX;
fY += dY;
}
//______________________________________________________________________________
inline Int_t TGLRect::Longest() const
{
return fWidth > fHeight ? fWidth : fHeight;
}
//______________________________________________________________________________
inline Double_t TGLRect::Aspect() const
{
// Return aspect ratio (width/height)
if (fHeight == 0) {
return 0.0;
} else {
return static_cast<Double_t>(fWidth) / static_cast<Double_t>(fHeight);
}
}
//////////////////////////////////////////////////////////////////////////
// //
// TGLPlane //
// //
// 3D plane class - of format Ax + By + Cz + D = 0 //
// //
// This is part of collection of simple utility classes for GL only in //
// TGLUtil.h/cxx. These provide const and non-const accessors Arr() & //
// CArr() to a GL compatible internal field - so can be used directly //
// with OpenGL C API calls - which TVector3 etc cannot (easily). //
// They are not intended to be fully featured just provide minimum //
// required. //
//////////////////////////////////////////////////////////////////////////
class TGLPlane
{
private:
// Fields
Double_t fVals[4];
// Methods
void Normalise();
public:
TGLPlane();
TGLPlane(const TGLPlane & other);
TGLPlane(Double_t a, Double_t b, Double_t c, Double_t d);
TGLPlane(Double_t eq[4]);
TGLPlane(const TGLVector3 & norm, const TGLVertex3 & point);
TGLPlane(const TGLVertex3 & p1, const TGLVertex3 & p2, const TGLVertex3 & p3);
~TGLPlane() = default;
TGLPlane &operator=(const TGLPlane &src);
// Manipulators
void Set(const TGLPlane & other);
void Set(Double_t a, Double_t b, Double_t c, Double_t d);
void Set(Double_t eq[4]);
void Set(const TGLVector3 & norm, const TGLVertex3 & point);
void Set(const TGLVertex3 & p1, const TGLVertex3 & p2, const TGLVertex3 & p3);
void Negate();
// Accessors
Double_t A() const { return fVals[0]; }
Double_t B() const { return fVals[1]; }
Double_t C() const { return fVals[2]; }
Double_t D() const { return fVals[3]; }
TGLVector3 Norm() const { return TGLVector3( fVals[0], fVals[1], fVals[2]); }
Double_t DistanceTo(const TGLVertex3 & vertex) const;
TGLVertex3 NearestOn(const TGLVertex3 & point) const;
// Internal data accessors - for GL API
const Double_t * CArr() const { return fVals; }
Double_t * Arr() { return fVals; }
void Dump() const;
ClassDefNV(TGLPlane,0); // GL plane helper/wrapper class
};
typedef std::vector<TGLPlane> TGLPlaneSet_t;
typedef std::vector<TGLPlane>::iterator TGLPlaneSet_i;
typedef std::vector<TGLPlane>::const_iterator TGLPlaneSet_ci;
// Some free functions for planes
std::pair<Bool_t, TGLLine3> Intersection(const TGLPlane & p1, const TGLPlane & p2);
std::pair<Bool_t, TGLVertex3> Intersection(const TGLPlane & p1, const TGLPlane & p2, const TGLPlane & p3);
std::pair<Bool_t, TGLVertex3> Intersection(const TGLPlane & plane, const TGLLine3 & line, Bool_t extend);
//////////////////////////////////////////////////////////////////////////
// //
// TGLMatrix //
// //
// 16 component (4x4) transform matrix - column MAJOR as per GL. //
// Provides limited support for adjusting the translation, scale and //
// rotation components. //
// //
// This is part of collection of simple utility classes for GL only in //
// TGLUtil.h/cxx. These provide const and non-const accessors Arr() & //
// CArr() to a GL compatible internal field - so can be used directly //
// with OpenGL C API calls - which TVector3 etc cannot (easily). //
// They are not intended to be fully featured just provide minimum //
// required. //
//////////////////////////////////////////////////////////////////////////
class TGLMatrix
{
private:
// Fields
Double_t fVals[16]; // Column MAJOR as per OGL
// Methods
Bool_t ValidIndex(UInt_t index) const { return (index < 16); }
public:
TGLMatrix();
TGLMatrix(Double_t x, Double_t y, Double_t z);
TGLMatrix(const TGLVertex3 & translation);
TGLMatrix(const TGLVertex3 & origin, const TGLVector3 & zAxis, const TGLVector3 & xAxis);
TGLMatrix(const TGLVertex3 & origin, const TGLVector3 & zAxis);
TGLMatrix(const Double_t vals[16]);
TGLMatrix(const TGLMatrix & other);
virtual ~TGLMatrix();
// Operators
TGLMatrix & operator =(const TGLMatrix & rhs);
Double_t & operator [] (Int_t index);
Double_t operator [] (Int_t index) const;
void MultRight(const TGLMatrix & rhs);
void MultLeft (const TGLMatrix & lhs);
TGLMatrix & operator*=(const TGLMatrix & rhs) { MultRight(rhs); return *this; }
// Manipulators
void Set(const TGLVertex3 & origin, const TGLVector3 & zAxis, const TGLVector3 & xAxis = nullptr);
void Set(const Double_t vals[16]);
void SetIdentity();
void SetTranslation(Double_t x, Double_t y, Double_t z);
void SetTranslation(const TGLVertex3 & translation);
void Translate(const TGLVector3 & vect);
void MoveLF(Int_t ai, Double_t amount);
void Move3LF(Double_t x, Double_t y, Double_t z);
void Scale(const TGLVector3 & scale);
void Rotate(const TGLVertex3 & pivot, const TGLVector3 & axis, Double_t angle);
void RotateLF(Int_t i1, Int_t i2, Double_t amount);
void RotatePF(Int_t i1, Int_t i2, Double_t amount);
void TransformVertex(TGLVertex3 & vertex) const;
void Transpose3x3();
Double_t Invert();
// Accesors
TGLVector3 GetTranslation() const;
TGLVector3 GetScale() const;
Bool_t IsScalingForRender() const;
void SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z);
void SetBaseVec(Int_t b, const TGLVector3& v);
void SetBaseVec(Int_t b, Double_t* x);
TGLVector3 GetBaseVec(Int_t b) const;
void GetBaseVec(Int_t b, TGLVector3& v) const;
void GetBaseVec(Int_t b, Double_t* x) const;
TGLVector3 Multiply(const TGLVector3& v, Double_t w=1) const;
TGLVector3 Rotate(const TGLVector3& v) const;
void MultiplyIP(TGLVector3& v, Double_t w=1) const;
void RotateIP(TGLVector3& v) const;
// Internal data accessors - for GL API
const Double_t * CArr() const { return fVals; }
Double_t * Arr() { return fVals; }
void Dump() const;
ClassDef(TGLMatrix,1); // GL matrix helper/wrapper class
};
//______________________________________________________________________________
inline TGLMatrix & TGLMatrix::operator =(const TGLMatrix & rhs)
{
// Check for self-assignment
if (this != &rhs) {
Set(rhs.fVals);
}
return *this;
}
//______________________________________________________________________________
inline Double_t & TGLMatrix::operator [] (Int_t index)
{
/*if (!ValidIndex(index)) {
assert(kFALSE);
return fVals[0];
} else {*/
return fVals[index];
//}
}
//______________________________________________________________________________
inline Double_t TGLMatrix::operator [] (Int_t index) const
{
/*if (!ValidIndex(index)) {
assert(kFALSE);
return fVals[0];
} else {*/
return fVals[index];
//}
}
//______________________________________________________________________________
inline TGLMatrix operator * (const TGLMatrix & lhs, const TGLMatrix & rhs)
{
TGLMatrix res;
res[ 0] = rhs[ 0] * lhs[ 0] + rhs[ 1] * lhs[ 4] + rhs[ 2] * lhs[ 8] + rhs[ 3] * lhs[12];
res[ 1] = rhs[ 0] * lhs[ 1] + rhs[ 1] * lhs[ 5] + rhs[ 2] * lhs[ 9] + rhs[ 3] * lhs[13];
res[ 2] = rhs[ 0] * lhs[ 2] + rhs[ 1] * lhs[ 6] + rhs[ 2] * lhs[10] + rhs[ 3] * lhs[14];
res[ 3] = rhs[ 0] * lhs[ 3] + rhs[ 1] * lhs[ 7] + rhs[ 2] * lhs[11] + rhs[ 3] * lhs[15];
res[ 4] = rhs[ 4] * lhs[ 0] + rhs[ 5] * lhs[ 4] + rhs[ 6] * lhs[ 8] + rhs[ 7] * lhs[12];
res[ 5] = rhs[ 4] * lhs[ 1] + rhs[ 5] * lhs[ 5] + rhs[ 6] * lhs[ 9] + rhs[ 7] * lhs[13];
res[ 6] = rhs[ 4] * lhs[ 2] + rhs[ 5] * lhs[ 6] + rhs[ 6] * lhs[10] + rhs[ 7] * lhs[14];
res[ 7] = rhs[ 4] * lhs[ 3] + rhs[ 5] * lhs[ 7] + rhs[ 6] * lhs[11] + rhs[ 7] * lhs[15];
res[ 8] = rhs[ 8] * lhs[ 0] + rhs[ 9] * lhs[ 4] + rhs[10] * lhs[ 8] + rhs[11] * lhs[12];
res[ 9] = rhs[ 8] * lhs[ 1] + rhs[ 9] * lhs[ 5] + rhs[10] * lhs[ 9] + rhs[11] * lhs[13];
res[10] = rhs[ 8] * lhs[ 2] + rhs[ 9] * lhs[ 6] + rhs[10] * lhs[10] + rhs[11] * lhs[14];
res[11] = rhs[ 8] * lhs[ 3] + rhs[ 9] * lhs[ 7] + rhs[10] * lhs[11] + rhs[11] * lhs[15];
res[12] = rhs[12] * lhs[ 0] + rhs[13] * lhs[ 4] + rhs[14] * lhs[ 8] + rhs[15] * lhs[12];
res[13] = rhs[12] * lhs[ 1] + rhs[13] * lhs[ 5] + rhs[14] * lhs[ 9] + rhs[15] * lhs[13];
res[14] = rhs[12] * lhs[ 2] + rhs[13] * lhs[ 6] + rhs[14] * lhs[10] + rhs[15] * lhs[14];
res[15] = rhs[12] * lhs[ 3] + rhs[13] * lhs[ 7] + rhs[14] * lhs[11] + rhs[15] * lhs[15];
return res;
}
//______________________________________________________________________________
inline void TGLMatrix::SetBaseVec(Int_t b, Double_t x, Double_t y, Double_t z)
{
Double_t* C = fVals + 4*--b;
C[0] = x; C[1] = y; C[2] = z;
}
//______________________________________________________________________________
inline void TGLMatrix::SetBaseVec(Int_t b, const TGLVector3& v)
{
Double_t* C = fVals + 4*--b;
C[0] = v[0]; C[1] = v[1]; C[2] = v[2];
}
//______________________________________________________________________________
inline void TGLMatrix::SetBaseVec(Int_t b, Double_t* x)
{
Double_t* C = fVals + 4*--b;
C[0] = x[0]; C[1] = x[1]; C[2] = x[2];
}
//______________________________________________________________________________
inline TGLVector3 TGLMatrix::GetBaseVec(Int_t b) const
{
return TGLVector3(&fVals[4*--b]);
}
//______________________________________________________________________________
inline void TGLMatrix::GetBaseVec(Int_t b, TGLVector3& v) const
{
const Double_t* C = fVals + 4*--b;
v[0] = C[0]; v[1] = C[1]; v[2] = C[2];
}
//______________________________________________________________________________
inline void TGLMatrix::GetBaseVec(Int_t b, Double_t* x) const
{
const Double_t* C = fVals + 4*--b;
x[0] = C[0], x[1] = C[1], x[2] = C[2];
}
//////////////////////////////////////////////////////////////////////////
//
// TGLColor
//
// Encapsulate color in preferred GL format - UChar_t RGBA array.
// Color index is also cached for easier interfacing with the
// traditional ROOT graphics.
//
//////////////////////////////////////////////////////////////////////////
class TGLColor
{
protected:
UChar_t fRGBA[4];
mutable Short_t fIndex;
public:
TGLColor();
TGLColor(Int_t r, Int_t g, Int_t b, Int_t a=255);
TGLColor(Float_t r, Float_t g, Float_t b, Float_t a=1);
TGLColor(Color_t color_index, Char_t transparency=0);
TGLColor(const TGLColor& c);
TGLColor& operator=(const TGLColor& c);
UChar_t* Arr() { return fRGBA; }
const UChar_t* CArr() const { return fRGBA; }
UChar_t GetRed() const { return fRGBA[0]; }
UChar_t GetGreen() const { return fRGBA[1]; }
UChar_t GetBlue() const { return fRGBA[2]; }
UChar_t GetAlpha() const { return fRGBA[3]; }
Color_t GetColorIndex() const;
Char_t GetTransparency() const;
void SetRed(Int_t v) { fRGBA[0] = v; }
void SetGreen(Int_t v) { fRGBA[1] = v; }
void SetBlue(Int_t v) { fRGBA[2] = v; }
void SetAlpha(Int_t v) { fRGBA[3] = v; }
void SetColor(Int_t r, Int_t g, Int_t b, Int_t a=255);
void SetColor(Float_t r, Float_t g, Float_t b, Float_t a=1);
void SetColor(Color_t color_index);
void SetColor(Color_t color_index, Char_t transparency);
void SetTransparency(Char_t transparency);
TString AsString() const;
ClassDefNV(TGLColor, 0); // Color in preferred GL format - RGBA.
};
//////////////////////////////////////////////////////////////////////////
//
// TGLColorSet
//
// A collection of colors used for OpenGL rendering.
//
//////////////////////////////////////////////////////////////////////////
class TGLColorSet
{
protected:
TGLColor fBackground;
TGLColor fForeground;
TGLColor fOutline;
TGLColor fMarkup;
TGLColor fSelection[5]; // Colors for shape-selection-levels
public:
TGLColorSet();
TGLColorSet(const TGLColorSet& s);
~TGLColorSet() = default;
TGLColorSet& operator=(const TGLColorSet& s);
TGLColor& Background() { return fBackground; }
TGLColor& Foreground() { return fForeground; }
TGLColor& Outline() { return fOutline; }
TGLColor& Markup() { return fMarkup; }
TGLColor& Selection(Int_t i) { return fSelection[i]; }
const TGLColor& Background() const { return fBackground; }
const TGLColor& Foreground() const { return fForeground; }
const TGLColor& Outline() const { return fOutline; }
const TGLColor& Markup() const { return fMarkup; }
const TGLColor& Selection(Int_t i) const { return fSelection[i]; }
void StdDarkBackground();
void StdLightBackground();
ClassDefNV(TGLColorSet, 0); // Collection of colors used for GL rendering.
};
//////////////////////////////////////////////////////////////////////////
// //
// TGLUtil //
// //
// Wrapper class for various misc static functions - error checking, //
// draw helpers etc. //
// //
//////////////////////////////////////////////////////////////////////////
class TGLUtil
{
public:
class TColorLocker
{
public:
TColorLocker() { LockColor(); }
virtual ~TColorLocker() { UnlockColor(); }
ClassDef(TColorLocker,0); // Lock/unlock color in constructor/destructor.
};
class TDrawQualityModifier
{
Int_t fOldQuality;
public:
TDrawQualityModifier(Int_t dq) :
fOldQuality(GetDrawQuality()) {SetDrawQuality(dq); }
virtual ~TDrawQualityModifier()
{ SetDrawQuality(fOldQuality); }
ClassDef(TDrawQualityModifier,0); // Set/restore draw quality in constructor/destructor.
};
class TDrawQualityScaler
{
Int_t fOldQuality;
public:
TDrawQualityScaler(Float_t fac) :
fOldQuality(GetDrawQuality()) {SetDrawQuality((Int_t)(fac*fOldQuality)); }
virtual ~TDrawQualityScaler()
{ SetDrawQuality(fOldQuality); }
ClassDef(TDrawQualityScaler,0); // Multiply/restore draw quality in constructor/destructor.
};
private:
static UInt_t fgDefaultDrawQuality;
static UInt_t fgDrawQuality;
static UInt_t fgColorLockCount;
static Float_t fgPointSize;
static Float_t fgLineWidth;
static Float_t fgPointSizeScale;
static Float_t fgLineWidthScale;
static Float_t fgScreenScalingFactor;
static Float_t fgPointLineScalingFactor;
static Int_t fgPickingRadius;
static Float_t fgSimpleAxisWidthScale;
static Float_t fgSimpleAxisBBoxScale;
TGLUtil(const TGLUtil&) = delete;
TGLUtil& operator=(const TGLUtil&) = delete;
public:
virtual ~TGLUtil() {}
static void InitializeIfNeeded();
// Error checking
static Int_t CheckError(const char * loc);
// Polygon tesselator for direct drawing
static GLUtesselator* GetDrawTesselator3fv();
static GLUtesselator* GetDrawTesselator4fv();
static GLUtesselator* GetDrawTesselator3dv();
static GLUtesselator* GetDrawTesselator4dv();
// Some simple shape drawing utils
enum ELineHeadShape { kLineHeadNone, kLineHeadArrow, kLineHeadBox };
enum EAxesType { kAxesNone, kAxesEdge, kAxesOrigin };
static UInt_t GetDrawQuality();
static void SetDrawQuality(UInt_t dq);
static void ResetDrawQuality();
static UInt_t GetDefaultDrawQuality();
static void SetDefaultDrawQuality(UInt_t dq);
static UInt_t LockColor();
static UInt_t UnlockColor();
static Bool_t IsColorLocked();
static void Color(const TGLColor& color);
static void ColorAlpha(const TGLColor& color, UChar_t alpha);
static void ColorAlpha(const TGLColor& color, Float_t alpha);
static void ColorAlpha(Color_t color_index, Float_t alpha=1);
static void ColorTransparency(Color_t color_index, Char_t transparency=0);
static void Color3ub(UChar_t r, UChar_t g, UChar_t b);
static void Color4ub(UChar_t r, UChar_t g, UChar_t b, UChar_t a);
static void Color3ubv(const UChar_t* rgb);
static void Color4ubv(const UChar_t* rgba);
static void Color3f(Float_t r, Float_t g, Float_t b);
static void Color4f(Float_t r, Float_t g, Float_t b, Float_t a);
static void Color3fv(const Float_t* rgb);
static void Color4fv(const Float_t* rgba);
// Coordinate conversion and extra scaling (needed for osx retina)
static void PointToViewport(Int_t& x, Int_t& y);
static void PointToViewport(Int_t& x, Int_t& y, Int_t& w, Int_t& h);
static Float_t GetScreenScalingFactor();
static Float_t GetPointLineScalingFactor();
static Int_t GetPickingRadius();
static Float_t GetPointSizeScale();
static void SetPointSizeScale(Float_t scale);
static Float_t GetLineWidthScale();
static void SetLineWidthScale(Float_t scale);
static void PointSize(Float_t point_size);
static void LineWidth(Float_t line_width);
static Float_t PointSize();
static Float_t LineWidth();
static void BeginExtendPickRegion(Float_t scale);
static void EndExtendPickRegion();
static void RenderPolyMarkers(const TAttMarker& marker, Char_t transp,
Float_t* p, Int_t n,