itkVoronoiDiagram2D.h
Go to the documentation of this file.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 "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;
00127
00128 typedef CellFeatureIdentifier CellFeatureCount;
00129 typedef CellInterface<PixelType,CellTraits> CellInterfaceType;
00130 typedef PolygonCell<CellInterfaceType> CellType;
00131 typedef typename CellType::CellAutoPointer CellAutoPointer;
00132 typedef Point<int,2> EdgeInfo;
00133 typedef std::deque<EdgeInfo> EdgeInfoDQ;
00134 typedef typename CellType::MultiVisitor CellMultiVisitorType;
00135 typedef std::vector<PointType> SeedsType;
00136 typedef typename SeedsType::iterator SeedsIterator;
00137 typedef LineCell <CellInterfaceType> Edge;
00138 typedef typename Edge::SelfAutoPointer EdgeAutoPointer;
00139 typedef std::list<PointType> PointList;
00140 typedef std::vector<int> INTvector;
00141 typedef typename INTvector::iterator NeighborIdIterator;
00142 typedef typename std::vector<PointType>::iterator VertexIterator;
00143
00145 itkGetConstMacro(NumberOfSeeds,unsigned int);
00146
00149 void SetSeeds (int num, SeedsIterator begin);
00150
00152 void SetBoundary(PointType vorsize);
00153 void SetOrigin(PointType vorsize);
00155
00157 NeighborIdIterator NeighborIdsBegin(int seeds);
00158 NeighborIdIterator NeighborIdsEnd(int seeds);
00160
00162 VertexIterator VertexBegin(void);
00163 VertexIterator VertexEnd(void);
00165
00167 PointType GetSeed(int SeedID);
00168
00170 void GetCellId(CellIdentifier cellId, CellAutoPointer &);
00171
00173 void GetPoint(int pId,PointType *answer);
00174
00175 class VoronoiEdge{
00176 public:
00177 PointType m_Left;
00178 PointType m_Right;
00179 int m_LeftID;
00180 int m_RightID;
00181 int m_LineID;
00182 VoronoiEdge(){}
00183 ~VoronoiEdge(){}
00184 };
00185
00187 typedef typename std::vector<VoronoiEdge>::iterator VoronoiEdgeIterator;
00188
00190 VoronoiEdgeIterator EdgeBegin(void);
00191 VoronoiEdgeIterator EdgeEnd(void);
00193
00195 EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task);
00196
00197
00198
00199 void Reset();
00200 void InsertCells();
00201
00202 void AddCellNeighbor(EdgeInfo x)
00203 {
00204 m_CellNeighborsID[x[0]].push_back(x[1]);
00205 m_CellNeighborsID[x[1]].push_back(x[0]);
00206 }
00207 void ClearRegion(int i)
00208 { m_VoronoiRegions[i]->ClearPoints();}
00209 void VoronoiRegionAddPointId(int id, int x)
00210 { m_VoronoiRegions[id]->AddPointId(x);}
00211 void BuildEdge(int id)
00212 { m_VoronoiRegions[id]->BuildEdges();}
00213
00214 void LineListClear(){ m_LineList.clear();}
00215 void EdgeListClear(){ m_EdgeList.clear();}
00216 void VertexListClear(){ m_VertexList.clear();}
00217 int LineListSize(){ return static_cast<int>( m_LineList.size() );}
00218 int EdgeListSize(){ return static_cast<int>( m_EdgeList.size() );}
00219 int VertexListSize(){ return static_cast<int>( m_VertexList.size() );}
00220 void AddLine(EdgeInfo x){ m_LineList.push_back(x);}
00221 void AddEdge(VoronoiEdge x){ m_EdgeList.push_back(x);}
00222 void AddVert(PointType x){ m_VertexList.push_back(x);}
00223 EdgeInfo GetLine(int id){ return m_LineList[id];}
00224 VoronoiEdge GetEdge(int id){ return m_EdgeList[id];}
00225 PointType GetVertex(int id){ return m_VertexList[id];}
00226 EdgeInfo GetEdgeEnd(int id)
00227 {
00228 EdgeInfo x;
00229 x[0]=m_EdgeList[id].m_LeftID;
00230 x[1]=m_EdgeList[id].m_RightID;
00231 return x;
00232 }
00233 int GetEdgeLineID(int id){ return m_EdgeList[id].m_LineID; }
00234
00235 protected:
00236 VoronoiDiagram2D();
00237 ~VoronoiDiagram2D();
00238 virtual void PrintSelf(std::ostream& os, Indent indent) const;
00239
00240
00241 private:
00242 VoronoiDiagram2D(const Self&);
00243 void operator=(const Self&);
00244
00245 SeedsType m_Seeds;
00246 unsigned int m_NumberOfSeeds;
00247 std::vector<CellType *> m_VoronoiRegions;
00248 PointType m_VoronoiBoundary;
00249 PointType m_VoronoiBoundaryOrigin;
00250 std::vector< std::vector<int> > m_CellNeighborsID;
00251
00252 std::vector< EdgeInfo > m_LineList;
00253 std::vector< PointType > m_VertexList;
00254 std::vector< VoronoiEdge > m_EdgeList;
00255
00256 };
00257
00258 }
00259
00260 #ifndef ITK_MANUAL_INSTANTIATION
00261 #include "itkVoronoiDiagram2D.txx"
00262 #endif
00263
00264 #endif
00265