diff --git a/Modules/DataTypesExt/Resources/Interactions/AffineDeformationConfig.xml b/Modules/DataTypesExt/Resources/Interactions/ClippingPlaneDeformationConfig.xml similarity index 100% rename from Modules/DataTypesExt/Resources/Interactions/AffineDeformationConfig.xml rename to Modules/DataTypesExt/Resources/Interactions/ClippingPlaneDeformationConfig.xml diff --git a/Modules/DataTypesExt/Resources/Interactions/AffineInteraction3D.xml b/Modules/DataTypesExt/Resources/Interactions/ClippingPlaneInteraction3D.xml similarity index 100% rename from Modules/DataTypesExt/Resources/Interactions/AffineInteraction3D.xml rename to Modules/DataTypesExt/Resources/Interactions/ClippingPlaneInteraction3D.xml diff --git a/Modules/DataTypesExt/Resources/Interactions/AffineRotationConfig.xml b/Modules/DataTypesExt/Resources/Interactions/ClippingPlaneRotationConfig.xml similarity index 100% rename from Modules/DataTypesExt/Resources/Interactions/AffineRotationConfig.xml rename to Modules/DataTypesExt/Resources/Interactions/ClippingPlaneRotationConfig.xml diff --git a/Modules/DataTypesExt/Resources/Interactions/AffineTranslationConfig.xml b/Modules/DataTypesExt/Resources/Interactions/ClippingPlaneTranslationConfig.xml similarity index 100% rename from Modules/DataTypesExt/Resources/Interactions/AffineTranslationConfig.xml rename to Modules/DataTypesExt/Resources/Interactions/ClippingPlaneTranslationConfig.xml diff --git a/Modules/DataTypesExt/files.cmake b/Modules/DataTypesExt/files.cmake index 770004c602..c3e5085e70 100644 --- a/Modules/DataTypesExt/files.cmake +++ b/Modules/DataTypesExt/files.cmake @@ -1,39 +1,44 @@ set(CPP_FILES - mitkAffineDataInteractor3D.cpp mitkApplyDiffImageOperation.cpp mitkBoundingObject.cpp mitkBoundingObjectGroup.cpp mitkCellOperation.cpp + mitkClippingPlaneInteractor3D.cpp mitkColorSequence.cpp mitkColorSequenceCycleH.cpp mitkColorSequenceRainbow.cpp mitkCompressedImageContainer.cpp mitkCone.cpp mitkCuboid.cpp mitkCylinder.cpp mitkDataStorageSelection.cpp mitkEllipsoid.cpp mitkGridRepresentationProperty.cpp mitkGridVolumeMapperProperty.cpp mitkLabeledImageLookupTable.cpp mitkLabeledImageVolumeCalculator.cpp mitkLineOperation.cpp mitkLookupTableSource.cpp mitkMesh.cpp mitkMultiStepper.cpp mitkOrganTypeProperty.cpp mitkPlane.cpp mitkSurfaceDeformationDataInteractor3D.cpp mitkUnstructuredGrid.cpp mitkUnstructuredGridSource.cpp mitkVideoSource.cpp Internal/mitkColorConversions.cpp ) set(RESOURCE_FILES - Interactions/AffineInteraction3D.xml - Interactions/AffineTranslationConfig.xml - Interactions/AffineRotationConfig.xml - Interactions/AffineDeformationConfig.xml + #Interactions/AffineInteraction3D.xml + #Interactions/AffineTranslationConfig.xml + #Interactions/AffineRotationConfig.xml + #Interactions/AffineDeformationConfig.xml + + Interactions/ClippingPlaneInteraction3D.xml + Interactions/ClippingPlaneTranslationConfig.xml + Interactions/ClippingPlaneRotationConfig.xml + Interactions/ClippingPlaneDeformationConfig.xml ) diff --git a/Modules/DataTypesExt/mitkAffineDataInteractor3D.cpp b/Modules/DataTypesExt/mitkClippingPlaneInteractor3D.cpp similarity index 87% rename from Modules/DataTypesExt/mitkAffineDataInteractor3D.cpp rename to Modules/DataTypesExt/mitkClippingPlaneInteractor3D.cpp index 27958f7987..45cf054240 100644 --- a/Modules/DataTypesExt/mitkAffineDataInteractor3D.cpp +++ b/Modules/DataTypesExt/mitkClippingPlaneInteractor3D.cpp @@ -1,356 +1,356 @@ /*=================================================================== 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 "mitkClippingPlaneInteractor3D.h" -#include "mitkInteractionConst.h" -#include "mitkInteractionPositionEvent.h" -#include "mitkRotationOperation.h" -#include "mitkSurface.h" +#include +#include +#include +#include #include #include #include #include #include #include -mitk::AffineDataInteractor3D::AffineDataInteractor3D() +mitk::ClippingPlaneInteractor3D::ClippingPlaneInteractor3D() { 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() +mitk::ClippingPlaneInteractor3D::~ClippingPlaneInteractor3D() { } -void mitk::AffineDataInteractor3D::ConnectActionsAndFunctions() +void mitk::ClippingPlaneInteractor3D::ConnectActionsAndFunctions() { // **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() +void mitk::ClippingPlaneInteractor3D::DataNodeChanged() { } -bool mitk::AffineDataInteractor3D::CheckOverObject(const InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::CheckOverObject(const InteractionEvent* interactionEvent) { const InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; Point3D currentWorldPoint; if(interactionEvent->GetSender()->PickObject(positionEvent->GetPointerPositionOnScreen(), currentWorldPoint) == this->GetDataNode().GetPointer()) return true; return false; } -bool mitk::AffineDataInteractor3D::SelectObject(StateMachineAction*, InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::SelectObject(StateMachineAction*, InteractionEvent* interactionEvent) { DataNode::Pointer node = this->GetDataNode(); if (node.IsNull()) return false; node->SetColor(1.0, 0.0, 0.0); // Colorize surface / wireframe dependend on distance from picked point this->ColorizeSurface(interactionEvent->GetSender(), 0.0); interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } -bool mitk::AffineDataInteractor3D::DeselectObject(StateMachineAction*, InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::DeselectObject(StateMachineAction*, InteractionEvent* interactionEvent) { DataNode::Pointer node = this->GetDataNode(); if (node.IsNull()) return false; node->SetColor( 1.0, 1.0, 1.0 ); // Colorize surface / wireframe as inactive this->ColorizeSurface(interactionEvent->GetSender(), -1.0); interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } -bool mitk::AffineDataInteractor3D::InitTranslate(StateMachineAction*, InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::InitTranslate(StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; m_InitialPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); vtkInteractorObserver::ComputeDisplayToWorld( interactionEvent->GetSender()->GetVtkRenderer(), m_InitialPickedDisplayPoint[0], m_InitialPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], m_InitialPickedWorldPoint ); // 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(this->GetDataNode()->GetData()->GetGeometry(timeStep)->Clone().GetPointer()); return true; } -bool mitk::AffineDataInteractor3D::InitRotate(StateMachineAction*, InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::InitRotate(StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; m_InitialPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); vtkInteractorObserver::ComputeDisplayToWorld( interactionEvent->GetSender()->GetVtkRenderer(), m_InitialPickedDisplayPoint[0], m_InitialPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], m_InitialPickedWorldPoint ); // Get the timestep to also support 3D+t 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(this->GetDataNode()->GetData()->GetGeometry(timeStep)->Clone().GetPointer()); return true; } -bool mitk::AffineDataInteractor3D::TranslateObject (StateMachineAction*, InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::TranslateObject (StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; double currentWorldPoint[4]; mitk::Point2D currentDisplayPoint = positionEvent->GetPointerPositionOnScreen(); vtkInteractorObserver::ComputeDisplayToWorld( interactionEvent->GetSender()->GetVtkRenderer(), currentDisplayPoint[0], currentDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], currentWorldPoint); Vector3D interactionMove; interactionMove[0] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0]; interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1]; interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2]; Point3D origin = m_OriginalGeometry->GetOrigin(); // Get the timestep to also support 3D+t 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"); 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 )->SetOrigin(origin + transformedObjectNormal * (interactionMove * transformedObjectNormal)); interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } -bool mitk::AffineDataInteractor3D::RotateObject (StateMachineAction*, InteractionEvent* interactionEvent) +bool mitk::ClippingPlaneInteractor3D::RotateObject (StateMachineAction*, InteractionEvent* interactionEvent) { InteractionPositionEvent* positionEvent = dynamic_cast(interactionEvent); if(positionEvent == NULL) return false; double currentWorldPoint[4]; Point2D currentPickedDisplayPoint = positionEvent->GetPointerPositionOnScreen(); vtkInteractorObserver::ComputeDisplayToWorld( interactionEvent->GetSender()->GetVtkRenderer(), currentPickedDisplayPoint[0], currentPickedDisplayPoint[1], 0.0, //m_InitialInteractionPickedPoint[2], currentWorldPoint); vtkCamera* camera = NULL; vtkRenderer* currentVtkRenderer = NULL; if ((interactionEvent->GetSender()) != NULL) { vtkRenderWindow* renderWindow = interactionEvent->GetSender()->GetRenderWindow(); if (renderWindow != NULL) { vtkRenderWindowInteractor* renderWindowInteractor = renderWindow->GetInteractor(); if ( renderWindowInteractor != NULL ) { currentVtkRenderer = renderWindowInteractor->GetInteractorStyle()->GetCurrentRenderer(); 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] = currentWorldPoint[0] - m_InitialPickedWorldPoint[0]; interactionMove[1] = currentWorldPoint[1] - m_InitialPickedWorldPoint[1]; interactionMove[2] = currentWorldPoint[2] - m_InitialPickedWorldPoint[2]; if (interactionMove[0] == 0 && interactionMove[1] == 0 && interactionMove[2] == 0) return true; Vector3D rotationAxis = itk::CrossProduct(viewPlaneNormal, interactionMove); rotationAxis.Normalize(); int* size = currentVtkRenderer->GetSize(); double l2 = (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])); // 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(m_OriginalGeometry->Clone().GetPointer()); newGeometry->ExecuteOperation( &op ); mitk::TimeGeometry::Pointer timeGeometry = this->GetDataNode()->GetData()->GetTimeGeometry(); if (timeGeometry.IsNotNull()) timeGeometry->SetTimeStepGeometry(newGeometry, timeStep); interactionEvent->GetSender()->GetRenderingManager()->RequestUpdateAll(); return true; } else return false; } -bool mitk::AffineDataInteractor3D::ColorizeSurface(BaseRenderer::Pointer renderer, double scalar) +bool mitk::ClippingPlaneInteractor3D::ColorizeSurface(BaseRenderer::Pointer renderer, double scalar) { BaseData::Pointer data = this->GetDataNode()->GetData(); if(data.IsNull()) { - MITK_ERROR << "AffineInteractor3D: No data object present!"; + MITK_ERROR << "ClippingPlaneInteractor3D: 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!"; + MITK_ERROR << "ClippingPlaneInteractor3D: No poly data present!"; return false; } vtkPointData* pointData = polyData->GetPointData(); if (pointData == NULL) { - MITK_ERROR << "AffineInteractor3D: No point data present!"; + MITK_ERROR << "ClippingPlaneInteractor3D: No point data present!"; return false; } vtkDataArray* scalars = pointData->GetScalars(); if (scalars == NULL) { - MITK_ERROR << "AffineInteractor3D: No scalars for point data present!"; + MITK_ERROR << "ClippingPlaneInteractor3D: No scalars for point data present!"; return false; } for (vtkIdType i = 0; i < pointData->GetNumberOfTuples(); ++i) { scalars->SetComponent(i, 0, scalar); } polyData->Modified(); pointData->Update(); return true; } diff --git a/Modules/DataTypesExt/mitkAffineDataInteractor3D.h b/Modules/DataTypesExt/mitkClippingPlaneInteractor3D.h similarity index 79% rename from Modules/DataTypesExt/mitkAffineDataInteractor3D.h rename to Modules/DataTypesExt/mitkClippingPlaneInteractor3D.h index 38a7cac017..51dfb9b0fe 100644 --- a/Modules/DataTypesExt/mitkAffineDataInteractor3D.h +++ b/Modules/DataTypesExt/mitkClippingPlaneInteractor3D.h @@ -1,82 +1,77 @@ /*=================================================================== 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_ +#ifndef mitkClippingPlaneInteractor3D_h +#define mitkClippingPlaneInteractor3D_h -#include "mitkBaseRenderer.h" -#include "mitkDataInteractor.h" +#include +#include +#include #include "MitkDataTypesExtExports.h" -#include "mitkGeometry3D.h" namespace mitk { /** - * \brief Affine interaction with objects in 3D windows. + * \brief Specialized interactor for clipping planes. * * \ingroup Interaction */ // Inherit from DataInteratcor, this provides functionality of a state machine and configurable inputs. -class MitkDataTypesExt_EXPORT AffineDataInteractor3D: public DataInteractor +class MitkDataTypesExt_EXPORT ClippingPlaneInteractor3D: public DataInteractor { public: - mitkClassMacro(AffineDataInteractor3D, DataInteractor); + mitkClassMacro(ClippingPlaneInteractor3D, DataInteractor); itkFactorylessNewMacro(Self) itkCloneMacro(Self) protected: - AffineDataInteractor3D(); - virtual ~AffineDataInteractor3D(); + ClippingPlaneInteractor3D(); + virtual ~ClippingPlaneInteractor3D(); /** * 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(); /** * This function is called when a DataNode has been set/changed. */ 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*); private: bool ColorizeSurface(BaseRenderer::Pointer renderer, double scalar = 0.0); double m_InitialPickedWorldPoint[4]; Point2D m_InitialPickedDisplayPoint; - //Point3D m_CurrentPickedPoint; - //Point2D m_CurrentPickedDisplayPoint; - Geometry3D::Pointer m_OriginalGeometry; Vector3D m_ObjectNormal; - }; - } -#endif +#endif //mitkClippingPlaneInteractor3D_h diff --git a/Plugins/org.mitk.gui.qt.segmentation/src/internal/QmitkDeformableClippingPlaneView.cpp b/Plugins/org.mitk.gui.qt.segmentation/src/internal/QmitkDeformableClippingPlaneView.cpp index 1c779e3099..027b2ce3ed 100644 --- a/Plugins/org.mitk.gui.qt.segmentation/src/internal/QmitkDeformableClippingPlaneView.cpp +++ b/Plugins/org.mitk.gui.qt.segmentation/src/internal/QmitkDeformableClippingPlaneView.cpp @@ -1,633 +1,633 @@ /*=================================================================== 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 "QmitkDeformableClippingPlaneView.h" -#include "mitkAffineDataInteractor3D.h" +#include "mitkClippingPlaneInteractor3D.h" #include "mitkHeightFieldSurfaceClipImageFilter.h" #include "mitkImageToSurfaceFilter.h" #include "mitkInteractionConst.h" #include "mitkLabeledImageLookupTable.h" #include "mitkLabeledImageVolumeCalculator.h" #include "mitkLevelWindowProperty.h" #include "mitkLookupTableProperty.h" #include "mitkNodePredicateProperty.h" #include "mitkNodePredicateDataType.h" #include "mitkRenderingModeProperty.h" #include "mitkRotationOperation.h" #include "mitkSurfaceDeformationDataInteractor3D.h" #include "mitkSurfaceVtkMapper3D.h" #include "mitkVtkRepresentationProperty.h" #include "usModuleRegistry.h" #include "vtkFloatArray.h" #include "vtkPointData.h" #include "vtkProperty.h" #include const std::string QmitkDeformableClippingPlaneView::VIEW_ID = "org.mitk.views.deformableclippingplane"; QmitkDeformableClippingPlaneView::QmitkDeformableClippingPlaneView() : QmitkFunctionality() , m_MultiWidget(NULL) , m_ReferenceNode(NULL) , m_WorkingNode(NULL) { } QmitkDeformableClippingPlaneView::~QmitkDeformableClippingPlaneView() { } void QmitkDeformableClippingPlaneView::CreateQtPartControl(QWidget *parent) { // create GUI widgets m_Controls.setupUi(parent); this->CreateConnections(); } void QmitkDeformableClippingPlaneView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_MultiWidget = &stdMultiWidget; } void QmitkDeformableClippingPlaneView::StdMultiWidgetNotAvailable() { m_MultiWidget = NULL; } void QmitkDeformableClippingPlaneView::CreateConnections() { mitk::NodePredicateProperty::Pointer clipPredicate = mitk::NodePredicateProperty::New("clippingPlane",mitk::BoolProperty::New(true)); //set only clipping planes in the list of the selector m_Controls.clippingPlaneSelector->SetDataStorage(this->GetDefaultDataStorage()); m_Controls.clippingPlaneSelector->SetPredicate(clipPredicate); //No working data set, yet m_Controls.volumeGroupBox->setEnabled(false); m_Controls.interactionSelectionBox->setEnabled(false); m_Controls.noSelectedImageLabel->show(); m_Controls.planesWarningLabel->hide(); connect (m_Controls.translationPushButton, SIGNAL(toggled(bool)), this, SLOT(OnTranslationMode(bool))); connect (m_Controls.rotationPushButton, SIGNAL(toggled(bool)), this, SLOT(OnRotationMode(bool))); connect (m_Controls.deformationPushButton, SIGNAL(toggled(bool)), this, SLOT(OnDeformationMode(bool))); connect (m_Controls.createNewPlanePushButton, SIGNAL(clicked()), this, SLOT(OnCreateNewClippingPlane())); connect (m_Controls.updateVolumePushButton, SIGNAL(clicked()), this, SLOT(OnCalculateClippingVolume())); connect (m_Controls.clippingPlaneSelector, SIGNAL(OnSelectionChanged(const mitk::DataNode*)), this, SLOT(OnComboBoxSelectionChanged(const mitk::DataNode*))); } void QmitkDeformableClippingPlaneView::Activated() { QmitkFunctionality::Activated(); //If a tube graph already exist in the data storage, set the working node correctly m_WorkingNode = m_Controls.clippingPlaneSelector->GetSelectedNode(); this->UpdateView(); } void QmitkDeformableClippingPlaneView::Deactivated() { if(m_WorkingNode.IsNotNull()) { if(m_WorkingNode->GetDataInteractor().IsNotNull()) m_WorkingNode->SetDataInteractor(NULL); } QmitkFunctionality::Deactivated(); } void QmitkDeformableClippingPlaneView::OnComboBoxSelectionChanged( const mitk::DataNode* node ) { this->DeactivateInteractionButtons(); mitk::DataNode* selectedNode = const_cast(node); if( selectedNode != NULL ) { if(m_WorkingNode.IsNotNull()) selectedNode->SetDataInteractor(m_WorkingNode->GetDataInteractor()); m_WorkingNode = selectedNode; } this->UpdateView(); } void QmitkDeformableClippingPlaneView::OnSelectionChanged(mitk::DataNode* node) { std::vector nodes; nodes.push_back(node); this->OnSelectionChanged(nodes); } void QmitkDeformableClippingPlaneView::OnSelectionChanged(std::vector nodes) { bool isClippingPlane(false); for(unsigned int i = 0; i < nodes.size(); ++i) { if(nodes.at(i)->GetBoolProperty("clippingPlane", isClippingPlane)) m_Controls.clippingPlaneSelector->setCurrentIndex( m_Controls.clippingPlaneSelector->Find(nodes.at(i)) ); else { if(dynamic_cast (nodes.at(i)->GetData())&& nodes.at(i)) { if(m_ReferenceNode.IsNotNull() && nodes.at(i)->GetData() == m_ReferenceNode->GetData()) return; m_ReferenceNode =nodes.at(i); } } } this->UpdateView(); } void::QmitkDeformableClippingPlaneView::NodeChanged(const mitk::DataNode* /*node*/) { this->UpdateView(); } void QmitkDeformableClippingPlaneView::NodeRemoved(const mitk::DataNode* node) { bool isClippingPlane(false); if (node->GetBoolProperty("clippingPlane", isClippingPlane)) { if(this->GetAllClippingPlanes()->Size()<=1) { m_WorkingNode = NULL; this->UpdateView(); } else { if (GetAllClippingPlanes()->front()!= node) this->OnSelectionChanged(GetAllClippingPlanes()->front()); else this->OnSelectionChanged(GetAllClippingPlanes()->ElementAt(1)); } } else { if(m_ReferenceNode.IsNotNull()) { if(node->GetData() == m_ReferenceNode->GetData()) { m_ReferenceNode = NULL; m_Controls.volumeList->clear(); } this->UpdateView(); } } } void QmitkDeformableClippingPlaneView::UpdateView() { if (m_ReferenceNode.IsNotNull()) { m_Controls.noSelectedImageLabel->hide(); m_Controls.selectedImageLabel->setText(QString::fromUtf8(m_ReferenceNode->GetName().c_str())); if (m_WorkingNode.IsNotNull()) { bool isSegmentation(false); m_ReferenceNode->GetBoolProperty("binary", isSegmentation); m_Controls.interactionSelectionBox->setEnabled(true); m_Controls.volumeGroupBox->setEnabled(isSegmentation); //clear list --> than search for all shown clipping plans (max 7 planes) m_Controls.selectedVolumePlanesLabel->setText(""); m_Controls.planesWarningLabel->hide(); int volumePlanes=0; mitk::DataStorage::SetOfObjects::ConstPointer allClippingPlanes = this->GetAllClippingPlanes(); for (mitk::DataStorage::SetOfObjects::ConstIterator itPlanes = allClippingPlanes->Begin(); itPlanes != allClippingPlanes->End(); itPlanes++) { bool isVisible(false); itPlanes.Value()->GetBoolProperty("visible",isVisible); if (isVisible) { if (volumePlanes<7) { volumePlanes ++; m_Controls.selectedVolumePlanesLabel->setText(m_Controls.selectedVolumePlanesLabel->text().append(QString::fromStdString(itPlanes.Value()->GetName()+"\n"))); } else { m_Controls.planesWarningLabel->show(); return; } } } } else { m_Controls.volumeGroupBox->setEnabled(false); m_Controls.interactionSelectionBox->setEnabled(false); m_Controls.selectedVolumePlanesLabel->setText(""); m_Controls.volumeList->clear(); } } else { m_Controls.volumeGroupBox->setEnabled(false); m_Controls.noSelectedImageLabel->show(); m_Controls.selectedImageLabel->setText(""); m_Controls.selectedVolumePlanesLabel->setText(""); m_Controls.planesWarningLabel->hide(); if(m_WorkingNode.IsNull()) m_Controls.interactionSelectionBox->setEnabled(false); else m_Controls.interactionSelectionBox->setEnabled(true); } } void QmitkDeformableClippingPlaneView::OnCreateNewClippingPlane() { this->DeactivateInteractionButtons(); //the new clipping plane mitk::Surface::Pointer plane = mitk::Surface::New(); mitk::Image::Pointer referenceImage = mitk::Image::New(); vtkSmartPointer planeSource = vtkSmartPointer::New(); // default initialization of the clipping plane planeSource->SetOrigin( -32.0, -32.0, 0.0 ); planeSource->SetPoint1( 32.0, -32.0, 0.0 ); planeSource->SetPoint2( -32.0, 32.0, 0.0 ); planeSource->SetResolution( 128, 128 ); planeSource->Update(); plane->SetVtkPolyData(planeSource->GetOutput()); double imageDiagonal = 200; if (m_ReferenceNode.IsNotNull()) { referenceImage = dynamic_cast (m_ReferenceNode->GetData()); if (referenceImage.IsNotNull()) { // check if user wants a surface model if(m_Controls.surfaceModelCheckBox->isChecked()) { //Check if there is a surface node from the image. If not, create one bool createSurfaceFromImage(true); mitk::NodePredicateDataType::Pointer isDwi = mitk::NodePredicateDataType::New("DiffusionImage"); mitk::NodePredicateDataType::Pointer isSurface = mitk::NodePredicateDataType::New("Surface"); mitk::DataStorage::SetOfObjects::ConstPointer childNodes = GetDataStorage()->GetDerivations(m_ReferenceNode,isSurface, true); for (mitk::DataStorage::SetOfObjects::ConstIterator itChildNodes = childNodes->Begin(); itChildNodes != childNodes->End(); itChildNodes++) { if (itChildNodes.Value().IsNotNull()) createSurfaceFromImage=false; } if(createSurfaceFromImage) { //Lsg 2: Surface for the 3D-perspective mitk::ImageToSurfaceFilter::Pointer surfaceFilter = mitk::ImageToSurfaceFilter::New(); surfaceFilter->SetInput(referenceImage); surfaceFilter->SetThreshold(1); surfaceFilter->SetSmooth(true); //Downsampling surfaceFilter->SetDecimate(mitk::ImageToSurfaceFilter::DecimatePro); mitk::DataNode::Pointer surfaceNode = mitk::DataNode::New(); surfaceNode->SetData(surfaceFilter->GetOutput()); surfaceNode->SetProperty("color", m_ReferenceNode->GetProperty("color")); surfaceNode->SetOpacity(0.5); surfaceNode->SetName(m_ReferenceNode->GetName()); GetDataStorage()->Add(surfaceNode, m_ReferenceNode); } } //If an image is selected trim the plane to this. imageDiagonal = referenceImage->GetGeometry()->GetDiagonalLength(); plane->SetOrigin( referenceImage->GetGeometry()->GetCenter()); // Rotate plane mitk::Vector3D rotationAxis; mitk::FillVector3D(rotationAxis, 0.0, 1.0, 0.0); mitk::RotationOperation op(mitk::OpROTATE, referenceImage->GetGeometry()->GetCenter(), rotationAxis, 90.0); plane->GetGeometry()->ExecuteOperation(&op); } } //set some properties for the clipping plane // plane->SetExtent(imageDiagonal * 0.9, imageDiagonal * 0.9); // plane->SetResolution(64, 64); // eequivalent to the extent and resolution function of the clipping plane const double x = imageDiagonal * 0.9; planeSource->SetOrigin( -x / 2.0, -x / 2.0, 0.0 ); planeSource->SetPoint1( x / 2.0, -x / 2.0, 0.0 ); planeSource->SetPoint2( -x / 2.0, x / 2.0, 0.0 ); planeSource->SetResolution( 64, 64 ); planeSource->Update(); plane->SetVtkPolyData(planeSource->GetOutput()); // Set scalars (for colorization of plane) vtkFloatArray *scalars = vtkFloatArray::New(); scalars->SetName("Distance"); scalars->SetNumberOfComponents(1); for ( unsigned int i = 0; i < plane->GetVtkPolyData(0)->GetNumberOfPoints(); ++i) { scalars->InsertNextValue(-1.0); } plane->GetVtkPolyData(0)->GetPointData()->SetScalars(scalars); plane->GetVtkPolyData(0)->GetPointData()->Update(); mitk::DataNode::Pointer planeNode = mitk::DataNode::New(); planeNode->SetData(plane); std::stringstream planeName; planeName << "ClippingPlane "; planeName << this->GetAllClippingPlanes()->Size() + 1; planeNode->SetName(planeName.str()); planeNode->AddProperty("clippingPlane",mitk::BoolProperty::New(true)); // Make plane pickable planeNode->SetBoolProperty("pickable", true); mitk::SurfaceVtkMapper3D::SetDefaultProperties(planeNode); // Don't include plane in bounding box! planeNode->SetProperty("includeInBoundingBox", mitk::BoolProperty::New(false)); // Set lookup table for plane surface visualization vtkSmartPointer lookupTable = vtkSmartPointer::New(); lookupTable->SetHueRange(0.6, 0.0); lookupTable->SetSaturationRange(1.0, 1.0); lookupTable->SetValueRange(1.0, 1.0); lookupTable->SetTableRange(-1.0, 1.0); lookupTable->Build(); mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); lut->SetVtkLookupTable(lookupTable); mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(lut); planeNode->SetProperty("LookupTable", prop); planeNode->SetBoolProperty("scalar visibility", true); planeNode->SetBoolProperty("color mode", true); planeNode->SetFloatProperty("ScalarsRangeMinimum", -1.0); planeNode->SetFloatProperty("ScalarsRangeMaximum", 1.0); // Configure material so that only scalar colors are shown planeNode->SetColor(0.0f,0.0f,0.0f); planeNode->SetOpacity(1.0f); planeNode->SetFloatProperty("material.wireframeLineWidth",2.0f); //Set view of plane to wireframe planeNode->SetProperty("material.representation", mitk::VtkRepresentationProperty::New(VTK_WIREFRAME)); //Set the plane as working data for the tools and selected it this->OnSelectionChanged (planeNode); //Add the plane to data storage this->GetDataStorage()->Add(planeNode); //Change the index of the selector to the new generated node m_Controls.clippingPlaneSelector->setCurrentIndex( m_Controls.clippingPlaneSelector->Find(planeNode) ); m_Controls.interactionSelectionBox->setEnabled(true); // set crosshair invisible mitk::DataNode* dataNode; dataNode = this->m_MultiWidget->GetWidgetPlane1(); if(dataNode) dataNode->SetVisibility(false); dataNode = this->m_MultiWidget->GetWidgetPlane2(); if(dataNode) dataNode->SetVisibility(false); dataNode = this->m_MultiWidget->GetWidgetPlane3(); if(dataNode) dataNode->SetVisibility(false); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkDeformableClippingPlaneView::OnCalculateClippingVolume() { bool isSegmentation(false); m_ReferenceNode->GetBoolProperty("binary", isSegmentation); if(m_ReferenceNode.IsNull() || !isSegmentation) { MITK_ERROR << "No segmentation selected! Can't calculate volume"; return; } std::vector clippingPlanes; mitk::DataStorage::SetOfObjects::ConstPointer allClippingPlanes = this->GetAllClippingPlanes(); for (mitk::DataStorage::SetOfObjects::ConstIterator itPlanes = allClippingPlanes->Begin(); itPlanes != allClippingPlanes->End(); itPlanes++) { bool isVisible(false); itPlanes.Value()->GetBoolProperty("visible",isVisible); mitk::Surface* plane = dynamic_cast(itPlanes.Value()->GetData()); if (isVisible && plane) clippingPlanes.push_back(plane); } if (clippingPlanes.empty()) { MITK_ERROR << "No clipping plane selected! Can't calculate volume"; return; } // deactivate Tools this->DeactivateInteractionButtons(); //Clear the list of volumes, before calculating the new values m_Controls.volumeList->clear(); m_ReferenceNode->SetBoolProperty("visible", false); //set some properties for clipping the image-->Output: labled Image mitk::HeightFieldSurfaceClipImageFilter::Pointer surfaceClipFilter = mitk::HeightFieldSurfaceClipImageFilter::New(); surfaceClipFilter->SetInput(dynamic_cast (m_ReferenceNode->GetData())); surfaceClipFilter->SetClippingModeToMultiPlaneValue(); surfaceClipFilter->SetClippingSurfaces(clippingPlanes); surfaceClipFilter->Update(); //delete the old clipped image node mitk::DataStorage::SetOfObjects::ConstPointer oldClippedNode = this->GetDataStorage()->GetSubset(mitk::NodePredicateProperty::New("name", mitk::StringProperty::New("Clipped Image"))); if (oldClippedNode.IsNotNull()) this->GetDataStorage()->Remove(oldClippedNode); //add the new clipped image node mitk::DataNode::Pointer clippedNode = mitk::DataNode::New(); mitk::Image::Pointer clippedImage = surfaceClipFilter->GetOutput(); clippedImage->DisconnectPipeline(); clippedNode->SetData(clippedImage); //clippedNode->SetProperty("helper object", mitk::BoolProperty::New(true)); clippedNode->SetName("Clipped Image"); clippedNode->SetColor(1.0,1.0,1.0); // color property will not be used, labeled image lookuptable will be used instead clippedNode->SetProperty ("use color", mitk::BoolProperty::New(false)); clippedNode->SetOpacity(0.4); this->GetDataStorage()->Add(clippedNode); mitk::LabeledImageVolumeCalculator::Pointer volumeCalculator = mitk::LabeledImageVolumeCalculator::New(); volumeCalculator->SetImage(clippedImage); volumeCalculator->Calculate(); std::vector volumes = volumeCalculator->GetVolumes(); mitk::LabeledImageLookupTable::Pointer lut = mitk::LabeledImageLookupTable::New(); int lablesWithVolume=0; for(unsigned int i = 1; i < volumes.size(); ++i) { if(volumes.at(i)!=0) { lablesWithVolume++; mitk::Color color (GetLabelColor(lablesWithVolume)); lut->SetColorForLabel(i,color.GetRed(), color.GetGreen(), color.GetBlue(), 1.0); QColor qcolor; qcolor.setRgbF(color.GetRed(), color.GetGreen(), color.GetBlue(), 0.7); //output volume as string "x.xx ml" std::stringstream stream; stream<< std::fixed << std::setprecision(2)<setText(QString::fromStdString(stream.str())); item->setBackgroundColor(qcolor); m_Controls.volumeList->addItem(item); } } //set the rendering mode to use the lookup table and level window clippedNode->SetProperty("Image Rendering.Mode", mitk::RenderingModeProperty::New(mitk::RenderingModeProperty::LOOKUPTABLE_LEVELWINDOW_COLOR)); mitk::LookupTableProperty::Pointer lutProp = mitk::LookupTableProperty::New(lut.GetPointer()); clippedNode->SetProperty("LookupTable", lutProp); // it is absolutely important, to use the LevelWindow settings provided by // the LUT generator, otherwise, it is not guaranteed, that colors show // up correctly. clippedNode->SetProperty("levelwindow", mitk::LevelWindowProperty::New(lut->GetLevelWindow())); } mitk::DataStorage::SetOfObjects::ConstPointer QmitkDeformableClippingPlaneView::GetAllClippingPlanes() { mitk::NodePredicateProperty::Pointer clipPredicate= mitk::NodePredicateProperty::New("clippingPlane",mitk::BoolProperty::New(true)); mitk::DataStorage::SetOfObjects::ConstPointer allPlanes = GetDataStorage()->GetSubset(clipPredicate); return allPlanes; } mitk::Color QmitkDeformableClippingPlaneView::GetLabelColor(int label) { float red, green, blue; switch ( label % 6 ) { case 0: {red = 1.0; green = 0.0; blue = 0.0; break;} case 1: {red = 0.0; green = 1.0; blue = 0.0; break;} case 2: {red = 0.0; green = 0.0; blue = 1.0;break;} case 3: {red = 1.0; green = 1.0; blue = 0.0;break;} case 4: {red = 1.0; green = 0.0; blue = 1.0;break;} case 5: {red = 0.0; green = 1.0; blue = 1.0;break;} default: {red = 0.0; green = 0.0; blue = 0.0;} } float tmp[3] = { red, green, blue }; double factor; int outerCycleNr = label / 6; int cycleSize = pow(2.0,(int)(log((double)(outerCycleNr))/log( 2.0 ))); if (cycleSize==0) cycleSize = 1; int insideCycleCounter = outerCycleNr % cycleSize; if ( outerCycleNr == 0) factor = 255; else factor = ( 256 / ( 2 * cycleSize ) ) + ( insideCycleCounter * ( 256 / cycleSize ) ); tmp[0]= tmp[0]/256*factor; tmp[1]= tmp[1]/256*factor; tmp[2]= tmp[2]/256*factor; return mitk::Color(tmp); } void QmitkDeformableClippingPlaneView::OnTranslationMode(bool check) { if(check) { //uncheck all other buttons m_Controls.rotationPushButton->setChecked(false); m_Controls.deformationPushButton->setChecked(false); - mitk::AffineDataInteractor3D::Pointer affineDataInteractor = mitk::AffineDataInteractor3D::New(); - affineDataInteractor->LoadStateMachine("AffineInteraction3D.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); - affineDataInteractor->SetEventConfig("AffineTranslationConfig.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); + mitk::ClippingPlaneInteractor3D::Pointer affineDataInteractor = mitk::ClippingPlaneInteractor3D::New(); + affineDataInteractor->LoadStateMachine("ClippingPlaneInteraction3D.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); + affineDataInteractor->SetEventConfig("ClippingPlaneTranslationConfig.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); affineDataInteractor->SetDataNode(m_WorkingNode); } else m_WorkingNode->SetDataInteractor(NULL); } void QmitkDeformableClippingPlaneView::OnRotationMode(bool check) { if(check) { //uncheck all other buttons m_Controls.translationPushButton->setChecked(false); m_Controls.deformationPushButton->setChecked(false); - mitk::AffineDataInteractor3D::Pointer affineDataInteractor = mitk::AffineDataInteractor3D::New(); - affineDataInteractor->LoadStateMachine("AffineInteraction3D.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); - affineDataInteractor->SetEventConfig("AffineRotationConfig.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); + mitk::ClippingPlaneInteractor3D::Pointer affineDataInteractor = mitk::ClippingPlaneInteractor3D::New(); + affineDataInteractor->LoadStateMachine("ClippingPlaneInteraction3D.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); + affineDataInteractor->SetEventConfig("ClippingPlaneRotationConfig.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); affineDataInteractor->SetDataNode(m_WorkingNode); } else m_WorkingNode->SetDataInteractor(NULL); } void QmitkDeformableClippingPlaneView::OnDeformationMode(bool check) { if(check) { //uncheck all other buttons m_Controls.translationPushButton->setChecked(false); m_Controls.rotationPushButton->setChecked(false); mitk::SurfaceDeformationDataInteractor3D::Pointer surfaceDataInteractor = mitk::SurfaceDeformationDataInteractor3D::New(); - surfaceDataInteractor->LoadStateMachine("AffineInteraction3D.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); - surfaceDataInteractor->SetEventConfig("AffineDeformationConfig.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); + surfaceDataInteractor->LoadStateMachine("ClippingPlaneInteraction3D.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); + surfaceDataInteractor->SetEventConfig("ClippingPlaneDeformationConfig.xml", us::ModuleRegistry::GetModule("MitkDataTypesExt")); surfaceDataInteractor->SetDataNode(m_WorkingNode); } else m_WorkingNode->SetDataInteractor(NULL); } void QmitkDeformableClippingPlaneView::DeactivateInteractionButtons() { m_Controls.translationPushButton->setChecked(false); m_Controls.rotationPushButton->setChecked(false); m_Controls.deformationPushButton->setChecked(false); }