Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkVoronoiDiagram2DGenerator.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVoronoiDiagram2DGenerator.h,v $
00005   Language:  C++
00006   Date:      $Date: 2002/02/21 21:43:56 $
00007   Version:   $Revision: 1.13 $
00008 
00009   Copyright (c) 2002 Insight Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkVoronoiDiagram2DGenerator_h
00018 #define __itkVoronoiDiagram2DGenerator_h
00019 
00020 #include "itkCellInterface.h"
00021 #include "itkCellBoundary.h"
00022 #include "itkLineCell.h"
00023 #include "itkMeshSource.h"
00024 #include "itkDefaultDynamicMeshTraits.h"
00025 #include "itkPolygonCell.h"
00026 #include "itkVoronoiDiagram2D.h"
00027 
00028 #include <vector>
00029 
00030 #ifndef NULL
00031 #define NULL 0 
00032 #endif
00033 
00034 namespace itk
00035 {
00053 template <typename TCoordType>
00054 class VoronoiDiagram2DGenerator:
00055     public MeshSource <VoronoiDiagram2D<TCoordType> >
00056 {
00057 public:
00058   typedef VoronoiDiagram2DGenerator   Self;
00059   typedef MeshSource <VoronoiDiagram2D<TCoordType> >    Superclass;
00060   typedef SmartPointer<Self>  Pointer;
00061   typedef SmartPointer<const Self>  ConstPointer;
00062 
00064   itkNewMacro(Self);
00065 
00067   itkTypeMacro(VoronoiDiagram2DGenerator, MeshSource);
00068   
00070   typedef VoronoiDiagram2D<TCoordType> VDMesh;
00071   typedef typename VDMesh::SeedsIterator SeedsIterator;
00072   typedef typename VDMesh::Pointer OutputType;
00073   typedef typename VDMesh::PointType PointType;
00074   typedef typename VDMesh::SeedsType SeedsType;
00075   typedef typename VDMesh::EdgeInfo EdgeInfo;
00076   typedef typename VDMesh::EdgeInfoDQ EdgeInfoDQ;
00077   typedef typename VDMesh::CoordRepType CoordRepType;
00078   typedef typename VDMesh::VoronoiEdge VoronoiEdge;
00079 
00081   itkGetMacro(NumberOfSeeds,unsigned int);
00082   
00085   void SetSeeds (int num, SeedsIterator begin);
00086 
00088   void AddSeeds(int num,SeedsIterator begin);
00089   void AddOneSeed(PointType);
00090 
00092   void SortSeeds(void);
00093 
00095   virtual void GenerateOutputInformation() {}
00096 
00098   void UpdateDiagram(void);
00099 
00101   void SetBoundary(PointType vorsize);
00102   void SetOrigin(PointType vorsize);
00103 
00105   void SetRandomSeeds(int num);
00106 
00108   PointType GetSeed(int SeedID);
00109 
00110 protected:
00111   VoronoiDiagram2DGenerator();
00112   ~VoronoiDiagram2DGenerator();
00113   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00114 
00116   void GenerateData(void);
00117 
00118 private:
00119   VoronoiDiagram2DGenerator(const Self&); //purposely not implemented
00120   void operator=(const Self&); //purposely not implemented
00121   
00122   unsigned int m_NumberOfSeeds;
00123   PointType m_VorBoundary;
00124   OutputType m_OutputVD;
00125   SeedsType m_Seeds;
00126 
00127   static bool comp(PointType arg1,PointType arg2);
00130   class FortuneSite{
00131   public:
00132     PointType m_Coord;
00133     int m_Sitenbr;
00134     FortuneSite() : m_Sitenbr(NumericTraits<int>::max()) { m_Coord.Fill(NumericTraits<CoordRepType>::max()); };
00135     ~FortuneSite(){};
00136   };
00137 
00138   class FortuneEdge{
00139   public:
00140     float m_A, m_B, m_C;  // explicit line function: Ax + By = C;
00141     FortuneSite *m_Ep[2];
00142     FortuneSite *m_Reg[2];
00143     int m_Edgenbr;
00144     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; };
00145     ~FortuneEdge(){};
00146   };
00147 
00148   class FortuneHalfEdge{
00149   public:
00150     FortuneHalfEdge *m_Left;
00151     FortuneHalfEdge *m_Right;
00152     FortuneEdge *m_Edge;
00153     bool m_RorL;
00154     FortuneSite *m_Vert;
00155     double m_Ystar;
00156     FortuneHalfEdge *m_Next;
00157     FortuneHalfEdge() : m_Left(0), m_Right(0), m_Edge(0), m_RorL( false ), m_Vert(0), m_Ystar(0.0), m_Next(0) {};
00158     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 ) {};
00159     ~FortuneHalfEdge(){};
00160   };
00161 
00162   double m_Pxmin;
00163   double m_Pxmax;
00164   double m_Pymin;
00165   double m_Pymax;
00166   double m_Deltax;
00167   double m_Deltay;
00168   double m_SqrtNSites;
00169   unsigned int m_PQcount;
00170   int m_PQmin;
00171   unsigned int m_PQhashsize;
00172   unsigned int m_Nedges;
00173   unsigned int m_Nvert;
00174   FortuneSite *m_BottomSite;
00175   std::vector<FortuneHalfEdge> m_PQHash;
00176   unsigned int m_ELhashsize;
00177   FortuneHalfEdge m_ELleftend;
00178   FortuneHalfEdge m_ELrightend;
00179   std::vector<FortuneHalfEdge *> m_ELHash;
00180   FortuneEdge m_DELETED;
00181   std::vector<FortuneSite> m_SeedSites;
00182   
00183   bool differentPoint(PointType p1,PointType p2);
00184   bool almostsame(CoordRepType p1,CoordRepType p2);
00185   unsigned char Pointonbnd(int VertID);
00186 
00187   void GenerateVDFortune(void);
00188   void ConstructDiagram(void);
00189 
00190   void createHalfEdge(FortuneHalfEdge *task, FortuneEdge *e,bool pm);
00191   void PQshowMin(PointType *task);
00192   FortuneHalfEdge *findLeftHE(PointType *p);
00193   FortuneHalfEdge *ELgethash(int b);
00194   bool right_of(FortuneHalfEdge *el, PointType *p);
00195   FortuneSite *getRightReg(FortuneHalfEdge *he);
00196   FortuneSite *getLeftReg(FortuneHalfEdge *he);
00197   void bisect(FortuneEdge *, FortuneSite *s1,FortuneSite *s2);
00198   void insertEdgeList(FortuneHalfEdge *lbase, FortuneHalfEdge *lnew);
00199   void intersect(FortuneSite *task,FortuneHalfEdge *el1,FortuneHalfEdge *el2);
00200   void deletePQ(FortuneHalfEdge *task);
00201   void deleteEdgeList(FortuneHalfEdge *task);
00202   int PQbucket(FortuneHalfEdge *task);
00203   void clip_line(FortuneEdge *task);
00204   void insertPQ(FortuneHalfEdge *he, FortuneSite *v, double offset);
00205   double dist(FortuneSite *s1,FortuneSite *s2);
00206   FortuneHalfEdge *getPQmin(void);
00207   void makeEndPoint(FortuneEdge *task, bool lr, FortuneSite *ends);
00208 };
00209 
00210 } // end namespace itk
00211 
00212 #ifndef ITK_MANUAL_INSTANTIATION
00213 #include "itkVoronoiDiagram2DGenerator.txx"
00214 #endif
00215 
00216 #endif
00217 
00218 

Generated at Fri May 21 01:15:35 2004 for ITK by doxygen 1.2.15 written by Dimitri van Heesch, © 1997-2000