$extrastylesheet
Olena  User documentation 2.1
An Image Processing Platform
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
morpho/attribute/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_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH
27 # define MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH
28 
35 
36 # include <mln/pw/internal/image_base.hh>
37 # include <mln/accu/internal/base.hh>
38 # include <mln/pw/image.hh>
39 # include <mln/util/pix.hh>
40 # include <mln/util/graph_ids.hh>
41 
42 namespace mln
43 {
44 
45  // Forward declaration.
46  namespace morpho {
47  namespace attribute {
48  template <typename I>
49  struct count_adjacent_vertices;
50  }
51  }
52 
53 
54  // Traits.
55 
56  namespace trait
57  {
58 
59  template <typename I>
60  struct accumulator_< morpho::attribute::count_adjacent_vertices<I> >
61  {
62  typedef accumulator::has_untake::no has_untake;
63  typedef accumulator::has_set_value::no has_set_value;
64  typedef accumulator::has_stop::no has_stop;
65  typedef accumulator::when_pix::use_p when_pix;
66  };
67 
68  } // end of namespace mln::trait
69 
70 
71  namespace morpho
72  {
73 
74  namespace attribute
75  {
76 
81  //
82  template <typename I>
84  : public accu::internal::base< unsigned ,
85  count_adjacent_vertices<I> >
86  {
87  typedef mln_psite(I) argument;
88 
90 
93  void init();
94 
95  void take(const argument& px);
96  void take(const count_adjacent_vertices<I>& other);
97 
98  void take_as_init_(const argument& px);
100 
102  unsigned to_result() const;
103 
105  bool is_valid() const;
106 
107 
108  protected:
110  void update_ ();
111 
113  unsigned count__;
115  std::set<util::vertex_id_t> vertices_;
116  };
117 
118 
119 
120 # ifndef MLN_INCLUDE_ONLY
121 
122  template <typename I>
123  inline
125  {
126  init();
127  }
128 
129  template <typename I>
130  inline
131  void
133  {
134  vertices_.clear();
135  update_();
136  }
137 
138  template <typename I>
139  inline
140  void
141  count_adjacent_vertices<I>::take(const argument& p)
142  {
143  vertices_.insert(p.v1());
144  vertices_.insert(p.v2());
145  update_();
146  }
147 
148  template <typename I>
149  inline
150  void
151  count_adjacent_vertices<I>::take(const count_adjacent_vertices<I>& other)
152  {
153  vertices_.insert (other.vertices_.begin(), other.vertices_.end());
154  update_();
155  }
156 
157  template <typename I>
158  inline
159  void
161  {
162  vertices_.clear();
163  take(px);
164  }
165 
166  template <typename I>
167  inline
168  unsigned
170  {
171  return count__;
172  }
173 
174  template <typename I>
175  inline
176  void
178  {
179  count__ = vertices_.size();
180  }
181 
182  template <typename I>
183  inline
184  bool
186  {
187  return true;
188  }
189 
190 
191 # endif // ! MLN_INCLUDE_ONLY
192 
193  } // end of namespace mln::morpho::attribute
194 
195  } // end of namespace mln::morpho
196 
197 } // end of namespace mln
198 
199 #endif // ! MLN_MORPHO_ATTRIBUTE_COUNT_ADJACENT_VERTICES_HH