Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TAttBBox.cxx
Go to the documentation of this file.
1 // @(#)root/base:$Id$
2 // Author: Matevz Tadel 7/4/2006
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2006, 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 
13 #include "TAttBBox.h"
14 
15 /** \class TAttBBox
16 \ingroup Base
17 \ingroup GraphicsAtt
18 
19 Helper for management of bounding-box information.
20 Optionally used by classes that use direct OpenGL rendering
21 via `<Class>GL class`.
22 */
23 
24 ClassImp(TAttBBox);
25 
26 ////////////////////////////////////////////////////////////////////////////////
27 /// Allocate and prepare for incremental filling.
28 
29 void TAttBBox::BBoxInit(Float_t infinity)
30 {
31  if (fBBox == 0) fBBox = new Float_t[6];
32 
33  fBBox[0] = infinity; fBBox[1] = -infinity;
34  fBBox[2] = infinity; fBBox[3] = -infinity;
35  fBBox[4] = infinity; fBBox[5] = -infinity;
36 }
37 
38 ////////////////////////////////////////////////////////////////////////////////
39 /// Create cube of volume (2*epsilon)^3 at (x,y,z).
40 /// epsilon is zero by default.
41 
42 void TAttBBox::BBoxZero(Float_t epsilon, Float_t x, Float_t y, Float_t z)
43 {
44  if (fBBox == 0) fBBox = new Float_t[6];
45 
46  fBBox[0] = x - epsilon; fBBox[1] = x + epsilon;
47  fBBox[2] = y - epsilon; fBBox[3] = y + epsilon;
48  fBBox[4] = z - epsilon; fBBox[5] = z + epsilon;
49 }
50 
51 ////////////////////////////////////////////////////////////////////////////////
52 /// Remove BBox information.
53 
54 void TAttBBox::BBoxClear()
55 {
56  delete [] fBBox; fBBox = 0;
57 }
58 
59 ////////////////////////////////////////////////////////////////////////////////
60 /// Assert extents of all sides of the bounding-box are at least epsilon.
61 
62 void TAttBBox::AssertBBoxExtents(Float_t epsilon)
63 {
64  for (Int_t i=0; i<6; i+=2) {
65  if (fBBox[i+1] - fBBox[i] < epsilon) {
66  Float_t b = 0.5*(fBBox[i] + fBBox[i+1]);
67  fBBox[i] = b - 0.5*epsilon;
68  fBBox[i+1] = b + 0.5*epsilon;
69  }
70  }
71 }
72 
73 ////////////////////////////////////////////////////////////////////////////////
74 /// Setup bounding box as cube with given extent and center position.
75 
76 void TAttBBox::SetupBBoxCube(Float_t extent, Float_t x, Float_t y, Float_t z)
77 {
78  BBoxZero(extent, x, y, z);
79 }