Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TAttBBox.h
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 #ifndef ROOT_TAttBBox
13 #define ROOT_TAttBBox
14 
15 #include "Rtypes.h"
16 
17 class TAttBBox
18 {
19 protected:
20  Float_t* fBBox; //! Dynamic Float_t[6] X(min,max), Y(min,max), Z(min,max)
21 
22  void BBoxInit(Float_t infinity=1e6);
23  void BBoxZero(Float_t epsilon=0, Float_t x=0, Float_t y=0, Float_t z=0);
24  void BBoxClear();
25 
26  void BBoxCheckPoint(Float_t x, Float_t y, Float_t z);
27  void BBoxCheckPoint(const Float_t* p);
28 
29  void AssertBBoxExtents(Float_t epsilon=0.005);
30 
31  TAttBBox(const TAttBBox& tab) : fBBox(0) {
32  BBoxInit(); if(tab.fBBox) for(Int_t i=0; i<6; i++) fBBox[i]=tab.fBBox[i];
33  }
34 
35 public:
36  TAttBBox(): fBBox(0) { }
37  virtual ~TAttBBox() { BBoxClear(); }
38 
39  TAttBBox& operator=(const TAttBBox& tab)
40  {if(this!=&tab) {BBoxInit(); if(tab.fBBox) for(Int_t i=0; i<6; i++) fBBox[i]=tab.fBBox[i];}
41  return *this;}
42 
43  Bool_t GetBBoxOK() const { return fBBox != 0; }
44  Float_t* GetBBox() { return fBBox; }
45  Float_t* AssertBBox() { if(fBBox == 0) ComputeBBox(); return fBBox; }
46  void ResetBBox() { if(fBBox != 0) BBoxClear(); }
47 
48  void SetupBBoxCube(Float_t extent, Float_t x, Float_t y, Float_t z);
49 
50  virtual void ComputeBBox() = 0;
51 
52  ClassDef(TAttBBox,1); // Helper for management of bounding-box information
53 };
54 
55 
56 // Inline methods:
57 
58 inline void TAttBBox::BBoxCheckPoint(Float_t x, Float_t y, Float_t z)
59 {
60  if(x < fBBox[0]) fBBox[0] = x;
61  if(x > fBBox[1]) fBBox[1] = x;
62  if(y < fBBox[2]) fBBox[2] = y;
63  if(y > fBBox[3]) fBBox[3] = y;
64  if(z < fBBox[4]) fBBox[4] = z;
65  if(z > fBBox[5]) fBBox[5] = z;
66 }
67 
68 inline void TAttBBox::BBoxCheckPoint(const Float_t* p)
69 {
70  BBoxCheckPoint(p[0], p[1], p[2]);
71 }
72 
73 #endif