diff --git a/Modules/SurfaceInterpolation/files.cmake b/Modules/SurfaceInterpolation/files.cmake index 0dd9c14810..1d2cbec81c 100644 --- a/Modules/SurfaceInterpolation/files.cmake +++ b/Modules/SurfaceInterpolation/files.cmake @@ -1,6 +1,7 @@ set(CPP_FILES mitkComputeContourSetNormalsFilter.cpp mitkCreateDistanceImageFromSurfaceFilter.cpp mitkReduceContourSetFilter.cpp mitkSurfaceInterpolationController.cpp -) \ No newline at end of file + mitkPointCloudScoringFilter.cpp +) diff --git a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp new file mode 100644 index 0000000000..c8b0f79d95 --- /dev/null +++ b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp @@ -0,0 +1,119 @@ +/*=================================================================== + +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 "mitkPointCloudScoringFilter.h" + +#include +#include +#include +#include + +mitk::PointCloudScoringFilter::PointCloudScoringFilter(): + m_NumberOfOutpPoints(0) +{ + m_OutpSurface = mitk::Surface::New(); + this->SetNumberOfRequiredInputs(2); + this->SetNumberOfRequiredOutputs(1); + + this->SetNthOutput(0, m_OutpSurface); +} + +mitk::PointCloudScoringFilter::~PointCloudScoringFilter(){} + +void mitk::PointCloudScoringFilter::GenerateData() +{ + if(SurfaceToSurfaceFilter::GetNumberOfInputs()!=2) + { + MITK_ERROR << "Not enough input arguments for PointCloudScoringFilter" << std::endl; + return; + } + + DataObjectPointerArray inputs = SurfaceToSurfaceFilter::GetInputs(); + mitk::Surface::Pointer edgeSurface = dynamic_cast(inputs.at(0).GetPointer()); + mitk::Surface::Pointer segmSurface = dynamic_cast(inputs.at(1).GetPointer()); + + if(edgeSurface->IsEmpty() || segmSurface->IsEmpty()) + { + MITK_ERROR << "Cannot convert input into Surfaces" << std::endl; + return; + } + + vtkSmartPointer edgePolyData = edgeSurface->GetVtkPolyData(); + vtkSmartPointer segmPolyData = segmSurface->GetVtkPolyData(); + + // KdTree from here + vtkSmartPointer kdPoints = vtkSmartPointer::New(); + vtkSmartPointer kdTree = vtkSmartPointer::New(); + + for(int i=0; iGetNumberOfPoints(); i++) + { + kdPoints->InsertNextPoint(edgePolyData->GetPoint(i)); + } + + kdTree->BuildLocatorFromPoints(kdPoints); + // KdTree until here + + vtkSmartPointer points = vtkSmartPointer::New(); + + for(int i=0; iGetNumberOfPoints(); i++) + { + points->InsertNextPoint(segmPolyData->GetPoint(i)); + } + + std::vector< ScorePair > score; + + double dist_glob; + double dist; + + for(int i=0; iGetNumberOfPoints(); i++) + { + double point[3]; + points->GetPoint(i,point); + kdTree->FindClosestPoint(point[0],point[1],point[2],dist); + dist_glob+=dist; + score.push_back(std::make_pair(i,dist)); + } + + double avg = dist_glob / points->GetNumberOfPoints(); + + for(unsigned int i=0; i avg) + { + m_FilteredScores.push_back(std::make_pair(score.at(i).first,score.at(i).second)); + } + } + + m_NumberOfOutpPoints = m_FilteredScores.size(); + + vtkSmartPointer outpSurface = vtkSmartPointer::New(); + vtkSmartPointer filteredPoints = vtkSmartPointer::New(); + + for(unsigned int i=0; iGetPoint(m_FilteredScores.at(i).first); + filteredPoints->InsertNextPoint(point[0],point[1],point[2]); + } + + outpSurface->SetPoints(filteredPoints); + m_OutpSurface->SetVtkPolyData(outpSurface); +} + +void mitk::PointCloudScoringFilter::GenerateOutputInformation() +{ + Superclass::GenerateOutputInformation(); +} diff --git a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h new file mode 100644 index 0000000000..36122d41a1 --- /dev/null +++ b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h @@ -0,0 +1,65 @@ +/*=================================================================== + +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 mitkImageToPointCloudFilter_h_Included +#define mitkImageToPointCloudFilter_h_Included + +#include +#include + +#include "mitkSurface.h" + +namespace mitk +{ + +class MitkSurfaceInterpolation_EXPORT PointCloudScoringFilter: + public SurfaceToSurfaceFilter +{ + +public: + + typedef std::pair ScorePair; + + mitkClassMacro( PointCloudScoringFilter, SurfaceToSurfaceFilter) + + itkFactorylessNewMacro(Self) + itkCloneMacro(Self) + + itkGetMacro(NumberOfOutpPoints, int) + itkGetMacro(FilteredScores, std::vector< ScorePair >) + +protected: + + virtual void GenerateData(); + + virtual void GenerateOutputInformation(); + + PointCloudScoringFilter(); + + virtual ~PointCloudScoringFilter(); + +private: + + mitk::Surface::Pointer m_OutpSurface; + + std::vector< ScorePair > m_FilteredScores; + + int m_NumberOfOutpPoints; + +}; + +} +#endif