21 #include <vtkDoubleArray.h>
22 #include <vtkKdTree.h>
23 #include <vtkPointData.h>
24 #include <vtkPoints.h>
25 #include <vtkPolyVertex.h>
26 #include <vtkSmartPointer.h>
27 #include <vtkUnstructuredGrid.h>
31 this->SetNumberOfIndexedOutputs(1);
40 if (UnstructuredGridToUnstructuredGridFilter::GetNumberOfInputs() != 2)
42 MITK_ERROR <<
"Not enough input arguments for PointCloudScoringFilter" << std::endl;
46 DataObjectPointerArray inputs = UnstructuredGridToUnstructuredGridFilter::GetInputs();
50 if (edgeGrid->IsEmpty() || segmGrid->IsEmpty())
52 if (edgeGrid->IsEmpty())
53 MITK_ERROR <<
"edgeGrid is empty" << std::endl;
54 if (segmGrid->IsEmpty())
55 MITK_ERROR <<
"segmGrid is empty" << std::endl;
58 if (m_FilteredScores.size() > 0)
59 m_FilteredScores.clear();
61 vtkSmartPointer<vtkUnstructuredGrid> edgevtkGrid = edgeGrid->GetVtkUnstructuredGrid();
62 vtkSmartPointer<vtkUnstructuredGrid> segmvtkGrid = segmGrid->GetVtkUnstructuredGrid();
68 for (
int i = 0; i < edgevtkGrid->GetNumberOfPoints(); i++)
70 kdPoints->InsertNextPoint(edgevtkGrid->GetPoint(i));
73 kdTree->BuildLocatorFromPoints(kdPoints);
78 for (
int i = 0; i < segmvtkGrid->GetNumberOfPoints(); i++)
80 points->InsertNextPoint(segmvtkGrid->GetPoint(i));
83 std::vector<ScorePair> score;
84 std::vector<double> distances;
86 double dist_glob = 0.0;
89 for (
int i = 0; i < points->GetNumberOfPoints(); i++)
92 points->GetPoint(i, point);
93 kdTree->FindClosestPoint(point[0], point[1], point[2], dist);
95 distances.push_back(dist);
96 score.push_back(std::make_pair(i, dist));
99 double avg = dist_glob / points->GetNumberOfPoints();
102 double highest = 0.0;
104 for (
unsigned int i = 0; i < distances.size(); i++)
106 tmpVar = tmpVar + ((distances.at(i) - avg) * (distances.at(i) - avg));
107 if (distances.at(i) > highest)
108 highest = distances.at(i);
112 double cubicAll = 0.0;
113 for (
unsigned i = 0; i < score.size(); i++)
115 cubicAll = cubicAll + score.at(i).second * score.at(i).second * score.at(i).second;
117 double root2 = cubicAll /
static_cast<double>(score.size());
118 double cubic = pow(root2, 1.0 / 3.0);
121 double metricValue = cubic;
123 for (
unsigned int i = 0; i < score.size(); i++)
125 if (score.at(i).second > metricValue)
127 m_FilteredScores.push_back(std::make_pair(score.at(i).first, score.at(i).second));
131 m_NumberOfOutpPoints = m_FilteredScores.size();
137 pointDataDistances->SetNumberOfComponents(1);
138 pointDataDistances->SetNumberOfTuples(m_FilteredScores.size());
139 pointDataDistances->SetName(
"Distances");
141 for (
unsigned int i = 0; i < m_FilteredScores.size(); i++)
144 point = segmvtkGrid->GetPoint(m_FilteredScores.at(i).first);
145 filteredPoints->InsertNextPoint(point[0], point[1], point[2]);
146 if (score.at(i).second > 0.001)
148 double dist[1] = {score.at(i).second};
149 pointDataDistances->InsertTuple(i, dist);
153 double dist[1] = {0.0};
154 pointDataDistances->InsertTuple(i, dist);
158 unsigned int numPoints = filteredPoints->GetNumberOfPoints();
162 verts->GetPointIds()->SetNumberOfIds(numPoints);
163 for (
unsigned int i = 0; i < numPoints; i++)
165 verts->GetPointIds()->SetId(i, i);
171 uGrid->InsertNextCell(verts->GetCellType(), verts->GetPointIds());
172 uGrid->SetPoints(filteredPoints);
173 uGrid->GetPointData()->AddArray(pointDataDistances);
176 outputGrid->SetVtkUnstructuredGrid(uGrid);
177 this->SetNthOutput(0, outputGrid);
185 Superclass::GenerateOutputInformation();
PointCloudScoringFilter()
virtual void GenerateOutputInformation() override
Class for storing unstructured grids (vtkUnstructuredGrid)
virtual void GenerateData() override
virtual ~PointCloudScoringFilter()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.