ITK  6.0.0
Insight Toolkit
itkVoronoiDiagram2DGenerator.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 itkVoronoiDiagram2DGenerator_h
19 #define itkVoronoiDiagram2DGenerator_h
20 
21 #include "itkMeshSource.h"
22 #include "itkVoronoiDiagram2D.h"
23 
24 #include <vector>
25 
26 namespace itk
27 {
49 template <typename TCoordinate>
50 class ITK_TEMPLATE_EXPORT VoronoiDiagram2DGenerator : public MeshSource<VoronoiDiagram2D<TCoordinate>>
51 {
52 public:
53  ITK_DISALLOW_COPY_AND_MOVE(VoronoiDiagram2DGenerator);
54 
59 
61  itkNewMacro(Self);
62 
64  itkOverrideGetNameOfClassMacro(VoronoiDiagram2DGenerator);
65 
70  using OutputType = typename VDMesh::Pointer;
71  using PointType = typename VDMesh::PointType;
72  using SeedsType = typename VDMesh::SeedsType;
73  using EdgeInfo = typename VDMesh::EdgeInfo;
74  using EdgeInfoDQ = typename VDMesh::EdgeInfoDQ;
76 #ifndef ITK_FUTURE_LEGACY_REMOVE
77  using CoordRepType ITK_FUTURE_DEPRECATED(
78  "ITK 6 discourages using `CoordRepType`. Please use `CoordinateType` instead!") = CoordinateType;
79 #endif
80  using VoronoiEdge = typename VDMesh::VoronoiEdge;
81 
83  itkGetConstMacro(NumberOfSeeds, unsigned int);
84 
88  void
89  SetSeeds(int num, SeedsIterator begin);
90 
92  void
93  AddSeeds(int num, SeedsIterator begin);
94 
96  void AddOneSeed(PointType);
97 
99  void
100  SortSeeds();
101 
103  void
105  {}
106 
108  void
109  UpdateDiagram();
110 
112  void
113  SetBoundary(PointType vorsize);
114 
115  void
116  SetOrigin(PointType vorsize);
117 
119  void
120  SetRandomSeeds(int num);
121 
123  PointType
124  GetSeed(int SeedID);
125 
126 protected:
128  ~VoronoiDiagram2DGenerator() override = default;
129  void
130  PrintSelf(std::ostream & os, Indent indent) const override;
131 
133  void
134  GenerateData() override;
135 
136 private:
137  unsigned int m_NumberOfSeeds{ 0 };
138  PointType m_VorBoundary{};
139  OutputType m_OutputVD{};
140  SeedsType m_Seeds{};
141 
143  static bool
144  comp(PointType arg1, PointType arg2);
145 
152  class FortuneSite;
153  class FortuneEdge;
155 
156  // All private nested classes must be friend classes to work with SunOS-CC
157  // compiler. If not, the private nested classes will not be able to access
158  // each other.
159  friend class FortuneSite;
160  friend class FortuneEdge;
161  friend class FortuneHalfEdge;
162 
164  {
165  public:
168 
170  : m_Sitenbr(NumericTraits<int>::max())
171  {
172  m_Coord.Fill(NumericTraits<CoordinateType>::max());
173  }
174 
175  ~FortuneSite() = default;
176  };
177 
179  {
180  public:
181  float m_A{ 0.0 }, m_B{ 0.0 }, m_C{ 0.0 }; // explicit line function: Ax + By = C;
182  FortuneSite * m_Ep[2];
183  FortuneSite * m_Reg[2];
184  int m_Edgenbr{ 0 };
185 
186  FortuneEdge() { m_Ep[0] = m_Ep[1] = m_Reg[0] = m_Reg[1] = nullptr; }
187 
188  ~FortuneEdge() = default;
189  };
190 
192  {
193  public:
197  bool m_RorL{ false };
199  double m_Ystar{ 0.0 };
201 
203  : m_Left(nullptr)
204  , m_Right(nullptr)
205  , m_Edge(nullptr)
206  , m_Vert(nullptr)
207  , m_Next(nullptr)
208  {}
209 
211  : m_Left(edge.m_Left)
212  , m_Right(edge.m_Right)
213  , m_Edge(edge.m_Edge)
214  , m_RorL(edge.m_RorL)
215  , m_Vert(edge.m_Vert)
216  , m_Ystar(edge.m_Ystar)
217  , m_Next(edge.m_Next)
218  {}
219 
220  ~FortuneHalfEdge() = default;
221  };
222 
223  double m_Pxmin{ 0.0 };
224  double m_Pxmax{ 0.0 };
225  double m_Pymin{ 0.0 };
226  double m_Pymax{ 0.0 };
227  double m_Deltax{ 0.0 };
228  double m_Deltay{ 0.0 };
229  double m_SqrtNSites{ 0.0 };
230 
231  unsigned int m_PQcount{ 0 };
232  int m_PQmin{ 0 };
233  unsigned int m_PQhashsize{ 0 };
234  unsigned int m_Nedges{ 0 };
235  unsigned int m_Nvert{ 0 };
236  FortuneSite * m_BottomSite{};
237  std::vector<FortuneHalfEdge> m_PQHash{};
238 
239  unsigned int m_ELhashsize{ 0 };
240  FortuneHalfEdge m_ELleftend{};
241  FortuneHalfEdge m_ELrightend{};
242  std::vector<FortuneHalfEdge *> m_ELHash{};
243 
244  FortuneEdge m_DELETED{};
245  std::vector<FortuneSite> m_SeedSites{};
246 
250  bool
251  differentPoint(PointType p1, PointType p2);
252 
253  bool
254  almostsame(CoordinateType p1, CoordinateType p2);
255 
256  unsigned char
257  Pointonbnd(int VertID);
258 
259  void
260  GenerateVDFortune();
261 
262  void
263  ConstructDiagram();
264 
265  void
266  createHalfEdge(FortuneHalfEdge * task, FortuneEdge * e, bool pm);
267 
268  void
269  PQshowMin(PointType * answer);
270 
271  FortuneHalfEdge *
272  findLeftHE(PointType * p);
273 
274  FortuneHalfEdge *
275  ELgethash(int b);
276 
281  bool
282  right_of(FortuneHalfEdge * el, PointType * p);
283 
284  FortuneSite *
285  getRightReg(FortuneHalfEdge * he);
286 
287  FortuneSite *
288  getLeftReg(FortuneHalfEdge * he);
289 
290  void
291  bisect(FortuneEdge *, FortuneSite * s1, FortuneSite * s2);
292 
293  void
294  insertEdgeList(FortuneHalfEdge * lbase, FortuneHalfEdge * lnew);
295 
296  void
297  intersect(FortuneSite * newV, FortuneHalfEdge * el1, FortuneHalfEdge * el2);
298 
299  void
300  deletePQ(FortuneHalfEdge * task);
301 
302  void
303  deleteEdgeList(FortuneHalfEdge * task);
304 
305  int
306  PQbucket(FortuneHalfEdge * task);
307 
308  void
309  clip_line(FortuneEdge * task);
310 
311  void
312  insertPQ(FortuneHalfEdge * he, FortuneSite * v, double offset);
313 
314  double
315  dist(FortuneSite * s1, FortuneSite * s2);
316 
317  FortuneHalfEdge *
318  getPQmin();
319 
320  void
321  makeEndPoint(FortuneEdge * task, bool lr, FortuneSite * ends);
322 };
323 } // end namespace itk
324 
325 #ifndef ITK_MANUAL_INSTANTIATION
326 # include "itkVoronoiDiagram2DGenerator.hxx"
327 #endif
328 
329 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::VoronoiDiagram2D::EdgeInfoDQ
std::deque< EdgeInfo > EdgeInfoDQ
Definition: itkVoronoiDiagram2D.h:117
itk::VoronoiDiagram2D
Implements the 2-Dimensional Voronoi Diagram.
Definition: itkVoronoiDiagram2D.h:51
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::m_Edge
FortuneEdge * m_Edge
Definition: itkVoronoiDiagram2DGenerator.h:196
itk::VoronoiDiagram2DGenerator::EdgeInfoDQ
typename VDMesh::EdgeInfoDQ EdgeInfoDQ
Definition: itkVoronoiDiagram2DGenerator.h:74
itk::VoronoiDiagram2DGenerator::EdgeInfo
typename VDMesh::EdgeInfo EdgeInfo
Definition: itkVoronoiDiagram2DGenerator.h:73
itk::GTest::TypedefsAndConstructors::Dimension2::PointType
ImageBaseType::PointType PointType
Definition: itkGTestTypedefsAndConstructors.h:51
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::m_Vert
FortuneSite * m_Vert
Definition: itkVoronoiDiagram2DGenerator.h:198
itk::VoronoiDiagram2DGenerator::FortuneSite::m_Sitenbr
int m_Sitenbr
Definition: itkVoronoiDiagram2DGenerator.h:167
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::FortuneHalfEdge
FortuneHalfEdge(const FortuneHalfEdge &edge)
Definition: itkVoronoiDiagram2DGenerator.h:210
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::m_Right
FortuneHalfEdge * m_Right
Definition: itkVoronoiDiagram2DGenerator.h:195
itk::MeshSource
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
itkVoronoiDiagram2D.h
itkMeshSource.h
itk::VoronoiDiagram2DGenerator::SeedsIterator
typename VDMesh::SeedsIterator SeedsIterator
Definition: itkVoronoiDiagram2DGenerator.h:69
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge
Definition: itkVoronoiDiagram2DGenerator.h:191
itk::VoronoiDiagram2DGenerator::FortuneEdge
Definition: itkVoronoiDiagram2DGenerator.h:178
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::m_Left
FortuneHalfEdge * m_Left
Definition: itkVoronoiDiagram2DGenerator.h:194
itk::VoronoiDiagram2DGenerator::FortuneSite
Small data structures for Fortune's Method and some public variables/methods not for external access.
Definition: itkVoronoiDiagram2DGenerator.h:163
itk::NumericTraits
Define additional traits for native types such as int or float.
Definition: itkNumericTraits.h:60
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::m_Next
FortuneHalfEdge * m_Next
Definition: itkVoronoiDiagram2DGenerator.h:200
itk::VoronoiDiagram2DGenerator::FortuneHalfEdge::FortuneHalfEdge
FortuneHalfEdge()
Definition: itkVoronoiDiagram2DGenerator.h:202
itk::VoronoiDiagram2DGenerator::FortuneEdge::FortuneEdge
FortuneEdge()
Definition: itkVoronoiDiagram2DGenerator.h:186
itk::VoronoiDiagram2DGenerator::CoordinateType
typename VDMesh::CoordinateType CoordinateType
Definition: itkVoronoiDiagram2DGenerator.h:75
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::VoronoiDiagram2D::CoordinateType
typename MeshTraits::CoordinateType CoordinateType
Definition: itkVoronoiDiagram2D.h:78
itk::VoronoiDiagram2DGenerator::SeedsType
typename VDMesh::SeedsType SeedsType
Definition: itkVoronoiDiagram2DGenerator.h:72
itk::VoronoiDiagram2D::SeedsIterator
typename SeedsType::iterator SeedsIterator
Definition: itkVoronoiDiagram2D.h:120
itk::VoronoiDiagram2DGenerator::GenerateOutputInformation
void GenerateOutputInformation() override
Definition: itkVoronoiDiagram2DGenerator.h:104
itk::Math::e
static constexpr double e
Definition: itkMath.h:56
itk::Point
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:53
itk::VoronoiDiagram2DGenerator::OutputType
typename VDMesh::Pointer OutputType
Definition: itkVoronoiDiagram2DGenerator.h:70
itk::VoronoiDiagram2DGenerator
Implement the Sweep Line Algorithm for the construction of the 2D Voronoi Diagram.
Definition: itkVoronoiDiagram2DGenerator.h:50
itk::VoronoiDiagram2DGenerator::FortuneSite::m_Coord
PointType m_Coord
Definition: itkVoronoiDiagram2DGenerator.h:166
itk::VoronoiDiagram2DGenerator::PointType
typename VDMesh::PointType PointType
Definition: itkVoronoiDiagram2DGenerator.h:71
itk::VoronoiDiagram2DGenerator::VoronoiEdge
typename VDMesh::VoronoiEdge VoronoiEdge
Definition: itkVoronoiDiagram2DGenerator.h:80
itk::VoronoiDiagram2D::SeedsType
std::vector< PointType > SeedsType
Definition: itkVoronoiDiagram2D.h:119
itk::VoronoiDiagram2D::VoronoiEdge
Definition: itkVoronoiDiagram2D.h:168
itk::VoronoiDiagram2DGenerator::FortuneSite::FortuneSite
FortuneSite()
Definition: itkVoronoiDiagram2DGenerator.h:169