TGLIsoMesh.h

Go to the documentation of this file.
00001 // @(#)root/gl:$Id: TGLIsoMesh.h 33600 2010-05-21 09:24:32Z rdm $
00002 // Author:  Timur Pocheptsov  06/01/2009
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2009, Rene Brun and Fons Rademakers.               *
00006  * All rights reserved.                                                  *
00007  *                                                                       *
00008  * For the licensing terms see $ROOTSYS/LICENSE.                         *
00009  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
00010  *************************************************************************/
00011 
00012 #ifndef ROOT_TGLIsoMesh
00013 #define ROOT_TGLIsoMesh
00014 
00015 #include <vector>
00016 
00017 #ifndef ROOT_Rtypes
00018 #include "Rtypes.h"
00019 #endif
00020 #ifndef ROOT_TAxis
00021 #include "TAxis.h"
00022 #endif
00023 
00024 class TGLBoxCut;
00025 
00026 namespace Rgl {
00027 namespace Mc {
00028 
00029 /*
00030 TIsoMesh - set of vertices, per-vertex normals, "triangles". 
00031 Each "triangle" is a triplet of indices, pointing into vertices 
00032 and normals arrays. For example, triangle t = {1, 4, 6}
00033 has vertices &fVerts[1 * 3], &fVerts[4 * 3], &fVerts[6 * 3];
00034 and normals &fNorms[1 * 3], &fNorms[4 * 3], &fNorms[6 * 3]
00035 "V" parameter should be Float_t or Double_t (or some
00036 integral type?).
00037 
00038 Prefix "T" in a class name only for code-style checker.
00039 */
00040 
00041 template<class V>
00042 class TIsoMesh {
00043 public:
00044    UInt_t AddVertex(const V *v)
00045    {
00046       const UInt_t index = UInt_t(fVerts.size() / 3);
00047       fVerts.push_back(v[0]);
00048       fVerts.push_back(v[1]);
00049       fVerts.push_back(v[2]);
00050 
00051       return index;
00052    }
00053 
00054    void AddNormal(const V *n)
00055    {
00056       fNorms.push_back(n[0]);
00057       fNorms.push_back(n[1]);
00058       fNorms.push_back(n[2]);
00059    }
00060 
00061    UInt_t AddTriangle(const UInt_t *t)
00062    {
00063       const UInt_t index = UInt_t(fTris.size() / 3);
00064       fTris.push_back(t[0]);
00065       fTris.push_back(t[1]);
00066       fTris.push_back(t[2]);
00067 
00068       return index;
00069    }
00070 
00071    void Swap(TIsoMesh &rhs)
00072    {
00073       std::swap(fVerts, rhs.fVerts);
00074       std::swap(fNorms, rhs.fNorms);
00075       std::swap(fTris, rhs.fTris);
00076    }
00077 
00078    void ClearMesh()
00079    {
00080       fVerts.clear();
00081       fNorms.clear();
00082       fTris.clear();
00083    }
00084 
00085    std::vector<V>      fVerts;
00086    std::vector<V>      fNorms;
00087    std::vector<UInt_t> fTris;
00088 };
00089 
00090 /*
00091 TGridGeometry describes ranges and cell steps (scales are 
00092 already in steps and ranges).
00093 */
00094 template<class V>
00095 class TGridGeometry {
00096 public:
00097    enum EVertexPosition{
00098       kBinCenter,
00099       kBinEdge
00100    };
00101 
00102    TGridGeometry() : fMinX(0),  fStepX(0),
00103                      fMinY(0),  fStepY(0),
00104                      fMinZ(0),  fStepZ(0),
00105                      fXScaleInverted(1.),
00106                      fYScaleInverted(1.),
00107                      fZScaleInverted(1.)
00108    {
00109       //Default constructor.
00110    }
00111    
00112    TGridGeometry(const TAxis *x, const TAxis *y, const TAxis *z,
00113                  Double_t xs = 1., Double_t ys = 1., Double_t zs = 1.,
00114                  EVertexPosition pos = kBinCenter)
00115          : fMinX(0),  fStepX(0),
00116            fMinY(0),  fStepY(0),
00117            fMinZ(0),  fStepZ(0),
00118            fXScaleInverted(1.),
00119            fYScaleInverted(1.),
00120            fZScaleInverted(1.)
00121    {
00122       //Define geometry using TAxis.
00123       if (pos == kBinCenter) {
00124          fMinX  = V(x->GetBinCenter(x->GetFirst()));
00125          fStepX = V((x->GetBinCenter(x->GetLast()) - fMinX) / (x->GetNbins() - 1));
00126          fMinY  = V(y->GetBinCenter(y->GetFirst()));
00127          fStepY = V((y->GetBinCenter(y->GetLast()) - fMinY) / (y->GetNbins() - 1));
00128          fMinZ  = V(z->GetBinCenter(z->GetFirst()));
00129          fStepZ = V((z->GetBinCenter(z->GetLast()) - fMinZ) / (z->GetNbins() - 1));
00130 
00131          fMinX *= xs, fStepX *= xs;
00132          fMinY *= ys, fStepY *= ys;
00133          fMinZ *= zs, fStepZ *= zs;
00134       } else if (pos == kBinEdge) {
00135          fMinX  = V(x->GetBinLowEdge(x->GetFirst()));
00136          fStepX = V((x->GetBinUpEdge(x->GetLast()) - fMinX) / (x->GetNbins()));
00137          fMinY  = V(y->GetBinLowEdge(y->GetFirst()));
00138          fStepY = V((y->GetBinUpEdge(y->GetLast()) - fMinY) / (y->GetNbins()));
00139          fMinZ  = V(z->GetBinLowEdge(z->GetFirst()));
00140          fStepZ = V((z->GetBinUpEdge(z->GetLast()) - fMinZ) / (z->GetNbins()));
00141 
00142          fMinX *= xs, fStepX *= xs;
00143          fMinY *= ys, fStepY *= ys;
00144          fMinZ *= zs, fStepZ *= zs;
00145       }
00146 
00147       fXScaleInverted = 1. / xs;
00148       fYScaleInverted = 1. / ys;
00149       fZScaleInverted = 1. / zs;
00150    }
00151    
00152    V fMinX;
00153    V fStepX;
00154 
00155    V fMinY;
00156    V fStepY;
00157 
00158    V fMinZ;
00159    V fStepZ;
00160 
00161    V fXScaleInverted;
00162    V fYScaleInverted;
00163    V fZScaleInverted;
00164 };
00165 
00166 }//namespace Mc
00167 
00168 //Auxilary functions to draw an iso mesh in different modes.
00169 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<Float_t> &ns, 
00170               const std::vector<UInt_t> &ts);
00171 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns, 
00172               const std::vector<UInt_t> &ts);
00173 
00174 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &fTS);
00175 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &fTS);
00176 
00177 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<Float_t> &ns, 
00178               const std::vector<UInt_t> &ts, const TGLBoxCut &box);
00179 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns, 
00180               const std::vector<UInt_t> &ts, const TGLBoxCut &box);
00181 
00182 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &ts,
00183               const TGLBoxCut &box);
00184 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &ts,
00185               const TGLBoxCut &box);
00186 
00187 void DrawMesh(const std::vector<Double_t> &vs, const std::vector<UInt_t> &ts, 
00188               const TGLBoxCut &box);
00189 void DrawMesh(const std::vector<Float_t> &vs, const std::vector<UInt_t> &ts, 
00190               const TGLBoxCut &box);
00191 
00192 void DrawMapleMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
00193                    const std::vector<UInt_t> &ts);
00194 void DrawMapleMesh(const std::vector<Double_t> &vs, const std::vector<Double_t> &ns,
00195                    const std::vector<UInt_t> &ts, const TGLBoxCut & box);
00196 
00197 }//namespace Rgl
00198 
00199 #endif

Generated on Tue Jul 5 14:16:45 2011 for ROOT_528-00b_version by  doxygen 1.5.1