27 #ifndef MLN_CORE_IMAGE_IMAGE2D_HH
28 # define MLN_CORE_IMAGE_IMAGE2D_HH
35 # include <mln/core/internal/image_primary.hh>
36 # include <mln/core/internal/fixme.hh>
37 # include <mln/core/alias/box2d.hh>
38 # include <mln/core/routine/init.hh>
40 # include <mln/border/thickness.hh>
41 # include <mln/value/set.hh>
42 # include <mln/fun/i2v/all_to.hh>
59 template <
typename T>
class image2d;
71 data(
const box2d& b,
unsigned bdr);
84 void swap_(
data< image2d<T> >& other_);
85 void reallocate_(
unsigned new_border);
94 struct image_<
image2d<
T> > : default_image_< T, image2d<T> >
97 typedef trait::image::category::primary
category;
98 typedef trait::image::speed::fastest
speed;
99 typedef trait::image::size::regular
size;
102 typedef trait::image::vw_io::none
vw_io;
103 typedef trait::image::vw_set::none
vw_set;
104 typedef trait::image::value_access::direct
value_access;
105 typedef trait::image::value_storage::one_block
value_storage;
106 typedef trait::image::value_browsing::site_wise_only
value_browsing;
108 typedef trait::image::value_io::read_write
value_io;
111 typedef trait::image::pw_io::read_write
pw_io;
112 typedef trait::image::localization::basic_grid
localization;
113 typedef trait::image::dimension::two_d
dimension;
116 typedef trait::image::ext_domain::extendable
ext_domain;
117 typedef trait::image::ext_value::multiple
ext_value;
118 typedef trait::image::ext_io::read_write
ext_io;
133 template <
typename T>
190 template <
typename P>
194 mln_precondition(this->
has(p));
200 return this->
data_->array_ [*(coord_t*)(&p.p_hook_())] [*((coord_t*)(&p.p_hook_()) + 1)];
217 unsigned nrows()
const;
220 unsigned ncols()
const;
227 using super_::offset_of_point;
256 void resize_(
unsigned new_border);
266 template <
typename T>
267 void init_(tag::border_t,
unsigned& bdr,
const image2d<T>& model);
269 template <
typename T,
typename J>
275 # ifndef MLN_INCLUDE_ONLY
279 template <
typename T>
281 void init_(tag::border_t,
unsigned& bdr,
const image2d<T>& model)
283 bdr = model.border();
286 template <
typename T,
typename J>
288 void init_(tag::image_t, image2d<T>& target,
const J& model)
294 target.init_(b, bdr);
302 template <
typename T>
313 template <
typename T>
320 template <
typename T>
325 vb_.pmin() = b_.pmin() - dpoint2d(
all_to(bdr_));
326 vb_.pmax() = b_.pmax() + dpoint2d(
all_to(bdr_));
329 template <
typename T>
338 buffer_ =
new T[nr * nc];
340 T* buf = buffer_ - vb_.pmin().col();
341 for (
unsigned i = 0; i < nr; ++i)
346 array_ -= vb_.pmin().row();
347 mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
348 mln_postcondition(vb_.len(1) == b_.len(1) + 2 * bdr_);
351 template <
typename T>
363 array_ += vb_.pmin().row();
369 template <
typename T>
379 template <
typename T>
394 template <
typename T>
396 image2d<T>::image2d()
400 template <
typename T>
402 image2d<T>::image2d(
int nrows,
int ncols,
unsigned bdr)
404 init_(make::box2d(nrows, ncols), bdr);
407 template <
typename T>
409 image2d<T>::image2d(
const box2d& b,
unsigned bdr)
414 template <
typename T>
417 image2d<T>::init_(
const box2d& b,
unsigned bdr)
419 mln_precondition(! this->is_valid());
420 this->data_ =
new internal::data< image2d<T> >(b, bdr);
423 template <
typename T>
426 image2d<T>::domain()
const
428 mln_precondition(this->is_valid());
429 return this->data_->b_;
432 template <
typename T>
437 mln_precondition(this->is_valid());
438 return this->data_->b_;
441 template <
typename T>
444 image2d<T>::vbbox()
const
446 mln_precondition(this->is_valid());
447 return this->data_->vb_;
450 template <
typename T>
453 image2d<T>::has(
const point2d& p)
const
455 mln_precondition(this->is_valid());
456 return this->data_->vb_.has(p);
459 template <
typename T>
462 image2d<T>::operator()(
const point2d& p)
const
464 mln_precondition(this->
has(p));
465 return this->data_->array_[p.row()][p.col()];
468 template <
typename T>
471 image2d<T>::operator()(
const point2d& p)
473 mln_precondition(this->
has(p));
474 return this->data_->array_[p.row()][p.col()];
480 template <
typename T>
485 mln_precondition(this->
has(
point2d(row, col)));
486 return this->data_->array_[row][col];
489 template <
typename T>
494 mln_precondition(this->
has(
point2d(row, col)));
495 return this->data_->array_[row][col];
498 template <
typename T>
503 mln_precondition(this->is_valid());
504 return this->data_->b_.len(0);
507 template <
typename T>
512 mln_precondition(this->is_valid());
513 return this->data_->b_.len(1);
519 template <
typename T>
522 image2d<T>::border()
const
524 mln_precondition(this->is_valid());
525 return this->data_->bdr_;
528 template <
typename T>
531 image2d<T>::nelements()
const
533 mln_precondition(this->is_valid());
534 return this->data_->vb_.nsites();
537 template <
typename T>
540 image2d<T>::element(
unsigned i)
const
543 return *(this->data_->buffer_ + i);
546 template <
typename T>
549 image2d<T>::element(
unsigned i)
552 return *(this->data_->buffer_ + i);
555 template <
typename T>
558 image2d<T>::buffer()
const
560 mln_precondition(this->is_valid());
561 return this->data_->buffer_;
564 template <
typename T>
569 mln_precondition(this->is_valid());
570 return this->data_->buffer_;
573 template <
typename T>
576 image2d<T>::delta_offset(
const dpoint2d& dp)
const
578 mln_precondition(this->is_valid());
579 int o = dp[0] * this->data_->vb_.len(1) + dp[1];
583 template <
typename T>
586 image2d<T>::point_at_offset(
unsigned i)
const
590 row =
static_cast<def::coord
>(i / this->data_->vb_.len(1) + this->data_->vb_.min_row()),
591 col = static_cast<def::coord>(i % this->data_->vb_.len(1) + this->data_->vb_.min_col());
593 mln_postcondition(& this->
operator()(p) == this->data_->buffer_ + i);
599 template <
typename T>
602 image2d<T>::resize_(
unsigned new_border)
604 mln_precondition(this->is_valid());
605 this->data_->reallocate_(new_border);
608 # endif // ! MLN_INCLUDE_ONLY
614 # include <mln/core/trait/pixter.hh>
615 # include <mln/core/dpoints_pixter.hh>
616 # include <mln/core/pixter2d.hh>
628 template <
typename T>
634 template <
typename T>
640 template <
typename T>
646 template <
typename T>
647 struct bkd_pixter< const
image2d<
T> >
654 template <
typename T,
typename W>
660 template <
typename T,
typename W>
666 template <
typename T,
typename W>
672 template <
typename T,
typename W>
673 struct bkd_qixter< const
image2d<
T>, W >
680 template <
typename T,
typename N>
686 template <
typename T,
typename N>
692 template <
typename T,
typename N>
698 template <
typename T,
typename N>
699 struct bkd_nixter< const
image2d<
T>, N >
709 # include <mln/make/image.hh>
710 # include <mln/make/image2d.hh>
713 #endif // ! MLN_CORE_IMAGE_IMAGE2D_HH