TEveGeoPolyShape.cxx

Go to the documentation of this file.
00001 // @(#)root/eve:$Id: TEveGeoPolyShape.cxx 37192 2010-12-02 15:54:26Z matevz $
00002 // Author: Matevz Tadel 2007
00003 
00004 /*************************************************************************
00005  * Copyright (C) 1995-2007, 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 #include "TEveGeoPolyShape.h"
00013 #include "TEveGeoShape.h"
00014 #include "TEvePad.h"
00015 #include "TEveUtil.h"
00016 
00017 #include "TVirtualPad.h"
00018 #include "TBuffer3D.h"
00019 #include "TBuffer3DTypes.h"
00020 #include "TGLScenePad.h"
00021 #include "TGLFaceSet.h"
00022 
00023 #include "TList.h"
00024 #include "TGeoBoolNode.h"
00025 #include "TGeoCompositeShape.h"
00026 #include "TGeoMatrix.h"
00027 
00028 //______________________________________________________________________________
00029 // Description of TEveGeoPolyShape
00030 //
00031 
00032 ClassImp(TEveGeoPolyShape);
00033 
00034 //______________________________________________________________________________
00035 TEveGeoPolyShape::TEveGeoPolyShape() :
00036    TGeoBBox(),
00037    fNbPols(0)
00038 {
00039    // Constructor.
00040 }
00041 
00042 //______________________________________________________________________________
00043 TEveGeoPolyShape* TEveGeoPolyShape::Construct(TGeoCompositeShape *cshape, Int_t n_seg)
00044 {
00045    // Static constructor from a composite shape.
00046 
00047    TEvePad       pad;
00048    TEvePadHolder gpad(kFALSE, &pad);
00049    TGLScenePad   scene_pad(&pad);
00050    pad.GetListOfPrimitives()->Add(cshape);
00051    pad.SetViewer3D(&scene_pad);
00052 
00053    TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur(), n_seg);
00054 
00055    scene_pad.BeginScene();
00056    {
00057       Double_t halfLengths[3] = { cshape->GetDX(), cshape->GetDY(), cshape->GetDZ() };
00058 
00059       TBuffer3D buff(TBuffer3DTypes::kComposite);
00060       buff.fID           = cshape;
00061       buff.fLocalFrame   = kTRUE;
00062       buff.SetLocalMasterIdentity();
00063       buff.SetAABoundingBox(cshape->GetOrigin(), halfLengths);
00064       buff.SetSectionsValid(TBuffer3D::kCore|TBuffer3D::kBoundingBox);
00065 
00066       Bool_t paintComponents = kTRUE;
00067 
00068       // Start a composite shape, identified by this buffer
00069       if (TBuffer3D::GetCSLevel() == 0)
00070          paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
00071 
00072       TBuffer3D::IncCSLevel();
00073 
00074       // Paint the boolean node - will add more buffers to viewer
00075       TGeoHMatrix xxx;
00076       TGeoMatrix *gst = TGeoShape::GetTransform();
00077       TGeoShape::SetTransform(&xxx);
00078       if (paintComponents) cshape->GetBoolNode()->Paint("");
00079       TGeoShape::SetTransform(gst);
00080       // Close the composite shape
00081       if (TBuffer3D::DecCSLevel() == 0)
00082          gPad->GetViewer3D()->CloseComposite();
00083    }
00084    scene_pad.EndScene();
00085    pad.SetViewer3D(0);
00086 
00087    TGLFaceSet* fs = dynamic_cast<TGLFaceSet*>(scene_pad.FindLogical(cshape));
00088    if (!fs) {
00089       ::Warning("TEveGeoPolyShape::Construct", "Failed extracting CSG tesselation for shape '%s'.", cshape->GetName());
00090       return 0;
00091    }
00092 
00093    TEveGeoPolyShape *egps = new TEveGeoPolyShape;
00094    egps->SetFromFaceSet(fs);
00095    egps->fOrigin[0] = cshape->GetOrigin()[0];
00096    egps->fOrigin[1] = cshape->GetOrigin()[1];
00097    egps->fOrigin[2] = cshape->GetOrigin()[2];
00098    egps->fDX = cshape->GetDX();
00099    egps->fDY = cshape->GetDY();
00100    egps->fDZ = cshape->GetDZ();
00101 
00102    return egps;
00103 }
00104 
00105 //______________________________________________________________________________
00106 void TEveGeoPolyShape::SetFromFaceSet(TGLFaceSet* fs)
00107 {
00108    // Set data-members from a face-set.
00109 
00110    fVertices = fs->GetVertices();
00111    fPolyDesc = fs->GetPolyDesc();
00112    fNbPols   = fs->GetNbPols();
00113 }
00114 
00115 //______________________________________________________________________________
00116 void TEveGeoPolyShape::FillBuffer3D(TBuffer3D& b, Int_t reqSections, Bool_t) const
00117 {
00118    // Fill the passed buffer 3D.
00119 
00120    if (reqSections & TBuffer3D::kCore)
00121    {
00122       // If writing core section all others will be invalid
00123       b.ClearSectionsValid();
00124 
00125       b.fID = const_cast<TEveGeoPolyShape*>(this);
00126       b.fColor = 0;
00127       b.fTransparency = 0;
00128       b.fLocalFrame = kFALSE;
00129       b.fReflection = kTRUE;
00130 
00131       b.SetSectionsValid(TBuffer3D::kCore);
00132    }
00133 
00134    if (reqSections & TBuffer3D::kRawSizes || reqSections & TBuffer3D::kRaw)
00135    {
00136       UInt_t nvrt = fVertices.size() / 3;
00137       UInt_t nseg = 0;
00138 
00139       std::map<Edge_t, Int_t> edges;
00140 
00141       const Int_t *pd = &fPolyDesc[0];
00142       for (UInt_t i = 0; i < fNbPols; ++i)
00143       {
00144          UInt_t nv = pd[0]; ++pd;
00145          for (UInt_t j = 0; j < nv; ++j)
00146          {
00147             Edge_t e(pd[j], (j != nv - 1) ? pd[j+1] : pd[0]);
00148             if (edges.find(e) == edges.end())
00149             {
00150                edges.insert(std::make_pair(e, 0));
00151                ++nseg;
00152             }
00153          }
00154          pd += nv;
00155       }
00156 
00157       b.SetRawSizes(nvrt, 3*nvrt, nseg, 3*nseg, fNbPols, fNbPols+fPolyDesc.size());
00158 
00159       memcpy(b.fPnts, &fVertices[0], sizeof(Double_t)*fVertices.size());
00160 
00161       Int_t si = 0, scnt = 0;
00162       for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
00163       {
00164          b.fSegs[si++] = 0;
00165          b.fSegs[si++] = i->first.fI;
00166          b.fSegs[si++] = i->first.fJ;
00167          i->second = scnt++;
00168       }
00169 
00170       Int_t pi = 0;
00171       pd = &fPolyDesc[0];
00172       for (UInt_t i = 0; i < fNbPols; ++i)
00173       {
00174          UInt_t nv = pd[0]; ++pd;
00175          b.fPols[pi++] = 0;
00176          b.fPols[pi++] = nv;
00177          for (UInt_t j = 0; j < nv; ++j)
00178          {
00179             b.fPols[pi++] = edges[Edge_t(pd[j], (j != nv - 1) ? pd[j+1] : pd[0])];
00180          }
00181          pd += nv;
00182       }
00183 
00184       
00185 
00186       b.SetSectionsValid(TBuffer3D::kRawSizes | TBuffer3D::kRaw);
00187    }
00188 }
00189 
00190 //______________________________________________________________________________
00191 const TBuffer3D& TEveGeoPolyShape::GetBuffer3D(Int_t reqSections, Bool_t localFrame) const
00192 {
00193    // Fill static buffer 3D.
00194 
00195    static TBuffer3D buf(TBuffer3DTypes::kGeneric);
00196 
00197    FillBuffer3D(buf, reqSections, localFrame);
00198 
00199    return buf;
00200 }
00201 
00202 //______________________________________________________________________________
00203 TBuffer3D* TEveGeoPolyShape::MakeBuffer3D() const
00204 {
00205    // Create buffer 3D and fill it with point/segment/poly data.
00206 
00207    TBuffer3D* buf = new TBuffer3D(TBuffer3DTypes::kGeneric);
00208 
00209    FillBuffer3D(*buf, TBuffer3D::kCore | TBuffer3D::kRawSizes | TBuffer3D::kRaw, kFALSE);
00210 
00211    return buf;
00212 }

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