ITK  5.4.0
Insight Toolkit
itkVoronoiDiagram2D.h
Go to the documentation of this file.
1/*=========================================================================
2 *
3 * Copyright NumFOCUS
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * https://www.apache.org/licenses/LICENSE-2.0.txt
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 *
17 *=========================================================================*/
18#ifndef itkVoronoiDiagram2D_h
19#define itkVoronoiDiagram2D_h
20
21
22#include "itkMesh.h"
24#include "itkPolygonCell.h"
25#include <vector>
26
27namespace itk
28{
50template <typename TCoordType>
51class ITK_TEMPLATE_EXPORT VoronoiDiagram2D
52 : public Mesh<TCoordType, 2, DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType>>
53{
54public:
55 ITK_DISALLOW_COPY_AND_MOVE(VoronoiDiagram2D);
56
62
64 itkNewMacro(Self);
65
67 itkOverrideGetNameOfClassMacro(VoronoiDiagram2D);
68
71
73 static constexpr unsigned int PointDimension = MeshTraits::PointDimension;
74 static constexpr unsigned int MaxTopologicalDimension = MeshTraits::MaxTopologicalDimension;
75
99 using PointsContainerConstIterator = typename PointsContainer::ConstIterator;
100 using PointsContainerIterator = typename PointsContainer::Iterator;
101 using CellsContainerConstIterator = typename CellsContainer::ConstIterator;
102 using CellsContainerIterator = typename CellsContainer::Iterator;
103 using CellLinksContainerIterator = typename CellLinksContainer::ConstIterator;
104 using PointDataContainerIterator = typename PointDataContainer::ConstIterator;
105 using CellDataContainerIterator = typename CellDataContainer::ConstIterator;
106 using PointCellLinksContainerIterator = typename PointCellLinksContainer::const_iterator;
107
109 using typename Superclass::CellType;
110 using typename Superclass::CellAutoPointer;
113 using EdgeInfoDQ = std::deque<EdgeInfo>;
115 using SeedsType = std::vector<PointType>;
116 using SeedsIterator = typename SeedsType::iterator;
118 using EdgeAutoPointer = typename Edge::SelfAutoPointer;
119 using PointList = std::list<PointType>;
120 using INTvector = std::vector<int>;
121 using NeighborIdIterator = typename INTvector::iterator;
124 itkGetConstMacro(NumberOfSeeds, unsigned int);
125
128 void
129 SetSeeds(int num, SeedsIterator begin);
130
132 void
134
135 void
137
141
143 NeighborIdsEnd(int seeds);
144
148
151
154 GetSeed(int SeedID);
155
157 void
159
161 void
162 GetPoint(int pId, PointType * answer);
163
165 {
166 public:
172 VoronoiEdge() = default;
173 ~VoronoiEdge() = default;
174 };
175
177 using VoronoiEdgeIterator = typename std::vector<VoronoiEdge>::iterator;
178
182
185
189
190 /********************************************************/
191
192 void
194
195 void
197
198 void
200 {
201 m_CellNeighborsID[x[0]].push_back(x[1]);
202 m_CellNeighborsID[x[1]].push_back(x[0]);
203 }
204
205 void
207 {
208 m_VoronoiRegions[i]->ClearPoints();
209 }
210
211 void
213 {
214 m_VoronoiRegions[id]->AddPointId(x);
215 }
216
217 void
218 BuildEdge(int id)
219 {
220 m_VoronoiRegions[id]->BuildEdges();
221 }
222
223 void
225 {
226 m_LineList.clear();
227 }
228
229 void
231 {
232 m_EdgeList.clear();
233 }
234
235 void
237 {
238 if (this->m_PointsContainer.IsNull())
239 {
240 this->m_PointsContainer = PointsContainer::New();
241 }
242
243 this->m_PointsContainer->Initialize();
244 }
245
246 int
248 {
249 return static_cast<int>(m_LineList.size());
250 }
251
252 int
254 {
255 return static_cast<int>(m_EdgeList.size());
256 }
257
258 int
260 {
261 return static_cast<int>(this->m_PointsContainer->Size());
262 }
263
264 void
266 {
267 m_LineList.push_back(x);
268 }
269
270 void
272 {
273 m_EdgeList.push_back(x);
274 }
275
276 void
278 {
279 this->m_PointsContainer->InsertElement(this->m_PointsContainer->Size(), x);
280 }
281
282 EdgeInfo
283 GetLine(int id)
284 {
285 return m_LineList[id];
286 }
287
288 VoronoiEdge
289 GetEdge(int id)
290 {
291 return m_EdgeList[id];
292 }
293
295 GetVertex(int id)
296 {
297 return this->m_PointsContainer->ElementAt(id);
298 }
299
300 EdgeInfo
302 {
303 EdgeInfo x;
304
305 x[0] = m_EdgeList[id].m_LeftID;
306 x[1] = m_EdgeList[id].m_RightID;
307 return x;
308 }
309
310 int
312 {
313 return m_EdgeList[id].m_LineID;
314 }
315
316protected:
318 ~VoronoiDiagram2D() override = default;
319 void
320 PrintSelf(std::ostream & os, Indent indent) const override;
321
322private:
323 SeedsType m_Seeds{};
324 unsigned int m_NumberOfSeeds{};
325 std::vector<PolygonCellType *> m_VoronoiRegions{};
326 PointType m_VoronoiBoundary{};
327 PointType m_VoronoiBoundaryOrigin{};
328 std::vector<std::vector<int>> m_CellNeighborsID{};
329
330 std::vector<EdgeInfo> m_LineList{};
331 std::vector<VoronoiEdge> m_EdgeList{};
332};
333
334} // end namespace itk
335
336#ifndef ITK_MANUAL_INSTANTIATION
337# include "itkVoronoiDiagram2D.hxx"
338#endif
339
340#endif
Represent and compute information about bounding boxes.
A visitor that can visit different cell types in a mesh. CellInterfaceVisitor instances can be regist...
Base class for all data objects in ITK.
A simple structure that holds type information for a mesh and its cells.
typename CellType::CellAutoPointer CellAutoPointer
std::set< CellIdentifier > PointCellLinksContainer
Control indentation during Print() invocation.
Definition: itkIndent.h:50
Represents a line segment for a Mesh.
Definition: itkLineCell.h:46
A wrapper of the STL "map" container.
Implements the N-dimensional mesh structure.
Definition: itkMesh.h:127
Base class for most ITK classes.
Definition: itkObject.h:62
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:54
Represents a polygon in a Mesh.
Implements the 2-Dimensional Voronoi Diagram.
typename std::vector< VoronoiEdge >::iterator VoronoiEdgeIterator
typename CellType::MultiVisitor CellMultiVisitorType
VertexIterator VertexBegin()
typename MeshTraits::PointType PointType
void GetCellId(CellIdentifier cellId, CellAutoPointer &)
typename CellsContainer::Pointer CellsContainerPointer
typename MeshTraits::PixelType PixelType
typename MeshTraits::CoordRepType CoordRepType
typename CellDataContainer::ConstIterator CellDataContainerIterator
typename CellDataContainer::Pointer CellDataContainerPointer
typename SeedsType::iterator SeedsIterator
typename PointDataContainer::ConstIterator PointDataContainerIterator
typename MeshTraits::CellTraits CellTraits
void SetOrigin(PointType vorsize)
typename PointsContainer::ConstIterator PointsContainerConstIterator
NeighborIdIterator NeighborIdsEnd(int seeds)
typename MeshTraits::CellsContainer CellsContainer
typename MeshTraits::PointsContainer PointsContainer
typename MeshTraits::CellDataContainer CellDataContainer
typename PointsContainer::Pointer PointsContainerPointer
typename MeshTraits::PointDataContainer PointDataContainer
void AddCellNeighbor(EdgeInfo x)
void AddVert(PointType x)
VoronoiEdge GetEdge(int id)
VertexIterator VertexEnd()
typename INTvector::iterator NeighborIdIterator
typename CellLinksContainer::ConstIterator CellLinksContainerIterator
void SetSeeds(int num, SeedsIterator begin)
PointType GetSeed(int SeedID)
PointType GetVertex(int id)
typename PointDataContainer::Pointer PointDataContainerPointer
VoronoiEdgeIterator EdgeBegin()
CellFeatureIdentifier CellFeatureCount
typename MeshTraits::InterpolationWeightType InterpolationWeightType
typename MeshTraits::CellLinksContainer CellLinksContainer
typename MeshTraits::CellFeatureIdentifier CellFeatureIdentifier
void VoronoiRegionAddPointId(int id, int x)
typename BoundingBoxType::Pointer BoundingBoxPointer
NeighborIdIterator NeighborIdsBegin(int seeds)
void SetBoundary(PointType vorsize)
PointsContainerIterator VertexIterator
EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task)
EdgeInfo GetEdgeEnd(int id)
typename MeshTraits::PointIdentifier PointIdentifier
typename PointCellLinksContainer::const_iterator PointCellLinksContainerIterator
typename Edge::SelfAutoPointer EdgeAutoPointer
typename MeshTraits::CellIdentifier CellIdentifier
typename MeshTraits::CellAutoPointer genericCellPointer
void AddEdge(VoronoiEdge x)
typename CellsContainer::ConstIterator CellsContainerConstIterator
std::vector< int > INTvector
VoronoiEdgeIterator EdgeEnd()
typename MeshTraits::PointCellLinksContainer PointCellLinksContainer
typename CellLinksContainer::Pointer CellLinksContainerPointer
std::vector< PointType > SeedsType
void PrintSelf(std::ostream &os, Indent indent) const override
~VoronoiDiagram2D() override=default
typename CellsContainer::Iterator CellsContainerIterator
std::list< PointType > PointList
typename PointsContainer::Iterator PointsContainerIterator
std::deque< EdgeInfo > EdgeInfoDQ
void GetPoint(int pId, PointType *answer)
static Pointer New()
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....