$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
flat_zones.hh
1 // Copyright (C) 2007, 2008, 2009, 2010, 2011, 2013 EPITA Research and
2 // Development 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_FLAT_ZONES_HH
28 # define MLN_LABELING_FLAT_ZONES_HH
29 
33 
34 # include <mln/core/concept/image.hh>
35 # include <mln/core/concept/neighborhood.hh>
36 # include <mln/canvas/labeling/video.hh>
37 
38 
39 namespace mln
40 {
41 
42  namespace labeling
43  {
44 
54  template <typename I, typename N, typename L>
55  mln_ch_value(I, L)
56  flat_zones(const Image<I>& input, const Neighborhood<N>& nbh,
57  L& nlabels);
58 
59 
60 
61 # ifndef MLN_INCLUDE_ONLY
62 
63  namespace impl
64  {
65 
66  // Flat zone functor for the labeling canvas.
67 
68  template <typename I, typename L>
69  struct flat_zones_functor
70  {
71  const I& input;
72 
73  // Generic implementation.
74 
75  typedef mln_psite(I) P;
76 
77  void init() {}
78  bool handles(const P&) const { return true; }
79 
80  bool equiv(const P& n, const P& p) const
81  { return input(n) == input(p); }
82 
83  bool labels(const P&) const { return true; }
84  void do_no_union(const P&, const P&) {}
85  void init_attr(const P&) {}
86  void merge_attr(const P&, const P&) {}
87  void set_new_label(const P&, const L&){}
88  void set_label(const P&, const L&) {}
89  void finalize() {}
90 
91 
92  // Fastest implementation.
93 
94  void init_() {}
95 
96  bool handles_(unsigned) const
97  { return true; }
98 
99  bool equiv_(unsigned n, unsigned p) const
100  { return input.element(n) == input.element(p); }
101 
102  bool labels_(unsigned) const { return true; }
103  void do_no_union_(unsigned, unsigned) {}
104  void init_attr_(unsigned) {}
105  void merge_attr_(unsigned, unsigned) {}
106  void set_new_label_(unsigned, const L&) {}
107  void set_label_(unsigned, const L&) {}
108  void finalize_() {}
109 
110  // end of requirements.
111 
112  flat_zones_functor(const I& input)
113  : input(input)
114  {}
115  };
116 
117 
118  } // end of namespace mln::labeling::impl
119 
120 
121 
122  // Facade.
123 
124  template <typename I, typename N, typename L>
125  mln_ch_value(I, L)
126  flat_zones(const Image<I>& input_, const Neighborhood<N>& nbh_,
127  L& nlabels)
128  {
129  mln_trace("labeling::flat_zones");
130 
131  const I& input = exact(input_);
132  const N& nbh = exact(nbh_);
133  mln_precondition(input.is_valid());
134 
135  // Call the labeling canvas.
136  typedef impl::flat_zones_functor<I,L> F;
137  F f(input);
138  mln_ch_value(I, L) output =
139  canvas::labeling::video(input, nbh, nlabels, f);
140 
141  return output;
142  }
143 
144 # endif // ! MLN_INCLUDE_ONLY
145 
146  } // end of namespace mln::labeling
147 
148 } // end of namespace mln
149 
150 
151 #endif // ! MLN_LABELING_FLAT_ZONES_HH