Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
TGLIsoMesh.h
Go to the documentation of this file.
1 // @(#)root/gl:$Id$
2 // Author: Timur Pocheptsov 06/01/2009
3 
4 /*************************************************************************
5  * Copyright (C) 1995-2009, 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_TGLIsoMesh
13 #define ROOT_TGLIsoMesh
14 
15 #include <vector>
16 
17 #include "Rtypes.h"
18 #include "TAxis.h"
19 
20 class TGLBoxCut;
21 
22 namespace Rgl {
23 namespace Mc {
24 
25 /*
26 TIsoMesh - set of vertices, per-vertex normals, "triangles".
27 Each "triangle" is a triplet of indices, pointing into vertices
28 and normals arrays. For example, triangle t = {1, 4, 6}
29 has vertices &fVerts[1 * 3], &fVerts[4 * 3], &fVerts[6 * 3];
30 and normals &fNorms[1 * 3], &fNorms[4 * 3], &fNorms[6 * 3]
31 "V" parameter should be Float_t or Double_t (or some
32 integral type?).
33 
34 Prefix "T" in a class name only for code-style checker.
35 */
36 
37 template<class V>
38 class TIsoMesh {
39 public:
40  UInt_t AddVertex(const V *v)
41  {
42  const UInt_t index = UInt_t(fVerts.size() / 3);
43  fVerts.push_back(v[0]);
44  fVerts.push_back(v[1]);
45  fVerts.push_back(v[2]);
46 
47  return index;
48  }
49 
50  void AddNormal(const V *n)
51  {
52  fNorms.push_back(n[0]);
53  fNorms.push_back(n[1]);
54  fNorms.push_back(n[2]);
55  }
56 
57  UInt_t AddTriangle(const UInt_t *t)
58  {
59  const UInt_t index = UInt_t(fTris.size() / 3);
60  fTris.push_back(t[0]);
61  fTris.push_back(t[1]);
62  fTris.push_back(t[2]);
63 
64  return index;
65  }
66 
67  void Swap(TIsoMesh &rhs)
68  {
69  std::swap(fVerts, rhs.fVerts);
70  std::swap(fNorms, rhs.fNorms);
71  std::swap(fTris, rhs.fTris);
72  }
73 
74  void ClearMesh()
75  {
76  fVerts.clear();
77  fNorms.clear();
78  fTris.clear();
79  }
80 
81  std::vector<V> fVerts;
82  std::vector<V> fNorms;
83  std::vector<UInt_t> fTris;
84 };
85 
86 /*
87 TGridGeometry describes ranges and cell steps (scales are
88 already in steps and ranges).
89 */
90 template<class V>
91 class TGridGeometry {
92 public:
93  enum EVertexPosition{
94  kBinCenter,
95  kBinEdge
96  };
97 
98  TGridGeometry() : fMinX(0), fStepX(0),
99  fMinY(0), fStepY(0),
100  fMinZ(0), fStepZ(0),
101  fXScaleInverted(1.),
102  fYScaleInverted(1.),
103  fZScaleInverted(1.)
104  {
105  //Default constructor.
106  }
107 
108  TGridGeometry(const TAxis *x, const TAxis *y, const TAxis *z,
109  Double_t xs = 1., Double_t ys = 1., Double_t zs = 1.,
110  EVertexPosition pos = kBinCenter)
111  : fMinX(0), fStepX(0),
112  fMinY(0), fStepY(0),
113  fMinZ(0), fStepZ(0),
114  fXScaleInverted(1.),
115  fYScaleInverted(1.),
116  fZScaleInverted(1.)
117  {
118  //Define geometry using TAxis.
119  if (pos == kBinCenter) {
120  fMinX = V(x->GetBinCenter(x->GetFirst()));
121  fStepX = V((x->GetBinCenter(x->GetLast()) - fMinX) / (x->GetNbins() - 1));
122  fMinY = V(y->GetBinCenter(y->GetFirst()));
123  fStepY = V((y->GetBinCenter(y->GetLast()) - fMinY) / (y->GetNbins() - 1));
124  fMinZ = V(z->GetBinCenter(z->GetFirst()));
125  fStepZ = V((z->GetBinCenter(z->GetLast()) - fMinZ) / (z->GetNbins() - 1));
126 
127  fMinX *= xs, fStepX *= xs;
128  fMinY *= ys, fStepY *= ys;
129  fMinZ *= zs, fStepZ *= zs;
130  } else if (pos == kBinEdge) {
131  fMinX = V(x->GetBinLowEdge(x->GetFirst()));
132  fStepX = V((x->GetBinUpEdge(x->GetLast()) - fMinX) / (x->GetNbins()));
133  fMinY = V(y->GetBinLowEdge(y->GetFirst()));
134  fStepY = V((y->GetBinUpEdge(y->GetLast()) - fMinY) / (y->GetNbins()));
135  fMinZ = V(z->GetBinLowEdge(z->GetFirst()));
136  fStepZ = V((z->GetBinUpEdge(z->GetLast()) - fMinZ) / (z->GetNbins()));
137 
138  fMinX *= xs, fStepX *= xs;
139  fMinY *= ys, fStepY *= ys;
140  fMinZ *= zs, fStepZ *= zs;
141  }
142 
143  fXScaleInverted = 1. / xs;
144  fYScaleInverted = 1. / ys;
145  fZScaleInverted = 1. / zs;
146  }
147 
148  V fMinX;
149  V fStepX;
150 
151  V fMinY;
152  V fStepY;
153 
154  V fMinZ;
155  V fStepZ;
156 
157  V fXScaleInverted;
158  V fYScaleInverted;
159  V fZScaleInverted;
160 };
161 
162 }//namespace Mc
163 
164 //Auxilary functions to draw an iso mesh in different modes.
165 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<Float_t> &ns,
166  const std::vector<UInt_t> &ts);
167 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
168  const std::vector<UInt_t> &ts);
169 
170 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &fTS);
171 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &fTS);
172 
173 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<Float_t> &ns,
174  const std::vector<UInt_t> &ts, const TGLBoxCut &box);
175 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
176  const std::vector<UInt_t> &ts, const TGLBoxCut &box);
177 
178 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &ts,
179  const TGLBoxCut &box);
180 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &ts,
181  const TGLBoxCut &box);
182 
183 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &ts,
184  const TGLBoxCut &box);
185 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &ts,
186  const TGLBoxCut &box);
187 
188 void DrawMapleMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
189  const std::vector<UInt_t> &ts);
190 void DrawMapleMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
191  const std::vector<UInt_t> &ts, const TGLBoxCut & box);
192 
193 }//namespace Rgl
194 
195 #endif