27 #ifndef MLN_CORE_IMAGE_IMAGE2D_HH
28 # define MLN_CORE_IMAGE_IMAGE2D_HH
38 # include <mln/core/internal/image_primary.hh>
39 # include <mln/core/internal/fixme.hh>
40 # include <mln/core/alias/box2d.hh>
41 # include <mln/core/routine/init.hh>
43 # include <mln/border/thickness.hh>
44 # include <mln/value/set.hh>
45 # include <mln/fun/i2v/all_to.hh>
62 template <
typename T>
class image2d;
85 void swap_(
data< image2d<T> >& other_);
86 void reallocate_(
unsigned new_border);
96 struct image_<
image2d<T> > : default_image_< T, image2d<T> >
99 typedef trait::image::category::primary category;
100 typedef trait::image::speed::fastest speed;
101 typedef trait::image::size::regular size;
104 typedef trait::image::vw_io::none vw_io;
105 typedef trait::image::vw_set::none vw_set;
106 typedef trait::image::value_access::direct value_access;
107 typedef trait::image::value_storage::one_block value_storage;
108 typedef trait::image::value_browsing::site_wise_only value_browsing;
109 typedef trait::image::value_alignment::with_grid value_alignment;
110 typedef trait::image::value_io::read_write value_io;
113 typedef trait::image::pw_io::read_write pw_io;
114 typedef trait::image::localization::basic_grid localization;
115 typedef trait::image::dimension::two_d dimension;
118 typedef trait::image::ext_domain::extendable ext_domain;
119 typedef trait::image::ext_value::multiple ext_value;
120 typedef trait::image::ext_io::read_write ext_io;
135 template <
typename T>
136 class image2d :
public internal::image_primary< T, mln::box2d, image2d<T> >
138 typedef internal::image_primary< T, mln::box2d, image2d<T> > super_;
164 image2d(
const box2d& b,
unsigned bdr = border::thickness);
168 void init_(
const box2d& b,
unsigned bdr = border::thickness);
181 const box2d& vbbox()
const;
190 template <
typename P>
194 mln_precondition(this->
has(p));
205 return this->data_->array_ [*(coord_t*)(&p.p_hook_())] [*((coord_t*)(&p.p_hook_()) + 1)];
220 unsigned nrows()
const;
223 unsigned ncols()
const;
230 using super_::index_of_point;
239 const T&
element(
unsigned i)
const;
258 void resize_(
unsigned new_border);
265 template <
typename T>
266 void init_(tag::border_t,
unsigned& bdr,
const image2d<T>& model);
268 template <
typename T,
typename J>
273 # ifndef MLN_INCLUDE_ONLY
277 template <
typename T>
279 void init_(tag::border_t,
unsigned& bdr,
const image2d<T>& model)
281 bdr = model.border();
284 template <
typename T,
typename J>
286 void init_(tag::image_t, image2d<T>& target,
const J& model)
289 init_(tag::bbox, b, model);
291 init_(tag::border, bdr, model);
292 target.init_(b, bdr);
300 template <
typename T>
311 template <
typename T>
318 template <
typename T>
323 vb_.pmin() = b_.pmin() -
dpoint2d(all_to(bdr_));
324 vb_.pmax() = b_.pmax() +
dpoint2d(all_to(bdr_));
327 template <
typename T>
336 buffer_ =
new T[nr * nc];
338 T* buf = buffer_ - vb_.pmin().col();
339 for (
unsigned i = 0; i < nr; ++i)
344 array_ -= vb_.pmin().row();
345 mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
346 mln_postcondition(vb_.len(1) == b_.len(1) + 2 * bdr_);
349 template <
typename T>
361 array_ += vb_.pmin().row();
367 template <
typename T>
377 template <
typename T>
392 template <
typename T>
398 template <
typename T>
402 init_(make::box2d(nrows, ncols), bdr);
405 template <
typename T>
412 template <
typename T>
417 mln_precondition(! this->is_valid());
418 this->data_ =
new internal::data< image2d<T> >(b, bdr);
421 template <
typename T>
426 mln_precondition(this->is_valid());
427 return this->data_->b_;
430 template <
typename T>
435 mln_precondition(this->is_valid());
436 return this->data_->b_;
439 template <
typename T>
444 mln_precondition(this->is_valid());
445 return this->data_->vb_;
448 template <
typename T>
453 mln_precondition(this->is_valid());
454 return this->data_->vb_.has(p);
457 template <
typename T>
462 mln_precondition(this->has(p));
463 return this->data_->array_[p.row()][p.col()];
466 template <
typename T>
471 mln_precondition(this->has(p));
472 return this->data_->array_[p.row()][p.col()];
478 template <
typename T>
483 mln_precondition(this->has(
point2d(row, col)));
484 return this->data_->array_[row][col];
487 template <
typename T>
492 mln_precondition(this->has(point2d(row, col)));
493 return this->data_->array_[row][col];
496 template <
typename T>
501 mln_precondition(this->is_valid());
502 return this->data_->b_.len(0);
505 template <
typename T>
510 mln_precondition(this->is_valid());
511 return this->data_->b_.len(1);
517 template <
typename T>
522 mln_precondition(this->is_valid());
523 return this->data_->bdr_;
526 template <
typename T>
531 mln_precondition(this->is_valid());
532 return this->data_->vb_.nsites();
535 template <
typename T>
540 mln_precondition(i < nelements());
541 return *(this->data_->buffer_ + i);
544 template <
typename T>
549 mln_precondition(i < nelements());
550 return *(this->data_->buffer_ + i);
553 template <
typename T>
558 mln_precondition(this->is_valid());
559 return this->data_->buffer_;
562 template <
typename T>
567 mln_precondition(this->is_valid());
568 return this->data_->buffer_;
571 template <
typename T>
576 mln_precondition(this->is_valid());
577 int o = dp[0] * this->data_->vb_.len(1) + dp[1];
581 template <
typename T>
586 mln_precondition(i < nelements());
588 row =
static_cast<def::coord>(i / this->data_->vb_.len(1) + this->data_->vb_.min_row()),
589 col = static_cast<def::coord>(i % this->data_->vb_.len(1) + this->data_->vb_.min_col());
591 mln_postcondition(& this->
operator()(p) == this->data_->buffer_ + i);
597 template <
typename T>
602 mln_precondition(this->is_valid());
603 this->data_->reallocate_(new_border);
606 # endif // ! MLN_INCLUDE_ONLY
612 # include <mln/core/trait/pixter.hh>
613 # include <mln/core/dpoints_pixter.hh>
614 # include <mln/core/pixter2d.hh>
626 template <
typename T>
627 struct fwd_pixter<
image2d<T> >
629 typedef fwd_pixter2d< image2d<T> > ret;
632 template <
typename T>
633 struct fwd_pixter< const
image2d<T> >
635 typedef fwd_pixter2d< const image2d<T> > ret;
638 template <
typename T>
639 struct bkd_pixter<
image2d<T> >
641 typedef bkd_pixter2d< image2d<T> > ret;
644 template <
typename T>
645 struct bkd_pixter< const
image2d<T> >
647 typedef bkd_pixter2d< const image2d<T> > ret;
652 template <
typename T,
typename W>
653 struct fwd_qixter<
image2d<T>, W >
655 typedef dpoints_fwd_pixter< image2d<T> > ret;
658 template <
typename T,
typename W>
659 struct fwd_qixter< const
image2d<T>, W >
661 typedef dpoints_fwd_pixter< const image2d<T> > ret;
664 template <
typename T,
typename W>
665 struct bkd_qixter<
image2d<T>, W >
667 typedef dpoints_bkd_pixter< image2d<T> > ret;
670 template <
typename T,
typename W>
671 struct bkd_qixter< const
image2d<T>, W >
673 typedef dpoints_bkd_pixter< const image2d<T> > ret;
678 template <
typename T,
typename N>
679 struct fwd_nixter<
image2d<T>, N >
681 typedef dpoints_fwd_pixter< image2d<T> > ret;
684 template <
typename T,
typename N>
685 struct fwd_nixter< const
image2d<T>, N >
687 typedef dpoints_fwd_pixter< const image2d<T> > ret;
690 template <
typename T,
typename N>
691 struct bkd_nixter<
image2d<T>, N >
693 typedef dpoints_bkd_pixter< image2d<T> > ret;
696 template <
typename T,
typename N>
697 struct bkd_nixter< const
image2d<T>, N >
699 typedef dpoints_bkd_pixter< const image2d<T> > ret;
707 # include <mln/make/image.hh>
708 # include <mln/make/image2d.hh>
711 #endif // ! MLN_CORE_IMAGE_IMAGE2D_HH