Milena (Olena)  User documentation 2.0a Id
 All Classes Namespaces Functions Variables Typedefs Enumerator Groups Pages
labeling/superpose.hh
1 // Copyright (C) 2009, 2010 EPITA Research and Development Laboratory
2 // (LRDE)
3 //
4 // This file is part of Olena.
5 //
6 // Olena is free software: you can redistribute it and/or modify it under
7 // the terms of the GNU General Public License as published by the Free
8 // Software Foundation, version 2 of the License.
9 //
10 // Olena is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 // General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
17 //
18 // As a special exception, you may use this file as part of a free
19 // software project without restriction. Specifically, if other files
20 // instantiate templates or use macros or inline functions from this
21 // file, or you compile this file and link it with other files to produce
22 // an executable, this file does not by itself cause the resulting
23 // executable to be covered by the GNU General Public License. This
24 // exception does not however invalidate any other reasons why the
25 // executable file might be covered by the GNU General Public License.
26 
27 #ifndef MLN_LABELING_SUPERPOSE_HH
28 # define MLN_LABELING_SUPERPOSE_HH
29 
33 
34 
35 # include <mln/core/concept/image.hh>
36 # include <mln/util/array.hh>
37 # include <mln/labeling/relabel.hh>
38 # include <mln/data/paste.hh>
39 # include <mln/pw/all.hh>
40 
41 # include <mln/value/next.hh>
42 # include <mln/value/equiv.hh>
43 
44 namespace mln
45 {
46 
47  namespace labeling
48  {
49 
50 
70  template <typename I, typename J>
71  mln_concrete(I)
72  superpose(const Image<I>& lhs, const mln_value(I)& lhs_nlabels,
73  const Image<J>& rhs, const mln_value(J)& rhs_nlabels,
74  mln_value(I)& new_nlabels);
75 
76 
77 
78 
79 # ifndef MLN_INCLUDE_ONLY
80 
81  template <typename I, typename J>
82  mln_concrete(I)
83  superpose(const Image<I>& lhs_, const mln_value(I)& lhs_nlabels,
84  const Image<J>& rhs_, const mln_value(J)& rhs_nlabels,
85  mln_value(I)& new_nlabels)
86  {
87  trace::entering("mln::labeling::superpose");
88 
89  const I& lhs = exact(lhs_);
90  const J& rhs = exact(rhs_);
91 
92  mlc_converts_to(mln_value(I), mln_value(J))::check();
93  mln_precondition(lhs.is_valid());
94  mln_precondition(rhs.is_valid());
95  mln_precondition(lhs.domain() == rhs.domain());
97 
98  mln_concrete(I) output = duplicate(lhs);
99 
101  rebase_lbl(value::next(rhs_nlabels));
102 
103  rebase_lbl(0) = 0;
104  for (unsigned i = 1; i <= rhs_nlabels; ++i)
105  rebase_lbl(i) = i + value::equiv(lhs_nlabels);
106 
107  data::paste(labeling::relabel(rhs, rhs_nlabels, rebase_lbl)
108  | (pw::value(rhs) != pw::cst(literal::zero)),
109  output);
110 
111  new_nlabels = value::equiv(lhs_nlabels)
112  + value::equiv(rhs_nlabels) + 1;
113 
114  trace::exiting("mln::labeling::superpose");
115  return output;
116  }
117 
118 
119 # endif // ! MLN_INCLUDE_ONLY
120 
121  } // end of namespace mln::labeling
122 
123 } // end of namespace mln
124 
125 
126 #endif // ! MLN_LABELING_SUPERPOSE_HH