diff --git a/Modules/ModuleList.cmake b/Modules/ModuleList.cmake index bb5dfec5a4..6c9775ec78 100644 --- a/Modules/ModuleList.cmake +++ b/Modules/ModuleList.cmake @@ -1,86 +1,85 @@ # The entries in the mitk_modules list must be # ordered according to their dependencies. set(MITK_MODULES Core CommandLine AppUtil LegacyIO DataTypesExt Annotation LegacyGL AlgorithmsExt MapperExt DICOMReader DICOMReaderServices DICOMQI DICOMTesting SceneSerializationBase PlanarFigure ImageDenoising ImageExtraction SceneSerialization Gizmo GraphAlgorithms Multilabel Chart ImageStatistics ContourModel SurfaceInterpolation Segmentation - PlanarFigureSegmentation QtWidgets QtWidgetsExt ImageStatisticsUI SegmentationUI MatchPointRegistration MatchPointRegistrationUI Classification OpenIGTLink IGTBase IGT CameraCalibration OpenCL OpenCVVideoSupport QtOverlays ToFHardware ToFProcessing ToFUI PhotoacousticsHardware PhotoacousticsAlgorithms PhotoacousticsLib US USUI DicomUI Remeshing Python QtPython Persistence OpenIGTLinkUI IGTUI DicomRT RTUI IOExt XNAT TubeGraph BiophotonicsHardware # TumorInvasionAnalysis BoundingShape RenderWindowManager RenderWindowManagerUI SemanticRelations SemanticRelationsUI CEST BasicImageProcessing ModelFit ModelFitUI Pharmacokinetics PharmacokineticsUI DICOMPM REST RESTService ) if(MITK_ENABLE_PIC_READER) list(APPEND MITK_MODULES IpPicSupportIO) endif() diff --git a/Modules/PlanarFigureSegmentation/CMakeLists.txt b/Modules/PlanarFigureSegmentation/CMakeLists.txt deleted file mode 100644 index 417756d1d5..0000000000 --- a/Modules/PlanarFigureSegmentation/CMakeLists.txt +++ /dev/null @@ -1,4 +0,0 @@ - -MITK_CREATE_MODULE( - DEPENDS MitkSurfaceInterpolation MitkPlanarFigure -) diff --git a/Modules/PlanarFigureSegmentation/files.cmake b/Modules/PlanarFigureSegmentation/files.cmake deleted file mode 100644 index 2a18d8c1c8..0000000000 --- a/Modules/PlanarFigureSegmentation/files.cmake +++ /dev/null @@ -1,5 +0,0 @@ -file(GLOB_RECURSE H_FILES RELATIVE "${CMAKE_CURRENT_SOURCE_DIR}" "${CMAKE_CURRENT_SOURCE_DIR}/include/*") - -set(CPP_FILES - mitkPlanarFigureSegmentationController.cpp -) diff --git a/Modules/PlanarFigureSegmentation/include/mitkPlanarFigureSegmentationController.h b/Modules/PlanarFigureSegmentation/include/mitkPlanarFigureSegmentationController.h deleted file mode 100644 index eebc3ffcad..0000000000 --- a/Modules/PlanarFigureSegmentation/include/mitkPlanarFigureSegmentationController.h +++ /dev/null @@ -1,149 +0,0 @@ -/*=================================================================== - -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 mitkPlanarFigureSegmentationController_h_Included -#define mitkPlanarFigureSegmentationController_h_Included - -#include "mitkCommon.h" -#include "mitkImage.h" -#include - -#include "mitkPlanarFigure.h" -#include "mitkReduceContourSetFilter.h" -#include -#include -#include - -namespace mitk -{ - /** - * \brief This class creates a binary image from a set of PlanarFigures. - * - * The class offers a convenient way to create a binary image from a - * variable number of contours that are represented by PlanarFigures. - * - * The first step is to create a mitkSurface for each PlanarFigure. - * - * The actual segmentation is done by interpolating these surfaces - * by means of the mitkCreateDistanceImageFromSurfaceFilter. - * - * Using the vtkMarchingCubes a surface is created from the resulting - * distance-image. This surface is then turned into a binary image using the - * mitkSurfaceToImageFilter. - */ - - class MITKPLANARFIGURESEGMENTATION_EXPORT PlanarFigureSegmentationController : public itk::Object - { - public: - mitkClassMacroItkParent(PlanarFigureSegmentationController, itk::Object); - itkFactorylessNewMacro( - PlanarFigureSegmentationController) /// specify the segmentation image that should be interpolated - itkCloneMacro(Self) - - ~PlanarFigureSegmentationController() override; - - typedef std::vector PlanarFigureListType; - typedef std::vector SurfaceListType; - - /** - * \brief Setter for the reference image. - * - * The reference image is the image on which the segmentation is - * performed. It's needed to set the correct geometry information - * on the segmentation result (pixel-spacing, slice-thickness, etc.). - */ - void SetReferenceImage(Image::Pointer referenceImage); - - /** - * \brief Adds a new PlanarFigure to be considered in the interpolation. - * - * This method can be used to add a new contour, represented by a - * PlanarFigure, to be considered in the interpolation. - * - * It is not possible to add the same PlanarFigure twice. - * - * \warn The method does NOT check if there are two PlanarFigures on - * the same slice. Doing this will lead to wrong segmentation results. - */ - void AddPlanarFigure(PlanarFigure::Pointer planarFigure); - - void RemovePlanarFigure(mitk::PlanarFigure::Pointer planarFigure); - - /** - * \brief Performs the interpolation and returns the result - * as binary image. - * - * This method updates the CreateDistanceImageFromSurfaceFilter - * and creates a binary image from the resulting distance-image. - * - * This is done by creating an intermediate mitk::Surface that - * represents the interpolated 3D contour using the vtkMarchingCubes. - * - * The binary image is then extracted from the surface by means of - * the mitkSurfaceToImageFilter. - */ - Image::Pointer GetInterpolationResult(); - - /** - * \brief Method to create a surface from a PlanarFigure - * - * This method takes any kind of PlanarFigure and creates a - * surface-representation. - * The resulting surface contains of only ONE vtkPolygon that contains - * all points of the PlanarFigure's polyline. - */ - static Surface::Pointer CreateSurfaceFromPlanarFigure(PlanarFigure::Pointer figure); - - PlanarFigureListType GetAllPlanarFigures(); - - void SetReferenceDirectionVector(mitk::Vector3D vector); - - protected: - PlanarFigureSegmentationController(); - - void InitializeFilters(); - - template - void GetImageBase(itk::Image *input, itk::ImageBase<3>::Pointer &result); - - PlanarFigureListType m_PlanarFigureList; - SurfaceListType m_SurfaceList; - - /** - * \brief Filter to reduce the number of control points. - */ - ReduceContourSetFilter::Pointer m_ReduceFilter; - - /** - * \brief Filter to compute the normals for the created surface - */ - ComputeContourSetNormalsFilter::Pointer m_NormalsFilter; - - /** - * \brief Filter to create "distance-image" from contours. - */ - CreateDistanceImageFromSurfaceFilter::Pointer m_DistanceImageCreator; - - Image::Pointer m_ReferenceImage; - - Image::Pointer m_SegmentationAsImage; - - mitk::Vector3D m_ReferenceDirectionVector; - }; - -} // namespace - -#endif diff --git a/Modules/PlanarFigureSegmentation/src/mitkPlanarFigureSegmentationController.cpp b/Modules/PlanarFigureSegmentation/src/mitkPlanarFigureSegmentationController.cpp deleted file mode 100644 index ccbf32965e..0000000000 --- a/Modules/PlanarFigureSegmentation/src/mitkPlanarFigureSegmentationController.cpp +++ /dev/null @@ -1,303 +0,0 @@ -/*=================================================================== - -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 "mitkPlanarFigureSegmentationController.h" - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -mitk::PlanarFigureSegmentationController::PlanarFigureSegmentationController() - : itk::Object(), - m_ReduceFilter(nullptr), - m_NormalsFilter(nullptr), - m_DistanceImageCreator(nullptr), - m_ReferenceImage(nullptr), - m_SegmentationAsImage(nullptr) -{ - InitializeFilters(); -} - -mitk::PlanarFigureSegmentationController::~PlanarFigureSegmentationController() -{ -} - -void mitk::PlanarFigureSegmentationController::SetReferenceImage(mitk::Image::Pointer referenceImage) -{ - m_ReferenceImage = referenceImage; -} - -void mitk::PlanarFigureSegmentationController::AddPlanarFigure(mitk::PlanarFigure::Pointer planarFigure) -{ - if (planarFigure.IsNull()) - return; - - bool newFigure = true; - std::size_t indexOfFigure = 0; - for (std::size_t i = 0; i < m_PlanarFigureList.size(); i++) - { - if (m_PlanarFigureList.at(i) == planarFigure) - { - indexOfFigure = i; - newFigure = false; - break; - } - } - - mitk::Surface::Pointer figureAsSurface = nullptr; - - if (newFigure) - { - m_PlanarFigureList.push_back(planarFigure); - figureAsSurface = this->CreateSurfaceFromPlanarFigure(planarFigure); - m_SurfaceList.push_back(figureAsSurface); - if (!m_PlanarFigureList.empty()) - { - indexOfFigure = m_PlanarFigureList.size() - 1; - } - } - else - { - figureAsSurface = this->CreateSurfaceFromPlanarFigure(planarFigure); - m_SurfaceList.at(indexOfFigure) = figureAsSurface; - } - - if (m_ReduceFilter.IsNull()) - { - InitializeFilters(); - } - - m_ReduceFilter->SetInput(indexOfFigure, figureAsSurface); - - m_NormalsFilter->SetInput(indexOfFigure, m_ReduceFilter->GetOutput(indexOfFigure)); - m_DistanceImageCreator->SetInput(indexOfFigure, m_NormalsFilter->GetOutput(indexOfFigure)); -} - -void mitk::PlanarFigureSegmentationController::RemovePlanarFigure(mitk::PlanarFigure::Pointer planarFigure) -{ - if (planarFigure.IsNull()) - return; - - bool figureFound = false; - std::size_t indexOfFigure = 0; - for (std::size_t i = 0; i < m_PlanarFigureList.size(); i++) - { - if (m_PlanarFigureList.at(i) == planarFigure) - { - indexOfFigure = i; - figureFound = true; - break; - } - } - - if (!figureFound) - return; - - auto whereIter = m_PlanarFigureList.begin(); - whereIter += indexOfFigure; - m_PlanarFigureList.erase(whereIter); - - auto surfaceIter = m_SurfaceList.begin(); - surfaceIter += indexOfFigure; - m_SurfaceList.erase(surfaceIter); - - // TODO: fix this! The following code had to be removed as the method - // RemoveInputs() has been removed in ITK 4 - // The remaining code works correctly but is slower - if (false && indexOfFigure == m_PlanarFigureList.size() - 1) - { - // Ff the removed figure was the last one in the list, we can simply - // remove the last input from each filter. - // m_DistanceImageCreator->RemoveInputs( m_NormalsFilter->GetOutput( indexOfFigure ) ); - // m_NormalsFilter->RemoveInput( m_ReduceFilter->GetOutput( indexOfFigure ) ); - // m_ReduceFilter->RemoveInput( const_cast(m_ReduceFilter->GetInput(indexOfFigure)) ); - } - else - { - // this is not very nice! If the figure that has been removed is NOT the last - // one in the list we have to create new filters and add all remaining - // inputs again. - // - // Has to be done as the filters do not work when removing an input - // other than the last one. - - // create new filters - InitializeFilters(); - - // and add all existing surfaces - auto surfaceIter = m_SurfaceList.begin(); - int index = 0; - for (surfaceIter = m_SurfaceList.begin(); surfaceIter != m_SurfaceList.end(); surfaceIter++) - { - m_ReduceFilter->SetInput(index, (*surfaceIter)); - m_NormalsFilter->SetInput(index, m_ReduceFilter->GetOutput(index)); - m_DistanceImageCreator->SetInput(index, m_NormalsFilter->GetOutput(index)); - - ++index; - } - } -} - -template -void mitk::PlanarFigureSegmentationController::GetImageBase(itk::Image *input, - itk::ImageBase<3>::Pointer &result) -{ - result = input; -} - -mitk::Image::Pointer mitk::PlanarFigureSegmentationController::GetInterpolationResult() -{ - m_SegmentationAsImage = nullptr; - - if (m_PlanarFigureList.size() == 0) - { - m_SegmentationAsImage = mitk::Image::New(); - m_SegmentationAsImage->Initialize(mitk::MakeScalarPixelType(), *m_ReferenceImage->GetTimeGeometry()); - - return m_SegmentationAsImage; - } - - itk::ImageBase<3>::Pointer itkImage; - AccessFixedDimensionByItk_1(m_ReferenceImage.GetPointer(), GetImageBase, 3, itkImage); - m_DistanceImageCreator->SetReferenceImage(itkImage.GetPointer()); - - m_ReduceFilter->Update(); - m_NormalsFilter->Update(); - m_DistanceImageCreator->Update(); - - mitk::Image::Pointer distanceImage = m_DistanceImageCreator->GetOutput(); - - // Cleanup the pipeline - distanceImage->DisconnectPipeline(); - m_DistanceImageCreator = nullptr; - m_NormalsFilter = nullptr; - m_ReduceFilter = nullptr; - itkImage = nullptr; - - // If this bool flag is true, the distanceImage will be written to the - // filesystem as nrrd-image and as surface-representation. - bool debugOutput(false); - if (debugOutput) - { - mitk::IOUtil::Save(distanceImage, "v:/DistanceImage.nrrd"); - } - - mitk::ImageToSurfaceFilter::Pointer imageToSurfaceFilter = mitk::ImageToSurfaceFilter::New(); - imageToSurfaceFilter->SetInput(distanceImage); - imageToSurfaceFilter->SetThreshold(0); - imageToSurfaceFilter->Update(); - - mitk::Surface::Pointer segmentationAsSurface = imageToSurfaceFilter->GetOutput(); - - // Cleanup the pipeline - segmentationAsSurface->DisconnectPipeline(); - imageToSurfaceFilter = nullptr; - - if (debugOutput) - { - mitk::IOUtil::Save(segmentationAsSurface, "v:/DistanceImageAsSurface.vtk"); - } - - mitk::SurfaceToImageFilter::Pointer surfaceToImageFilter = mitk::SurfaceToImageFilter::New(); - surfaceToImageFilter->SetInput(segmentationAsSurface); - surfaceToImageFilter->SetImage(m_ReferenceImage); - surfaceToImageFilter->SetMakeOutputBinary(true); - surfaceToImageFilter->Update(); - - m_SegmentationAsImage = surfaceToImageFilter->GetOutput(); - - // Cleanup the pipeline - m_SegmentationAsImage->DisconnectPipeline(); - - return m_SegmentationAsImage; -} - -mitk::Surface::Pointer mitk::PlanarFigureSegmentationController::CreateSurfaceFromPlanarFigure( - mitk::PlanarFigure::Pointer figure) -{ - if (figure.IsNull()) - { - MITK_ERROR << "Given PlanarFigure is nullptr. Please provide valid PlanarFigure."; - return nullptr; - } - - mitk::Surface::Pointer newSurface = mitk::Surface::New(); - - vtkSmartPointer points = vtkSmartPointer::New(); - vtkSmartPointer polygon = vtkSmartPointer::New(); - vtkSmartPointer cells = vtkSmartPointer::New(); - vtkSmartPointer polyData = vtkSmartPointer::New(); - - const mitk::PlaneGeometry *figureGeometry = figure->GetPlaneGeometry(); - - // Get the polyline - mitk::PlanarFigure::PolyLineType planarPolyLine = figure->GetPolyLine(0); - mitk::PlanarFigure::PolyLineType::iterator iter; - - // iterate over the polyline, ... - int pointCounter = 0; - for (iter = planarPolyLine.begin(); iter != planarPolyLine.end(); iter++) - { - // ... determine the world-coordinates - mitk::Point3D pointInWorldCoordiantes; - figureGeometry->Map(*iter, pointInWorldCoordiantes); - - // and add them as new points to the vtkPoints - points->InsertNextPoint(pointInWorldCoordiantes[0], pointInWorldCoordiantes[1], pointInWorldCoordiantes[2]); - ++pointCounter; - } - - // create a polygon with the points of the polyline - polygon->GetPointIds()->SetNumberOfIds(pointCounter); - for (int i = 0; i < pointCounter; i++) - { - polygon->GetPointIds()->SetId(i, i); - } - - // initialize the vtkCellArray and vtkPolyData - cells->InsertNextCell(polygon); - polyData->SetPoints(points); - polyData->SetPolys(cells); - - // set the polydata to the surface - newSurface->SetVtkPolyData(polyData); - - return newSurface; -} - -mitk::PlanarFigureSegmentationController::PlanarFigureListType - mitk::PlanarFigureSegmentationController::GetAllPlanarFigures() -{ - return m_PlanarFigureList; -} - -void mitk::PlanarFigureSegmentationController::InitializeFilters() -{ - m_ReduceFilter = mitk::ReduceContourSetFilter::New(); - m_ReduceFilter->SetReductionType(ReduceContourSetFilter::NTH_POINT); - m_ReduceFilter->SetStepSize(10); - m_NormalsFilter = mitk::ComputeContourSetNormalsFilter::New(); - m_DistanceImageCreator = mitk::CreateDistanceImageFromSurfaceFilter::New(); -}