ROOT  6.06/09
Reference Guide
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 #ifndef ROOT_Rtypes
18 #include "Rtypes.h"
19 #endif
20 #ifndef ROOT_TAxis
21 #include "TAxis.h"
22 #endif
23 
24 class TGLBoxCut;
25 
26 namespace Rgl {
27 namespace Mc {
28 
29 /*
30 TIsoMesh - set of vertices, per-vertex normals, "triangles".
31 Each "triangle" is a triplet of indices, pointing into vertices
32 and normals arrays. For example, triangle t = {1, 4, 6}
33 has vertices &fVerts[1 * 3], &fVerts[4 * 3], &fVerts[6 * 3];
34 and normals &fNorms[1 * 3], &fNorms[4 * 3], &fNorms[6 * 3]
35 "V" parameter should be Float_t or Double_t (or some
36 integral type?).
37 
38 Prefix "T" in a class name only for code-style checker.
39 */
40 
41 template<class V>
42 class TIsoMesh {
43 public:
44  UInt_t AddVertex(const V *v)
45  {
46  const UInt_t index = UInt_t(fVerts.size() / 3);
47  fVerts.push_back(v[0]);
48  fVerts.push_back(v[1]);
49  fVerts.push_back(v[2]);
50 
51  return index;
52  }
53 
54  void AddNormal(const V *n)
55  {
56  fNorms.push_back(n[0]);
57  fNorms.push_back(n[1]);
58  fNorms.push_back(n[2]);
59  }
60 
62  {
63  const UInt_t index = UInt_t(fTris.size() / 3);
64  fTris.push_back(t[0]);
65  fTris.push_back(t[1]);
66  fTris.push_back(t[2]);
67 
68  return index;
69  }
70 
71  void Swap(TIsoMesh &rhs)
72  {
73  std::swap(fVerts, rhs.fVerts);
74  std::swap(fNorms, rhs.fNorms);
75  std::swap(fTris, rhs.fTris);
76  }
77 
78  void ClearMesh()
79  {
80  fVerts.clear();
81  fNorms.clear();
82  fTris.clear();
83  }
84 
85  std::vector<V> fVerts;
86  std::vector<V> fNorms;
87  std::vector<UInt_t> fTris;
88 };
89 
90 /*
91 TGridGeometry describes ranges and cell steps (scales are
92 already in steps and ranges).
93 */
94 template<class V>
96 public:
100  };
101 
103  fMinY(0), fStepY(0),
104  fMinZ(0), fStepZ(0),
105  fXScaleInverted(1.),
106  fYScaleInverted(1.),
107  fZScaleInverted(1.)
108  {
109  //Default constructor.
110  }
111 
112  TGridGeometry(const TAxis *x, const TAxis *y, const TAxis *z,
113  Double_t xs = 1., Double_t ys = 1., Double_t zs = 1.,
115  : fMinX(0), fStepX(0),
116  fMinY(0), fStepY(0),
117  fMinZ(0), fStepZ(0),
118  fXScaleInverted(1.),
119  fYScaleInverted(1.),
120  fZScaleInverted(1.)
121  {
122  //Define geometry using TAxis.
123  if (pos == kBinCenter) {
124  fMinX = V(x->GetBinCenter(x->GetFirst()));
125  fStepX = V((x->GetBinCenter(x->GetLast()) - fMinX) / (x->GetNbins() - 1));
126  fMinY = V(y->GetBinCenter(y->GetFirst()));
127  fStepY = V((y->GetBinCenter(y->GetLast()) - fMinY) / (y->GetNbins() - 1));
128  fMinZ = V(z->GetBinCenter(z->GetFirst()));
129  fStepZ = V((z->GetBinCenter(z->GetLast()) - fMinZ) / (z->GetNbins() - 1));
130 
131  fMinX *= xs, fStepX *= xs;
132  fMinY *= ys, fStepY *= ys;
133  fMinZ *= zs, fStepZ *= zs;
134  } else if (pos == kBinEdge) {
135  fMinX = V(x->GetBinLowEdge(x->GetFirst()));
136  fStepX = V((x->GetBinUpEdge(x->GetLast()) - fMinX) / (x->GetNbins()));
137  fMinY = V(y->GetBinLowEdge(y->GetFirst()));
138  fStepY = V((y->GetBinUpEdge(y->GetLast()) - fMinY) / (y->GetNbins()));
139  fMinZ = V(z->GetBinLowEdge(z->GetFirst()));
140  fStepZ = V((z->GetBinUpEdge(z->GetLast()) - fMinZ) / (z->GetNbins()));
141 
142  fMinX *= xs, fStepX *= xs;
143  fMinY *= ys, fStepY *= ys;
144  fMinZ *= zs, fStepZ *= zs;
145  }
146 
147  fXScaleInverted = 1. / xs;
148  fYScaleInverted = 1. / ys;
149  fZScaleInverted = 1. / zs;
150  }
151 
152  V fMinX;
154 
155  V fMinY;
157 
158  V fMinZ;
160 
164 };
165 
166 }//namespace Mc
167 
168 //Auxilary functions to draw an iso mesh in different modes.
169 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<Float_t> &ns,
170  const std::vector<UInt_t> &ts);
171 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
172  const std::vector<UInt_t> &ts);
173 
174 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &fTS);
175 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &fTS);
176 
177 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<Float_t> &ns,
178  const std::vector<UInt_t> &ts, const TGLBoxCut &box);
179 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
180  const std::vector<UInt_t> &ts, const TGLBoxCut &box);
181 
182 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &ts,
183  const TGLBoxCut &box);
184 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &ts,
185  const TGLBoxCut &box);
186 
187 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &ts,
188  const TGLBoxCut &box);
189 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &ts,
190  const TGLBoxCut &box);
191 
192 void DrawMapleMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
193  const std::vector<UInt_t> &ts);
194 void DrawMapleMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
195  const std::vector<UInt_t> &ts, const TGLBoxCut & box);
196 
197 }//namespace Rgl
198 
199 #endif
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:429
std::vector< UInt_t > fTris
Definition: TGLIsoMesh.h:87
void swap(ROOT::THist< DIMENSIONS, PRECISION > &a, ROOT::THist< DIMENSIONS, PRECISION > &b) noexcept
Swap two histograms.
Definition: THist.h:196
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:489
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
UInt_t AddVertex(const V *v)
Definition: TGLIsoMesh.h:44
void AddNormal(const V *n)
Definition: TGLIsoMesh.h:54
Double_t x[n]
Definition: legend1.C:17
TGridGeometry(const TAxis *x, const TAxis *y, const TAxis *z, Double_t xs=1., Double_t ys=1., Double_t zs=1., EVertexPosition pos=kBinCenter)
Definition: TGLIsoMesh.h:112
Class to manage histogram axis.
Definition: TAxis.h:36
SVector< double, 2 > v
Definition: Dict.h:5
Int_t GetNbins() const
Definition: TAxis.h:125
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:499
unsigned int UInt_t
Definition: RtypesCore.h:42
void Swap(TIsoMesh &rhs)
Definition: TGLIsoMesh.h:71
std::vector< V > fNorms
Definition: TGLIsoMesh.h:86
double Double_t
Definition: RtypesCore.h:55
Double_t y[n]
Definition: legend1.C:17
void DrawMapleMesh(const std::vector< Double_t > &vs, const std::vector< Double_t > &ns, const std::vector< UInt_t > &ts)
Colored mesh with lighting disabled.
Definition: TGLIsoMesh.cxx:192
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:440
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:449
Used by plot-painters to determine the area of the plot that is cut away.
std::vector< V > fVerts
Definition: TGLIsoMesh.h:85
UInt_t AddTriangle(const UInt_t *t)
Definition: TGLIsoMesh.h:61
const Int_t n
Definition: legend1.C:16
void DrawMesh(const std::vector< Float_t > &vs, const std::vector< Float_t > &ns, const std::vector< UInt_t > &ts)
Call function-template.
Definition: TGLIsoMesh.cxx:39