27 #ifndef MLN_CORE_IMAGE_IMAGE3D_HH
28 # define MLN_CORE_IMAGE_IMAGE3D_HH
34 # include <mln/core/internal/fixme.hh>
35 # include <mln/core/internal/image_primary.hh>
36 # include <mln/core/alias/box3d.hh>
38 # include <mln/border/thickness.hh>
39 # include <mln/value/set.hh>
40 # include <mln/fun/i2v/all_to.hh>
54 template <
typename T>
struct image3d;
78 void swap_ (
data< image3d<T> >& other_);
79 void reallocate_(
unsigned new_border);
90 struct image_<
image3d<T> > : default_image_< T, image3d<T> >
93 typedef trait::image::category::primary category;
94 typedef trait::image::speed::fastest speed;
95 typedef trait::image::size::regular size;
98 typedef trait::image::vw_io::none vw_io;
99 typedef trait::image::vw_set::none vw_set;
100 typedef trait::image::value_access::direct value_access;
101 typedef trait::image::value_storage::one_block value_storage;
102 typedef trait::image::value_browsing::site_wise_only value_browsing;
103 typedef trait::image::value_alignment::with_grid value_alignment;
104 typedef trait::image::value_io::read_write value_io;
107 typedef trait::image::pw_io::read_write pw_io;
108 typedef trait::image::localization::basic_grid localization;
109 typedef trait::image::dimension::three_d dimension;
112 typedef trait::image::ext_domain::extendable ext_domain;
113 typedef trait::image::ext_value::multiple ext_value;
114 typedef trait::image::ext_io::read_write ext_io;
129 template <
typename T>
130 struct image3d :
public internal::image_primary< T, box3d, image3d<T> >
137 typedef mln_fwd_piter(
box3d) fwd_piter;
138 typedef mln_bkd_piter(
box3d) bkd_piter;
144 typedef internal::image_primary< T, box3d, image3d<T> > super_;
164 image3d(
const box3d& b,
unsigned bdr = border::thickness);
172 void init_(
const box3d& b,
unsigned bdr = border::thickness);
200 const T&
element(
unsigned i)
const;
215 unsigned nslis()
const;
218 unsigned nrows()
const;
221 unsigned ncols()
const;
244 void resize_(
unsigned new_border);
248 template <
typename T,
typename J>
253 # ifndef MLN_INCLUDE_ONLY
257 template <
typename T>
259 void init_(tag::border_t,
unsigned& b,
const image3d<T>& model)
264 template <
typename T,
typename J>
266 void init_(tag::image_t, image3d<T>& target,
const J& model)
269 init_(tag::bbox, b, model);
271 init_(tag::border, bdr, model);
272 target.init_(b, bdr);
281 template <
typename T>
292 template <
typename T>
299 template <
typename T>
304 vb_.pmin() = b_.pmin() -
dpoint3d(all_to(bdr_));
305 vb_.pmax() = b_.pmax() +
dpoint3d(all_to(bdr_));
308 template <
typename T>
318 buffer_ =
new T[nr * nc * ns];
319 array_ =
new T**[ns];
320 T* buf = buffer_ - vb_.pmin().col();
321 for (
unsigned i = 0; i < ns; ++i)
323 T** tmp =
new T*[nr];
325 for (
unsigned j = 0; j < nr; ++j)
330 array_[i] -= vb_.pmin().row();
332 array_ -= vb_.pmin().sli();
333 mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
336 template <
typename T>
346 for (
typename point3d::coord i = vb_.pmin().sli(); i <= vb_.pmax().sli(); ++i)
350 array_[i] += vb_.pmin().row();
357 array_ += vb_.pmin().sli();
363 template <
typename T>
373 template <
typename T>
387 template <
typename T>
393 template <
typename T>
400 template <
typename T>
404 init_(make::box3d(nslis, nrows, ncols), bdr);
407 template <
typename T>
412 mln_precondition(! this->is_valid());
413 this->data_ =
new internal::data< image3d<T> >(b, bdr);
416 template <
typename T>
421 mln_precondition(this->is_valid());
425 template <
typename T>
430 mln_precondition(this->is_valid());
434 template <
typename T>
439 mln_precondition(this->is_valid());
443 template <
typename T>
448 mln_precondition(this->is_valid());
452 template <
typename T>
457 mln_precondition(this->is_valid());
458 return data_->vb_.nsites();
461 template <
typename T>
466 mln_precondition(this->is_valid());
467 return data_->vb_.has(p);
470 template <
typename T>
475 mln_precondition(this->has(p));
476 return data_->array_[p.sli()][p.row()][p.col()];
479 template <
typename T>
484 mln_precondition(this->has(p));
485 return data_->array_[p.sli()][p.row()][p.col()];
488 template <
typename T>
493 mln_precondition(i < nelements());
494 return *(data_->buffer_ + i);
497 template <
typename T>
502 mln_precondition(i < nelements());
503 return *(data_->buffer_ + i);
506 template <
typename T>
511 mln_precondition(this->has(
point3d(sli, row, col)));
512 return data_->array_[sli][row][col];
515 template <
typename T>
518 image3d<T>::at_(def::coord sli, def::coord row, def::coord col)
520 mln_precondition(this->has(point3d(sli, row, col)));
521 return data_->array_[sli][row][col];
524 template <
typename T>
529 mln_precondition(this->is_valid());
530 return this->data_->b_.len(0);
533 template <
typename T>
538 mln_precondition(this->is_valid());
539 return this->data_->b_.len(1);
542 template <
typename T>
547 mln_precondition(this->is_valid());
548 return this->data_->b_.len(2);
551 template <
typename T>
556 mln_precondition(this->is_valid());
557 return data_->buffer_;
560 template <
typename T>
565 mln_precondition(this->is_valid());
566 return data_->buffer_;
569 template <
typename T>
574 mln_precondition(this->is_valid());
575 int o = (dp[0] * this->data_->vb_.len(1)
576 + dp[1]) * this->data_->vb_.len(2) + dp[2];
580 template <
typename T>
585 mln_precondition(o < nelements());
587 sli =
static_cast<def::coord>(o / (data_->vb_.len(1) * data_->vb_.len(2)) + data_->vb_.min_sli()),
588 row = static_cast<def::coord>((o % (data_->vb_.len(1) * data_->vb_.len(2))) / data_->vb_.len(2) + data_->vb_.min_row()),
589 col = static_cast<def::coord>(o % data_->vb_.len(2) + data_->vb_.min_col());
591 mln_postcondition(& this->
operator()(p) == this->data_->buffer_ + o);
595 template <
typename T>
600 this->data_->reallocate_(new_border);
603 # endif // ! MLN_INCLUDE_ONLY
609 # include <mln/core/trait/pixter.hh>
610 # include <mln/core/dpoints_pixter.hh>
611 # include <mln/core/pixter3d.hh>
612 # include <mln/core/w_window.hh>
623 template <
typename T>
624 struct fwd_pixter<
image3d<T> >
626 typedef fwd_pixter3d< image3d<T> > ret;
629 template <
typename T>
630 struct fwd_pixter< const
image3d<T> >
632 typedef fwd_pixter3d< const image3d<T> > ret;
635 template <
typename T>
636 struct bkd_pixter<
image3d<T> >
638 typedef bkd_pixter3d< image3d<T> > ret;
641 template <
typename T>
642 struct bkd_pixter< const
image3d<T> >
644 typedef bkd_pixter3d< const image3d<T> > ret;
649 template <
typename T,
typename W>
650 struct fwd_qixter<
image3d<T>, W >
652 typedef dpoints_fwd_pixter< image3d<T> > ret;
655 template <
typename T,
typename W>
656 struct fwd_qixter< const
image3d<T>, W >
658 typedef dpoints_fwd_pixter< const image3d<T> > ret;
661 template <
typename T,
typename W>
662 struct bkd_qixter<
image3d<T>, W >
664 typedef dpoints_bkd_pixter< image3d<T> > ret;
667 template <
typename T,
typename W>
668 struct bkd_qixter< const
image3d<T>, W >
670 typedef dpoints_bkd_pixter< const image3d<T> > ret;
675 template <
typename T,
typename W>
676 struct fwd_nixter<
image3d<T>, W >
678 typedef dpoints_fwd_pixter< image3d<T> > ret;
681 template <
typename T,
typename W>
682 struct fwd_nixter< const
image3d<T>, W >
684 typedef dpoints_fwd_pixter< const image3d<T> > ret;
687 template <
typename T,
typename W>
688 struct bkd_nixter<
image3d<T>, W >
690 typedef dpoints_bkd_pixter< image3d<T> > ret;
693 template <
typename T,
typename W>
694 struct bkd_nixter< const
image3d<T>, W >
696 typedef dpoints_bkd_pixter< const image3d<T> > ret;
704 #endif // ! MLN_CORE_IMAGE_IMAGE3D_HH