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.
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.
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/>.
18 * @file DomainAdjacency.ih
19 * @author Jacques-Olivier Lachaud (\c jacques-olivier.lachaud@univ-savoie.fr )
20 * Laboratory of Mathematics (CNRS, UMR 5807), University of Savoie, France
24 * Implementation of inline methods defined in DomainAdjacency.h
26 * This file is part of the DGtal library.
30 //////////////////////////////////////////////////////////////////////////////
32 //////////////////////////////////////////////////////////////////////////////
34 ///////////////////////////////////////////////////////////////////////////////
35 // IMPLEMENTATION of inline methods.
36 ///////////////////////////////////////////////////////////////////////////////
37 #include "DGtal/topology/MetricAdjacency.h"
38 ///////////////////////////////////////////////////////////////////////////////
39 // ----------------------- Standard services ------------------------------
41 template <typename TDomain, typename TAdjacency>
43 DGtal::DomainAdjacency<TDomain,TAdjacency>
46 //------------------------------------------------------------------------------
47 template <typename TDomain, typename TAdjacency>
49 DGtal::DomainAdjacency<TDomain,TAdjacency>
50 ::DomainAdjacency( ConstAlias<Domain> aDomain,
51 ConstAlias<Adjacency> adjacency )
52 : myPred( aDomain ), myAdjacency( adjacency )
55 //------------------------------------------------------------------------------
56 template <typename TDomain, typename TAdjacency>
58 DGtal::DomainAdjacency<TDomain,TAdjacency>
59 ::DomainAdjacency( const DomainAdjacency & other )
60 : myPred( other.myPred ), myAdjacency( other.myAdjacency )
63 //------------------------------------------------------------------------------
64 template <typename TDomain, typename TAdjacency>
67 DGtal::DomainAdjacency<TDomain,TAdjacency>
70 return myPred.domain();
72 //------------------------------------------------------------------------------
73 template <typename TDomain, typename TAdjacency>
75 const typename DGtal::DomainAdjacency<TDomain,TAdjacency>::Predicate &
76 DGtal::DomainAdjacency<TDomain,TAdjacency>
81 //------------------------------------------------------------------------------
82 template <typename TDomain, typename TAdjacency>
85 DGtal::DomainAdjacency<TDomain,TAdjacency>
86 ::isAdjacentTo( const Point & p1, const Point & p2 ) const
88 ASSERT( myPred( p1 ) );
89 ASSERT( myPred( p2 ) );
90 return myAdjacency.isAdjacentTo( p1, p2 );
92 //------------------------------------------------------------------------------
93 template <typename TDomain, typename TAdjacency>
96 DGtal::DomainAdjacency<TDomain,TAdjacency>
97 ::isProperlyAdjacentTo( const Point & p1, const Point & p2 ) const
99 ASSERT( myPred( p1 ) );
100 ASSERT( myPred( p2 ) );
101 return myAdjacency.isProperlyAdjacentTo( p1, p2 );
103 //------------------------------------------------------------------------------
104 template <typename TDomain, typename TAdjacency>
107 DGtal::DomainAdjacency<TDomain,TAdjacency>
108 ::selfDisplay ( std::ostream & out ) const
110 out << "[DomainAdjacency]";
112 //------------------------------------------------------------------------------
113 template <typename TDomain, typename TAdjacency>
116 DGtal::DomainAdjacency<TDomain,TAdjacency>
121 //------------------------------------------------------------------------------
122 template <typename TDomain, typename TAdjacency>
125 DGtal::operator<< ( std::ostream & out,
126 const DomainAdjacency<TDomain,TAdjacency> & object )
128 object.selfDisplay( out );
132 ///////////////////////////////////////////////////////////////////////////////
133 // ----------------------- Local graph services -----------------------------
136 * @return maximum number of neighbors for this adjacency
138 template <typename TDomain, typename TAdjacency>
140 typename DGtal::DomainAdjacency<TDomain, TAdjacency>::Size
141 DGtal::DomainAdjacency<TDomain, TAdjacency>::bestCapacity() const
143 return myAdjacency.bestCapacity();
147 * @param v any vertex
149 * @return the number of neighbors of this vertex
151 template <typename TDomain, typename TAdjacency>
153 typename DGtal::DomainAdjacency<TDomain, TAdjacency>::Size
154 DGtal::DomainAdjacency<TDomain, TAdjacency>::degree
155 ( const Vertex & v ) const
157 std::vector<Vertex> vect;
158 std::back_insert_iterator< std::vector<Vertex> > out_it(vect);
159 myAdjacency.writeNeighbors( out_it, v, myPred );
160 return static_cast<Size>( vect.size() );
161 // return myAdjacency.degree( v );
165 * Writes the neighbors of a vertex using an output iterator
168 * @tparam OutputIterator the type of an output iterator writing
169 * in a container of vertices.
171 * @param it the output iterator
173 * @param v the vertex whose neighbors will be written
175 template <typename TDomain, typename TAdjacency>
176 template <typename OutputIterator>
179 DGtal::DomainAdjacency<TDomain, TAdjacency>::writeNeighbors
180 ( OutputIterator &it, const Vertex & v ) const
182 //myAdjacency.writeProperNeighborhood( v, it, myPred );//writeNeighbors<OutputIterator>( v, it );
183 // myAdjacency.writeNeighbors( it, v );
184 myAdjacency.writeNeighbors( it, v, myPred );
189 * Writes the neighbors of a vertex which satisfy a predicate using an
193 * @tparam OutputIterator the type of an output iterator writing
194 * in a container of vertices.
196 * @tparam VertexPredicate the type of the predicate
198 * @param it the output iterator
200 * @param v the vertex whose neighbors will be written
202 * @param pred the predicate that must be satisfied
204 template <typename TDomain, typename TAdjacency>
205 template <typename OutputIterator, typename VertexPredicate>
207 DGtal::DomainAdjacency<TDomain, TAdjacency>::writeNeighbors
208 ( OutputIterator &it, const Vertex & v, const VertexPredicate & pred) const
210 std::vector<Vertex> vect;
211 std::back_insert_iterator< std::vector<Vertex> > out_it(vect);
212 //myAdjacency.writeProperNeighborhood( vect, out_it, myPred );
213 myAdjacency.writeNeighbors( out_it, v, myPred );
214 for( typename std::vector<Vertex>::const_iterator cit = vect.begin(); cit != vect.end(); cit ++ )
221 //myAdjacency.writeNeighbors<OutputIterator, VertexPredicate>( v, it, pred );
225 ///////////////////////////////////////////////////////////////////////////////