File indexing completed on 2025-12-15 10:29:52
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012 #ifndef ROOT_TGLBoundingBox
0013 #define ROOT_TGLBoundingBox
0014
0015 #include "TGLUtil.h"
0016
0017 #include <vector>
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 class TGLBoundingBox
0033 {
0034 private:
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
0057
0058 TGLVertex3 fVertex[8];
0059 Double_t fVolume;
0060 Double_t fDiagonal;
0061 TGLVector3 fAxes[3];
0062 TGLVector3 fAxesNorm[3];
0063
0064
0065 void UpdateCache();
0066 Bool_t ValidIndex(UInt_t index) const { return (index < 8); }
0067 Double_t Min(UInt_t index) const;
0068 Double_t Max(UInt_t index) const;
0069
0070 public:
0071 TGLBoundingBox();
0072 TGLBoundingBox(const TGLVertex3 vertex[8]);
0073 TGLBoundingBox(const Double_t vertex[8][3]);
0074 TGLBoundingBox(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
0075 TGLBoundingBox(const TGLBoundingBox & other);
0076 virtual ~TGLBoundingBox();
0077
0078
0079 TGLBoundingBox & operator =(const TGLBoundingBox & other);
0080 void Set(const TGLVertex3 vertex[8]);
0081 void Set(const Double_t vertex[8][3]);
0082 void Set(const TGLBoundingBox & other);
0083 void SetEmpty();
0084
0085
0086 void SetAligned(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
0087 void SetAligned(UInt_t nbPnts, const Double_t * pnts);
0088 void MergeAligned(const TGLBoundingBox & other);
0089 void ExpandAligned(const TGLVertex3 & point);
0090
0091
0092 void Transform(const TGLMatrix & matrix);
0093 void Scale(Double_t factor);
0094 void Scale(Double_t xFactor, Double_t yFactor, Double_t zFactor);
0095 void Translate(const TGLVector3 & offset);
0096
0097
0098 const TGLVertex3 & operator [] (UInt_t index) const;
0099 const TGLVertex3 & Vertex(UInt_t index) const;
0100 Double_t XMin() const { return Min(0); }
0101 Double_t XMax() const { return Max(0); }
0102 Double_t YMin() const { return Min(1); }
0103 Double_t YMax() const { return Max(1); }
0104 Double_t ZMin() const { return Min(2); }
0105 Double_t ZMax() const { return Max(2); }
0106 TGLVertex3 MinAAVertex() const;
0107 TGLVertex3 MaxAAVertex() const;
0108
0109
0110 const TGLVertex3* Vertices() const;
0111 Int_t NumVertices() const { return 8; }
0112
0113 enum EFace { kFaceLowX, kFaceHighX, kFaceLowY, kFaceHighY, kFaceLowZ, kFaceHighZ, kFaceCount };
0114 const std::vector<UInt_t> & FaceVertices(EFace face) const;
0115
0116
0117 TGLVertex3 Center() const;
0118 TGLVector3 Extents() const;
0119 const TGLVector3 & Axis(UInt_t i, Bool_t normalised = kTRUE) const;
0120 Bool_t IsEmpty() const;
0121 Double_t Volume() const { return fVolume; }
0122 Double_t Diagonal() const { return fDiagonal; }
0123 void PlaneSet(TGLPlaneSet_t & planeSet) const;
0124 TGLPlane GetNearPlane() const;
0125
0126
0127 Rgl::EOverlap Overlap(const TGLPlane & plane) const;
0128 Rgl::EOverlap Overlap(const TGLBoundingBox & box) const;
0129
0130 void Draw(Bool_t solid = kFALSE) const;
0131 void Dump() const;
0132
0133 ClassDef(TGLBoundingBox,0);
0134 };
0135
0136
0137 inline TGLBoundingBox & TGLBoundingBox::operator =(const TGLBoundingBox & other)
0138 {
0139
0140 if (this != &other) {
0141 Set(other);
0142 }
0143 return *this;
0144 }
0145
0146
0147 inline const TGLVertex3 & TGLBoundingBox::operator [] (UInt_t index) const
0148 {
0149 return fVertex[index];
0150 }
0151
0152
0153 inline const TGLVertex3 & TGLBoundingBox::Vertex(UInt_t index) const
0154 {
0155 return fVertex[index];
0156 }
0157
0158
0159 inline const TGLVertex3* TGLBoundingBox::Vertices() const
0160 {
0161 return fVertex;
0162 }
0163
0164
0165 inline TGLVector3 TGLBoundingBox::Extents() const
0166 {
0167
0168 return TGLVector3(Axis(0,kFALSE).Mag(),
0169 Axis(1,kFALSE).Mag(),
0170 Axis(2,kFALSE).Mag());
0171 }
0172
0173
0174 inline TGLVertex3 TGLBoundingBox::Center() const
0175 {
0176
0177 return TGLVertex3((fVertex[0].X() + fVertex[6].X())/2.0,
0178 (fVertex[0].Y() + fVertex[6].Y())/2.0,
0179 (fVertex[0].Z() + fVertex[6].Z())/2.0);
0180 }
0181
0182
0183 inline const TGLVector3 & TGLBoundingBox::Axis(UInt_t i, Bool_t normalised) const
0184 {
0185
0186
0187
0188
0189
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199 if (normalised) {
0200 return fAxesNorm[i];
0201 } else {
0202 return fAxes[i];
0203 }
0204 }
0205
0206
0207 inline Bool_t TGLBoundingBox::IsEmpty() const
0208 {
0209
0210
0211
0212 return (Diagonal() == 0.0);
0213 }
0214
0215 #endif