21 #include <vtkDataArray.h>
22 #include <vtkDelaunay3D.h>
23 #include <vtkDoubleArray.h>
24 #include <vtkPointData.h>
25 #include <vtkPointLocator.h>
26 #include <vtkPoints.h>
27 #include <vtkPolyVertex.h>
28 #include <vtkSmartPointer.h>
29 #include <vtkUnstructuredGrid.h>
30 #include <vtkVariant.h>
33 : m_eps(5.0), m_MinPts(4), m_Meshing(false), m_DistCalc(false)
52 m_UnstructGrid = this->GetOutput();
58 if (inputGrid.IsNull())
61 vtkSmartPointer<vtkUnstructuredGrid> vtkInpGrid = inputGrid->GetVtkUnstructuredGrid();
62 vtkSmartPointer<vtkPoints> inpPoints = vtkInpGrid->GetPoints();
66 if (inputGrid->GetVtkUnstructuredGrid()->GetPointData()->GetNumberOfArrays() > 0)
69 distances =
dynamic_cast<vtkDoubleArray *
>(vtkInpGrid->GetPointData()->GetArray(0));
74 pLocator->SetNumberOfPointsPerBucket(2);
78 for (
int i = 0; i < inpPoints->GetNumberOfPoints(); i++)
82 clusterMember[i] =
false;
85 for (
int i = 0; i < inpPoints->GetNumberOfPoints(); i++)
91 pLocator->FindPointsWithinRadius(m_eps, inpPoints->GetPoint(i), idList);
92 if (idList->GetNumberOfIds() < m_MinPts)
99 clusterVector.push_back(cluster);
101 i, idList, cluster, inpPoints);
108 int numberOfClusterPoints = 0;
109 int IdOfBiggestCluster = 0;
111 for (
unsigned int i = 0; i < m_Clusters.size(); i++)
114 vtkSmartPointer<vtkPoints> points = m_Clusters.at(i);
117 array->SetNumberOfComponents(1);
118 array->SetNumberOfTuples(points->GetNumberOfPoints());
119 for (
int j = 0; j < points->GetNumberOfPoints(); j++)
122 points->GetPoint(j, point);
123 if (clustersPointsIDs.at(i).at(j) < inpPoints->GetNumberOfPoints())
125 if (distances->GetValue(clustersPointsIDs.at(i).at(j)) > 0.001)
127 double dist[1] = {distances->GetValue(clustersPointsIDs.at(i).at(j))};
128 array->SetTuple(j, dist);
132 double dist[1] = {0.0};
133 array->SetTuple(j, dist);
137 m_DistanceArrays.push_back(array);
139 if (points->GetNumberOfPoints() > numberOfClusterPoints)
141 numberOfClusterPoints = points->GetNumberOfPoints();
142 IdOfBiggestCluster = i;
149 points = m_Clusters.at(IdOfBiggestCluster);
152 verts->GetPointIds()->SetNumberOfIds(m_Clusters.at(IdOfBiggestCluster)->GetNumberOfPoints());
153 for (
int i = 0; i < m_Clusters.at(IdOfBiggestCluster)->GetNumberOfPoints(); i++)
155 verts->GetPointIds()->SetId(i, i);
158 biggestCluster->Allocate(1);
159 biggestCluster->InsertNextCell(verts->GetCellType(), verts->GetPointIds());
160 biggestCluster->SetPoints(m_Clusters.at(IdOfBiggestCluster));
165 mesher->SetInputData(biggestCluster);
166 mesher->SetAlpha(0.9);
169 vtkSmartPointer<vtkUnstructuredGrid> output = mesher->GetOutput();
170 m_UnstructGrid->SetVtkUnstructuredGrid(output);
174 m_UnstructGrid->SetVtkUnstructuredGrid(biggestCluster);
177 clusterVector.clear();
178 clustersPointsIDs.clear();
181 void mitk::UnstructuredGridClusteringFilter::ExpandCluster(
int id,
184 vtkPoints *inpPoints)
188 cluster->InsertNextPoint(inpPoints->GetPoint(
id));
189 clusterMember[id] =
true;
192 inpPoints->GetPoints(pointIDs, neighbours);
194 for (
int i = 0; i < pointIDs->GetNumberOfIds(); i++)
196 if (!visited[pointIDs->GetId(i)])
198 visited[pointIDs->GetId(i)] =
true;
201 m_eps, inpPoints->GetPoint(pointIDs->GetId(i)), idList);
203 if (idList->GetNumberOfIds() >= m_MinPts)
205 for (
int j = 0; j < idList->GetNumberOfIds(); j++)
207 if (idList->GetId(j) < inpPoints->GetNumberOfPoints())
209 pointIDs->InsertNextId(idList->GetId(j));
214 if (!clusterMember[pointIDs->GetId(i)])
216 if (pointIDs->GetId(i) < inpPoints->GetNumberOfPoints())
218 clusterMember[pointIDs->GetId(i)] =
true;
219 x.push_back(pointIDs->GetId(i));
220 cluster->InsertNextPoint(inpPoints->GetPoint(pointIDs->GetId(i)));
225 clustersPointsIDs.push_back(x);
230 std::vector<mitk::UnstructuredGrid::Pointer> mitkUGridVector;
232 for (
unsigned int i = 0; i < m_Clusters.size(); i++)
236 vtkSmartPointer<vtkPoints> points = m_Clusters.at(i);
240 verts->GetPointIds()->SetNumberOfIds(points->GetNumberOfPoints());
241 for (
int j = 0; j < points->GetNumberOfPoints(); j++)
243 verts->GetPointIds()->SetId(j, j);
246 cluster->Allocate(1);
247 cluster->InsertNextCell(verts->GetCellType(), verts->GetPointIds());
248 cluster->SetPoints(points);
251 cluster->GetPointData()->AddArray(m_DistanceArrays.at(i));
259 mesher->SetInputData(cluster);
260 mesher->SetAlpha(0.9);
263 vtkSmartPointer<vtkUnstructuredGrid> output = mesher->GetOutput();
264 mitkGrid->SetVtkUnstructuredGrid(output);
268 mitkGrid->SetVtkUnstructuredGrid(cluster);
271 mitkUGridVector.push_back(mitkGrid);
274 return mitkUGridVector;
279 return m_Clusters.size();
virtual void GenerateOutputInformation()
std::vector< std::vector< int > > clustersPointsIDs
std::map< int, bool > isNoise
std::map< int, bool > visited
UnstructuredGridClusteringFilter()
virtual void GenerateData()
std::vector< vtkSmartPointer< vtkPoints > > clusterVector
virtual std::vector< mitk::UnstructuredGrid::Pointer > GetAllClusters()
virtual int GetNumberOfFoundClusters()
std::map< int, bool > clusterMember
vtkSmartPointer< vtkPointLocator > pLocator
Class for storing unstructured grids (vtkUnstructuredGrid)
virtual ~UnstructuredGridClusteringFilter()
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.