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
00028 #ifndef OLENA_CORE_NEIGHBORHOOD3D_HH
00029 # define OLENA_CORE_NEIGHBORHOOD3D_HH
00030
00031 # include <oln/core/abstract/neighborhoodnd.hh>
00032 # include <oln/core/winiter.hh>
00033 # include <oln/core/accum.hh>
00034 # include <oln/core/window3d.hh>
00035 # include <algorithm>
00036
00037 namespace oln {
00038
00039 class neighborhood3d;
00040
00044 template<>
00045 struct struct_elt_traits<neighborhood3d>: public
00046 struct_elt_traits<abstract::neighborhoodnd<neighborhood3d> >
00047 {
00048 enum { dim = 3 };
00049 typedef point3d point_type;
00050 typedef dpoint3d dpoint_type;
00051 typedef winiter< neighborhood3d > iter_type;
00052 typedef winneighb< neighborhood3d > neighb_type;
00053 typedef window3d win_type;
00054 };
00055
00064 class neighborhood3d :
00065 public abstract::neighborhoodnd< neighborhood3d >
00066 {
00067 public:
00068
00069 typedef abstract::neighborhoodnd< neighborhood3d > super_type;
00071 typedef neighborhood3d self_type;
00072
00078 typedef struct_elt_traits< self_type >::iter_type iter_type;
00079 typedef struct_elt_traits< self_type >::neighb_type neighb_type;
00080
00086 typedef struct_elt_traits< self_type >::dpoint_type dpoint_type;
00087
00088 friend class abstract::window_base<abstract::neighborhood<neighborhood3d>, neighborhood3d>;
00089
00097 neighborhood3d&
00098 add(const dpoint_type& dp)
00099 {
00100 this->exact().add_(dp);
00101 return this->exact().add_(-dp);
00102 }
00103
00113 neighborhood3d&
00114 add(coord slice, coord row, coord col)
00115 {
00116 return this->add(dpoint3d(slice, row, col));
00117 }
00118
00122 neighborhood3d() : super_type()
00123 {}
00124
00129 neighborhood3d(unsigned size) : super_type(size)
00130 {}
00131
00137 neighborhood3d(unsigned n, const coord crd[]) : super_type()
00138 {
00139 for (unsigned i = 0; i < 3 * n; i += 3)
00140 add(dpoint_type(crd[i], crd[i+1], crd[i+2]));
00141 }
00142
00144 static std::string
00145 name()
00146 {
00147 return std::string("neighborhood3d");
00148 }
00149
00150 protected:
00151
00160 coord
00161 delta_update_(const dpoint_type& dp)
00162 {
00163 delta_(abs(dp.slice()));
00164 delta_(abs(dp.row()));
00165 delta_(abs(dp.col()));
00166 return delta_;
00167 }
00168
00169 };
00170
00171
00172
00177 inline const neighborhood3d&
00178 neighb_c6()
00179 {
00180 static const coord crd[] = { 0, 0, 1,
00181 0, 1, 0,
00182 1, 0, 0};
00183 static const neighborhood3d neighb(3, crd);
00184 return neighb;
00185 }
00186
00191 inline const neighborhood3d&
00192 neighb_c18()
00193 {
00194 static const coord crd[] = { 0, 0, 1,
00195 0, 1, -1,
00196 0, 1, 0,
00197 0, 1, 1,
00198 1, -1, 0,
00199 1, 0, -1,
00200 1, 0, 0,
00201 1, 0, 1,
00202 1, 1, 0 };
00203 static neighborhood3d neighb(9, crd);
00204 return neighb;
00205 }
00206
00211 inline const neighborhood3d&
00212 neighb_c26()
00213 {
00214 static const coord crd[] = { 0, 0, 1,
00215 0, 1, -1,
00216 0, 1, 0,
00217 0, 1, 1,
00218 1, -1, -1,
00219 1, -1, 0,
00220 1, -1, 1,
00221 1, 0, -1,
00222 1, 0, 0,
00223 1, 0, 1,
00224 1, 1, -1,
00225 1, 1, 0,
00226 1, 1, 1 };
00227 static neighborhood3d neighb(13, crd);
00228 return neighb;
00229 }
00230
00231
00232
00246 inline neighborhood3d
00247 mk_neighb_block(unsigned nslices, unsigned nrows, unsigned ncols)
00248 {
00249 precondition(nslices >= 3 && (nslices % 2) == 1);
00250 precondition(nrows >= 3 && (nrows % 2) == 1);
00251 precondition(ncols >= 3 && (ncols % 2) == 1);
00252 neighborhood3d neighb(nrows * ncols);
00253 int half_nslices = nslices / 2;
00254 int half_nrows = nrows / 2;
00255 int half_ncols = ncols / 2;
00256 for (coord slice = - half_nslices; slice <= half_nslices; ++slice)
00257 for (coord row = - half_nrows; row <= half_nrows; ++row)
00258 for (coord col = (slice > 0) ? 0 : 1 ; col <= half_ncols; ++col)
00259 neighb.add(slice, row, col);
00260 return neighb;
00261 }
00262
00268 inline neighborhood3d
00269 mk_neighb_cube(unsigned width)
00270 {
00271 return mk_neighb_block(width, width, width);
00272 }
00273
00279 inline window3d
00280 mk_win_from_neighb(const neighborhood3d& n)
00281 {
00282 window3d win(n.card());
00283 for (unsigned i = 0; i < n.card(); ++i)
00284 win.add(n.dp(i));
00285 return win;
00286 }
00287
00288 }
00289
00290 #endif // OLENA_CORE_NEIGHBORHOOD3D_HH