diff --git a/Modules/SurfaceInterpolation/Testing/files.cmake b/Modules/SurfaceInterpolation/Testing/files.cmake index b6552de249..4dc47a7217 100644 --- a/Modules/SurfaceInterpolation/Testing/files.cmake +++ b/Modules/SurfaceInterpolation/Testing/files.cmake @@ -1,8 +1,9 @@ set(MODULE_TESTS mitkComputeContourSetNormalsFilterTest.cpp mitkReduceContourSetFilterTest.cpp + mitkSurfaceInterpolationControllerTest.cpp ) if(NOT WIN32) set(MODULE_TESTS ${MODULE_TESTS} mitkCreateDistanceImageFromSurfaceFilterTest.cpp) endif() diff --git a/Modules/SurfaceInterpolation/Testing/mitkSurfaceInterpolationControllerTest.cpp b/Modules/SurfaceInterpolation/Testing/mitkSurfaceInterpolationControllerTest.cpp new file mode 100644 index 0000000000..d919b27272 --- /dev/null +++ b/Modules/SurfaceInterpolation/Testing/mitkSurfaceInterpolationControllerTest.cpp @@ -0,0 +1,164 @@ +/*=================================================================== + +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 + +class mitkSurfaceInterpolationControllerTestSuite : public mitk::TestFixture +{ + CPPUNIT_TEST_SUITE(mitkSurfaceInterpolationControllerTestSuite); + MITK_TEST(TestSingleton); + MITK_TEST(TestSetCurrentInterpolationSession); + MITK_TEST(TestRemoveAllInterpolationSessions); + MITK_TEST(TestRemoveInterpolationSession); + MITK_TEST(TestOnSegmentationDeleted); +// MITK_TEST(TestSetSegmentationImage); //Duplicate +// MITK_TEST(TestAddNewContour); +// MITK_TEST(TestSetDistanceImageVolume); + CPPUNIT_TEST_SUITE_END(); + +private: + + mitk::SurfaceInterpolationController::Pointer m_Controller; + +public: + + mitk::Image::Pointer createImage(unsigned int *dimensions) + { + mitk::Image::Pointer newImage = mitk::Image::New(); + mitk::PixelType p_type = mitk::MakeScalarPixelType(); + newImage->Initialize(p_type, 3, dimensions); + return newImage; + } + + void setUp() + { + m_Controller = mitk::SurfaceInterpolationController::GetInstance(); + + vtkSmartPointer polygonSource = vtkSmartPointer::New(); + polygonSource->SetRadius(100); + polygonSource->SetNumberOfSides(7); + polygonSource->Update(); + mitk::Surface::Pointer surface = mitk::Surface::New(); + surface->SetVtkPolyData(polygonSource->GetOutput()); + } + + void TestSingleton() + { + mitk::SurfaceInterpolationController::Pointer controller2 = mitk::SurfaceInterpolationController::GetInstance(); + CPPUNIT_ASSERT_MESSAGE("SurfaceInterpolationController pointers are not equal!", m_Controller.GetPointer() == controller2.GetPointer()); + } + + void TestSetCurrentInterpolationSession() + { + // Create image for testing + unsigned int dimensions1[] = {10, 10, 10}; + mitk::Image::Pointer segmentation_1 = createImage(dimensions1); + + unsigned int dimensions2[] = {20, 10, 30}; + mitk::Image::Pointer segmentation_2 = createImage(dimensions2); + + // Test 1 + m_Controller->SetCurrentInterpolationSession(segmentation_1); + MITK_ASSERT_EQUAL(m_Controller->GetCurrentSegmentation(), segmentation_1->Clone(), "Segmentation images are not equal"); + CPPUNIT_ASSERT_MESSAGE("Segmentation images are not equal", m_Controller->GetCurrentSegmentation().GetPointer() == segmentation_1.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 1", m_Controller->GetNumberOfInterpolationSessions() == 1); + + // Test 2 + m_Controller->SetCurrentInterpolationSession(segmentation_2); + MITK_ASSERT_EQUAL(m_Controller->GetCurrentSegmentation(), segmentation_2->Clone(), "Segmentation images are not equal"); + CPPUNIT_ASSERT_MESSAGE("Segmentation images are not equal", m_Controller->GetCurrentSegmentation().GetPointer() == segmentation_2.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 2", m_Controller->GetNumberOfInterpolationSessions() == 2); + + // Test 3 + m_Controller->SetCurrentInterpolationSession(segmentation_1); + MITK_ASSERT_EQUAL(m_Controller->GetCurrentSegmentation(), segmentation_1->Clone(), "Segmentation images are not equal"); + CPPUNIT_ASSERT_MESSAGE("Segmentation images are not equal", m_Controller->GetCurrentSegmentation().GetPointer() == segmentation_1.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 2", m_Controller->GetNumberOfInterpolationSessions() == 2); + + // Test 4 + m_Controller->SetCurrentInterpolationSession(segmentation_1); + MITK_ASSERT_EQUAL(m_Controller->GetCurrentSegmentation(), segmentation_1->Clone(), "Segmentation images are not equal"); + CPPUNIT_ASSERT_MESSAGE("Segmentation images are not equal", m_Controller->GetCurrentSegmentation().GetPointer() == segmentation_1.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 2", m_Controller->GetNumberOfInterpolationSessions() == 2); + + // Test 5 + m_Controller->SetCurrentInterpolationSession(0); + CPPUNIT_ASSERT_MESSAGE("Segmentation images are not equal", m_Controller->GetCurrentSegmentation().IsNull()); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 2", m_Controller->GetNumberOfInterpolationSessions() == 2); + } + + void TestRemoveAllInterpolationSessions() + { + // Create image for testing + unsigned int dimensions1[] = {10, 10, 10}; + mitk::Image::Pointer segmentation_1 = createImage(dimensions1); + + unsigned int dimensions2[] = {20, 10, 30}; + mitk::Image::Pointer segmentation_2 = createImage(dimensions2); + + // Test 1 + m_Controller->SetCurrentInterpolationSession(segmentation_1); + m_Controller->SetCurrentInterpolationSession(segmentation_2); + m_Controller->RemoveAllInterpolationSessions(); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 0", m_Controller->GetNumberOfInterpolationSessions() == 0); + } + + void TestRemoveInterpolationSession() + { + // Create image for testing + unsigned int dimensions1[] = {10, 10, 10}; + mitk::Image::Pointer segmentation_1 = createImage(dimensions1); + + unsigned int dimensions2[] = {20, 10, 30}; + mitk::Image::Pointer segmentation_2 = createImage(dimensions2); + + // Test 1 + m_Controller->SetCurrentInterpolationSession(segmentation_1); + m_Controller->SetCurrentInterpolationSession(segmentation_2); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 2", m_Controller->GetNumberOfInterpolationSessions() == 2); + + // Test current segmentation should not be null if another one was removed + m_Controller->RemoveInterpolationSession(segmentation_1); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 1", m_Controller->GetNumberOfInterpolationSessions() == 1); + CPPUNIT_ASSERT_MESSAGE("Segmentation images are not equal", m_Controller->GetCurrentSegmentation().GetPointer() == segmentation_2.GetPointer()); + CPPUNIT_ASSERT_MESSAGE("Current segmentation is null after another one was removed", m_Controller->GetCurrentSegmentation().IsNotNull()); + + m_Controller->SetCurrentInterpolationSession(segmentation_1); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 2", m_Controller->GetNumberOfInterpolationSessions() == 2); + + // Test current segmentation should not be null if another one was removed + m_Controller->RemoveInterpolationSession(segmentation_1); + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 1", m_Controller->GetNumberOfInterpolationSessions() == 1); + CPPUNIT_ASSERT_MESSAGE("Current segmentation is not null after session was removed", m_Controller->GetCurrentSegmentation().IsNull()); + } + + + void TestOnSegmentationDeleted() + { + { + // Create image for testing + unsigned int dimensions1[] = {10, 10, 10}; + mitk::Image::Pointer segmentation_1 = createImage(dimensions1); + m_Controller->SetCurrentInterpolationSession(segmentation_1); + } + CPPUNIT_ASSERT_MESSAGE("Number of interpolation session not 0", m_Controller->GetNumberOfInterpolationSessions() == 0); + } +}; +MITK_TEST_SUITE_REGISTRATION(mitkSurfaceInterpolationController) diff --git a/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.cpp b/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.cpp index 1290d30c2d..4b83363493 100644 --- a/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.cpp +++ b/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.cpp @@ -1,319 +1,363 @@ /*=================================================================== 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 "mitkSurfaceInterpolationController.h" #include "mitkMemoryUtilities.h" #include "mitkImageAccessByItk.h" #include "mitkImageCast.h" #include "mitkImageToSurfaceFilter.h" + mitk::SurfaceInterpolationController::SurfaceInterpolationController() :m_SelectedSegmentation(0) { m_ReduceFilter = ReduceContourSetFilter::New(); m_NormalsFilter = ComputeContourSetNormalsFilter::New(); m_InterpolateSurfaceFilter = CreateDistanceImageFromSurfaceFilter::New(); m_ReduceFilter->SetUseProgressBar(false); m_NormalsFilter->SetUseProgressBar(false); m_InterpolateSurfaceFilter->SetUseProgressBar(false); m_Contours = Surface::New(); m_PolyData = vtkSmartPointer::New(); m_PolyData->SetPoints(vtkPoints::New()); m_InterpolationResult = 0; m_CurrentNumberOfReducedContours = 0; } mitk::SurfaceInterpolationController::~SurfaceInterpolationController() { - ContourListMap::iterator it = m_MapOfContourLists.begin(); - for (; it != m_MapOfContourLists.end(); it++) + ContourListMap::iterator it = m_ListOfInterpolationSessions.begin(); + for (; it != m_ListOfInterpolationSessions.end(); it++) { - for (unsigned int j = 0; j < m_MapOfContourLists[(*it).first].size(); ++j) + for (unsigned int j = 0; j < m_ListOfInterpolationSessions[(*it).first].size(); ++j) { - delete(m_MapOfContourLists[(*it).first].at(j).position); + delete(m_ListOfInterpolationSessions[(*it).first].at(j).position); } - m_MapOfContourLists.erase(it); + m_ListOfInterpolationSessions.erase(it); } //Removing all observers std::map::iterator dataIter = m_SegmentationObserverTags.begin(); for (; dataIter != m_SegmentationObserverTags.end(); ++dataIter ) { - (*dataIter).first->GetProperty("visible")->RemoveObserver( (*dataIter).second ); + (*dataIter).first->RemoveObserver( (*dataIter).second ); } m_SegmentationObserverTags.clear(); } mitk::SurfaceInterpolationController* mitk::SurfaceInterpolationController::GetInstance() { static mitk::SurfaceInterpolationController* m_Instance; if ( m_Instance == 0) { m_Instance = new SurfaceInterpolationController(); } return m_Instance; } void mitk::SurfaceInterpolationController::AddNewContour (mitk::Surface::Pointer newContour ,RestorePlanePositionOperation* op) { AffineTransform3D::Pointer transform = AffineTransform3D::New(); transform = op->GetTransform(); mitk::Vector3D direction = op->GetDirectionVector(); int pos (-1); - for (unsigned int i = 0; i < m_MapOfContourLists[m_SelectedSegmentation].size(); i++) + for (unsigned int i = 0; i < m_ListOfInterpolationSessions[m_SelectedSegmentation].size(); i++) { - itk::Matrix diffM = transform->GetMatrix()-m_MapOfContourLists[m_SelectedSegmentation].at(i).position->GetTransform()->GetMatrix(); + itk::Matrix diffM = transform->GetMatrix()-m_ListOfInterpolationSessions[m_SelectedSegmentation].at(i).position->GetTransform()->GetMatrix(); bool isSameMatrix(true); for (unsigned int j = 0; j < 3; j++) { if (fabs(diffM[j][0]) > 0.0001 && fabs(diffM[j][1]) > 0.0001 && fabs(diffM[j][2]) > 0.0001) { isSameMatrix = false; break; } } - itk::Vector diffV = m_MapOfContourLists[m_SelectedSegmentation].at(i).position->GetTransform()->GetOffset()-transform->GetOffset(); - if ( isSameMatrix && m_MapOfContourLists[m_SelectedSegmentation].at(i).position->GetPos() == op->GetPos() && (fabs(diffV[0]) < 0.0001 && fabs(diffV[1]) < 0.0001 && fabs(diffV[2]) < 0.0001) ) + itk::Vector diffV = m_ListOfInterpolationSessions[m_SelectedSegmentation].at(i).position->GetTransform()->GetOffset()-transform->GetOffset(); + if ( isSameMatrix && m_ListOfInterpolationSessions[m_SelectedSegmentation].at(i).position->GetPos() == op->GetPos() && (fabs(diffV[0]) < 0.0001 && fabs(diffV[1]) < 0.0001 && fabs(diffV[2]) < 0.0001) ) { pos = i; break; } } //Don't save a new empty contour if (pos == -1 && newContour->GetVtkPolyData()->GetNumberOfPoints() > 0) { mitk::RestorePlanePositionOperation* newOp = new mitk::RestorePlanePositionOperation (OpRESTOREPLANEPOSITION, op->GetWidth(), op->GetHeight(), op->GetSpacing(), op->GetPos(), direction, transform); ContourPositionPair newData; newData.contour = newContour; newData.position = newOp; - m_ReduceFilter->SetInput(m_MapOfContourLists[m_SelectedSegmentation].size(), newContour); - m_MapOfContourLists[m_SelectedSegmentation].push_back(newData); + m_ReduceFilter->SetInput(m_ListOfInterpolationSessions[m_SelectedSegmentation].size(), newContour); + m_ListOfInterpolationSessions[m_SelectedSegmentation].push_back(newData); } //Edit a existing contour. If the contour is empty, edit it anyway so that the interpolation will always be consistent else if (pos != -1) { - m_MapOfContourLists[m_SelectedSegmentation].at(pos).contour = newContour; + m_ListOfInterpolationSessions[m_SelectedSegmentation].at(pos).contour = newContour; m_ReduceFilter->SetInput(pos, newContour); } m_ReduceFilter->Update(); m_CurrentNumberOfReducedContours = m_ReduceFilter->GetNumberOfOutputs(); for (unsigned int i = 0; i < m_CurrentNumberOfReducedContours; i++) { m_NormalsFilter->SetInput(i, m_ReduceFilter->GetOutput(i)); m_InterpolateSurfaceFilter->SetInput(i, m_NormalsFilter->GetOutput(i)); } this->Modified(); } void mitk::SurfaceInterpolationController::Interpolate() { if (m_CurrentNumberOfReducedContours< 2) { //If no interpolation is possible reset the interpolation result m_InterpolationResult = 0; return; } //Setting up progress bar /* * Removed due to bug 12441. ProgressBar messes around with Qt event queue which is fatal for segmentation */ //mitk::ProgressBar::GetInstance()->AddStepsToDo(8); // update the filter and get teh resulting distance-image m_InterpolateSurfaceFilter->Update(); Image::Pointer distanceImage = m_InterpolateSurfaceFilter->GetOutput(); // create a surface from the distance-image mitk::ImageToSurfaceFilter::Pointer imageToSurfaceFilter = mitk::ImageToSurfaceFilter::New(); imageToSurfaceFilter->SetInput( distanceImage ); imageToSurfaceFilter->SetThreshold( 0 ); imageToSurfaceFilter->SetSmooth(true); imageToSurfaceFilter->SetSmoothIteration(20); imageToSurfaceFilter->Update(); m_InterpolationResult = imageToSurfaceFilter->GetOutput(); vtkSmartPointer polyDataAppender = vtkSmartPointer::New(); for (unsigned int i = 0; i < m_ReduceFilter->GetNumberOfOutputs(); i++) { polyDataAppender->AddInputData(m_ReduceFilter->GetOutput(i)->GetVtkPolyData()); } polyDataAppender->Update(); m_Contours->SetVtkPolyData(polyDataAppender->GetOutput()); //Last progress step /* * Removed due to bug 12441. ProgressBar messes around with Qt event queue which is fatal for segmentation */ //mitk::ProgressBar::GetInstance()->Progress(8); m_InterpolationResult->DisconnectPipeline(); } mitk::Surface::Pointer mitk::SurfaceInterpolationController::GetInterpolationResult() { return m_InterpolationResult; } mitk::Surface* mitk::SurfaceInterpolationController::GetContoursAsSurface() { return m_Contours; } void mitk::SurfaceInterpolationController::SetDataStorage(DataStorage::Pointer ds) { m_DataStorage = ds; } void mitk::SurfaceInterpolationController::SetMinSpacing(double minSpacing) { m_ReduceFilter->SetMinSpacing(minSpacing); } void mitk::SurfaceInterpolationController::SetMaxSpacing(double maxSpacing) { m_ReduceFilter->SetMaxSpacing(maxSpacing); m_NormalsFilter->SetMaxSpacing(maxSpacing); } void mitk::SurfaceInterpolationController::SetDistanceImageVolume(unsigned int distImgVolume) { m_InterpolateSurfaceFilter->SetDistanceImageVolume(distImgVolume); } -void mitk::SurfaceInterpolationController::SetSegmentationImage(Image* workingImage) +void mitk::SurfaceInterpolationController::SetSegmentationImage(Image* /*workingImage*/) +{ +// m_NormalsFilter->SetSegmentationBinaryImage(workingImage); +} + +mitk::Image::Pointer mitk::SurfaceInterpolationController::GetCurrentSegmentation() { - m_NormalsFilter->SetSegmentationBinaryImage(workingImage); + return m_SelectedSegmentation; } mitk::Image* mitk::SurfaceInterpolationController::GetImage() { return m_InterpolateSurfaceFilter->GetOutput(); } double mitk::SurfaceInterpolationController::EstimatePortionOfNeededMemory() { double numberOfPointsAfterReduction = m_ReduceFilter->GetNumberOfPointsAfterReduction()*3; double sizeOfPoints = pow(numberOfPointsAfterReduction,2)*sizeof(double); double totalMem = mitk::MemoryUtilities::GetTotalSizeOfPhysicalRam(); double percentage = sizeOfPoints/totalMem; return percentage; } +unsigned int mitk::SurfaceInterpolationController::GetNumberOfInterpolationSessions() +{ + return m_ListOfInterpolationSessions.size(); +} + template void mitk::SurfaceInterpolationController::GetImageBase(itk::Image* input, itk::ImageBase<3>::Pointer& result) { result->Graft(input); } -void mitk::SurfaceInterpolationController::SetCurrentSegmentationInterpolationList(mitk::Image* segmentation) +void mitk::SurfaceInterpolationController::SetCurrentSegmentationInterpolationList(mitk::Image::Pointer segmentation) { - if (segmentation == m_SelectedSegmentation) + this->SetCurrentInterpolationSession(segmentation); +} + +void mitk::SurfaceInterpolationController::SetCurrentInterpolationSession(mitk::Image::Pointer currentSegmentationImage) +{ + if (currentSegmentationImage.GetPointer() == m_SelectedSegmentation) return; m_ReduceFilter->Reset(); m_NormalsFilter->Reset(); m_InterpolateSurfaceFilter->Reset(); - if (segmentation == 0) + if (currentSegmentationImage.IsNull()) { m_SelectedSegmentation = 0; return; } - ContourListMap::iterator it = m_MapOfContourLists.find(segmentation); - - m_SelectedSegmentation = segmentation; + ContourListMap::iterator it = m_ListOfInterpolationSessions.find(currentSegmentationImage.GetPointer()); + m_SelectedSegmentation = currentSegmentationImage.GetPointer(); itk::ImageBase<3>::Pointer itkImage = itk::ImageBase<3>::New(); AccessFixedDimensionByItk_1( m_SelectedSegmentation, GetImageBase, 3, itkImage ); m_InterpolateSurfaceFilter->SetReferenceImage( itkImage.GetPointer() ); - if (it == m_MapOfContourLists.end()) + if (it == m_ListOfInterpolationSessions.end()) { ContourPositionPairList newList; - m_MapOfContourLists.insert(std::pair(segmentation, newList)); + m_ListOfInterpolationSessions.insert(std::pair(m_SelectedSegmentation, newList)); m_InterpolationResult = 0; m_CurrentNumberOfReducedContours = 0; itk::MemberCommand::Pointer command = itk::MemberCommand::New(); command->SetCallbackFunction(this, &SurfaceInterpolationController::OnSegmentationDeleted); - m_SegmentationObserverTags.insert( std::pair( segmentation, segmentation->AddObserver( itk::DeleteEvent(), command ) ) ); + m_SegmentationObserverTags.insert( std::pair( m_SelectedSegmentation, m_SelectedSegmentation->AddObserver( itk::DeleteEvent(), command ) ) ); } else { - for (unsigned int i = 0; i < m_MapOfContourLists[m_SelectedSegmentation].size(); i++) + for (unsigned int i = 0; i < m_ListOfInterpolationSessions[m_SelectedSegmentation].size(); i++) { - m_ReduceFilter->SetInput(i, m_MapOfContourLists[m_SelectedSegmentation].at(i).contour); + m_ReduceFilter->SetInput(i, m_ListOfInterpolationSessions[m_SelectedSegmentation].at(i).contour); } m_ReduceFilter->Update(); m_CurrentNumberOfReducedContours = m_ReduceFilter->GetNumberOfOutputs(); for (unsigned int i = 0; i < m_CurrentNumberOfReducedContours; i++) { m_NormalsFilter->SetInput(i, m_ReduceFilter->GetOutput(i)); m_InterpolateSurfaceFilter->SetInput(i, m_NormalsFilter->GetOutput(i)); } } Modified(); } void mitk::SurfaceInterpolationController::RemoveSegmentationFromContourList(mitk::Image *segmentation) { - if (segmentation != 0) + this->RemoveInterpolationSession(segmentation); +} + +void mitk::SurfaceInterpolationController::RemoveInterpolationSession(mitk::Image::Pointer segmentationImage) +{ + if (segmentationImage) { - m_MapOfContourLists.erase(segmentation); - if (m_SelectedSegmentation == segmentation) + if (m_SelectedSegmentation == segmentationImage) { SetSegmentationImage(NULL); m_SelectedSegmentation = 0; } + m_ListOfInterpolationSessions.erase(segmentationImage); + // Remove observer + std::map::iterator pos = m_SegmentationObserverTags.find(segmentationImage); + if (pos != m_SegmentationObserverTags.end()) + { + segmentationImage->RemoveObserver((*pos).second); + m_SegmentationObserverTags.erase(pos); + } + } +} + +void mitk::SurfaceInterpolationController::RemoveAllInterpolationSessions() +{ + //Removing all observers + std::map::iterator dataIter = m_SegmentationObserverTags.begin(); + while (dataIter != m_SegmentationObserverTags.end()) + { + mitk::Image* image = (*dataIter).first; + image->RemoveObserver((*dataIter).second); + ++dataIter; } + + m_SegmentationObserverTags.clear(); + m_SelectedSegmentation = 0; + m_ListOfInterpolationSessions.clear(); } void mitk::SurfaceInterpolationController::OnSegmentationDeleted(const itk::Object *caller, const itk::EventObject &/*event*/) { mitk::Image* tempImage = dynamic_cast(const_cast(caller)); if (tempImage) { - RemoveSegmentationFromContourList(tempImage); - if (tempImage == m_SelectedSegmentation) + if (m_SelectedSegmentation == tempImage) { SetSegmentationImage(NULL); m_SelectedSegmentation = 0; } + m_SegmentationObserverTags.erase(tempImage); + m_ListOfInterpolationSessions.erase(tempImage); } } diff --git a/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.h b/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.h index f64105df10..8cef048e88 100644 --- a/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.h +++ b/Modules/SurfaceInterpolation/mitkSurfaceInterpolationController.h @@ -1,167 +1,194 @@ /*=================================================================== 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 mitkSurfaceInterpolationController_h_Included #define mitkSurfaceInterpolationController_h_Included #include "mitkCommon.h" #include #include "mitkRestorePlanePositionOperation.h" #include "mitkSurface.h" #include "mitkInteractionConst.h" #include "mitkColorProperty.h" #include "mitkProperties.h" #include "mitkCreateDistanceImageFromSurfaceFilter.h" #include "mitkReduceContourSetFilter.h" #include "mitkComputeContourSetNormalsFilter.h" #include "mitkDataNode.h" #include "mitkDataStorage.h" #include "mitkWeakPointer.h" #include "vtkPolygon.h" #include "vtkPoints.h" #include "vtkCellArray.h" #include "vtkPolyData.h" #include "vtkSmartPointer.h" #include "vtkAppendPolyData.h" #include "vtkMarchingCubes.h" #include "vtkImageData.h" #include "mitkVtkRepresentationProperty.h" #include "vtkProperty.h" #include "mitkProgressBar.h" namespace mitk { class MitkSurfaceInterpolation_EXPORT SurfaceInterpolationController : public itk::Object { public: mitkClassMacro(SurfaceInterpolationController, itk::Object) itkFactorylessNewMacro(Self) itkCloneMacro(Self) static SurfaceInterpolationController* GetInstance(); /** * Adds a new extracted contour to the list */ void AddNewContour(Surface::Pointer newContour, RestorePlanePositionOperation *op); /** * Interpolates the 3D surface from the given extracted contours */ void Interpolate (); mitk::Surface::Pointer GetInterpolationResult(); /** * Sets the minimum spacing of the current selected segmentation * This is needed since the contour points we reduced before they are used to interpolate the surface */ void SetMinSpacing(double minSpacing); /** * Sets the minimum spacing of the current selected segmentation * This is needed since the contour points we reduced before they are used to interpolate the surface */ void SetMaxSpacing(double maxSpacing); /** * Sets the volume i.e. the number of pixels that the distance image should have * By evaluation we found out that 50.000 pixel delivers a good result */ void SetDistanceImageVolume(unsigned int distImageVolume); /** * Sets the current segmentation which is used by the interpolation * This is needed because the calculation of the normals needs to now wheather a normal points inside a segmentation or not */ void SetSegmentationImage(Image* workingImage); + /** + * @brief Get the current selected segmentation for which the interpolation is performed + * @return the current segmentation image + */ + mitk::Image::Pointer GetCurrentSegmentation(); + Surface* GetContoursAsSurface(); void SetDataStorage(DataStorage::Pointer ds); + /** + * Sets the current list of contourpoints which is used for the surface interpolation + * @param segmentation The current selected segmentation + * \deprecatedSince{2014_03} + */ + DEPRECATED (void SetCurrentSegmentationInterpolationList(mitk::Image::Pointer segmentation)); + /** * Sets the current list of contourpoints which is used for the surface interpolation * @param segmentation The current selected segmentation */ - void SetCurrentSegmentationInterpolationList(mitk::Image* segmentation); + void SetCurrentInterpolationSession(mitk::Image::Pointer currentSegmentationImage); /** * Removes the segmentation and all its contours from the list * @param segmentation The segmentation to be removed + * \deprecatedSince{2014_03} */ - void RemoveSegmentationFromContourList(mitk::Image* segmentation); + DEPRECATED (void RemoveSegmentationFromContourList(mitk::Image* segmentation)); + + /** + * @brief Remove interpolation session + * @param segmentationImage the session to be removed + */ + void RemoveInterpolationSession(mitk::Image::Pointer segmentationImage); + + /** + * @brief Removes all sessions + */ + void RemoveAllInterpolationSessions(); mitk::Image* GetImage(); /** * Estimates the memory which is needed to build up the equationsystem for the interpolation. * \returns The percentage of the real memory which will be used by the interpolation */ double EstimatePortionOfNeededMemory(); + unsigned int GetNumberOfInterpolationSessions(); + protected: SurfaceInterpolationController(); ~SurfaceInterpolationController(); template void GetImageBase(itk::Image* input, itk::ImageBase<3>::Pointer& result); private: void OnSegmentationDeleted(const itk::Object *caller, const itk::EventObject &event); struct ContourPositionPair { Surface::Pointer contour; RestorePlanePositionOperation* position; }; typedef std::vector ContourPositionPairList; - typedef std::map ContourListMap; + typedef std::map ContourListMap; ContourPositionPairList::iterator m_Iterator; ReduceContourSetFilter::Pointer m_ReduceFilter; ComputeContourSetNormalsFilter::Pointer m_NormalsFilter; CreateDistanceImageFromSurfaceFilter::Pointer m_InterpolateSurfaceFilter; Surface::Pointer m_Contours; vtkSmartPointer m_PolyData; mitk::DataStorage::Pointer m_DataStorage; - ContourListMap m_MapOfContourLists; + ContourListMap m_ListOfInterpolationSessions; mitk::Surface::Pointer m_InterpolationResult; unsigned int m_CurrentNumberOfReducedContours; mitk::Image* m_SelectedSegmentation; std::map m_SegmentationObserverTags; }; } #endif