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_ABSTRACT_IMAGE_WITH_DIM_HH
00029 # define OLENA_CORE_ABSTRACT_IMAGE_WITH_DIM_HH
00030
00031 # include <mlc/contract.hh>
00032 # include <oln/core/abstract/image.hh>
00033 # include <oln/core/coord.hh>
00034 # include <oln/core/point1d.hh>
00035 # include <oln/core/image1d_size.hh>
00036 # include <oln/core/point2d.hh>
00037 # include <oln/core/image2d_size.hh>
00038 # include <oln/core/point3d.hh>
00039 # include <oln/core/image3d_size.hh>
00040
00041 # include <cstdlib>
00042
00043
00044
00045 namespace oln {
00046
00047
00048 template<class Exact>
00049 struct fwd_iter1d;
00050 template<class Exact>
00051 struct bkd_iter1d;
00052
00053 template<class Exact>
00054 struct fwd_iter2d;
00055 template<class Exact>
00056 struct bkd_iter2d;
00057
00058 template<class Exact>
00059 struct fwd_iter3d;
00060 template<class Exact>
00061 struct bkd_iter3d;
00062
00063 namespace abstract {
00064
00065
00066 template <unsigned Dim, class Exact>
00067 class image_with_dim;
00068
00069 }
00070
00071
00077 template <class Exact>
00078 struct image_traits<abstract::image_with_dim<1, Exact> >
00079 : public image_traits<abstract::image<Exact> >
00080 {
00081
00082 enum {dim = 1};
00084 typedef point1d point_type;
00086 typedef dpoint1d dpoint_type;
00088 typedef fwd_iter1d<mlc::final> iter_type;
00090 typedef fwd_iter1d<mlc::final> fwd_iter_type;
00092 typedef bkd_iter1d<mlc::final> bkd_iter_type;
00094 typedef image1d_size size_type;
00096 };
00097
00098
00105 template <class Exact>
00106 struct image_traits<abstract::image_with_dim<2, Exact> >
00107 : public image_traits<abstract::image<Exact> >
00108 {
00109 enum {dim = 2};
00111 typedef point2d point_type;
00113 typedef dpoint2d dpoint_type;
00115 typedef fwd_iter2d<mlc::final> iter_type;
00117 typedef fwd_iter2d<mlc::final> fwd_iter_type;
00119 typedef bkd_iter2d<mlc::final> bkd_iter_type;
00121 typedef image2d_size size_type;
00123 };
00124
00130 template <class Exact>
00131 struct image_traits<abstract::image_with_dim<3, Exact> >
00132 : public image_traits<abstract::image<Exact> >
00133 {
00134 enum {dim = 3};
00136 typedef point3d point_type;
00138 typedef dpoint3d dpoint_type;
00140 typedef fwd_iter3d<mlc::final> iter_type;
00142 typedef fwd_iter3d<mlc::final> fwd_iter_type;
00144 typedef bkd_iter3d<mlc::final> bkd_iter_type;
00146 typedef image3d_size size_type;
00148 };
00149
00150
00151 namespace abstract {
00152
00153
00155 template <class Exact>
00156 class image_with_dim<1, Exact>: virtual public image<Exact>
00157 {
00158 public:
00159 typedef typename image_traits<Exact>::point_type point_type;
00165 typedef typename image_traits<Exact>::point_type dpoint_type;
00171 typedef typename image_traits<Exact>::iter_type iter_type;
00177 typedef typename image_traits<Exact>::fwd_iter_type fwd_iter_type;
00179 typedef typename image_traits<Exact>::bkd_iter_type bkd_iter_type;
00181 typedef typename image_traits<Exact>::value_type value_type;
00185 typedef typename image_traits<Exact>::size_type size_type;
00191 typedef image<Exact> super_type;
00192 typedef image_with_dim<1, Exact> self_type;
00193 typedef Exact exact_type;
00194
00195 friend class image<exact_type>;
00196
00197
00199
00200 coord
00201 ncols() const
00202 {
00203 return this->size().ncols();
00204 }
00205
00210 const value_type
00211 operator()(coord col) const
00212 {
00213 return this->exact()[point_type(col)];
00214 }
00215
00220 value_type&
00221 operator()(coord col)
00222 {
00223 return this->exact()[point_type(col)];
00224 }
00225
00226 using super_type::hold;
00227
00235 bool
00236 hold(coord col) const
00237 {
00238 return hold(point_type(col));
00239 }
00240
00248 exact_type&
00249 operator=(self_type rhs)
00250 {
00251 return this->exact().assign(rhs.exact());
00252 }
00253
00254 static std::string
00255 name()
00256 {
00257 return
00258 std::string("abstract::image_with_dim<")
00259 + self_type::Dim + ","
00260 + Exact::name() + ">";
00261 }
00262
00263 protected:
00264
00266 size_t
00267 npoints_() const
00268 {
00269 return size_t(ncols());
00270 }
00271
00272 image_with_dim() : super_type()
00273 {}
00274
00275 };
00276
00277
00278
00280 template <class Exact>
00281 class image_with_dim<2, Exact>: virtual public image<Exact>
00282 {
00283 public:
00284
00285 typedef typename image_traits<Exact>::point_type point_type;
00291 typedef typename image_traits<Exact>::point_type dpoint_type;
00297 typedef typename image_traits<Exact>::iter_type iter_type;
00303 typedef typename image_traits<Exact>::fwd_iter_type fwd_iter_type;
00305 typedef typename image_traits<Exact>::bkd_iter_type bkd_iter_type;
00307 typedef typename image_traits<Exact>::value_type value_type;
00311 typedef typename image_traits<Exact>::size_type size_type;
00317 typedef image<Exact> super_type;
00318 typedef image_with_dim<2, Exact> self_type;
00319 typedef Exact exact_type;
00320
00321 friend class image<exact_type>;
00322
00323
00325 coord
00326 nrows() const
00327 {
00328 return this->exact().size().nrows();
00329 }
00330
00331
00333
00334 coord
00335 ncols() const
00336 {
00337 return this->exact().size().ncols();
00338 }
00339
00344 const value_type
00345 operator()(coord row, coord col) const
00346 {
00347 return this->exact()[point_type(row, col)];
00348 }
00349
00354 value_type&
00355 operator()(coord row, coord col)
00356 {
00357 return this->exact()[point_type(row, col)];
00358 }
00359
00360 using super_type::hold;
00361
00371 bool
00372 hold(coord row, coord col) const
00373 {
00374 return hold(point_type(row, col));
00375 }
00376
00385 exact_type&
00386 operator=(self_type rhs)
00387 {
00388 return this->exact().assign(rhs.exact());
00389 }
00390
00391 static std::string
00392 name()
00393 {
00394 return
00395 std::string("abstract::image_with_dim<")
00396 + self_type::Dim + ","
00397 + Exact::name() + ">";
00398 }
00399
00400 protected:
00401
00402
00404
00405 size_t
00406 npoints_() const
00407 {
00408 return size_t(nrows()) * size_t(ncols());
00409 }
00410
00411 image_with_dim() : super_type()
00412 {}
00413
00414 };
00415
00416
00418
00419 template <class Exact>
00420 class image_with_dim<3, Exact>: virtual public image<Exact>
00421 {
00422 public:
00423 typedef typename image_traits<Exact>::point_type point_type;
00429 typedef typename image_traits<Exact>::point_type dpoint_type;
00435 typedef typename image_traits<Exact>::iter_type iter_type;
00441 typedef typename image_traits<Exact>::fwd_iter_type fwd_iter_type;
00443 typedef typename image_traits<Exact>::bkd_iter_type bkd_iter_type;
00445 typedef typename image_traits<Exact>::value_type value_type;
00449 typedef typename image_traits<Exact>::size_type size_type;
00455 typedef image<Exact> super_type;
00456 typedef image_with_dim<3, Exact> self_type;
00457 typedef Exact exact_type;
00458
00459 friend class image<exact_type>;
00460
00461
00462
00464
00465 coord
00466 nslices() const
00467 {
00468 return this->size().nslices();
00469 }
00470
00471
00473
00474 coord
00475 nrows() const
00476 {
00477 return this->size().nrows();
00478 }
00479
00481
00482 coord
00483 ncols() const
00484 {
00485 return this->size().ncols();
00486 }
00487
00492 const value_type
00493 operator()(coord slice, coord row, coord col) const
00494 {
00495 return this->exact()[point_type(slice, row, col)];
00496 }
00497
00503 value_type&
00504 operator()(coord slice, coord row, coord col)
00505 {
00506 return this->exact()[point_type(slice, row, col)];
00507 }
00508
00509 using super_type::hold;
00510
00522 bool
00523 hold(coord slice, coord row, coord col) const
00524 {
00525 return hold(point_type(slice, row, col));
00526 }
00527
00536 exact_type&
00537 operator=(self_type rhs)
00538 {
00539 return this->exact().assign(rhs.exact());
00540 }
00541
00542 static std::string
00543 name()
00544 {
00545 return
00546 std::string("abstract::image_with_dim<")
00547 + self_type::Dim + ","
00548 + Exact::name() + ">";
00549 }
00550
00551 protected:
00552
00553
00554
00556
00557 size_t
00558 npoints_() const
00559 {
00560 return size_t(nslices()) * size_t(nrows()) * size_t(ncols());
00561 }
00562
00563
00564 image_with_dim() : super_type()
00565 {}
00566
00567 };
00568
00569
00570 }
00571 }
00572
00573
00575
00576 template<class Exact>
00577 inline std::ostream&
00578 operator<<(std::ostream& o, const oln::abstract::image_with_dim<1, Exact>& ima)
00579 {
00580 if (ima.exact().impl() == 0)
00581 return o << "null";
00582 for (oln::coord col = 0; col < ima.ncols(); ++col)
00583 o << ima(col) << ' ';
00584 o << std::endl;
00585 return o;
00586 }
00587
00588
00590
00591 template<class Exact>
00592 inline std::ostream&
00593 operator<<(std::ostream& o, const oln::abstract::image_with_dim<2, Exact>& ima)
00594 {
00595 typedef typename oln::image_id<Exact>::value_type value_type;
00596 if (ima.exact().impl() == 0)
00597 return o << "null";
00598
00599 for (oln::coord row = 0; row < ima.nrows(); ++row)
00600 {
00601 for (oln::coord col = 0; col < ima.ncols(); ++col)
00602 {
00603 o.width(ntg_max_print_width(value_type));
00604 o << ima(row,col) << ' ';
00605 }
00606 o << std::endl;
00607 }
00608 return o;
00609 }
00610
00612
00613 template<class Exact>
00614 inline std::ostream&
00615 operator<<(std::ostream& o, const oln::abstract::image_with_dim<3, Exact>& ima)
00616 {
00617 typedef typename oln::image_id<Exact>::value_type value_type;
00618
00619 if (ima.exact().impl() == 0)
00620 return o << "null";
00621 for (oln::coord slice = 0; slice < ima.nslices(); ++slice) {
00622 o << "### " << slice << std::endl;
00623 for (oln::coord row = 0; row < ima.nrows(); ++row) {
00624 for (oln::coord col = 0; col < ima.ncols(); ++col)
00625 {
00626 o.width(ntg_max_print_width(value_type));
00627 o << ima(slice, row, col) << ' ';
00628 }
00629 o << std::endl;
00630 }
00631 }
00632 return o;
00633 }
00634
00635 #endif // ! OLENA_CORE_ABSTRACT_IMAGE_WITH_DIM_HH