DGtal  1.5.beta
DigitalSurfaceBoostGraphInterface.ih
1 /**
2  * This program is free software: you can redistribute it and/or modify
3  * it under the terms of the GNU Lesser General Public License as
4  * published by the Free Software Foundation, either version 3 of the
5  * License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  **/
16 
17 /**
18  * @file DigitalSurfaceBoostGraphInterface.ih
19  * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20  * Laboratory of Mathematics (CNRS, UMR 5127), University of Savoie, France
21  *
22  * @date 2013/01/20
23  *
24  * Implementation of inline methods defined in DigitalSurfaceBoostGraphInterface.h
25  *
26  * This file is part of the DGtal library.
27  */
28 
29 
30 //////////////////////////////////////////////////////////////////////////////
31 #include <cstdlib>
32 //////////////////////////////////////////////////////////////////////////////
33 
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
40 
41 template < class TDigitalSurfaceContainer >
42 inline
43 std::pair<
44  typename boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator,
45  typename boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::vertex_iterator
46  >
47 boost::vertices( const DGtal::DigitalSurface< TDigitalSurfaceContainer > & digSurf )
48 {
49  return std::make_pair( digSurf.begin(), digSurf.end() );
50 }
51 //-----------------------------------------------------------------------------
52 template < class TDigitalSurfaceContainer >
53 inline
54 boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator::
55 edge_iterator()
56  : myGraph( 0 )
57 {}
58 //-----------------------------------------------------------------------------
59 template < class TDigitalSurfaceContainer >
60 inline
61 boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator::
62 edge_iterator( ConstAlias<Adapted> graph,
63  const vertex_iterator & itB, const vertex_iterator & itE )
64  : myGraph( &graph ),
65  myVertexRange( itB, itE ),
66  myOutEdgeRange()
67 {
68  if ( myVertexRange.first != myVertexRange.second )
69  {
70  myOutEdgeRange = boost::out_edges( *myVertexRange.first, *myGraph );
71  }
72 }
73 //-----------------------------------------------------------------------------
74 template < class TDigitalSurfaceContainer >
75 inline
76 const typename boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::Arc &
77 boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator::
78 dereference() const
79 {
80  ASSERT( myVertexRange.first != myVertexRange.second );
81  ASSERT( myOutEdgeRange.first != myOutEdgeRange.second );
82  return *( myOutEdgeRange.first );
83 }
84 //-----------------------------------------------------------------------------
85 template < class TDigitalSurfaceContainer >
86 inline
87 bool
88 boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator::
89 equal( const edge_iterator & other ) const
90 {
91  bool thisAtEnd = ( myVertexRange.first == myVertexRange.second );
92  bool otherAtEnd = ( other.myVertexRange.first == other.myVertexRange.second );
93  if ( thisAtEnd || otherAtEnd ) return thisAtEnd && otherAtEnd;
94  else
95  {
96  ASSERT( myOutEdgeRange.first != myOutEdgeRange.second );
97  ASSERT( other.myOutEdgeRange.first != other.myOutEdgeRange.second );
98  return *myOutEdgeRange.first == *other.myOutEdgeRange.first;
99  }
100 }
101 //-----------------------------------------------------------------------------
102 template < class TDigitalSurfaceContainer >
103 inline
104 void
105 boost::graph_traits< DGtal::DigitalSurface< TDigitalSurfaceContainer > >::edge_iterator::
106 increment()
107 {
108  ++myOutEdgeRange.first;
109  if ( myOutEdgeRange.first == myOutEdgeRange.second )
110  {
111  ++myVertexRange.first;
112  if ( myVertexRange.first != myVertexRange.second )
113  myOutEdgeRange = boost::out_edges( *myVertexRange.first, *myGraph );
114  }
115 }
116 
117 // //
118 ///////////////////////////////////////////////////////////////////////////////
119 
120