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

itkVoronoiDiagram2D.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkVoronoiDiagram2D.h,v $
00005   Language:  C++
00006   Date:      $Date: 2003/09/10 14:28:40 $
00007   Version:   $Revision: 1.18 $
00008 
00009   Copyright (c) Insight Software 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 __itkVoronoiDiagram2D_h
00018 #define __itkVoronoiDiagram2D_h
00019 
00020 #if defined(_MSC_VER)
00021 #pragma warning ( disable : 4786 )
00022 #endif
00023 
00024 #include "itkCellInterface.h"
00025 #include "itkLineCell.h"
00026 #include "itkMesh.h"
00027 #include "itkDefaultDynamicMeshTraits.h"
00028 #include "itkPolygonCell.h"
00029 #include <vector>
00030 
00031 #ifndef NULL
00032 #define NULL 0 
00033 #endif
00034 
00035 namespace itk
00036 {
00053 template <typename TCoordType>
00054 class ITK_EXPORT VoronoiDiagram2D:
00055     public Mesh <TCoordType, 2,
00056                  DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType> >
00057 {
00058 public:
00060   typedef VoronoiDiagram2D   Self;
00061   typedef Mesh <TCoordType, 2,
00062                 DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType> >
00063   Superclass;
00064   typedef SmartPointer<Self>  Pointer;
00065   typedef SmartPointer<const Self>  ConstPointer;
00066 
00068   itkNewMacro(Self);
00069 
00071   itkTypeMacro(VoronoiDiagram2D, Mesh);
00072 
00074   typedef DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType> MeshTraits;
00075 
00077   itkStaticConstMacro(PointDimension, unsigned int,
00078                       MeshTraits::PointDimension);
00079   itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
00080                       MeshTraits::MaxTopologicalDimension);
00082 
00084   typedef typename MeshTraits::PixelType               PixelType;  
00085   typedef typename MeshTraits::CoordRepType            CoordRepType;  
00086   typedef typename MeshTraits::InterpolationWeightType InterpolationWeightType;
00087   typedef typename MeshTraits::PointIdentifier         PointIdentifier;
00088   typedef typename MeshTraits::CellIdentifier          CellIdentifier;
00089   typedef typename MeshTraits::CellFeatureIdentifier   CellFeatureIdentifier;
00090   typedef typename MeshTraits::PointType               PointType;
00091   typedef typename MeshTraits::PointsContainer         PointsContainer;
00092   typedef typename MeshTraits::CellTraits              CellTraits;
00093   typedef typename MeshTraits::CellsContainer          CellsContainer;
00094   typedef typename MeshTraits::PointCellLinksContainer PointCellLinksContainer;
00095   typedef typename MeshTraits::CellLinksContainer      CellLinksContainer;
00096   typedef typename MeshTraits::PointDataContainer      PointDataContainer;
00097   typedef typename MeshTraits::CellDataContainer       CellDataContainer;  
00098   typedef typename MeshTraits::CellAutoPointer         genericCellPointer;
00099   typedef PointLocator<PointIdentifier,itkGetStaticConstMacro(PointDimension),
00100                        CoordRepType,PointsContainer>  PointLocatorType;
00101   typedef BoundingBox<PointIdentifier,itkGetStaticConstMacro(PointDimension),
00102                       CoordRepType,PointsContainer>   BoundingBoxType;
00103   typedef typename PointsContainer::Pointer       PointsContainerPointer;
00104   typedef typename CellsContainer::Pointer        CellsContainerPointer;
00105   typedef typename CellLinksContainer::Pointer    CellLinksContainerPointer;
00106   typedef typename PointDataContainer::Pointer    PointDataContainerPointer;
00107   typedef typename CellDataContainer::Pointer     CellDataContainerPointer;
00108   typedef typename PointLocatorType::Pointer      PointLocatorPointer;
00109   typedef typename BoundingBoxType::Pointer       BoundingBoxPointer;
00110   typedef typename
00111   PointsContainer::ConstIterator        PointsContainerConstIterator;
00112   typedef typename
00113   PointsContainer::Iterator             PointsContainerIterator;
00114   typedef typename
00115   CellsContainer::ConstIterator         CellsContainerConstIterator;
00116   typedef typename
00117   CellsContainer::Iterator              CellsContainerIterator;
00118   typedef typename
00119   CellLinksContainer::ConstIterator     CellLinksContainerIterator;
00120   typedef typename
00121   PointDataContainer::ConstIterator     PointDataContainerIterator;
00122   typedef typename
00123   CellDataContainer::ConstIterator      CellDataContainerIterator;
00124   typedef typename
00125   PointCellLinksContainer::const_iterator        PointCellLinksContainerIterator;
00126   typedef CellFeatureIdentifier                     CellFeatureCount;
00127   typedef CellInterface<PixelType,CellTraits>       CellInterfaceType;
00128   typedef PolygonCell<CellInterfaceType>            CellType;
00129   typedef typename CellType::CellAutoPointer        CellAutoPointer;
00130   typedef Point<int,2> EdgeInfo;
00131   typedef std::deque<EdgeInfo> EdgeInfoDQ;
00132   typedef typename CellType::MultiVisitor CellMultiVisitorType;
00133   typedef std::vector<PointType> SeedsType;
00134   typedef typename SeedsType::iterator SeedsIterator;
00135   typedef LineCell <CellInterfaceType> Edge;
00136   typedef typename Edge::SelfAutoPointer EdgeAutoPointer;
00137   typedef std::list<PointType> PointList;
00138   typedef std::vector<int> INTvector;
00139   typedef typename INTvector::iterator NeighborIdIterator;
00140   typedef typename std::vector<PointType>::iterator VertexIterator;
00142 
00144   itkGetMacro(NumberOfSeeds,unsigned int);
00145 
00148   void SetSeeds (int num, SeedsIterator begin);
00149 
00151   void SetBoundary(PointType vorsize);
00152   void SetOrigin(PointType vorsize);
00154 
00156   NeighborIdIterator NeighborIdsBegin(int seeds);
00157   NeighborIdIterator NeighborIdsEnd(int seeds);
00159 
00161   VertexIterator VertexBegin(void);
00162   VertexIterator VertexEnd(void);
00164 
00166   PointType GetSeed(int SeedID);
00167 
00169   void GetCellId(CellIdentifier cellId, CellAutoPointer &);
00170 
00172   void GetPoint(int pId,PointType *answer);
00173 
00174   class VoronoiEdge{
00175   public:
00176     PointType m_Left;
00177     PointType m_Right;
00178     int m_LeftID;
00179     int m_RightID;
00180     int m_LineID;
00181     VoronoiEdge(){};
00182     ~VoronoiEdge(){};
00183   };
00184   
00186   typedef typename std::vector<VoronoiEdge>::iterator VoronoiEdgeIterator;
00187 
00189   VoronoiEdgeIterator EdgeBegin(void);
00190   VoronoiEdgeIterator EdgeEnd(void);
00192 
00194   EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task);
00195 
00196 /********************************************************/
00197 
00198   void Reset();
00199   void InsertCells();
00200 
00201   void AddCellNeighbor(EdgeInfo x){ 
00202     m_CellNeighborsID[x[0]].push_back(x[1]);
00203     m_CellNeighborsID[x[1]].push_back(x[0]);};
00204   void ClearRegion(int i){ m_VoronoiRegions[i]->ClearPoints();};  
00205   void VoronoiRegionAddPointId(int id, int x){m_VoronoiRegions[id]->AddPointId(x);};
00206   void BuildEdge(int id){ m_VoronoiRegions[id]->BuildEdges();};
00207 
00208   void LineListClear(){ f_LineList.clear();};
00209   void EdgeListClear(){ f_EdgeList.clear();};
00210   void VertexListClear(){ f_VertexList.clear();};
00211   int LineListSize(){ return static_cast<int>( f_LineList.size() );}; 
00212   int EdgeListSize(){ return static_cast<int>( f_EdgeList.size() );}; 
00213   int VertexListSize(){ return static_cast<int>( f_VertexList.size() );}; 
00214   void AddLine(EdgeInfo x){ f_LineList.push_back(x);};
00215   void AddEdge(VoronoiEdge x){ f_EdgeList.push_back(x);};
00216   void AddVert(PointType x){ f_VertexList.push_back(x);};
00217   EdgeInfo GetLine(int id){ return f_LineList[id];}; 
00218   VoronoiEdge GetEdge(int id){ return f_EdgeList[id];}; 
00219   PointType GetVertex(int id){ return f_VertexList[id];}; 
00220   EdgeInfo GetEdgeEnd(int id){
00221     EdgeInfo x;
00222     x[0]=f_EdgeList[id].m_LeftID;
00223     x[1]=f_EdgeList[id].m_RightID;
00224     return x;
00225   }
00226   int GetEdgeLineID(int id){ return f_EdgeList[id].m_LineID; };
00227 
00228 protected:
00229   VoronoiDiagram2D();
00230   ~VoronoiDiagram2D();
00231   virtual void PrintSelf(std::ostream& os, Indent indent) const;
00232   
00233   
00234 private:
00235   VoronoiDiagram2D(const Self&); //purposely not implemented
00236   void operator=(const Self&); //purposely not implemented
00237   
00238   SeedsType m_Seeds;
00239   unsigned int m_NumberOfSeeds;
00240   std::vector<CellType *> m_VoronoiRegions;
00241   PointType m_VoronoiBoundary;
00242   PointType m_VoronoiBoundaryOrigin;
00243   std::vector< std::vector<int> > m_CellNeighborsID;
00244   
00245   std::vector< EdgeInfo > f_LineList;
00246   std::vector< PointType > f_VertexList;
00247   std::vector< VoronoiEdge > f_EdgeList;
00248 
00249 }; // end class: VoronoiDiagram2D
00250 
00251 } // end namespace itk
00252 
00253 #ifndef ITK_MANUAL_INSTANTIATION
00254 #include "itkVoronoiDiagram2D.txx"
00255 #endif
00256 
00257 #endif
00258 
00259 
00260 

Generated at Thu Nov 6 00:54:32 2008 for ITK by doxygen 1.5.1 written by Dimitri van Heesch, © 1997-2000