Commit ece7a482 authored by Thierry Geraud's avatar Thierry Geraud
Browse files

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.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@854 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 627292f4
2007-03-06 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.
2007-03-05 Thierry Geraud <thierry.geraud@lrde.epita.fr>
Update image concepts and add single_value_image.
......
// 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 @@ namespace oln
# 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 @@ namespace oln
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 @@ namespace oln
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 @@ namespace oln
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_;
......
......@@ -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 mlc::uint_<2> dim;
};
template <typename Exact>
struct Grid_2D : public Grid<Exact>
{
typedef Grid< grid2d > ret;
protected:
Grid_2D() {}
};
/// \}
/// Virtual types.
template <>
struct vtypes< grid2d >
/// \{
/// Super types.
template<>
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
......
// 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 @@ namespace oln
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>
<