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;
68 data(
const box3d& b,
unsigned bdr);
81 void swap_ (
data< image3d<T> >& other_);
82 void reallocate_(
unsigned new_border);
93 struct image_<
image3d<
T> > : default_image_< T, image3d<T> >
96 typedef trait::image::category::primary
category;
97 typedef trait::image::speed::fastest
speed;
98 typedef trait::image::size::regular
size;
101 typedef trait::image::vw_io::none
vw_io;
102 typedef trait::image::vw_set::none
vw_set;
103 typedef trait::image::value_access::direct
value_access;
104 typedef trait::image::value_storage::one_block
value_storage;
105 typedef trait::image::value_browsing::site_wise_only
value_browsing;
107 typedef trait::image::value_io::read_write
value_io;
110 typedef trait::image::pw_io::read_write
pw_io;
111 typedef trait::image::localization::basic_grid
localization;
112 typedef trait::image::dimension::three_d
dimension;
115 typedef trait::image::ext_domain::extendable
ext_domain;
116 typedef trait::image::ext_value::multiple
ext_value;
117 typedef trait::image::ext_io::read_write
ext_io;
132 template <
typename T>
176 void init_(const box3d& b,
unsigned bdr =
border::thickness);
184 const box3d&
domain() const;
187 const box3d&
bbox() const;
190 const box3d&
vbbox() const;
199 const T& operator()(const
point3d&
p) const;
205 const T&
element(
unsigned i) const;
223 unsigned nslis() const;
226 unsigned nrows() const;
229 unsigned ncols() const;
253 void resize_(
unsigned new_border);
259 template <typename T, typename J>
260 void init_(tag::image_t, mln::
image3d<T>& target, const J& model);
264 # ifndef MLN_INCLUDE_ONLY
268 template <
typename T>
275 template <
typename T,
typename J>
283 target.
init_(b, bdr);
292 template <
typename T>
303 template <
typename T>
310 template <
typename T>
315 vb_.pmin() = b_.pmin() - dpoint3d(
all_to(bdr_));
316 vb_.pmax() = b_.pmax() + dpoint3d(
all_to(bdr_));
319 template <
typename T>
329 buffer_ =
new T[nr * nc * ns];
330 array_ =
new T**[ns];
331 T* buf = buffer_ - vb_.pmin().col();
332 for (
unsigned i = 0; i < ns; ++i)
334 T** tmp =
new T*[nr];
336 for (
unsigned j = 0; j < nr; ++j)
341 array_[i] -= vb_.pmin().row();
343 array_ -= vb_.pmin().sli();
344 mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
347 template <
typename T>
357 for (
typename point3d::coord i = vb_.pmin().sli(); i <= vb_.pmax().sli(); ++i)
361 array_[i] += vb_.pmin().row();
368 array_ += vb_.pmin().sli();
374 template <
typename T>
384 template <
typename T>
398 template <
typename T>
400 image3d<T>::image3d()
404 template <
typename T>
406 image3d<T>::image3d(
const box3d& b,
unsigned bdr)
411 template <
typename T>
413 image3d<T>::image3d(
int nslis,
int nrows,
int ncols,
unsigned bdr)
415 init_(make::box3d(nslis, nrows, ncols), bdr);
418 template <
typename T>
421 image3d<T>::init_(
const box3d& b,
unsigned bdr)
423 mln_precondition(! this->is_valid());
424 this->data_ =
new internal::data< image3d<T> >(b, bdr);
427 template <
typename T>
430 image3d<T>::domain()
const
432 mln_precondition(this->is_valid());
436 template <
typename T>
441 mln_precondition(this->is_valid());
445 template <
typename T>
448 image3d<T>::vbbox()
const
450 mln_precondition(this->is_valid());
454 template <
typename T>
457 image3d<T>::border()
const
459 mln_precondition(this->is_valid());
463 template <
typename T>
466 image3d<T>::nelements()
const
468 mln_precondition(this->is_valid());
469 return data_->vb_.nsites();
472 template <
typename T>
475 image3d<T>::has(
const point3d& p)
const
477 mln_precondition(this->is_valid());
478 return data_->vb_.has(p);
481 template <
typename T>
484 image3d<T>::operator()(
const point3d& p)
const
486 mln_precondition(this->
has(p));
487 return data_->array_[p.sli()][p.row()][p.col()];
490 template <
typename T>
493 image3d<T>::operator()(
const point3d& p)
495 mln_precondition(this->
has(p));
496 return data_->array_[p.sli()][p.row()][p.col()];
499 template <
typename T>
502 image3d<T>::element(
unsigned i)
const
505 return *(data_->buffer_ + i);
508 template <
typename T>
511 image3d<T>::element(
unsigned i)
514 return *(data_->buffer_ + i);
517 template <
typename T>
520 image3d<T>::at_(def::coord sli, def::coord row, def::coord col)
const
522 mln_precondition(this->
has(
point3d(sli, row, col)));
523 return data_->array_[sli][row][col];
526 template <
typename T>
529 image3d<T>::at_(def::coord sli, def::coord row, def::coord col)
531 mln_precondition(this->
has(
point3d(sli, row, col)));
532 return data_->array_[sli][row][col];
535 template <
typename T>
540 mln_precondition(this->is_valid());
541 return this->data_->b_.len(0);
544 template <
typename T>
549 mln_precondition(this->is_valid());
550 return this->data_->b_.len(1);
553 template <
typename T>
558 mln_precondition(this->is_valid());
559 return this->data_->b_.len(2);
562 template <
typename T>
565 image3d<T>::buffer()
const
567 mln_precondition(this->is_valid());
568 return data_->buffer_;
571 template <
typename T>
576 mln_precondition(this->is_valid());
577 return data_->buffer_;
580 template <
typename T>
583 image3d<T>::delta_offset(
const dpoint3d& dp)
const
585 mln_precondition(this->is_valid());
586 int o = (dp[0] * this->data_->vb_.len(1)
587 + dp[1]) * this->data_->vb_.len(2) + dp[2];
591 template <
typename T>
594 image3d<T>::point_at_offset(
unsigned o)
const
598 sli =
static_cast<def::coord
>(o / (data_->vb_.len(1) * data_->vb_.len(2)) + data_->vb_.min_sli()),
599 row = static_cast<def::coord>((o % (data_->vb_.len(1) * data_->vb_.len(2))) / data_->vb_.len(2) + data_->vb_.min_row()),
600 col = static_cast<def::coord>(o % data_->vb_.len(2) + data_->vb_.min_col());
602 mln_postcondition(& this->
operator()(p) == this->data_->buffer_ + o);
606 template <
typename T>
609 image3d<T>::resize_(
unsigned new_border)
611 this->data_->reallocate_(new_border);
614 # endif // ! MLN_INCLUDE_ONLY
620 # include <mln/core/trait/pixter.hh>
621 # include <mln/core/dpoints_pixter.hh>
622 # include <mln/core/pixter3d.hh>
623 # include <mln/core/w_window.hh>
634 template <
typename T>
640 template <
typename T>
646 template <
typename T>
647 struct bkd_pixter<
image3d<T> >
652 template <
typename T>
653 struct bkd_pixter< const
image3d<T> >
660 template <
typename T,
typename W>
666 template <
typename T,
typename W>
672 template <
typename T,
typename W>
673 struct bkd_qixter<
image3d<T>, W >
678 template <
typename T,
typename W>
679 struct bkd_qixter< const
image3d<T>, W >
686 template <
typename T,
typename W>
692 template <
typename T,
typename W>
698 template <
typename T,
typename W>
699 struct bkd_nixter<
image3d<T>, W >
704 template <
typename T,
typename W>
705 struct bkd_nixter< const
image3d<T>, W >
715 #endif // ! MLN_CORE_IMAGE_IMAGE3D_HH