DGtal 1.3.0
Loading...
Searching...
No Matches
ObjectBoostGraphInterface.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 ObjectBoostGraphInterface.ih
19 * @author Pablo Hernandez-Cerdan. Institute of Fundamental Sciences.
20 * Massey University. Palmerston North, New Zealand
21 *
22 * @date 2016/02/01
23 *
24 * Implementation of inline methods defined in ObjectBoostGraphInterface.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
41template < class TDigitalTopology, class TDigitalSet >
42inline
43std::pair<
44 typename boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::vertex_iterator,
45 typename boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::vertex_iterator
46 >
47boost::vertices( const DGtal::Object< TDigitalTopology, TDigitalSet > & obj )
48{
49 return std::make_pair( obj.begin(), obj.end() );
50}
51//-----------------------------------------------------------------------------
52template < class TDigitalTopology, class TDigitalSet >
53inline
54boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::edge_iterator::
55edge_iterator()
56 : myGraph( 0 )
57{}
58//-----------------------------------------------------------------------------
59template < class TDigitalTopology, class TDigitalSet >
60inline
61boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::edge_iterator::
62edge_iterator( const 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//-----------------------------------------------------------------------------
74template < class TDigitalTopology, class TDigitalSet >
75inline
76const typename boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::Edge &
77boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::edge_iterator::
78dereference() const
79{
80 ASSERT( myVertexRange.first != myVertexRange.second );
81 ASSERT( myOutEdgeRange.first != myOutEdgeRange.second );
82 return *( myOutEdgeRange.first );
83}
84//-----------------------------------------------------------------------------
85template < class TDigitalTopology, class TDigitalSet >
86inline
87bool
88boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::edge_iterator::
89equal( 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//-----------------------------------------------------------------------------
102template < class TDigitalTopology, class TDigitalSet >
103inline
104void
105boost::graph_traits< DGtal::Object< TDigitalTopology, TDigitalSet > >::edge_iterator::
106increment()
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