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

2006-10-09 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>

	Separate definition code from declaration code in olena.

	* oln/core/type.hh: Split code.
	* oln/core/point_set_entry.hh: Likewise.
	* oln/core/automatic/image.hh: Likewise.
	* oln/core/automatic/topology_having_bbox.hh: Likewise.
	* oln/core/automatic/image_being_random_accessible.hh: Likewise.
	* oln/core/automatic/image_having_neighborhood.hh: Likewise.
	* oln/core/automatic/topology_being_random_accessible.hh: Likewise.
	* oln/core/automatic/topology_having_subset.hh: Likewise.
	* oln/core/automatic/image_being_mutable.hh: Likewise.
	* oln/core/automatic/topology_having_neighborhood.hh: Likewise.
	* oln/core/neighborhood_entry.hh: Likewise.
	* oln/core/topology_entry.hh: Likewise.
	* oln/core/image_entry.hh: Likewise.
	* oln/core/abstract/iterator_on_points.hh: Likewise.
	* oln/core/abstract/topology_having_bbox.hh: Likewise.
	* oln/core/abstract/image.hh: Likewise.
	* oln/core/abstract/image/type/binary.hh: Likewise.
	* oln/core/abstract/image/type/data.hh: Likewise.
	* oln/core/abstract/image/type/grey_level.hh: Likewise.
	* oln/core/abstract/image/type/color.hh: Likewise.
	* oln/core/abstract/image/type/label.hh: Likewise.
	* oln/core/abstract/image/hybrid/classical.hh: Likewise.
	* oln/core/abstract/image/mutability/hierarchy.hh: Likewise.
	* oln/core/abstract/image/dimension/2d.hh: Likewise.
	* oln/core/abstract/image/neighborhood/hierarchy.hh: Likewise.
	* oln/core/abstract/image/accessibility/hierarchy.hh: Likewise.
	* oln/core/abstract/image/bbox/hierarchy.hh: Likewise.
	* oln/core/abstract/point_set_being_random_accessible.hh: Likewise.
	* oln/core/abstract/grid.hh: Likewise.
	* oln/core/abstract/iterator.hh: Likewise.
	* oln/core/abstract/point.hh: Likewise.
	* oln/core/abstract/bbox.hh: Likewise.
	* oln/core/abstract/point_set_being_connected.hh: Likewise.
	* oln/core/abstract/dpoint.hh: Likewise.
	* oln/core/abstract/topology_being_random_accessible.hh: Likewise.
	* oln/core/abstract/topology_having_subset.hh: Likewise.
	* oln/core/abstract/topology_having_neighborhood.hh: Likewise.
	* oln/core/abstract/entry.hh: Likewise.
	* oln/core/abstract/point_set.hh: Likewise.
	* oln/core/abstract/point_set_having_known_size.hh: Likewise.
	* oln/core/abstract/neighborhood.hh: Likewise.
	* oln/core/abstract/point_set_having_bbox.hh: Likewise.
	* oln/core/abstract/topology.hh: Likewise.
	* oln/core/2d/neighb2d.hh: Likewise.
	* oln/core/2d/dpoint2d.hh: Likewise.
	* oln/core/2d/array2d.hh: Likewise.
	* oln/core/2d/image2d.hh: Likewise.
	* oln/core/2d/point2d.hh: Likewise.
	* oln/core/gen/piter_isubset.hh: Likewise.
	* oln/core/gen/topo_add_isubset.hh: Likewise.
	* oln/core/gen/bbox.hh: Likewise.
	* oln/core/gen/topo_bbox.hh: Likewise.
	* oln/core/gen/neighb.hh: Likewise.
	* oln/core/gen/fwd_piter_bbox.hh: Likewise.
	* oln/core/gen/bbox_fwd_piter.hh: Likewise.
	* oln/core/gen/fwd_niter_neighb.hh: Likewise.
	* oln/core/gen/fwd_qiter_win.hh: Likewise.
	* oln/core/gen/topo_lbbox.hh: Likewise.
	* oln/core/gen/window.hh: Likewise.
	* oln/core/gen/bbox_bkd_piter.hh: Likewise.
	* oln/core/gen/bkd_piter_bbox.hh: Likewise.
	* oln/core/gen/topo_add_nbh.hh: Likewise.
	* oln/core/gen/mapimage.hh: Likewise.
	* oln/core/internal/tracked_ptr.hh: Likewise.
	* oln/core/internal/topology_morpher.hh: Likewise.
	* oln/core/internal/point_nd.hh: Likewise.
	* oln/core/internal/bbox_bkd_piter.hh: Likewise.
	* oln/core/internal/bbox_fwd_piter.hh: Likewise.
	* oln/core/internal/dpoint_nd.hh: Likewise.
	* oln/basics2d.hh: Likewise.
	* oln/morpher/add_isubset.hh: Likewise.
	* oln/morpher/identity.hh: Likewise.
	* oln/morpher/internal/image_extension.hh: Likewise.
	* oln/morpher/add_neighborhood.hh: Likewise.



