$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
labeling/superpose.hh
1 // Copyright (C) 2009, 2010, 2013 EPITA Research and Development
2 // Laboratory (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 
71  template <typename I, typename J>
72  mln_concrete(I)
73  superpose(const Image<I>& lhs, const mln_value(I)& lhs_nlabels,
74  const Image<J>& rhs, const mln_value(J)& rhs_nlabels,
75  mln_value(I)& new_nlabels);
76 
77 
78 
79 
80 # ifndef MLN_INCLUDE_ONLY
81 
82  template <typename I, typename J>
83  mln_concrete(I)
84  superpose(const Image<I>& lhs_, const mln_value(I)& lhs_nlabels,
85  const Image<J>& rhs_, const mln_value(J)& rhs_nlabels,
86  mln_value(I)& new_nlabels)
87  {
88  mln_trace("mln::labeling::superpose");
89 
90  const I& lhs = exact(lhs_);
91  const J& rhs = exact(rhs_);
92 
93  mlc_converts_to(mln_value(I), mln_value(J))::check();
94  mln_precondition(lhs.is_valid());
95  mln_precondition(rhs.is_valid());
96  mln_precondition(lhs.domain() == rhs.domain());
98 
99  mln_concrete(I) output = duplicate(lhs);
100 
101  util::array<mln_value(J)>
102  rebase_lbl(value::next(rhs_nlabels));
103 
104  rebase_lbl(0) = 0;
105  for (unsigned i = 1; i <= rhs_nlabels; ++i)
106  rebase_lbl(i) = i + value::equiv(lhs_nlabels);
107 
108  data::paste(labeling::relabel(rhs, rhs_nlabels, rebase_lbl)
109  | (pw::value(rhs) != pw::cst(literal::zero)),
110  output);
111 
112  new_nlabels = value::equiv(lhs_nlabels)
113  + value::equiv(rhs_nlabels) + 1;
114 
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