diff --git a/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.cpp b/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.cpp index 5ba04bdc38..f3cabc67db 100644 --- a/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.cpp +++ b/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.cpp @@ -1,148 +1,157 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-01-14 14:20:26 +0100 (Thu, 14 Jan 2010) $ Version: $Revision: 21047 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkDisplayVectorInteractorScroll.h" #include "mitkOperation.h" #include "mitkDisplayCoordinateOperation.h" //#include "mitkDisplayPositionEvent.h" #include "mitkUndoController.h" #include "mitkStateEvent.h" #include "mitkInteractionConst.h" #include "mitkAction.h" void mitk::DisplayVectorInteractorScroll::ExecuteOperation(Operation* itkNotUsed( operation ) ) { } bool mitk::DisplayVectorInteractorScroll::ExecuteAction(Action* action, mitk::StateEvent const* stateEvent) { bool ok=false; const DisplayPositionEvent* posEvent=dynamic_cast(stateEvent->GetEvent()); if(posEvent==NULL) return false; int actionId = action->GetActionId(); switch(actionId) { case AcINITMOVE: { m_Sender=posEvent->GetSender(); m_StartDisplayCoordinate=posEvent->GetDisplayPosition(); m_LastDisplayCoordinate=posEvent->GetDisplayPosition(); m_CurrentDisplayCoordinate=posEvent->GetDisplayPosition(); ok = true; break; } case AcSCROLL: { mitk::SliceNavigationController::Pointer sliceNaviController = m_Sender->GetSliceNavigationController(); if(sliceNaviController) { int delta = m_LastDisplayCoordinate[1]-posEvent->GetDisplayPosition()[1]; // if we moved less than 'm_IndexToSliceModifier' pixels slice ONE slice only if ( delta>0 && delta-m_IndexToSliceModifier) { delta=-m_IndexToSliceModifier; } delta /= m_IndexToSliceModifier; - int newPos = sliceNaviController->GetSlice()->GetPos() - delta; + + if ( m_InvertScrollingDirection ) + delta *= -1; + + int newPos = sliceNaviController->GetSlice()->GetPos() + delta; // if auto repeat is on, start at first slice if you reach the last slice and vice versa int maxSlices = sliceNaviController->GetSlice()->GetSteps(); if ( m_AutoRepeat ) { while(newPos<0) { newPos += maxSlices; } while(newPos>=maxSlices) { newPos -= maxSlices; } } else { // if the new slice is below 0 we still show slice 0 // due to the stepper using unsigned int we have to do this ourselves if ( newPos < 1 ) newPos = 0; } // set the new position sliceNaviController->GetSlice()->SetPos( newPos ); } m_LastDisplayCoordinate=m_CurrentDisplayCoordinate; m_CurrentDisplayCoordinate=posEvent->GetDisplayPosition(); } case AcFINISHMOVE: { ok = true; break; } default: ok = false; break; } return ok; } void mitk::DisplayVectorInteractorScroll::SetIndexToSliceModifier( int modifier ) { m_IndexToSliceModifier = modifier; } void mitk::DisplayVectorInteractorScroll::SetAutoRepeat( bool autoRepeat ) { m_AutoRepeat = autoRepeat; } mitk::DisplayVectorInteractorScroll::DisplayVectorInteractorScroll(const char * type, mitk::OperationActor* destination) : mitk::StateMachine(type) , m_Sender(NULL) , m_Destination(destination) , m_IndexToSliceModifier(4) , m_AutoRepeat( false ) + , m_InvertScrollingDirection( false ) { m_StartDisplayCoordinate.Fill(0); m_LastDisplayCoordinate.Fill(0); m_CurrentDisplayCoordinate.Fill(0); m_UndoEnabled = false; //if(m_Destination==NULL) // m_Destination=this; } mitk::DisplayVectorInteractorScroll::~DisplayVectorInteractorScroll() { if ( m_Destination != this ) delete m_Destination; } +void mitk::DisplayVectorInteractorScroll::SetInvertScrollingDirection( bool invert ) +{ + m_InvertScrollingDirection = invert; +} diff --git a/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.h b/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.h index 2e40770190..fc03b2243a 100644 --- a/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.h +++ b/Core/Code/Interactions/mitkDisplayVectorInteractorScroll.h @@ -1,109 +1,114 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2009-05-28 17:19:30 +0200 (Thu, 28 May 2009) $ Version: $Revision: 17495 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKDISPLAYVECTORINTERACTORSCROLL_H_HEADER_INCLUDED_C10DC4EB #define MITKDISPLAYVECTORINTERACTORSCROLL_H_HEADER_INCLUDED_C10DC4EB #include "mitkCommon.h" #include "mitkBaseRenderer.h" #include "mitkStateMachine.h" namespace mitk { class Operation; class OperationActor; /** * @brief Interactor for scrolling through the slices of an image * * This class implements an Interactor for slice-scrolling. It is defined by the 'Scroll'-statemachine which maps 'initmove' to left mousebutton pressed, * 'scroll' to left mousebutton and move and 'finishmove' to left mousebutton released. * * Thus it is possible to scroll through the slices of an image rapidly, without using the mousewheel. * * @ingroup MITK_CORE_EXPORT **/ class MITK_CORE_EXPORT DisplayVectorInteractorScroll : public StateMachine { public: mitkClassMacro(DisplayVectorInteractorScroll, StateMachine); mitkNewMacro2Param(Self, const char*, OperationActor*); /** * @brief Method derived from OperationActor to recieve and execute operations **/ virtual void ExecuteOperation(Operation* operation); /** * \brief Defines how many slices are scrolled per pixel that the mouse cursor has moved */ void SetIndexToSliceModifier( int modifier ); void SetAutoRepeat( bool autoRepeat ); + void SetInvertScrollingDirection( bool ); + protected: /** * @brief Default Constructor **/ DisplayVectorInteractorScroll(const char * type, mitk::OperationActor* destination=NULL); /** * @brief Default Destructor **/ virtual ~DisplayVectorInteractorScroll(); /** * @brief Method derived from StateMachine to implement the own actions **/ virtual bool ExecuteAction(Action* action, mitk::StateEvent const* stateEvent); private: BaseRenderer::Pointer m_Sender; mitk::Point2D m_StartDisplayCoordinate; mitk::Point2D m_LastDisplayCoordinate; mitk::Point2D m_CurrentDisplayCoordinate; OperationActor* m_Destination; /** * \brief Modifier that defines how many slices are scrolled per pixel that the mouse has moved * * This modifier defines how many slices the scene is scrolled per pixel that the mouse cursor has moved. * By default the modifier is 4. This means that when the user moves the cursor by 4 pixels in Y-direction * the scene is scrolled by one slice. If the user has moved the the cursor by 20 pixels, the scene is * scrolled by 5 slices. * * If the cursor has moved less than m_IndexToSliceModifier pixels the scene is scrolled by one slice. */ int m_IndexToSliceModifier; /** * \brief Defines if it is possible to scroll endlessly * * If AutoRepeat is on, scrolling further than the last slice will restart at the first slice and vice versa */ bool m_AutoRepeat; + + bool m_InvertScrollingDirection; + }; } // namespace mitk #endif /* MITKDISPLAYVECTORINTERACTOR_H_HEADER_INCLUDED_C10DC4EB */ diff --git a/Core/Code/Rendering/mitkRenderWindowBase.cpp b/Core/Code/Rendering/mitkRenderWindowBase.cpp index eb49f375da..cc000d23c6 100644 --- a/Core/Code/Rendering/mitkRenderWindowBase.cpp +++ b/Core/Code/Rendering/mitkRenderWindowBase.cpp @@ -1,194 +1,205 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-07-05 09:49:37 +0200 (Mo, 05 Jul 2010) $ Version: $Revision: 24298 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "mitkRenderWindowBase.h" #include "mitkDisplayPositionEvent.h" #include "mitkVtkLayerController.h" #include "mitkRenderingManager.h" #include "vtkRenderer.h" -mitk::RenderWindowBase::RenderWindowBase( ) : m_ProcessWheelEvents(true) +mitk::RenderWindowBase::RenderWindowBase( ) +: m_ProcessWheelEvents(true), +m_InvertScrollingDirection(false) { } /* * "Member functions, including virtual functions (10.3), can be called during construction or destruction (12.6.2). When a * virtual function is called directly or indirectly from a constructor (including from the mem-initializer for a data member) or from * a destructor, and the object to which the call applies is the object under construction or destruction, the function called is * the one defined in the constructor or destructor’s own class or in one of its bases, but not a function overriding it in a class * derived from the constructor or destructor’s class, or overriding it in one of the other base classes of the most derived object[..]" * or short: within constructors and destructors classes are not polymorph. */ void mitk::RenderWindowBase::Initialize( mitk::RenderingManager* renderingManager, const char* name ) { if ( renderingManager == NULL ) { renderingManager = mitk::RenderingManager::GetInstance(); } if(m_Renderer.IsNull()) { m_Renderer = mitk::VtkPropRenderer::New( name , GetVtkRenderWindow(), renderingManager ); } m_Renderer->InitRenderer(this->GetVtkRenderWindow()); mitk::BaseRenderer::AddInstance(GetVtkRenderWindow(),m_Renderer); renderingManager->AddRenderWindow(GetVtkRenderWindow()); m_RenderProp = vtkMitkRenderProp::New(); m_RenderProp->SetPropRenderer(m_Renderer); m_Renderer->GetVtkRenderer()->AddViewProp(m_RenderProp); if((this->GetVtkRenderWindow()->GetSize()[0] > 10) && (this->GetVtkRenderWindow()->GetSize()[1] > 10)) m_Renderer->InitSize(this->GetVtkRenderWindow()->GetSize()[0], this->GetVtkRenderWindow()->GetSize()[1]); m_InResize = false; } void mitk::RenderWindowBase::Destroy() { m_Renderer->GetRenderingManager()->RemoveRenderWindow(GetVtkRenderWindow()); mitk::BaseRenderer::RemoveInstance(GetVtkRenderWindow()); m_Renderer->GetVtkRenderer()->RemoveViewProp(m_RenderProp); m_RenderProp->Delete(); } mitk::RenderWindowBase::~RenderWindowBase() { } void mitk::RenderWindowBase::mousePressMitkEvent(mitk::MouseEvent *me) { if (m_Renderer.IsNotNull()) m_Renderer->MousePressEvent(me); } void mitk::RenderWindowBase::mouseReleaseMitkEvent(mitk::MouseEvent *me) { if(m_Renderer.IsNotNull()) m_Renderer->MouseReleaseEvent(me); } void mitk::RenderWindowBase::mouseMoveMitkEvent(mitk::MouseEvent *me) { if (m_Renderer.IsNotNull()) m_Renderer->MouseMoveEvent(me); } void mitk::RenderWindowBase::wheelMitkEvent(mitk::WheelEvent *we) { if ( !m_ProcessWheelEvents ) return; if ( !GetSliceNavigationController()->GetSliceLocked() ) { mitk::Stepper* stepper = GetSliceNavigationController()->GetSlice(); if (stepper->GetSteps() <= 1) { stepper = GetSliceNavigationController()->GetTime(); } - //if (we->orientation() * we->GetDelta() > 0) - if (we->GetDelta() > 0) + // get the desired delta + int delta = we->GetDelta(); + if ( m_InvertScrollingDirection ) + delta *= -1; // If we want to invert the scrolling direction -> delta * -1 + + if ( delta < 0 ) { stepper->Next(); } else { stepper->Previous(); } //also send to Renderer to send if to MITK interaction mechanism if(m_Renderer.IsNotNull()) m_Renderer->WheelEvent(we); } } void mitk::RenderWindowBase::keyPressMitkEvent(mitk::KeyEvent* mke) { if (m_Renderer.IsNotNull()) m_Renderer->KeyPressEvent(mke); } void mitk::RenderWindowBase::resizeMitkEvent(int width, int height) { if(m_InResize) //@FIXME CRITICAL probably related to VtkSizeBug return; m_InResize = true; if(m_Renderer.IsNotNull()) { m_Renderer->Resize(width, height); } m_InResize = false; } mitk::SliceNavigationController * mitk::RenderWindowBase::GetSliceNavigationController() { return mitk::BaseRenderer::GetInstance(this->GetVtkRenderWindow())->GetSliceNavigationController(); } mitk::CameraRotationController * mitk::RenderWindowBase::GetCameraRotationController() { return mitk::BaseRenderer::GetInstance(this->GetVtkRenderWindow())->GetCameraRotationController(); } mitk::BaseController * mitk::RenderWindowBase::GetController() { mitk::BaseRenderer * renderer = mitk::BaseRenderer::GetInstance(GetVtkRenderWindow()); switch ( renderer->GetMapperID() ) { case mitk::BaseRenderer::Standard2D: return GetSliceNavigationController(); case mitk::BaseRenderer::Standard3D: return GetCameraRotationController(); default: return GetSliceNavigationController(); } } mitk::VtkPropRenderer* mitk::RenderWindowBase::GetRenderer() { return m_Renderer; } void mitk::RenderWindowBase::SetProcessWheelEvents( bool state ) { m_ProcessWheelEvents = state; } bool mitk::RenderWindowBase::GetProcessWheelEvents() { return m_ProcessWheelEvents; } + +void mitk::RenderWindowBase::SetInvertScrollingDirection( bool invert ) +{ + m_InvertScrollingDirection = invert; +} \ No newline at end of file diff --git a/Core/Code/Rendering/mitkRenderWindowBase.h b/Core/Code/Rendering/mitkRenderWindowBase.h index dbb32b20c5..6773d0fd65 100644 --- a/Core/Code/Rendering/mitkRenderWindowBase.h +++ b/Core/Code/Rendering/mitkRenderWindowBase.h @@ -1,97 +1,101 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date: 2010-06-30 15:12:34 +0200 (Mi, 30. Jun 2010) $ Version: $Revision: 24176 $ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef MITKRENDERWINDOWBASE_H_HEADER_INCLUDED_C1C40D66ASDF #define MITKRENDERWINDOWBASE_H_HEADER_INCLUDED_C1C40D66ASDF #include "mitkCommon.h" #include "mitkVtkPropRenderer.h" #include "vtkMitkRenderProp.h" #include "mitkSliceNavigationController.h" #include "mitkCameraRotationController.h" namespace mitk { /** * \brief Base class of MITK RenderWindows * * This class sets up the MITK rendering mechanism and it's integration into VTK. * * Currently, there are two specific implementations of this abstract class: * QmitkRenderWindow, inerhits from the QVTKWidget and is the matured way for MITK rendering * mitkRenderWindow is a new, QT-independent RenderWindow implementation * * \ingroup Renderer */ class MITK_CORE_EXPORT RenderWindowBase { public: //mitkClassMacro(RenderWindowBase,itk::Object); //itkNewMacro(Self); virtual ~RenderWindowBase(); void InitRenderer(); virtual mitk::SliceNavigationController * GetSliceNavigationController(); virtual mitk::CameraRotationController * GetCameraRotationController(); virtual mitk::BaseController * GetController(); virtual mitk::VtkPropRenderer* GetRenderer(); virtual vtkRenderWindow* GetVtkRenderWindow() = 0; virtual vtkRenderWindowInteractor* GetVtkRenderWindowInteractor() = 0; void SetProcessWheelEvents( bool state ); bool GetProcessWheelEvents(); + void SetInvertScrollingDirection( bool ); + virtual void mousePressMitkEvent(mitk::MouseEvent *me); virtual void mouseReleaseMitkEvent(mitk::MouseEvent *me); virtual void mouseMoveMitkEvent(mitk::MouseEvent *me); virtual void wheelMitkEvent(mitk::WheelEvent *we); virtual void keyPressMitkEvent(mitk::KeyEvent* mke); virtual void resizeMitkEvent(int width, int height); protected: RenderWindowBase(); // helper functions: within constructors and destructors classes are not polymorph. void Initialize( mitk::RenderingManager* renderingManager = NULL, const char* name = "unnamed renderer" ); void Destroy(); mitk::VtkPropRenderer::Pointer m_Renderer; vtkMitkRenderProp* m_RenderProp; bool m_InResize; bool m_ProcessWheelEvents; + bool m_InvertScrollingDirection; + private: }; } #endif /* MITKRENDERWINDOWBASE_H_HEADER_INCLUDED_C1C40D66ASDF */