From dfe819991d4899a963434233ccdecb79abd56dd5 Mon Sep 17 00:00:00 2001 From: Ulrich Kemloh <kemlohulrich@gmail.com> Date: Fri, 8 Aug 2014 15:24:07 +0200 Subject: [PATCH] cursor position is now displayed in the window title bar --- src/InteractorStyle.cpp | 40 +++++++++++++++++++++++++++++++------ src/InteractorStyle.h | 1 + src/ThreadVisualisation.cpp | 1 + src/TimerCallback.cpp | 4 ++-- 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/src/InteractorStyle.cpp b/src/InteractorStyle.cpp index 594e1cf..aacc6ef 100644 --- a/src/InteractorStyle.cpp +++ b/src/InteractorStyle.cpp @@ -42,6 +42,7 @@ #include "InteractorStyle.h" #include <iostream> +#include <QStringList> using namespace std; @@ -96,6 +97,36 @@ void InteractorStyle::Dolly() vtkInteractorStyleTrackballCamera::Dolly(); } +void InteractorStyle::OnMouseMove() +{ + vtkRenderWindowInteractor *rwi = this->Interactor; + vtkRenderWindow *renderWindow = rwi->GetRenderWindow(); + + int pos[2]={0,0}; + rwi->GetEventPosition(pos); + int pos_x=pos[0]; + int pos_y=pos[1]; + + VTK_CREATE(vtkCoordinate,coordinate); + coordinate->SetCoordinateSystemToDisplay(); + coordinate->SetValue(pos_x,pos_y,0); + double* world = coordinate->GetComputedWorldValue(renderWindow->GetRenderers()->GetFirstRenderer()); + //conversion in metre + world[0]/=100; world[1]/=100; world[2]/=100; + + QString winName=renderWindow->GetWindowName(); + QStringList query = winName.split(" -->") ; + + if(query.size()>1) + { + char tmp[50]; + sprintf(tmp,"--> [ %.2f x %.2f x %.2f ]",world[0],world[1],world[2]); + winName=query[0] +" -->"+QString(tmp); + renderWindow->SetWindowName(winName.toStdString().c_str()); + } + vtkInteractorStyleTrackballCamera::OnMouseMove(); +} + void InteractorStyle::OnChar() { @@ -290,13 +321,10 @@ void InteractorStyle::OnLeftButtonUp() vtkRenderWindowInteractor *rwi = this->Interactor; - int pos_x=0; - int pos_y=0; - //rwi->GetMousePosition(&pos_x, &pos_y); - int pos[2]; + int pos[2] = {0,0}; rwi->GetEventPosition(pos); - pos_x=pos[0]; - pos_y=pos[1]; + int pos_x=pos[0]; + int pos_y=pos[1]; VTK_CREATE(vtkCoordinate,coordinate); coordinate->SetCoordinateSystemToDisplay(); diff --git a/src/InteractorStyle.h b/src/InteractorStyle.h index 7171fb4..a780fad 100644 --- a/src/InteractorStyle.h +++ b/src/InteractorStyle.h @@ -59,6 +59,7 @@ public: virtual void Pan(); virtual void Dolly(); virtual void OnLeftButtonUp(); + virtual void OnMouseMove(); diff --git a/src/ThreadVisualisation.cpp b/src/ThreadVisualisation.cpp index 0843f3c..6a99522 100644 --- a/src/ThreadVisualisation.cpp +++ b/src/ThreadVisualisation.cpp @@ -351,6 +351,7 @@ void ThreadVisualisation::run() //style->SetKeyPressActivationValue('R'); //style->SetKeyPressActivation(true); + //renderWindow->SetCurrentCursor(VTK_CURSOR_CROSSHAIR); //save the top view camera _topViewCamera=vtkCamera::New(); diff --git a/src/TimerCallback.cpp b/src/TimerCallback.cpp index 9751623..1b9631b 100644 --- a/src/TimerCallback.cpp +++ b/src/TimerCallback.cpp @@ -206,10 +206,10 @@ void TimerCallback::Execute(vtkObject *caller, unsigned long eventId, winName.append(" [ "); s=QString::number(winSize[0]).toStdString(); winName.append(s); - winName.append("X"); + winName.append(" x "); s=QString::number(winSize[1]).toStdString(); winName.append(s); - winName.append(" ] "); + winName.append(" ] -->"); int posY=winSize[1]*(1.0-30.0/536.0); int posX=winSize[0]*(1.0-450.0/720.0); -- GitLab