00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef ROOT_TGLBoundingBox
00013 #define ROOT_TGLBoundingBox
00014
00015 #ifndef ROOT_TGLUtil
00016 #include "TGLUtil.h"
00017 #endif
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 class TGLBoundingBox
00033 {
00034 private:
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 TGLVertex3 fVertex[8];
00059 Double_t fVolume;
00060 Double_t fDiagonal;
00061 TGLVector3 fAxes[3];
00062 TGLVector3 fAxesNorm[3];
00063
00064
00065 void UpdateCache();
00066 Bool_t ValidIndex(UInt_t index) const { return (index < 8); }
00067 Double_t Min(UInt_t index) const;
00068 Double_t Max(UInt_t index) const;
00069
00070 public:
00071 TGLBoundingBox();
00072 TGLBoundingBox(const TGLVertex3 vertex[8]);
00073 TGLBoundingBox(const Double_t vertex[8][3]);
00074 TGLBoundingBox(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
00075 TGLBoundingBox(const TGLBoundingBox & other);
00076 virtual ~TGLBoundingBox();
00077
00078
00079 TGLBoundingBox & operator =(const TGLBoundingBox & other);
00080 void Set(const TGLVertex3 vertex[8]);
00081 void Set(const Double_t vertex[8][3]);
00082 void Set(const TGLBoundingBox & other);
00083 void SetEmpty();
00084
00085
00086 void SetAligned(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
00087 void SetAligned(UInt_t nbPnts, const Double_t * pnts);
00088 void MergeAligned(const TGLBoundingBox & other);
00089 void ExpandAligned(const TGLVertex3 & point);
00090
00091
00092 void Transform(const TGLMatrix & matrix);
00093 void Scale(Double_t factor);
00094 void Scale(Double_t xFactor, Double_t yFactor, Double_t zFactor);
00095 void Translate(const TGLVector3 & offset);
00096
00097
00098 const TGLVertex3 & operator [] (UInt_t index) const;
00099 const TGLVertex3 & Vertex(UInt_t index) const;
00100 Double_t XMin() const { return Min(0); }
00101 Double_t XMax() const { return Max(0); }
00102 Double_t YMin() const { return Min(1); }
00103 Double_t YMax() const { return Max(1); }
00104 Double_t ZMin() const { return Min(2); }
00105 Double_t ZMax() const { return Max(2); }
00106 TGLVertex3 MinAAVertex() const;
00107 TGLVertex3 MaxAAVertex() const;
00108
00109
00110 const TGLVertex3* Vertices() const;
00111 Int_t NumVertices() const { return 8; }
00112
00113 enum EFace { kFaceLowX, kFaceHighX, kFaceLowY, kFaceHighY, kFaceLowZ, kFaceHighZ, kFaceCount };
00114 const std::vector<UInt_t> & FaceVertices(EFace face) const;
00115
00116
00117 TGLVertex3 Center() const;
00118 TGLVector3 Extents() const;
00119 const TGLVector3 & Axis(UInt_t i, Bool_t normalised = kTRUE) const;
00120 Bool_t IsEmpty() const;
00121 Double_t Volume() const { return fVolume; }
00122 Double_t Diagonal() const { return fDiagonal; }
00123 void PlaneSet(TGLPlaneSet_t & planeSet) const;
00124 TGLPlane GetNearPlane() const;
00125
00126
00127 EOverlap Overlap(const TGLPlane & plane) const;
00128 EOverlap Overlap(const TGLBoundingBox & box) const;
00129
00130 void Draw(Bool_t solid = kFALSE) const;
00131 void Dump() const;
00132
00133 ClassDef(TGLBoundingBox,0);
00134 };
00135
00136
00137 inline TGLBoundingBox & TGLBoundingBox::operator =(const TGLBoundingBox & other)
00138 {
00139
00140 if (this != &other) {
00141 Set(other);
00142 }
00143 return *this;
00144 }
00145
00146
00147 inline const TGLVertex3 & TGLBoundingBox::operator [] (UInt_t index) const
00148 {
00149 return fVertex[index];
00150 }
00151
00152
00153 inline const TGLVertex3 & TGLBoundingBox::Vertex(UInt_t index) const
00154 {
00155 return fVertex[index];
00156 }
00157
00158
00159 inline const TGLVertex3* TGLBoundingBox::Vertices() const
00160 {
00161 return fVertex;
00162 }
00163
00164
00165 inline TGLVector3 TGLBoundingBox::Extents() const
00166 {
00167
00168 return TGLVector3(Axis(0,kFALSE).Mag(),
00169 Axis(1,kFALSE).Mag(),
00170 Axis(2,kFALSE).Mag());
00171 }
00172
00173
00174 inline TGLVertex3 TGLBoundingBox::Center() const
00175 {
00176
00177 return TGLVertex3((fVertex[0].X() + fVertex[6].X())/2.0,
00178 (fVertex[0].Y() + fVertex[6].Y())/2.0,
00179 (fVertex[0].Z() + fVertex[6].Z())/2.0);
00180 }
00181
00182
00183 inline const TGLVector3 & TGLBoundingBox::Axis(UInt_t i, Bool_t normalised) const
00184 {
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199 if (normalised) {
00200 return fAxesNorm[i];
00201 } else {
00202 return fAxes[i];
00203 }
00204 }
00205
00206
00207 inline Bool_t TGLBoundingBox::IsEmpty() const
00208 {
00209
00210
00211
00212 return (Diagonal() == 0.0);
00213 }
00214
00215 #endif // ROOT_TGLBoundingBox