#ifndef ROOT_TGLBoundingBox
#define ROOT_TGLBoundingBox
#ifndef ROOT_TGLUtil
#include "TGLUtil.h"
#endif
class TGLBoundingBox
{
private:
TGLVertex3 fVertex[8];
Double_t fVolume;
Double_t fDiagonal;
TGLVector3 fAxes[3];
TGLVector3 fAxesNorm[3];
void UpdateCache();
Bool_t ValidIndex(UInt_t index) const { return (index < 8); }
Double_t Min(UInt_t index) const;
Double_t Max(UInt_t index) const;
public:
TGLBoundingBox();
TGLBoundingBox(const TGLVertex3 vertex[8]);
TGLBoundingBox(const Double_t vertex[8][3]);
TGLBoundingBox(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
TGLBoundingBox(const TGLBoundingBox & other);
virtual ~TGLBoundingBox();
TGLBoundingBox & operator =(const TGLBoundingBox & other);
void Set(const TGLVertex3 vertex[8]);
void Set(const Double_t vertex[8][3]);
void Set(const TGLBoundingBox & other);
void SetEmpty();
void SetAligned(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
void SetAligned(UInt_t nbPnts, const Double_t * pnts);
void MergeAligned(const TGLBoundingBox & other);
void ExpandAligned(const TGLVertex3 & point);
void Transform(const TGLMatrix & matrix);
void Scale(Double_t factor);
void Scale(Double_t xFactor, Double_t yFactor, Double_t zFactor);
void Translate(const TGLVector3 & offset);
const TGLVertex3 & operator [] (UInt_t index) const;
const TGLVertex3 & Vertex(UInt_t index) const;
Double_t XMin() const { return Min(0); }
Double_t XMax() const { return Max(0); }
Double_t YMin() const { return Min(1); }
Double_t YMax() const { return Max(1); }
Double_t ZMin() const { return Min(2); }
Double_t ZMax() const { return Max(2); }
TGLVertex3 MinAAVertex() const;
TGLVertex3 MaxAAVertex() const;
const TGLVertex3* Vertices() const;
Int_t NumVertices() const { return 8; }
enum EFace { kFaceLowX, kFaceHighX, kFaceLowY, kFaceHighY, kFaceLowZ, kFaceHighZ, kFaceCount };
const std::vector<UInt_t> & FaceVertices(EFace face) const;
TGLVertex3 Center() const;
TGLVector3 Extents() const;
const TGLVector3 & Axis(UInt_t i, Bool_t normalised = kTRUE) const;
Bool_t IsEmpty() const;
Double_t Volume() const { return fVolume; }
Double_t Diagonal() const { return fDiagonal; }
void PlaneSet(TGLPlaneSet_t & planeSet) const;
TGLPlane GetNearPlane() const;
Rgl::EOverlap Overlap(const TGLPlane & plane) const;
Rgl::EOverlap Overlap(const TGLBoundingBox & box) const;
void Draw(Bool_t solid = kFALSE) const;
void Dump() const;
ClassDef(TGLBoundingBox,0);
};
inline TGLBoundingBox & TGLBoundingBox::operator =(const TGLBoundingBox & other)
{
if (this != &other) {
Set(other);
}
return *this;
}
inline const TGLVertex3 & TGLBoundingBox::operator [] (UInt_t index) const
{
return fVertex[index];
}
inline const TGLVertex3 & TGLBoundingBox::Vertex(UInt_t index) const
{
return fVertex[index];
}
inline const TGLVertex3* TGLBoundingBox::Vertices() const
{
return fVertex;
}
inline TGLVector3 TGLBoundingBox::Extents() const
{
return TGLVector3(Axis(0,kFALSE).Mag(),
Axis(1,kFALSE).Mag(),
Axis(2,kFALSE).Mag());
}
inline TGLVertex3 TGLBoundingBox::Center() const
{
return TGLVertex3((fVertex[0].X() + fVertex[6].X())/2.0,
(fVertex[0].Y() + fVertex[6].Y())/2.0,
(fVertex[0].Z() + fVertex[6].Z())/2.0);
}
inline const TGLVector3 & TGLBoundingBox::Axis(UInt_t i, Bool_t normalised) const
{
if (normalised) {
return fAxesNorm[i];
} else {
return fAxes[i];
}
}
inline Bool_t TGLBoundingBox::IsEmpty() const
{
return (Diagonal() == 0.0);
}
#endif // ROOT_TGLBoundingBox