Milena (Olena)
User documentation 2.0a Id
|
00001 // Copyright (C) 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_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 } // end of namespace mln::make::internal 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 // Construct graph. 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 } // end of namespace mln::make::impl::generic 00149 00150 } // end of namespace mln::make::impl 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 } // end of namespace mln::make::internal 00167 00168 00169 00170 // Facade 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 } // end of namespace mln::make 00194 00195 } // end of namespace mln 00196 00197 00198 #endif // ! MLN_MAKE_INFLUENCE_ZONE_ADJACENCY_GRAPH_HH