$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
objects_small_filter.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 SCRIBO_FUN_V2B_COMPONENTS_SMALL_FILTER_HH
28 # define SCRIBO_FUN_V2B_COMPONENTS_SMALL_FILTER_HH
29 
33 
34 
35 # include <mln/core/concept/function.hh>
36 
37 # include <mln/util/array.hh>
38 
39 # include <mln/accu/math/count.hh>
40 
41 # include <mln/labeling/compute.hh>
42 
43 # include <mln/value/next.hh>
44 
45 # include <scribo/core/component_set.hh>
46 
47 namespace scribo
48 {
49 
50  namespace fun
51  {
52 
53  namespace v2b
54  {
55 
56  using namespace mln;
57 
58 
61  template <typename L>
63  : Function_v2b< components_small_filter<L> >
64  {
66 
71  //
73  unsigned min_size);
74 
75 
82  //
83  bool operator()(const mln_value(L)& l) const;
84 
86  unsigned min_size_;
87 
90 
92  mutable mln_value(L) nlabels_;
93 
95  mutable mln::util::array<bool> marked_;
96  };
97 
98 
99 
100 
101 # ifndef MLN_INCLUDE_ONLY
102 
103 
104  template <typename L>
105  inline
107  const component_set<L>& components,
108  unsigned min_size)
109  : min_size_(min_size), components_(components), nlabels_(0),
110  marked_(mln::value::next(components.nelements()), false)
111  {
112  }
113 
114 
115 
116  template <typename L>
117  inline
118  bool
119  components_small_filter<L>::operator()(const mln_value(L)& l) const
120  {
121  if (l == literal::zero)
122  return false;
123  if (components_.info(l).card() >= min_size_)
124  {
125  if (!marked_(l))
126  {
127  nlabels_ = value::next(nlabels_);
128  marked_(l) = true;
129  }
130  return true;
131  }
132 
133  return false;
134  }
135 
136 
137 # endif // ! MLN_INCLUDE_ONLY
138 
139 
140  } // end of namespace scribo::fun::v2b
141 
142  } // end of namespace scribo::fun
143 
144 } // end of namespace scribo
145 
146 #endif // ! SCRIBO_FUN_V2B_COMPONENTS_SMALL_FILTER_HH