ITK  4.6.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 >
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,
74  itkStaticConstMacro(MaxTopologicalDimension, unsigned int,
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;
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 
169 
171 
174 
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 
203 
205 
208 
209 /********************************************************/
210 
211  void Reset();
212 
213  void InsertCells();
214 
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(); }
231  {
232  if ( this->m_PointsContainer.IsNull() )
233  {
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); }
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:
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
CellDataContainer::Pointer CellDataContainerPointer
Superclass::CellType CellType
virtual void PrintSelf(std::ostream &os, Indent indent) const
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
VoronoiEdgeIterator EdgeEnd(void)
NeighborIdIterator NeighborIdsBegin(int seeds)
A wrapper of the STL &quot;map&quot; container.
CellType::MultiVisitor CellMultiVisitorType
static const unsigned int PointDimension
SeedsType::iterator SeedsIterator
MeshTraits::PointCellLinksContainer PointCellLinksContainer
VertexIterator VertexEnd(void)
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)
static Pointer New()
NeighborIdIterator NeighborIdsEnd(int seeds)
Edge::SelfAutoPointer EdgeAutoPointer
VoronoiEdgeIterator EdgeBegin(void)
void SetSeeds(int num, SeedsIterator begin)
CellsContainer::ConstIterator CellsContainerConstIterator
void AddEdge(VoronoiEdge x)
CellsContainer::Iterator CellsContainerIterator
void GetCellId(CellIdentifier cellId, CellAutoPointer &)
MeshTraits::PixelType PixelType
PointsContainer::Pointer PointsContainerPointer
CellsContainer::Pointer CellsContainerPointer
The non-const iterator type for the map.
CellLinksContainer::ConstIterator CellLinksContainerIterator
std::vector< int > INTvector
void SetBoundary(PointType vorsize)
MeshTraits::PointIdentifier PointIdentifier
The const iterator type for the map.
void operator=(const Self &)
DefaultDynamicMeshTraits< TCoordType, 2, 2, TCoordType > MeshTraits
MeshTraits::CellAutoPointer genericCellPointer
std::vector< VoronoiEdge > m_EdgeList
PointsContainerIterator VertexIterator
CellType::CellAutoPointer CellAutoPointer
INTvector::iterator NeighborIdIterator
std::list< PointType > PointList
std::vector< std::vector< int > > m_CellNeighborsID
MeshTraits::CellIdentifier CellIdentifier
void AddVert(PointType x)
Represents a polygon in a Mesh.
static const unsigned int MaxTopologicalDimension
bool IsNull() const
void AddCellNeighbor(EdgeInfo x)
void SetOrigin(PointType vorsize)
PointsContainer::Iterator PointsContainerIterator
static const unsigned int PointDimension
MeshTraits::InterpolationWeightType InterpolationWeightType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
VertexIterator VertexBegin(void)
BoundingBox< PointIdentifier, itkGetStaticConstMacro(PointDimension), CoordRepType, PointsContainer > BoundingBoxType
PointType GetSeed(int SeedID)
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.
EdgeInfo GetSeedsIDAroundEdge(VoronoiEdge *task)
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:51
MeshTraits::CellFeatureIdentifier CellFeatureIdentifier
MeshTraits::CellTraits CellTraits
MeshTraits::PointType PointType
MeshTraits::PointsContainer PointsContainer
std::vector< PolygonCellType * > m_VoronoiRegions
void GetPoint(int pId, PointType *answer)
Base class for all data objects in ITK.
Represent and compute information about bounding boxes.
LineCell< CellType > Edge
std::deque< EdgeInfo > EdgeInfoDQ
std::vector< EdgeInfo > m_LineList
Mesh< TCoordType, 2, DefaultDynamicMeshTraits< TCoordType, 2, 2, TCoordType > > Superclass
std::set< CellIdentifier > PointCellLinksContainer
PointType GetVertex(int id)
static const unsigned int MaxTopologicalDimension