diff --git a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp index 7c2c44aa09..0a71bbdd08 100644 --- a/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp +++ b/Modules/SurfaceInterpolation/mitkPointCloudScoringFilter.cpp @@ -1,119 +1,142 @@ /*=================================================================== 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 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()) { if(edgeSurface->IsEmpty()) MITK_ERROR << "Cannot convert EdgeSurface into Surfaces" << std::endl; if(segmSurface->IsEmpty()) MITK_ERROR << "Cannot convert SegmSurface into Surfaces" << std::endl; } 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); + unsigned int numPoints = filteredPoints->GetNumberOfPoints(); + + vtkSmartPointer polyLine = vtkSmartPointer::New(); + polyLine->GetPointIds()->SetNumberOfIds(numPoints); + + for(unsigned int i = 0; i < numPoints; i++) + { + polyLine->GetPointIds()->SetId(i,i); + } + + vtkSmartPointer cells = vtkSmartPointer::New(); + cells->InsertNextCell(polyLine); + + vtkSmartPointer polyData = vtkSmartPointer::New(); + + polyData->SetPoints(filteredPoints); + polyData->SetLines(cells); + + outpSurface->BuildCells(); + outpSurface->BuildLinks(); + m_OutpSurface->SetVtkPolyData(polyData); } void mitk::PointCloudScoringFilter::GenerateOutputInformation() { Superclass::GenerateOutputInformation(); }