00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkVoronoiDiagram2DGenerator_h
00018 #define __itkVoronoiDiagram2DGenerator_h
00019
00020 #include "itkCellInterface.h"
00021 #include "itkLineCell.h"
00022 #include "itkMeshSource.h"
00023 #include "itkDefaultDynamicMeshTraits.h"
00024 #include "itkPolygonCell.h"
00025 #include "itkVoronoiDiagram2D.h"
00026
00027 #include <vector>
00028
00029 #ifndef NULL
00030 #define NULL 0
00031 #endif
00032
00033 namespace itk
00034 {
00052 template <typename TCoordType>
00053 class ITK_EXPORT VoronoiDiagram2DGenerator:
00054 public MeshSource <VoronoiDiagram2D<TCoordType> >
00055 {
00056 public:
00057 typedef VoronoiDiagram2DGenerator Self;
00058 typedef MeshSource <VoronoiDiagram2D<TCoordType> > Superclass;
00059 typedef SmartPointer<Self> Pointer;
00060 typedef SmartPointer<const Self> ConstPointer;
00061
00063 itkNewMacro(Self);
00064
00066 itkTypeMacro(VoronoiDiagram2DGenerator, MeshSource);
00067
00069 typedef VoronoiDiagram2D<TCoordType> VDMesh;
00070 typedef typename VDMesh::SeedsIterator SeedsIterator;
00071 typedef typename VDMesh::Pointer OutputType;
00072 typedef typename VDMesh::PointType PointType;
00073 typedef typename VDMesh::SeedsType SeedsType;
00074 typedef typename VDMesh::EdgeInfo EdgeInfo;
00075 typedef typename VDMesh::EdgeInfoDQ EdgeInfoDQ;
00076 typedef typename VDMesh::CoordRepType CoordRepType;
00077 typedef typename VDMesh::VoronoiEdge VoronoiEdge;
00078
00080 itkGetMacro(NumberOfSeeds,unsigned int);
00081
00084 void SetSeeds (int num, SeedsIterator begin);
00085
00087 void AddSeeds(int num,SeedsIterator begin);
00088 void AddOneSeed(PointType);
00089
00091 void SortSeeds(void);
00092
00094 virtual void GenerateOutputInformation() {}
00095
00097 void UpdateDiagram(void);
00098
00100 void SetBoundary(PointType vorsize);
00101 void SetOrigin(PointType vorsize);
00102
00104 void SetRandomSeeds(int num);
00105
00107 PointType GetSeed(int SeedID);
00108
00109 protected:
00110 VoronoiDiagram2DGenerator();
00111 ~VoronoiDiagram2DGenerator();
00112 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00113
00115 void GenerateData(void);
00116
00117 private:
00118 VoronoiDiagram2DGenerator(const Self&);
00119 void operator=(const Self&);
00120
00121 unsigned int m_NumberOfSeeds;
00122 PointType m_VorBoundary;
00123 OutputType m_OutputVD;
00124 SeedsType m_Seeds;
00125
00126 static bool comp(PointType arg1,PointType arg2);
00129 class FortuneSite{
00130 public:
00131 PointType m_Coord;
00132 int m_Sitenbr;
00133 FortuneSite() : m_Sitenbr(NumericTraits<int>::max()) { m_Coord.Fill(NumericTraits<CoordRepType>::max()); };
00134 ~FortuneSite(){};
00135 };
00136
00137 class FortuneEdge{
00138 public:
00139 float m_A, m_B, m_C;
00140 FortuneSite *m_Ep[2];
00141 FortuneSite *m_Reg[2];
00142 int m_Edgenbr;
00143 FortuneEdge() : m_A(0.0), m_B(0.0), m_C(0.0) {m_Ep[0] = m_Ep[1] = m_Reg[0] = m_Reg[1] = 0; };
00144 ~FortuneEdge(){};
00145 };
00146
00147 class FortuneHalfEdge{
00148 public:
00149 FortuneHalfEdge *m_Left;
00150 FortuneHalfEdge *m_Right;
00151 FortuneEdge *m_Edge;
00152 bool m_RorL;
00153 FortuneSite *m_Vert;
00154 double m_Ystar;
00155 FortuneHalfEdge *m_Next;
00156 FortuneHalfEdge() : m_Left(0), m_Right(0), m_Edge(0), m_RorL( false ), m_Vert(0), m_Ystar(0.0), m_Next(0) {};
00157 FortuneHalfEdge(const FortuneHalfEdge &edge) : m_Left(edge.m_Left), m_Right(edge.m_Right), m_Edge(edge.m_Edge), m_RorL( edge.m_RorL ), m_Vert( edge.m_Vert ), m_Ystar( edge.m_Ystar ), m_Next( edge.m_Next ) {};
00158 ~FortuneHalfEdge(){};
00159 };
00160
00161 double m_Pxmin;
00162 double m_Pxmax;
00163 double m_Pymin;
00164 double m_Pymax;
00165 double m_Deltax;
00166 double m_Deltay;
00167 double m_SqrtNSites;
00168 unsigned int m_PQcount;
00169 int m_PQmin;
00170 unsigned int m_PQhashsize;
00171 unsigned int m_Nedges;
00172 unsigned int m_Nvert;
00173 FortuneSite *m_BottomSite;
00174 std::vector<FortuneHalfEdge> m_PQHash;
00175 unsigned int m_ELhashsize;
00176 FortuneHalfEdge m_ELleftend;
00177 FortuneHalfEdge m_ELrightend;
00178 std::vector<FortuneHalfEdge *> m_ELHash;
00179 FortuneEdge m_DELETED;
00180 std::vector<FortuneSite> m_SeedSites;
00181
00182 bool differentPoint(PointType p1,PointType p2);
00183 bool almostsame(CoordRepType p1,CoordRepType p2);
00184 unsigned char Pointonbnd(int VertID);
00185
00186 void GenerateVDFortune(void);
00187 void ConstructDiagram(void);
00188
00189 void createHalfEdge(FortuneHalfEdge *task, FortuneEdge *e,bool pm);
00190 void PQshowMin(PointType *task);
00191 FortuneHalfEdge *findLeftHE(PointType *p);
00192 FortuneHalfEdge *ELgethash(int b);
00193 bool right_of(FortuneHalfEdge *el, PointType *p);
00194 FortuneSite *getRightReg(FortuneHalfEdge *he);
00195 FortuneSite *getLeftReg(FortuneHalfEdge *he);
00196 void bisect(FortuneEdge *, FortuneSite *s1,FortuneSite *s2);
00197 void insertEdgeList(FortuneHalfEdge *lbase, FortuneHalfEdge *lnew);
00198 void intersect(FortuneSite *task,FortuneHalfEdge *el1,FortuneHalfEdge *el2);
00199 void deletePQ(FortuneHalfEdge *task);
00200 void deleteEdgeList(FortuneHalfEdge *task);
00201 int PQbucket(FortuneHalfEdge *task);
00202 void clip_line(FortuneEdge *task);
00203 void insertPQ(FortuneHalfEdge *he, FortuneSite *v, double offset);
00204 double dist(FortuneSite *s1,FortuneSite *s2);
00205 FortuneHalfEdge *getPQmin(void);
00206 void makeEndPoint(FortuneEdge *task, bool lr, FortuneSite *ends);
00207 };
00208
00209 }
00210
00211 #ifndef ITK_MANUAL_INSTANTIATION
00212 #include "itkVoronoiDiagram2DGenerator.txx"
00213 #endif
00214
00215 #endif
00216
00217