edge_image.hh 6.67 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 Olena.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
4
//
5
6
7
8
9
// Olena is free software: you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation, version 2 of the License.
//
// Olena is distributed in the hope that it will be useful,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
10
11
12
13
14
// 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
15
// along with Olena.  If not, see <http://www.gnu.org/licenses/>.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
16
17
//
// As a special exception, you may use this file as part of a free
18
// software project without restriction.  Specifically, if other files
Guillaume Lazzara's avatar
Guillaume Lazzara committed
19
// instantiate templates or use macros or inline functions from this
20
21
22
23
24
// 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.
Guillaume Lazzara's avatar
Guillaume Lazzara committed
25
26
27
28

#ifndef MLN_MAKE_EDGE_IMAGE_HH
# define MLN_MAKE_EDGE_IMAGE_HH

29
/// \file
Guillaume Lazzara's avatar
Guillaume Lazzara committed
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
///
/// 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);

Edwin Carlinet's avatar
Edwin Carlinet committed
57
58
59
60
61
62
63
64
65
66
    /// 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 FV, typename G>
    mln::edge_image<void, mln_result(FV), G>
    edge_image(const Graph<G>& g, const Function_v2v<FV>& fv);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
67

Guillaume Lazzara's avatar
Guillaume Lazzara committed
68

Guillaume Lazzara's avatar
Guillaume Lazzara committed
69
70
    /// Construct an edge image.
    ///
Guillaume Lazzara's avatar
Guillaume Lazzara committed
71
    /// \param[in] g_  A graph
Guillaume Lazzara's avatar
Guillaume Lazzara committed
72
73
74
75
76
77
78
79
    /// \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_,
80
81
	       const Function_v2v<FP>& fp,
	       const Function_v2v<FV>& fv);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
82
83


Guillaume Lazzara's avatar
Guillaume Lazzara committed
84

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



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


Guillaume Lazzara's avatar
Guillaume Lazzara committed
117
118
119
# ifndef MLN_INCLUDE_ONLY


Guillaume Lazzara's avatar
Guillaume Lazzara committed
120

Guillaume Lazzara's avatar
Guillaume Lazzara committed
121
122
123
124
125
126
127
128
129
130
131
132
133
134
    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;
    }

Edwin Carlinet's avatar
Edwin Carlinet committed
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
    template <typename FV, typename G>
    mln::edge_image<void,mln_result(FV),G>
    edge_image(const Graph<G>& g_,
	       const Function_v2v<FV>& fv)
    {
      trace::entering("make::edge_image");
      const G& g = exact(g_);
      const FV& f = exact(fv);
      mln_precondition(g.is_valid());

      p_edges<G> pe(g);
      typedef mln::edge_image<void,mln_result(FV),G> ima_t;
      ima_t ima(pe);

      mln_piter(ima_t) e(ima.domain());
      for_all(e)
	ima(e) = f(e.id());

      trace::exiting("make::edge_image");
      return ima;
    }
Guillaume Lazzara's avatar
Guillaume Lazzara committed
156

Guillaume Lazzara's avatar
Guillaume Lazzara committed
157

Guillaume Lazzara's avatar
Guillaume Lazzara committed
158
159
160
    template <typename FP, typename FV, typename G>
    mln::edge_image<mln_result(FP),mln_result(FV),G>
    edge_image(const Graph<G>& g_,
161
162
	       const Function_v2v<FP>& fp,
	       const Function_v2v<FV>& fv)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
163
164
165
166
167
168
169
170
171
172
173
174
175
    {
      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
176

Guillaume Lazzara's avatar
Guillaume Lazzara committed
177
    template <typename P, typename V, typename G, typename FP, typename FV>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
178
    mln::edge_image<mln_result(FP),mln_result(FV),G>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
179
    edge_image(const mln::vertex_image<P,V,G>& v_ima_,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
180
	       const p_edges<G,FP> pe,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
181
182
183
184
185
	       const Function_vv2v<FV>& fv_)
    {
      trace::entering("make::edge_image");

      const FV& fv = exact(fv_);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
186
      const mln::vertex_image<P,V,G>& v_ima = exact(v_ima_);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
187
188
189
      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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
      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>
Guillaume Lazzara's avatar
Guillaume Lazzara committed
204
    edge_image(const mln::vertex_image<P,V,G>& v_ima_,
Guillaume Lazzara's avatar
Guillaume Lazzara committed
205
206
207
208
209
	       const Function_vv2v<FV>& fv_)
    {
      trace::entering("make::edge_image");

      const FV& fv = exact(fv_);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
210
      const mln::vertex_image<P,V,G>& v_ima = exact(v_ima_);
Guillaume Lazzara's avatar
Guillaume Lazzara committed
211
212
      mln_precondition(v_ima.is_valid());

Guillaume Lazzara's avatar
Guillaume Lazzara committed
213
      p_edges<G> pe(v_ima.domain().graph());
Guillaume Lazzara's avatar
Guillaume Lazzara committed
214
215
      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
216
217
218

      mln_piter(edge_ima_t) e(ima_e.domain());
      for_all(e)
Guillaume Lazzara's avatar
Guillaume Lazzara committed
219
	ima_e(e) = fv(v_ima(e.element().v1()), v_ima(e.element().v2()));
Guillaume Lazzara's avatar
Guillaume Lazzara committed
220
221
222
223
224
225

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


Guillaume Lazzara's avatar
Guillaume Lazzara committed
226

Guillaume Lazzara's avatar
Guillaume Lazzara committed
227
228
229
230
231
232
233
# endif // ! MLN_INCLUDE_ONLY


  } // end of namespace mln::make

} // end of namespace mln

Guillaume Lazzara's avatar
Guillaume Lazzara committed
234
#endif // ! MLN_MAKE_EDGE_IMAGE_HH