Commit e9b02fbc authored by Roland Levillain's avatar Roland Levillain
Browse files

Add oln::image1d and associated types.

	* oln/core/1d/image1d.hh, oln/core/1d/array1d.hh,
	* oln/core/1d/point1d.hh, oln/core/1d/dpoint1d.hh,
	* oln/core/1d/neighb1d.hh, oln/core/1d/aliases.hh,
	* oln/basics1d.hh: New.
	* oln/core/abstract/point_set_being_connected.hh
	(oln::abstract::point_set_being_1d_connected): New class.
	(oln::case_<point_set_hierarchy_wrt_connectivity, E, 1>): Handle
	the 1-dimension case, and move the 2-dimension case...
	(oln::case_<point_set_hierarchy_wrt_connectivity, E, 2>): ...here
	(new).
	* tests/image1d.cc: New test.
	* tests/Makefile.am (check_PROGRAMS): Add image1d.
	(image1d_SOURCES): New.


git-svn-id: https://svn.lrde.epita.fr/svn/oln/trunk@604 4aad255d-cdde-0310-9447-f3009e2ae8c0
parent 3a331bf9
2006-10-03 Roland Levillain <roland@lrde.epita.fr>
Add oln::image1d and associated types.
* oln/core/1d/image1d.hh, oln/core/1d/array1d.hh,
* oln/core/1d/point1d.hh, oln/core/1d/dpoint1d.hh,
* oln/core/1d/neighb1d.hh, oln/core/1d/aliases.hh,
* oln/basics1d.hh: New.
* oln/core/abstract/point_set_being_connected.hh
(oln::abstract::point_set_being_1d_connected): New class.
(oln::case_<point_set_hierarchy_wrt_connectivity, E, 1>): Handle
the 1-dimension case, and move the 2-dimension case...
(oln::case_<point_set_hierarchy_wrt_connectivity, E, 2>): ...here
(new).
* tests/image1d.cc: New test.
* tests/Makefile.am (check_PROGRAMS): Add image1d.
(image1d_SOURCES): New.
2006-10-03 Roland Levillain <roland@lrde.epita.fr>
Clean up morphers.
......
// 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_BASICS1D_HH
# define OLN_BASICS1D_HH
# include <oln/core/1d/aliases.hh>
# include <oln/core/1d/grid1d.hh>
# include <oln/core/1d/point1d.hh>
namespace oln { template class point1d_<int>; }
# include <oln/core/1d/dpoint1d.hh>
namespace oln { template class dpoint1d_<int>; }
# include <oln/core/gen/bbox.hh>
namespace oln { template class bbox_<point1d>; }
# include <oln/core/gen/topo_lbbox.hh>
namespace oln { template class topo_lbbox_<point1d>; }
# include <oln/core/gen/fwd_piter_bbox.hh>
namespace oln { template class fwd_piter_bbox_<topo1d>; }
# include <oln/core/gen/bkd_piter_bbox.hh>
namespace oln { template class bkd_piter_bbox_<topo1d>; }
# include <oln/core/gen/neighb.hh>
namespace oln { template class neighb_<dpoint1d>; }
# include <oln/core/1d/neighb1d.hh>
# include <oln/core/1d/image1d.hh>
#endif // ! OLN_BASICS1D_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_1D_ALIASES_HH
# define OLN_CORE_1D_ALIASES_HH
namespace oln
{
/// \{
/// Forward declarations.
template <typename C> class point1d_;
template <typename C> class dpoint1d_;
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 grid1d;
/// \}
/// \{
/// Alliases.
typedef point1d_<int> point1d;
typedef dpoint1d_<int> dpoint1d;
typedef neighb_<dpoint1d> neighb1d;
typedef bbox_<point1d> bbox1d;
typedef topo_lbbox_<point1d> topo1d;
typedef fwd_piter_bbox_<topo1d> fwd_piter1d;
typedef bkd_piter_bbox_<topo1d> bkd_piter1d;
typedef point1d_<float> point1df;
typedef dpoint1d_<float> dpoint1df;
/// \}
} // end of namespace oln
#endif // ! OLN_CORE_1D_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_1D_ARRAY1D_HH
# define OLN_CORE_1D_ARRAY1D_HH
# include <cstdlib>
# include <mlc/contract.hh>
namespace oln
{
/// General 1D array class.
template <typename value_t, typename coord_t = int>
class array1d
{
public:
/// Ctor.
array1d(coord_t min, coord_t max) :
min_(min), max_(max)
{
precondition(max >= min);
len_ = max - min + 1;
allocate_();
}
/// Ctor.
array1d(coord_t len) :
min_(0), len_(len)
{
precondition(len > 0);
max_ = min_ + len_;
allocate_();
}
/// Dtor.
~array1d()
{
deallocate_();
}
value_t operator()(coord_t i) const
{
precondition(has(i));
return buffer_[i - min_];
}
value_t& operator()(coord_t i)
{
precondition(has(i));
return buffer_[i - min_];
}
bool has(coord_t i) const
{
return
i >= min_ and i <= max_;
}
size_t memsize() const
{
return size_t(len_) * sizeof(value_t);
}
protected:
coord_t min_, max_;
coord_t len_;
value_t* buffer_;
private:
void allocate_()
{
buffer_ = new value_t[size_t(len_)];
}
void deallocate_()
{
precondition(buffer_ != 0);
delete[] buffer_;
buffer_ = 0; // safety
}
};
} // end of namespace oln
#endif // ! OLN_CORE_1D_ARRAY1D_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_1D_DPOINT1D_HH
# define OLN_CORE_1D_DPOINT1D_HH
# include <mlc/int.hh>
# include <oln/core/1d/point1d.hh>
# include <oln/core/internal/dpoint_nd.hh>
namespace oln
{
/// Super type.
template<typename C>
struct set_super_type< dpoint1d_<C> >
{
typedef internal::dpoint_nd< dpoint1d_<C> > ret;
};
/// Virtual types associated to oln::dpoint1d_<C>.
template <typename C>
struct vtypes< dpoint1d_<C> >
{
typedef grid1d grid_type;
typedef point1d point_type;
typedef C coord_type;
typedef mlc::uint_<1> dim_type;
};
/// General 1D dpoint class.
template <typename C>
class dpoint1d_
: public stc_get_supers(dpoint1d_<C>)
{
typedef dpoint1d_<C> self_t;
typedef stc_get_super(dpoint1d_<C>) super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_;
public:
/// Ctor.
dpoint1d_()
{
}
/// Ctor.
dpoint1d_(const xtd::vec<1,coord_t>& v)
: super_t(v)
{
}
/// Ctor.
dpoint1d_(coord_t index)
: super_t(xtd::mk_vec(index))
{
}
coord_t index() const { return v_[0]; }
coord_t& index() { return v_[0]; }
};
} // end of namespace oln
#endif // ! OLN_CORE_1D_DPOINT1D_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_1D_IMAGE1D_HH
# define OLN_CORE_1D_IMAGE1D_HH
# include <oln/core/image_entry.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/internal/tracked_ptr.hh>
namespace oln
{
// Forward declaration.
template <typename T> class image1d;
/// Virtual types associated to oln::image1d<T>.
template <typename T>
struct vtypes< image1d<T> >
{
typedef topo_lbbox_<point1d> topo_type;
typedef grid1d grid_type;
typedef point1d 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 image1d<T> real_type;
};
/// Super type declaration.
template <typename T>
struct set_super_type< image1d<T> >
{
typedef image1d<T> self_t;
typedef image_entry<self_t> ret;
};
/// General 1D image class.
template <typename T>
class image1d : public image_entry< image1d<T> >
{
typedef image1d<T> self_t;
typedef array1d<T> array_t;
public:
/// Ctor using sizes.
image1d(unsigned nindices, unsigned border = 2)
: topo_(bbox1d(point1d(0), point1d(nindices - 1)), border),
data_(new array_t(0 - border,
nindices - 1 + border))
{
}
/// Ctor using an existing topology.
image1d(const topo1d& topo)
: topo_(topo),
data_(new array_t(topo.bbox().pmin().index(),
topo.bbox().pmax().index()))
{
}
const topo1d& impl_topo() const
{
return topo_;
}
T impl_op_read(const point1d& p) const
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.index());
}
T& impl_op_readwrite(const point1d& p)
{
precondition(data_ != 0);
precondition(topo_.has_large(p));
return data_->operator()(p.index());
}
private:
topo1d topo_;
internal::tracked_ptr<array_t> data_;
};
} // end of namespace oln
#endif // ! OLN_CORE_1D_IMAGE1D_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_1D_NEIGHB1D_HH
# define OLN_CORE_1D_NEIGHB1D_HH
# include <oln/core/gen/neighb.hh>
# include <oln/core/1d/aliases.hh>
namespace oln
{
neighb1d c2()
{
static bool flower = true;
static neighb1d the_;
if (flower)
{
the_.add(dpoint1d(1));
flower = false;
}
return the_;
}
} // end of namespace oln
#endif // ! OLN_CORE_1D_NEIGHB1D_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_1D_POINT1D_HH
# define OLN_CORE_1D_POINT1D_HH
# include <mlc/int.hh>
# include <oln/core/internal/point_nd.hh>
namespace oln
{
/* FIXME: Is this the right place for these functions (on types)?
In particular, the function on dpoint1d should be near the
definition of dpoint1d, not point1d's. */
/// Specializations of functions point and dpoint :
/// \f$(n, coord) \rightarrow type\f$ for \f$n = 1\f$.
/// \{
template <typename C> struct point_ <1, C> { typedef point1d_<C> ret; };
template <typename C> struct dpoint_ <1, C> { typedef dpoint1d_<C> ret; };
/// \}
/// Super type.
template<typename C>
struct set_super_type< point1d_<C> >
{
typedef internal::point_nd< point1d_<C> > ret;
};
/// Virtual types associated to oln::point1d_<C>.
template <typename C>
struct vtypes< point1d_<C> >
{
typedef grid1d grid_type;
typedef dpoint1d dpoint_type;
typedef C coord_type;
typedef mlc::uint_<1> dim_type;
};
/// General 1D point class.
template <typename C>
class point1d_ : public stc_get_supers(point1d_<C>)
{
typedef point1d_<C> self_t;
typedef stc_get_super(point1d_<C>) super_t;
typedef oln_type_of(self_t, coord) coord_t;
using super_t::v_;