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 #ifndef MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH
00027 # define MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH
00028
00037
00038 # include <mln/core/concept/image.hh>
00039 # include <mln/core/concept/neighborhood.hh>
00040 # include <mln/core/image/image2d.hh>
00041 # include <mln/core/alias/box2d.hh>
00042 # include <mln/extension/adjust_fill.hh>
00043 # include <mln/util/graph.hh>
00044 # include <mln/util/adjacency_matrix.hh>
00045
00046
00047 namespace mln
00048 {
00049
00050 namespace make
00051 {
00052
00060
00061 template <typename I, typename N>
00062 util::graph
00063 influence_zone_adjacency_graph(const Image<I>& iz_,
00064 const Neighborhood<N>& nbh,
00065 const mln_value(I)& nlabels);
00066
00067
00068
00069 # ifndef MLN_INCLUDE_ONLY
00070
00071
00072 namespace internal
00073 {
00074
00075 template <typename I, typename N>
00076 void
00077 influence_zone_adjacency_graph_tests(const Image<I>& iz,
00078 const Neighborhood<N>& nbh,
00079 const mln_value(I)&)
00080 {
00081 mln_precondition(exact(iz).is_valid());
00082 mln_precondition(exact(nbh).is_valid());
00083 (void) iz;
00084 (void) nbh;
00085 }
00086
00087 }
00088
00089
00090 namespace impl
00091 {
00092
00093 namespace generic
00094 {
00095
00103
00104 template <typename I, typename N>
00105 util::graph
00106 influence_zone_adjacency_graph(const Image<I>& iz_,
00107 const Neighborhood<N>& nbh_,
00108 const mln_value(I)& nlabels)
00109 {
00110 trace::entering("make::impl::generic::influence_zone_adjacency_graph");
00111
00112 internal::influence_zone_adjacency_graph_tests(iz_, nbh_, nlabels);
00113 const I& iz = exact(iz_);
00114 const N& nbh = exact(nbh_);
00115
00116 util::adjacency_matrix<> adj(nlabels.next());
00117 extension::adjust_fill(iz, nbh, 0u);
00118
00119 typedef mln_value(I) L;
00120 mln_piter(I) p(iz.domain());
00121 mln_niter(N) n(nbh, p);
00122 for_all(p)
00123 {
00124 L l1 = iz(p);
00125 for_all(n)
00126 {
00127 if (iz.domain().has(n))
00128 {
00129 L l2 = iz(n);
00130 if (iz(n) != iz((p)))
00131 adj.add(l1, l2);
00132 }
00133 }
00134 }
00135
00136
00137 util::graph g;
00138 g.add_vertices(nlabels.next());
00139 for (unsigned i = 0; i < nlabels.next(); ++i)
00140 for (unsigned j = 0; j < i; ++j)
00141 if (adj.are_adjacent(i, j))
00142 g.add_edge(i, j);
00143
00144 trace::exiting("make::impl::generic::influence_zone_adjacency_graph");
00145 return g;
00146 }
00147
00148 }
00149
00150 }
00151
00152
00153
00154 namespace internal
00155 {
00156
00157 template <typename I, typename N>
00158 util::graph
00159 influence_zone_adjacency_graph_dispatch(const Image<I>& iz,
00160 const Neighborhood<N>& nbh,
00161 const mln_value(I)& nlabels)
00162 {
00163 return make::impl::generic::influence_zone_adjacency_graph(iz, nbh, nlabels);
00164 }
00165
00166 }
00167
00168
00169
00170
00171
00172 template <typename I, typename N>
00173 inline
00174 util::graph
00175 influence_zone_adjacency_graph(const Image<I>& iz,
00176 const Neighborhood<N>& nbh,
00177 const mln_value(I)& nlabels)
00178 {
00179 trace::entering("make::influence_zone_adjacency_graph");
00180
00181 internal::influence_zone_adjacency_graph_tests(iz, nbh, nlabels);
00182
00183 util::graph g = internal::influence_zone_adjacency_graph_dispatch(iz, nbh, nlabels);
00184
00185 trace::exiting("make::influence_zone_adjacency_graph");
00186 return g;
00187 }
00188
00189
00190 # endif // ! MLN_INCLUDE_ONLY
00191
00192
00193 }
00194
00195 }
00196
00197
00198 #endif // ! MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH