19 #include <vtkPointSet.h>
22 : m_SearchTreeInitialized(false),
24 m_MitkPoints(nullptr),
29 m_ANNDataPoints(nullptr),
30 m_ANNQueryPoint(nullptr),
31 m_ANNPointIndexes(nullptr),
32 m_ANNDistances(nullptr),
39 if (m_SearchTreeInitialized)
45 if (pointSet ==
nullptr)
47 itkWarningMacro(
"Points are NULL!");
50 vtkPoints *points = pointSet->GetPoints();
54 if ((m_VtkPoints == points) && (m_VtkPoints->GetMTime() == points->GetMTime()))
61 size_t size = points->GetNumberOfPoints();
62 if (m_ANNDataPoints !=
nullptr)
63 delete[] m_ANNDataPoints;
64 m_ANNDataPoints = annAllocPts(size, m_ANNDimension);
65 m_IndexToPointIdContainer.clear();
66 m_IndexToPointIdContainer.resize(size);
67 for (vtkIdType i = 0; (unsigned)i < size; ++i)
69 double *currentPoint = points->GetPoint(i);
70 (m_ANNDataPoints[i])[0] = currentPoint[0];
71 (m_ANNDataPoints[i])[1] = currentPoint[1];
72 (m_ANNDataPoints[i])[2] = currentPoint[2];
73 m_IndexToPointIdContainer[i] = i;
80 if (points ==
nullptr)
82 itkWarningMacro(
"Points are NULL!");
88 if ((m_MitkPoints == points) && (m_MitkPoints->GetMTime() == points->
GetMTime()))
93 m_MitkPoints = points;
95 size_t size = points->
GetSize();
96 if (m_ANNDataPoints !=
nullptr)
97 delete[] m_ANNDataPoints;
98 m_ANNDataPoints = annAllocPts(size, m_ANNDimension);
99 m_IndexToPointIdContainer.clear();
100 m_IndexToPointIdContainer.resize(size);
103 mitk::PointSet::PointsContainer::Iterator it;
105 mitk::PointSet::PointsContainer::ElementIdentifier currentId;
106 for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it, ++counter)
108 currentPoint = it->Value();
109 currentId = it->Index();
110 (m_ANNDataPoints[counter])[0] = currentPoint[0];
111 (m_ANNDataPoints[counter])[1] = currentPoint[1];
112 (m_ANNDataPoints[counter])[2] = currentPoint[2];
113 m_IndexToPointIdContainer[counter] = currentId;
120 if (pointSet ==
nullptr)
122 itkWarningMacro(
"Points are NULL!");
128 if ((m_ItkPoints == pointSet) && (m_ItkPoints->GetMTime() == pointSet->GetMTime()))
133 m_ItkPoints = pointSet;
135 size_t size = pointSet->GetNumberOfPoints();
136 if (m_ANNDataPoints !=
nullptr)
137 delete[] m_ANNDataPoints;
138 m_ANNDataPoints = annAllocPts(size, m_ANNDimension);
139 m_IndexToPointIdContainer.clear();
140 m_IndexToPointIdContainer.resize(size);
142 ITKPointSet::PointsContainerConstPointer pointsContainer = pointSet->GetPoints();
143 ITKPointSet::PointsContainer::ConstIterator it;
145 ITKPointSet::PointsContainer::ElementIdentifier currentId;
146 for (it = pointsContainer->Begin(); it != pointsContainer->End(); ++it, ++counter)
148 currentPoint = it->Value();
149 currentId = it->Index();
150 (m_ANNDataPoints[counter])[0] = currentPoint[0];
151 (m_ANNDataPoints[counter])[1] = currentPoint[1];
152 (m_ANNDataPoints[counter])[2] = currentPoint[2];
153 m_IndexToPointIdContainer[counter] = currentId;
160 m_ANNQueryPoint[0] = point[0];
161 m_ANNQueryPoint[1] = point[1];
162 m_ANNQueryPoint[2] = point[2];
163 return FindClosestANNPoint(m_ANNQueryPoint);
168 m_ANNQueryPoint[0] = x;
169 m_ANNQueryPoint[1] = y;
170 m_ANNQueryPoint[2] = z;
171 return FindClosestANNPoint(m_ANNQueryPoint);
176 m_ANNQueryPoint[0] = point[0];
177 m_ANNQueryPoint[1] = point[1];
178 m_ANNQueryPoint[2] = point[2];
179 return FindClosestANNPoint(m_ANNQueryPoint);
184 if (!m_SearchTreeInitialized)
186 m_ANNTree->annkSearch(point, m_ANNK, m_ANNPointIndexes, m_ANNDistances);
187 return m_IndexToPointIdContainer[m_ANNPointIndexes[0]];
192 m_ANNQueryPoint[0] = point[0];
193 m_ANNQueryPoint[1] = point[1];
194 m_ANNQueryPoint[2] = point[2];
195 return GetMinimalDistance(m_ANNQueryPoint);
200 if (!m_SearchTreeInitialized)
202 m_ANNTree->annkSearch(point, m_ANNK, m_ANNPointIndexes, m_ANNDistances);
203 return m_ANNDistances[0];
208 if (m_SearchTreeInitialized)
211 m_ANNQueryPoint = annAllocPt(m_ANNDimension);
212 m_ANNPointIndexes =
new ANNidx[m_ANNK];
213 m_ANNDistances =
new ANNdist[m_ANNK];
214 m_ANNTree =
new ANNkd_tree(m_ANNDataPoints, m_IndexToPointIdContainer.size(), m_ANNDimension);
216 m_SearchTreeInitialized =
true;
221 m_SearchTreeInitialized =
false;
222 if (m_ANNQueryPoint !=
nullptr)
223 annDeallocPt(m_ANNQueryPoint);
224 if (m_ANNDataPoints !=
nullptr)
225 annDeallocPts(m_ANNDataPoints);
226 if (m_ANNPointIndexes !=
nullptr)
227 delete[] m_ANNPointIndexes;
228 if (m_ANNDistances !=
nullptr)
229 delete[] m_ANNDistances;
230 if (m_ANNTree !=
nullptr)
236 m_ANNQueryPoint[0] = point[0];
237 m_ANNQueryPoint[1] = point[1];
238 m_ANNQueryPoint[2] = point[2];
240 m_ANNTree->annkSearch(m_ANNQueryPoint, m_ANNK, m_ANNPointIndexes, m_ANNDistances);
242 *
id = m_IndexToPointIdContainer[m_ANNPointIndexes[0]];
243 *dist = m_ANNDistances[0];
virtual int GetSize(unsigned int t=0) const
returns the current size of the point-list
DistanceType GetMinimalDistance(mitk::PointSet::PointType point)
void SetPoints(vtkPointSet *points)
bool FindClosestPointAndDistance(mitk::PointSet::PointType point, IdType *id, DistanceType *dist)
Data structure which stores a set of points. Superclass of mitk::Mesh.
virtual DataType::Pointer GetPointSet(int t=0) const
returns the pointset
virtual unsigned long GetMTime() const override
Get the modified time of the last change of the contents this data object or its geometry.
DataType::PointsContainer PointsContainer
itk::PointSet< PixelType, 3, MeshTraits > ITKPointSet
IdType FindClosestANNPoint(const MyANNpoint &point)
IdType FindClosestPoint(const double point[3])