Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 2007, 2008, 2009 EPITA Research and Development Laboratory (LRDE) 00002 // 00003 // This file is part of Olena. 00004 // 00005 // Olena is free software: you can redistribute it and/or modify it under 00006 // the terms of the GNU General Public License as published by the Free 00007 // Software Foundation, version 2 of the License. 00008 // 00009 // Olena is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // General Public License for more details. 00013 // 00014 // You should have received a copy of the GNU General Public License 00015 // along with Olena. If not, see <http://www.gnu.org/licenses/>. 00016 // 00017 // As a special exception, you may use this file as part of a free 00018 // software project without restriction. Specifically, if other files 00019 // instantiate templates or use macros or inline functions from this 00020 // file, or you compile this file and link it with other files to produce 00021 // an executable, this file does not by itself cause the resulting 00022 // executable to be covered by the GNU General Public License. This 00023 // exception does not however invalidate any other reasons why the 00024 // executable file might be covered by the GNU General Public License. 00025 00026 #ifndef MLN_ACCU_COUNT_ADJACENT_VERTICES_HH 00027 # define MLN_ACCU_COUNT_ADJACENT_VERTICES_HH 00028 00033 00034 # include <mln/accu/internal/base.hh> 00035 # include <mln/core/concept/meta_accumulator.hh> 00036 # include <mln/pw/image.hh> 00037 # include <mln/util/pix.hh> 00038 00039 namespace mln 00040 { 00041 00042 namespace accu 00043 { 00044 00056 // 00057 template <typename F, typename S> 00058 struct count_adjacent_vertices 00059 : public mln::accu::internal::base< unsigned, 00060 count_adjacent_vertices<F,S> > 00061 { 00062 typedef mln::util::pix< pw::image<F,S> > argument; 00063 00064 count_adjacent_vertices(); 00065 00068 void init(); 00069 void take(const argument& arg); 00070 void take(const count_adjacent_vertices<F,S>& other); 00071 00073 void set_value(unsigned c); 00075 00077 unsigned to_result() const; 00078 00080 bool is_valid() const; 00081 00082 protected: 00084 void update_ (); 00085 00086 protected: 00088 unsigned count__; 00090 std::set<unsigned> vertices_; 00091 }; 00092 00093 00094 namespace meta 00095 { 00096 00098 struct count_adjacent_vertices 00099 : public Meta_Accumulator< count_adjacent_vertices > 00100 { 00101 template <typename F, typename S> 00102 struct with 00103 { 00104 typedef accu::count_adjacent_vertices<F,S> ret; 00105 }; 00106 }; 00107 00108 } // end of namespace mln::accu::meta 00109 00110 00111 # ifndef MLN_INCLUDE_ONLY 00112 00113 template <typename F, typename S> 00114 inline 00115 count_adjacent_vertices<F,S>::count_adjacent_vertices() 00116 { 00117 init(); 00118 } 00119 00120 template <typename F, typename S> 00121 inline 00122 void 00123 count_adjacent_vertices<F,S>::init() 00124 { 00125 vertices_.clear(); 00126 update_(); 00127 } 00128 00129 template <typename F, typename S> 00130 inline 00131 void 00132 count_adjacent_vertices<F,S>::take(const argument& arg) 00133 { 00134 vertices_.insert(arg.p().v1()); 00135 vertices_.insert(arg.p().v2()); 00136 update_(); 00137 } 00138 00139 template <typename F, typename S> 00140 inline 00141 void 00142 count_adjacent_vertices<F,S>::take(const count_adjacent_vertices<F,S>& other) 00143 { 00144 vertices_.insert (other.vertices_.begin(), other.vertices_.end()); 00145 update_(); 00146 } 00147 00148 template <typename F, typename S> 00149 inline 00150 unsigned 00151 count_adjacent_vertices<F,S>::to_result() const 00152 { 00153 return count__; 00154 } 00155 00156 template <typename F, typename S> 00157 inline 00158 void 00159 count_adjacent_vertices<F,S>::set_value(unsigned c) 00160 { 00161 count__ = c; 00163 vertices_.clear(); 00164 } 00165 00166 template <typename F, typename S> 00167 inline 00168 void 00169 count_adjacent_vertices<F,S>::update_() 00170 { 00171 count__ = vertices_.size(); 00172 } 00173 00174 template <typename F, typename S> 00175 inline 00176 bool 00177 count_adjacent_vertices<F,S>::is_valid() const 00178 { 00179 return true; 00180 } 00181 00182 # endif // ! MLN_INCLUDE_ONLY 00183 00184 } // end of namespace mln::accu 00185 00186 } // end of namespace mln 00187 00188 00189 #endif // ! MLN_ACCU_COUNT_ADJACENT_VERTICES_HH