ITK  5.0.0
Insight Segmentation and Registration Toolkit
itkVoronoiDiagram2DGenerator.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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  * http://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 {
45 template< typename TCoordType >
46 class ITK_TEMPLATE_EXPORT VoronoiDiagram2DGenerator:
47  public MeshSource< VoronoiDiagram2D< TCoordType > >
48 {
49 public:
50  ITK_DISALLOW_COPY_AND_ASSIGN(VoronoiDiagram2DGenerator);
51 
56 
58  itkNewMacro(Self);
59 
62 
67  using OutputType = typename VDMesh::Pointer;
68  using PointType = typename VDMesh::PointType;
69  using SeedsType = typename VDMesh::SeedsType;
70  using EdgeInfo = typename VDMesh::EdgeInfo;
71  using EdgeInfoDQ = typename VDMesh::EdgeInfoDQ;
73  using VoronoiEdge = typename VDMesh::VoronoiEdge;
74 
76  itkGetConstMacro(NumberOfSeeds, unsigned int);
77 
81  void SetSeeds(int num, SeedsIterator begin);
82 
84  void AddSeeds(int num, SeedsIterator begin);
85 
87  void AddOneSeed(PointType);
88 
90  void SortSeeds();
91 
93  void GenerateOutputInformation() override {}
94 
96  void UpdateDiagram();
97 
99  void SetBoundary(PointType vorsize);
100 
101  void SetOrigin(PointType vorsize);
102 
104  void SetRandomSeeds(int num);
105 
107  PointType GetSeed(int SeedID);
108 
109 protected:
111  ~VoronoiDiagram2DGenerator() override = default;
112  void PrintSelf(std::ostream & os, Indent indent) const override;
113 
115  void GenerateData() override;
116 
117 private:
118  unsigned int m_NumberOfSeeds{ 0 };
122 
124  static bool comp(PointType arg1, PointType arg2);
125 
132  class FortuneSite;
133  class FortuneEdge;
135 
136  // All private nested classes must be friend classes to work with SunOS-CC
137  // compiler. If not, the private nested classes will not be able to access
138  // each other.
139  friend class FortuneSite;
140  friend class FortuneEdge;
141  friend class FortuneHalfEdge;
142 
144  {
145  public:
148 
150  m_Sitenbr( NumericTraits< int >::max() )
151  {
152  m_Coord.Fill( NumericTraits< CoordRepType >::max() );
153  }
154 
155  ~FortuneSite()= default;
156  };
157 
159  {
160  public:
161  float m_A{0.0}, m_B{0.0}, m_C{0.0}; // explicit line function: Ax + By = C;
162  FortuneSite *m_Ep[2];
163  FortuneSite *m_Reg[2];
164  int m_Edgenbr{0};
165 
167 
168  {
169  m_Ep[0] = m_Ep[1] = m_Reg[0] = m_Reg[1] = nullptr;
170  }
171 
172  ~FortuneEdge()= default;
173  };
174 
176  {
177  public:
181  bool m_RorL{false};
183  double m_Ystar{0.0};
185 
187  m_Left(nullptr),
188  m_Right(nullptr),
189  m_Edge(nullptr),
190  m_Vert(nullptr),
191  m_Next(nullptr)
192  {}
193 
195  m_Left(edge.m_Left),
196  m_Right(edge.m_Right),
197  m_Edge(edge.m_Edge),
198  m_RorL(edge.m_RorL),
199  m_Vert(edge.m_Vert),
200  m_Ystar(edge.m_Ystar),
201  m_Next(edge.m_Next)
202  {}
203 
204  ~FortuneHalfEdge() = default;
205  };
206 
207  double m_Pxmin{ 0.0 };
208  double m_Pxmax{ 0.0 };
209  double m_Pymin{ 0.0 };
210  double m_Pymax{ 0.0 };
211  double m_Deltax{ 0.0 };
212  double m_Deltay{ 0.0 };
213  double m_SqrtNSites{ 0.0 };
214 
215  unsigned int m_PQcount{ 0 };
216  int m_PQmin{ 0 };
217  unsigned int m_PQhashsize{ 0 };
218  unsigned int m_Nedges{ 0 };
219  unsigned int m_Nvert{ 0 };
221  std::vector< FortuneHalfEdge > m_PQHash;
222 
223  unsigned int m_ELhashsize{ 0 };
226  std::vector< FortuneHalfEdge * > m_ELHash;
227 
229  std::vector< FortuneSite > m_SeedSites;
230 
234  bool differentPoint(PointType p1, PointType p2);
235 
236  bool almostsame(CoordRepType p1, CoordRepType p2);
237 
238  unsigned char Pointonbnd(int VertID);
239 
240  void GenerateVDFortune();
241 
242  void ConstructDiagram();
243 
244  void createHalfEdge(FortuneHalfEdge *task, FortuneEdge *e, bool pm);
245 
246  void PQshowMin(PointType *task);
247 
248  FortuneHalfEdge * findLeftHE(PointType *p);
249 
250  FortuneHalfEdge * ELgethash(int b);
251 
256  bool right_of(FortuneHalfEdge *el, PointType *p);
257 
258  FortuneSite * getRightReg(FortuneHalfEdge *he);
259 
260  FortuneSite * getLeftReg(FortuneHalfEdge *he);
261 
262  void bisect(FortuneEdge *, FortuneSite *s1, FortuneSite *s2);
263 
264  void insertEdgeList(FortuneHalfEdge *lbase, FortuneHalfEdge *lnew);
265 
266  void intersect(FortuneSite *task, FortuneHalfEdge *el1, FortuneHalfEdge *el2);
267 
268  void deletePQ(FortuneHalfEdge *task);
269 
270  void deleteEdgeList(FortuneHalfEdge *task);
271 
272  int PQbucket(FortuneHalfEdge *task);
273 
274  void clip_line(FortuneEdge *task);
275 
276  void insertPQ(FortuneHalfEdge *he, FortuneSite *v, double offset);
277 
278  double dist(FortuneSite *s1, FortuneSite *s2);
279 
280  FortuneHalfEdge * getPQmin();
281 
282  void makeEndPoint(FortuneEdge *task, bool lr, FortuneSite *ends);
283 };
284 } // end namespace itk
285 
286 #ifndef ITK_MANUAL_INSTANTIATION
287 #include "itkVoronoiDiagram2DGenerator.hxx"
288 #endif
289 
290 #endif
std::vector< FortuneHalfEdge * > m_ELHash
Light weight base class for most itk classes.
Define numeric traits for std::vector.
typename VDMesh::CoordRepType CoordRepType
typename VDMesh::VoronoiEdge VoronoiEdge
std::vector< PointType > SeedsType
Implements the 2-Dimensional Voronoi Diagram.
std::vector< FortuneHalfEdge > m_PQHash
typename VDMesh::EdgeInfoDQ EdgeInfoDQ
std::deque< EdgeInfo > EdgeInfoDQ
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
Small data structures for Fortune&#39;s Method and some public variables/methods not for external access...
static constexpr double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:53
Implement the Sweep Line Algorithm for the construction of the 2D Voronoi Diagram.
typename MeshTraits::CoordRepType CoordRepType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
typename VDMesh::SeedsIterator SeedsIterator
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
typename SeedsType::iterator SeedsIterator