ITK  4.6.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 #ifndef NULL
27 #define NULL 0
28 #endif
29 
30 namespace itk
31 {
49 template< typename TCoordType >
51  public MeshSource< VoronoiDiagram2D< TCoordType > >
52 {
53 public:
58 
60  itkNewMacro(Self);
61 
64 
68  typedef typename VDMesh::Pointer OutputType;
69  typedef typename VDMesh::PointType PointType;
70  typedef typename VDMesh::SeedsType SeedsType;
71  typedef typename VDMesh::EdgeInfo EdgeInfo;
72  typedef typename VDMesh::EdgeInfoDQ EdgeInfoDQ;
74  typedef typename VDMesh::VoronoiEdge VoronoiEdge;
75 
77  itkGetConstMacro(NumberOfSeeds, unsigned int);
78 
84  void SetSeeds(int num, SeedsIterator begin);
85 
87  void AddSeeds(int num, SeedsIterator begin);
88 
90  void AddOneSeed(PointType);
91 
93  void SortSeeds(void);
94 
96  virtual void GenerateOutputInformation() {}
97 
99  void UpdateDiagram(void);
100 
102  void SetBoundary(PointType vorsize);
103 
104  void SetOrigin(PointType vorsize);
105 
110  void SetRandomSeeds(int num);
111 
113  PointType GetSeed(int SeedID);
114 
115 protected:
118  virtual void PrintSelf(std::ostream & os, Indent indent) const;
119 
121  void GenerateData(void);
122 
123 private:
124  VoronoiDiagram2DGenerator(const Self &); //purposely not implemented
125  void operator=(const Self &); //purposely not implemented
126 
127  unsigned int m_NumberOfSeeds;
131 
133  static bool comp(PointType arg1, PointType arg2);
134 
141  class FortuneSite;
142  class FortuneEdge;
144 
145  // All private nested classes must be friend classes to work with SunOS-CC
146  // compiler. If not, the private nested classes will not be able to access
147  // each other.
148  friend class FortuneSite;
149  friend class FortuneEdge;
150  friend class FortuneHalfEdge;
151 
153  {
154  public:
157 
159  m_Sitenbr( NumericTraits< int >::max() )
160  {
162  }
163 
165  };
166 
168  {
169  public:
170  float m_A, m_B, m_C; // explicit line function: Ax + By = C;
174 
176  m_A(0.0),
177  m_B(0.0),
178  m_C(0.0),
179  m_Edgenbr(0)
180  {
181  m_Ep[0] = m_Ep[1] = m_Reg[0] = m_Reg[1] = ITK_NULLPTR;
182  }
183 
185  };
186 
188  {
189  public:
193  bool m_RorL;
195  double m_Ystar;
197 
199  m_Left(ITK_NULLPTR),
200  m_Right(ITK_NULLPTR),
201  m_Edge(ITK_NULLPTR),
202  m_RorL(false),
203  m_Vert(ITK_NULLPTR),
204  m_Ystar(0.0),
205  m_Next(ITK_NULLPTR)
206  {}
207 
209  m_Left(edge.m_Left),
210  m_Right(edge.m_Right),
211  m_Edge(edge.m_Edge),
212  m_RorL(edge.m_RorL),
213  m_Vert(edge.m_Vert),
214  m_Ystar(edge.m_Ystar),
215  m_Next(edge.m_Next)
216  {}
217 
219  };
220 
221  double m_Pxmin;
222  double m_Pxmax;
223  double m_Pymin;
224  double m_Pymax;
225  double m_Deltax;
226  double m_Deltay;
227  double m_SqrtNSites;
228 
229  unsigned int m_PQcount;
230  int m_PQmin;
231  unsigned int m_PQhashsize;
232  unsigned int m_Nedges;
233  unsigned int m_Nvert;
235  std::vector< FortuneHalfEdge > m_PQHash;
236 
237  unsigned int m_ELhashsize;
240  std::vector< FortuneHalfEdge * > m_ELHash;
241 
243  std::vector< FortuneSite > m_SeedSites;
244 
248  bool differentPoint(PointType p1, PointType p2);
249 
250  bool almostsame(CoordRepType p1, CoordRepType p2);
251 
252  unsigned char Pointonbnd(int VertID);
253 
254  void GenerateVDFortune(void);
255 
256  void ConstructDiagram(void);
257 
258  void createHalfEdge(FortuneHalfEdge *task, FortuneEdge *e, bool pm);
259 
260  void PQshowMin(PointType *task);
261 
263 
264  FortuneHalfEdge * ELgethash(int b);
265 
270  bool right_of(FortuneHalfEdge *el, PointType *p);
271 
273 
275 
276  void bisect(FortuneEdge *, FortuneSite *s1, FortuneSite *s2);
277 
278  void insertEdgeList(FortuneHalfEdge *lbase, FortuneHalfEdge *lnew);
279 
280  void intersect(FortuneSite *task, FortuneHalfEdge *el1, FortuneHalfEdge *el2);
281 
282  void deletePQ(FortuneHalfEdge *task);
283 
284  void deleteEdgeList(FortuneHalfEdge *task);
285 
286  int PQbucket(FortuneHalfEdge *task);
287 
288  void clip_line(FortuneEdge *task);
289 
290  void insertPQ(FortuneHalfEdge *he, FortuneSite *v, double offset);
291 
292  double dist(FortuneSite *s1, FortuneSite *s2);
293 
294  FortuneHalfEdge * getPQmin(void);
295 
296  void makeEndPoint(FortuneEdge *task, bool lr, FortuneSite *ends);
297 };
298 } // end namespace itk
299 
300 #ifndef ITK_MANUAL_INSTANTIATION
301 #include "itkVoronoiDiagram2DGenerator.hxx"
302 #endif
303 
304 #endif
std::vector< FortuneHalfEdge * > m_ELHash
bool right_of(FortuneHalfEdge *el, PointType *p)
void makeEndPoint(FortuneEdge *task, bool lr, FortuneSite *ends)
Light weight base class for most itk classes.
void createHalfEdge(FortuneHalfEdge *task, FortuneEdge *e, bool pm)
void SetSeeds(int num, SeedsIterator begin)
void clip_line(FortuneEdge *task)
void bisect(FortuneEdge *, FortuneSite *s1, FortuneSite *s2)
bool differentPoint(PointType p1, PointType p2)
virtual void PrintSelf(std::ostream &os, Indent indent) const
static bool comp(PointType arg1, PointType arg2)
SeedsType::iterator SeedsIterator
unsigned char Pointonbnd(int VertID)
Implements the 2-Dimensional Voronoi Diagram.
std::vector< FortuneHalfEdge > m_PQHash
static const double e
The base of the natural logarithm or Euler&#39;s number
Definition: itkMath.h:45
MeshTraits::CoordRepType CoordRepType
void insertEdgeList(FortuneHalfEdge *lbase, FortuneHalfEdge *lnew)
void Fill(const ValueType &)
Base class for all process objects that output mesh data.
Definition: itkMeshSource.h:49
double dist(FortuneSite *s1, FortuneSite *s2)
MeshSource< VoronoiDiagram2D< TCoordType > > Superclass
VoronoiDiagram2D< TCoordType > VDMesh
FortuneHalfEdge * ELgethash(int b)
void insertPQ(FortuneHalfEdge *he, FortuneSite *v, double offset)
void intersect(FortuneSite *task, FortuneHalfEdge *el1, FortuneHalfEdge *el2)
void operator=(const Self &)
void PQshowMin(PointType *task)
FortuneHalfEdge * getPQmin(void)
Small data structures for Fortune&#39;s Method and some public variables/methods not for external access...
FortuneSite * getLeftReg(FortuneHalfEdge *he)
void deleteEdgeList(FortuneHalfEdge *task)
FortuneHalfEdge * findLeftHE(PointType *p)
Implement the Sweep Line Algorithm for the construction of the 2D Voronoi Diagram.
Control indentation during Print() invocation.
Definition: itkIndent.h:49
void SetBoundary(PointType vorsize)
int PQbucket(FortuneHalfEdge *task)
FortuneSite * getRightReg(FortuneHalfEdge *he)
void SetOrigin(PointType vorsize)
Define additional traits for native types such as int or float.
std::vector< PointType > SeedsType
PointType GetSeed(int SeedID)
void deletePQ(FortuneHalfEdge *task)
void AddSeeds(int num, SeedsIterator begin)
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:51
std::deque< EdgeInfo > EdgeInfoDQ
bool almostsame(CoordRepType p1, CoordRepType p2)