ITK  4.3.0
Insight Segmentation and Registration Toolkit
itkVoronoiDiagram2D.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef __itkVoronoiDiagram2D_h
19 #define __itkVoronoiDiagram2D_h
20 
21 
22 #include "itkMesh.h"
24 #include "itkPolygonCell.h"
25 #include <vector>
26 
27 #ifndef NULL
28 #define NULL 0
29 #endif
30 
31 namespace itk
32 {
50 template< typename TCoordType >
51 class ITK_EXPORT VoronoiDiagram2D:
52  public Mesh< TCoordType, 2,
53  DefaultDynamicMeshTraits< TCoordType, 2, 2, TCoordType > >
54 {
55 public:
61 
63  itkNewMacro(Self);
64 
66  itkTypeMacro(VoronoiDiagram2D, Mesh);
67 
70 
72  itkStaticConstMacro(PointDimension, unsigned int,
73  MeshTraits::PointDimension);
74  itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
75  MeshTraits::MaxTopologicalDimension);
77 
79  typedef typename MeshTraits::PixelType
81  typedef typename MeshTraits::CoordRepType
85  typedef typename MeshTraits::PointIdentifier
87  typedef typename MeshTraits::CellIdentifier
89  typedef typename MeshTraits::CellFeatureIdentifier
91  typedef typename MeshTraits::PointType
93  typedef typename MeshTraits::PointsContainer
95  typedef typename MeshTraits::CellTraits
97  typedef typename MeshTraits::CellsContainer
101  typedef typename MeshTraits::CellLinksContainer
103  typedef typename MeshTraits::PointDataContainer
105  typedef typename MeshTraits::CellDataContainer
107  typedef typename MeshTraits::CellAutoPointer
109  typedef BoundingBox< PointIdentifier, itkGetStaticConstMacro(PointDimension), CoordRepType,
111  typedef typename PointsContainer::Pointer
113  typedef typename CellsContainer::Pointer
115  typedef typename CellLinksContainer::Pointer
117  typedef typename PointDataContainer::Pointer
119  typedef typename CellDataContainer::Pointer
121  typedef typename BoundingBoxType::Pointer
123  typedef typename PointsContainer::ConstIterator
125  typedef typename PointsContainer::Iterator
127  typedef typename CellsContainer::ConstIterator
129  typedef typename CellsContainer::Iterator
131  typedef typename CellLinksContainer::ConstIterator
133  typedef typename PointDataContainer::ConstIterator
135  typedef typename CellDataContainer::ConstIterator
137  typedef typename PointCellLinksContainer::const_iterator
139 
141  typedef typename Superclass::CellType CellType;
142  typedef typename Superclass::CellAutoPointer CellAutoPointer;
145  typedef std::deque< EdgeInfo > EdgeInfoDQ;
146  typedef typename CellType::MultiVisitor CellMultiVisitorType;
147  typedef std::vector< PointType > SeedsType;
148  typedef typename SeedsType::iterator SeedsIterator;
150  typedef typename Edge::SelfAutoPointer EdgeAutoPointer;
151  typedef std::list< PointType > PointList;
152  typedef std::vector< int > INTvector;
153  typedef typename INTvector::iterator NeighborIdIterator;
156  itkGetConstMacro(NumberOfSeeds, unsigned int);
157 
160  void SetSeeds(int num, SeedsIterator begin);
161 
163  void SetBoundary(PointType vorsize);
164 
165  void SetOrigin(PointType vorsize);
166 
168  NeighborIdIterator NeighborIdsBegin(int seeds);
169 
170  NeighborIdIterator NeighborIdsEnd(int seeds);
171 
173  VertexIterator VertexBegin(void);
174 
175  VertexIterator VertexEnd(void);
176 
178  PointType GetSeed(int SeedID);
179 
181  void GetCellId(CellIdentifier cellId, CellAutoPointer &);
182 
184  void GetPoint(int pId, PointType *answer);
185 
187  {
188 public:
191  int m_LeftID;
193  int m_LineID;
196  };
197 
199  typedef typename std::vector< VoronoiEdge >::iterator VoronoiEdgeIterator;
200 
202  VoronoiEdgeIterator EdgeBegin(void);
203 
204  VoronoiEdgeIterator EdgeEnd(void);
205 
207  EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task);
208 
209 /********************************************************/
210 
211  void Reset();
212 
213  void InsertCells();
214 
215  void AddCellNeighbor(EdgeInfo x)
216  {
217  m_CellNeighborsID[x[0]].push_back(x[1]);
218  m_CellNeighborsID[x[1]].push_back(x[0]);
219  }
220 
221  void ClearRegion(int i)
222  { m_VoronoiRegions[i]->ClearPoints(); }
223  void VoronoiRegionAddPointId(int id, int x)
224  { m_VoronoiRegions[id]->AddPointId(x); }
225  void BuildEdge(int id)
226  { m_VoronoiRegions[id]->BuildEdges(); }
227 
228  void LineListClear(){ m_LineList.clear(); }
229  void EdgeListClear(){ m_EdgeList.clear(); }
230  void VertexListClear()
231  {
232  if ( this->m_PointsContainer.IsNull() )
233  {
234  this->m_PointsContainer = PointsContainer::New();
235  }
236 
237  this->m_PointsContainer->Initialize();
238  }
239 
240  int LineListSize(){ return static_cast< int >( m_LineList.size() ); }
241  int EdgeListSize(){ return static_cast< int >( m_EdgeList.size() ); }
242  int VertexListSize(){ return static_cast< int >(this->m_PointsContainer->Size()); }
243  void AddLine(EdgeInfo x){ m_LineList.push_back(x); }
244  void AddEdge(VoronoiEdge x){ m_EdgeList.push_back(x); }
245  void AddVert(PointType x){ this->m_PointsContainer->InsertElement(this->m_PointsContainer->Size(), x);}
246  EdgeInfo GetLine(int id){ return m_LineList[id]; }
247  VoronoiEdge GetEdge(int id){ return m_EdgeList[id]; }
248  PointType GetVertex(int id){ return this-> m_PointsContainer->ElementAt(id); }
249  EdgeInfo GetEdgeEnd(int id)
250  {
251  EdgeInfo x;
252 
253  x[0] = m_EdgeList[id].m_LeftID;
254  x[1] = m_EdgeList[id].m_RightID;
255  return x;
256  }
257 
258  int GetEdgeLineID(int id){ return m_EdgeList[id].m_LineID; }
259 
260 protected:
262  ~VoronoiDiagram2D();
263  virtual void PrintSelf(std::ostream & os, Indent indent) const;
264 
265 private:
266  VoronoiDiagram2D(const Self &); //purposely not implemented
267  void operator=(const Self &); //purposely not implemented
268 
270  unsigned int m_NumberOfSeeds;
271  std::vector< PolygonCellType * > m_VoronoiRegions;
274  std::vector< std::vector< int > > m_CellNeighborsID;
275 
276  std::vector< EdgeInfo > m_LineList;
277  std::vector< VoronoiEdge > m_EdgeList;
278 }; // end class: VoronoiDiagram2D
279 } // end namespace itk
280 
281 #ifndef ITK_MANUAL_INSTANTIATION
282 #include "itkVoronoiDiagram2D.hxx"
283 #endif
284 
285 #endif
286