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
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>
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
00115
00116
00117 void init_() {}
00118 bool handles_(unsigned p) const { return input.element(p) == val; }
00119 bool equiv_(unsigned n, unsigned) const { return input.element(n) == val; }
00120 bool labels_(unsigned) const { return true; }
00121 void do_no_union_(unsigned, unsigned) {}
00122 void init_attr_(unsigned) {}
00123 void merge_attr_(unsigned, unsigned) {}
00124
00125
00126
00127 value_functor(const Image<I>& input_, const mln_value(I)& val)
00128 : input(exact(input_)),
00129 val(val)
00130 {
00131 }
00132 };
00133
00134 }
00135
00136
00137
00138
00139
00140
00141 template <typename I, typename N, typename L>
00142 mln_ch_value(I, L)
00143 value(const Image<I>& input, const mln_value(I)& val,
00144 const Neighborhood<N>& nbh, L& nlabels)
00145 {
00146 trace::entering("labeling::value");
00147
00148 internal::value_tests(input, val, nbh, nlabels);
00149
00150 mln_ch_value(I, L) output;
00151 impl::value_functor<I> f(input, val);
00152 output = canvas::labeling::video(input, nbh, nlabels, f);
00153
00154 trace::exiting("labeling::value");
00155 return output;
00156 }
00157
00158 # endif // ! MLN_INCLUDE_ONLY
00159
00160 }
00161
00162 }
00163
00164
00165 #endif // ! MLN_LABELING_VALUE_HH