diff --git a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp index b45d410b51..dd6ae412ba 100644 --- a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp +++ b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp @@ -1,139 +1,134 @@ /*=================================================================== 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 -#include -#include #include #include mitk::PointCloudScoringFilter::PointCloudScoringFilter(): m_NumberOfOutpPoints(0) { m_OutpGrid = mitk::UnstructuredGrid::New(); -// this->SetNumberOfRequiredInputs(2); -// this->SetNumberOfRequiredOutputs(1); this->SetNthOutput(0, m_OutpGrid); } mitk::PointCloudScoringFilter::~PointCloudScoringFilter(){} void mitk::PointCloudScoringFilter::GenerateData() { if(UnstructuredGridToUnstructuredGridFilter::GetNumberOfInputs()!=2) { MITK_ERROR << "Not enough input arguments for PointCloudScoringFilter" << std::endl; return; } DataObjectPointerArray inputs = UnstructuredGridToUnstructuredGridFilter::GetInputs(); mitk::UnstructuredGrid::Pointer edgeGrid = dynamic_cast(inputs.at(0).GetPointer()); mitk::UnstructuredGrid::Pointer segmGrid = dynamic_cast(inputs.at(1).GetPointer()); if(edgeGrid->IsEmpty() || segmGrid->IsEmpty()) { if(edgeGrid->IsEmpty()) MITK_ERROR << "Cannot convert edgeGrid into Surfaces" << std::endl; if(segmGrid->IsEmpty()) MITK_ERROR << "Cannot convert segmGrid into Surfaces" << std::endl; } vtkSmartPointer edgevtkGrid = edgeGrid->GetVtkUnstructuredGrid(); vtkSmartPointer segmvtkGrid = segmGrid->GetVtkUnstructuredGrid(); // KdTree from here vtkSmartPointer kdPoints = vtkSmartPointer::New(); vtkSmartPointer kdTree = vtkSmartPointer::New(); for(int i=0; iGetNumberOfPoints(); i++) { kdPoints->InsertNextPoint(edgevtkGrid->GetPoint(i)); } kdTree->BuildLocatorFromPoints(kdPoints); // KdTree until here vtkSmartPointer points = vtkSmartPointer::New(); for(int i=0; iGetNumberOfPoints(); i++) { points->InsertNextPoint(segmvtkGrid->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 filteredPoints = vtkSmartPointer::New(); for(unsigned int i=0; iGetPoint(m_FilteredScores.at(i).first); filteredPoints->InsertNextPoint(point[0],point[1],point[2]); } unsigned int numPoints = filteredPoints->GetNumberOfPoints(); vtkSmartPointer verts = vtkSmartPointer::New(); verts->GetPointIds()->SetNumberOfIds(numPoints); for(unsigned int i=0; iGetPointIds()->SetId(i,i); } vtkSmartPointer uGrid = vtkSmartPointer::New(); uGrid->Allocate(1); uGrid->InsertNextCell(verts->GetCellType(), verts->GetPointIds()); uGrid->SetPoints(filteredPoints); m_OutpGrid->SetVtkUnstructuredGrid(uGrid); } void mitk::PointCloudScoringFilter::GenerateOutputInformation() { Superclass::GenerateOutputInformation(); } diff --git a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h index 29e29aefe4..5a0d5e84e4 100644 --- a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h +++ b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.h @@ -1,87 +1,89 @@ /*=================================================================== 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 mitkPointCloudScoringFilter_h_Included #define mitkPointCloudScoringFilter_h_Included #include #include -#include + namespace mitk { +class UnstructuredGrid; + /** * @brief Scores an UnstructuredGrid as good as one matches to the other. * * The result UnstructureGrid of the filter are the points where the distance to * the closest point of the other UnstructuredGrid is higher than the average * distance from all points to their closest neighbours of the other * UnstructuredGrid. * The second input is the UnstructuredGrid, which you want to score. All Points * of the output UnstructuredGrid are from the second input. */ class MitkSurfaceInterpolation_EXPORT PointCloudScoringFilter: public UnstructuredGridToUnstructuredGridFilter { public: typedef std::pair ScorePair; mitkClassMacro( PointCloudScoringFilter, UnstructuredGridToUnstructuredGridFilter) itkFactorylessNewMacro(Self) itkCloneMacro(Self) /** Number of Points of the scored UnstructuredGrid. These points are far away * from their neighbours */ itkGetMacro(NumberOfOutpPoints, int) /** A vector in which the point IDs and their distance to their neighbours * is stored */ itkGetMacro(FilteredScores, std::vector< ScorePair >) protected: /** is called by the Update() method */ virtual void GenerateData(); /** Defines the output */ virtual void GenerateOutputInformation(); /** Constructor */ PointCloudScoringFilter(); /** Destructor */ virtual ~PointCloudScoringFilter(); private: /** The output UnstructuredGrid containing the scored points, which are far * aways from their neighbours */ mitk::UnstructuredGrid::Pointer m_OutpGrid; /** The Point IDs and their distance to their neighbours */ std::vector< ScorePair > m_FilteredScores; /** The number of points which are far aways from their neighbours */ int m_NumberOfOutpPoints; }; } #endif