diff --git a/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.cpp b/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.cpp index 4f93fb17fb..021fa2db0c 100644 --- a/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.cpp +++ b/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.cpp @@ -1,364 +1,329 @@ /*=================================================================== 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 "mitkAffineDataInteractor3D.h" -#include "mitkDispatcher.h" -#include "mitkInteractionConst.h" // TODO: refactor file +#include "mitkInteractionConst.h" #include "mitkInteractionPositionEvent.h" -#include "mitkInternalEvent.h" -#include "mitkMouseMoveEvent.h" -#include "mitkRenderingManager.h" #include "mitkRotationOperation.h" #include "mitkSurface.h" -#include - #include -#include #include #include #include #include mitk::AffineDataInteractor3D::AffineDataInteractor3D() { m_OriginalGeometry = Geometry3D::New(); // Initialize vector arithmetic m_ObjectNormal[0] = 0.0; m_ObjectNormal[1] = 0.0; m_ObjectNormal[2] = 1.0; } mitk::AffineDataInteractor3D::~AffineDataInteractor3D() { } void mitk::AffineDataInteractor3D::ConnectActionsAndFunctions() { - // **Conditions** that can be used in the state machine, - // to ensure that certain conditions are met, before - // actually executing an action + // **Conditions** that can be used in the state machine, to ensure that certain conditions are met, before actually executing an action CONNECT_CONDITION("isOverObject", CheckOverObject); // **Function** in the statmachine patterns also referred to as **Actions** CONNECT_FUNCTION("selectObject",SelectObject); CONNECT_FUNCTION("deselectObject",DeselectObject); CONNECT_FUNCTION("initTranslate",InitTranslate); CONNECT_FUNCTION("initRotate",InitRotate); CONNECT_FUNCTION("translateObject",TranslateObject); CONNECT_FUNCTION("rotateObject",RotateObject); } void mitk::AffineDataInteractor3D::DataNodeChanged() { } bool mitk::AffineDataInteractor3D::CheckOverObject(const InteractionEvent* interactionEvent) { - ////Is only a copy of the old AffineInteractor3D. Not sure if is still needed. - ////Re-enable VTK interactor (may have been disabled previously) const InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; - m_CurrentPickedPoint = positionEvent->GetPositionInWorld(); - m_CurrentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); - - if(interactionEvent->GetSender()->PickObject( m_CurrentPickedDisplayPoint, m_CurrentPickedPoint ) == this->GetDataNode().GetPointer()) - { + Point3D currentPickedPoint; + if(interactionEvent->GetSender()->PickObject(positionEvent->GetPointerPositionOnScreen(), currentPickedPoint) == this->GetDataNode().GetPointer()) return true; - } + return false; } bool mitk::AffineDataInteractor3D::SelectObject(StateMachineAction*, InteractionEvent* interactionEvent) { DataNode::Pointer node = this->GetDataNode(); if (node.IsNull()) return false; - node->SetColor( 1.0, 0.0, 0.0 ); - //TODO: Only 3D reinit - RenderingManager::GetInstance()->RequestUpdateAll(); + node->SetColor(1.0, 0.0, 0.0); // Colorize surface / wireframe dependend on distance from picked point - //TODO Check the return value - this->ColorizeSurface( interactionEvent->GetSender(), 0.0 ); + this->ColorizeSurface(interactionEvent->GetSender(), 0.0); + + interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } bool mitk::AffineDataInteractor3D::DeselectObject(StateMachineAction*, InteractionEvent* interactionEvent) { DataNode::Pointer node = this->GetDataNode(); if (node.IsNull()) return false; node->SetColor( 1.0, 1.0, 1.0 ); - //TODO: Only 3D reinit - RenderingManager::GetInstance()->RequestUpdateAll(); // Colorize surface / wireframe as inactive - //TODO Check the return value - this->ColorizeSurface( interactionEvent->GetSender(), -1.0 ); + this->ColorizeSurface(interactionEvent->GetSender(), -1.0); + + interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } bool mitk::AffineDataInteractor3D::InitTranslate(StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; - m_CurrentPickedPoint = positionEvent->GetPositionInWorld(); - m_CurrentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); - - m_InitialPickedPoint = m_CurrentPickedPoint; - m_InitialPickedDisplayPoint = m_CurrentPickedDisplayPoint; + m_InitialPickedPoint = positionEvent->GetPositionInWorld(); + m_InitialPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); // Get the timestep to also support 3D+t int timeStep = 0; if ((interactionEvent->GetSender()) != NULL) timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData()); // Make deep copy of current Geometry3D of the plane this->GetDataNode()->GetData()->UpdateOutputInformation(); // make sure that the Geometry is up-to-date - m_OriginalGeometry = static_cast< Geometry3D * >(this->GetDataNode()->GetData()->GetGeometry( timeStep )->Clone().GetPointer() ); + m_OriginalGeometry = static_cast(this->GetDataNode()->GetData()->GetGeometry(timeStep)->Clone().GetPointer()); return true; } bool mitk::AffineDataInteractor3D::InitRotate(StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; - m_CurrentPickedPoint = positionEvent->GetPositionInWorld(); - m_CurrentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); - - m_InitialPickedPoint = m_CurrentPickedPoint; - m_InitialPickedDisplayPoint = m_CurrentPickedDisplayPoint; + m_InitialPickedPoint = positionEvent->GetPositionInWorld(); + m_InitialPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); // Get the timestep to also support 3D+t - int timeStep = 0; - if ((interactionEvent->GetSender()) != NULL) - timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData()); + int timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData()); // Make deep copy of current Geometry3D of the plane this->GetDataNode()->GetData()->UpdateOutputInformation(); // make sure that the Geometry is up-to-date - m_OriginalGeometry = static_cast< Geometry3D * >(this->GetDataNode()->GetData()->GetGeometry( timeStep )->Clone().GetPointer() ); + m_OriginalGeometry = static_cast(this->GetDataNode()->GetData()->GetGeometry(timeStep)->Clone().GetPointer()); + return true; } bool mitk::AffineDataInteractor3D::TranslateObject (StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; - m_CurrentPickedPoint = positionEvent->GetPositionInWorld(); - m_CurrentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); + Point3D currentPickedPoint = positionEvent->GetPositionInWorld(); Vector3D interactionMove; - interactionMove[0] = m_CurrentPickedPoint[0] - m_InitialPickedPoint[0]; - interactionMove[1] = m_CurrentPickedPoint[1] - m_InitialPickedPoint[1]; - interactionMove[2] = m_CurrentPickedPoint[2] - m_InitialPickedPoint[2]; + interactionMove[0] = currentPickedPoint[0] - m_InitialPickedPoint[0]; + interactionMove[1] = currentPickedPoint[1] - m_InitialPickedPoint[1]; + interactionMove[2] = currentPickedPoint[2] - m_InitialPickedPoint[2]; Point3D origin = m_OriginalGeometry->GetOrigin(); // Get the timestep to also support 3D+t - int timeStep = 0; - if ((interactionEvent->GetSender()) != NULL) - timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData()); + int timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData()); // If data is an mitk::Surface, extract it Surface::Pointer surface = dynamic_cast< Surface* >(this->GetDataNode()->GetData()); vtkPolyData* polyData = NULL; if (surface.IsNotNull()) { polyData = surface->GetVtkPolyData( timeStep ); // Extract surface normal from surface (if existent, otherwise use default) vtkPointData* pointData = polyData->GetPointData(); if (pointData != NULL) { - vtkDataArray* normal = polyData->GetPointData()->GetVectors( "planeNormal" ); + vtkDataArray* normal = polyData->GetPointData()->GetVectors("planeNormal"); if (normal != NULL) { m_ObjectNormal[0] = normal->GetComponent( 0, 0 ); m_ObjectNormal[1] = normal->GetComponent( 0, 1 ); m_ObjectNormal[2] = normal->GetComponent( 0, 2 ); } } } Vector3D transformedObjectNormal; - this->GetDataNode()->GetData()->GetGeometry( timeStep )->IndexToWorld( - m_ObjectNormal, transformedObjectNormal ); + this->GetDataNode()->GetData()->GetGeometry( timeStep )->IndexToWorld(m_ObjectNormal, transformedObjectNormal); - this->GetDataNode()->GetData()->GetGeometry( timeStep )->SetOrigin( - origin + transformedObjectNormal * (interactionMove * transformedObjectNormal) ); + this->GetDataNode()->GetData()->GetGeometry( timeStep )->SetOrigin(origin + transformedObjectNormal * (interactionMove * transformedObjectNormal)); - //TODO: Only 3D reinit - RenderingManager::GetInstance()->RequestUpdateAll(); + interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } bool mitk::AffineDataInteractor3D::RotateObject (StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; - m_CurrentPickedPoint = positionEvent->GetPositionInWorld(); - m_CurrentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); + Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); + Point3D currentPickedPoint = positionEvent->GetPositionInWorld(); vtkCamera* camera = NULL; - vtkRenderer *currentVtkRenderer = NULL; + vtkRenderer* currentVtkRenderer = NULL; if ((interactionEvent->GetSender()) != NULL) { vtkRenderWindow* renderWindow = interactionEvent->GetSender()->GetRenderWindow(); - if ( renderWindow != NULL ) + if (renderWindow != NULL) { vtkRenderWindowInteractor* renderWindowInteractor = renderWindow->GetInteractor(); if ( renderWindowInteractor != NULL ) { currentVtkRenderer = renderWindowInteractor->GetInteractorStyle()->GetCurrentRenderer(); - if ( currentVtkRenderer != NULL ) + if (currentVtkRenderer != NULL) camera = currentVtkRenderer->GetActiveCamera(); } } } if ( camera ) { double vpn[3]; camera->GetViewPlaneNormal( vpn ); Vector3D viewPlaneNormal; viewPlaneNormal[0] = vpn[0]; viewPlaneNormal[1] = vpn[1]; viewPlaneNormal[2] = vpn[2]; Vector3D interactionMove; - interactionMove[0] = m_CurrentPickedPoint[0] - m_InitialPickedPoint[0]; - interactionMove[1] = m_CurrentPickedPoint[1] - m_InitialPickedPoint[1]; - interactionMove[2] = m_CurrentPickedPoint[2] - m_InitialPickedPoint[2]; + interactionMove[0] = currentPickedPoint[0] - m_InitialPickedPoint[0]; + interactionMove[1] = currentPickedPoint[1] - m_InitialPickedPoint[1]; + interactionMove[2] = currentPickedPoint[2] - m_InitialPickedPoint[2]; - if (interactionMove[0]==0 && interactionMove[1]==0 && interactionMove[2]==0) + if (interactionMove[0] == 0 && interactionMove[1] == 0 && interactionMove[2] == 0) return true; - Vector3D rotationAxis = itk::CrossProduct( viewPlaneNormal, interactionMove ); + Vector3D rotationAxis = itk::CrossProduct(viewPlaneNormal, interactionMove); rotationAxis.Normalize(); - m_CurrentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); - - int *size = currentVtkRenderer->GetSize(); + int* size = currentVtkRenderer->GetSize(); double l2 = - (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) * - (m_CurrentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) + - (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) * - (m_CurrentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]); + (currentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) * + (currentPickedDisplayPoint[0] - m_InitialPickedDisplayPoint[0]) + + (currentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]) * + (currentPickedDisplayPoint[1] - m_InitialPickedDisplayPoint[1]); - double rotationAngle = 360.0 * sqrt(l2/(size[0]*size[0]+size[1]*size[1])); + double rotationAngle = 360.0 * sqrt(l2 / (size[0] * size[0] + size[1] * size[1])); // Use center of data bounding box as center of rotation Point3D rotationCenter = m_OriginalGeometry->GetCenter(); int timeStep = 0; if ((interactionEvent->GetSender()) != NULL) timeStep = interactionEvent->GetSender()->GetTimeStep(this->GetDataNode()->GetData()); // Reset current Geometry3D to original state (pre-interaction) and // apply rotation RotationOperation op( OpROTATE, rotationCenter, rotationAxis, rotationAngle ); - Geometry3D::Pointer newGeometry = static_cast< Geometry3D * >( - m_OriginalGeometry->Clone().GetPointer() ); + Geometry3D::Pointer newGeometry = static_cast(m_OriginalGeometry->Clone().GetPointer()); newGeometry->ExecuteOperation( &op ); mitk::TimeGeometry::Pointer timeGeometry = this->GetDataNode()->GetData()->GetTimeGeometry(); if (timeGeometry.IsNotNull()) - { - timeGeometry->SetTimeStepGeometry( newGeometry, timeStep ); - } + timeGeometry->SetTimeStepGeometry(newGeometry, timeStep); - //TODO: Only 3D reinit - RenderingManager::GetInstance()->RequestUpdateAll(); + interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } else return false; } bool mitk::AffineDataInteractor3D::ColorizeSurface(BaseRenderer::Pointer renderer, double scalar) { BaseData::Pointer data = this->GetDataNode()->GetData(); if(data.IsNull()) { MITK_ERROR << "AffineInteractor3D: No data object present!"; return false; } // Get the timestep to also support 3D+t int timeStep = 0; if (renderer.IsNotNull()) timeStep = renderer->GetTimeStep(data); // If data is an mitk::Surface, extract it Surface::Pointer surface = dynamic_cast< Surface* >(data.GetPointer()); vtkPolyData* polyData = NULL; if (surface.IsNotNull()) polyData = surface->GetVtkPolyData(timeStep); if (polyData == NULL) { MITK_ERROR << "AffineInteractor3D: No poly data present!"; return false; } - vtkPointData *pointData = polyData->GetPointData(); + vtkPointData* pointData = polyData->GetPointData(); if (pointData == NULL) { MITK_ERROR << "AffineInteractor3D: No point data present!"; return false; } - vtkDataArray *scalars = pointData->GetScalars(); + vtkDataArray* scalars = pointData->GetScalars(); if (scalars == NULL) { MITK_ERROR << "AffineInteractor3D: No scalars for point data present!"; return false; } for (unsigned int i = 0; i < pointData->GetNumberOfTuples(); ++i) { scalars->SetComponent(i, 0, scalar); } polyData->Modified(); pointData->Update(); return true; } diff --git a/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.h b/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.h index fa4621438d..d6af00f1fc 100644 --- a/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.h +++ b/Modules/MitkExt/Interactions/mitkAffineDataInteractor3D.h @@ -1,88 +1,81 @@ /*=================================================================== 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 mitkAffineDataInteractor3D_h_ #define mitkAffineDataInteractor3D_h_ -//#include "itkObject.h" -//#include "itkSmartPointer.h" -//#include "itkObjectFactory.h" #include "mitkBaseRenderer.h" -#include "mitkCommon.h" #include "mitkDataInteractor.h" #include "MitkExtExports.h" #include "mitkGeometry3D.h" namespace mitk { - /** +/** * \brief Affine interaction with objects in 3D windows. * * \ingroup Interaction */ +// Inherit from DataInteratcor, this provides functionality of a state machine and configurable inputs. +class MitkExt_EXPORT AffineDataInteractor3D: public DataInteractor +{ - // Inherit from DataInteratcor, this provides functionality of a state machine and configurable inputs. - class MitkExt_EXPORT AffineDataInteractor3D: public DataInteractor - { - - public: - mitkClassMacro(AffineDataInteractor3D, DataInteractor); - itkNewMacro(Self); +public: + mitkClassMacro(AffineDataInteractor3D, DataInteractor); + itkNewMacro(Self); - protected: - AffineDataInteractor3D(); - virtual ~AffineDataInteractor3D(); - /** +protected: + AffineDataInteractor3D(); + virtual ~AffineDataInteractor3D(); + /** * Here actions strings from the loaded state machine pattern are mapped to functions of * the DataInteractor. These functions are called when an action from the state machine pattern is executed. */ - virtual void ConnectActionsAndFunctions(); - /** + virtual void ConnectActionsAndFunctions(); + /** * This function is called when a DataNode has been set/changed. */ - virtual void DataNodeChanged(); + virtual void DataNodeChanged(); - /** + /** * Initializes the movement, stores starting position. */ - virtual bool CheckOverObject (const InteractionEvent *); - virtual bool SelectObject (StateMachineAction*, InteractionEvent*); - virtual bool DeselectObject (StateMachineAction*, InteractionEvent*); - virtual bool InitTranslate (StateMachineAction*, InteractionEvent*); - virtual bool InitRotate (StateMachineAction*, InteractionEvent*); - virtual bool TranslateObject (StateMachineAction*, InteractionEvent*); - virtual bool RotateObject (StateMachineAction*, InteractionEvent*); - - bool ColorizeSurface(BaseRenderer::Pointer renderer, double scalar = 0.0); + virtual bool CheckOverObject (const InteractionEvent *); + virtual bool SelectObject (StateMachineAction*, InteractionEvent*); + virtual bool DeselectObject (StateMachineAction*, InteractionEvent*); + virtual bool InitTranslate (StateMachineAction*, InteractionEvent*); + virtual bool InitRotate (StateMachineAction*, InteractionEvent*); + virtual bool TranslateObject (StateMachineAction*, InteractionEvent*); + virtual bool RotateObject (StateMachineAction*, InteractionEvent*); - private: +private: - Point3D m_InitialPickedPoint; - Point2D m_InitialPickedDisplayPoint; + bool ColorizeSurface(BaseRenderer::Pointer renderer, double scalar = 0.0); - Point3D m_CurrentPickedPoint; - Point2D m_CurrentPickedDisplayPoint; + Point3D m_InitialPickedPoint; + Point2D m_InitialPickedDisplayPoint; - Geometry3D::Pointer m_Geometry; + //Point3D m_CurrentPickedPoint; + //Point2D m_CurrentPickedDisplayPoint; - Geometry3D::Pointer m_OriginalGeometry; + Geometry3D::Pointer m_OriginalGeometry; - Vector3D m_ObjectNormal; + Vector3D m_ObjectNormal; - }; +}; } #endif diff --git a/Modules/MitkExt/Resources/Interactions/AffineInteraction3D.xml b/Modules/MitkExt/Resources/Interactions/AffineInteraction3D.xml index 20223135e3..36d4e14d15 100644 --- a/Modules/MitkExt/Resources/Interactions/AffineInteraction3D.xml +++ b/Modules/MitkExt/Resources/Interactions/AffineInteraction3D.xml @@ -1,72 +1,72 @@ - + diff --git a/Modules/MitkExt/Resources/Interactions/AffineTranslationConfig.xml b/Modules/MitkExt/Resources/Interactions/AffineTranslationConfig.xml index 7f5fca8574..4bbbe5c8be 100644 --- a/Modules/MitkExt/Resources/Interactions/AffineTranslationConfig.xml +++ b/Modules/MitkExt/Resources/Interactions/AffineTranslationConfig.xml @@ -1,13 +1,13 @@ - + - +