From 4baa702964de2db46d99093b8986761b5a96f946 Mon Sep 17 00:00:00 2001 From: Rene Brun <Rene.Brun@cern.ch> Date: Fri, 17 Sep 2004 19:33:31 +0000 Subject: [PATCH] From Timur Several improvements git-svn-id: http://root.cern.ch/svn/root/trunk@10090 27541ba8-7e3a-0410-8455-c3a389f83636 --- gl/inc/TArcBall.h | 41 ++++++++++++- gl/inc/TViewerOpenGL.h | 8 +-- gl/src/TArcBall.cxx | 123 ++++++++++++++++++++++++++++++++++++++- gl/src/TViewerOpenGL.cxx | 31 ++++++---- 4 files changed, 185 insertions(+), 18 deletions(-) diff --git a/gl/inc/TArcBall.h b/gl/inc/TArcBall.h index 42a7991b14d..bbb91b98716 100644 --- a/gl/inc/TArcBall.h +++ b/gl/inc/TArcBall.h @@ -1,4 +1,4 @@ -// @(#)root/gl:$Name: $:$Id: TArcBall.h,v 1.4 2004/09/03 12:52:42 brun Exp $ +// @(#)root/gl:$Name: $:$Id: TArcBall.h,v 1.5 2004/09/14 15:37:34 rdm Exp $ // Author: Timur Pocheptsov 03/08/2004 /************************************************************************* @@ -51,5 +51,44 @@ public: } }; +class TEqRow { +private: + Double_t fData[4]; +public: + TEqRow(); + TEqRow(const Double_t *source); + + void SetRow(const Double_t *source); + + Double_t &operator [] (UInt_t ind) + { + return fData[ind]; + } + Double_t operator [] (UInt_t ind)const + { + return fData[ind]; + } + + TEqRow &operator *= (Double_t x); + TEqRow &operator /= (Double_t x); + TEqRow &operator += (const TEqRow &row); +}; + +TEqRow operator * (const TEqRow &row, Double_t x); +TEqRow operator * (Double_t x, const TEqRow &row); +TEqRow operator / (const TEqRow &row, Double_t x); +TEqRow operator + (const TEqRow &row1, const TEqRow &row2); + +class TToySolver { +private: + TEqRow fMatrix[3]; + Int_t fBase[3]; +public: + TToySolver(const Double_t *source); + void GetSolution(Double_t *sink); +private: + void AddNewBV(UInt_t i, UInt_t j); +}; + #endif diff --git a/gl/inc/TViewerOpenGL.h b/gl/inc/TViewerOpenGL.h index 08c8cc44aaf..bfba7fbaad3 100644 --- a/gl/inc/TViewerOpenGL.h +++ b/gl/inc/TViewerOpenGL.h @@ -1,4 +1,4 @@ -// @(#)root/gl:$Name: $:$Id: TViewerOpenGL.h,v 1.11 2004/09/14 15:37:34 rdm Exp $ +// @(#)root/gl:$Name: $:$Id: TViewerOpenGL.h,v 1.12 2004/09/15 14:26:58 brun Exp $ // Author: Timur Pocheptsov 03/08/2004 /************************************************************************* @@ -31,6 +31,7 @@ #endif class TGLRenderArea; +class TContextMenu; class TGLSelection; class TGVSplitter; class TGPopupMenu; @@ -80,14 +81,13 @@ private: enum EMode{kNav, kPick}; enum EViews{kXOY, kXOZ, kYOZ, kPERSP}; - enum EActivePlane{kAPXOY, kAPXOZ, kAPYOZ}; EViews fConf; EMode fMode; - EActivePlane fActivePlane; + TContextMenu *fContextMenu; TGLSceneObject *fSelectedObj; - Color_t fRGBA[4]; + Color_t fRGBA[4]; public: TViewerOpenGL(TVirtualPad * pad); diff --git a/gl/src/TArcBall.cxx b/gl/src/TArcBall.cxx index 118f6341b3b..85b051e3ed0 100644 --- a/gl/src/TArcBall.cxx +++ b/gl/src/TArcBall.cxx @@ -1,4 +1,4 @@ -// @(#)root/gl:$Name: $:$Id: TArcBall.cxx,v 1.3 2004/08/10 14:11:40 brun Exp $ +// @(#)root/gl:$Name: $:$Id: TArcBall.cxx,v 1.4 2004/09/03 12:52:42 brun Exp $ // Author: Timur Pocheptsov 03/08/2004 /************************************************************************* @@ -263,3 +263,124 @@ void TArcBall::ResetMatrices() Matrix3dSetIdentity(fLastRot); Matrix3dSetIdentity(fThisRot); } + +//______________________________________________________________________________ +TEqRow::TEqRow() + :fData() +{ +} + +//______________________________________________________________________________ +TEqRow::TEqRow(const Double_t *source) +{ + fData[0] = source[0]; + fData[1] = source[1]; + fData[2] = source[2]; + fData[3] = source[3]; +} + +//______________________________________________________________________________ +void TEqRow::SetRow(const Double_t *source) +{ + fData[0] = source[0]; + fData[1] = source[1]; + fData[2] = source[2]; + fData[3] = source[3]; +} + +//______________________________________________________________________________ +TEqRow &TEqRow::operator *= (Double_t x) +{ + fData[0] *= x; + fData[1] *= x; + fData[2] *= x; + fData[3] *= x; + + return *this; +} + +//______________________________________________________________________________ +TEqRow &TEqRow::operator /= (Double_t x) +{ + fData[0] /= x; + fData[1] /= x; + fData[2] /= x; + fData[3] /= x; + + return *this; +} + +//______________________________________________________________________________ +TEqRow &TEqRow::operator += (const TEqRow &row) +{ + fData[0] += row.fData[0]; + fData[1] += row.fData[1]; + fData[2] += row.fData[2]; + fData[3] += row.fData[3]; + + return *this; +} + +//______________________________________________________________________________ +TEqRow operator * (const TEqRow &row, Double_t x) +{ + return TEqRow(row) *= x; +} + +//______________________________________________________________________________ +TEqRow operator * (Double_t x, const TEqRow &row) +{ + return TEqRow(row) *= x; +} + +//______________________________________________________________________________ +TEqRow operator / (const TEqRow &row, Double_t x) +{ + return TEqRow(row) /= x; +} + +//______________________________________________________________________________ +TEqRow operator + (const TEqRow &r1, const TEqRow &r2) +{ + return TEqRow(r1)+=r2; +} + +//______________________________________________________________________________ +TToySolver::TToySolver(const Double_t *source) +{ + fMatrix[0].SetRow(source); + fMatrix[1].SetRow(source + 4); + fMatrix[2].SetRow(source + 8); + fBase[0] = fBase[1] = fBase[2] = -1; +} + +//______________________________________________________________________________ +void TToySolver::GetSolution(Double_t *sink) +{ + for (UInt_t i = 0; i < 3; ++i) { + for (UInt_t j = 0; j < 3; ++j) { + if (fMatrix[i][j] != 0.) AddNewBV(i, j); + } + } + + //j for vc 6.0 :)) + for (UInt_t j = 0; j < 3; ++j) { + if (fBase[j] >= 0)sink[fBase[j]] = fMatrix[j][3]; + } +} + +//______________________________________________________________________________ +void TToySolver::AddNewBV(UInt_t row, UInt_t col) +{ + Double_t tmp1 = fMatrix[row][col]; + fMatrix[row] /= tmp1; + + for (UInt_t i = 0; i < 3; ++i) { + if (i != row) { + Double_t tmp2 = fMatrix[i][col]; + fMatrix[i] += -tmp2 * fMatrix[row]; + } + } + + fBase[row] = col; +} diff --git a/gl/src/TViewerOpenGL.cxx b/gl/src/TViewerOpenGL.cxx index f13527203cf..cffcf5101f9 100644 --- a/gl/src/TViewerOpenGL.cxx +++ b/gl/src/TViewerOpenGL.cxx @@ -1,4 +1,4 @@ -// @(#)root/gl:$Name: $:$Id: TViewerOpenGL.cxx,v 1.21 2004/09/15 14:26:58 brun Exp $ +// @(#)root/gl:$Name: $:$Id: TViewerOpenGL.cxx,v 1.22 2004/09/17 08:33:33 rdm Exp $ // Author: Timur Pocheptsov 03/08/2004 /************************************************************************* @@ -104,7 +104,7 @@ TViewerOpenGL::TViewerOpenGL(TVirtualPad * vp) fNbShapes = 0; fConf = kPERSP; fMode = kNav; - fActivePlane = kAPXOY; + fContextMenu = 0; fSelectedObj = 0; static struct Init { @@ -229,6 +229,7 @@ TViewerOpenGL::~TViewerOpenGL() delete fL2; delete fL3; delete fL4; + delete fContextMenu; } //______________________________________________________________________________ @@ -285,6 +286,8 @@ Bool_t TViewerOpenGL::HandleContainerButton(Event_t *event) if ((fSelectedObj = TestSelection(event))) { fSelectedObj->GetColor(fRGBA[0], fRGBA[1], fRGBA[2], fRGBA[3]); fEditor->SetRGBA(fRGBA[0], fRGBA[1], fRGBA[2], fRGBA[3]); + if (!fContextMenu) fContextMenu = new TContextMenu("glcm", "glcm"); + fContextMenu->Popup(event->fXRoot, event->fYRoot, fSelectedObj->GetRealObject()); } else { fEditor->GetButton()->SetState(kButtonDisabled); fEditor->Stop(); @@ -297,6 +300,9 @@ Bool_t TViewerOpenGL::HandleContainerButton(Event_t *event) gVirtualGL->EndMovement(&fRender); DrawObjects(); } + } else if(event->fCode == kButton3) { +// delete fContextMenu; +// fContextMenu = 0; } } @@ -367,11 +373,10 @@ Bool_t TViewerOpenGL::HandleContainerMotion(Event_t *event) TGLWindow *glWin = fCanvasContainer->GetGLWindow(); Double_t xshift = (event->fX - fLastPos.fX) / Double_t(glWin->GetWidth()); Double_t yshift = (event->fY - fLastPos.fY) / Double_t(glWin->GetHeight()); + xshift *= fViewVolume[0] * 1.9 * fZoom[fConf]; + yshift *= fViewVolume[1] * 1.9 * fZoom[fConf]; if (fConf != kPERSP) { - xshift *= fViewVolume[0] * 1.9 * fZoom[fConf]; - yshift *= fViewVolume[1] * 1.9 * fZoom[fConf]; - MakeCurrent(); switch (fConf) { case kXOY: @@ -387,6 +392,15 @@ Bool_t TViewerOpenGL::HandleContainerMotion(Event_t *event) break; } } else { + const Double_t *rotM = fArcBall->GetRotMatrix(); + Double_t matrix[3][4] = {{rotM[0], -rotM[8], rotM[4], xshift}, + {rotM[1], -rotM[9], rotM[5], -yshift}, + {rotM[2], -rotM[10], rotM[6], 0.}}; + + TToySolver tr(*matrix); + Double_t shift[3] = {0.}; + tr.GetSolution(shift); + gVirtualGL->MoveSelected(&fRender, shift[0], shift[1], shift[2]); } DrawObjects(); @@ -594,11 +608,6 @@ Bool_t TViewerOpenGL::ProcessMessage(Long_t msg, Long_t parm1, Long_t) break; case kGLPickMode: fMode = kPick; - if (fConf == kPERSP) { - fConf = kXOY; - fRender.SetActive(fConf); - DrawObjects(); - } break; case kGLXOY: @@ -631,8 +640,6 @@ Bool_t TViewerOpenGL::ProcessMessage(Long_t msg, Long_t parm1, Long_t) fConf = kPERSP; fRender.SetActive(fConf); DrawObjects(); - if(fMode != kNav) - fMode = kNav; } break; case kGLExit: -- GitLab