00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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 "itkCellBoundary.h"
00026 #include "itkLineCell.h"
00027 #include "itkMesh.h"
00028 #include "itkDefaultDynamicMeshTraits.h"
00029 #include "itkPolygonCell.h"
00030 #include <vector>
00031
00032 #ifndef NULL
00033 #define NULL 0
00034 #endif
00035
00036 namespace itk
00037 {
00054 template <typename TCoordType>
00055 class VoronoiDiagram2D:
00056 public Mesh <TCoordType, 2,
00057 DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType> >
00058 {
00059 public:
00061 typedef VoronoiDiagram2D Self;
00062 typedef Mesh <TCoordType, 2,
00063 DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType> >
00064 Superclass;
00065 typedef SmartPointer<Self> Pointer;
00066 typedef SmartPointer<const Self> ConstPointer;
00067
00069 itkNewMacro(Self);
00070
00072 itkTypeMacro(VoronoiDiagram2D, Mesh);
00073
00075 typedef DefaultDynamicMeshTraits<TCoordType, 2, 2, TCoordType> MeshTraits;
00076
00078 itkStaticConstMacro(PointDimension, unsigned int,
00079 MeshTraits::PointDimension);
00080 itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
00081 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::BoundaryIdentifier BoundaryIdentifier;
00090 typedef typename MeshTraits::CellFeatureIdentifier CellFeatureIdentifier;
00091 typedef typename MeshTraits::PointType PointType;
00092 typedef typename MeshTraits::PointsContainer PointsContainer;
00093 typedef typename MeshTraits::CellTraits CellTraits;
00094 typedef typename MeshTraits::CellsContainer CellsContainer;
00095 typedef typename MeshTraits::PointCellLinksContainer PointCellLinksContainer;
00096 typedef typename MeshTraits::CellLinksContainer CellLinksContainer;
00097 typedef typename MeshTraits::PointDataContainer PointDataContainer;
00098 typedef typename MeshTraits::CellDataContainer CellDataContainer;
00099 typedef typename MeshTraits::BoundariesContainer BoundariesContainer;
00100 typedef typename MeshTraits::BoundaryDataContainer BoundaryDataContainer;
00101 typedef typename MeshTraits::CellAutoPointer genericCellPointer;
00102 typedef PointLocator<PointIdentifier,itkGetStaticConstMacro(PointDimension),
00103 CoordRepType,PointsContainer> PointLocatorType;
00104 typedef BoundingBox<PointIdentifier,itkGetStaticConstMacro(PointDimension),
00105 CoordRepType,PointsContainer> BoundingBoxType;
00106 typedef typename PointsContainer::Pointer PointsContainerPointer;
00107 typedef typename CellsContainer::Pointer CellsContainerPointer;
00108 typedef typename CellLinksContainer::Pointer CellLinksContainerPointer;
00109 typedef typename PointDataContainer::Pointer PointDataContainerPointer;
00110 typedef typename CellDataContainer::Pointer CellDataContainerPointer;
00111 typedef typename BoundariesContainer::Pointer BoundariesContainerPointer;
00112 typedef typename BoundaryDataContainer::Pointer BoundaryDataContainerPointer;
00113 typedef typename PointLocatorType::Pointer PointLocatorPointer;
00114 typedef typename BoundingBoxType::Pointer BoundingBoxPointer;
00115 typedef typename
00116 PointsContainer::ConstIterator PointsContainerConstIterator;
00117 typedef typename
00118 PointsContainer::Iterator PointsContainerIterator;
00119 typedef typename
00120 CellsContainer::ConstIterator CellsContainerConstIterator;
00121 typedef typename
00122 CellsContainer::Iterator CellsContainerIterator;
00123 typedef typename
00124 CellLinksContainer::ConstIterator CellLinksContainerIterator;
00125 typedef typename
00126 PointDataContainer::ConstIterator PointDataContainerIterator;
00127 typedef typename
00128 CellDataContainer::ConstIterator CellDataContainerIterator;
00129 typedef typename
00130 BoundariesContainer::ConstIterator BoundariesContainerIterator;
00131 typedef typename
00132 BoundaryDataContainer::ConstIterator BoundaryDataContainerIterator;
00133 typedef typename
00134 PointCellLinksContainer::const_iterator PointCellLinksContainerIterator;
00135 typedef CellFeatureIdentifier CellFeatureCount;
00136 typedef CellInterface<PixelType,CellTraits> CellInterfaceType;
00137 typedef PolygonCell<CellInterfaceType> CellType;
00138 typedef typename CellType::CellAutoPointer CellAutoPointer;
00139 typedef Point<int,2> EdgeInfo;
00140 typedef std::deque<EdgeInfo> EdgeInfoDQ;
00141 typedef CellType BoundaryType;
00142 typedef CellAutoPointer BoundaryAutoPointer;
00143 typedef typename CellType::MultiVisitor CellMultiVisitorType;
00144 typedef std::vector<PointType> SeedsType;
00145 typedef typename SeedsType::iterator SeedsIterator;
00146 typedef LineBoundary <CellInterfaceType> Edge;
00147 typedef typename Edge::SelfAutoPointer EdgeAutoPointer;
00148 typedef std::list<PointType> PointList;
00149 typedef std::vector<int> INTvector;
00150 typedef typename INTvector::iterator NeighborIdIterator;
00151 typedef typename std::vector<PointType>::iterator VertexIterator;
00152
00154 itkGetMacro(NumberOfSeeds,unsigned int);
00155
00158 void SetSeeds (int num, SeedsIterator begin);
00159
00161 void SetBoundary(PointType vorsize);
00162 void SetOrigin(PointType vorsize);
00163
00165 NeighborIdIterator NeighborIdsBegin(int seeds);
00166 NeighborIdIterator NeighborIdsEnd(int seeds);
00167
00169 VertexIterator VertexBegin(void);
00170 VertexIterator VertexEnd(void);
00171
00173 PointType GetSeed(int SeedID);
00174
00176 void GetCellId(CellIdentifier cellId, CellAutoPointer &);
00177
00179 void GetPoint(int pId,PointType *answer);
00180
00181 class VoronoiEdge{
00182 public:
00183 PointType m_Left;
00184 PointType m_Right;
00185 int m_LeftID;
00186 int m_RightID;
00187 int m_LineID;
00188 VoronoiEdge(){};
00189 ~VoronoiEdge(){};
00190 };
00191
00193 typedef typename std::vector<VoronoiEdge>::iterator VoronoiEdgeIterator;
00194
00196 VoronoiEdgeIterator EdgeBegin(void);
00197 VoronoiEdgeIterator EdgeEnd(void);
00198
00200 EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task);
00201
00202
00203 void Reset();
00204 void InsertCells();
00205
00206 void AddCellNeighbor(EdgeInfo x){
00207 m_CellNeighborsID[x[0]].push_back(x[1]);
00208 m_CellNeighborsID[x[1]].push_back(x[0]);};
00209 void ClearRegion(int i){ m_VoronoiRegions[i]->ClearPoints();};
00210 void VoronoiRegionAddPointId(int id, int x){m_VoronoiRegions[id]->AddPointId(x);};
00211 void BuildEdge(int id){ m_VoronoiRegions[id]->BuildEdges();};
00212
00213 void LineListClear(){ f_LineList.clear();};
00214 void EdgeListClear(){ f_EdgeList.clear();};
00215 void VertexListClear(){ f_VertexList.clear();};
00216 int LineListSize(){ return static_cast<int>( f_LineList.size() );};
00217 int EdgeListSize(){ return static_cast<int>( f_EdgeList.size() );};
00218 int VertexListSize(){ return static_cast<int>( f_VertexList.size() );};
00219 void AddLine(EdgeInfo x){ f_LineList.push_back(x);};
00220 void AddEdge(VoronoiEdge x){ f_EdgeList.push_back(x);};
00221 void AddVert(PointType x){ f_VertexList.push_back(x);};
00222 EdgeInfo GetLine(int id){ return f_LineList[id];};
00223 VoronoiEdge GetEdge(int id){ return f_EdgeList[id];};
00224 PointType GetVertex(int id){ return f_VertexList[id];};
00225 EdgeInfo GetEdgeEnd(int id){
00226 EdgeInfo x;
00227 x[0]=f_EdgeList[id].m_LeftID;
00228 x[1]=f_EdgeList[id].m_RightID;
00229 return x;
00230 }
00231 int GetEdgeLineID(int id){ return f_EdgeList[id].m_LineID; };
00232
00233 protected:
00234 VoronoiDiagram2D();
00235 ~VoronoiDiagram2D();
00236 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00237
00238
00239 private:
00240 VoronoiDiagram2D(const Self&);
00241 void operator=(const Self&);
00242
00243 SeedsType m_Seeds;
00244 unsigned int m_NumberOfSeeds;
00245 std::vector<CellType *> m_VoronoiRegions;
00246 PointType m_VoronoiBoundary;
00247 PointType m_VoronoiBoundaryOrigin;
00248 std::vector< std::vector<int> > m_CellNeighborsID;
00249
00250 std::vector< EdgeInfo > f_LineList;
00251 std::vector< PointType > f_VertexList;
00252 std::vector< VoronoiEdge > f_EdgeList;
00253
00254 };
00255
00256 }
00257
00258 #ifndef ITK_MANUAL_INSTANTIATION
00259 #include "itkVoronoiDiagram2D.txx"
00260 #endif
00261
00262 #endif
00263
00264