git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@608 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 1f303fb1
2006-10-09 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Separate definition code from declaration code in olena.
* oln/core/type.hh: Split code.
* oln/core/point_set_entry.hh: Likewise.
* oln/core/automatic/image.hh: Likewise.
* oln/core/automatic/topology_having_bbox.hh: Likewise.
* oln/core/automatic/image_being_random_accessible.hh: Likewise.
* oln/core/automatic/image_having_neighborhood.hh: Likewise.
* oln/core/automatic/topology_being_random_accessible.hh: Likewise.
* oln/core/automatic/topology_having_subset.hh: Likewise.
* oln/core/automatic/image_being_mutable.hh: Likewise.
* oln/core/automatic/topology_having_neighborhood.hh: Likewise.
* oln/core/neighborhood_entry.hh: Likewise.
* oln/core/topology_entry.hh: Likewise.
* oln/core/image_entry.hh: Likewise.
* oln/core/abstract/iterator_on_points.hh: Likewise.
* oln/core/abstract/topology_having_bbox.hh: Likewise.
* oln/core/abstract/image.hh: Likewise.
* oln/core/abstract/image/type/binary.hh: Likewise.
* oln/core/abstract/image/type/data.hh: Likewise.
* oln/core/abstract/image/type/grey_level.hh: Likewise.
* oln/core/abstract/image/type/color.hh: Likewise.
* oln/core/abstract/image/type/label.hh: Likewise.
* oln/core/abstract/image/hybrid/classical.hh: Likewise.
* oln/core/abstract/image/mutability/hierarchy.hh: Likewise.
* oln/core/abstract/image/dimension/2d.hh: Likewise.
* oln/core/abstract/image/neighborhood/hierarchy.hh: Likewise.
* oln/core/abstract/image/accessibility/hierarchy.hh: Likewise.
* oln/core/abstract/image/bbox/hierarchy.hh: Likewise.
* oln/core/abstract/point_set_being_random_accessible.hh: Likewise.
* oln/core/abstract/grid.hh: Likewise.
* oln/core/abstract/iterator.hh: Likewise.
* oln/core/abstract/point.hh: Likewise.
* oln/core/abstract/bbox.hh: Likewise.
* oln/core/abstract/point_set_being_connected.hh: Likewise.
* oln/core/abstract/dpoint.hh: Likewise.
* oln/core/abstract/topology_being_random_accessible.hh: Likewise.
* oln/core/abstract/topology_having_subset.hh: Likewise.
* oln/core/abstract/topology_having_neighborhood.hh: Likewise.
* oln/core/abstract/entry.hh: Likewise.
* oln/core/abstract/point_set.hh: Likewise.
* oln/core/abstract/point_set_having_known_size.hh: Likewise.
* oln/core/abstract/neighborhood.hh: Likewise.
* oln/core/abstract/point_set_having_bbox.hh: Likewise.
* oln/core/abstract/topology.hh: Likewise.
* oln/core/2d/neighb2d.hh: Likewise.
* oln/core/2d/dpoint2d.hh: Likewise.
* oln/core/2d/array2d.hh: Likewise.
* oln/core/2d/image2d.hh: Likewise.
* oln/core/2d/point2d.hh: Likewise.
* oln/core/gen/piter_isubset.hh: Likewise.
* oln/core/gen/topo_add_isubset.hh: Likewise.
* oln/core/gen/bbox.hh: Likewise.
* oln/core/gen/topo_bbox.hh: Likewise.
* oln/core/gen/neighb.hh: Likewise.
* oln/core/gen/fwd_piter_bbox.hh: Likewise.
* oln/core/gen/bbox_fwd_piter.hh: Likewise.
* oln/core/gen/fwd_niter_neighb.hh: Likewise.
* oln/core/gen/fwd_qiter_win.hh: Likewise.
* oln/core/gen/topo_lbbox.hh: Likewise.
* oln/core/gen/window.hh: Likewise.
* oln/core/gen/bbox_bkd_piter.hh: Likewise.
* oln/core/gen/bkd_piter_bbox.hh: Likewise.
* oln/core/gen/topo_add_nbh.hh: Likewise.
* oln/core/gen/mapimage.hh: Likewise.
* oln/core/internal/tracked_ptr.hh: Likewise.
* oln/core/internal/topology_morpher.hh: Likewise.
* oln/core/internal/point_nd.hh: Likewise.
* oln/core/internal/bbox_bkd_piter.hh: Likewise.
* oln/core/internal/bbox_fwd_piter.hh: Likewise.
* oln/core/internal/dpoint_nd.hh: Likewise.
* oln/basics2d.hh: Likewise.
* oln/morpher/add_isubset.hh: Likewise.
* oln/morpher/identity.hh: Likewise.
* oln/morpher/internal/image_extension.hh: Likewise.
* oln/morpher/add_neighborhood.hh: Likewise.
2006-10-05 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Decouple iterators from image topology; update neighborhood tools
......
......@@ -35,25 +35,17 @@
# include <oln/core/2d/grid2d.hh>
# include <oln/core/2d/point2d.hh>
namespace oln { template class point2d_<int>; }
# include <oln/core/2d/dpoint2d.hh>
namespace oln { template class dpoint2d_<int>; }
# include <oln/core/gen/bbox.hh>
namespace oln { template class bbox_<point2d>; }
# include <oln/core/gen/topo_lbbox.hh>
namespace oln { template class topo_lbbox_<point2d>; }
# include <oln/core/gen/fwd_piter_bbox.hh>
namespace oln { template class fwd_piter_bbox_<point2d>; }
# include <oln/core/gen/bkd_piter_bbox.hh>
namespace oln { template class bkd_piter_bbox_<point2d>; }
# include <oln/core/gen/neighb.hh>
namespace oln { template class neighb_<dpoint2d>; }
# include <oln/core/2d/neighb2d.hh>
# include <oln/core/2d/image2d.hh>
......
......@@ -44,65 +44,21 @@ namespace oln
/// Ctor.
array2d(coord_t imin, coord_t jmin,
coord_t imax, coord_t jmax) :
imin_(imin),
jmin_(jmin),
imax_(imax),
jmax_(jmax)
{
precondition(imax >= imin and jmax >= jmin);
ilen_ = imax - imin + 1;
jlen_ = jmax - jmin + 1;
allocate_();
}
coord_t imax, coord_t jmax);
/// Ctor.
array2d(coord_t ilen, coord_t jlen) :
imin_(0),
jmin_(0),
ilen_(ilen),
jlen_(jlen)
{
precondition(ilen > 0 and jlen > 0);
imax_ = imin_ + ilen_;
jmax_ = jmin_ + ilen_;
allocate_();
}
array2d(coord_t ilen, coord_t jlen);
/// Dtor.
~array2d()
{
deallocate_();
}
value_t operator()(coord_t i, coord_t j) const
{
precondition(has(i, j));
return array_[i][j];
}
value_t& operator()(coord_t i, coord_t j)
{
precondition(has(i, j));
return array_[i][j];
}
bool has(coord_t i, coord_t j) const
{
return
i >= imin_ and i <= imax_ and
j >= jmin_ and j <= jmax_;
}
size_t memsize() const
{
return
// buffer_
size_t(ilen_) * size_t(jlen_) * sizeof(value_t)
+
// array_
size_t(ilen_) * sizeof(value_t*);
}
~array2d();
value_t operator()(coord_t i, coord_t j) const;
value_t& operator()(coord_t i, coord_t j);
bool has(coord_t i, coord_t j) const;
size_t memsize() const;
protected:
......@@ -113,31 +69,112 @@ namespace oln
private:
void 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)
{
array_[i] = buf;
buf += jlen_;
}
array_ -= imin_;
}
void deallocate_()
{
precondition(buffer_ != 0 and array_ != 0);
delete[] buffer_;
buffer_ = 0; // safety
array_ += imin_;
delete[] array_;
array_ = 0; // safety
}
void allocate_();
void deallocate_();
};
# 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) :
imin_(imin),
jmin_(jmin),
imax_(imax),
jmax_(jmax)
{
precondition(imax >= imin and jmax >= jmin);
ilen_ = imax - imin + 1;
jlen_ = jmax - jmin + 1;
allocate_();
}
template <typename value_t, typename coord_t>
/// Ctor.
array2d<value_t, coord_t>::array2d(coord_t ilen, coord_t jlen) :
imin_(0),
jmin_(0),
ilen_(ilen),
jlen_(jlen)
{
precondition(ilen > 0 and jlen > 0);
imax_ = imin_ + ilen_;
jmax_ = jmin_ + ilen_;
allocate_();
}
template <typename value_t, typename coord_t>
/// Dtor.
array2d<value_t, coord_t>::~array2d()
{
deallocate_();
}
template <typename value_t, typename coord_t>
value_t array2d<value_t, coord_t>::operator()(coord_t i, coord_t 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)
{
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
{
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
{
return
// buffer_
size_t(ilen_) * size_t(jlen_) * sizeof(value_t)
+
// array_
size_t(ilen_) * sizeof(value_t*);
}
template <typename value_t, typename coord_t>
void array2d<value_t, coord_t>::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)
{
array_[i] = buf;
buf += jlen_;
}
array_ -= imin_;
}
template <typename value_t, typename coord_t>
void array2d<value_t, coord_t>::deallocate_()
{
precondition(buffer_ != 0 and array_ != 0);
delete[] buffer_;
buffer_ = 0; // safety
array_ += imin_;
delete[] array_;
array_ = 0; // safety
}
# endif
} // end of namespace oln
......
......@@ -64,37 +64,63 @@ namespace oln
{
typedef dpoint2d_<C> self_t;
typedef stc_get_super(dpoint2d_<C>) super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_;
public:
/// Ctor.
dpoint2d_()
{
}
dpoint2d_();
/// Ctor.
dpoint2d_(const xtd::vec<2,coord_t>& v)
: super_t(v)
{
}
dpoint2d_(const xtd::vec<2,C>& v);
/// Ctor.
dpoint2d_(coord_t row, coord_t col)
: super_t(xtd::mk_vec(row, col))
{
}
dpoint2d_(C row, C col);
coord_t row() const { return v_[0]; }
coord_t& row() { return v_[0]; }
C row() const;
C& row();
coord_t col() const { return v_[1]; }
coord_t& col() { return v_[1]; }
C col() const;
C& col();
};
# ifndef OLN_INCLUDE_ONLY
template <typename C>
dpoint2d_<C>::dpoint2d_()
{
}
/// Ctor.
template <typename C>
dpoint2d_<C>::dpoint2d_(const xtd::vec<2,C>& v)
: super_t(v)
{
}
/// Ctor.
template <typename C>
dpoint2d_<C>::dpoint2d_(C row, C col)
: super_t(xtd::mk_vec(row, col))
{
}
template <typename C>
C dpoint2d_<C>::row() const { return v_[0]; }
template <typename C>
C& dpoint2d_<C>::row() { return v_[0]; }
template <typename C>
C dpoint2d_<C>::col() const { return v_[1]; }
template <typename C>
C& dpoint2d_<C>::col() { return v_[1]; }
# endif
} // end of namespace oln
......
......@@ -78,43 +78,16 @@ namespace oln
public:
/// Ctor using sizes.
image2d(unsigned nrows, unsigned ncols, unsigned border = 2)
: 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(unsigned nrows, unsigned ncols, unsigned border = 2);
/// Ctor using an existing topology.
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()))
{
}
const topo2d& impl_topo() const
{
return topo_;
}
T impl_op_read(const point2d& p) const
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.row(), p.col());
}
T& impl_op_readwrite(const point2d& p)
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.row(), p.col());
}
image2d(const topo2d& topo);
const topo2d& impl_topo() const;
T impl_op_read(const point2d& p) const;
T& impl_op_readwrite(const point2d& p);
private:
......@@ -123,6 +96,55 @@ namespace oln
};
# ifndef OLN_INCLUDE_ONLY
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))
{
}
/// Ctor using an existing topology.
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()))
{
}
template <typename T>
const topo2d& image2d<T>::impl_topo() const
{
return topo_;
}
template <typename T>
T image2d<T>::impl_op_read(const point2d& p) const
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.row(), p.col());
}
template <typename T>
T& image2d<T>::impl_op_readwrite(const point2d& p)
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.row(), p.col());
}
# endif
} // end of namespace oln
......
......@@ -40,69 +40,69 @@ namespace oln
namespace internal
{
neighb2d mk_c4();
neighb2d mk_c8();
neighb2d mk_c2_row();
neighb2d mk_c2_col();
# ifndef OLN_INCLUDE_ONLY
neighb2d mk_c4()
{
static bool flower = true;
static neighb2d the_;
if (flower)
{
the_
.add(dpoint2d(0, 1))
.add(dpoint2d(1, 0));
flower = false;
}
neighb2d the_;
the_
.add(dpoint2d(0, 1))
.add(dpoint2d(1, 0));
return the_;
}
neighb2d mk_c8()
{
static bool flower = true;
static neighb2d the_;
if (flower)
{
the_
.add(dpoint2d(0, 1))
.add(dpoint2d(1,-1))
.add(dpoint2d(1, 0))
.add(dpoint2d(1, 1));
flower = false;
}
neighb2d the_;
the_
.add(dpoint2d(0, 1))
.add(dpoint2d(1,-1))
.add(dpoint2d(1, 0))
.add(dpoint2d(1, 1));
return the_;
}
neighb2d mk_c2_row()
{
static bool flower = true;
static neighb2d the_;
if (flower)
{
the_
.add(dpoint2d(0, 1));
flower = false;
}
neighb2d the_;
the_
.add(dpoint2d(0, 1));
return the_;
}
neighb2d mk_c2_col()
{
static bool flower = true;
static neighb2d the_;
if (flower)
{
the_
.add(dpoint2d(1, 0));
flower = false;
}
neighb2d the_;
the_
.add(dpoint2d(1, 0));
return the_;
}
# endif
} // end of namespace oln::internal
static const neighb2d c4 = internal::mk_c4();
static const neighb2d c8 = internal::mk_c8();
static const neighb2d c2r = internal::mk_c2_row();
static const neighb2d c2c = internal::mk_c2_col();
extern const neighb2d c4;
extern const neighb2d c8;
extern const neighb2d c2r;
extern const neighb2d c2c;
# ifndef OLN_INCLUDE_ONLY
const neighb2d c4 = internal::mk_c4();
const neighb2d c8 = internal::mk_c8();
const neighb2d c2r = internal::mk_c2_row();
const neighb2d c2c = internal::mk_c2_col();
# endif