ITK  4.13.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 namespace itk
28 {
46 template< typename TCoordType >
47 class ITK_TEMPLATE_EXPORT VoronoiDiagram2D:
48  public Mesh< TCoordType, 2,
49  DefaultDynamicMeshTraits< TCoordType, 2, 2, TCoordType > >
50 {
51 public:
57 
59  itkNewMacro(Self);
60 
62  itkTypeMacro(VoronoiDiagram2D, Mesh);
63 
66 
68  itkStaticConstMacro(PointDimension, unsigned int,
69  MeshTraits::PointDimension);
70  itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
71  MeshTraits::MaxTopologicalDimension);
73 
75  typedef typename MeshTraits::PixelType
77  typedef typename MeshTraits::CoordRepType
81  typedef typename MeshTraits::PointIdentifier
83  typedef typename MeshTraits::CellIdentifier
85  typedef typename MeshTraits::CellFeatureIdentifier
87  typedef typename MeshTraits::PointType
89  typedef typename MeshTraits::PointsContainer
91  typedef typename MeshTraits::CellTraits
93  typedef typename MeshTraits::CellsContainer
97  typedef typename MeshTraits::CellLinksContainer
99  typedef typename MeshTraits::PointDataContainer
101  typedef typename MeshTraits::CellDataContainer
103  typedef typename MeshTraits::CellAutoPointer
105  typedef BoundingBox< PointIdentifier, itkGetStaticConstMacro(PointDimension), CoordRepType,
107  typedef typename PointsContainer::Pointer
109  typedef typename CellsContainer::Pointer
111  typedef typename CellLinksContainer::Pointer
113  typedef typename PointDataContainer::Pointer
115  typedef typename CellDataContainer::Pointer
117  typedef typename BoundingBoxType::Pointer
119  typedef typename PointsContainer::ConstIterator
121  typedef typename PointsContainer::Iterator
123  typedef typename CellsContainer::ConstIterator
125  typedef typename CellsContainer::Iterator
127  typedef typename CellLinksContainer::ConstIterator
129  typedef typename PointDataContainer::ConstIterator
131  typedef typename CellDataContainer::ConstIterator
133  typedef typename PointCellLinksContainer::const_iterator
135 
137  typedef typename Superclass::CellType CellType;
138  typedef typename Superclass::CellAutoPointer CellAutoPointer;
141  typedef std::deque< EdgeInfo > EdgeInfoDQ;
142  typedef typename CellType::MultiVisitor CellMultiVisitorType;
143  typedef std::vector< PointType > SeedsType;
144  typedef typename SeedsType::iterator SeedsIterator;
146  typedef typename Edge::SelfAutoPointer EdgeAutoPointer;
147  typedef std::list< PointType > PointList;
148  typedef std::vector< int > INTvector;
149  typedef typename INTvector::iterator NeighborIdIterator;
152  itkGetConstMacro(NumberOfSeeds, unsigned int);
153 
156  void SetSeeds(int num, SeedsIterator begin);
157 
159  void SetBoundary(PointType vorsize);
160 
161  void SetOrigin(PointType vorsize);
162 
164  NeighborIdIterator NeighborIdsBegin(int seeds);
165 
166  NeighborIdIterator NeighborIdsEnd(int seeds);
167 
169  VertexIterator VertexBegin();
170 
171  VertexIterator VertexEnd();
172 
174  PointType GetSeed(int SeedID);
175 
177  void GetCellId(CellIdentifier cellId, CellAutoPointer &);
178 
180  void GetPoint(int pId, PointType *answer);
181 
183  {
184 public:
187  int m_LeftID;
189  int m_LineID;
192  };
193 
195  typedef typename std::vector< VoronoiEdge >::iterator VoronoiEdgeIterator;
196 
198  VoronoiEdgeIterator EdgeBegin();
199 
200  VoronoiEdgeIterator EdgeEnd();
201 
203  EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task);
204 
205 /********************************************************/
206 
207  void Reset();
208 
209  void InsertCells();
210 
212  {
213  m_CellNeighborsID[x[0]].push_back(x[1]);
214  m_CellNeighborsID[x[1]].push_back(x[0]);
215  }
216 
217  void ClearRegion(int i)
218  {
219  m_VoronoiRegions[i]->ClearPoints();
220  }
221 
222  void VoronoiRegionAddPointId(int id, int x)
223  {
224  m_VoronoiRegions[id]->AddPointId(x);
225  }
226 
227  void BuildEdge(int id)
228  {
229  m_VoronoiRegions[id]->BuildEdges();
230  }
231 
233  {
234  m_LineList.clear();
235  }
236 
238  {
239  m_EdgeList.clear();
240  }
241 
243  {
244  if ( this->m_PointsContainer.IsNull() )
245  {
246  this->m_PointsContainer = PointsContainer::New();
247  }
248 
249  this->m_PointsContainer->Initialize();
250  }
251 
253  {
254  return static_cast< int >( m_LineList.size() );
255  }
256 
258  {
259  return static_cast< int >( m_EdgeList.size() );
260  }
261 
263  {
264  return static_cast< int >(this->m_PointsContainer->Size());
265  }
266 
268  {
269  m_LineList.push_back(x);
270  }
271 
273  {
274  m_EdgeList.push_back(x);
275  }
276 
278  {
279  this->m_PointsContainer->InsertElement(this->m_PointsContainer->Size(), x);
280  }
281 
283  {
284  return m_LineList[id];
285  }
286 
288  {
289  return m_EdgeList[id];
290  }
291 
293  {
294  return this-> m_PointsContainer->ElementAt(id);
295  }
296 
298  {
299  EdgeInfo x;
300 
301  x[0] = m_EdgeList[id].m_LeftID;
302  x[1] = m_EdgeList[id].m_RightID;
303  return x;
304  }
305 
306  int GetEdgeLineID(int id)
307  {
308  return m_EdgeList[id].m_LineID;
309  }
310 
311 protected:
313  ~VoronoiDiagram2D() ITK_OVERRIDE;
314  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
315 
316 private:
317  ITK_DISALLOW_COPY_AND_ASSIGN(VoronoiDiagram2D);
318 
319  SeedsType m_Seeds;
320  unsigned int m_NumberOfSeeds;
321  std::vector< PolygonCellType * > m_VoronoiRegions;
322  PointType m_VoronoiBoundary;
323  PointType m_VoronoiBoundaryOrigin;
324  std::vector< std::vector< int > > m_CellNeighborsID;
325 
326  std::vector< EdgeInfo > m_LineList;
327  std::vector< VoronoiEdge > m_EdgeList;
328 };
329 
330 } // end namespace itk
331 
332 #ifndef ITK_MANUAL_INSTANTIATION
333 #include "itkVoronoiDiagram2D.hxx"
334 #endif
335 
336 #endif
CellDataContainer::Pointer CellDataContainerPointer
Superclass::CellType CellType
MeshTraits::CellsContainer CellsContainer
PointDataContainer::Pointer PointDataContainerPointer
CellDataContainer::ConstIterator CellDataContainerIterator
SmartPointer< const Self > ConstPointer
PolygonCell< CellType > PolygonCellType
Represents a line segment for a Mesh.
Definition: itkLineCell.h:42
std::vector< VoronoiEdge >::iterator VoronoiEdgeIterator
A wrapper of the STL &quot;map&quot; container.
CellType::MultiVisitor CellMultiVisitorType
SeedsType::iterator SeedsIterator
MeshTraits::PointCellLinksContainer PointCellLinksContainer
void VoronoiRegionAddPointId(int id, int x)
BoundingBoxType::Pointer BoundingBoxPointer
Implements the 2-Dimensional Voronoi Diagram.
PointDataContainer::ConstIterator PointDataContainerIterator
Implements the N-dimensional mesh structure.
Definition: itkMesh.h:108
MeshTraits::CoordRepType CoordRepType
MeshTraits::PointDataContainer PointDataContainer
EdgeInfo GetEdgeEnd(int id)
Edge::SelfAutoPointer EdgeAutoPointer
CellsContainer::ConstIterator CellsContainerConstIterator
void AddEdge(VoronoiEdge x)
CellsContainer::Iterator CellsContainerIterator
MeshTraits::PixelType PixelType
PointsContainer::Pointer PointsContainerPointer
CellsContainer::Pointer CellsContainerPointer
The non-const iterator type for the map.
CellLinksContainer::ConstIterator CellLinksContainerIterator
std::vector< int > INTvector
MeshTraits::PointIdentifier PointIdentifier
The const iterator type for the map.
DefaultDynamicMeshTraits< TCoordType, 2, 2, TCoordType > MeshTraits
MeshTraits::CellAutoPointer genericCellPointer
PointsContainerIterator VertexIterator
CellType::CellAutoPointer CellAutoPointer
INTvector::iterator NeighborIdIterator
std::list< PointType > PointList
MeshTraits::CellIdentifier CellIdentifier
void AddVert(PointType x)
Represents a polygon in a Mesh.
void AddCellNeighbor(EdgeInfo x)
PointsContainer::Iterator PointsContainerIterator
MeshTraits::InterpolationWeightType InterpolationWeightType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
BoundingBox< PointIdentifier, itkGetStaticConstMacro(PointDimension), CoordRepType, PointsContainer > BoundingBoxType
CellFeatureIdentifier CellFeatureCount
std::vector< PointType > SeedsType
SmartPointer< Self > Pointer
MeshTraits::CellDataContainer CellDataContainer
A simple structure that holds type information for a mesh and its cells.
PointCellLinksContainer::const_iterator PointCellLinksContainerIterator
VoronoiEdge GetEdge(int id)
Superclass::CellAutoPointer CellAutoPointer
MeshTraits::CellLinksContainer CellLinksContainer
CellLinksContainer::Pointer CellLinksContainerPointer
PointsContainer::ConstIterator PointsContainerConstIterator
A templated class holding a geometric point in n-Dimensional space.
Definition: itkPoint.h:52
MeshTraits::CellFeatureIdentifier CellFeatureIdentifier
MeshTraits::CellTraits CellTraits
MeshTraits::PointType PointType
MeshTraits::PointsContainer PointsContainer
Base class for all data objects in ITK.
Represent and compute information about bounding boxes.
LineCell< CellType > Edge
std::deque< EdgeInfo > EdgeInfoDQ
Mesh< TCoordType, 2, DefaultDynamicMeshTraits< TCoordType, 2, 2, TCoordType > > Superclass
std::set< CellIdentifier > PointCellLinksContainer
PointType GetVertex(int id)