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_CORE_CONCEPT_NEIGHBORHOOD_HH
00027 # define MLN_CORE_CONCEPT_NEIGHBORHOOD_HH
00028
00032
00033 # include <mln/core/concept/window.hh>
00034 # include <mln/trait/windows.hh>
00035
00036
00037
00038 # define mln_is_simple_neighborhood(N) mln_is_simple_window(mln_window(N))
00039
00040
00041
00042
00043 namespace mln
00044 {
00045
00046
00047
00048 template <typename E> struct Neighborhood;
00049
00050
00052
00053 template <>
00054 struct Neighborhood<void>
00055 {
00056 typedef Object<void> super;
00057 };
00058
00059
00064
00065 template <typename E>
00066 struct Neighborhood : public Object<E>
00067 {
00068 typedef Neighborhood<void> category;
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082 protected:
00083 Neighborhood();
00084 };
00085
00086
00087
00088 template <typename L, typename R>
00089 bool operator==(const Neighborhood<L>& lhs, const Neighborhood<R>& rhs);
00090
00091
00092 template <typename N>
00093 std::ostream&
00094 operator<<(std::ostream&ostr, const Neighborhood<N>& nbh);
00095
00096
00097
00098 template <typename I, typename N>
00099 util::array<int>
00100 offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh);
00101
00102 template <typename I, typename N>
00103 util::array<int>
00104 positive_offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh);
00105
00106 template <typename I, typename N>
00107 util::array<int>
00108 negative_offsets_wrt(const Image<I>& ima, const Neighborhood<N>& nbh);
00109
00110
00111
00112 # ifndef MLN_INCLUDE_ONLY
00113
00114 template <typename E>
00115 inline
00116 Neighborhood<E>::Neighborhood()
00117 {
00118 typedef mln_niter(E) niter;
00119 typedef mln_fwd_niter(E) fwd_niter;
00120 typedef mln_bkd_niter(E) bkd_niter;
00121
00122 typedef mln_window(E) window;
00123 bool m = (& E::win) == (& E::win);
00124 m = 0;
00125 bool (E::*m2)() const = &E::is_valid;
00126 m2 = 0;
00127
00128 # if 0
00129
00130
00131
00132 const window& (E::*m1)() const = & E::win;
00133 m = m1;
00134 # endif
00135 }
00136
00137
00138 template <typename L, typename R>
00139 inline
00140 bool operator==(const Neighborhood<L>& lhs, const Neighborhood<R>& rhs)
00141 {
00142 return exact(lhs).win() == exact(rhs).win();
00143 }
00144
00145 template <typename N>
00146 inline
00147 std::ostream&
00148 operator<<(std::ostream&ostr, const Neighborhood<N>& nbh)
00149 {
00150 return ostr << exact(nbh).win();
00151 }
00152
00153 template <typename I, typename N>
00154 inline
00155 util::array<int>
00156 offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_)
00157 {
00158 mln_is_simple_neighborhood(N)::check();
00159
00160 const I& ima = exact(ima_);
00161 const N& nbh = exact(nbh_);
00162 mln_precondition(ima.is_valid());
00163 mln_precondition(nbh.is_valid());
00164
00165 return offsets_wrt(ima, nbh.win());
00166 }
00167
00168 template <typename I, typename N>
00169 util::array<int>
00170 positive_offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_)
00171 {
00172 mln_is_simple_neighborhood(N)::check();
00173
00174 const I& ima = exact(ima_);
00175 const N& nbh = exact(nbh_);
00176 mln_precondition(ima.is_valid());
00177 mln_precondition(nbh.is_valid());
00178
00179 return positive_offsets_wrt(ima, nbh.win());
00180 }
00181
00182 template <typename I, typename N>
00183 util::array<int>
00184 negative_offsets_wrt(const Image<I>& ima_, const Neighborhood<N>& nbh_)
00185 {
00186 mln_is_simple_neighborhood(N)::check();
00187
00188 const I& ima = exact(ima_);
00189 const N& nbh = exact(nbh_);
00190 mln_precondition(ima.is_valid());
00191 mln_precondition(nbh.is_valid());
00192
00193 return negative_offsets_wrt(ima, nbh.win());
00194 }
00195
00196 # endif // ! MLN_INCLUDE_ONLY
00197
00198 }
00199
00200
00201 #endif // ! MLN_CORE_CONCEPT_NEIGHBORHOOD_HH