diff --git a/Modules/SurfaceRegistration/src/DataManagement/MitkShortestDistanceCalculator.cpp b/Modules/SurfaceRegistration/src/DataManagement/MitkShortestDistanceCalculator.cpp index 9b049cfc60..4d4be4079a 100644 --- a/Modules/SurfaceRegistration/src/DataManagement/MitkShortestDistanceCalculator.cpp +++ b/Modules/SurfaceRegistration/src/DataManagement/MitkShortestDistanceCalculator.cpp @@ -1,72 +1,71 @@ /*=================================================================== 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 "mitkShortestDistanceCalculator.h" #include "vtkCellLocator.h" #include "vtkPointData.h" #include "vtkImplicitPolyDataDistance.h" #include "vtkDoubleArray.h" #include // std::abs mitk::ShortestDistanceCalculator::ShortestDistanceCalculator() { } mitk::ShortestDistanceCalculator::~ShortestDistanceCalculator() { } vtkSmartPointer mitk::ShortestDistanceCalculator::calculateShortestDistance(vtkSmartPointer moving, vtkSmartPointer target) { MITK_INFO << "calculate shortest distance ..."; vtkSmartPointer distances = vtkSmartPointer::New(); double fromPoint[3] = { 0, 0, 0 }; int pointNumber = moving->GetPoints()->GetNumberOfPoints(); vtkSmartPointer implicitPolyDataDistance = vtkSmartPointer::New(); implicitPolyDataDistance->SetInput(target); //test double mean = 0; double min = 0; double max = 0; for (int i = 0; i < pointNumber; ++i) { moving->GetPoints()->GetPoint(i, fromPoint); double distance = implicitPolyDataDistance->FunctionValue(fromPoint[0], fromPoint[1], fromPoint[2]); // MITK_INFO << distance; - //+4 for correct LookUpTable value - distances->InsertNextValue(distance + 4); + distances->InsertNextValue(distance); mean += std::abs(distance); if (distance < min) { min = distance; } else if (distance > max) { max = distance; } } mean = mean / pointNumber; MITK_INFO << "The mean is: " << mean; MITK_INFO << "Min Value is: " << min; MITK_INFO << "Max Value is: " << max; return distances; } \ No newline at end of file diff --git a/Modules/SurfaceRegistration/src/mitkShapeComparisonManager.cpp b/Modules/SurfaceRegistration/src/mitkShapeComparisonManager.cpp index 1e75c3f902..bec5415d8e 100644 --- a/Modules/SurfaceRegistration/src/mitkShapeComparisonManager.cpp +++ b/Modules/SurfaceRegistration/src/mitkShapeComparisonManager.cpp @@ -1,194 +1,159 @@ /*=================================================================== 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 #include #include #include #include #include #include #include #include #include #include -#include -#include #include #include mitk::ShapeComparisonManager::ShapeComparisonManager(mitk::Surface::Pointer moving, mitk::Surface::Pointer target) { this->m_MovingSurface = moving; this->m_TargetSurface = target; createLookUpTable(); } mitk::ShapeComparisonManager::~ShapeComparisonManager() { m_MovingSurface->Delete(); m_TargetSurface->Delete(); + m_registeredSurface->Delete(); + m_distances->Delete(); + m_LookupTable->Delete(); } mitk::Surface::Pointer mitk::ShapeComparisonManager::getRegisteredSurface() { return m_registeredSurface; } void mitk::ShapeComparisonManager::execute() { // printPoints(); manageICPCalculation(); manageCalculateDistances(); } vtkSmartPointer mitk::ShapeComparisonManager::getTable() { return m_LookupTable; } mitk::DataNode::Pointer mitk::ShapeComparisonManager::getColourTransformedDataNode() { mitk::Surface::Pointer currentSurface; if (m_registeredSurface == nullptr) { currentSurface = m_MovingSurface; } else { currentSurface = m_registeredSurface; } currentSurface->GetVtkPolyData()->GetPointData()->SetScalars(m_distances); currentSurface->GetVtkPolyData()->GetPointData()->Update(); mitk::LookupTable::Pointer lut = mitk::LookupTable::New(); lut->SetVtkLookupTable(m_LookupTable); - //lut->SetType(mitk::LookupTable::JET); mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(lut); currentSurface->GetVtkPolyData()->GetPointData()->Update(); mitk::DataNode::Pointer planeNodeTrans = mitk::DataNode::New(); planeNodeTrans->SetProperty("LookupTable", prop); planeNodeTrans->SetBoolProperty("scalar visibility", true); planeNodeTrans->SetBoolProperty("color mode", true); - planeNodeTrans->SetFloatProperty("ScalarsRangeMinimum", 0.0); - planeNodeTrans->SetFloatProperty("ScalarsRangeMaximum", 8.0); + planeNodeTrans->SetFloatProperty("ScalarsRangeMinimum", -5.0); + planeNodeTrans->SetFloatProperty("ScalarsRangeMaximum", 5.0); // Configure material so that only scalar colors are shown planeNodeTrans->SetColor(0.0f, 0.0f, 0.0f); planeNodeTrans->SetOpacity(1.0f); planeNodeTrans->SetFloatProperty("material.wireframeLineWidth", 2.0f); //Set view of plane to VTK_SURFACE planeNodeTrans->SetProperty("material.representation", mitk::VtkRepresentationProperty::New());//VTK_SURFACE currently default // save colored surface node planeNodeTrans->SetData(currentSurface); planeNodeTrans->SetName("ColouredNode"); return planeNodeTrans; } - void mitk::ShapeComparisonManager::manageICPCalculation() { m_registeredSurface = mitk::Surface::New(); - mitk::SurfaceRegistrationICP *registrationHelper = new SurfaceRegistrationICP(); m_registeredSurface = registrationHelper->CalculateICP(m_MovingSurface, m_TargetSurface); - } + void mitk::ShapeComparisonManager::manageCalculateDistances() { mitk::ShortestDistanceCalculator *distanceCalculator = new ShortestDistanceCalculator(); if (m_registeredSurface) { m_distances = distanceCalculator->calculateShortestDistance(m_registeredSurface->GetVtkPolyData(), m_TargetSurface->GetVtkPolyData()); } else { m_distances = distanceCalculator->calculateShortestDistance(m_MovingSurface->GetVtkPolyData(), m_TargetSurface->GetVtkPolyData()); } } void mitk::ShapeComparisonManager::createLookUpTable() { m_LookupTable = vtkSmartPointer::New(); - int tableSize = 3; - m_LookupTable->SetNumberOfTableValues(tableSize); + m_LookupTable->SetNumberOfTableValues(25); + m_LookupTable->SetTableRange(-5.0, 5.0); m_LookupTable->Build(); - - m_LookupTable->SetNumberOfTableValues(9); - vtkSmartPointer valArray = vtkSmartPointer::New(); - vtkSmartPointer strgArray = vtkSmartPointer::New(); - strgArray->InsertNextValue("-4"); - valArray->InsertNextValue(vtkVariant(0.45)); - m_LookupTable->SetTableValue(0, 0.0, 0.0, 1.0); // blue = -4 mm - strgArray->InsertNextValue("-3"); - valArray->InsertNextValue(vtkVariant(1.35)); - m_LookupTable->SetTableValue(1, 0.0, 0.5, 1.0); // - strgArray->InsertNextValue("-2"); - valArray->InsertNextValue(vtkVariant(2.25)); - m_LookupTable->SetTableValue(2, 0.0, 1.0, 1.0); // turquoise = -2 mm - strgArray->InsertNextValue("-1"); - valArray->InsertNextValue(vtkVariant(3.15)); - m_LookupTable->SetTableValue(3, 0.0, 1.0, 0.5); // - strgArray->InsertNextValue("0"); - valArray->InsertNextValue(vtkVariant(4.05)); - m_LookupTable->SetTableValue(4, 0.0, 1.0, 0.0); // green = 0 mm - strgArray->InsertNextValue("1"); - valArray->InsertNextValue(vtkVariant(4.95)); - m_LookupTable->SetTableValue(5, 0.5, 1.0, 0.0); // - strgArray->InsertNextValue("2"); - valArray->InsertNextValue(vtkVariant(5.85)); - m_LookupTable->SetTableValue(6, 1.0, 1.0, 0.0); // yellow = 2 mm - strgArray->InsertNextValue("3"); - valArray->InsertNextValue(vtkVariant(6.75)); - m_LookupTable->SetTableValue(7, 1.0, 0.5, 0.0); // - strgArray->InsertNextValue("4"); - valArray->InsertNextValue(vtkVariant(7.65)); - m_LookupTable->SetTableValue(8, 1.0, 0.0, 0.0); // red = 4 mm - m_LookupTable->SetAnnotations(valArray, strgArray); - m_LookupTable->SetTableRange(0.0, 8.0); } void mitk::ShapeComparisonManager::printPoints() { MITK_INFO << "printing"; std::ofstream OutputFileMoving; OutputFileMoving.open("movingPoints.txt"); int pointNumber = m_MovingSurface->GetVtkPolyData()->GetPoints()->GetNumberOfPoints(); double printPoint[3] = { 0,0,0 }; for (int i = 0; i < pointNumber; ++i) { m_MovingSurface->GetVtkPolyData()->GetPoints()->GetPoint(i, printPoint); OutputFileMoving << printPoint[0]<<" " << printPoint[1] << " " << printPoint[2] <GetVtkPolyData()->GetPoints()->GetNumberOfPoints(); double printPoint2[3] = { 0,0,0 }; for (int i = 0; i < pointNumber2; ++i) { m_TargetSurface->GetVtkPolyData()->GetPoints()->GetPoint(i, printPoint2); OutputFileTarget << printPoint2[0] << " " << printPoint2[1] << " " << printPoint2[2] << std::endl; } OutputFileTarget.close(); } diff --git a/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.cpp b/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.cpp index 398b1ef491..66e28d2ff9 100644 --- a/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.cpp +++ b/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.cpp @@ -1,248 +1,228 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #include "QmitkSurfaceRegistration.h" #include #include #include #include -#include -#include -#include -#include - #include #include #include #include #include #include #include #include -#include - -//#include -//#include -//#include -//#include +#include +#include #include #include -#include -#include -#include -#include -#include -#include -#include #include const std::string QmitkSurfaceRegistration::VIEW_ID = "org.mitk.views.qmitksurfaceregistration"; QmitkSurfaceRegistration::QmitkSurfaceRegistration(QObject *parent) : m_ParentWidget(0), m_movingSurfaceNode(nullptr), m_targetSurfaceNode(nullptr) { - m_colorBarAnnotation = mitk::ColorBarAnnotation::New(); } QmitkSurfaceRegistration::~QmitkSurfaceRegistration() { - // delete pointer objects m_movingSurfaceNode = nullptr; m_targetSurfaceNode = nullptr; } -void QmitkSurfaceRegistration::SetFocus(){ +void QmitkSurfaceRegistration::SetFocus() +{ m_Controls.groupBoxMoving->setFocus(); } QWidget * QmitkSurfaceRegistration::GetControls() { return nullptr; } void QmitkSurfaceRegistration::CreateQtPartControl(QWidget *parent) { // create GUI widgets from the Qt Designer's .ui file m_Controls.setupUi(parent); connect(m_Controls.pushButtonExecute, SIGNAL(clicked()), this, SLOT(doExecute())); mitk::RenderingManager::GetInstance()->SetDataStorage(this->GetDataStorageReference()->GetDataStorage()); mitk::RenderingManager::GetInstance()->InitializeViews(); - mitk::RenderingModeProperty::LOOKUPTABLE_COLOR;//works without? m_ParentWidget = parent; } void QmitkSurfaceRegistration::OnSelectionChanged(berry::IWorkbenchPart::Pointer /*part*/, const QList &nodes) { - MITK_INFO << "On Selection Changed"; bool rotationEnabled = false; if (nodes.empty()) { - MITK_INFO << "Nothing selected yet"; m_Controls.labelSelectMovingSurface->setStyleSheet(" QLabel { color: rgb(255, 0, 0) }"); m_Controls.labelSelectTargetSurface->setStyleSheet(" QLabel { color: rgb(255, 0, 0) }"); m_Controls.labelMovingSurfaceName->setText(QString::fromStdString("No moving surface selected")); m_Controls.labelTargetSurfaceName->setText(QString::fromStdString("No target surface selected")); m_Controls.groupBoxMoving->setEnabled(true); m_Controls.groupBoxMappedData->setEnabled(false); if (m_useTestConfig) { m_Controls.pushButtonExecute->setEnabled(true); } else{ m_Controls.pushButtonExecute->setEnabled(false); } m_Controls.radioButtonMirroring->setEnabled(false); return; } else { if (nodes.size() == 1) { if (nodes[0].IsNotNull() && dynamic_cast(nodes[0]->GetData())) { MITK_INFO << "There is exactly one image selected"; m_movingSurfaceNode = nodes[0]; m_Controls.labelSelectMovingSurface->setText("Selected moving surface:"); m_Controls.labelSelectMovingSurface->setStyleSheet(" QLabel { color: rgb(0, 0, 0) }"); m_Controls.labelMovingSurfaceName->setText( QString::fromStdString("File name: " + m_movingSurfaceNode->GetName())); m_Controls.radioButtonMirroring->setEnabled(true); m_Controls.groupBoxTarget->setEnabled(true); m_Controls.groupBoxMappedData->setEnabled(true); m_Controls.groupBoxTarget->setEnabled(true); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } else { QMessageBox::information(nullptr, "Warning", "Are you sure? - I dont think this is a Surface! Try again!"); } } else if (nodes.size() == 2) { if (nodes[1].IsNotNull() && dynamic_cast(nodes[1]->GetData())) { MITK_INFO << "There are two images selected"; m_targetSurfaceNode = nodes[1]; m_Controls.labelSelectTargetSurface->setText("Selected target surface:"); m_Controls.labelSelectTargetSurface->setStyleSheet(" QLabel { color: rgb(0, 0, 0) }"); m_Controls.labelTargetSurfaceName->setText( QString::fromStdString("File name: " + m_targetSurfaceNode->GetName())); m_Controls.textMappedDataName->setEnabled(true); m_Controls.pushButtonExecute->setEnabled(true); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); m_useTestConfig = false; } else { QMessageBox::information(nullptr, "Warning", "Are you sure? - I dont think this is a Surface!"); } } else { QMessageBox::information(nullptr, "Warning", "You do know that it only works with two surfaces, right? If you continue to click execute, this might crash one day!"); //wie kann ich die Auswahl zurueck setzen? } } } void QmitkSurfaceRegistration::doExecute() { if (m_useTestConfig) { setUpTestConfig(); } - MITK_INFO << "pushButtonExecute clicked"; + MITK_INFO << "push Button execute clicked..."; mitk::Surface::Pointer movingSurface = dynamic_cast (m_movingSurfaceNode->GetData()); mitk::Surface::Pointer targetSurface = dynamic_cast (m_targetSurfaceNode->GetData()); mitk::ShapeComparisonManager *manager = new mitk::ShapeComparisonManager(movingSurface, targetSurface); manager->execute(); mitk::DataNode::Pointer registeredNode = mitk::DataNode::New(); registeredNode->SetData(manager->getRegisteredSurface()); this->GetDataStorageReference()->GetDataStorage()->Add(registeredNode, m_movingSurfaceNode); MITK_INFO << "registration done"; mitk::DataNode::Pointer colouredData = manager->getColourTransformedDataNode(); this->GetDataStorage()->Add(colouredData); this->GetDataStorageReference()->GetDataStorage()->Modified(); registeredNode->SetName("defaultMappedDataName"); mitk::RenderingManager::GetInstance()->InitializeViews(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); vtkSmartPointer lut = manager->getTable(); showLookUpTable(lut); } void QmitkSurfaceRegistration::setUpTestConfig() { mitk::StandaloneDataStorage::Pointer ds = mitk::StandaloneDataStorage::New(); mitk::IOUtil::Load("//ad/fs/E130-Projekte/BGLU/Fibula/Python/DataGAN/Registered/Surface/Tibia/tibia01_q0.stl", *ds); mitk::IOUtil::Load("//ad/fs/E130-Projekte/BGLU/Fibula/Python/DataGAN/Registered/Surface/Tibia/tibia02_q0.stl", *ds); m_movingSurfaceNode = ds->GetAll()->at(0); m_targetSurfaceNode = ds->GetAll()->at(1); this->GetDataStorageReference()->GetDataStorage()->Add(mitk::DataNode::Pointer(ds->GetAll()->at(0))); this->GetDataStorageReference()->GetDataStorage()->Add(mitk::DataNode::Pointer(ds->GetAll()->at(1))); this->GetDataStorageReference()->GetDataStorage()->Modified(); mitk::RenderingManager::GetInstance()->SetDataStorage(this->GetDataStorageReference()->GetDataStorage()); mitk::RenderingManager::GetInstance()->InitializeViews(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); m_Controls.pushButtonExecute->setEnabled(true); m_Controls.labelMovingSurfaceName->setText("tibia01_q0"); m_Controls.labelTargetSurfaceName->setText("tibia02_q0"); m_Controls.labelSelectMovingSurface->setText("Selected moving surface:"); m_Controls.labelSelectMovingSurface->setStyleSheet(" QLabel { color: rgb(0, 0, 0) }"); m_Controls.labelSelectTargetSurface->setText("Selected target surface:"); m_Controls.labelSelectTargetSurface->setStyleSheet(" QLabel { color: rgb(0, 0, 0) }"); this->GetDataStorageReference()->GetDataStorage()->Modified(); mitk::RenderingManager::GetInstance()->InitializeViews(); mitk::RenderingManager::GetInstance()->RequestUpdateAll(); } void QmitkSurfaceRegistration::showLookUpTable(vtkSmartPointer lut) { mitk::BaseRenderer::Pointer renderer = mitk::BaseRenderer::GetInstance(mitk::BaseRenderer::GetRenderWindowByName("stdmulti.widget4")); - + m_colorBarAnnotation = mitk::ColorBarAnnotation::New(); mitk::LookupTable::Pointer mitkTable = mitk::LookupTable::New(); mitkTable->SetVtkLookupTable(lut); - //mitkTable->SetType(mitk::LookupTable::JET); mitk::LookupTableProperty::Pointer prop = mitk::LookupTableProperty::New(mitkTable); m_colorBarAnnotation->SetProperty("ColorBarAnnotation.LookupTable", prop.GetPointer()); + MITK_INFO<GetPropertyList(); m_colorBarAnnotation->SetNumberOfLabels(9); m_colorBarAnnotation->SetAnnotationTextScaling(true); m_colorBarAnnotation->SetDrawAnnotations(true); - m_colorBarAnnotation->SetDrawTickLabels(false); + m_colorBarAnnotation->SetDrawTickLabels(true); mitk::LayoutAnnotationRenderer::AddAnnotation( - m_colorBarAnnotation, renderer, mitk::LayoutAnnotationRenderer::Right, 5, 5, 1); + m_colorBarAnnotation, renderer, mitk::LayoutAnnotationRenderer::Right, 10, 10, 10); } \ No newline at end of file diff --git a/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.h b/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.h index 7408e31d75..4739d26374 100644 --- a/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.h +++ b/Plugins/org.mitk.gui.qt.surfaceregistration/src/internal/QmitkSurfaceRegistration.h @@ -1,117 +1,115 @@ /*========================================================================= Program: Medical Imaging & Interaction Toolkit Language: C++ Date: $Date$ Version: $Revision$ Copyright (c) German Cancer Research Center, Division of Medical and Biological Informatics. All rights reserved. See MITKCopyright.txt or http://www.mitk.org/copyright.html for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef QmitkSurfaceRegistration_h #define QmitkSurfaceRegistration_h #include #ifdef WIN32 #pragma warning( disable : 4250 ) #endif #include "QVTKWidget.h" #include "QmitkRegisterClasses.h" #include #include "ui_SurfaceRegistrationControls.h" #include "usServiceRegistration.h" #include "mitkAnnotation.h" #include "mitkColorBarAnnotation.h" #include #include /*! @brief QmitkSurfaceRegistrationView \warning This class is not yet documented. Use "git blame" and ask the author to provide basic documentation. \sa QmitkFunctionality \ingroup ${plugin_target}_internal */ class QmitkSurfaceRegistration : public QmitkAbstractView { // this is needed for all Qt objects that should have a Qt meta-object // (everything that derives from QObject and wants to have signal/slots) private: Q_OBJECT public: /*! @brief Constructor. Called by SampleApp (or other apps that use functionalities) */ QmitkSurfaceRegistration(QObject *parent = 0); virtual ~QmitkSurfaceRegistration(); static const std::string VIEW_ID; virtual void CreateQtPartControl(QWidget *parent); virtual void SetFocus() override; ///*! //@brief Creates the Qt connections needed //*/ QWidget* GetControls(); /// @brief Called when the user clicks the GUI button protected slots: void doExecute(); protected: // /*! //@brief called by QmitkFunctionality when DataManager's selection has changed // */ void OnSelectionChanged(berry::IWorkbenchPart::Pointer part, const QList& nodes) override; private: /*! * The parent QWidget */ QWidget* m_ParentWidget; mitk::BaseRenderer *m_Renderer; /*! * @brief A pointer to the node of the moving surface. */ mitk::DataNode::Pointer m_movingSurfaceNode; /*! * @brief A pointer to the node of the target surface. */ mitk::DataNode::Pointer m_targetSurfaceNode; Ui::SurfaceRegistrationControls m_Controls; mitk::ColorBarAnnotation::Pointer m_colorBarAnnotation; - bool m_useTestConfig = true; - - void performICPRegistration(); + bool m_useTestConfig = false; void setUpTestConfig(); void showLookUpTable(vtkSmartPointer lut); }; #endif // QmitkSurfaceRegistration_h \ No newline at end of file