Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TGLBoundingBox.h
Go to the documentation of this file.
1// @(#)root/gl:$Id$
2// Author: Richard Maunder 25/05/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2004, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12#ifndef ROOT_TGLBoundingBox
13#define ROOT_TGLBoundingBox
14
15#include "TGLUtil.h"
16
17#include <vector>
18
19//////////////////////////////////////////////////////////////////////////
20// //
21// TGLBoundingBox //
22// //
23// Concrete class describing an orientated (free) or axis aligned box //
24// of 8 verticies. Supports methods for setting aligned or orientated //
25// boxes, find volume, axes, extents, centers, face planes etc. //
26// Also tests for overlap testing of planes and other bounding boxes, //
27// with fast sphere approximation. //
28//////////////////////////////////////////////////////////////////////////
29
30// TODO: Create more compact version + axis aligned version, both with lazy
31// sphere testing.
33{
34private:
35 // Fields
36
37 // Box vertices are indexed thus (OpenGL is left handed by default)
38 // y
39 // |
40 // |
41 // |________x
42 // / 3-------2
43 // / /| /|
44 // z 7-------6 |
45 // | 0-----|-1
46 // |/ |/
47 // 4-------5
48 //
49 // 0123 'far' face
50 // 4567 'near' face
51 //
52 // This could be more compact:
53 // For orientated box 3 vertices which form plane cutting box
54 // diagonally (e.g. 0,5,6 or 1,3,6 etc) would fix in space.
55 // For axis aligned 2 verticies would suffice.
56 // Rest could be calculated on demand - however speed more important
57 // than memory considerations
58 TGLVertex3 fVertex[8]; //! the 8 bounding box vertices
59 Double_t fVolume; //! box volume - cached for speed
60 Double_t fDiagonal; //! max box diagonal - cached for speed
61 TGLVector3 fAxes[3]; //! box axes in global frame - cached for speed
62 TGLVector3 fAxesNorm[3];//! normalised box axes in global frame - cached for speed
63
64 // Methods
65 void UpdateCache();
66 Bool_t ValidIndex(UInt_t index) const { return (index < 8); }
67 Double_t Min(UInt_t index) const;
68 Double_t Max(UInt_t index) const;
69
70public:
72 TGLBoundingBox(const TGLVertex3 vertex[8]);
73 TGLBoundingBox(const Double_t vertex[8][3]);
74 TGLBoundingBox(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex);
75 TGLBoundingBox(const TGLBoundingBox & other);
76 virtual ~TGLBoundingBox(); // ClassDef introduces virtual fns
77
78 // Set orientated box
80 void Set(const TGLVertex3 vertex[8]);
81 void Set(const Double_t vertex[8][3]);
82 void Set(const TGLBoundingBox & other);
83 void SetEmpty();
84
85 // Set axis aligned box
86 void SetAligned(const TGLVertex3 & lowVertex, const TGLVertex3 & highVertex); // axis aligned
87 void SetAligned(UInt_t nbPnts, const Double_t * pnts); // axis aligned
88 void MergeAligned(const TGLBoundingBox & other);
89 void ExpandAligned(const TGLVertex3 & point);
90
91 // Manipulation
92 void Transform(const TGLMatrix & matrix);
93 void Scale(Double_t factor);
94 void Scale(Double_t xFactor, Double_t yFactor, Double_t zFactor);
95 void Translate(const TGLVector3 & offset);
96
97 // Single vertex accessors
98 const TGLVertex3 & operator [] (UInt_t index) const;
99 const TGLVertex3 & Vertex(UInt_t index) const;
100 Double_t XMin() const { return Min(0); }
101 Double_t XMax() const { return Max(0); }
102 Double_t YMin() const { return Min(1); }
103 Double_t YMax() const { return Max(1); }
104 Double_t ZMin() const { return Min(2); }
105 Double_t ZMax() const { return Max(2); }
106 TGLVertex3 MinAAVertex() const;
107 TGLVertex3 MaxAAVertex() const;
108
109 // Multiple vertices accessors
110 const TGLVertex3* Vertices() const; // All 8 box vertices
111 Int_t NumVertices() const { return 8; }
112
114 const std::vector<UInt_t> & FaceVertices(EFace face) const; // 4 box face vertices
115
116 // Other properties
117 TGLVertex3 Center() const;
118 TGLVector3 Extents() const;
119 const TGLVector3 & Axis(UInt_t i, Bool_t normalised = kTRUE) const;
120 Bool_t IsEmpty() const;
121 Double_t Volume() const { return fVolume; }
122 Double_t Diagonal() const { return fDiagonal; }
123 void PlaneSet(TGLPlaneSet_t & planeSet) const;
124 TGLPlane GetNearPlane() const;
125
126 // Overlap testing
127 Rgl::EOverlap Overlap(const TGLPlane & plane) const;
129
130 void Draw(Bool_t solid = kFALSE) const;
131 void Dump() const;
132
133 ClassDef(TGLBoundingBox,0); // a 3D orientated bounding box
134};
135
136//______________________________________________________________________________
138{
139 // Check for self-assignment
140 if (this != &other) {
141 Set(other);
142 }
143 return *this;
144}
145
146//______________________________________________________________________________
148{
149 return fVertex[index];
150}
151
152//______________________________________________________________________________
154{
155 return fVertex[index];
156}
157
158//______________________________________________________________________________
160{
161 return fVertex;
162}
163
164//______________________________________________________________________________
166{
167 // Return the local axis entents of the box
168 return TGLVector3(Axis(0,kFALSE).Mag(),
169 Axis(1,kFALSE).Mag(),
170 Axis(2,kFALSE).Mag());
171}
172
173//______________________________________________________________________________
175{
176 // Return the center vertex of the box
177 return TGLVertex3((fVertex[0].X() + fVertex[6].X())/2.0,
178 (fVertex[0].Y() + fVertex[6].Y())/2.0,
179 (fVertex[0].Z() + fVertex[6].Z())/2.0);
180}
181
182//______________________________________________________________________________
183inline const TGLVector3 & TGLBoundingBox::Axis(UInt_t i, Bool_t normalised) const
184{
185 // Return a vector representing axis of index i (0:X, 1:Y, 2:Z).
186 // Vector can be as-is (edge, magnitude == extent) or normalised (default)
187 // y
188 // |
189 // |
190 // |________x
191 // / 3-------2
192 // / /| /|
193 // z 7-------6 |
194 // | 0-----|-1
195 // |/ |/
196 // 4-------5
197 //
198
199 if (normalised) {
200 return fAxesNorm[i];
201 } else {
202 return fAxes[i];
203 }
204}
205
206//______________________________________________________________________________
208{
209 // Return kTRUE if box has zero diagonal - kFALSE otherwise
210
211 // TODO: Round errors - should have epsilon test
212 return (Diagonal() == 0.0);
213}
214
215#endif // ROOT_TGLBoundingBox
bool Bool_t
Definition RtypesCore.h:63
unsigned int UInt_t
Definition RtypesCore.h:46
constexpr Bool_t kFALSE
Definition RtypesCore.h:101
double Double_t
Definition RtypesCore.h:59
constexpr Bool_t kTRUE
Definition RtypesCore.h:100
#define ClassDef(name, id)
Definition Rtypes.h:337
#define X(type, name)
std::vector< TGLPlane > TGLPlaneSet_t
Definition TGLUtil.h:571
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h offset
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Concrete class describing an orientated (free) or axis aligned box of 8 vertices.
Double_t Volume() const
Double_t Min(UInt_t index) const
Find minimum vertex value for axis of index X(0), Y(1), Z(2)
Double_t fDiagonal
box volume - cached for speed
Double_t XMin() const
TGLPlane GetNearPlane() const
Return the near-plane.
TGLVector3 Extents() const
TGLVertex3 Center() const
void Set(const TGLVertex3 vertex[8])
Set a bounding box from provided 8 vertices.
Double_t Diagonal() const
void SetEmpty()
Set bounding box empty - all vertices at (0,0,0)
void PlaneSet(TGLPlaneSet_t &planeSet) const
Fill out supplied plane set vector with TGLPlane objects representing six faces of box.
TGLBoundingBox & operator=(const TGLBoundingBox &other)
const std::vector< UInt_t > & FaceVertices(EFace face) const
return a vector of face vertices y | | |________x / 3----—2 / /| /| z 7----—6 | | 0--—|-1 |/ |/ 4----...
TGLVertex3 fVertex[8]
Bool_t IsEmpty() const
void Transform(const TGLMatrix &matrix)
Transform all vertices with matrix.
TGLVector3 fAxesNorm[3]
box axes in global frame - cached for speed
void MergeAligned(const TGLBoundingBox &other)
Expand current bbox so that it includes other's bbox.
void Translate(const TGLVector3 &offset)
Translate all vertices by offset.
Double_t ZMax() const
const TGLVertex3 * Vertices() const
Double_t XMax() const
TGLVertex3 MinAAVertex() const
Find minimum vertex values.
Double_t YMin() const
TGLBoundingBox()
Construct an empty bounding box.
void Scale(Double_t factor)
Isotropically scale bounding box along it's LOCAL axes, preserving center.
TGLVector3 fAxes[3]
max box diagonal - cached for speed
const TGLVertex3 & Vertex(UInt_t index) const
void SetAligned(const TGLVertex3 &lowVertex, const TGLVertex3 &highVertex)
Set ALIGNED box from two low/high vertices.
TGLVertex3 MaxAAVertex() const
Find maximum vertex values.
Bool_t ValidIndex(UInt_t index) const
void UpdateCache()
normalised box axes in global frame - cached for speed
Double_t Max(UInt_t index) const
Find maximum vertex value for axis of index X(0), Y(1), Z(2)
const TGLVector3 & Axis(UInt_t i, Bool_t normalised=kTRUE) const
void ExpandAligned(const TGLVertex3 &point)
Expand current bbox so that it includes the point.
Double_t YMax() const
Double_t fVolume
the 8 bounding box vertices
virtual ~TGLBoundingBox()
Destroy bounding box.
void Dump() const
Output to std::cout the vertices, center and volume of box.
Int_t NumVertices() const
const TGLVertex3 & operator[](UInt_t index) const
Double_t ZMin() const
Rgl::EOverlap Overlap(const TGLPlane &plane) const
Find overlap (Inside, Outside, Partial) of plane c.f. bounding box.
16 component (4x4) transform matrix - column MAJOR as per GL.
Definition TGLUtil.h:598
3D plane class - of format Ax + By + Cz + D = 0
Definition TGLUtil.h:525
3 component (x/y/z) vector class.
Definition TGLUtil.h:248
3 component (x/y/z) vertex class.
Definition TGLUtil.h:84
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition fillpatterns.C:1
EOverlap
Definition TGLUtil.h:35
th1 Draw()