diff --git a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationSelectorView.cpp b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationSelectorView.cpp index fcca0f263c..af8596c430 100644 --- a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationSelectorView.cpp +++ b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationSelectorView.cpp @@ -1,773 +1,783 @@ /*=================================================================== 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 "mitkImageTimeSelector.h" #include #include #include #include "mitkMatrixConvert.h" #include #include #include "QmitkLoadPresetDialog.h" #include #include "mitkRigidRegistrationPreset.h" #include "mitkProgressBar.h" #include "QmitkRigidRegistrationSelectorView.h" #include "QmitkTranslationTransformView.h" #include "QmitkScaleTransformView.h" #include "QmitkScaleLogarithmicTransformView.h" #include "QmitkAffineTransformView.h" #include "QmitkFixedCenterOfRotationAffineTransformView.h" #include "QmitkEuler3DTransformView.h" #include "QmitkCenteredEuler3DTransformView.h" #include "QmitkQuaternionRigidTransformView.h" #include "QmitkVersorTransformView.h" #include "QmitkVersorRigid3DTransformView.h" #include "QmitkScaleSkewVersor3DTransformView.h" #include "QmitkSimilarity3DTransformView.h" #include "QmitkRigid2DTransformView.h" #include "QmitkCenteredRigid2DTransformView.h" #include "QmitkEuler2DTransformView.h" #include "QmitkSimilarity2DTransformView.h" #include "QmitkCenteredSimilarity2DTransformView.h" #include "QmitkMeanSquaresMetricView.h" #include "QmitkNormalizedCorrelationMetricView.h" #include "QmitkGradientDifferenceMetricView.h" #include "QmitkKullbackLeiblerCompareHistogramMetricView.h" #include "QmitkCorrelationCoefficientHistogramMetricView.h" #include "QmitkMeanSquaresHistogramMetricView.h" #include "QmitkMutualInformationHistogramMetricView.h" #include "QmitkNormalizedMutualInformationHistogramMetricView.h" #include "QmitkMattesMutualInformationMetricView.h" #include "QmitkMeanReciprocalSquareDifferenceMetricView.h" #include "QmitkMutualInformationMetricView.h" #include "QmitkMatchCardinalityMetricView.h" #include "QmitkKappaStatisticMetricView.h" #include "QmitkExhaustiveOptimizerView.h" #include "QmitkGradientDescentOptimizerView.h" #include "QmitkQuaternionRigidTransformGradientDescentOptimizerView.h" #include "QmitkLBFGSBOptimizerView.h" #include "QmitkOnePlusOneEvolutionaryOptimizerView.h" #include "QmitkPowellOptimizerView.h" #include "QmitkFRPROptimizerView.h" #include "QmitkRegularStepGradientDescentOptimizerView.h" #include "QmitkVersorTransformOptimizerView.h" #include "QmitkAmoebaOptimizerView.h" #include "QmitkConjugateGradientOptimizerView.h" #include "QmitkLBFGSOptimizerView.h" #include "QmitkSPSAOptimizerView.h" #include "QmitkVersorRigid3DTransformOptimizerView.h" QmitkRigidRegistrationSelectorView::QmitkRigidRegistrationSelectorView(QWidget* parent, Qt::WindowFlags f ) : QWidget( parent, f ), m_FixedNode(NULL), m_FixedMaskNode(NULL), m_MovingNode(NULL), m_MovingMaskNode(NULL), m_FixedDimension(0), m_MovingDimension(0), m_StopOptimization(false), m_GeometryItkPhysicalToWorldTransform(NULL), m_GeometryWorldToItkPhysicalTransform(NULL), m_MovingGeometry(NULL), m_ImageGeometry(NULL) { m_Controls.setupUi(parent); this->AddTransform(new QmitkTranslationTransformView(this, f)); this->AddTransform(new QmitkScaleTransformView(this, f)); this->AddTransform(new QmitkScaleLogarithmicTransformView(this, f)); this->AddTransform(new QmitkAffineTransformView(this, f)); this->AddTransform(new QmitkFixedCenterOfRotationAffineTransformView(this, f)); this->AddTransform(new QmitkEuler3DTransformView(this, f)); this->AddTransform(new QmitkCenteredEuler3DTransformView(this, f)); this->AddTransform(new QmitkQuaternionRigidTransformView(this, f)); this->AddTransform(new QmitkVersorTransformView(this, f)); this->AddTransform(new QmitkVersorRigid3DTransformView(this, f)); this->AddTransform(new QmitkScaleSkewVersor3DTransformView(this, f)); this->AddTransform(new QmitkSimilarity3DTransformView(this, f)); this->AddTransform(new QmitkRigid2DTransformView(this, f)); this->AddTransform(new QmitkCenteredRigid2DTransformView(this, f)); this->AddTransform(new QmitkEuler2DTransformView(this, f)); this->AddTransform(new QmitkSimilarity2DTransformView(this, f)); this->AddTransform(new QmitkCenteredSimilarity2DTransformView(this, f)); this->AddMetric(new QmitkMeanSquaresMetricView(this, f)); this->AddMetric(new QmitkNormalizedCorrelationMetricView(this, f)); this->AddMetric(new QmitkGradientDifferenceMetricView(this, f)); this->AddMetric(new QmitkKullbackLeiblerCompareHistogramMetricView(this, f)); this->AddMetric(new QmitkCorrelationCoefficientHistogramMetricView(this, f)); this->AddMetric(new QmitkMeanSquaresHistogramMetricView(this, f)); this->AddMetric(new QmitkMutualInformationHistogramMetricView(this, f)); this->AddMetric(new QmitkNormalizedMutualInformationHistogramMetricView(this, f)); this->AddMetric(new QmitkMattesMutualInformationMetricView(this, f)); this->AddMetric(new QmitkMeanReciprocalSquareDifferenceMetricView(this, f)); this->AddMetric(new QmitkMutualInformationMetricView(this, f)); this->AddMetric(new QmitkMatchCardinalityMetricView(this, f)); this->AddMetric(new QmitkKappaStatisticMetricView(this, f)); this->AddOptimizer(new QmitkExhaustiveOptimizerView(this, f)); this->AddOptimizer(new QmitkGradientDescentOptimizerView(this, f)); this->AddOptimizer(new QmitkQuaternionRigidTransformGradientDescentOptimizerView(this, f)); this->AddOptimizer(new QmitkLBFGSBOptimizerView(this, f)); this->AddOptimizer(new QmitkOnePlusOneEvolutionaryOptimizerView(this, f)); this->AddOptimizer(new QmitkPowellOptimizerView(this, f)); this->AddOptimizer(new QmitkFRPROptimizerView(this, f)); this->AddOptimizer(new QmitkRegularStepGradientDescentOptimizerView(this, f)); this->AddOptimizer(new QmitkVersorTransformOptimizerView(this, f)); this->AddOptimizer(new QmitkAmoebaOptimizerView(this, f)); this->AddOptimizer(new QmitkConjugateGradientOptimizerView(this, f)); this->AddOptimizer(new QmitkLBFGSOptimizerView(this, f)); this->AddOptimizer(new QmitkSPSAOptimizerView(this, f)); this->AddOptimizer(new QmitkVersorRigid3DTransformOptimizerView(this, f)); m_Observer = mitk::RigidRegistrationObserver::New(); m_Controls.m_TransformFrame->setEnabled(true); m_Controls.m_MetricFrame->setEnabled(true); m_Controls.m_OptimizerFrame->setEnabled(true); m_Controls.m_InterpolatorFrame->setEnabled(true); m_Controls.m_TransformFrame->hide(); m_Controls.m_MetricFrame->hide(); m_Controls.m_OptimizerFrame->hide(); m_Controls.m_InterpolatorFrame->hide(); m_Controls.m_TransformBox->setCurrentIndex(0); m_Controls.m_MetricBox->setCurrentIndex(0); m_Controls.m_OptimizerBox->setCurrentIndex(0); m_Controls.m_TransformWidgetStack->setCurrentIndex(0); m_Controls.m_MetricWidgetStack->setCurrentIndex(0); m_Controls.m_OptimizerWidgetStack->setCurrentIndex(0); /// and show the selected views this->TransformSelected(m_Controls.m_TransformBox->currentIndex()); this->MetricSelected(m_Controls.m_MetricBox->currentIndex()); this->OptimizerSelected(m_Controls.m_OptimizerBox->currentIndex()); //// create connections connect( m_Controls.m_TransformGroup, SIGNAL(clicked(bool)), m_Controls.m_TransformFrame, SLOT(setVisible(bool))); connect( m_Controls.m_TransformBox, SIGNAL(activated(int)), m_Controls.m_TransformWidgetStack, SLOT(setCurrentIndex(int))); connect( m_Controls.m_TransformBox, SIGNAL(activated(int)), this, SLOT(TransformSelected(int))); connect( m_Controls.m_MetricBox, SIGNAL(activated(int)), this, SLOT(MetricSelected(int))); connect( m_Controls.m_OptimizerBox, SIGNAL(activated(int)), this, SLOT(OptimizerSelected(int))); connect( m_Controls.m_MetricGroup, SIGNAL(clicked(bool)), m_Controls.m_MetricFrame, SLOT(setVisible(bool))); connect( m_Controls.m_MetricBox, SIGNAL(activated(int)), m_Controls.m_MetricWidgetStack, SLOT(setCurrentIndex(int))); connect( m_Controls.m_OptimizerGroup, SIGNAL(clicked(bool)), m_Controls.m_OptimizerFrame, SLOT(setVisible(bool))); connect( m_Controls.m_OptimizerBox, SIGNAL(activated(int)), m_Controls.m_OptimizerWidgetStack, SLOT(setCurrentIndex(int))); connect( m_Controls.m_InterpolatorGroup, SIGNAL(toggled(bool)), m_Controls.m_InterpolatorFrame, SLOT(setVisible(bool))); m_Preset = new mitk::RigidRegistrationPreset(); m_Preset->LoadPreset(); this->DoLoadRigidRegistrationPreset("AffineMutualInformationGradientDescent"); } QmitkRigidRegistrationSelectorView::~QmitkRigidRegistrationSelectorView() { } /// this method starts the registration process void QmitkRigidRegistrationSelectorView::CalculateTransformation(unsigned int timestep) { if (m_FixedNode.IsNotNull() && m_MovingNode.IsNotNull()) { emit AddNewTransformationToUndoList(); mitk::Image::Pointer fimage = dynamic_cast(m_FixedNode->GetData())->Clone(); mitk::Image::Pointer mimage = dynamic_cast(m_MovingNode->GetData())->Clone(); mitk::Image::Pointer mmimage = NULL; mitk::Image::Pointer fmimage = NULL; if (m_MovingMaskNode.IsNotNull()) { mmimage = dynamic_cast(m_MovingMaskNode->GetData()); } if (m_FixedMaskNode.IsNotNull()) { fmimage = dynamic_cast(m_FixedMaskNode->GetData()); } mitk::ImageTimeSelector::Pointer its = mitk::ImageTimeSelector::New(); if(fimage->GetDimension()>3) { its->SetInput(fimage); its->SetTimeNr(timestep); its->Update(); fimage = its->GetOutput(); } if(mimage->GetDimension()>3) { its->SetInput(mimage); its->SetTimeNr(timestep); its->Update(); mimage = its->GetOutput(); } // Initial moving image geometry m_ImageGeometry = m_MovingNode->GetData()->GetGeometry()->Clone(); std::cout << "Moving Image Geometry (IndexToWorldTransform)" << std::endl; std::cout << m_ImageGeometry->GetIndexToWorldTransform()->GetMatrix(); mitk::Geometry3D::TransformType::InputPointType center = m_ImageGeometry->GetIndexToWorldTransform()->GetCenter(); std::cout << "center " << center[0] << " " << center[1] << " " << center[2] << std::endl; mitk::Geometry3D::TransformType::OutputVectorType offset = m_ImageGeometry->GetIndexToWorldTransform()->GetOffset(); std::cout << "offset " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl; std::cout << std::endl; // Fixed image geometry // mitk::AffineGeometryFrame3D::Pointer m_FixedGeometryCopy = m_FixedNode->GetData()->GetGeometry()->Clone(); // std::cout << "Fixed Image Geometry (IndexToWorldTransform)" << std::endl; // std::cout << m_FixedGeometryCopy->GetIndexToWorldTransform()->GetMatrix(); // center = m_FixedGeometryCopy->GetIndexToWorldTransform()->GetCenter(); // std::cout << "center " << center[0] << " " << center[1] << " " << center[2] << std::endl; // offset = m_FixedGeometryCopy->GetIndexToWorldTransform()->GetOffset(); // std::cout << "offset " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl; // std::cout << std::endl; // Calculate the World to ITK-Physical transform for the moving image m_MovingGeometry = m_MovingNode->GetData()->GetGeometry(); - unsigned long size; - size = m_MovingNodeChildren->Size(); - mitk::DataNode::Pointer childNode; - for (unsigned long i = 0; i < size; ++i) + // container that holds all derived moving data, that needs to be transformed with the transformation found by registration + if(m_MovingMaskNode.IsNotNull()) + { + m_ChildNodes.insert(std::pair(m_MovingMaskNode, m_MovingMaskNode->GetData()->GetGeometry())); + m_ChildNodes2.insert(std::pair(m_MovingMaskNode, m_MovingMaskNode->GetData()->GetGeometry()->Clone())); + } + + if(m_MovingNodeChildren.IsNotNull()) { - m_ChildNodes.insert(std::pair(m_MovingNodeChildren->GetElement(i), m_MovingNodeChildren->GetElement(i)->GetData()->GetGeometry())); - m_ChildNodes2.insert(std::pair(m_MovingNodeChildren->GetElement(i), m_MovingNodeChildren->GetElement(i)->GetData()->GetGeometry()->Clone())); + unsigned long size = 0; + size = m_MovingNodeChildren->Size(); + mitk::DataNode::Pointer childNode; + for (unsigned long i = 0; i < size; ++i) + { + m_ChildNodes.insert(std::pair(m_MovingNodeChildren->GetElement(i), m_MovingNodeChildren->GetElement(i)->GetData()->GetGeometry())); + m_ChildNodes2.insert(std::pair(m_MovingNodeChildren->GetElement(i), m_MovingNodeChildren->GetElement(i)->GetData()->GetGeometry()->Clone())); + } } m_GeometryWorldToItkPhysicalTransform = mitk::Geometry3D::TransformType::New(); GetWorldToItkPhysicalTransform(m_MovingGeometry, m_GeometryWorldToItkPhysicalTransform.GetPointer()); // std::cout << "Moving Image: World to ITK-physical transform" << std::endl; // std::cout << m_GeometryWorldToItkPhysicalTransform->GetMatrix(); // center = m_GeometryWorldToItkPhysicalTransform->GetCenter(); // std::cout << "center " << center[0] << " " << center[1] << " " << center[2] << std::endl; // offset = m_GeometryWorldToItkPhysicalTransform->GetOffset(); // std::cout << "offset " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl; // std::cout << std::endl; // Calculate the ITK-Physical to World transform for the fixed image m_GeometryItkPhysicalToWorldTransform = mitk::Geometry3D::TransformType::New(); mitk::Geometry3D::TransformType::Pointer fixedWorld2Phys = mitk::Geometry3D::TransformType::New(); GetWorldToItkPhysicalTransform(m_FixedNode->GetData()->GetGeometry(), fixedWorld2Phys.GetPointer()); fixedWorld2Phys->GetInverse(m_GeometryItkPhysicalToWorldTransform); // std::cout << "Fixed Image: ITK-physical to World transform" << std::endl; // std::cout << m_GeometryItkPhysicalToWorldTransform->GetMatrix(); // center = m_GeometryItkPhysicalToWorldTransform->GetCenter(); // std::cout << "center " << center[0] << " " << center[1] << " " << center[2] << std::endl; // offset = m_GeometryItkPhysicalToWorldTransform->GetOffset(); // std::cout << "offset " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl; // std::cout << std::endl; // init callback itk::ReceptorMemberCommand::Pointer command = itk::ReceptorMemberCommand::New(); command->SetCallbackFunction(this, &QmitkRigidRegistrationSelectorView::SetOptimizerValue); int observer = m_Observer->AddObserver( itk::AnyEvent(), command ); std::vector presets; // init registration method mitk::ImageRegistrationMethod::Pointer registration = mitk::ImageRegistrationMethod::New(); registration->SetObserver(m_Observer); registration->SetInterpolator(m_Controls.m_InterpolatorBox->currentIndex()); registration->SetReferenceImage(fimage); registration->SetInput(mimage); if (mmimage.IsNotNull()) { registration->SetMovingMask(mmimage); } if (fmimage.IsNotNull()) { registration->SetFixedMask(fmimage); } dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->SetFixedImage(dynamic_cast(m_FixedNode->GetData())); dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->SetMovingImage(dynamic_cast(m_MovingNode->GetData())); registration->SetOptimizerScales(dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->GetScales()); registration->SetTransform(dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->GetTransform()); dynamic_cast(m_Controls.m_MetricWidgetStack->currentWidget())->SetMovingImage(dynamic_cast(m_MovingNode->GetData())); registration->SetMetric(dynamic_cast(m_Controls.m_MetricWidgetStack->currentWidget())->GetMetric()); registration->SetOptimizer(dynamic_cast(m_Controls.m_OptimizerWidgetStack->currentWidget())->GetOptimizer()); double time(0.0); double tstart(0.0); tstart = clock(); try { registration->Update(); } catch (itk::ExceptionObject e) { MITK_INFO << "Caught exception: "<Progress(20); } time += clock() - tstart; time = time / CLOCKS_PER_SEC; //printOut of the Time MITK_INFO << "Registration Time: " << time; m_Observer->RemoveObserver(observer); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationSelectorView::SetFixedNode( mitk::DataNode * fixedNode ) { m_FixedNode = fixedNode; m_Controls.m_TransformBox->setCurrentIndex(m_Controls.m_TransformBox->currentIndex()); } void QmitkRigidRegistrationSelectorView::SetFixedDimension( int dimension ) { m_FixedDimension = dimension; } void QmitkRigidRegistrationSelectorView::SetMovingNode( mitk::DataNode * movingNode ) { m_MovingNode = movingNode; this->TransformSelected(m_Controls.m_TransformBox->currentIndex()); } void QmitkRigidRegistrationSelectorView::SetMovingDimension(int dimension ) { m_MovingDimension = dimension; } // this is a callback function that retrieves the current transformation // parameters after every step of progress in the optimizer. // depending on the choosen transformation, we construct a vtktransform // that will be applied to the geometry of the moving image. // the values are delivered by mitkRigidRgistrationObserver.cpp void QmitkRigidRegistrationSelectorView::SetOptimizerValue( const itk::EventObject & ) { if (m_StopOptimization) { m_Observer->SetStopOptimization(true); m_StopOptimization = false; } // retreive optimizer value for the current transformation double value = m_Observer->GetCurrentOptimizerValue(); // retreive current parameterset of the transformation itk::Array transformParams = m_Observer->GetCurrentTranslation(); // init an empty affine transformation that will be filled with // the corresponding transformation parameters in the following vtkMatrix4x4* vtkmatrix = vtkMatrix4x4::New(); vtkmatrix->Identity(); // init a transform that will be initialized with the vtkmatrix later vtkTransform* vtktransform = vtkTransform::New(); if (m_MovingNode.IsNotNull()) { vtktransform = dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->Transform(vtkmatrix, vtktransform, transformParams); // the retrieved transform goes from fixed to moving space. // invert the transform in order to go from moving to fixed space. vtkMatrix4x4* vtkmatrix_inv = vtkMatrix4x4::New(); vtktransform->GetInverse(vtkmatrix_inv); // now adapt the moving geometry accordingly m_MovingGeometry->GetIndexToWorldTransform()->SetIdentity(); // the next view lines: Phi(Phys2World)*Phi(Result)*Phi(World2Phy)*Phi(Initial) // set moving image geometry to registration result m_MovingGeometry->SetIndexToWorldTransformByVtkMatrix(vtkmatrix_inv); /*std::cout << std::endl; std::cout << m_MovingGeometry->GetIndexToWorldTransform()->GetMatrix(); mitk::Geometry3D::TransformType::OutputVectorType offset = m_MovingGeometry->GetIndexToWorldTransform()->GetOffset(); std::cout << "offset " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl;*/ #if !defined(ITK_IMAGE_BEHAVES_AS_ORIENTED_IMAGE) // the next few lines: Phi(Phys2World)*Phi(Result)*Phi(World2Phy)*Phi(Initial) // go to itk physical space before applying the registration result m_MovingGeometry->Compose(m_GeometryWorldToItkPhysicalTransform, 1); // right in the beginning, transform by initial moving image geometry m_MovingGeometry->Compose(m_ImageGeometry->GetIndexToWorldTransform(), 1); // in the end, go back to world space m_MovingGeometry->Compose(m_GeometryItkPhysicalToWorldTransform, 0); #else m_MovingGeometry->Compose(m_ImageGeometry->GetIndexToWorldTransform(), 1); #endif /*std::cout << std::endl << m_MovingGeometry->GetIndexToWorldTransform()->GetMatrix(); offset = m_MovingGeometry->GetIndexToWorldTransform()->GetOffset(); std::cout << "offset " << offset[0] << " " << offset[1] << " " << offset[2] << std::endl << std::endl;*/ // now adapt all children geometries accordingly if children exist std::map::iterator iter; std::map::iterator iter2; mitk::DataNode::Pointer childNode; for( iter = m_ChildNodes.begin(); iter != m_ChildNodes.end(); iter++ ) { childNode = (*iter).first; if (childNode.IsNotNull()) { mitk::Geometry3D* childGeometry; mitk::AffineGeometryFrame3D::Pointer childImageGeometry; // Calculate the World to ITK-Physical transform for the moving mask childGeometry = (*iter).second; iter2 = m_ChildNodes2.find(childNode); childImageGeometry = (*iter2).second; childGeometry->GetIndexToWorldTransform()->SetIdentity(); // the next view lines: Phi(Phys2World)*Phi(Result)*Phi(World2Phy)*Phi(Initial) // set moving mask geometry to registration result childGeometry->SetIndexToWorldTransformByVtkMatrix(vtkmatrix_inv); #if !defined(ITK_IMAGE_BEHAVES_AS_ORIENTED_IMAGE) // the next few lines: Phi(Phys2World)*Phi(Result)*Phi(World2Phy)*Phi(Initial) // go to itk physical space before applying the registration result childGeometry->Compose(m_GeometryWorldToItkPhysicalTransform, 1); // right in the beginning, transform by initial moving image geometry childGeometry->Compose(childImageGeometry->GetIndexToWorldTransform(), 1); // in the end, go back to world space childGeometry->Compose(m_GeometryItkPhysicalToWorldTransform, 0); #else childGeometry->Compose(childImageGeometry->GetIndexToWorldTransform(), 1); #endif } } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } emit OptimizerChanged(value); } /// this method is called whenever the combobox with the selectable transforms changes /// responsible for showing the selected transform parameters void QmitkRigidRegistrationSelectorView::TransformSelected( int transform ) { if (m_FixedNode.IsNotNull()) { dynamic_cast(m_Controls.m_TransformWidgetStack->widget(transform))->SetFixedImage(dynamic_cast(m_FixedNode->GetData())); } if (m_MovingNode.IsNotNull()) { dynamic_cast(m_Controls.m_TransformWidgetStack->widget(transform))->SetMovingImage(dynamic_cast(m_MovingNode->GetData())); } int numberOfTransformParameters = dynamic_cast(m_Controls.m_TransformWidgetStack->widget(transform))->GetNumberOfTransformParameters(); dynamic_cast(m_Controls.m_OptimizerWidgetStack->currentWidget())->SetNumberOfTransformParameters(numberOfTransformParameters); //set fixed height m_Controls.m_TransformWidgetStack->setFixedHeight( dynamic_cast(m_Controls.m_TransformWidgetStack->widget(transform))->minimumSizeHint().height() ); this->OptimizerSelected(m_Controls.m_OptimizerWidgetStack->currentIndex()); } /// this method is called whenever the combobox with the selectable metrics changes /// responsible for showing the selected metric parameters void QmitkRigidRegistrationSelectorView::MetricSelected( int metric ) { if (m_FixedNode.IsNotNull()) { dynamic_cast(m_Controls.m_MetricWidgetStack->widget(metric))->SetMovingImage(dynamic_cast(m_MovingNode->GetData())); } //set fixed height m_Controls.m_MetricWidgetStack->setFixedHeight( dynamic_cast(m_Controls.m_MetricWidgetStack->widget(metric))->minimumSizeHint().height() ); } /// this method is called whenever the combobox with the selectable optimizers changes /// responsible for showing the selected optimizer parameters void QmitkRigidRegistrationSelectorView::OptimizerSelected( int optimizer ) { int numberOfTransformParameters = dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->GetNumberOfTransformParameters(); dynamic_cast(m_Controls.m_OptimizerWidgetStack->widget(optimizer))->SetNumberOfTransformParameters(numberOfTransformParameters); //set fixed height m_Controls.m_OptimizerWidgetStack->setFixedHeight( dynamic_cast(m_Controls.m_OptimizerWidgetStack->widget(optimizer))->minimumSizeHint().height() ); } void QmitkRigidRegistrationSelectorView::LoadRigidRegistrationParameter() { this->DoLoadRigidRegistrationParameter(); } void QmitkRigidRegistrationSelectorView::DoLoadRigidRegistrationParameter() { std::map > existingPresets; existingPresets = m_Preset->getTransformValuesPresets(); std::map >::iterator iter; std::list presets; for( iter = existingPresets.begin(); iter != existingPresets.end(); iter++ ) { presets.push_back( (*iter).first ); } if (presets.empty()) { QMessageBox::warning( NULL, "RigidRegistrationParameters.xml", "RigidRegistrationParameters.xml is empty/does not exist. There are no presets to select."); return; } presets.sort(); // ask about the name to load a preset QmitkLoadPresetDialog dialog( this, 0, "Load Preset", presets ); // needs a QWidget as parent int dialogReturnValue = dialog.exec(); if ( dialogReturnValue == QDialog::Rejected ) return; // user clicked cancel or pressed Esc or something similar this->DoLoadRigidRegistrationPreset(dialog.GetPresetName()); } void QmitkRigidRegistrationSelectorView::DoLoadRigidRegistrationPreset(std::string presetName) { itk::Array transformValues; transformValues = m_Preset->getTransformValues(presetName); m_Controls.m_TransformGroup->setChecked(true); m_Controls.m_TransformFrame->setVisible(true); m_Controls.m_TransformBox->setCurrentIndex((int)transformValues[0]); m_Controls.m_TransformWidgetStack->setCurrentIndex((int)transformValues[0]); this->TransformSelected((int)transformValues[0]); itk::Array transformValuesForGUI; transformValuesForGUI.SetSize(transformValues.Size()); transformValuesForGUI.fill(0); for (unsigned int i = 1; i < transformValues.Size(); i++) { transformValuesForGUI[i-1] = transformValues[i]; } dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->SetTransformParameters(transformValuesForGUI); itk::Array metricValues; metricValues = m_Preset->getMetricValues(presetName); m_Controls.m_MetricGroup->setChecked(true); m_Controls.m_MetricFrame->setVisible(true); m_Controls.m_MetricBox->setCurrentIndex((int)metricValues[0]); m_Controls.m_MetricWidgetStack->setCurrentIndex((int)metricValues[0]); this->MetricSelected((int)metricValues[0]); itk::Array metricValuesForGUI; metricValuesForGUI.SetSize(metricValues.Size()); metricValuesForGUI.fill(0); for (unsigned int i = 1; i < metricValues.Size(); i++) { metricValuesForGUI[i-1] = metricValues[i]; } dynamic_cast(m_Controls.m_MetricWidgetStack->currentWidget())->SetMetricParameters(metricValuesForGUI); itk::Array optimizerValues; optimizerValues = m_Preset->getOptimizerValues(presetName); m_Controls.m_OptimizerGroup->setChecked(true); m_Controls.m_OptimizerFrame->setVisible(true); m_Controls.m_OptimizerBox->setCurrentIndex((int)optimizerValues[0]); m_Controls.m_OptimizerWidgetStack->setCurrentIndex((int)optimizerValues[0]); this->OptimizerSelected((int)optimizerValues[0]); itk::Array optimizerValuesForGUI; optimizerValuesForGUI.SetSize(optimizerValues.Size()); optimizerValuesForGUI.fill(0); for (unsigned int i = 1; i < optimizerValues.Size(); i++) { optimizerValuesForGUI[i-1] = optimizerValues[i]; } dynamic_cast(m_Controls.m_OptimizerWidgetStack->currentWidget())->SetOptimizerParameters(optimizerValuesForGUI); itk::Array interpolatorValues; interpolatorValues = m_Preset->getInterpolatorValues(presetName); m_Controls.m_InterpolatorGroup->setChecked(true); m_Controls.m_InterpolatorFrame->setVisible(true); m_Controls.m_InterpolatorBox->setCurrentIndex((int)interpolatorValues[0]); } void QmitkRigidRegistrationSelectorView::SaveRigidRegistrationParameter() { this->DoSaveRigidRegistrationParameter(); } void QmitkRigidRegistrationSelectorView::DoSaveRigidRegistrationParameter() { bool ok; QString text = QInputDialog::getText(this, "Save Parameter Preset", "Enter name for preset:", QLineEdit::Normal, QString::null, &ok ); if ( ok ) { std::map > existingPresets; existingPresets = m_Preset->getTransformValuesPresets(); std::map >::iterator iter = existingPresets.find(std::string((const char*)text.toLatin1())); if (iter != existingPresets.end()) { QMessageBox::critical( this, "Preset definition", "Presetname already exists."); return; } if (text.isEmpty()) { QMessageBox::critical( this, "Preset definition", "Presetname has to be set.\n" "You have to enter a Presetname." ); return; } itk::Array transformValues; transformValues.SetSize(25); transformValues.fill(0); transformValues[0] = m_Controls.m_TransformBox->currentIndex(); itk::Array transformValuesFromGUI = dynamic_cast(m_Controls.m_TransformWidgetStack->currentWidget())->GetTransformParameters(); for (unsigned int i = 0; i < transformValuesFromGUI.Size(); i++) { transformValues[i+1] = transformValuesFromGUI[i]; } std::map > transformMap; transformMap = m_Preset->getTransformValuesPresets(); transformMap[std::string((const char*)text.toLatin1())] = transformValues; itk::Array metricValues; metricValues.SetSize(25); metricValues.fill(0); metricValues[0] = m_Controls.m_MetricBox->currentIndex(); itk::Array metricValuesFromGUI = dynamic_cast(m_Controls.m_MetricWidgetStack->currentWidget())->GetMetricParameters(); for (unsigned int i = 0; i < metricValuesFromGUI.Size(); i++) { metricValues[i+1] = metricValuesFromGUI[i]; } std::map > metricMap; metricMap = m_Preset->getMetricValuesPresets(); metricMap[std::string((const char*)text.toLatin1())] = metricValues; itk::Array optimizerValues; optimizerValues.SetSize(25); optimizerValues.fill(0); optimizerValues[0] = m_Controls.m_OptimizerBox->currentIndex(); itk::Array optimizerValuesFromGUI = dynamic_cast(m_Controls.m_OptimizerWidgetStack->currentWidget())->GetOptimizerParameters(); for (unsigned int i = 0; i < optimizerValuesFromGUI.Size(); i++) { optimizerValues[i+1] = optimizerValuesFromGUI[i]; } std::map > optimizerMap; optimizerMap = m_Preset->getOptimizerValuesPresets(); optimizerMap[std::string((const char*)text.toLatin1())] = optimizerValues; itk::Array interpolatorValues; interpolatorValues.SetSize(25); interpolatorValues.fill(0); interpolatorValues[0] = m_Controls.m_InterpolatorBox->currentIndex(); std::map > interpolatorMap; interpolatorMap = m_Preset->getInterpolatorValuesPresets(); interpolatorMap[std::string((const char*)text.toLatin1())] = interpolatorValues; m_Preset->newPresets(transformMap, metricMap, optimizerMap, interpolatorMap); } else { // user pressed Cancel } } void QmitkRigidRegistrationSelectorView::StopOptimization(bool stopOptimization) { m_StopOptimization = stopOptimization; } int QmitkRigidRegistrationSelectorView::GetSelectedTransform() { return m_Controls.m_TransformBox->currentIndex(); } void QmitkRigidRegistrationSelectorView::SetFixedMaskNode( mitk::DataNode * fixedMaskNode ) { m_FixedMaskNode = fixedMaskNode; this->TransformSelected(m_Controls.m_TransformBox->currentIndex()); } void QmitkRigidRegistrationSelectorView::SetMovingMaskNode( mitk::DataNode * movingMaskNode ) { m_MovingMaskNode = movingMaskNode; this->TransformSelected(m_Controls.m_TransformBox->currentIndex()); } void QmitkRigidRegistrationSelectorView::SetMovingNodeChildren(mitk::DataStorage::SetOfObjects::ConstPointer children) { m_MovingNodeChildren = children; } void QmitkRigidRegistrationSelectorView::AddTransform(QmitkRigidRegistrationTransformsGUIBase* transform) { m_Controls.m_TransformBox->addItem(transform->GetName()); int i = 0; if (!dynamic_cast(m_Controls.m_TransformWidgetStack->widget(i))) { m_Controls.m_TransformWidgetStack->addWidget(transform); m_Controls.m_TransformWidgetStack->removeWidget(m_Controls.m_TransformWidgetStack->widget(i)); transform->SetupUI(m_Controls.m_TransformWidgetStack->widget(i)); } else { i = m_Controls.m_TransformWidgetStack->addWidget(transform); transform->SetupUI(m_Controls.m_TransformWidgetStack->widget(i)); } } void QmitkRigidRegistrationSelectorView::AddMetric(QmitkRigidRegistrationMetricsGUIBase* metric) { m_Controls.m_MetricBox->addItem(metric->GetName()); int i = 0; if (!dynamic_cast(m_Controls.m_MetricWidgetStack->widget(i))) { m_Controls.m_MetricWidgetStack->addWidget(metric); m_Controls.m_MetricWidgetStack->removeWidget(m_Controls.m_MetricWidgetStack->widget(i)); metric->SetupUI(m_Controls.m_MetricWidgetStack->widget(i)); } else { i = m_Controls.m_MetricWidgetStack->addWidget(metric); metric->SetupUI(m_Controls.m_MetricWidgetStack->widget(i)); } } void QmitkRigidRegistrationSelectorView::AddOptimizer(QmitkRigidRegistrationOptimizerGUIBase* optimizer) { m_Controls.m_OptimizerBox->addItem(optimizer->GetName()); int i = 0; if (!dynamic_cast(m_Controls.m_OptimizerWidgetStack->widget(i))) { m_Controls.m_OptimizerWidgetStack->addWidget(optimizer); m_Controls.m_OptimizerWidgetStack->removeWidget(m_Controls.m_OptimizerWidgetStack->widget(i)); optimizer->SetupUI(m_Controls.m_OptimizerWidgetStack->widget(i)); } else { i = m_Controls.m_OptimizerWidgetStack->addWidget(optimizer); optimizer->SetupUI(m_Controls.m_OptimizerWidgetStack->widget(i)); } } diff --git a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp index d4e63c5d88..dde7603abb 100644 --- a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp +++ b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.cpp @@ -1,1409 +1,1465 @@ /*=================================================================== 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. ===================================================================*/ +// Qmitk includes #include "QmitkRigidRegistrationView.h" - #include "QmitkStdMultiWidget.h" + +// MITK includes +#include "mitkDataNodeObject.h" +#include +#include "mitkManualSegmentationToSurfaceFilter.h" +#include +#include +#include "mitkNodePredicateDataType.h" +#include "mitkNodePredicateAnd.h" +#include "mitkNodePredicateProperty.h" + +// QT includes #include "qinputdialog.h" #include "qmessagebox.h" #include "qcursor.h" #include "qapplication.h" #include "qradiobutton.h" #include "qslider.h" #include "qtooltip.h" +// VTK includes #include -#include "mitkDataNodeObject.h" -#include +// ITK includes +#include +// BlueBerry includes #include "berryIWorkbenchWindow.h" #include "berryISelectionService.h" -#include "mitkManualSegmentationToSurfaceFilter.h" -#include - -#include - - -#include - - const std::string QmitkRigidRegistrationView::VIEW_ID = "org.mitk.views.rigidregistration"; using namespace berry; struct SelListenerRigidRegistration : ISelectionListener { berryObjectMacro(SelListenerRigidRegistration); SelListenerRigidRegistration(QmitkRigidRegistrationView* view) { m_View = view; } void DoSelectionChanged(ISelection::ConstPointer selection) { -// if (!m_View->IsVisible()) -// return; // save current selection in member variable m_View->m_CurrentSelection = selection.Cast(); // do something with the selected items if(m_View->m_CurrentSelection) { if (m_View->m_CurrentSelection->Size() != 2) { if (m_View->m_FixedNode.IsNull() || m_View->m_MovingNode.IsNull()) { m_View->m_Controls.m_StatusLabel->show(); m_View->m_Controls.TextLabelFixed->hide(); m_View->m_Controls.m_FixedLabel->hide(); m_View->m_Controls.TextLabelMoving->hide(); m_View->m_Controls.m_MovingLabel->hide(); + m_View->m_Controls.m_UseMaskingCB->hide(); m_View->m_Controls.m_OpacityLabel->setEnabled(false); m_View->m_Controls.m_OpacitySlider->setEnabled(false); m_View->m_Controls.label->setEnabled(false); m_View->m_Controls.label_2->setEnabled(false); m_View->m_Controls.m_ShowRedGreenValues->setEnabled(false); m_View->m_Controls.m_SwitchImages->hide(); } } else { m_View->m_Controls.m_StatusLabel->hide(); bool foundFixedImage = false; mitk::DataNode::Pointer fixedNode; // iterate selection for (IStructuredSelection::iterator i = m_View->m_CurrentSelection->Begin(); i != m_View->m_CurrentSelection->End(); ++i) { // extract datatree node if (mitk::DataNodeObject::Pointer nodeObj = i->Cast()) { mitk::DataNode::Pointer node = nodeObj->GetDataNode(); // only look at interesting types if(QString("Image").compare(node->GetData()->GetNameOfClass())==0) { if (dynamic_cast(node->GetData())->GetDimension() == 4) { m_View->m_Controls.m_StatusLabel->show(); QMessageBox::information( NULL, "RigidRegistration", "Only 2D or 3D images can be processed.", QMessageBox::Ok ); return; } if (foundFixedImage == false) { fixedNode = node; foundFixedImage = true; } else { - m_View->SetImagesVisible(selection); + // m_View->SetImagesVisible(selection); m_View->FixedSelected(fixedNode); m_View->MovingSelected(node); m_View->m_Controls.m_StatusLabel->hide(); m_View->m_Controls.TextLabelFixed->show(); m_View->m_Controls.m_FixedLabel->show(); m_View->m_Controls.TextLabelMoving->show(); m_View->m_Controls.m_MovingLabel->show(); + m_View->m_Controls.m_UseMaskingCB->show(); m_View->m_Controls.m_OpacityLabel->setEnabled(true); m_View->m_Controls.m_OpacitySlider->setEnabled(true); m_View->m_Controls.label->setEnabled(true); m_View->m_Controls.label_2->setEnabled(true); m_View->m_Controls.m_ShowRedGreenValues->setEnabled(true); } } else { m_View->m_Controls.m_StatusLabel->show(); return; } } } } } else if (m_View->m_FixedNode.IsNull() || m_View->m_MovingNode.IsNull()) { m_View->m_Controls.m_StatusLabel->show(); } } void SelectionChanged(IWorkbenchPart::Pointer part, ISelection::ConstPointer selection) { // check, if selection comes from datamanager if (part) { QString partname(part->GetPartName().c_str()); - if(partname.compare("Datamanager")==0) + if(partname.compare("Data Manager")==0) { // apply selection DoSelectionChanged(selection); } } } QmitkRigidRegistrationView* m_View; }; QmitkRigidRegistrationView::QmitkRigidRegistrationView(QObject * /*parent*/, const char * /*name*/) : QmitkFunctionality(), m_MultiWidget(NULL), m_MovingNode(NULL), m_MovingMaskNode(NULL), m_FixedNode(NULL), m_FixedMaskNode(NULL), - m_ShowRedGreen(false), m_Opacity(0.5), m_OriginalOpacity(1.0), m_Deactivated(false),m_FixedDimension(0), m_MovingDimension(0) +m_ShowRedGreen(false), m_Opacity(0.5), m_OriginalOpacity(1.0), m_Deactivated(false),m_FixedDimension(0), m_MovingDimension(0) { m_TranslateSliderPos[0] = 0; m_TranslateSliderPos[1] = 0; m_TranslateSliderPos[2] = 0; m_RotateSliderPos[0] = 0; m_RotateSliderPos[1] = 0; m_RotateSliderPos[2] = 0; m_ScaleSliderPos[0] = 0; m_ScaleSliderPos[1] = 0; m_ScaleSliderPos[2] = 0; translationParams = new int[3]; rotationParams = new int[3]; scalingParams = new int[3]; m_TimeStepperAdapter = NULL; this->GetDataStorage()->RemoveNodeEvent.AddListener(mitk::MessageDelegate1 ( this, &QmitkRigidRegistrationView::DataNodeHasBeenRemoved )); } QmitkRigidRegistrationView::~QmitkRigidRegistrationView() { if(m_SelListener.IsNotNull()) { berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; } + + this->GetDataStorage()->RemoveNodeEvent.RemoveListener(mitk::MessageDelegate1 ( this, &QmitkRigidRegistrationView::DataNodeHasBeenRemoved )); + } void QmitkRigidRegistrationView::CreateQtPartControl(QWidget* parent) { m_Controls.setupUi(parent); m_Controls.m_ManualFrame->hide(); m_Controls.timeSlider->hide(); m_Controls.TextLabelFixed->hide(); m_Controls.m_FixedLabel->hide(); m_Controls.TextLabelMoving->hide(); m_Controls.m_MovingLabel->hide(); - m_Controls.m_UseFixedImageMask->hide(); - m_Controls.m_UseMovingImageMask->hide(); + //m_Controls.m_UseFixedImageMask->hide(); + //m_Controls.m_UseMovingImageMask->hide(); + m_Controls.m_UseMaskingCB->hide(); m_Controls.m_OpacityLabel->setEnabled(false); m_Controls.m_OpacitySlider->setEnabled(false); m_Controls.label->setEnabled(false); m_Controls.label_2->setEnabled(false); m_Controls.m_ShowRedGreenValues->setEnabled(false); m_Controls.m_SwitchImages->hide(); if (m_Controls.m_RigidTransform->currentIndex() == 1) { m_Controls.frame->show(); } else { m_Controls.frame->hide(); } m_Controls.m_ManualFrame->setEnabled(false); m_Parent->setEnabled(false); + mitk::NodePredicateAnd::Pointer andPred = // we want binary images in the selectors + mitk::NodePredicateAnd::New(mitk::NodePredicateDataType::New("Image"), + mitk::NodePredicateProperty::New("binary", mitk::BoolProperty::New(true))); + + m_Controls.m_FixedImageCB->SetPredicate(andPred); + m_Controls.m_FixedImageCB->SetDataStorage(this->GetDataStorage()); + m_Controls.m_FixedImageCB->hide(); + m_Controls.m_FixedMaskLB->hide(); + + m_Controls.m_MovingImageCB->SetPredicate(andPred); + m_Controls.m_MovingImageCB->SetDataStorage(this->GetDataStorage()); + m_Controls.m_MovingImageCB->hide(); + m_Controls.m_MovingMaskLB->hide(); + this->CreateConnections(); this->CheckCalculateEnabled(); } void QmitkRigidRegistrationView::StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget) { m_Parent->setEnabled(true); m_MultiWidget = &stdMultiWidget; m_MultiWidget->SetWidgetPlanesVisibility(true); } void QmitkRigidRegistrationView::StdMultiWidgetNotAvailable() { m_Parent->setEnabled(false); m_MultiWidget = NULL; } void QmitkRigidRegistrationView::CreateConnections() { connect( m_Controls.m_ManualRegistrationCheckbox, SIGNAL(toggled(bool)), this, SLOT(ShowManualRegistrationFrame(bool))); connect((QObject*)(m_Controls.m_SwitchImages),SIGNAL(clicked()),this,SLOT(SwitchImages())); connect(m_Controls.m_ShowRedGreenValues, SIGNAL(toggled(bool)), this, SLOT(ShowRedGreen(bool))); connect(m_Controls.m_ShowContour, SIGNAL(toggled(bool)), this, SLOT(EnableContour(bool))); - connect(m_Controls.m_UseFixedImageMask, SIGNAL(toggled(bool)), this, SLOT(UseFixedMaskImageChecked(bool))); - connect(m_Controls.m_UseMovingImageMask, SIGNAL(toggled(bool)), this, SLOT(UseMovingMaskImageChecked(bool))); + //connect(m_Controls.m_UseFixedImageMask, SIGNAL(toggled(bool)), this, SLOT(UseFixedMaskImageChecked(bool))); + //connect(m_Controls.m_UseMovingImageMask, SIGNAL(toggled(bool)), this, SLOT(UseMovingMaskImageChecked(bool))); connect(m_Controls.m_RigidTransform, SIGNAL(currentChanged(int)), this, SLOT(TabChanged(int))); connect(m_Controls.m_OpacitySlider, SIGNAL(valueChanged(int)), this, SLOT(OpacityUpdate(int))); connect(m_Controls.m_ContourSlider, SIGNAL(sliderReleased()), this, SLOT(ShowContour())); connect(m_Controls.m_CalculateTransformation, SIGNAL(clicked()), this, SLOT(Calculate())); connect(m_Controls.m_UndoTransformation,SIGNAL(clicked()),this,SLOT(UndoTransformation())); connect(m_Controls.m_RedoTransformation,SIGNAL(clicked()),this,SLOT(RedoTransformation())); connect(m_Controls.m_AutomaticTranslation,SIGNAL(clicked()),this,SLOT(AlignCenters())); connect(m_Controls.m_StopOptimization,SIGNAL(clicked()), this , SLOT(StopOptimizationClicked())); connect(m_Controls.m_XTransSlider, SIGNAL(valueChanged(int)), this, SLOT(xTrans_valueChanged(int))); connect(m_Controls.m_YTransSlider, SIGNAL(valueChanged(int)), this, SLOT(yTrans_valueChanged(int))); connect(m_Controls.m_ZTransSlider, SIGNAL(valueChanged(int)), this, SLOT(zTrans_valueChanged(int))); connect(m_Controls.m_XRotSlider, SIGNAL(valueChanged(int)), this, SLOT(xRot_valueChanged(int))); connect(m_Controls.m_YRotSlider, SIGNAL(valueChanged(int)), this, SLOT(yRot_valueChanged(int))); connect(m_Controls.m_ZRotSlider, SIGNAL(valueChanged(int)), this, SLOT(zRot_valueChanged(int))); connect(m_Controls.m_XScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(xScale_valueChanged(int))); connect(m_Controls.m_YScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(yScale_valueChanged(int))); connect(m_Controls.m_ZScaleSlider, SIGNAL(valueChanged(int)), this, SLOT(zScale_valueChanged(int))); connect(m_Controls.m_LoadRigidRegistrationParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(LoadRigidRegistrationParameter())); connect(m_Controls.m_SaveRigidRegistrationParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(SaveRigidRegistrationParameter())); connect(m_Controls.m_LoadRigidRegistrationTestParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(LoadRigidRegistrationTestParameter())); connect(m_Controls.m_SaveRigidRegistrationTestParameter, SIGNAL(clicked()), m_Controls.qmitkRigidRegistrationSelector1, SLOT(SaveRigidRegistrationTestParameter())); connect(m_Controls.qmitkRigidRegistrationSelector1,SIGNAL(OptimizerChanged(double)),this,SLOT(SetOptimizerValue( double ))); connect(m_Controls.qmitkRigidRegistrationSelector1,SIGNAL(TransformChanged()),this,SLOT(CheckCalculateEnabled())); connect(m_Controls.qmitkRigidRegistrationSelector1,SIGNAL(AddNewTransformationToUndoList()),this,SLOT(AddNewTransformationToUndoList())); + connect(m_Controls.m_UseMaskingCB, SIGNAL(stateChanged(int)),this,SLOT(OnUseMaskingChanged(int))); + connect(m_Controls.m_FixedImageCB, SIGNAL(OnSelectionChanged(const mitk::DataNode*)),this,SLOT(OnFixedMaskImageChanged(const mitk::DataNode*))); + connect(m_Controls.m_MovingImageCB, SIGNAL(OnSelectionChanged(const mitk::DataNode*)),this,SLOT(OnMovingMaskImageChanged(const mitk::DataNode*))); } void QmitkRigidRegistrationView::Activated() { m_Deactivated = false; mitk::RenderingManager::GetInstance()->RequestUpdateAll(); QmitkFunctionality::Activated(); if (m_SelListener.IsNull()) { m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/*"org.mitk.views.datamanager",*/ m_SelListener); berry::ISelection::ConstPointer sel( this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); m_CurrentSelection = sel.Cast(); m_SelListener.Cast()->DoSelectionChanged(sel); } this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); this->ClearTransformationLists(); this->CheckCalculateEnabled(); /* m_Deactivated = false; - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - QmitkFunctionality::Activated(); - if (m_SelListener.IsNull()) - { - m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/ *"org.mitk.views.datamanager",* / m_SelListener); - berry::ISelection::ConstPointer sel( - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); - m_CurrentSelection = sel.Cast(); - m_SelListener.Cast()->DoSelectionChanged(sel); - } - this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); - this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); - this->ClearTransformationLists(); - this->CheckCalculateEnabled();*/ + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + QmitkFunctionality::Activated(); + if (m_SelListener.IsNull()) + { + m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener(/ *"org.mitk.views.datamanager",* / m_SelListener); + berry::ISelection::ConstPointer sel( + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); + m_CurrentSelection = sel.Cast(); + m_SelListener.Cast()->DoSelectionChanged(sel); + } + this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); + this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); + this->ClearTransformationLists(); + this->CheckCalculateEnabled();*/ } void QmitkRigidRegistrationView::Visible() { /* m_Deactivated = false; mitk::RenderingManager::GetInstance()->RequestUpdateAll(); QmitkFunctionality::Activated(); if (m_SelListener.IsNull()) { - m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener("org.mitk.views.datamanager", m_SelListener); - berry::ISelection::ConstPointer sel( - this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); - m_CurrentSelection = sel.Cast(); - m_SelListener.Cast()->DoSelectionChanged(sel); + m_SelListener = berry::ISelectionListener::Pointer(new SelListenerRigidRegistration(this)); + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->AddPostSelectionListener("org.mitk.views.datamanager", m_SelListener); + berry::ISelection::ConstPointer sel( + this->GetSite()->GetWorkbenchWindow()->GetSelectionService()->GetSelection("org.mitk.views.datamanager")); + m_CurrentSelection = sel.Cast(); + m_SelListener.Cast()->DoSelectionChanged(sel); } this->OpacityUpdate(m_Controls.m_OpacitySlider->value()); this->ShowRedGreen(m_Controls.m_ShowRedGreenValues->isChecked()); this->ClearTransformationLists(); this->CheckCalculateEnabled();*/ } void QmitkRigidRegistrationView::Deactivated() { m_Deactivated = true; this->SetImageColor(false); if (m_FixedNode.IsNotNull()) m_FixedNode->SetOpacity(1.0); m_FixedNode = NULL; m_MovingNode = NULL; this->ClearTransformationLists(); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; /* m_Deactivated = true; - this->SetImageColor(false); - m_FixedNode = NULL; - m_MovingNode = NULL; - this->ClearTransformationLists(); - berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); - if(s) - s->RemovePostSelectionListener(m_SelListener); - m_SelListener = NULL; - mitk::RenderingManager::GetInstance()->RequestUpdateAll(); - QmitkFunctionality::Deactivated();*/ - + this->SetImageColor(false); + m_FixedNode = NULL; + m_MovingNode = NULL; + this->ClearTransformationLists(); + berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); + if(s) + s->RemovePostSelectionListener(m_SelListener); + m_SelListener = NULL; + mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + QmitkFunctionality::Deactivated();*/ } void QmitkRigidRegistrationView::Hidden() { /*m_Deactivated = true; this->SetImageColor(false); m_FixedNode = NULL; m_MovingNode = NULL; this->ClearTransformationLists(); berry::ISelectionService* s = GetSite()->GetWorkbenchWindow()->GetSelectionService(); if(s) - s->RemovePostSelectionListener(m_SelListener); + s->RemovePostSelectionListener(m_SelListener); m_SelListener = NULL; //mitk::RenderingManager::GetInstance()->RequestUpdateAll(); //QmitkFunctionality::Deactivated();*/ } void QmitkRigidRegistrationView::DataNodeHasBeenRemoved(const mitk::DataNode* node) { if(node == m_FixedNode || node == m_MovingNode) { m_Controls.m_StatusLabel->show(); m_Controls.TextLabelFixed->hide(); m_Controls.m_FixedLabel->hide(); m_Controls.TextLabelMoving->hide(); m_Controls.m_MovingLabel->hide(); m_Controls.m_OpacityLabel->setEnabled(false); m_Controls.m_OpacitySlider->setEnabled(false); m_Controls.label->setEnabled(false); m_Controls.label_2->setEnabled(false); m_Controls.m_ShowRedGreenValues->setEnabled(false); m_Controls.m_SwitchImages->hide(); } else if(node == m_ContourHelperNode) { // can this cause a memory leak? m_ContourHelperNode = NULL; } } void QmitkRigidRegistrationView::FixedSelected(mitk::DataNode::Pointer fixedImage) { if (m_FixedNode.IsNotNull()) { this->SetImageColor(false); m_FixedNode->SetOpacity(1.0); } m_FixedNode = fixedImage; if (m_FixedNode.IsNotNull()) { m_FixedNode->SetOpacity(0.5); m_FixedNode->SetVisibility(true); m_Controls.TextLabelFixed->setText(QString::fromStdString(m_FixedNode->GetName())); m_Controls.m_FixedLabel->show(); m_Controls.TextLabelFixed->show(); m_Controls.m_SwitchImages->show(); mitk::ColorProperty::Pointer colorProperty; colorProperty = dynamic_cast(m_FixedNode->GetProperty("color")); if ( colorProperty.IsNotNull() ) { m_FixedColor = colorProperty->GetColor(); } this->SetImageColor(m_ShowRedGreen); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); if (dynamic_cast(m_FixedNode->GetData())) { m_FixedDimension = dynamic_cast(m_FixedNode->GetData())->GetDimension(); m_Controls.qmitkRigidRegistrationSelector1->SetFixedDimension(m_FixedDimension); m_Controls.qmitkRigidRegistrationSelector1->SetFixedNode(m_FixedNode); } - bool hasMask = false; - mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_FixedNode); - unsigned long size; - size = children->Size(); - for (unsigned long i = 0; i < size; ++i) - { - mitk::BoolProperty::Pointer isMaskProp = dynamic_cast(children->GetElement(i)->GetProperty("binary")); - if(isMaskProp.IsNotNull() && isMaskProp->GetValue() == true) - { - m_FixedMaskNode = children->GetElement(i); - hasMask = true; - this->CheckForMaskImages(); - break; - } - } - if (!hasMask) - { - this->CheckForMaskImages(); - m_FixedMaskNode = NULL; - } + // what's about masking? + m_Controls.m_UseMaskingCB->show(); // Modify slider range mitk::Image::Pointer image = dynamic_cast(m_FixedNode->GetData()); int min = (int)image->GetStatistics()->GetScalarValueMin(); int max = (int)image->GetStatistics()->GetScalarValueMax(); m_Controls.m_ContourSlider->setRange(min, max); // Set slider to a default value int avg = (min+max) / 2; m_Controls.m_ContourSlider->setSliderPosition(avg); m_Controls.m_ThresholdLabel->setText(QString::number(avg)); } else { m_Controls.m_FixedLabel->hide(); m_Controls.TextLabelFixed->hide(); m_Controls.m_SwitchImages->hide(); } this->CheckCalculateEnabled(); if(this->GetActiveStdMultiWidget()) { m_TimeStepperAdapter = new QmitkStepperAdapter((QObject*) m_Controls.timeSlider, m_MultiWidget->GetTimeNavigationController()->GetTime(), "sliceNavigatorTimeFromRigidRegistration"); connect( m_TimeStepperAdapter, SIGNAL( Refetch() ), this, SLOT( UpdateTimestep() ) ); } } void QmitkRigidRegistrationView::MovingSelected(mitk::DataNode::Pointer movingImage) { if (m_MovingNode.IsNotNull()) { m_MovingNode->SetOpacity(m_OriginalOpacity); if (m_FixedNode == m_MovingNode) m_FixedNode->SetOpacity(0.5); this->SetImageColor(false); } m_MovingNode = movingImage; if (m_MovingNode.IsNotNull()) { m_MovingNode->SetVisibility(true); m_Controls.TextLabelMoving->setText(QString::fromStdString(m_MovingNode->GetName())); m_Controls.m_MovingLabel->show(); m_Controls.TextLabelMoving->show(); mitk::ColorProperty::Pointer colorProperty; colorProperty = dynamic_cast(m_MovingNode->GetProperty("color")); if ( colorProperty.IsNotNull() ) { m_MovingColor = colorProperty->GetColor(); } this->SetImageColor(m_ShowRedGreen); m_MovingNode->GetFloatProperty("opacity", m_OriginalOpacity); this->OpacityUpdate(m_Opacity); - bool hasMask = false; - mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); - m_Controls.qmitkRigidRegistrationSelector1->SetMovingNodeChildren(children); - unsigned long size; - size = children->Size(); - for (unsigned long i = 0; i < size; ++i) - { - mitk::BoolProperty::Pointer isMaskProp = dynamic_cast(children->GetElement(i)->GetProperty("binary")); - if(isMaskProp.IsNotNull() && isMaskProp->GetValue() == true) - { - m_MovingMaskNode = children->GetElement(i); - hasMask = true; - this->CheckForMaskImages(); - break; - } - } - if (!hasMask) - { - m_MovingMaskNode = NULL; - this->CheckForMaskImages(); - } + // what's about masking? + m_Controls.m_UseMaskingCB->show(); } else { m_Controls.m_MovingLabel->hide(); m_Controls.TextLabelMoving->hide(); + m_Controls.m_UseMaskingCB->hide(); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); this->MovingImageChanged(); this->CheckCalculateEnabled(); } bool QmitkRigidRegistrationView::CheckCalculate() { if(m_MovingNode==m_FixedNode) return false; return true; } void QmitkRigidRegistrationView::AddNewTransformationToUndoList() { mitk::BaseData::Pointer movingData = m_MovingNode->GetData(); - m_UndoGeometryList.push_back(static_cast(movingData->GetGeometry(0)->Clone().GetPointer())); - unsigned long size; + m_UndoGeometryList.push_back(static_cast(movingData->GetGeometry()->Clone().GetPointer())); + + GeometryMapType childGeometries = GeometryMapType(); + if(m_MovingMaskNode.IsNotNull()) + { + childGeometries.insert(std::pair(m_MovingMaskNode, + static_cast(m_MovingMaskNode->GetData()->GetGeometry()->Clone().GetPointer()))); + } + mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); - size = children->Size(); - std::map childGeometries; - for (unsigned long i = 0; i < size; ++i) + if(children.IsNotNull() && children->Size() != 0) { - childGeometries.insert(std::pair(children->GetElement(i), children->GetElement(i)->GetData()->GetGeometry())); + unsigned long size; + size = children->Size(); + for (unsigned long i = 0; i < size; ++i) + { + childGeometries.insert(std::pair(children->GetElement(i), + static_cast(children->GetElement(i)->GetData()->GetGeometry()->Clone().GetPointer()))); + } } m_UndoChildGeometryList.push_back(childGeometries); m_RedoGeometryList.clear(); m_RedoChildGeometryList.clear(); this->SetUndoEnabled(true); this->SetRedoEnabled(false); } void QmitkRigidRegistrationView::UndoTransformation() { if(!m_UndoGeometryList.empty()) { mitk::BaseData::Pointer movingData = m_MovingNode->GetData(); m_RedoGeometryList.push_back(static_cast(movingData->GetGeometry(0)->Clone().GetPointer())); - unsigned long size; + + unsigned long size = 0; + GeometryMapType childGeometries = GeometryMapType(); + if(m_MovingMaskNode.IsNotNull()) + { + ++size; + } + mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); - size = children->Size(); - std::map childGeometries; + size += children->Size(); + for (unsigned long i = 0; i < size; ++i) { - childGeometries.insert(std::pair(children->GetElement(i), children->GetElement(i)->GetData()->GetGeometry())); + if(i==0) + { + childGeometries.insert(std::pair(m_MovingMaskNode, + static_cast(m_MovingMaskNode->GetData()->GetGeometry()->Clone().GetPointer()))); + } + else + { + childGeometries.insert(std::pair(children->GetElement(i), + static_cast(children->GetElement(i)->GetData()->GetGeometry()->Clone().GetPointer()))); + } } + m_RedoChildGeometryList.push_back(childGeometries); movingData->SetGeometry(m_UndoGeometryList.back()); m_UndoGeometryList.pop_back(); - std::map oldChildGeometries; + GeometryMapType oldChildGeometries; oldChildGeometries = m_UndoChildGeometryList.back(); m_UndoChildGeometryList.pop_back(); - std::map::iterator iter; + + GeometryMapType::iterator iter; for (unsigned long j = 0; j < size; ++j) { - iter = oldChildGeometries.find(children->GetElement(j)); - children->GetElement(j)->GetData()->SetGeometry((*iter).second); + if(j == 0) // we have put the geometry for the moving mask at position one + { + iter = oldChildGeometries.find(m_MovingMaskNode); + mitk::Geometry3D* geo = static_cast((*iter).second); + m_MovingMaskNode->GetData()->SetGeometry(geo); + m_MovingMaskNode->GetData()->GetTimeSlicedGeometry()->UpdateInformation(); + } + else + { + iter = oldChildGeometries.find(children->GetElement(j)); + children->GetElement(j)->GetData()->SetGeometry((*iter).second); + } } //\FIXME when geometry is substituted the matrix referenced by the actor created by the mapper //is still pointing to the old one. Workaround: delete mapper - m_MovingNode->SetMapper(1, NULL); - mitk::RenderingManager::GetInstance()->RequestUpdate(m_MultiWidget->mitkWidget4->GetRenderWindow()); - movingData->GetTimeSlicedGeometry()->UpdateInformation(); - this->SetRedoEnabled(true); + //m_MovingNode->SetMapper(1, NULL); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + + this->SetRedoEnabled(true); } if(!m_UndoGeometryList.empty()) { this->SetUndoEnabled(true); } else { this->SetUndoEnabled(false); } this->CheckCalculateEnabled(); } void QmitkRigidRegistrationView::RedoTransformation() { if(!m_RedoGeometryList.empty()) { mitk::BaseData::Pointer movingData = m_MovingNode->GetData(); m_UndoGeometryList.push_back(static_cast(movingData->GetGeometry(0)->Clone().GetPointer())); - unsigned long size; + + unsigned long size = 0; + GeometryMapType childGeometries = GeometryMapType(); + if(m_MovingMaskNode.IsNotNull()) + { + ++size; + } + mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); - size = children->Size(); - std::map childGeometries; + size += children->Size(); + for (unsigned long i = 0; i < size; ++i) { - childGeometries.insert(std::pair(children->GetElement(i), children->GetElement(i)->GetData()->GetGeometry())); + if(i == 0) + { + childGeometries.insert(std::pair(m_MovingMaskNode, + static_cast(m_MovingMaskNode->GetData()->GetGeometry()->Clone().GetPointer()))); + } + else + { + childGeometries.insert(std::pair(children->GetElement(i), + static_cast(children->GetElement(i)->GetData()->GetGeometry()->Clone().GetPointer()))); + } } + m_UndoChildGeometryList.push_back(childGeometries); movingData->SetGeometry(m_RedoGeometryList.back()); m_RedoGeometryList.pop_back(); - std::map oldChildGeometries; + GeometryMapType oldChildGeometries; oldChildGeometries = m_RedoChildGeometryList.back(); m_RedoChildGeometryList.pop_back(); - std::map::iterator iter; + GeometryMapType::iterator iter; for (unsigned long j = 0; j < size; ++j) { - iter = oldChildGeometries.find(children->GetElement(j)); - children->GetElement(j)->GetData()->SetGeometry((*iter).second); + if(j == 0) + { + iter = oldChildGeometries.find(m_MovingMaskNode); + m_MovingMaskNode->GetData()->SetGeometry((*iter).second); + } + else + { + iter = oldChildGeometries.find(children->GetElement(j)); + children->GetElement(j)->GetData()->SetGeometry((*iter).second); + } } - //\FIXME when geometry is substituted the matrix referenced by the actor created by the mapper - //is still pointing to the old one. Workaround: delete mapper - m_MovingNode->SetMapper(1, NULL); - mitk::RenderingManager::GetInstance()->RequestUpdate(m_MultiWidget->mitkWidget4->GetRenderWindow()); - movingData->GetTimeSlicedGeometry()->UpdateInformation(); - this->SetUndoEnabled(true); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); + + this->SetUndoEnabled(true); } if(!m_RedoGeometryList.empty()) { this->SetRedoEnabled(true); } else { this->SetRedoEnabled(false); } } void QmitkRigidRegistrationView::ShowRedGreen(bool redGreen) { m_ShowRedGreen = redGreen; this->SetImageColor(m_ShowRedGreen); } void QmitkRigidRegistrationView::EnableContour(bool show) { if(show) ShowContour(); // Can happen when the m_ContourHelperNode was deleted before and now the show contour checkbox is turned off if(m_ContourHelperNode.IsNull()) return; m_Controls.m_ContourSlider->setEnabled(show); m_ContourHelperNode->SetProperty("visible", mitk::BoolProperty::New(show)); mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkRigidRegistrationView::ShowContour() { int threshold = m_Controls.m_ContourSlider->value(); bool show = m_Controls.m_ShowContour->isChecked(); if(m_FixedNode.IsNull() || !show) return; // Update the label next to the slider m_Controls.m_ThresholdLabel->setText(QString::number(threshold)); mitk::Image::Pointer image = dynamic_cast(m_FixedNode->GetData()); typedef itk::Image FloatImageType; typedef itk::Image ShortImageType; // Create a binary image using the given treshold typedef itk::BinaryThresholdImageFilter ThresholdFilterType; FloatImageType::Pointer floatImage = FloatImageType::New(); mitk::CastToItkImage(image, floatImage); ThresholdFilterType::Pointer thresholdFilter = ThresholdFilterType::New(); thresholdFilter->SetInput(floatImage); thresholdFilter->SetLowerThreshold(threshold); thresholdFilter->SetUpperThreshold((int)image->GetStatistics()->GetScalarValueMax()); thresholdFilter->SetInsideValue(1); thresholdFilter->SetOutsideValue(0); thresholdFilter->Update(); ShortImageType::Pointer binaryImage = thresholdFilter->GetOutput(); mitk::Image::Pointer mitkBinaryImage = mitk::Image::New(); mitk::CastToMitkImage(binaryImage, mitkBinaryImage); // Create a contour from the binary image mitk::ManualSegmentationToSurfaceFilter::Pointer surfaceFilter = mitk::ManualSegmentationToSurfaceFilter::New(); surfaceFilter->SetInput( mitkBinaryImage ); surfaceFilter->SetThreshold( 1 ); //expects binary image with zeros and ones surfaceFilter->SetUseGaussianImageSmooth(false); // apply gaussian to thresholded image ? surfaceFilter->SetMedianFilter3D(false); // apply median to segmentation before marching cubes ? surfaceFilter->SetDecimate( mitk::ImageToSurfaceFilter::NoDecimation ); surfaceFilter->UpdateLargestPossibleRegion(); // calculate normals for nicer display mitk::Surface::Pointer surface = surfaceFilter->GetOutput(); if(m_ContourHelperNode.IsNull()) { m_ContourHelperNode = mitk::DataNode::New(); m_ContourHelperNode->SetData(surface); m_ContourHelperNode->SetProperty("opacity", mitk::FloatProperty::New(1.0) ); m_ContourHelperNode->SetProperty("line width", mitk::IntProperty::New(2) ); m_ContourHelperNode->SetProperty("scalar visibility", mitk::BoolProperty::New(false) ); m_ContourHelperNode->SetProperty( "name", mitk::StringProperty::New("surface") ); m_ContourHelperNode->SetProperty("color", mitk::ColorProperty::New(1.0, 0.0, 0.0)); m_ContourHelperNode->SetBoolProperty("helper object", true); this->GetDataStorage()->Add(m_ContourHelperNode); } else { m_ContourHelperNode->SetData(surface); } mitk::RenderingManager::GetInstance()->ForceImmediateUpdateAll(); } void QmitkRigidRegistrationView::SetImageColor(bool redGreen) { if (!redGreen && m_FixedNode.IsNotNull()) { m_FixedNode->SetColor(m_FixedColor); } if (!redGreen && m_MovingNode.IsNotNull()) { m_MovingNode->SetColor(m_MovingColor); } if (redGreen && m_FixedNode.IsNotNull()) { m_FixedNode->SetColor(1.0f, 0.0f, 0.0f); } if (redGreen && m_MovingNode.IsNotNull()) { m_MovingNode->SetColor(0.0f, 1.0f, 0.0f); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkRigidRegistrationView::OpacityUpdate(float opacity) { m_Opacity = opacity; if (m_MovingNode.IsNotNull()) { m_MovingNode->SetOpacity(m_Opacity); } mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkRigidRegistrationView::OpacityUpdate(int opacity) { float fValue = ((float)opacity)/100.0f; this->OpacityUpdate(fValue); } void QmitkRigidRegistrationView::ClearTransformationLists() { this->SetUndoEnabled(false); this->SetRedoEnabled(false); m_UndoGeometryList.clear(); m_UndoChildGeometryList.clear(); m_RedoGeometryList.clear(); m_RedoChildGeometryList.clear(); } void QmitkRigidRegistrationView::Translate(int* translateVector) { if (m_MovingNode.IsNotNull()) { mitk::Vector3D translateVec; translateVec[0] = translateVector[0] - m_TranslateSliderPos[0]; translateVec[1] = translateVector[1] - m_TranslateSliderPos[1]; translateVec[2] = translateVector[2] - m_TranslateSliderPos[2]; m_TranslateSliderPos[0] = translateVector[0]; m_TranslateSliderPos[1] = translateVector[1]; m_TranslateSliderPos[2] = translateVector[2]; vtkMatrix4x4* translationMatrix = vtkMatrix4x4::New(); translationMatrix->Identity(); double (*transMatrix)[4] = translationMatrix->Element; transMatrix[0][3] = -translateVec[0]; transMatrix[1][3] = -translateVec[1]; transMatrix[2][3] = -translateVec[2]; translationMatrix->Invert(); m_MovingNode->GetData()->GetGeometry()->Compose( translationMatrix ); m_MovingNode->GetData()->Modified(); mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); unsigned long size; size = children->Size(); mitk::DataNode::Pointer childNode; for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( translationMatrix ); childNode->GetData()->Modified(); } m_RedoGeometryList.clear(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationView::Rotate(int* rotateVector) { if (m_MovingNode.IsNotNull()) { mitk::Vector3D rotateVec; rotateVec[0] = rotateVector[0] - m_RotateSliderPos[0]; rotateVec[1] = rotateVector[1] - m_RotateSliderPos[1]; rotateVec[2] = rotateVector[2] - m_RotateSliderPos[2]; m_RotateSliderPos[0] = rotateVector[0]; m_RotateSliderPos[1] = rotateVector[1]; m_RotateSliderPos[2] = rotateVector[2]; vtkMatrix4x4* rotationMatrix = vtkMatrix4x4::New(); vtkMatrix4x4* translationMatrix = vtkMatrix4x4::New(); rotationMatrix->Identity(); translationMatrix->Identity(); double (*rotMatrix)[4] = rotationMatrix->Element; double (*transMatrix)[4] = translationMatrix->Element; mitk::Point3D centerBB = m_MovingNode->GetData()->GetGeometry()->GetCenter(); transMatrix[0][3] = centerBB[0]; transMatrix[1][3] = centerBB[1]; transMatrix[2][3] = centerBB[2]; translationMatrix->Invert(); m_MovingNode->GetData()->GetGeometry()->Compose( translationMatrix ); mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); unsigned long size; size = children->Size(); mitk::DataNode::Pointer childNode; for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( translationMatrix ); childNode->GetData()->Modified(); } double radianX = rotateVec[0] * vnl_math::pi / 180; double radianY = rotateVec[1] * vnl_math::pi / 180; double radianZ = rotateVec[2] * vnl_math::pi / 180; if ( rotateVec[0] != 0 ) { rotMatrix[1][1] = cos( radianX ); rotMatrix[1][2] = -sin( radianX ); rotMatrix[2][1] = sin( radianX ); rotMatrix[2][2] = cos( radianX ); } else if ( rotateVec[1] != 0 ) { rotMatrix[0][0] = cos( radianY ); rotMatrix[0][2] = sin( radianY ); rotMatrix[2][0] = -sin( radianY ); rotMatrix[2][2] = cos( radianY ); } else if ( rotateVec[2] != 0 ) { rotMatrix[0][0] = cos( radianZ ); rotMatrix[0][1] = -sin( radianZ ); rotMatrix[1][0] = sin( radianZ ); rotMatrix[1][1] = cos( radianZ ); } m_MovingNode->GetData()->GetGeometry()->Compose( rotationMatrix ); for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( rotationMatrix ); childNode->GetData()->Modified(); } translationMatrix->Invert(); m_MovingNode->GetData()->GetGeometry()->Compose( translationMatrix ); for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( rotationMatrix ); childNode->GetData()->Modified(); } m_MovingNode->GetData()->Modified(); m_RedoGeometryList.clear(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationView::Scale(int* scaleVector) { if (m_MovingNode.IsNotNull()) { mitk::Vector3D scaleVec; scaleVec[0] = scaleVector[0] - m_ScaleSliderPos[0]; scaleVec[1] = scaleVector[1] - m_ScaleSliderPos[1]; scaleVec[2] = scaleVector[2] - m_ScaleSliderPos[2]; m_ScaleSliderPos[0] = scaleVector[0]; m_ScaleSliderPos[1] = scaleVector[1]; m_ScaleSliderPos[2] = scaleVector[2]; vtkMatrix4x4* scalingMatrix = vtkMatrix4x4::New(); scalingMatrix->Identity(); double (*scaleMatrix)[4] = scalingMatrix->Element; if (scaleVec[0] >= 0) { for(int i = 0; i= 0) { for(int i = 0; i= 0) { for(int i = 0; iInvert(); m_MovingNode->GetData()->GetGeometry()->Compose( scalingMatrix ); m_MovingNode->GetData()->Modified(); mitk::DataStorage::SetOfObjects::ConstPointer children = this->GetDataStorage()->GetDerivations(m_MovingNode); unsigned long size; size = children->Size(); mitk::DataNode::Pointer childNode; for (unsigned long i = 0; i < size; ++i) { childNode = children->GetElement(i); childNode->GetData()->GetGeometry()->Compose( scalingMatrix ); childNode->GetData()->Modified(); } m_RedoGeometryList.clear(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } } void QmitkRigidRegistrationView::AlignCenters() { if (m_FixedNode.IsNotNull() && m_MovingNode.IsNotNull()) { mitk::Point3D fixedPoint = m_FixedNode->GetData()->GetGeometry()->GetCenter(); mitk::Point3D movingPoint = m_MovingNode->GetData()->GetGeometry()->GetCenter(); mitk::Vector3D translateVec; translateVec = fixedPoint - movingPoint; m_Controls.m_XTransSlider->setValue((int)m_Controls.m_XTransSlider->value() + (int)translateVec[0]); m_Controls.m_YTransSlider->setValue((int)m_Controls.m_YTransSlider->value() + (int)translateVec[1]); m_Controls.m_ZTransSlider->setValue((int)m_Controls.m_ZTransSlider->value() + (int)translateVec[2]); } } void QmitkRigidRegistrationView::SetUndoEnabled( bool enable ) { m_Controls.m_UndoTransformation->setEnabled(enable); } void QmitkRigidRegistrationView::SetRedoEnabled( bool enable ) { m_Controls.m_RedoTransformation->setEnabled(enable); } void QmitkRigidRegistrationView::CheckCalculateEnabled() { if (m_FixedNode.IsNotNull() && m_MovingNode.IsNotNull()) { m_Controls.m_ManualFrame->setEnabled(true); m_Controls.m_CalculateTransformation->setEnabled(true); if ( (m_FixedDimension != m_MovingDimension && std::max(m_FixedDimension, m_MovingDimension) != 4) || m_FixedDimension < 2 /*|| m_FixedDimension > 3*/) { m_Controls.m_CalculateTransformation->setEnabled(false); } else if (m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() < 5 && (m_FixedDimension < 2) /*|| m_FixedDimension > 3)*/) { m_Controls.m_CalculateTransformation->setEnabled(false); } else if ((m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() > 4 && m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() < 13) && !(m_FixedDimension > 2)) { m_Controls.m_CalculateTransformation->setEnabled(false); } else if (m_Controls.qmitkRigidRegistrationSelector1->GetSelectedTransform() > 12 && m_FixedDimension != 2) { m_Controls.m_CalculateTransformation->setEnabled(false); } } else { m_Controls.m_CalculateTransformation->setEnabled(false); m_Controls.m_ManualFrame->setEnabled(false); } } void QmitkRigidRegistrationView::xTrans_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { translationParams[0]=v; translationParams[1]=m_Controls.m_YTransSlider->value(); translationParams[2]=m_Controls.m_ZTransSlider->value(); Translate(translationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::yTrans_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { translationParams[0]=m_Controls.m_XTransSlider->value(); translationParams[1]=v; translationParams[2]=m_Controls.m_ZTransSlider->value(); Translate(translationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::zTrans_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { translationParams[0]=m_Controls.m_XTransSlider->value(); translationParams[1]=m_Controls.m_YTransSlider->value(); translationParams[2]=v; Translate(translationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::xRot_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { rotationParams[0]=v; rotationParams[1]=m_Controls.m_YRotSlider->value(); rotationParams[2]=m_Controls.m_ZRotSlider->value(); Rotate(rotationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::yRot_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { rotationParams[0]=m_Controls.m_XRotSlider->value(); rotationParams[1]=v; rotationParams[2]=m_Controls.m_ZRotSlider->value(); Rotate(rotationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::zRot_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { rotationParams[0]=m_Controls.m_XRotSlider->value(); rotationParams[1]=m_Controls.m_YRotSlider->value(); rotationParams[2]=v; Rotate(rotationParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::xScale_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { scalingParams[0]=v; scalingParams[1]=m_Controls.m_YScaleSlider->value(); scalingParams[2]=m_Controls.m_ZScaleSlider->value(); Scale(scalingParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::yScale_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { scalingParams[0]=m_Controls.m_XScaleSlider->value(); scalingParams[1]=v; scalingParams[2]=m_Controls.m_ZScaleSlider->value(); Scale(scalingParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::zScale_valueChanged( int v ) { if (m_MovingNode.IsNotNull()) { scalingParams[0]=m_Controls.m_XScaleSlider->value(); scalingParams[1]=m_Controls.m_YScaleSlider->value(); scalingParams[2]=v; Scale(scalingParams); } else { MovingImageChanged(); } } void QmitkRigidRegistrationView::MovingImageChanged() { if (dynamic_cast(m_MovingNode->GetData())) { m_Controls.m_XTransSlider->setValue(0); m_Controls.m_YTransSlider->setValue(0); m_Controls.m_ZTransSlider->setValue(0); translationParams[0]=0; translationParams[1]=0; translationParams[2]=0; m_Controls.m_XRotSlider->setValue(0); m_Controls.m_YRotSlider->setValue(0); m_Controls.m_ZRotSlider->setValue(0); rotationParams[0]=0; rotationParams[1]=0; rotationParams[2]=0; m_Controls.m_XScaleSlider->setValue(0); m_Controls.m_YScaleSlider->setValue(0); m_Controls.m_ZScaleSlider->setValue(0); scalingParams[0]=0; scalingParams[1]=0; scalingParams[2]=0; m_MovingDimension = dynamic_cast(m_MovingNode->GetData())->GetDimension(); m_Controls.qmitkRigidRegistrationSelector1->SetMovingDimension(m_MovingDimension); m_Controls.qmitkRigidRegistrationSelector1->SetMovingNode(m_MovingNode); this->CheckCalculateEnabled(); } } void QmitkRigidRegistrationView::Calculate() { m_Controls.qmitkRigidRegistrationSelector1->SetFixedNode(m_FixedNode); m_Controls.qmitkRigidRegistrationSelector1->SetMovingNode(m_MovingNode); - if (m_FixedMaskNode.IsNotNull() && m_Controls.m_UseFixedImageMask->isChecked()) + if (m_FixedMaskNode.IsNotNull() && m_Controls.m_UseMaskingCB->isChecked()) { m_Controls.qmitkRigidRegistrationSelector1->SetFixedMaskNode(m_FixedMaskNode); } else { m_Controls.qmitkRigidRegistrationSelector1->SetFixedMaskNode(NULL); } - if (m_MovingMaskNode.IsNotNull() && m_Controls.m_UseMovingImageMask->isChecked()) + if (m_MovingMaskNode.IsNotNull() && m_Controls.m_UseMaskingCB->isChecked()) { m_Controls.qmitkRigidRegistrationSelector1->SetMovingMaskNode(m_MovingMaskNode); } else { m_Controls.qmitkRigidRegistrationSelector1->SetMovingMaskNode(NULL); } m_Controls.frame_2->setEnabled(false); m_Controls.frame_3->setEnabled(false); m_Controls.m_CalculateTransformation->setEnabled(false); m_Controls.m_StopOptimization->setEnabled(true); m_Controls.qmitkRigidRegistrationSelector1->CalculateTransformation(((QmitkSliderNavigatorWidget*)m_Controls.timeSlider)->GetPos()); m_Controls.m_StopOptimization->setEnabled(false); m_Controls.frame_2->setEnabled(true); m_Controls.frame_3->setEnabled(true); m_Controls.m_CalculateTransformation->setEnabled(true); m_Controls.qmitkRigidRegistrationSelector1->StopOptimization(false); } void QmitkRigidRegistrationView::SetOptimizerValue( double value ) { m_Controls.m_OptimizerValueLCD->display(value); } void QmitkRigidRegistrationView::StopOptimizationClicked() { m_Controls.qmitkRigidRegistrationSelector1->StopOptimization(true); } void QmitkRigidRegistrationView::UpdateTimestep() { mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkRigidRegistrationView::ShowManualRegistrationFrame(bool show) { if (show) { m_Controls.m_ManualFrame->show(); } else { m_Controls.m_ManualFrame->hide(); } } void QmitkRigidRegistrationView::SetImagesVisible(berry::ISelection::ConstPointer /*selection*/) { if (this->m_CurrentSelection->Size() == 0) { // show all images mitk::DataStorage::SetOfObjects::ConstPointer setOfObjects = this->GetDataStorage()->GetAll(); for (mitk::DataStorage::SetOfObjects::ConstIterator nodeIt = setOfObjects->Begin() ; nodeIt != setOfObjects->End(); ++nodeIt) // for each node { if ( (nodeIt->Value().IsNotNull()) && (nodeIt->Value()->GetProperty("visible")) && dynamic_cast(nodeIt->Value()->GetData())==NULL) { nodeIt->Value()->SetVisibility(true); } } } else { // hide all images mitk::DataStorage::SetOfObjects::ConstPointer setOfObjects = this->GetDataStorage()->GetAll(); for (mitk::DataStorage::SetOfObjects::ConstIterator nodeIt = setOfObjects->Begin() ; nodeIt != setOfObjects->End(); ++nodeIt) // for each node { if ( (nodeIt->Value().IsNotNull()) && (nodeIt->Value()->GetProperty("visible")) && dynamic_cast(nodeIt->Value()->GetData())==NULL) { nodeIt->Value()->SetVisibility(false); } } } } -void QmitkRigidRegistrationView::CheckForMaskImages() -{ - if (m_FixedMaskNode.IsNotNull()) - { - m_Controls.m_UseFixedImageMask->show(); - } - else - { - m_Controls.m_UseFixedImageMask->hide(); - } - if (m_MovingMaskNode.IsNotNull()) - { - m_Controls.m_UseMovingImageMask->show(); - } - else - { - m_Controls.m_UseMovingImageMask->hide(); - } -} - -void QmitkRigidRegistrationView::UseFixedMaskImageChecked(bool checked) -{ - if (checked) - { - m_FixedMaskNode->SetVisibility(true); - } - else - { - m_FixedMaskNode->SetVisibility(false); - } -} - -void QmitkRigidRegistrationView::UseMovingMaskImageChecked(bool checked) -{ - if (checked) - { - m_MovingMaskNode->SetVisibility(true); - } - else - { - m_MovingMaskNode->SetVisibility(false); - } -} - void QmitkRigidRegistrationView::TabChanged(int index) { if (index == 0) { m_Controls.frame->hide(); } else { m_Controls.frame->show(); } } void QmitkRigidRegistrationView::SwitchImages() { mitk::DataNode::Pointer newMoving = m_FixedNode; mitk::DataNode::Pointer newFixed = m_MovingNode; this->FixedSelected(newFixed); this->MovingSelected(newMoving); if(m_ContourHelperNode.IsNotNull()) { - // Update the contour ShowContour(); + } + + if(m_Controls.m_UseMaskingCB->isChecked()) + { + mitk::DataNode::Pointer tempMovingMask = NULL; + mitk::DataNode::Pointer tempFixedMask = NULL; + if(m_FixedMaskNode.IsNotNull()) // it is initialized + { + tempFixedMask = m_Controls.m_FixedImageCB->GetSelectedNode(); + } + if(m_MovingMaskNode.IsNotNull()) // it is initialized + { + tempMovingMask = m_Controls.m_MovingImageCB->GetSelectedNode(); + } + m_Controls.m_FixedImageCB->SetSelectedNode(tempMovingMask); + m_Controls.m_MovingImageCB->SetSelectedNode(tempFixedMask); } +} +void QmitkRigidRegistrationView::OnUseMaskingChanged( int state ) +{ + if(state == Qt::Checked) + { + m_Controls.m_FixedImageCB->show(); + m_Controls.m_MovingImageCB->show(); + m_Controls.m_MovingMaskLB->show(); + m_Controls.m_FixedMaskLB->show(); + } + else + { + m_Controls.m_FixedImageCB->hide(); + m_Controls.m_MovingImageCB->hide(); + m_Controls.m_MovingMaskLB->hide(); + m_Controls.m_FixedMaskLB->hide(); + + m_FixedMaskNode = NULL; + m_MovingMaskNode = NULL; + } } + +void QmitkRigidRegistrationView::OnFixedMaskImageChanged( const mitk::DataNode* node ) +{ + if(m_Controls.m_UseMaskingCB->isChecked()) + m_FixedMaskNode = const_cast(node); + else + m_FixedMaskNode = NULL; +} + +void QmitkRigidRegistrationView::OnMovingMaskImageChanged( const mitk::DataNode* node ) +{ + if(m_Controls.m_UseMaskingCB->isChecked()) + m_MovingMaskNode = const_cast(node); + else + m_MovingMaskNode = NULL; +} \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.h b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.h index d268ab2fa1..c08c790b56 100644 --- a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.h +++ b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationView.h @@ -1,308 +1,323 @@ /*=================================================================== 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 QMITKRIGIDREGISTRATION_H #define QMITKRIGIDREGISTRATION_H #include "QmitkFunctionality.h" #include "ui_QmitkRigidRegistrationViewControls.h" #include "berryISelectionListener.h" #include "berryIStructuredSelection.h" #include // Time Slider related #include /*! \brief This functionality allows you to register 2D as well as 3D images in a rigid manner. Register means to align two images, so that they become as similar as possible. Therefore you can select from different transforms, metrics and optimizers. Registration results will directly be applied to the Moving Image. \sa QmitkFunctionality \ingroup Functionalities \ingroup RigidRegistration \author Daniel Stein */ class REGISTRATION_EXPORT QmitkRigidRegistrationView : public QmitkFunctionality { friend struct SelListenerRigidRegistration; Q_OBJECT public: static const std::string VIEW_ID; /*! \brief default constructor */ QmitkRigidRegistrationView(QObject *parent=0, const char *name=0); /*! \brief default destructor */ virtual ~QmitkRigidRegistrationView(); /*! \brief method for creating the applications main widget */ virtual void CreateQtPartControl(QWidget *parent); /*! \brief Sets the StdMultiWidget and connects it to the functionality. */ virtual void StdMultiWidgetAvailable (QmitkStdMultiWidget &stdMultiWidget); /*! \brief Removes the StdMultiWidget and disconnects it from the functionality. */ virtual void StdMultiWidgetNotAvailable(); /*! \brief method for creating the connections of main and control widget */ virtual void CreateConnections(); /*! \brief Method which is called when this functionality is selected in MITK */ virtual void Activated(); /*! \brief Method which is called whenever the functionality is deselected in MITK */ virtual void Deactivated(); virtual void Visible(); virtual void Hidden(); void DataNodeHasBeenRemoved(const mitk::DataNode* node); signals: protected slots: /*! * sets the fixed Image according to TreeNodeSelector widget */ void FixedSelected(mitk::DataNode::Pointer fixedImage); /*! * sets the moving Image according to TreeNodeSelector widget */ void MovingSelected(mitk::DataNode::Pointer movingImage); /*! * checks if registration is possible */ bool CheckCalculate(); /*! * \brief Undo the last registration. */ void UndoTransformation(); /*! * \brief Redo the last registration */ void RedoTransformation(); /*! * \brief Adds a new Transformation to the undo list and enables the undo button. */ void AddNewTransformationToUndoList(); /*! * \brief Translates the moving image in x, y and z direction given by translateVector * * @param translateVector Contains the translation in x, y and z direction. */ void Translate(int* translateVector); /*! * \brief Rotates the moving image in x, y and z direction given by rotateVector * * @param rotateVector Contains the rotation around x, y and z axis. */ void Rotate(int* rotateVector); /*! * \brief Scales the moving image in x, y and z direction given by scaleVector * * @param scaleVector Contains the scaling around x, y and z axis. */ void Scale(int* scaleVector); /*! * \brief Automatically aligns the image centers. */ void AlignCenters(); /*! * \brief Stores whether the image will be shown in gray values or in red for fixed image and green for moving image * @param show if true, then images will be shown in red and green */ void ShowRedGreen(bool show); /*! * \brief Draws the contour of the fixed image according to a threshold * @param show if true, then images will be shown in red and green */ void ShowContour(); /*! * \brief Stores whether the contour of the fixed image will be shhown * @param show if true, the contour of the fixed image is shown */ void EnableContour(bool show); /*! * \brief Changes the visibility of the manual registration methods accordingly to the checkbox "Manual Registration" in GUI * @param show if true, then manual registration methods will be shown */ void ShowManualRegistrationFrame(bool show); /*! * \brief Sets the selected opacity for moving image * @param opacity the selected opacity */ void OpacityUpdate(float opacity); /*! \brief Sets the selected opacity for moving image @param opacity the selected opacity */ void OpacityUpdate(int opacity); /*! * \brief Sets the images to grayvalues or fixed image to red and moving image to green * @param redGreen if true, then images will be shown in red and green */ void SetImageColor(bool redGreen); /*! * \brief Clears the undo and redo lists and sets the undo and redo buttons to disabled. */ void ClearTransformationLists(); void SetUndoEnabled( bool enable ); void SetRedoEnabled( bool enable ); void CheckCalculateEnabled(); void xTrans_valueChanged( int v ); void yTrans_valueChanged( int v ); void zTrans_valueChanged( int v ); void xRot_valueChanged( int v ); void yRot_valueChanged( int v ); void zRot_valueChanged( int v ); void xScale_valueChanged( int v ); void yScale_valueChanged( int v ); void zScale_valueChanged( int v ); void MovingImageChanged(); /*! * \brief Starts the registration process. */ void Calculate(); void SetOptimizerValue( double value ); void StopOptimizationClicked(); void UpdateTimestep(); void SetImagesVisible(berry::ISelection::ConstPointer /*selection*/); - void CheckForMaskImages(); + //void CheckForMaskImages(); - void UseFixedMaskImageChecked(bool checked); + //void UseFixedMaskImageChecked(bool checked); - void UseMovingMaskImageChecked(bool checked); + //void UseMovingMaskImageChecked(bool checked); void TabChanged(int index); void SwitchImages(); + /*! + * indicates if the masking option shall be used. + */ + void OnUseMaskingChanged(int state); + + /*! + * method called if the fixed mask image selector changed. + */ + void OnFixedMaskImageChanged(const mitk::DataNode* node); + /*! + * method called if the moving mask image selector changed. + */ + void OnMovingMaskImageChanged(const mitk::DataNode* node); + protected: berry::ISelectionListener::Pointer m_SelListener; berry::IStructuredSelection::ConstPointer m_CurrentSelection; /*! * default main widget containing 4 windows showing 3 * orthogonal slices of the volume and a 3d render window */ QmitkStdMultiWidget * m_MultiWidget; /*! * control widget to make all changes for Deformable registration */ Ui::QmitkRigidRegistrationViewControls m_Controls; mitk::DataNode::Pointer m_MovingNode; mitk::DataNode::Pointer m_MovingMaskNode; mitk::DataNode::Pointer m_FixedNode; mitk::DataNode::Pointer m_FixedMaskNode; // A node to store the contour of the fixed image in mitk::DataNode::Pointer m_ContourHelperNode; + typedef std::map GeometryMapType; + typedef std::list< GeometryMapType > GeometryMapListType; + typedef std::list GeometryListType; - - std::list m_UndoGeometryList; - std::list > m_UndoChildGeometryList; - std::list m_RedoGeometryList; - std::list > m_RedoChildGeometryList; + GeometryListType m_UndoGeometryList; + GeometryMapListType m_UndoChildGeometryList; + GeometryListType m_RedoGeometryList; + GeometryMapListType m_RedoChildGeometryList; bool m_ShowRedGreen; float m_Opacity; float m_OriginalOpacity; bool m_Deactivated; int m_FixedDimension; int m_MovingDimension; int * translationParams; int * rotationParams; int * scalingParams; mitk::Color m_FixedColor; mitk::Color m_MovingColor; int m_TranslateSliderPos[3]; int m_RotateSliderPos[3]; int m_ScaleSliderPos[3]; QmitkStepperAdapter* m_TimeStepperAdapter; }; #endif //QMITKRigidREGISTRATION_H diff --git a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationViewControls.ui b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationViewControls.ui index 40f715a99f..1156b0fea3 100644 --- a/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationViewControls.ui +++ b/Plugins/org.mitk.gui.qt.registration/src/internal/QmitkRigidRegistrationViewControls.ui @@ -1,1030 +1,1049 @@ QmitkRigidRegistrationViewControls 0 0 - 417 - 932 + 482 + 973 0 0 RigidRegistrationControls 0 0 QTabWidget::South QTabWidget::Triangular 0 Qt::ElideNone Automatic Registration QFrame::StyledPanel QFrame::Raised 0 0 QFrame::StyledPanel QFrame::Raised - - - - - QFormLayout::AllNonFixedFieldsGrow + + + + + + 8 + - - - - - 8 - - - - Fixed Image: - - - - - - - - 10 - - - - - - - false - - - - - - - - 8 - - - - Moving Image : - - - - - - - - 10 - - + + Fixed Image: + + + + + + + + 10 + + + + + + + false + + + + + + + - - - - false + Fixed Image Mask: - - - - Switch fixed and moving image - - + + - - + + + + + + + 8 + + + + Moving Image: + + + + + + + + 10 + + + + + + + false + + + + + + + - Use Fixed Image Mask + Moving Image Mask: - - - - Use Moving Image Mask - - + + - + + + + Switch fixed and moving image + + + + + + + Use Image Masking + + + + 255 0 0 0 0 0 0 0 0 255 0 0 0 0 0 0 0 0 118 116 108 118 116 108 118 116 108 8 You have to select two images from Data Manager using CTRL + left click! - + 0% Moving Image Opacity: false 0 0 100 50 Qt::Horizontal 100% - + - + Show contour false Qt::Horizontal 0 - + 0 0 Show Images Red/Green - + Load Preset false Stop false 0 0 0 0 Register :/QmitkRigidRegistrationView/RigidRegistration.xpm:/QmitkRigidRegistrationView/RigidRegistration.xpm false QFrame::StyledPanel QFrame::Raised Optimizer Value: false QFrame::Raised 10 QLCDNumber::Flat false 0 0 Undo Transformation :/org.mitk.gui.qt.ext/edit-undo.png:/org.mitk.gui.qt.ext/edit-undo.png false 0 0 Redo Transformation :/org.mitk.gui.qt.ext/edit-redo.png:/org.mitk.gui.qt.ext/edit-redo.png Manual Registration true QFrame::StyledPanel QFrame::Raised 0 50 false Align Image Centers 75 true Interactive Translations true false 6 0 50 false x-Direction (Frontal): false 50 false y-Direction (Sagittal): false 50 false z-Direction (Axial): false ArrowCursor -10000 10000 Qt::Horizontal -10000 10000 Qt::Horizontal -10000 10000 Qt::Horizontal 75 true Interactive Rotations true 0 50 false x-Axis (Frontal): false 50 false y-Axis (Sagittal): false 50 false z-Axis (Axial): false ArrowCursor -20 20 Qt::Horizontal -20 20 Qt::Horizontal -20 20 Qt::Horizontal 75 true Interactive Scaling true 0 50 false x-Direction (Frontal): false 50 false y-Direction (Sagittal): false 50 false z-Direction (Axial): false ArrowCursor -180 180 1 1 Qt::Horizontal false QSlider::NoTicks -180 180 1 Qt::Horizontal -180 180 1 Qt::Horizontal Qt::Vertical 20 40 Advanced Mode Load Testpresets QFrame::StyledPanel QFrame::Raised 10 10 505 712 0 0 Save as Testpreset Save as Preset QmitkRigidRegistrationSelectorView QWidget
src/internal/QmitkRigidRegistrationSelectorView.h
1
QmitkSliderNavigatorWidget QWidget
QmitkSliderNavigatorWidget.h
1
+ + QmitkDataStorageComboBox + QComboBox +
QmitkDataStorageComboBox.h
+
mitkDataNode.h mitkBaseData.h