$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
accu/count_adjacent_vertices.hh
1 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE)
2 //
3 // This file is part of Olena.
4 //
5 // Olena is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free
7 // Software Foundation, version 2 of the License.
8 //
9 // Olena is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with Olena. If not, see <http://www.gnu.org/licenses/>.
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
19 // instantiate templates or use macros or inline functions from this
20 // file, or you compile this file and link it with other files to produce
21 // an executable, this file does not by itself cause the resulting
22 // executable to be covered by the GNU General Public License. This
23 // exception does not however invalidate any other reasons why the
24 // executable file might be covered by the GNU General Public License.
25 
26 #ifndef MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
27 # define MLN_ACCU_COUNT_ADJACENT_VERTICES_HH
28 
33 
34 # include <mln/accu/internal/base.hh>
35 # include <mln/core/concept/meta_accumulator.hh>
36 # include <mln/pw/image.hh>
37 # include <mln/util/pix.hh>
38 
39 namespace mln
40 {
41 
42  namespace accu
43  {
44 
56  //
57  template <typename F, typename S>
59  : public mln::accu::internal::base< unsigned,
60  count_adjacent_vertices<F,S> >
61  {
63 
65 
68  void init();
69  void take(const argument& arg);
70  void take(const count_adjacent_vertices<F,S>& other);
71 
73  void set_value(unsigned c);
75 
77  unsigned to_result() const;
78 
80  bool is_valid() const;
81 
82  protected:
84  void update_ ();
85 
86  protected:
88  unsigned count__;
90  std::set<unsigned> vertices_;
91  };
92 
93 
94  namespace meta
95  {
96 
99  : public Meta_Accumulator< count_adjacent_vertices >
100  {
101  template <typename F, typename S>
102  struct with
103  {
105  };
106  };
107 
108  } // end of namespace mln::accu::meta
109 
110 
111 # ifndef MLN_INCLUDE_ONLY
112 
113  template <typename F, typename S>
114  inline
116  {
117  init();
118  }
119 
120  template <typename F, typename S>
121  inline
122  void
124  {
125  vertices_.clear();
126  update_();
127  }
128 
129  template <typename F, typename S>
130  inline
131  void
132  count_adjacent_vertices<F,S>::take(const argument& arg)
133  {
134  vertices_.insert(arg.p().v1());
135  vertices_.insert(arg.p().v2());
136  update_();
137  }
138 
139  template <typename F, typename S>
140  inline
141  void
142  count_adjacent_vertices<F,S>::take(const count_adjacent_vertices<F,S>& other)
143  {
144  vertices_.insert (other.vertices_.begin(), other.vertices_.end());
145  update_();
146  }
147 
148  template <typename F, typename S>
149  inline
150  unsigned
152  {
153  return count__;
154  }
155 
156  template <typename F, typename S>
157  inline
158  void
160  {
161  count__ = c;
163  vertices_.clear();
164  }
165 
166  template <typename F, typename S>
167  inline
168  void
170  {
171  count__ = vertices_.size();
172  }
173 
174  template <typename F, typename S>
175  inline
176  bool
178  {
179  return true;
180  }
181 
182 # endif // ! MLN_INCLUDE_ONLY
183 
184  } // end of namespace mln::accu
185 
186 } // end of namespace mln
187 
188 
189 #endif // ! MLN_ACCU_COUNT_ADJACENT_VERTICES_HH