diff --git a/graf3d/eve/inc/TEveGeoShape.h b/graf3d/eve/inc/TEveGeoShape.h index 5124b76105540d14a44ae35d872784ce0aee56a7..174842cb164ede158df1c795d2ec8ac3269525dc 100644 --- a/graf3d/eve/inc/TEveGeoShape.h +++ b/graf3d/eve/inc/TEveGeoShape.h @@ -32,6 +32,7 @@ protected: Color_t fColor; Int_t fNSegments; TGeoShape* fShape; + Bool_t fMiniOutline; static TGeoManager* fgGeoMangeur; @@ -45,11 +46,13 @@ public: virtual TObject* GetObject(const TEveException&) const { const TObject* obj = this; return const_cast<TObject*>(obj); } - Color_t GetColor() const { return fColor; } + Color_t GetColor() const { return fColor; } Int_t GetNSegments() const { return fNSegments; } - void SetNSegments(Int_t s) { fNSegments = s; } - TGeoShape* GetShape() { return fShape; } + void SetNSegments(Int_t s) { fNSegments = s; } + TGeoShape* GetShape() { return fShape; } void SetShape(TGeoShape* s); + Bool_t GetMiniOutline() const { return fMiniOutline; } + void SetMiniOutline(Bool_t r) { fMiniOutline = r; } virtual void Paint(Option_t* option=""); @@ -65,7 +68,7 @@ public: static TGeoManager* GetGeoMangeur(); - ClassDef(TEveGeoShape, 1); // Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TGeoShape's (without an active TGeoManager) and simplified geometries (needed for NLT projections). + ClassDef(TEveGeoShape, 2); // Wrapper for TGeoShape with absolute positioning and color attributes allowing display of extracted TGeoShape's (without an active TGeoManager) and simplified geometries (needed for NLT projections). }; //------------------------------------------------------------------------------ @@ -79,7 +82,8 @@ private: TEveGeoShapeProjected& operator=(const TEveGeoShapeProjected&); // Not implemented protected: - TBuffer3D* fBuff; + TBuffer3D *fBuff; + Bool_t fMiniOutline; virtual void SetDepthLocal(Float_t d); @@ -87,7 +91,7 @@ public: TEveGeoShapeProjected(); virtual ~TEveGeoShapeProjected() {} - virtual Bool_t CanEditMainTransparency() const { return kTRUE; } + virtual Bool_t CanEditMainTransparency() const { return kTRUE; } virtual void SetProjection(TEveProjectionManager* proj, TEveProjectable* model); virtual void UpdateProjection(); @@ -96,6 +100,9 @@ public: virtual void ComputeBBox(); virtual void Paint(Option_t* option = ""); + Bool_t GetMiniOutline() const { return fMiniOutline; } + void SetMiniOutline(Bool_t r) { fMiniOutline = r; } + ClassDef(TEveGeoShapeProjected, 0); }; diff --git a/graf3d/eve/inc/TEveGeoShapeExtract.h b/graf3d/eve/inc/TEveGeoShapeExtract.h index 12385760a4d1201b19eeb5c5f1c9976f173c25b5..31013b9f48c3d27f5279b4f4d75427066e43424a 100644 --- a/graf3d/eve/inc/TEveGeoShapeExtract.h +++ b/graf3d/eve/inc/TEveGeoShapeExtract.h @@ -27,6 +27,7 @@ protected: Float_t fRGBA[4]; // RGBA color. Bool_t fRnrSelf; // Render this object. Bool_t fRnrElements; // Render children of this object. + Bool_t fMiniOutline; // Minimize shape outline when drawing. TGeoShape* fShape; // Shape to be drawn for this object. TList* fElements; // Children elements. @@ -41,6 +42,7 @@ public: void SetRGBA (const Float_t arr[4]); void SetRnrSelf(Bool_t r) { fRnrSelf = r; } void SetRnrElements(Bool_t r) { fRnrElements = r; } + void SetMiniOutline(Bool_t r) { fMiniOutline = r; } void SetShape(TGeoShape* s) { fShape = s; } void SetElements(TList* e) { fElements = e; } @@ -48,10 +50,11 @@ public: Float_t* GetRGBA() { return fRGBA; } Bool_t GetRnrSelf() { return fRnrSelf; } Bool_t GetRnrElements() { return fRnrElements; } + Bool_t GetMiniOutline() { return fMiniOutline; } TGeoShape* GetShape() { return fShape; } TList* GetElements() { return fElements; } - ClassDef(TEveGeoShapeExtract, 1); // Globally positioned TGeoShape with rendering attributes and an optional list of daughter shape-extracts. + ClassDef(TEveGeoShapeExtract, 2); // Globally positioned TGeoShape with rendering attributes and an optional list of daughter shape-extracts. }; #endif diff --git a/graf3d/eve/inc/TEvePolygonSetProjected.h b/graf3d/eve/inc/TEvePolygonSetProjected.h index 0e6d5142e4dbbd6dc52904c4292880312703a9ae..01909cc596ffa3256f875d6f99ebe78ddc801474 100644 --- a/graf3d/eve/inc/TEvePolygonSetProjected.h +++ b/graf3d/eve/inc/TEvePolygonSetProjected.h @@ -41,7 +41,12 @@ protected: { fNPnts = x.fNPnts; fPnts = x.fPnts; return *this; } Int_t FindPoint(Int_t pi) - { for (Int_t i=0; i<fNPnts; ++i) if (fPnts[i] == pi) return i; return -1; } + { + for (Int_t i=0; i<fNPnts; ++i) { + if (fPnts[i] == pi) return i; + } + return -1; + } }; typedef std::list<Polygon_t> vpPolygon_t; @@ -66,6 +71,8 @@ protected: Int_t fNPnts; // number of reduced and projected points TEveVector* fPnts; // reduced and projected points + Bool_t fMiniOutline; + virtual void SetDepthLocal(Float_t d); public: @@ -83,6 +90,9 @@ public: virtual void DumpPolys() const; void DumpBuffer3D(); + Bool_t GetMiniOutline() const { return fMiniOutline; } + void SetMiniOutline(Bool_t r) { fMiniOutline = r; } + ClassDef(TEvePolygonSetProjected,0); // Set of projected polygons with outline; typically produced from a TBuffer3D. }; diff --git a/graf3d/eve/inc/TEvePolygonSetProjectedGL.h b/graf3d/eve/inc/TEvePolygonSetProjectedGL.h index 334eb1d3b2bc75589f563027430270e29d005bef..0030ae7c11476dfad2fefb2f2465b74d114caed7 100644 --- a/graf3d/eve/inc/TEvePolygonSetProjectedGL.h +++ b/graf3d/eve/inc/TEvePolygonSetProjectedGL.h @@ -14,8 +14,31 @@ #include "TGLObject.h" +class TEvePolygonSetProjected; + class TEvePolygonSetProjectedGL : public TGLObject { +protected: + struct Edge_t + { + Int_t fI, fJ; + Edge_t(Int_t i, Int_t j) + { + if (i <= j) { fI = i; fJ = j; } + else { fI = j; fJ = i; } + } + + bool operator<(const Edge_t& e) const + { + if (fI == e.fI) + return fJ < e.fJ; + else + return fI < e.fI; + } + }; + + TEvePolygonSetProjected *fM; + public: TEvePolygonSetProjectedGL(); virtual ~TEvePolygonSetProjectedGL() {} diff --git a/graf3d/eve/src/TEveGeoShape.cxx b/graf3d/eve/src/TEveGeoShape.cxx index 4e2e403cdaa7399d4b11e78f8365f788725991a8..33d9ea9b91f872e61deb05a87de566094caec921 100644 --- a/graf3d/eve/src/TEveGeoShape.cxx +++ b/graf3d/eve/src/TEveGeoShape.cxx @@ -96,7 +96,8 @@ TEveGeoShape::TEveGeoShape(const char* name, const char* title) : TNamed (name, title), fColor (0), fNSegments (0), - fShape (0) + fShape (0), + fMiniOutline (kTRUE) { // Constructor. @@ -230,6 +231,7 @@ TEveGeoShapeExtract* TEveGeoShape::DumpShapeTree(TEveGeoShape* gsre, she->SetRGBA(rgba); she->SetRnrSelf(gsre->GetRnrSelf()); she->SetRnrElements(gsre->GetRnrChildren()); + she->SetMiniOutline(gsre->GetMiniOutline()); she->SetShape(gsre->GetShape()); if (gsre->HasChildren()) { @@ -276,6 +278,7 @@ TEveGeoShape* TEveGeoShape::SubImportShapeExtract(TEveGeoShapeExtract* gse, gsre->SetMainAlpha(rgba[3]); gsre->SetRnrSelf(gse->GetRnrSelf()); gsre->SetRnrChildren(gse->GetRnrElements()); + gsre->SetMiniOutline(gse->GetMiniOutline()); gsre->SetShape(gse->GetShape()); if (parent) @@ -354,7 +357,8 @@ ClassImp(TEveGeoShapeProjected); //______________________________________________________________________________ TEveGeoShapeProjected::TEveGeoShapeProjected() : TEveElementList("TEveGeoShapeProjected", "", kTRUE), - fBuff(0) + fBuff(0), + fMiniOutline(kTRUE) { // Constructor. } @@ -380,6 +384,7 @@ void TEveGeoShapeProjected::SetProjection(TEveProjectionManager* mng, TEveGeoShape* gre = dynamic_cast<TEveGeoShape*>(fProjectable); SetMainColor(gre->GetMainColor()); + SetMiniOutline(gre->GetMiniOutline()); CopyVizParams(gre); } diff --git a/graf3d/eve/src/TEveGeoShapeExtract.cxx b/graf3d/eve/src/TEveGeoShapeExtract.cxx index 2222cf1ad498e417a344ab8121595a4b2af599a6..8177330676245cc49da2e2f81a359aea5d370a31 100644 --- a/graf3d/eve/src/TEveGeoShapeExtract.cxx +++ b/graf3d/eve/src/TEveGeoShapeExtract.cxx @@ -34,9 +34,9 @@ ClassImp(TEveGeoShapeExtract); //______________________________________________________________________________ TEveGeoShapeExtract::TEveGeoShapeExtract(const char* n, const char* t) : TNamed (n,t), - fRnrSelf (kTRUE), fRnrElements (kTRUE), + fMiniOutline (kTRUE), fShape (0), fElements (0) { diff --git a/graf3d/eve/src/TEvePolygonSetProjected.cxx b/graf3d/eve/src/TEvePolygonSetProjected.cxx index eb84125b2fe0d97a2381ab5fbba9bc0695914e62..8769601ad05ff64e58a6969b965653c7a07d2b87 100644 --- a/graf3d/eve/src/TEvePolygonSetProjected.cxx +++ b/graf3d/eve/src/TEvePolygonSetProjected.cxx @@ -54,7 +54,8 @@ TEvePolygonSetProjected::TEvePolygonSetProjected(const char* n, const char* t) : TEveShape(n, t), fBuff(0), fNPnts(0), - fPnts(0) + fPnts(0), + fMiniOutline(kTRUE) { // Constructor. } @@ -103,6 +104,7 @@ void TEvePolygonSetProjected::SetProjection(TEveProjectionManager* mng, SetLineColor(color); // SetLineColor((Color_t)TColor::GetColorBright(color)); SetMainTransparency(gre->GetMainTransparency()); + SetMiniOutline(gre->GetMiniOutline()); } } @@ -124,7 +126,7 @@ void TEvePolygonSetProjected::UpdateProjection() if (fBuff == 0) return; - // drop polygons, and projected/reduced points + // drop polygons and projected/reduced points fPols.clear(); ProjectBuffer3D(); @@ -205,9 +207,8 @@ Float_t TEvePolygonSetProjected::AddPolygon(std::list<Int_t>& pp, vpPolygon_t& p if (pp.size() <= 2) return 0; - // dimension of bbox - Float_t bbox[] = { 1e6, -1e6, 1e6, -1e6, 1e6, -1e6 }; - for (std::list<Int_t>::iterator u = pp.begin(); u!= pp.end(); ++u) + Float_t bbox[4] = { 1e6, -1e6, 1e6, -1e6 }; + for (std::list<Int_t>::iterator u = pp.begin(); u != pp.end(); ++u) { Int_t idx = *u; if (fPnts[idx].fX < bbox[0]) bbox[0] = fPnts[idx].fX; @@ -219,37 +220,58 @@ Float_t TEvePolygonSetProjected::AddPolygon(std::list<Int_t>& pp, vpPolygon_t& p Float_t eps = 2*TEveProjection::fgEps; if ((bbox[1]-bbox[0]) < eps || (bbox[3]-bbox[2]) < eps) return 0; - // duplication + // Duplication for (vpPolygon_i poi = pols.begin(); poi != pols.end(); ++poi) { Polygon_t& refP = *poi; - if ((Int_t)pp.size() != refP.fNPnts) - continue; - std::list<Int_t>::iterator u = pp.begin(); - Int_t pidx = refP.FindPoint(*u); - if (pidx < 0) + + if ((Int_t) pp.size() != refP.fNPnts) continue; - while (u != pp.end()) + + Int_t start_idx = refP.FindPoint(pp.front()); + if (start_idx < 0) + continue; + if (++start_idx >= refP.fNPnts) start_idx = 0; + + // Same orientation duplicate { - if ((*u) != refP.fPnts[pidx]) - break; - ++u; - if (++pidx >= refP.fNPnts) pidx = 0; + std::list<Int_t>::iterator u = ++pp.begin(); + Int_t pidx = start_idx; + while (u != pp.end()) + { + if ((*u) != refP.fPnts[pidx]) + break; + ++u; + if (++pidx >= refP.fNPnts) pidx = 0; + } + if (u == pp.end()) return 0; + } + // Inverse orientation duplicate + { + std::list<Int_t>::iterator u = --pp.end(); + Int_t pidx = start_idx; + while (u != pp.begin()) + { + if ((*u) != refP.fPnts[pidx]) + break; + --u; + if (++pidx >= refP.fNPnts) pidx = 0; + } + if (u == pp.begin()) return 0; } - if (u == pp.end()) return 0; } - Int_t* pv = new Int_t[pp.size()]; - Int_t count=0; - for (std::list<Int_t>::iterator u = pp.begin(); u != pp.end(); u++) + Int_t *pv = new Int_t[pp.size()]; + Int_t count = 0; + for (std::list<Int_t>::iterator u = pp.begin(); u != pp.end(); ++u) { pv[count] = *u; - count++; + ++count; } pols.push_back(Polygon_t()); - pols.back().fNPnts = pp.size(); - pols.back().fPnts = &pv[0]; + pols.back().fNPnts = pp.size(); + pols.back().fPnts = &pv[0]; return (bbox[1]-bbox[0]) * (bbox[3]-bbox[2]); } @@ -260,17 +282,17 @@ Float_t TEvePolygonSetProjected::MakePolygonsFromBP(Int_t* idxMap) // Build polygons from list of buffer polygons. TEveProjection* projection = fManager->GetProjection(); - Int_t* bpols = fBuff->fPols; - Float_t surf =0; // surface of projected polygons - for (UInt_t pi = 0; pi< fBuff->NbPols(); pi++) + Int_t *bpols = fBuff->fPols; + Float_t surf = 0; // surface of projected polygons + for (UInt_t pi = 0; pi < fBuff->NbPols(); ++pi) { std::list<Int_t> pp; // points in current polygon - UInt_t segN = bpols[1]; - Int_t* seg = &bpols[2]; + UInt_t segN = bpols[1]; + Int_t *seg = &bpols[2]; // start idx in the fist segment depends of second segment - Int_t tail, head; - Bool_t h = IsFirstIdxHead(seg[0], seg[1]); - if (h) { + Int_t tail, head; + if (IsFirstIdxHead(seg[0], seg[1])) + { head = idxMap[fBuff->fSegs[3*seg[0] + 1]]; tail = idxMap[fBuff->fSegs[3*seg[0] + 2]]; } @@ -285,24 +307,23 @@ Float_t TEvePolygonSetProjected::MakePolygonsFromBP(Int_t* idxMap) for (UInt_t s = 1; s < segN; ++s) segs.push_back(Seg_t(fBuff->fSegs[3*seg[s] + 1],fBuff->fSegs[3*seg[s] + 2])); - Bool_t accepted = kFALSE; for (LSegIt_t it = segs.begin(); it != segs.end(); ++it) { Int_t mv1 = idxMap[(*it).fV1]; Int_t mv2 = idxMap[(*it).fV2]; - accepted = projection->AcceptSegment(fPnts[mv1], fPnts[mv2], TEveProjection::fgEps); - if (accepted == kFALSE) + if ( ! projection->AcceptSegment(fPnts[mv1], fPnts[mv2], TEveProjection::fgEps)) { pp.clear(); break; } if (tail != pp.back()) pp.push_back(tail); - tail = (mv1 == tail) ? mv2 :mv1; + tail = (mv1 == tail) ? mv2 : mv1; } - // DirectDraw() implementation: last and first vertices should not be equal - if (pp.empty() == kFALSE) + + if ( ! pp.empty()) { + // DirectDraw() implementation: last and first vertices should not be equal if (pp.front() == pp.back()) pp.pop_front(); surf += AddPolygon(pp, fPolsBP); } diff --git a/graf3d/eve/src/TEvePolygonSetProjectedGL.cxx b/graf3d/eve/src/TEvePolygonSetProjectedGL.cxx index bb4b39401404ee54cc2b77b3a073f549de1b02a7..a2eb3e9cf5aedc299bc3f29489dc04e24f2e23b7 100644 --- a/graf3d/eve/src/TEvePolygonSetProjectedGL.cxx +++ b/graf3d/eve/src/TEvePolygonSetProjectedGL.cxx @@ -34,7 +34,7 @@ TEvePolygonSetProjectedGL::TEvePolygonSetProjectedGL() : TGLObject() { // Constructor - // fDLCache = false; // Disable DL. + // fDLCache = kFALSE; // Disable DL. fMultiColor = kTRUE; // Potentially false, reset in DirectDraw(). } @@ -45,7 +45,8 @@ Bool_t TEvePolygonSetProjectedGL::SetModel(TObject* obj, const Option_t* /*opt*/ { // Set model object. - return SetModelCheckClass(obj, TEvePolygonSetProjected::Class()); + fM = SetModelDynCast<TEvePolygonSetProjected>(obj); + return kTRUE; } //______________________________________________________________________________ @@ -53,7 +54,7 @@ void TEvePolygonSetProjectedGL::SetBBox() { // Setup bounding-box information. - SetAxisAlignedBBox(((TEvePolygonSetProjected*)fExternalObj)->AssertBBox()); + SetAxisAlignedBBox(fM->AssertBBox()); } /******************************************************************************/ @@ -75,21 +76,46 @@ void TEvePolygonSetProjectedGL::DrawOutline() const { // Draw polygons outline. - TEvePolygonSetProjected& refPS = * (TEvePolygonSetProjected*) fExternalObj; - if (refPS.fPols.size() == 0) return; + if (fM->fPols.size() == 0) return; - Int_t vi; - for (TEvePolygonSetProjected::vpPolygon_ci i = refPS.fPols.begin(); - i != refPS.fPols.end(); ++i) + if (fM->GetMiniOutline()) { - glBegin(GL_LINE_LOOP); - for(Int_t k = 0; k < (*i).fNPnts; ++k) + std::map<Edge_t, Int_t> edges; + + for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin(); + i != fM->fPols.end(); ++i) { - vi = (*i).fPnts[k]; - glVertex3fv(refPS.fPnts[vi].Arr()); + for(Int_t k = 0; k < i->fNPnts - 1; ++k) + { + ++edges[Edge_t(i->fPnts[k], i->fPnts[k+1])]; + } + ++edges[Edge_t(i->fPnts[0], i->fPnts[i->fNPnts - 1])]; + } + + glBegin(GL_LINES); + for (std::map<Edge_t, Int_t>::iterator i = edges.begin(); i != edges.end(); ++i) + { + if (i->second == 1) + { + glVertex3fv(fM->fPnts[i->first.fI].Arr()); + glVertex3fv(fM->fPnts[i->first.fJ].Arr()); + } } glEnd(); } + else + { + for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin(); + i != fM->fPols.end(); ++i) + { + glBegin(GL_LINE_LOOP); + for(Int_t k = 0; k < i->fNPnts; ++k) + { + glVertex3fv(fM->fPnts[i->fPnts[k]].Arr()); + } + glEnd(); + } + } } //______________________________________________________________________________ @@ -97,8 +123,7 @@ void TEvePolygonSetProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const { // Do GL rendering. - TEvePolygonSetProjected& refPS = * (TEvePolygonSetProjected*) fExternalObj; - if (refPS.fPols.size() == 0) return; + if (fM->fPols.size() == 0) return; glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT | GL_POLYGON_BIT); @@ -108,16 +133,16 @@ void TEvePolygonSetProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glDisable(GL_CULL_FACE); - fMultiColor = (refPS.fDrawFrame && refPS.fFillColor != refPS.fLineColor); + fMultiColor = (fM->fDrawFrame && fM->fFillColor != fM->fLineColor); // polygons glEnable(GL_POLYGON_OFFSET_FILL); glPolygonOffset(1.0f,1.0f); GLUtesselator *tessObj = TGLUtil::GetDrawTesselator3fv(); - TEveVector* pnts = refPS.fPnts; - for (TEvePolygonSetProjected::vpPolygon_ci i = refPS.fPols.begin(); - i != refPS.fPols.end(); ++i) + TEveVector* pnts = fM->fPnts; + for (TEvePolygonSetProjected::vpPolygon_ci i = fM->fPols.begin(); + i != fM->fPols.end(); ++i) { Int_t vi; //current vertex index of curent polygon Int_t pntsN = (*i).fNPnts; // number of points in current polygon @@ -151,11 +176,11 @@ void TEvePolygonSetProjectedGL::DirectDraw(TGLRnrCtx& /*rnrCtx*/) const glDisable(GL_POLYGON_OFFSET_FILL); // Outline - if (refPS.fDrawFrame) + if (fM->fDrawFrame) { - TGLUtil::Color(refPS.fLineColor); + TGLUtil::Color(fM->fLineColor); glEnable(GL_LINE_SMOOTH); - TGLUtil::LineWidth(refPS.fLineWidth); + TGLUtil::LineWidth(fM->fLineWidth); DrawOutline(); } @@ -170,9 +195,7 @@ void TEvePolygonSetProjectedGL::DrawHighlight(TGLRnrCtx& rnrCtx, const TGLPhysic // XXXX to support highlight AND selection ... if (lvl < 0) lvl = pshp->GetSelected(); - TEvePolygonSetProjected& refPS = * (TEvePolygonSetProjected*) fExternalObj; - - if (refPS.GetHighlightFrame()) + if (fM->GetHighlightFrame()) { glPushAttrib(GL_ENABLE_BIT | GL_LINE_BIT); glDisable(GL_LIGHTING); @@ -196,7 +219,7 @@ void TEvePolygonSetProjectedGL::DrawHighlight(TGLRnrCtx& rnrCtx, const TGLPhysic TGLUtil::UnlockColor(); rnrCtx.SetHighlightOutline(kFALSE); - TGLUtil::Color(refPS.fLineColor); + TGLUtil::Color(fM->fLineColor); for (int i = 0; i < 4; ++i) { glViewport(vp.X() + inner[i][0], vp.Y() + inner[i][1], vp.Width(), vp.Height());