edge_image.hh 5.9 KB
Newer Older
Guillaume Lazzara's avatar
Guillaume Lazzara committed
1
2
// Copyright (C) 2009 EPITA Research and Development Laboratory (LRDE)
//
3
// This file is part of the Milena Library.  This library is free
Guillaume Lazzara's avatar
Guillaume Lazzara committed
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// software; you can redistribute it and/or modify it under the terms
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING.  If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction.  Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License.  This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.

#ifndef MLN_MAKE_EDGE_IMAGE_HH
# define MLN_MAKE_EDGE_IMAGE_HH

/// \file mln/make/edge_image.hh
///
/// Routine to create a edge image.

# include <mln/core/image/edge_image.hh>
# include <mln/core/image/vertex_image.hh>
# include <mln/core/concept/function.hh>
# include <mln/util/internal/id2element.hh>


namespace mln
{

  namespace make
  {


    /// Construct an edge image.
    ///
    /// \param[in] g  A graph
    /// \param[in] fv A function mapping edge ids to values.
    ///
    /// \return an edge image.
    //
    template <typename V, typename G>
    mln::edge_image<void,V,G>
    edge_image(const Graph<G>& g, const fun::i2v::array<V>& fv);


Guillaume Lazzara's avatar
Guillaume Lazzara committed
60

Guillaume Lazzara's avatar
Guillaume Lazzara committed
61
62
    /// Construct an edge image.
    ///
Guillaume Lazzara's avatar
Guillaume Lazzara committed
63
    /// \param[in] g_  A graph
Guillaume Lazzara's avatar
Guillaume Lazzara committed
64
65
66
67
68
69
70
71
    /// \param[in] fp A function mapping edge ids to sites.
    /// \param[in] fv A function mapping edge ids to values.
    ///
    /// \return an edge image.
    //
    template <typename FP, typename FV, typename G>
    mln::edge_image<mln_result(FP),mln_result(FV),G>
    edge_image(const Graph<G>& g_,
72
73
	       const Function_v2v<FP>& fp,
	       const Function_v2v<FV>& fv);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
74
75


Guillaume Lazzara's avatar
Guillaume Lazzara committed
76

Guillaume Lazzara's avatar
Guillaume Lazzara committed
77
78
79
    /// Construct an edge image.
    ///
    /// \param[in] v_ima_ A vertex image.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
80
    /// \param[in] pe	  A p_edges mapping graph element to sites .
Guillaume Lazzara's avatar
Guillaume Lazzara committed
81
    /// \param[in] fv_	  A function mapping two vertex ids to a value.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
82
83
84
85
    ///			  The result is associated to the corresponding edge.
    ///
    /// \return an edge image.
    //
Guillaume Lazzara's avatar
Guillaume Lazzara committed
86
    template <typename P, typename V, typename G, typename FP, typename FV>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
87
88
    mln::edge_image<mln_result(FP),mln_result(FV),G>
    edge_image(const vertex_image<P,V,G>& v_ima_,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
89
	       const p_edges<G,FP> pe,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
90
91
92
93
	       const Function_vv2v<FV>& fv_);



Guillaume Lazzara's avatar
Guillaume Lazzara committed
94
95
96
    /// Construct an edge image.
    ///
    /// \param[in] v_ima_ A vertex image.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
97
    /// \param[in] fv_	  A function mapping two vertex ids to a value.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
98
99
    ///			  The result is associated to the corresponding edge.
    ///
Guillaume Lazzara's avatar
Guillaume Lazzara committed
100
101
    /// \return an edge image without localization information mapped to
    /// graph elements.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
102
103
104
105
106
107
108
    //
    template <typename P, typename V, typename G, typename FV>
    mln::edge_image<void,mln_result(FV),G>
    edge_image(const vertex_image<P,V,G>& v_ima_,
	       const Function_vv2v<FV>& fv_);


Guillaume Lazzara's avatar
Guillaume Lazzara committed
109
110
111
# ifndef MLN_INCLUDE_ONLY


Guillaume Lazzara's avatar
Guillaume Lazzara committed
112

Guillaume Lazzara's avatar
Guillaume Lazzara committed
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
    template <typename V, typename G>
    mln::edge_image<void,V,G>
    edge_image(const Graph<G>& g, const fun::i2v::array<V>& fv)
    {
      trace::entering("make::edge_image");
      mln_precondition(exact(g).is_valid());

      p_vertices<G> pv(g);
      mln::edge_image<void,V,G> ima(pv, fv);

      trace::exiting("make::edge_image");
      return ima;
    }


Guillaume Lazzara's avatar
Guillaume Lazzara committed
128

Guillaume Lazzara's avatar
Guillaume Lazzara committed
129
130
131
    template <typename FP, typename FV, typename G>
    mln::edge_image<mln_result(FP),mln_result(FV),G>
    edge_image(const Graph<G>& g_,
132
133
	       const Function_v2v<FP>& fp,
	       const Function_v2v<FV>& fv)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
134
135
136
137
138
139
140
141
142
143
144
145
146
    {
      trace::entering("make::edge_image");
      const G& g = exact(g_);
      mln_precondition(g.is_valid());

      p_vertices<G,FP> pv(g,fp);
      mln::edge_image<mln_result(FP),mln_result(FV),G> ima(pv, fv);

      trace::exiting("make::edge_image");
      return ima;
    }


Guillaume Lazzara's avatar
Guillaume Lazzara committed
147

Guillaume Lazzara's avatar
Guillaume Lazzara committed
148
    template <typename P, typename V, typename G, typename FP, typename FV>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
149
150
    mln::edge_image<mln_result(FP),mln_result(FV),G>
    edge_image(const vertex_image<P,V,G>& v_ima_,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
151
	       const p_edges<G,FP> pe,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
152
153
154
155
156
157
158
159
160
	       const Function_vv2v<FV>& fv_)
    {
      trace::entering("make::edge_image");

      const FV& fv = exact(fv_);
      const vertex_image<P,V,G>& v_ima = exact(v_ima_);
      mln_precondition(v_ima.is_valid());

      typedef mln::edge_image<mln_result(FP),mln_result(FV),G> edge_ima_t;
Guillaume Lazzara's avatar
Guillaume Lazzara committed
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
      edge_ima_t ima_e(pe);

      mln_piter(edge_ima_t) e(ima_e.domain());
      for_all(e)
	ima_e(e) = fv(e.element().v1(), e.element().v2());

      trace::exiting("make::edge_image");
      return ima_e;
    }



