Orfeo Toolbox  3.16
itkQuadEdgeMeshFrontIterator.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkQuadEdgeMeshFrontIterator.txx,v $
5  Language: C++
6  Date: $Date: 2009-12-15 15:37:47 $
7  Version: $Revision: 1.10 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 #ifndef __itkQuadEdgeMeshFrontIterator_txx
18 #define __itkQuadEdgeMeshFrontIterator_txx
19 
21 
22 namespace itk
23 {
24 
25 // ---------------------------------------------------------------------
26 template< class TMesh, class TQE >
29  bool start,
30  QEType* seed )
31  : m_Mesh( mesh ), m_Seed( seed ), m_Start( start )
32 {
33  if( !mesh )
34  {
35  // Invalidate the iterator and call it quits
36  m_Start = false;
37  return;
38  }
39  if( !seed )
40  {
41  seed = FindDefaultSeed( );
42  if( !seed )
43  {
44  // Invalidate the iterator and call it quits
45  m_Start = false;
46  return;
47  }
48  }
49  m_Front = new FrontType;
50  m_Front->push_back( FrontAtom( seed, 0 ) );
52  m_IsPointVisited->SetElement( seed->GetOrigin( ), true );
53  m_IsPointVisited->SetElement( seed->GetDestination( ), true );
54  m_CurrentEdge = seed;
55 }
56 
57 // ---------------------------------------------------------------------
58 template< class TMesh, class TQE >
61 {
62  if( m_Front )
63  {
64  delete m_Front;
65  }
66 }
67 
68 // ---------------------------------------------------------------------
69 template< class TMesh, class TQE >
73 {
74  // We continue only if not previously marked as finish...
75  if( !m_Start )
76  {
77  return( *this );
78  }
79 
80  // ... or until the front is empty:
81  if( m_Front->empty( ) )
82  {
83  m_Start = false;
84  return( *this );
85  }
86 
87  // Sort on the Cost:
88  m_Front->sort( );
89  // Consider the edge with lowest Cost:
90  FrontTypeIterator fit = m_Front->begin( );
91  QEType* edge = fit->m_Edge;
92 
93  // Traverse the Onext ring in search of an unvisited Origin:
94  typedef typename QEType::IteratorGeom QEIterator;
95  for( QEIterator qit = edge->BeginGeomOnext( );
96  qit != edge->EndGeomOnext( );
97  qit++ )
98  {
99  QEType* oEdge = qit.Value( );
100  // Things are quite straightforward except when QEType
101  // is in fact a QEDual (in disguise) AND oEdge->GetDestination( )
102  // is m_NoFace [in which case oEdge->GetDestination() has a value
103  // but oEdge->IsDestination() is false]. When this is the case
104  // we consider oEdge->GetDestination() as already visited.
105  if( ( m_IsPointVisited->IndexExists( oEdge->GetDestination() ) )
106  || ( ! oEdge->IsDestinationSet() ) )
107  {
108  continue;
109  }
110  else
111  {
112  // Mark the destination as visited:
113  m_IsPointVisited->SetElement( oEdge->GetDestination( ), true );
114 
115  // Compute the Cost of the new OriginType:
116  CoordRepType oCost = this->GetCost( oEdge ) + fit->m_Cost;
117 
118  // Push the Sym() on the front:
119  m_Front->push_back( FrontAtom( oEdge->GetSym( ), oCost ) );
120 
121  // We still want to handle oEdge
122  m_CurrentEdge = oEdge;
123  return( *this );
124  }
125  }
126 
127  // All the edge->Origin() neighbours were allready visited. Remove
128  // the edge from the front, and move to next edge...
129  m_Front->pop_front( );
130  m_CurrentEdge = (QEType*)0;
131  return( this->operator++() );
132 }
133 
138 template< class TMesh, class TQE >
142 {
143  if( QEType* edge = dynamic_cast< QEType* >( m_Mesh->GetEdge( ) ) )
144  {
145  return edge;
146  }
147  typedef typename QEType::DualType QEDual;
148  if( QEDual* edge = dynamic_cast< QEDual* >( m_Mesh->GetEdge( ) ) )
149  {
150  return edge->GetRot( );
151  }
152  return (QEType*)0;
153 }
154 
155 }
156 #endif

Generated at Sun May 19 2013 00:01:27 for Orfeo Toolbox with doxygen 1.8.3.1