ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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 TCoordinate>
51class ITK_TEMPLATE_EXPORT VoronoiDiagram2D
52 : public Mesh<TCoordinate, 2, DefaultDynamicMeshTraits<TCoordinate, 2, 2, TCoordinate>>
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;
75
79#ifndef ITK_FUTURE_LEGACY_REMOVE
80 using CoordRepType ITK_FUTURE_DEPRECATED(
81 "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
82#endif
97 using PointsContainerPointer = typename PointsContainer::Pointer;
98 using CellsContainerPointer = typename CellsContainer::Pointer;
99 using CellLinksContainerPointer = typename CellLinksContainer::Pointer;
100 using PointDataContainerPointer = typename PointDataContainer::Pointer;
101 using CellDataContainerPointer = typename CellDataContainer::Pointer;
103 using PointsContainerConstIterator = typename PointsContainer::ConstIterator;
104 using PointsContainerIterator = typename PointsContainer::Iterator;
105 using CellsContainerConstIterator = typename CellsContainer::ConstIterator;
106 using CellsContainerIterator = typename CellsContainer::Iterator;
107 using CellLinksContainerIterator = typename CellLinksContainer::ConstIterator;
108 using PointDataContainerIterator = typename PointDataContainer::ConstIterator;
109 using CellDataContainerIterator = typename CellDataContainer::ConstIterator;
110 using PointCellLinksContainerIterator = typename PointCellLinksContainer::const_iterator;
111
113 using typename Superclass::CellType;
114 using typename Superclass::CellAutoPointer;
117 using EdgeInfoDQ = std::deque<EdgeInfo>;
118 using CellMultiVisitorType = typename CellType::MultiVisitor;
119 using SeedsType = std::vector<PointType>;
120 using SeedsIterator = typename SeedsType::iterator;
122 using EdgeAutoPointer = typename Edge::SelfAutoPointer;
123 using PointList = std::list<PointType>;
124 using INTvector = std::vector<int>;
125 using NeighborIdIterator = typename INTvector::iterator;
128 itkGetConstMacro(NumberOfSeeds, unsigned int);
129
132 void
133 SetSeeds(int num, SeedsIterator begin);
134
136 void
138
139 void
141
145
147 NeighborIdsEnd(int seeds);
148
152
155
158 GetSeed(int SeedID);
159
161 void
163
165 void
166 GetPoint(int pId, PointType * answer);
167
169 {
170 public:
176 VoronoiEdge() = default;
177 ~VoronoiEdge() = default;
178 };
179
181 using VoronoiEdgeIterator = typename std::vector<VoronoiEdge>::iterator;
182
186
189
192 GetSeedsIDAroundEdge(VoronoiEdge * task);
193
194 /********************************************************/
195
196 void
198
199 void
201
202 void
204 {
205 m_CellNeighborsID[x[0]].push_back(x[1]);
206 m_CellNeighborsID[x[1]].push_back(x[0]);
207 }
208
209 void
211 {
212 m_VoronoiRegions[i]->ClearPoints();
213 }
214
215 void
217 {
218 m_VoronoiRegions[id]->AddPointId(x);
219 }
220
221 void
222 BuildEdge(int id)
223 {
224 m_VoronoiRegions[id]->BuildEdges();
225 }
226
227 void
229 {
230 m_LineList.clear();
231 }
232
233 void
235 {
236 m_EdgeList.clear();
237 }
238
239 void
241 {
242 if (this->m_PointsContainer.IsNull())
243 {
244 this->m_PointsContainer = PointsContainer::New();
245 }
246
247 this->m_PointsContainer->Initialize();
248 }
249
250 int
252 {
253 return static_cast<int>(m_LineList.size());
254 }
255
256 int
258 {
259 return static_cast<int>(m_EdgeList.size());
260 }
261
262 int
264 {
265 return static_cast<int>(this->m_PointsContainer->Size());
266 }
267
268 void
270 {
271 m_LineList.push_back(x);
272 }
273
274 void
275 AddEdge(VoronoiEdge x)
276 {
277 m_EdgeList.push_back(x);
278 }
279
280 void
282 {
283 this->m_PointsContainer->InsertElement(this->m_PointsContainer->Size(), x);
284 }
285
286 EdgeInfo
287 GetLine(int id)
288 {
289 return m_LineList[id];
290 }
291
292 VoronoiEdge
293 GetEdge(int id)
294 {
295 return m_EdgeList[id];
296 }
297
298 PointType
299 GetVertex(int id)
300 {
301 return this->m_PointsContainer->ElementAt(id);
302 }
303
304 EdgeInfo
306 {
307 EdgeInfo x;
308
309 x[0] = m_EdgeList[id].m_LeftID;
310 x[1] = m_EdgeList[id].m_RightID;
311 return x;
312 }
313
314 int
316 {
317 return m_EdgeList[id].m_LineID;
318 }
319
320protected:
322 ~VoronoiDiagram2D() override = default;
323 void
324 PrintSelf(std::ostream & os, Indent indent) const override;
325
326private:
328 unsigned int m_NumberOfSeeds{};
329 std::vector<PolygonCellType *> m_VoronoiRegions{};
332 std::vector<std::vector<int>> m_CellNeighborsID{};
333
334 std::vector<EdgeInfo> m_LineList{};
335 std::vector<VoronoiEdge> m_EdgeList{};
336};
337
338} // end namespace itk
339
340#ifndef ITK_MANUAL_INSTANTIATION
341# include "itkVoronoiDiagram2D.hxx"
342#endif
343
344#endif
Represent and compute information about bounding boxes.
A simple structure that holds type information for a mesh and its cells.
static constexpr unsigned int MaxTopologicalDimension
MapContainer< PointIdentifier, PointCellLinksContainer > CellLinksContainer
static constexpr unsigned int PointDimension
Control indentation during Print() invocation.
Definition itkIndent.h:50
Represents a line segment for a Mesh.
Definition itkLineCell.h:41
PointsContainerPointer m_PointsContainer
A templated class holding a geometric point in n-Dimensional space.
Definition itkPoint.h:54
Represents a polygon in a Mesh.
Implements transparent reference counting.
typename CellLinksContainer::ConstIterator CellLinksContainerIterator
void SetBoundary(PointType vorsize)
typename SeedsType::iterator SeedsIterator
~VoronoiDiagram2D() override=default
VoronoiEdge GetEdge(int id)
typename MeshTraits::PointCellLinksContainer PointCellLinksContainer
typename BoundingBoxType::Pointer BoundingBoxPointer
typename MeshTraits::CellIdentifier CellIdentifier
PointsContainerIterator VertexIterator
std::vector< std::vector< int > > m_CellNeighborsID
typename MeshTraits::PointIdentifier PointIdentifier
void SetSeeds(int num, SeedsIterator begin)
std::vector< PointType > SeedsType
typename CellsContainer::Pointer CellsContainerPointer
VoronoiEdgeIterator EdgeBegin()
typename MeshTraits::CoordinateType CoordinateType
static constexpr unsigned int MaxTopologicalDimension
typename PointCellLinksContainer::const_iterator PointCellLinksContainerIterator
typename MeshTraits::CellTraits CellTraits
typename PointsContainer::Iterator PointsContainerIterator
typename MeshTraits::CellAutoPointer genericCellPointer
typename PointDataContainer::Pointer PointDataContainerPointer
PointType GetVertex(int id)
typename MeshTraits::PointsContainer PointsContainer
typename PointsContainer::Pointer PointsContainerPointer
PolygonCell< CellType > PolygonCellType
SmartPointer< const Self > ConstPointer
PointType GetSeed(int SeedID)
std::vector< VoronoiEdge > m_EdgeList
void SetOrigin(PointType vorsize)
typename std::vector< VoronoiEdge >::iterator VoronoiEdgeIterator
void VoronoiRegionAddPointId(int id, int x)
DefaultDynamicMeshTraits< TCoordinate, 2, 2, TCoordinate > MeshTraits
typename MeshTraits::PointType PointType
typename MeshTraits::InterpolationWeightType InterpolationWeightType
NeighborIdIterator NeighborIdsEnd(int seeds)
typename MeshTraits::CellsContainer CellsContainer
static constexpr unsigned int PointDimension
void AddEdge(VoronoiEdge x)
void PrintSelf(std::ostream &os, Indent indent) const override
typename PointDataContainer::ConstIterator PointDataContainerIterator
typename CellDataContainer::Pointer CellDataContainerPointer
void AddCellNeighbor(EdgeInfo x)
LineCell< CellType > Edge
typename MeshTraits::PixelType PixelType
typename Edge::SelfAutoPointer EdgeAutoPointer
typename CellsContainer::Iterator CellsContainerIterator
typename INTvector::iterator NeighborIdIterator
BoundingBox< PointIdentifier, Self::PointDimension, CoordinateType, PointsContainer > BoundingBoxType
typename CellType::MultiVisitor CellMultiVisitorType
NeighborIdIterator NeighborIdsBegin(int seeds)
SmartPointer< Self > Pointer
std::vector< PolygonCellType * > m_VoronoiRegions
void GetCellId(CellIdentifier cellId, CellAutoPointer &)
VertexIterator VertexBegin()
void GetPoint(int pId, PointType *answer)
EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task)
VoronoiEdgeIterator EdgeEnd()
typename PointsContainer::ConstIterator PointsContainerConstIterator
VertexIterator VertexEnd()
std::deque< EdgeInfo > EdgeInfoDQ
typename CellLinksContainer::Pointer CellLinksContainerPointer
typename CellDataContainer::ConstIterator CellDataContainerIterator
typename MeshTraits::PointDataContainer PointDataContainer
typename CellsContainer::ConstIterator CellsContainerConstIterator
typename MeshTraits::CellLinksContainer CellLinksContainer
std::vector< int > INTvector
typename MeshTraits::CellFeatureIdentifier CellFeatureIdentifier
typename MeshTraits::CellDataContainer CellDataContainer
std::list< PointType > PointList
Mesh< TCoordinate, 2, DefaultDynamicMeshTraits< TCoordinate, 2, 2, TCoordinate > > Superclass
CellFeatureIdentifier CellFeatureCount
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....