Logo ROOT   6.14/05
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 #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 
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>
92 public:
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;
150 
151  V fMinY;
153 
154  V fMinZ;
156 
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
std::vector< UInt_t > fTris
Definition: TGLIsoMesh.h:83
Int_t GetFirst() const
Return first bin on the axis i.e.
Definition: TAxis.cxx:444
virtual Double_t GetBinLowEdge(Int_t bin) const
Return low edge of bin.
Definition: TAxis.cxx:504
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
void box(Int_t pat, Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Definition: fillpatterns.C:1
virtual Double_t GetBinUpEdge(Int_t bin) const
Return up edge of bin.
Definition: TAxis.cxx:514
UInt_t AddVertex(const V *v)
Definition: TGLIsoMesh.h:40
void AddNormal(const V *n)
Definition: TGLIsoMesh.h:50
Double_t x[n]
Definition: legend1.C:17
virtual Double_t GetBinCenter(Int_t bin) const
Return center of bin.
Definition: TAxis.cxx:464
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:108
Int_t GetLast() const
Return last bin on the axis i.e.
Definition: TAxis.cxx:455
Class to manage histogram axis.
Definition: TAxis.h:30
SVector< double, 2 > v
Definition: Dict.h:5
unsigned int UInt_t
Definition: RtypesCore.h:42
void Swap(TIsoMesh &rhs)
Definition: TGLIsoMesh.h:67
std::vector< V > fNorms
Definition: TGLIsoMesh.h:82
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
you should not use this method at all Int_t Int_t z
Definition: TRolke.cxx:630
Used by plot-painters to determine the area of the plot that is cut away.
Int_t GetNbins() const
Definition: TAxis.h:121
std::vector< V > fVerts
Definition: TGLIsoMesh.h:81
UInt_t AddTriangle(const UInt_t *t)
Definition: TGLIsoMesh.h:57
static constexpr double ns
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