    template <typename P, typename V, typename G, typename FV>
    mln::edge_image<void,mln_result(FV),G>
    edge_image(const vertex_image<P,V,G>& v_ima_,
	       const Function_vv2v<FV>& fv_)
    {
      trace::entering("make::edge_image");

      const FV& fv = exact(fv_);
      const vertex_image<P,V,G>& v_ima = exact(v_ima_);
      mln_precondition(v_ima.is_valid());

Guillaume Lazzara's avatar
Guillaume Lazzara committed
184
      p_edges<G> pe(v_ima.graph());
Guillaume Lazzara's avatar
Guillaume Lazzara committed
185
186
      typedef mln::edge_image<void,mln_result(FV),G> edge_ima_t;
      edge_ima_t ima_e(pe);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
187
188
189

      mln_piter(edge_ima_t) e(ima_e.domain());
      for_all(e)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
190
	ima_e(e) = fv(v_ima(e.element().v1()), v_ima(e.element().v2()));
Guillaume Lazzara's avatar
Guillaume Lazzara committed
191
192
193
194
195
196

      trace::exiting("make::edge_image");
      return ima_e;
    }


Guillaume Lazzara's avatar
Guillaume Lazzara committed
197

Guillaume Lazzara's avatar
Guillaume Lazzara committed
198
199
200
201
202
203
204
205
# endif // ! MLN_INCLUDE_ONLY


  } // end of namespace mln::make

} // end of namespace mln

# endif // ! MLN_MAKE_EDGE_IMAGE_HH