00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027 #ifndef MLN_LABELING_VALUE_HH
00028 # define MLN_LABELING_VALUE_HH
00029
00033
00034 # include <mln/core/concept/image.hh>
00035 # include <mln/core/concept/neighborhood.hh>
00036 # include <mln/canvas/labeling/video.hh>
00037 # include <mln/data/fill.hh>
00038
00039
00040
00041 namespace mln
00042 {
00043
00044 namespace labeling
00045 {
00046
00055
00056 template <typename I, typename N, typename L>
00057 mln_ch_value(I, L)
00058 value(const Image<I>& input, const mln_value(I)& val,
00059 const Neighborhood<N>& nbh, L& nlabels);
00060
00061
00062 # ifndef MLN_INCLUDE_ONLY
00063
00064
00065
00066
00067 namespace internal
00068 {
00069
00070 template <typename I, typename N, typename L>
00071 void
00072 value_tests(const Image<I>& input, const mln_value(I)& val, const Neighborhood<N>& nbh,
00073 L& nlabels)
00074 {
00075 mln_precondition(exact(input).is_valid());
00076 mln_precondition(exact(nbh).is_valid());
00077
00078 (void) input;
00079 (void) val;
00080 (void) nbh;
00081 (void) nlabels;
00082 }
00083
00084 }
00085
00086
00087
00088 namespace impl
00089 {
00090
00091
00092
00093 template <typename I, typename L>
00094 struct value_functor
00095 {
00096 typedef mln_psite(I) P;
00097
00098 const I& input;
00099 const mln_value(I)& val;
00100
00101
00102
00103 typedef mln_domain(I) S;
00104
00105
00106
00107 void init() {}
00108 bool handles(const P& p) const { return input(p) == val; }
00109 bool equiv(const P& n, const P&) const { return input(n) == val; }
00110 bool labels(const P&) const { return true; }
00111 void do_no_union(const P&, const P&) {}
00112 void init_attr(const P&) {}
00113 void merge_attr(const P&, const P&) {}
00114 void set_new_label(const P& p, const L& l){}
00115 void set_label(const P& p, const L& l) {}
00116 void finalize() {}
00117
00118
00119
00120 void init_() {}
00121 bool handles_(unsigned p) const { return input.element(p) == val; }
00122 bool equiv_(unsigned n, unsigned) const { return input.element(n) == val; }
00123 bool labels_(unsigned) const { return true; }
00124 void do_no_union_(unsigned, unsigned) {}
00125 void init_attr_(unsigned) {}
00126 void merge_attr_(unsigned, unsigned) {}
00127 void set_new_label_(unsigned, const L&) {}
00128 void set_label_(unsigned, const L&) {}
00129 void finalize_() {}
00130
00131
00132
00133 value_functor(const Image<I>& input_, const mln_value(I)& val)
00134 : input(exact(input_)),
00135 val(val)
00136 {
00137 }
00138 };
00139
00140 }
00141
00142
00143
00144
00145
00146
00147 template <typename I, typename N, typename L>
00148 mln_ch_value(I, L)
00149 value(const Image<I>& input, const mln_value(I)& val,
00150 const Neighborhood<N>& nbh, L& nlabels)
00151 {
00152 trace::entering("labeling::value");
00153
00154 internal::value_tests(input, val, nbh, nlabels);
00155
00156 mln_ch_value(I, L) output;
00157 impl::value_functor<I,L> f(input, val);
00158 output = canvas::labeling::video(input, nbh, nlabels, f);
00159
00160 trace::exiting("labeling::value");
00161 return output;
00162 }
00163
00164 # endif // ! MLN_INCLUDE_ONLY
00165
00166 }
00167
00168 }
00169
00170
00171 #endif // ! MLN_LABELING_VALUE_HH