854: Extend image selectors and add image2d type.

https://svn.lrde.epita.fr/svn/oln/trunk/olena Index: ChangeLog from Thierry Geraud <thierry.geraud@lrde.epita.fr> Extend image selectors and add image2d type. * core/concept/image.hh (doc): New. (Fast_Image): New. (Random_Accessible_Image, Random_Mutable_Image): Merge into Fast_Image. * core/concept/point_set.hh (include): Update. * core/concept/point.hh: Likewise. * core/2d/array2d.hh (include): Remove abstract/array. (array2d): Rename as... (array2d_): ...this. (imin, jmin, imax, jmax, buffer, ncells): New methods. * core/2d/image2d.hh: Update. * core/2d/image2d_b.hh: New. * core/2d/grid2d.hh (Grid_2D): New. (grid2d_rec, grid2d_hex, grid2d_tri): New. * core/equipment.hh (ch_value, output): New. * core/gen/box.hh: Fix. * core/internal/image_selectors.hh: Update. * core/internal/image_base.hh (qiter, fwd_qiter, bkd_qiter): New. * stc/scoop.hh (stc_get_type_, stc_get_type, stc_is_a): New. core/2d/array2d.hh | 132 ++++++++++++++++++++-------- core/2d/grid2d.hh | 75 +++++++++++++--- core/2d/image2d.hh | 178 +++++++++++++++++++++------------------ core/2d/image2d_b.hh | 50 +++++----- core/concept/image.hh | 141 +++++++++++++++++++++--------- core/concept/point.hh | 1 core/concept/point_set.hh | 3 core/equipment.hh | 4 core/gen/box.hh | 4 core/internal/image_base.hh | 7 + core/internal/image_selectors.hh | 72 ++++++++++++++- stc/scoop.hh | 11 ++ 12 files changed, 471 insertions(+), 207 deletions(-) Index: oln/core/concept/image.hh --- oln/core/concept/image.hh (revision 853) +++ oln/core/concept/image.hh (working copy) @@ -29,9 +29,74 @@ #ifndef OLN_CORE_CONCEPT_IMAGE_HH # define OLN_CORE_CONCEPT_IMAGE_HH +# include <cstddef> # include <oln/core/equipment.hh> +/* + + +Image + | + | + | + o -- Mutable_Image + | | + | + -- Fast_Image + | + | + | + o -- + -- Image_1D + | | + | + -- Image_2D + | | | + | | + -- Image_2D_rec + | | | + | | + -- Image_2D_hex + | | | + | | + -- Image_2D_tri + | | + | + -- Image_3D + | + | + | + o -- Point_Wise_Accessible_Image + | | + | | Image_2D + | | | + | | | + | + -- Point_Wise_Accessible_Image_2D + | | | + | | | Mutable_Image + | | | | + | | | | + | | + -- Point_Wise_Mutable_Image_2D + | | + | + ... + | + | + | + o -- + -- Gray_Level_Image + | | + | + -- Color_Image + | | + | + -- Label_Image + | | | + | | + -- Binary_Image + | | | + | | + -- String_Image + | | + | + -- Deformation_Field_Image + | | + | + -- Data_Image + | + | + | + ... + +*/ + + namespace oln { @@ -57,6 +122,8 @@ stc_typename(box); stc_typename(pset); + // stc_typename(output); // FIXME: Uncomment! + bool owns_(const psite& p) const; rvalue operator()(const psite& p) const; @@ -99,55 +166,42 @@ }; - /// Concept-class "Point_Wise_Accessible_Image". + /// Concept-class "Fast_Image". template <typename Exact> - struct Point_Wise_Accessible_Image : public virtual Image<Exact>, - public automatic::get_impl<Point_Wise_Accessible_Image, Exact> - { - stc_using_from(Image, point); - - stc_typename(qiter); - stc_typename(fwd_qiter); - stc_typename(bkd_qiter); - bool has(const point& p) const; - - protected: - Point_Wise_Accessible_Image(); - }; - - - /// Concept-class "Random_Accessible_Image". - - template <typename Exact> - struct Random_Accessible_Image : public virtual Image<Exact>, - public automatic::get_impl<Random_Accessible_Image, Exact> + struct Fast_Image : public virtual Mutable_Image<Exact>, + public automatic::get_impl<Fast_Image, Exact> { stc_using_from(Image, rvalue); + stc_using_from(Image, lvalue); stc_typename(index); + rvalue operator[](index i) const; + lvalue operator[](index i); + std::size_t npoints() const; + // FIXME: ... protected: - Random_Accessible_Image(); + Fast_Image(); }; - /// Concept-class "Random_Mutable_Image". + /// Concept-class "Point_Wise_Accessible_Image". template <typename Exact> - struct Random_Mutable_Image : public virtual Random_Accessible_Image<Exact>, - public virtual Mutable_Image<Exact>, - public automatic::get_impl<Random_Mutable_Image, Exact> + struct Point_Wise_Accessible_Image : public virtual Image<Exact>, + public automatic::get_impl<Point_Wise_Accessible_Image, Exact> { - stc_using_from(Random_Accessible_Image, index); - stc_using_from(Mutable_Image, lvalue); - using Random_Accessible_Image<Exact>::operator[]; + stc_using_from(Image, point); - lvalue operator[](index i); + stc_typename(qiter); + stc_typename(fwd_qiter); + stc_typename(bkd_qiter); + bool has(const point& p) const; protected: - Random_Mutable_Image(); + Point_Wise_Accessible_Image(); }; @@ -352,31 +406,31 @@ { } - // ----------------------------------- Random_Accessible_Image<Exact> + // ----------------------------------- Fast_Image<Exact> template <typename Exact> - typename Random_Accessible_Image<Exact>::rvalue - Random_Accessible_Image<Exact>::operator[](typename Random_Accessible_Image<Exact>::index i) const + typename Fast_Image<Exact>::rvalue + Fast_Image<Exact>::operator[](typename Fast_Image<Exact>::index i) const { return exact(this)->impl_index_read(p); } template <typename Exact> - Random_Accessible_Image<Exact>::Random_Accessible_Image() + typename Fast_Image<Exact>::lvalue + Fast_Image<Exact>::operator[](typename Fast_Image<Exact>::index i) { + return exact(this)->impl_index_read_write(p); } - // ----------------------------------- Random_Mutable_Image<Exact> - template <typename Exact> - typename Random_Mutable_Image<Exact>::lvalue - Random_Mutable_Image<Exact>::operator[](typename Random_Accessible_Image<Exact>::index i) + std::size_t + Fast_Image<Exact>::npoints() const { - return exact(this)->impl_index_read_write(p); + return exact(this)->impl_npoints(p); } template <typename Exact> - Random_Mutable_Image<Exact>::Random_Mutable_Image() + Fast_Image<Exact>::Fast_Image() { } @@ -483,6 +537,11 @@ return this->at(p); } + template <typename Exact> + Point_Wise_Mutable_Image_2D<Exact>::Point_Wise_Mutable_Image_2D() + { + } + # endif Index: oln/core/concept/point_set.hh --- oln/core/concept/point_set.hh (revision 853) +++ oln/core/concept/point_set.hh (working copy) @@ -29,8 +29,7 @@ # define OLN_CORE_CONCEPT_POINT_SET_HH # include <ostream> -# include <oln/core/equipment.hh> -# include <oln/core/point.hh> +# include <oln/core/concept/point.hh> namespace oln Index: oln/core/concept/point.hh --- oln/core/concept/point.hh (revision 853) +++ oln/core/concept/point.hh (working copy) @@ -30,7 +30,6 @@ # define OLN_CORE_CONCEPT_POINT_HH # include <mlc/value.hh> -# include <oln/core/equipment.hh> # include <oln/core/concept/operators.hh> Index: oln/core/2d/array2d.hh --- oln/core/2d/array2d.hh (revision 853) +++ oln/core/2d/array2d.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2003, 2004, 2006 EPITA Research and Development -// Laboratory +// Copyright (C) 2001, 2003, 2004, 2006, 2007 EPITA Research and +// Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -31,39 +31,49 @@ # include <cstddef> # include <mlc/contract.hh> -# include <oln/core/abstract/array.hh> namespace oln { /// General 2D array class. - template <typename value_t, typename coord_t = int> - class array2d : public abstract::array + + template <typename T, typename C = int> + class array2d_ { public: /// Ctor. - array2d(coord_t imin, coord_t jmin, coord_t imax, coord_t jmax); + array2d_(C imin, C jmin, C imax, C jmax); + /// Ctor. - array2d(coord_t ilen, coord_t jlen); + array2d_(C ilen, C jlen); /// Dtor. - ~array2d(); + ~array2d_(); - value_t operator()(coord_t i, coord_t j) const; - value_t& operator()(coord_t i, coord_t j); + const T& operator()(C i, C j) const; + T& operator()(C i, C j); - bool has(coord_t i, coord_t j) const; + bool has(C i, C j) const; std::size_t memsize() const; + std::size_t ncells() const; + + C imin() const; + C jmin() const; + C imax() const; + C jmax() const; + + const T* buffer() const; + T* buffer(); protected: - coord_t imin_, jmin_, imax_, jmax_; - coord_t ilen_, jlen_; - value_t* buffer_; - value_t** array_; + C imin_, jmin_, imax_, jmax_; + C ilen_, jlen_; + T* buffer_; + T** array_; private: @@ -75,9 +85,8 @@ # ifndef OLN_INCLUDE_ONLY - template <typename value_t, typename coord_t> - array2d<value_t, coord_t>::array2d(coord_t imin, coord_t jmin, - coord_t imax, coord_t jmax) : + template <typename T, typename C> + array2d_<T, C>::array2d_(C imin, C jmin, C imax, C jmax) : imin_(imin), jmin_(jmin), imax_(imax), @@ -89,8 +98,8 @@ allocate_(); } - template <typename value_t, typename coord_t> - array2d<value_t, coord_t>::array2d(coord_t ilen, coord_t jlen) : + template <typename T, typename C> + array2d_<T, C>::array2d_(C ilen, C jlen) : imin_(0), jmin_(0), ilen_(ilen), @@ -102,52 +111,95 @@ allocate_(); } - template <typename value_t, typename coord_t> - array2d<value_t, coord_t>::~array2d() + template <typename T, typename C> + array2d_<T, C>::~array2d_() { deallocate_(); } - template <typename value_t, typename coord_t> - value_t array2d<value_t, coord_t>::operator()(coord_t i, coord_t j) const + template <typename T, typename C> + const T& array2d_<T, C>::operator()(C i, C j) const { precondition(has(i, j)); return array_[i][j]; } - template <typename value_t, typename coord_t> - value_t& array2d<value_t, coord_t>::operator()(coord_t i, coord_t j) + template <typename T, typename C> + T& array2d_<T, C>::operator()(C i, C j) { precondition(has(i, j)); return array_[i][j]; } - template <typename value_t, typename coord_t> - bool array2d<value_t, coord_t>::has(coord_t i, coord_t j) const + template <typename T, typename C> + bool array2d_<T, C>::has(C i, C j) const { return i >= imin_ and i <= imax_ and j >= jmin_ and j <= jmax_; } - template <typename value_t, typename coord_t> - size_t array2d<value_t, coord_t>::memsize() const + + template <typename T, typename C> + C array2d_<T, C>::imin() const + { + return imin_; + } + + template <typename T, typename C> + C array2d_<T, C>::jmin() const + { + return jmin_; + } + + template <typename T, typename C> + C array2d_<T, C>::imax() const + { + return imax_; + } + + template <typename T, typename C> + C array2d_<T, C>::jmax() const + { + return jmax_; + } + + template <typename T, typename C> + const T* array2d_<T, C>::buffer() const + { + return buffer_; + } + + template <typename T, typename C> + T* array2d_<T, C>::buffer() + { + return buffer_; + } + + template <typename T, typename C> + std::size_t array2d_<T, C>::ncells() const + { + return std::size_t(ilen_) * std::size_t(jlen_); + } + + template <typename T, typename C> + std::size_t array2d_<T, C>::memsize() const { return // buffer_ - size_t(ilen_) * size_t(jlen_) * sizeof(value_t) + std::size_t(ilen_) * std::size_t(jlen_) * sizeof(T) + // array_ - size_t(ilen_) * sizeof(value_t*); + std::size_t(ilen_) * sizeof(T*); } - template <typename value_t, typename coord_t> - void array2d<value_t, coord_t>::allocate_() + template <typename T, typename C> + void array2d_<T, C>::allocate_() { - buffer_ = new value_t[size_t(ilen_) * size_t(jlen_)]; - array_ = new value_t*[size_t(ilen_)]; - value_t* buf = buffer_ - jmin_; - for (coord_t i = 0; i < ilen_; ++i) + buffer_ = new T[std::size_t(ilen_) * std::size_t(jlen_)]; + array_ = new T*[std::size_t(ilen_)]; + T* buf = buffer_ - jmin_; + for (C i = 0; i < ilen_; ++i) { array_[i] = buf; buf += jlen_; @@ -155,8 +207,8 @@ array_ -= imin_; } - template <typename value_t, typename coord_t> - void array2d<value_t, coord_t>::deallocate_() + template <typename T, typename C> + void array2d_<T, C>::deallocate_() { precondition(buffer_ != 0 and array_ != 0); delete[] buffer_; Index: oln/core/2d/image2d.hh --- oln/core/2d/image2d.hh (revision 853) +++ oln/core/2d/image2d.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and -// Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA +// Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -29,79 +29,77 @@ #ifndef OLN_CORE_2D_IMAGE2D_HH # define OLN_CORE_2D_IMAGE2D_HH -# include <oln/core/image_entry.hh> -# include <oln/core/gen/grid.hh> -# include <oln/core/internal/tracked_ptr.hh> +# include <oln/core/internal/image_base.hh> # include <oln/core/2d/array2d.hh> -# include <oln/core/2d/point2d.hh> -# include <oln/core/2d/topo2d.hh> -// For fwd_piter and bkd_piter virtual types. -# include <oln/core/iterator_vtypes.hh> +# include <oln/core/2d/box2d.hh> namespace oln { - // Forward declaration. + // Fwd decl. template <typename T> class image2d; - /// Virtual types associated to oln::image2d<T>. + /// Virtual types. template <typename T> struct vtypes< image2d<T> > { - typedef topo2d topo_type; + typedef point2d point; + typedef point psite; - typedef point2d point_type; + typedef int coord; + typedef unsigned index; - typedef mlc::false_ is_computed_type; - typedef T value_type; - typedef T& lvalue_type; + typedef T value; + typedef const T& rvalue; + typedef T& lvalue; + + typedef box2d pset; + typedef array2d_<value, coord> data; }; - /// Super type declaration. + /// Super type. template <typename T> - struct set_super_type< image2d<T> > + struct super_trait_< image2d<T> > { - typedef image2d<T> self_t; - typedef image_entry<self_t> ret; + typedef image2d<T> current; + typedef internal::image_base_<current> ret; }; /// General 2D image class. + template <typename T> - class image2d : public image_entry< image2d<T> > + class image2d : public internal::image_base_< image2d<T> > { - typedef image2d<T> self_t; - typedef array2d<T> array_t; - + typedef image2d<T> current; + typedef internal::image_base_<current> super; public: + stc_using(data); - /// Ctor without info. image2d(); + image2d(const box2d& b); + image2d(unsigned nrows, unsigned ncols); - /// Ctor using sizes. - image2d(unsigned nrows, unsigned ncols, unsigned border = 2); + bool impl_owns_(const point2d& p) const; - /// Ctor using an existing topology. - image2d(const topo2d& topo); + bool impl_has(const point2d& p) const; + bool impl_has_at(int row, int col) const; - const topo2d& impl_topo() const; + const T& impl_read(const point2d& p) const; + const T& impl_index_read(unsigned i) const; + const T& impl_at(int row, int col) const; - T impl_op_read(const point2d& p) const; - T impl_at(int row, int col) const; - - T& impl_op_readwrite(const point2d& p); + T& impl_read_write(const point2d& p); + T& impl_index_read_write(unsigned i); T& impl_at(int row, int col); - T* adr_at(int row, int col); - const T* adr_at(int row, int col) const; - - private: + std::size_t npoints() const; - topo2d topo_; - internal::tracked_ptr<array_t> data_; + box2d impl_bbox() const; + box2d impl_points() const; }; @@ -110,86 +108,110 @@ template <typename T> image2d<T>::image2d() - : topo_(), - data_() { } template <typename T> - image2d<T>::image2d(unsigned nrows, unsigned ncols, unsigned border) - : topo_(bbox2d(point2d(0, 0 ), - point2d(nrows - 1, ncols - 1)), - border), - data_(new array_t(0 - border, 0 - border, - nrows - 1 + border, ncols - 1 + border)) + image2d<T>::image2d(const box2d& b) { + this->data_ = new data(b.pmin().row(), b.pmin().col(), + b.pmax().row(), b.pmax().col()); } template <typename T> - image2d<T>::image2d(const topo2d& topo) - : topo_(topo), - data_(new array_t(topo.bbox().pmin().row(), - topo.bbox().pmin().col(), - topo.bbox().pmax().row(), - topo.bbox().pmax().col())) + image2d<T>::image2d(unsigned nrows, unsigned ncols) { + precondition(nrows != 0 and ncols != 0); + this->data_ = new data(0, 0, nrows - 1, ncols - 1); } + template <typename T> + bool image2d<T>::impl_owns_(const point2d& p) const + { + assert(this->has_data()); + return this->data_->has(p.row(), p.col()); + } template <typename T> - const topo2d& image2d<T>::impl_topo() const + bool image2d<T>::impl_has(const point2d& p) const { - return topo_; + assert(this->has_data()); + return this->data_->has(p.row(), p.col()); } + template <typename T> + bool image2d<T>::impl_has_at(int row, int col) const + { + assert(this->has_data()); + return this->data_->has(row, col); + } template <typename T> - T image2d<T>::impl_op_read(const point2d& p) const + const T& image2d<T>::impl_read(const point2d& p) const { - precondition(data_ != 0); - precondition(topo_.has_large(p)); - return data_->operator()(p.row(), p.col()); + assert(this->has_data()); + return this->data_->operator()(p.row(), p.col()); } template <typename T> - T image2d<T>::impl_at(int row, int col) const + const T& image2d<T>::impl_index_read(unsigned i) const { - precondition(data_ != 0); - precondition(data_->has(row, col)); - return data_->operator()(row, col); + assert(this->has_data()); + assert(i < this->npoints()); + return this->data_->buffer()[i]; } + template <typename T> + const T& image2d<T>::impl_at(int row, int col) const + { + assert(this->has_data()); + return this->data_->operator()(row, col); + } + + template <typename T> + T& image2d<T>::impl_read_write(const point2d& p) + { + assert(this->has_data()); + return this->data_->operator()(p.row(), p.col()); + } template <typename T> - T& image2d<T>::impl_op_readwrite(const point2d& p) + T& image2d<T>::impl_index_read_write(unsigned i) { - precondition(data_ != 0); - precondition(topo_.has_large(p)); - return data_->operator()(p.row(), p.col()); + assert(this->has_data()); + assert(i < this->npoints()); + return this->data_->buffer()[i]; } template <typename T> T& image2d<T>::impl_at(int row, int col) { - precondition(data_->has(row, col)); - return data_->operator()(row, col); + assert(this->has_data()); + return this->data_->operator()(row, col); } + template <typename T> + std::size_t image2d<T>::npoints() const + { + assert(this->has_data()); + return this->data_->ncells(); + } template <typename T> - T* image2d<T>::adr_at(int row, int col) + box2d image2d<T>::impl_bbox() const { - precondition(data_ != 0); - precondition(data_->has(row, col)); - return &(data_->operator()(row, col)); + assert(this->has_data()); + point2d + pmin(this->data_->imin(), this->data_->jmin()), + pmax(this->data_->imax(), this->data_->jmax()); + box2d b(pmin, pmax); + return b; } template <typename T> - const T* image2d<T>::adr_at(int row, int col) const + box2d image2d<T>::impl_points() const { - precondition(data_ != 0); - precondition(data_->has(row, col)); - return &(data_->operator()(row, col)); + return this->bbox(); } # endif Index: oln/core/2d/image2d_b.hh --- oln/core/2d/image2d_b.hh (revision 850) +++ oln/core/2d/image2d_b.hh (working copy) @@ -1,5 +1,5 @@ -// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and -// Development Laboratory +// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA +// Research and Development Laboratory // // This file is part of the Olena Library. This library is free // software; you can redistribute it and/or modify it under the terms @@ -26,8 +26,8 @@ // reasons why the executable file might be covered by the GNU General // Public License. -#ifndef OLN_CORE_2D_IMAGE2D_HH -# define OLN_CORE_2D_IMAGE2D_HH +#ifndef OLN_CORE_2D_IMAGE2D_B_HH +# define OLN_CORE_2D_IMAGE2D_B_HH # include <oln/core/image_entry.hh> # include <oln/core/gen/grid.hh> @@ -43,12 +43,12 @@ { // Forward declaration. - template <typename T> class image2d; + template <typename T> class image2d_b; - /// Virtual types associated to oln::image2d<T>. + /// Virtual types associated to oln::image2d_b<T>. template <typename T> - struct vtypes< image2d<T> > + struct vtypes< image2d_b<T> > { typedef topo2d topo_type; @@ -62,30 +62,30 @@ /// Super type declaration. template <typename T> - struct set_super_type< image2d<T> > + struct set_super_type< image2d_b<T> > { - typedef image2d<T> self_t; + typedef image2d_b<T> self_t; typedef image_entry<self_t> ret; }; /// General 2D image class. template <typename T> - class image2d : public image_entry< image2d<T> > + class image2d_b : public image_entry< image2d_b<T> > { - typedef image2d<T> self_t; + typedef image2d_b<T> self_t; typedef array2d<T> array_t; public: /// Ctor without info. - image2d(); + image2d_b(); /// Ctor using sizes. - image2d(unsigned nrows, unsigned ncols, unsigned border = 2); + image2d_b(unsigned nrows, unsigned ncols, unsigned border = 2); /// Ctor using an existing topology. - image2d(const topo2d& topo); + image2d_b(const topo2d& topo); const topo2d& impl_topo() const; @@ -109,14 +109,14 @@ # ifndef OLN_INCLUDE_ONLY template <typename T> - image2d<T>::image2d() + image2d_b<T>::image2d_b() : topo_(), data_() { } template <typename T> - image2d<T>::image2d(unsigned nrows, unsigned ncols, unsigned border) + image2d_b<T>::image2d_b(unsigned nrows, unsigned ncols, unsigned border) : topo_(bbox2d(point2d(0, 0 ), point2d(nrows - 1, ncols - 1)), border), @@ -126,7 +126,7 @@ } template <typename T> - image2d<T>::image2d(const topo2d& topo) + image2d_b<T>::image2d_b(const topo2d& topo) : topo_(topo), data_(new array_t(topo.bbox().pmin().row(), topo.bbox().pmin().col(), @@ -137,14 +137,14 @@ template <typename T> - const topo2d& image2d<T>::impl_topo() const + const topo2d& image2d_b<T>::impl_topo() const { return topo_; } template <typename T> - T image2d<T>::impl_op_read(const point2d& p) const + T image2d_b<T>::impl_op_read(const point2d& p) const { precondition(data_ != 0); precondition(topo_.has_large(p)); @@ -152,7 +152,7 @@ } template <typename T> - T image2d<T>::impl_at(int row, int col) const + T image2d_b<T>::impl_at(int row, int col) const { precondition(data_ != 0); precondition(data_->has(row, col)); @@ -161,7 +161,7 @@ template <typename T> - T& image2d<T>::impl_op_readwrite(const point2d& p) + T& image2d_b<T>::impl_op_readwrite(const point2d& p) { precondition(data_ != 0); precondition(topo_.has_large(p)); @@ -169,7 +169,7 @@ } template <typename T> - T& image2d<T>::impl_at(int row, int col) + T& image2d_b<T>::impl_at(int row, int col) { precondition(data_->has(row, col)); return data_->operator()(row, col); @@ -177,7 +177,7 @@ template <typename T> - T* image2d<T>::adr_at(int row, int col) + T* image2d_b<T>::adr_at(int row, int col) { precondition(data_ != 0); precondition(data_->has(row, col)); @@ -185,7 +185,7 @@ } template <typename T> - const T* image2d<T>::adr_at(int row, int col) const + const T* image2d_b<T>::adr_at(int row, int col) const { precondition(data_ != 0); precondition(data_->has(row, col)); @@ -198,4 +198,4 @@ } // end of namespace oln -#endif // ! OLN_CORE_2D_IMAGE2D_HH +#endif // ! OLN_CORE_2D_IMAGE2D_B_HH Index: oln/core/2d/grid2d.hh --- oln/core/2d/grid2d.hh (revision 853) +++ oln/core/2d/grid2d.hh (working copy) @@ -35,33 +35,82 @@ namespace oln { - struct grid2d; + /// \{ + /// Fwd decls. - /// Super type. - template<> - struct super_trait_< grid2d > + template <typename Exact> struct Grid_2D; + struct grid2d_rec; + struct grid2d_hex; + struct grid2d_tri; + + /// \} + + + /// \{ + /// Grid_2D. + + template <typename Exact> + struct vtypes< Grid_2D<Exact> > { - typedef Grid< grid2d > ret; + typedef mlc::uint_<2> dim; }; + template <typename Exact> + struct Grid_2D : public Grid<Exact> + { + protected: + Grid_2D() {} + }; + + /// \} + + + /// \{ + /// Super types. - /// Virtual types. template <> - struct vtypes< grid2d > + struct super_trait_< grid2d_rec > { - typedef mlc::uint_<2> dim; + typedef Grid_2D< grid2d_rec > ret; }; + template<> + struct super_trait_< grid2d_hex > + { + typedef Grid_2D< grid2d_hex > ret; + }; - /// Rectangular grid class. - class grid2d : public Grid< grid2d > + template<> + struct super_trait_< grid2d_tri > { - public: - /// Ctor. - grid2d() {} + typedef Grid_2D< grid2d_tri > ret; }; + /// \} + + + + + /// Rectangular grid struct. + + struct grid2d_rec : public Grid_2D< grid2d_rec > + {}; + + typedef grid2d_rec grid2d; // for short + + + /// Hexagonal grid struct. + + struct grid2d_hex : public Grid_2D< grid2d_hex > + {}; + + + /// Triangular grid struct. + + struct grid2d_tri : public Grid_2D< grid2d_tri > + {}; + } // end of namespace oln Index: oln/core/equipment.hh --- oln/core/equipment.hh (revision 853) +++ oln/core/equipment.hh (working copy) @@ -47,6 +47,7 @@ // c stc_decl_associated_type( coord ); + stc_decl_associated_type( ch_value ); // d stc_decl_associated_type( data ); @@ -73,6 +74,9 @@ stc_decl_associated_type( nbh ); stc_decl_associated_type( niter ); + // o + stc_decl_associated_type( output ); + // p stc_decl_associated_type( piter ); stc_decl_associated_type( point ); Index: oln/core/gen/box.hh --- oln/core/gen/box.hh (revision 853) +++ oln/core/gen/box.hh (working copy) @@ -240,7 +240,7 @@ box_<P>::pmin() const { for (unsigned i = 0; i < n; ++i) - invariant(pmin[i] <= pmax[i]); + invariant(this->pmin_[i] <= this->pmax_[i]); return this->pmin_; } @@ -249,7 +249,7 @@ box_<P>::pmax() const { for (unsigned i = 0; i < n; ++i) - invariant(pmax[i] >= pmin[i]); + invariant(this->pmax_[i] >= this->pmin_[i]); return this->pmax_; } Index: oln/core/internal/image_selectors.hh --- oln/core/internal/image_selectors.hh (revision 853) +++ oln/core/internal/image_selectors.hh (working copy) @@ -29,6 +29,7 @@ # define OLN_CORE_INTERNAL_IMAGE_SELECTORS_HH # include <oln/core/concept/image.hh> +# include <oln/core/2d/grid2d.hh> namespace oln @@ -43,24 +44,85 @@ typedef selector<Image, 1> Image_mutability; template <typename Exact> - struct case_< Image_mutability, Exact, 1 > : where_< stc_type_is_found(lvalue) > + struct case_< Image_mutability, Exact, 1 > + : + where_< stc_type_is_found(lvalue) > { typedef Mutable_Image<Exact> ret; }; + template <typename Exact> + struct case_< Image_mutability, Exact, 2 > + : + where_< mlc::and_< stc_type_is_found(lvalue), + stc_type_is_found(index) > > + { + typedef Fast_Image<Exact> ret; + }; + + + // 2. dimension + + typedef selector<Image, 2> Image_dimension; + + template <typename Exact> + struct case_< Image_dimension, Exact, 1 > + : + where_< stc_is_a(grid, Grid_2D) > + { + typedef Image_2D<Exact> ret; + }; + + // FIXME: ... + + + // 3. point-wise accessibility + + typedef selector<Image, 3> Image_pw_accessibility; - // 2. point-wise accessibility + template <typename Exact> + struct case_< Image_pw_accessibility, Exact, 1 > + : + where_< mlc::and_list_< mlc::eq_< stc_get_type(psite), stc_get_type(point) >, + stc_type_is_found(lvalue), + stc_is_a(grid, Grid_2D) > > + { + typedef Point_Wise_Mutable_Image_2D<Exact> ret; + }; + + template <typename Exact> + struct case_< Image_pw_accessibility, Exact, 2 > + : + where_< mlc::and_< mlc::eq_< stc_get_type(psite), stc_get_type(point) >, + stc_is_a(grid, Grid_2D) > > + { + typedef Point_Wise_Accessible_Image_2D<Exact> ret; + }; - typedef selector<Image, 2> Image_pw_accessibility; + // FIXME: ... template <typename Exact> - struct case_< Image_pw_accessibility, Exact, 1 > : where_< mlc::eq_< stc_type(Exact, psite), - stc_type(Exact, point) > > + struct default_case_< Image_pw_accessibility, Exact > + : + where_< mlc::eq_< stc_get_type(psite), stc_get_type(point) > > { typedef Point_Wise_Accessible_Image<Exact> ret; }; + // 4. nbh + + typedef selector<Image, 4> Image_nbh; + + template <typename Exact> + struct case_< Image_nbh, Exact, 1 > + : + where_< stc_type_is_found(nbh) > + { + typedef Image_with_Nbh<Exact> ret; + }; + + } // end of namespace oln::internal Index: oln/core/internal/image_base.hh --- oln/core/internal/image_base.hh (revision 853) +++ oln/core/internal/image_base.hh (working copy) @@ -98,8 +98,15 @@ typedef stc::abstract value; typedef stc::abstract rvalue; + // FIXME: Uncomment below! + // typedef stc::abstract output; typedef stc::abstract data; + // FIXME: Temporary hack: + typedef mlc::none qiter; + typedef mlc::none fwd_qiter; + typedef mlc::none bkd_qiter; + // Deferred. typedef stc_deferred(point) point__; Index: oln/stc/scoop.hh --- oln/stc/scoop.hh (revision 853) +++ oln/stc/scoop.hh (working copy) @@ -99,6 +99,11 @@ # define stc_type_(From, Type) vtype<From, typedef_::Type>::ret # define stc_type(From, Type) typename stc_type_(From, Type) +# define stc_get_type_(Type) vtype<Exact, typedef_::Type>::ret +# define stc_get_type(Type) typename stc_get_type_(Type) + +// FIXME: Swap name of stc_type and stc_get_type? + // below the more tolerant version is used, namely stc_deferred, // yet it sometimes can be replaced by "stc_find_type(E, Name)" @@ -111,6 +116,11 @@ +# define stc_is_a(T, U) \ +mlc::wrap_< \ + typename mlc::is_a_< sizeof(mlc::form::of< U >()) >::template ret< typename mlc::basic_< stc_deferred(T) >::ret, U > \ +> + @@ -134,6 +144,7 @@ + // the macro below was called stc_prop which was ambiguous // (that lets us think that it is true_ or false_) but the // result is a mlc::bexpr_!
participants (1)
-
Thierry Geraud