Commit 57b5b067 authored by Roland Levillain's avatar Roland Levillain
Browse files

Add oln::image3d and associated types.

	* oln/core/3d/image3d.hh, oln/core/3d/array3d.hh,
	* oln/core/3d/point3d.hh, oln/core/3d/dpoint3d.hh,
	* oln/core/3d/neighb3d.hh, oln/core/3d/aliases.hh,
	* oln/basics3d.hh: New.
	* oln/core/abstract/point_set_being_connected.hh
	(oln::abstract::point_set_being_3d_connected): New class.
	(oln::case_<point_set_hierarchy_wrt_connectivity, E, 3>): New
	case.
	* tests/image3d.cc: New test.
	* tests/Makefile.am (check_PROGRAMS): Add image3d.
	(image3d_SOURCES): New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@605 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent e9b02fbc
2006-10-03 Roland Levillain <roland@lrde.epita.fr>
Add oln::image3d and associated types.
* oln/core/3d/image3d.hh, oln/core/3d/array3d.hh,
* oln/core/3d/point3d.hh, oln/core/3d/dpoint3d.hh,
* oln/core/3d/neighb3d.hh, oln/core/3d/aliases.hh,
* oln/basics3d.hh: New.
* oln/core/abstract/point_set_being_connected.hh
(oln::abstract::point_set_being_3d_connected): New class.
(oln::case_<point_set_hierarchy_wrt_connectivity, E, 3>): New
case.
* tests/image3d.cc: New test.
* tests/Makefile.am (check_PROGRAMS): Add image3d.
(image3d_SOURCES): New.
2006-10-03 Roland Levillain <roland@lrde.epita.fr>
Add oln::image1d and associated types.
......
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_BASICS3D_HH
# define OLN_BASICS3D_HH
# include <oln/core/3d/aliases.hh>
# include <oln/core/3d/grid3d.hh>
# include <oln/core/3d/point3d.hh>
namespace oln { template class point3d_<int>; }
# include <oln/core/3d/dpoint3d.hh>
namespace oln { template class dpoint3d_<int>; }
# include <oln/core/gen/bbox.hh>
namespace oln { template class bbox_<point3d>; }
# include <oln/core/gen/topo_lbbox.hh>
namespace oln { template class topo_lbbox_<point3d>; }
# include <oln/core/gen/fwd_piter_bbox.hh>
namespace oln { template class fwd_piter_bbox_<topo3d>; }
# include <oln/core/gen/bkd_piter_bbox.hh>
namespace oln { template class bkd_piter_bbox_<topo3d>; }
# include <oln/core/gen/neighb.hh>
namespace oln { template class neighb_<dpoint3d>; }
# include <oln/core/3d/neighb3d.hh>
# include <oln/core/3d/image3d.hh>
#endif // ! OLN_BASICS3D_HH
// Copyright (C) 2001, 2003, 2004, 2005, 2006 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_3D_ALIASES_HH
# define OLN_CORE_3D_ALIASES_HH
namespace oln
{
/// \{
/// Forward declarations.
template <typename C> class point3d_;
template <typename C> class dpoint3d_;
template <typename D> class neighb_;
template <typename P> class bbox_;
template <typename P> class topo_lbbox_;
template <typename T> class fwd_piter_bbox_;
template <typename T> class bkd_piter_bbox_;
class grid3d;
/// \}
/// \{
/// Alliases.
typedef point3d_<int> point3d;
typedef dpoint3d_<int> dpoint3d;
typedef neighb_<dpoint3d> neighb3d;
typedef bbox_<point3d> bbox3d;
typedef topo_lbbox_<point3d> topo3d;
typedef fwd_piter_bbox_<topo3d> fwd_piter3d;
typedef bkd_piter_bbox_<topo3d> bkd_piter3d;
typedef point3d_<float> point3df;
typedef dpoint3d_<float> dpoint3df;
/// \}
} // end of namespace oln
#endif // ! OLN_CORE_3D_ALIASES_HH
// Copyright (C) 2001, 2003, 2004, 2006 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_3D_ARRAY3D_HH
# define OLN_CORE_3D_ARRAY3D_HH
# include <cstdlib>
# include <mlc/contract.hh>
namespace oln
{
/// General 3D array class.
template <typename value_t, typename coord_t = int>
class array3d
{
public:
/// Ctor.
array3d(coord_t imin, coord_t jmin, coord_t kmin,
coord_t imax, coord_t jmax, coord_t kmax) :
imin_(imin), jmin_(jmin), kmin_(kmin),
imax_(imax), jmax_(jmax), kmax_(kmax)
{
precondition(imax >= imin and jmax >= jmin and kmax >= kmin);
ilen_ = imax - imin + 1;
jlen_ = jmax - jmin + 1;
klen_ = kmax - kmin + 1;
allocate_();
}
/// Ctor.
array3d(coord_t ilen, coord_t jlen, coord_t klen) :
imin_(0), jmin_(0), kmin_(0),
ilen_(ilen), jlen_(jlen), klen_(klen)
{
precondition(ilen > 0 and jlen > 0 and klen > 0);
imax_ = imin_ + ilen_;
jmax_ = jmin_ + ilen_;
kmax_ = kmin_ + klen_;
allocate_();
}
/// Dtor.
~array3d()
{
deallocate_();
}
value_t operator()(coord_t i, coord_t j, coord_t k) const
{
precondition(has(i, j, k));
return array_1st_dim_[i][j][k];
}
value_t& operator()(coord_t i, coord_t j, coord_t k)
{
precondition(has(i, j, k));
return array_1st_dim_[i][j][k];
}
bool has(coord_t i, coord_t j, coord_t k) const
{
return
i >= imin_ and i <= imax_ and
j >= jmin_ and j <= jmax_ and
k >= kmin_ and k <= kmax_;
}
size_t memsize() const
{
return
// buffer_
size_t(ilen_) * size_t(jlen_) * size_t(klen_) * sizeof(value_t)
+
// array_2nd_dim_
size_t(ilen_) * size_t(jlen_) * sizeof(value_t*)
+
// array_1st_dim_
size_t(ilen_) * sizeof(value_t*);
}
protected:
coord_t imin_, jmin_, kmin_, imax_, jmax_, kmax_;
coord_t ilen_, jlen_, klen_;
value_t* buffer_;
value_t** array_2nd_dim_;
value_t*** array_1st_dim_;
private:
void allocate_()
{
buffer_ = new value_t[size_t(ilen_) * size_t(jlen_) * size_t(klen_)];
array_2nd_dim_ = new value_t*[size_t(ilen_) * size_t(jlen_)];
array_1st_dim_ = new value_t**[size_t(ilen_)];
value_t* buf = buffer_ - kmin_;
for (coord_t i = 0; i < ilen_; ++i)
{
value_t** nth_array_2nd_dim = array_2nd_dim_ + i * jlen_;
array_1st_dim_[i] = nth_array_2nd_dim - jmin_;
for (coord_t j = 0; j < jlen_; ++j)
{
nth_array_2nd_dim[j] = buf;
buf += klen_;
}
}
array_1st_dim_ -= imin_;
}
void deallocate_()
{
precondition(buffer_ != 0 and
array_2nd_dim_ != 0 and
array_1st_dim_ != 0);
delete[] buffer_;
buffer_ = 0; // safety
delete[] array_2nd_dim_;
array_2nd_dim_ = 0; // safety
array_1st_dim_ += imin_;
delete[] array_1st_dim_;
array_1st_dim_ = 0; // safety
}
};
} // end of namespace oln
#endif // ! OLN_CORE_3D_ARRAY3D_HH
// Copyright (C) 2001, 2002, 2003, 2004, 2006 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_3D_DPOINT3D_HH
# define OLN_CORE_3D_DPOINT3D_HH
# include <mlc/int.hh>
# include <oln/core/3d/point3d.hh>
# include <oln/core/internal/dpoint_nd.hh>
namespace oln
{
/// Super type.
template<typename C>
struct set_super_type< dpoint3d_<C> >
{
typedef internal::dpoint_nd< dpoint3d_<C> > ret;
};
/// Virtual types associated to oln::dpoint3d_<C>.
template <typename C>
struct vtypes< dpoint3d_<C> >
{
typedef grid3d grid_type;
typedef point3d point_type;
typedef C coord_type;
typedef mlc::uint_<3> dim_type;
};
/// General 3D dpoint class.
template <typename C>
class dpoint3d_
: public stc_get_supers(dpoint3d_<C>)
{
typedef dpoint3d_<C> self_t;
typedef stc_get_super(dpoint3d_<C>) super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_;
public:
/// Ctor.
dpoint3d_()
{
}
/// Ctor.
dpoint3d_(const xtd::vec<3,coord_t>& v)
: super_t(v)
{
}
/// Ctor.
dpoint3d_(coord_t slice, coord_t row, coord_t col)
: super_t(xtd::mk_vec(slice, row, col))
{
}
coord_t slice() const { return v_[0]; }
coord_t& slice() { return v_[0]; }
coord_t row() const { return v_[1]; }
coord_t& row() { return v_[1]; }
coord_t col() const { return v_[2]; }
coord_t& col() { return v_[2]; }
};
} // end of namespace oln
#endif // ! OLN_CORE_3D_DPOINT3D_HH
// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_3D_IMAGE3D_HH
# define OLN_CORE_3D_IMAGE3D_HH
# include <oln/core/image_entry.hh>
# include <oln/core/3d/array3d.hh>
# include <oln/core/internal/tracked_ptr.hh>
namespace oln
{
// Forward declaration.
template <typename T> class image3d;
/// Virtual types associated to oln::image3d<T>.
template <typename T>
struct vtypes< image3d<T> >
{
// FIXME: or `typedef topo3d topo_type;' ?
typedef topo_lbbox_<point3d> topo_type;
typedef grid3d grid_type;
typedef point3d point_type;
typedef fwd_piter_bbox_<topo_type> fwd_piter_type;
typedef bkd_piter_bbox_<topo_type> bkd_piter_type;
typedef T value_type;
typedef T lvalue_type;
typedef mlc::true_ is_mutable_type;
typedef image3d<T> real_type;
};
/// Super type declaration.
template <typename T>
struct set_super_type< image3d<T> >
{
typedef image3d<T> self_t;
typedef image_entry<self_t> ret;
};
/// General 3D image class.
template <typename T>
class image3d : public image_entry< image3d<T> >
{
typedef image3d<T> self_t;
typedef array3d<T> array_t;
public:
/// Ctor using sizes.
image3d(unsigned nslices, unsigned nrows, unsigned ncols,
unsigned border = 2)
: topo_(bbox3d(point3d(0, 0, 0 ),
point3d(nslices - 1, nrows - 1, ncols - 1)),
border),
data_(new array_t(0 - border,
0 - border,
0 - border,
nslices - 1 + border,
nrows - 1 + border,
ncols - 1 + border))
{
}
/// Ctor using an existing topology.
image3d(const topo3d& topo)
: topo_(topo),
data_(new array_t(topo.bbox().pmin().slice(),
topo.bbox().pmin().row(),
topo.bbox().pmin().col(),
topo.bbox().pmax().slice(),
topo.bbox().pmax().row(),
topo.bbox().pmax().col()))
{
}
const topo3d& impl_topo() const
{
return topo_;
}
T impl_op_read(const point3d& p) const
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.slice(), p.row(), p.col());
}
T& impl_op_readwrite(const point3d& p)
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.slice(), p.row(), p.col());
}
private:
topo3d topo_;
internal::tracked_ptr<array_t> data_;
};
} // end of namespace oln
#endif // ! OLN_CORE_3D_IMAGE3D_HH
// Copyright (C) 2001, 2002, 2003, 2004, 2006 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
// of the GNU General Public License version 2 as published by the
// Free Software Foundation.
//
// This library is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this library; see the file COPYING. If not, write to
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
// As a special exception, you may use this file as part of a free
// software library without restriction. Specifically, if other files
// instantiate templates or use macros or inline functions from this
// file, or you compile this file and link it with other files to
// produce an executable, this file does not by itself cause the
// resulting executable to be covered by the GNU General Public
// License. This exception does not however invalidate any other
// reasons why the executable file might be covered by the GNU General
// Public License.
#ifndef OLN_CORE_3D_NEIGHB3D_HH
# define OLN_CORE_3D_NEIGHB3D_HH
# include <oln/core/gen/neighb.hh>
# include <oln/core/3d/aliases.hh>
namespace oln
{
neighb3d c6()
{
static bool flower = true;
static neighb3d the_;
if (flower)
{
the_
.add(dpoint3d(0, 0, 1))
.add(dpoint3d(0, 1, 0))
.add(dpoint3d(1, 0, 0));
flower = false;
}
return the_;
}
neighb3d c18()
{
static bool flower = true;
static neighb3d the_;
if (flower)
{
the_
.add(dpoint3d(0, 0, 1))
.add(dpoint3d(0, 1, -1))
.add(dpoint3d(0, 1, 0))
.add(dpoint3d(0, 1, 1))
.add(dpoint3d(1, -1, 0))
.add(dpoint3d(1, 0, -1))
.add(dpoint3d(1, 0, 0))
.add(dpoint3d(1, 0, 1))