diff --git a/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.cpp b/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.cpp index d8b9523905..43df2b0fcb 100644 --- a/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.cpp +++ b/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.cpp @@ -1,131 +1,161 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #include "mitkDisplayVectorInteractorLevelWindow.h" #include "mitkOperation.h" #include "mitkDisplayCoordinateOperation.h" #include "mitkStateEvent.h" #include "mitkInteractionConst.h" #include "mitkAction.h" #include "mitkStandaloneDataStorage.h" #include "mitkNodePredicateDataType.h" #include "mitkLevelWindowProperty.h" #include "mitkLevelWindow.h" void mitk::DisplayVectorInteractorLevelWindow::ExecuteOperation(Operation* itkNotUsed( operation ) ) { } bool mitk::DisplayVectorInteractorLevelWindow::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: // MITK_INFO << "AcINITMOVE"; { m_Sender=posEvent->GetSender(); m_StartDisplayCoordinate=posEvent->GetDisplayPosition(); m_LastDisplayCoordinate=posEvent->GetDisplayPosition(); m_CurrentDisplayCoordinate=posEvent->GetDisplayPosition(); ok = true; break; } case AcLEVELWINDOW: { m_LastDisplayCoordinate=m_CurrentDisplayCoordinate; m_CurrentDisplayCoordinate=posEvent->GetDisplayPosition(); mitk::DataStorage::Pointer storage = m_Sender->GetDataStorage(); mitk::DataNode::Pointer node = NULL; mitk::DataStorage::SetOfObjects::ConstPointer allImageNodes = storage->GetSubset(mitk::NodePredicateDataType::New( "Image") ); for ( unsigned int i = 0; i < allImageNodes->size() ; i++ ) { bool isActiveImage = false; bool propFound = allImageNodes->at( i )->GetBoolProperty( "imageForLevelWindow", isActiveImage ); if ( propFound && isActiveImage ) { node = allImageNodes->at( i ); continue; } } if ( node.IsNull() ) { node = storage->GetNode( mitk::NodePredicateDataType::New( "Image" ) ); } if ( node.IsNull() ) { return false; } - mitk::LevelWindow lv = mitk::LevelWindow(); node->GetLevelWindow(lv); ScalarType level = lv.GetLevel(); ScalarType window = lv.GetWindow(); - level += ( m_CurrentDisplayCoordinate[0] - m_LastDisplayCoordinate[0] )*static_cast(2); - window += ( m_CurrentDisplayCoordinate[1] - m_LastDisplayCoordinate[1] )*static_cast(2); + // determine which index shall be used for level and which one for window + int levelIndex = m_HorizontalLevelling ? 0 : 1; + int windowIndex = m_HorizontalLevelling ? 1 : 0; + + // determine if one these is supposed to be inverted + Point2D invertModifier; + invertModifier[levelIndex] = m_InvertLevel ? -1 : 1; + invertModifier[windowIndex] = m_InvertWindow ? -1 : 1; + + // difference of the two positions + // *2 to make interaction faster + // *inverModifier to handle inverted interactionscheme + level += ( m_CurrentDisplayCoordinate[levelIndex] - m_LastDisplayCoordinate[levelIndex] )* static_cast(2) * invertModifier[levelIndex]; + window += ( m_CurrentDisplayCoordinate[windowIndex] - m_LastDisplayCoordinate[windowIndex] )* static_cast(2) * invertModifier[windowIndex]; lv.SetLevelWindow( level, window ); dynamic_cast(node->GetProperty("levelwindow"))->SetLevelWindow( lv ); m_Sender->GetRenderingManager()->RequestUpdateAll(); ok = true; break; } case AcFINISHMOVE: // MITK_INFO << "AcFINISHMOVE"; { ok = true; break; } default: ok = false; break; } return ok; } mitk::DisplayVectorInteractorLevelWindow::DisplayVectorInteractorLevelWindow(const char * type) - : mitk::StateMachine(type), m_Sender(NULL) + : mitk::StateMachine(type) + , m_Sender(NULL) + , m_HorizontalLevelling( false ) + , m_InvertLevel( false ) + , m_InvertWindow( false ) { m_StartDisplayCoordinate.Fill(0); m_LastDisplayCoordinate.Fill(0); m_CurrentDisplayCoordinate.Fill(0); m_UndoEnabled = false; } mitk::DisplayVectorInteractorLevelWindow::~DisplayVectorInteractorLevelWindow() { } +void mitk::DisplayVectorInteractorLevelWindow::SetHorizontalLevelling( bool enabled ) +{ + m_HorizontalLevelling = enabled; +} + +void mitk::DisplayVectorInteractorLevelWindow::SetInvertLevel( bool inverted ) +{ + m_InvertLevel = inverted; +} + +void mitk::DisplayVectorInteractorLevelWindow::SetInvertWindow( bool inverted ) +{ + m_InvertWindow = inverted; +} + diff --git a/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.h b/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.h index 621c52e621..d97fbba894 100644 --- a/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.h +++ b/Core/Code/Interactions/mitkDisplayVectorInteractorLevelWindow.h @@ -1,92 +1,111 @@ /*=================================================================== The Medical Imaging Interaction Toolkit (MITK) Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See LICENSE.txt or http://www.mitk.org for details. ===================================================================*/ #ifndef MITKDisplayVectorInteractorLevelWindow_H_HEADER_INCLUDED_C10DC4EB #define MITKDisplayVectorInteractorLevelWindow_H_HEADER_INCLUDED_C10DC4EB #include #include "mitkBaseRenderer.h" #include "mitkStateMachine.h" namespace mitk { class Operation; class OperationActor; /** * @brief Interactor for adjusting both level- and window-values for an image * * This class implements an Interactor for adjusting the LevelWindow. It is defined by the 'LevelWindow'-statemachine which maps 'initmove' to right mousebutton pressed, * 'levelwindow' to right mousebutton and move and 'finishmove' to right mousebutton released. * * Using this tool, it is possible to increase the 'level'-value of the selected image * ( if no image has the 'selected'-property == true, the first image in the DataStorage is used ) * by moving the mouse right and decreasing the level by moving the mouse to the left. * * The 'window'-value and also be adjusted by moving the mouse-curser up (increase) and down (decrease). * * @ingroup MITK_CORE_EXPORT **/ class MITK_CORE_EXPORT DisplayVectorInteractorLevelWindow : public StateMachine { public: mitkClassMacro(DisplayVectorInteractorLevelWindow, StateMachine); mitkNewMacro1Param(Self, const char*); //static Pointer New(const char* type) //{ // Pointer smartPtr = new DisplayVectorInteractorLevelWindow ( type ); // smartPtr->UnRegister(); // return smartPtr; //} /** * @brief Method derived from OperationActor to recieve and execute operations **/ virtual void ExecuteOperation(Operation* operation); + /** + * \brief If set, horizontal movement modifies the level instead of the window. + */ + void SetHorizontalLevelling( bool enabled ); + + /** + * \brief If set, the interaction for modifying the level are inverted. + */ + void SetInvertLevel( bool inverted ); + + /** + * \brief If set, the interaction for modifying the window are inverted. + */ + void SetInvertWindow( bool inverted ); + protected: /** * @brief Default Constructor **/ DisplayVectorInteractorLevelWindow(const char * type); /** * @brief Default Destructor **/ virtual ~DisplayVectorInteractorLevelWindow(); /** * @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; + + bool m_HorizontalLevelling; + bool m_InvertLevel; + bool m_InvertWindow; }; } // namespace mitk #endif /* MITKDISPLAYVECTORINTERACTOR_H_HEADER_INCLUDED_C10DC4EB */