diff --git a/Fireworks/Core/interface/FW3DViewBase.h b/Fireworks/Core/interface/FW3DViewBase.h index 01279952fe6f5..706ffa3dcfc76 100644 --- a/Fireworks/Core/interface/FW3DViewBase.h +++ b/Fireworks/Core/interface/FW3DViewBase.h @@ -93,7 +93,7 @@ class FW3DViewBase : public FWEveView FWEnumParameter m_cameraType; FWBoolParameter m_clipEnable; - FWDoubleParameter m_clipEta; + FWDoubleParameter m_clipTheta; FWDoubleParameter m_clipPhi; FWDoubleParameter m_clipDelta1; FWDoubleParameter m_clipDelta2; @@ -105,7 +105,7 @@ class FW3DViewBase : public FWEveView void selectable( bool ); void enableSceneClip( bool ); - void updateClipPlanes(); + void updateClipPlanes(bool resetCamera); void rnrStyle(long); void showMuonBarrel( long ); diff --git a/Fireworks/Core/interface/FWGUIManager.h b/Fireworks/Core/interface/FWGUIManager.h index 33996acb14330..d9294a76237f1 100644 --- a/Fireworks/Core/interface/FWGUIManager.h +++ b/Fireworks/Core/interface/FWGUIManager.h @@ -282,7 +282,7 @@ class FWGUIManager : public FWConfigurable sigc::connection m_modelChangeConn; std::auto_ptr m_tasks; - + std::vector m_regionViews; int m_WMOffsetX, m_WMOffsetY, m_WMDecorH; }; diff --git a/Fireworks/Core/src/FW3DViewBase.cc b/Fireworks/Core/src/FW3DViewBase.cc index 204ee36c4ca70..232fd9d497c6d 100644 --- a/Fireworks/Core/src/FW3DViewBase.cc +++ b/Fireworks/Core/src/FW3DViewBase.cc @@ -110,7 +110,7 @@ FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId, un m_selectable(this, "Enable Tooltips", false), m_cameraType(this, "Camera Type", 0l, 0l, 5l), m_clipEnable(this, "Enable Clip", false), - m_clipEta(this, "Clip Eta", 0.0, -5.0, 5.0), + m_clipTheta(this, "Clip Theta", 0.0, -5.0, 5.0), m_clipPhi(this, "Clip Phi", 0.0, -2.0, 2.0), m_clipDelta1(this, "Clip Delta1", 0.2, 0.01, 2), m_clipDelta2(this, "Clip Delta2", 0.2, 0.01, 2), @@ -143,10 +143,10 @@ FW3DViewBase::FW3DViewBase(TEveWindowSlot* iParent, FWViewType::EType typeId, un m_cameraType.changed_.connect(boost::bind(&FW3DViewBase::setCameraType,this, _1)); m_clipEnable.changed_.connect(boost::bind(&FW3DViewBase::enableSceneClip,this, _1)); - m_clipEta.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this)); - m_clipPhi.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this)); - m_clipDelta1.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this)); - m_clipDelta2.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this)); + m_clipTheta.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false)); + m_clipPhi.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false)); + m_clipDelta1.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false)); + m_clipDelta2.changed_.connect(boost::bind(&FW3DViewBase::updateClipPlanes,this, false)); m_ecalBarrel = new TEveBoxSet("ecalBarrel"); @@ -238,37 +238,90 @@ FW3DViewBase::enableSceneClip( bool x) ((TEveScene*)(*it))->GetGLScene()->SetClip(x ? m_glClip : 0); } eventScene()->GetGLScene()->SetClip(x ? m_glClip : 0); - updateClipPlanes(); + updateClipPlanes(true); viewerGL()->RequestDraw(); } void -FW3DViewBase::setClip(float eta, float phi) +FW3DViewBase::setClip(float theta, float phi) { // called from popup menu via FWGUIManager - /* - m_showMuonBarrel.set(1); - m_showMuonEndcap.set(true); - m_showPixelBarrel.set(true); - m_showPixelEndcap.set(true); - m_showTrackerBarrel.set(true); - */ - m_clipEta.set(eta); - m_clipPhi.set(phi); + + // limit to 2 decimals, else TGNumber entry in the view controller shows only last 5 irrelevant digits + double base = 100.0; + int thetaInt = theta*base; + int phiInt = phi*base; + m_clipTheta.set(thetaInt/base); + m_clipPhi.set(phiInt/base); m_clipEnable.set(true); } +namespace { +float getBBoxLineLength(TEveScene* scene, TEveVector in) +{ + if (!scene->NumChildren()) return 0; + + scene->Repaint(); + scene->GetGLScene()->CalcBoundingBox(); + const TGLBoundingBox& bb = scene->GetGLScene()->BoundingBox(); + if (bb.IsEmpty()) return 0; + + TGLPlaneSet_t ps; bb.PlaneSet(ps); + TEveVector inn = in; inn.Normalize(); + inn *= 10000; + TGLLine3 line(TGLVertex3(), TGLVertex3(inn.fX, inn.fY, inn.fZ)); + std::vector res; + for (TGLPlaneSet_i i = ps.begin(); i!= ps.end(); ++i) + { + std::pair r = Intersection(*i, line, false); + if(r.first) { + TGLVector3 vr(r.second.X(), r.second.Y(), r.second.Z()); + res.push_back(vr.Mag()); + } + } + std::sort(res.begin(), res.end()); + return res.front(); +} + +void setBBoxClipped(TGLBoundingBox& bbox, TEveVector dir, TEveVector b0, TEveVector b1, float fac) +{ + dir *= fac; + b0 *= fac; + b1 *= fac; + + TEveVectorD bb[8]; + bb[0] += b0; bb[0] += b1; + bb[1] -= b0; bb[1] += b1; + bb[2] -= b0; bb[2] -= b1; + bb[3] += b0; bb[3] -= b1; + + for (int i = 4; i < 8; ++i) + bb[i] = dir; + + bb[0+4] += b0; bb[0+4] += b1; + bb[1+4] -= b0; bb[1+4] += b1; + bb[2+4] -= b0; bb[2+4] -= b1; + bb[3+4] += b0; bb[3+4] -= b1; + + TGLVertex3 bbv[8]; + for (int i = 0; i < 8; ++i) { + bbv[i].Set(bb[i].fX, bb[i].fY, bb[i].fZ); + } + bbox.Set(bbv); +} +} + void -FW3DViewBase::updateClipPlanes() +FW3DViewBase::updateClipPlanes(bool resetCamera) { // TEveScene* gs = (TEveScene*)gEve->GetScenes()->FindChild(TString("TopGeoNodeScene")); //printf("node scene %p\n", gs); if (m_clipEnable.value()) { - float eta = m_clipEta.value(); + float theta = m_clipTheta.value(); float phi = m_clipPhi.value(); using namespace TMath; - TEveVector in(Sin(eta)*Cos(phi), Sin(eta)*Sin(phi), Cos(eta)); + TEveVector in(Sin(theta)*Cos(phi), Sin(theta)*Sin(phi), Cos(theta)); // one side of cross section plane is paralel to XY plane TEveVector normXY(0., 1., 0); @@ -288,43 +341,42 @@ FW3DViewBase::updateClipPlanes() c[2] -= b0; c[2] -= b1; c[3] += b0; c[3] -= b1; for (int i = 0; i < 4; ++i) - c[i] += in; + c[i] += in; ((Clipsi*)m_glClip)->SetPlaneInfo(&c[0]); - /* - // debug - TEveStraightLineSet* ls = (TEveStraightLineSet*)eventScene()->FindChild(TString("Frust")); - if (!ls) { - ls = new TEveStraightLineSet("Frust"); - eventScene()->AddElement(ls); - ls->SetMainColor(kWhite); - } - in *= 500; - ls->AddLine(0, 0, 0, in.fX, in.fY, in.fZ); + if (resetCamera) { + TGLBoundingBox bbox; + float es = getBBoxLineLength(eventScene(), in); + float gs = getBBoxLineLength(geoScene(), in); + setBBoxClipped(bbox, in, b0, b1, TMath::Max(es, gs)); + + /* + TEvePointSet* bmarker = new TEvePointSet(8); + bmarker->Reset(4); + bmarker->SetName("bbox"); + bmarker->SetMarkerColor(kOrange); + bmarker->SetMarkerStyle(3); + bmarker->SetMarkerSize(0.2); + for (int i = 0; i < 8; ++i) + bmarker->SetPoint(i, bbox[i].X(), bbox[i].Y(), bbox[i].Z()); + eventScene()->AddElement(bmarker); */ - TEvePointSet* psi = (TEvePointSet*)eventScene()->FindChild(TString("marker")); - TEvePointSet* marker = (TEvePointSet*)(psi); - if (!marker) { - marker = new TEvePointSet(8); - marker->Reset(4); - marker->SetName("marker"); - marker->SetMarkerColor(kOrange); - marker->SetMarkerStyle(3); - marker->SetMarkerSize(0.2); + TGLCamera& cam = viewerGL()->CurrentCamera(); + cam.SetExternalCenter(true); + cam.SetCenterVec(bbox.Center().X(), bbox.Center().Y(), bbox.Center().Z()); + cam.Setup(bbox, true); } - for (int i = 0; i < 4; ++i) - marker->SetPoint(i, c[i].fX, c[i].fY, c[i].fZ); - eventScene()->AddElement(marker); - } - /* - else { - fwLog(fwlog::kError) << "Clipping is not enabled!\n"; - } - */ + else { + eventScene()->Repaint(); + } + } + + gEve->Redraw3D(); + } //______________________________________________________________________________ @@ -395,7 +447,7 @@ FW3DViewBase::populateController(ViewerParameterGUI& gui) const addParam(&m_selectable). separator(). addParam(&m_clipEnable). - addParam(&m_clipEta). + addParam(&m_clipTheta). addParam(&m_clipPhi). addParam(&m_clipDelta1). addParam(&m_clipDelta2); diff --git a/Fireworks/Core/src/FWGUIManager.cc b/Fireworks/Core/src/FWGUIManager.cc index 399416e6d2640..163d086fcfc86 100644 --- a/Fireworks/Core/src/FWGUIManager.cc +++ b/Fireworks/Core/src/FWGUIManager.cc @@ -341,6 +341,18 @@ FWGUIManager::eventChangedCallback() { ev->GetGLViewer()->DeleteOverlayAnnotations(); } + for (auto reg : m_regionViews) + { + for(ViewMap_i it = m_viewMap.begin(); it != m_viewMap.end(); ++it) + { + if (it->second == reg) { + m_viewMap.erase(it); + reg->destroy(); + break; + } + } + } + m_cmsShowMainFrame->loadEvent(*getCurrentEvent()); m_detailViewManager->newEventCallback(); } @@ -643,7 +655,7 @@ void FWGUIManager::open3DRegion() { FWModelId id = *(m_context->selectionManager()->selected().begin()); - float eta =0, phi = 0; + float theta =0, phi = 0; { edm::TypeWithDict type = edm::TypeWithDict((TClass*)id.item()->modelType()); using namespace boost::spirit::classic; @@ -652,14 +664,15 @@ FWGUIManager::open3DRegion() edm::ObjectWithDict o(type, (void*)id.item()->modelData(id.index())); try { parse("theta()", grammar.use_parser<1>() >> end_p, space_p).full; - eta = tmpPtr->value(o); + theta = tmpPtr->value(o); parse("phi()", grammar.use_parser<1>() >> end_p, space_p).full; phi = tmpPtr->value(o); ViewMap_i it = createView( "3D Tower", m_viewSecPack->NewSlot()); FW3DViewBase* v = static_cast(it->second); - v->setClip(eta, phi); + v->setClip(theta, phi); it->first->UndockWindow(); + m_regionViews.push_back(v); } catch(const reco::parser::BaseException& e) {