35 ClassImp(TEveGeoPolyShape);
40 TEveGeoPolyShape::TEveGeoPolyShape() :
49 TEveGeoPolyShape* TEveGeoPolyShape::Construct(TGeoCompositeShape *cshape, Int_t n_seg)
52 TEvePadHolder gpad(kFALSE, &pad);
53 TGLScenePad scene_pad(&pad);
54 pad.GetListOfPrimitives()->Add(cshape);
55 pad.SetViewer3D(&scene_pad);
57 TEveGeoManagerHolder gmgr(TEveGeoShape::GetGeoMangeur(), n_seg);
59 scene_pad.BeginScene();
61 Double_t halfLengths[3] = { cshape->GetDX(), cshape->GetDY(), cshape->GetDZ() };
63 TBuffer3D buff(TBuffer3DTypes::kComposite);
65 buff.fLocalFrame = kTRUE;
66 buff.SetLocalMasterIdentity();
67 buff.SetAABoundingBox(cshape->GetOrigin(), halfLengths);
68 buff.SetSectionsValid(TBuffer3D::kCore|TBuffer3D::kBoundingBox);
70 Bool_t paintComponents = kTRUE;
73 if (TBuffer3D::GetCSLevel() == 0)
74 paintComponents = gPad->GetViewer3D()->OpenComposite(buff);
76 TBuffer3D::IncCSLevel();
79 TGeoMatrix *gst = TGeoShape::GetTransform();
80 TGeoShape::SetTransform(TEveGeoShape::GetGeoHMatrixIdentity());
81 if (paintComponents) cshape->GetBoolNode()->Paint(
"");
82 TGeoShape::SetTransform(gst);
84 if (TBuffer3D::DecCSLevel() == 0)
85 gPad->GetViewer3D()->CloseComposite();
90 TGLFaceSet* fs =
dynamic_cast<TGLFaceSet*
>(scene_pad.FindLogical(cshape));
92 ::Warning(
"TEveGeoPolyShape::Construct",
"Failed extracting CSG tesselation for shape '%s'.", cshape->GetName());
96 TEveGeoPolyShape *egps =
new TEveGeoPolyShape;
97 egps->SetFromFaceSet(fs);
98 egps->fOrigin[0] = cshape->GetOrigin()[0];
99 egps->fOrigin[1] = cshape->GetOrigin()[1];
100 egps->fOrigin[2] = cshape->GetOrigin()[2];
101 egps->fDX = cshape->GetDX();
102 egps->fDY = cshape->GetDY();
103 egps->fDZ = cshape->GetDZ();
111 void TEveGeoPolyShape::SetFromFaceSet(TGLFaceSet* fs)
113 fVertices = fs->GetVertices();
114 fPolyDesc = fs->GetPolyDesc();
115 fNbPols = fs->GetNbPols();
121 void TEveGeoPolyShape::FillBuffer3D(TBuffer3D& b, Int_t reqSections, Bool_t)
const
123 if (reqSections & TBuffer3D::kCore)
126 b.ClearSectionsValid();
128 b.fID =
const_cast<TEveGeoPolyShape*
>(
this);
131 b.fLocalFrame = kFALSE;
132 b.fReflection = kTRUE;
134 b.SetSectionsValid(TBuffer3D::kCore);
137 if (reqSections & TBuffer3D::kRawSizes || reqSections & TBuffer3D::kRaw)
139 UInt_t nvrt = fVertices.size() / 3;
142 std::map<Edge_t, Int_t> edges;
144 const Int_t *pd = &fPolyDesc[0];
145 for (UInt_t i = 0; i < fNbPols; ++i)
147 UInt_t nv = pd[0]; ++pd;
148 for (UInt_t j = 0; j < nv; ++j)
150 Edge_t e(pd[j], (j != nv - 1) ? pd[j+1] : pd[0]);
151 if (edges.find(e) == edges.end())
153 edges.insert(std::make_pair(e, 0));
160 b.SetRawSizes(nvrt, 3*nvrt, nseg, 3*nseg, fNbPols, fNbPols+fPolyDesc.size());
162 memcpy(b.fPnts, &fVertices[0],
sizeof(Double_t)*fVertices.size());
164 Int_t si = 0, scnt = 0;
165 for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i)
168 b.fSegs[si++] = i->first.fI;
169 b.fSegs[si++] = i->first.fJ;
175 for (UInt_t i = 0; i < fNbPols; ++i)
177 UInt_t nv = pd[0]; ++pd;
180 for (UInt_t j = 0; j < nv; ++j)
182 b.fPols[pi++] = edges[Edge_t(pd[j], (j != nv - 1) ? pd[j+1] : pd[0])];
189 b.SetSectionsValid(TBuffer3D::kRawSizes | TBuffer3D::kRaw);
196 const TBuffer3D& TEveGeoPolyShape::GetBuffer3D(Int_t reqSections, Bool_t localFrame)
const
198 static TBuffer3D buf(TBuffer3DTypes::kGeneric);
200 FillBuffer3D(buf, reqSections, localFrame);
208 TBuffer3D* TEveGeoPolyShape::MakeBuffer3D()
const
210 TBuffer3D* buf =
new TBuffer3D(TBuffer3DTypes::kGeneric);
212 FillBuffer3D(*buf, TBuffer3D::kCore | TBuffer3D::kRawSizes | TBuffer3D::kRaw, kFALSE);