Skip to content

Commit

Permalink
Merge pull request #11215 from alja/clipcamera
Browse files Browse the repository at this point in the history
74x Fireworks: Adjust camera position when open 3D region
  • Loading branch information
cmsbuild committed Sep 18, 2015
2 parents c5fe44a + 98933a2 commit 5f32591
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 55 deletions.
4 changes: 2 additions & 2 deletions Fireworks/Core/interface/FW3DViewBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 );
Expand Down
2 changes: 1 addition & 1 deletion Fireworks/Core/interface/FWGUIManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ class FWGUIManager : public FWConfigurable
sigc::connection m_modelChangeConn;

std::auto_ptr<CmsShowTaskExecutor> m_tasks;

std::vector<FWViewBase*> m_regionViews;
int m_WMOffsetX, m_WMOffsetY, m_WMDecorH;
};

Expand Down
150 changes: 101 additions & 49 deletions Fireworks/Core/src/FW3DViewBase.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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<float> res;
for (TGLPlaneSet_i i = ps.begin(); i!= ps.end(); ++i)
{
std::pair<Bool_t, TGLVertex3> 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);
Expand All @@ -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();

}

//______________________________________________________________________________
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 16 additions & 3 deletions Fireworks/Core/src/FWGUIManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down Expand Up @@ -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;
Expand All @@ -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<FW3DViewBase*>(it->second);
v->setClip(eta, phi);
v->setClip(theta, phi);
it->first->UndockWindow();
m_regionViews.push_back(v);
}
catch(const reco::parser::BaseException& e)
{
Expand Down

0 comments on commit 5f32591

Please sign in to comment.