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> 2006-10-05 Thierry GERAUD <theo@tegucigalpa.lrde.epita.fr>
Decouple iterators from image topology; update neighborhood tools Decouple iterators from image topology; update neighborhood tools
......
...@@ -35,25 +35,17 @@ ...@@ -35,25 +35,17 @@
# include <oln/core/2d/grid2d.hh> # include <oln/core/2d/grid2d.hh>
# include <oln/core/2d/point2d.hh> # include <oln/core/2d/point2d.hh>
namespace oln { template class point2d_<int>; }
# include <oln/core/2d/dpoint2d.hh> # include <oln/core/2d/dpoint2d.hh>
namespace oln { template class dpoint2d_<int>; }
# include <oln/core/gen/bbox.hh> # include <oln/core/gen/bbox.hh>
namespace oln { template class bbox_<point2d>; } namespace oln { template class bbox_<point2d>; }
# include <oln/core/gen/topo_lbbox.hh> # include <oln/core/gen/topo_lbbox.hh>
namespace oln { template class topo_lbbox_<point2d>; }
# include <oln/core/gen/fwd_piter_bbox.hh> # include <oln/core/gen/fwd_piter_bbox.hh>
namespace oln { template class fwd_piter_bbox_<point2d>; }
# include <oln/core/gen/bkd_piter_bbox.hh> # include <oln/core/gen/bkd_piter_bbox.hh>
namespace oln { template class bkd_piter_bbox_<point2d>; }
# include <oln/core/gen/neighb.hh> # include <oln/core/gen/neighb.hh>
namespace oln { template class neighb_<dpoint2d>; }
# include <oln/core/2d/neighb2d.hh> # include <oln/core/2d/neighb2d.hh>
# include <oln/core/2d/image2d.hh> # include <oln/core/2d/image2d.hh>
......
...@@ -44,65 +44,21 @@ namespace oln ...@@ -44,65 +44,21 @@ namespace oln
/// Ctor. /// Ctor.
array2d(coord_t imin, coord_t jmin, array2d(coord_t imin, coord_t jmin,
coord_t imax, coord_t jmax) : 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_();
}
/// Ctor. /// Ctor.
array2d(coord_t ilen, coord_t jlen) : 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_();
}
/// Dtor. /// Dtor.
~array2d() ~array2d();
{
deallocate_(); value_t operator()(coord_t i, coord_t j) const;
}
value_t& operator()(coord_t i, coord_t j);
value_t operator()(coord_t i, coord_t j) const
{ bool has(coord_t i, coord_t j) const;
precondition(has(i, j));
return array_[i][j]; size_t memsize() const;
}
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*);
}
protected: protected:
...@@ -113,31 +69,112 @@ namespace oln ...@@ -113,31 +69,112 @@ namespace oln
private: private:
void allocate_() void allocate_();
{
buffer_ = new value_t[size_t(ilen_) * size_t(jlen_)]; void deallocate_();
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
}
}; };
# 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 } // end of namespace oln
......
...@@ -64,37 +64,63 @@ namespace oln ...@@ -64,37 +64,63 @@ namespace oln
{ {
typedef dpoint2d_<C> self_t; typedef dpoint2d_<C> self_t;
typedef stc_get_super(dpoint2d_<C>) super_t; typedef stc_get_super(dpoint2d_<C>) super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_; using super_t::v_;
public: public:
/// Ctor. /// Ctor.
dpoint2d_() dpoint2d_();
{
}
/// Ctor. /// Ctor.
dpoint2d_(const xtd::vec<2,coord_t>& v) dpoint2d_(const xtd::vec<2,C>& v);
: super_t(v)
{
}
/// Ctor. /// Ctor.
dpoint2d_(coord_t row, coord_t col) dpoint2d_(C row, C col);
: super_t(xtd::mk_vec(row, col))
{
}
coord_t row() const { return v_[0]; } C row() const;
coord_t& row() { return v_[0]; } C& row();
coord_t col() const { return v_[1]; } C col() const;
coord_t& col() { return v_[1]; } 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 } // end of namespace oln
......
...@@ -78,43 +78,16 @@ namespace oln ...@@ -78,43 +78,16 @@ namespace oln
public: public:
/// Ctor using sizes. /// Ctor using sizes.
image2d(unsigned nrows, unsigned ncols, unsigned border = 2) 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))
{
}
/// Ctor using an existing topology. /// Ctor using an existing topology.
image2d(const topo2d& topo) image2d(const topo2d& topo);
: topo_(topo),
data_(new array_t(topo.bbox().pmin().row(), const topo2d& impl_topo() const;
topo.bbox().pmin().col(),
topo.bbox().pmax().row(), T impl_op_read(const point2d& p) const;
topo.bbox().pmax().col()))
{ T& impl_op_readwrite(const point2d& p);
}
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());
}
private: private:
...@@ -123,6 +96,55 @@ namespace oln ...@@ -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 } // end of namespace oln
......
...@@ -40,69 +40,69 @@ namespace oln ...@@ -40,69 +40,69 @@ namespace oln
namespace internal namespace internal
{ {
neighb2d mk_c4();
neighb2d mk_c8();
neighb2d mk_c2_row();
neighb2d mk_c2_col();
# ifndef OLN_INCLUDE_ONLY
neighb2d mk_c4() neighb2d mk_c4()
{ {
static bool flower = true; neighb2d the_;
static neighb2d the_; the_
if (flower) .add(dpoint2d(0, 1))
{ .add(dpoint2d(1, 0));
the_
.add(dpoint2d(0, 1))
.add(dpoint2d(1, 0));
flower = false;
}
return the_; return the_;
} }
neighb2d mk_c8() neighb2d mk_c8()
{ {
static bool flower = true; neighb2d the_;
static neighb2d the_; the_
if (flower) .add(dpoint2d(0, 1))
{ .add(dpoint2d(1,-1))
the_ .add(dpoint2d(1, 0))
.add(dpoint2d(0, 1)) .add(dpoint2d(1, 1));
.add(dpoint2d(1,-1))
.add(dpoint2d(1, 0))
.add(dpoint2d(1, 1));
flower = false;
}
return the_; return the_;
} }