Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add infinite point set type.
* oln/core/internal/f_pset_plain.hh: Rename as...
* oln/core/internal/f_pset_to_plain_image.hh: ...this.
(include): Add f_grid_to_plain_image.hh.
(f_pset_plain_, oln_f_pset_plain): Rename as...
(f_pset_to_plain_image_, oln_f_pset_to_plain_image): ...these.
(pset_to_plain_image__): New versions to handle op_<S, such_as, F>
and gen_box<P>.
* oln/core/gen/single_value_image.hh: Update.
* oln/core/gen/infty_pset.hh,
* oln/core/internal/f_grid_to_plain_image.hh,
* oln/core/internal/f_grid_to_box.hh: New.
* oln/core/internal/iterator_on_points_base.hh
(iterator_on_points_base): Rename as...
(iterator_on_points_base_): ...this.
* oln/core/rle/rle_pset.hh,
* oln/core/gen/dpoints_piter.hh,
* oln/core/gen/image_pset_piter.hh,
* oln/core/internal/box.hh,
* oln/core/internal/point_set_std_based.hh,
* oln/core/internal/piter_adaptor.hh: Update.
* oln/draw/bresenham.hh (bresenham_): Rely on level::paste.
(input): Rename as...
(in_out): ...this.
* oln/core/equipment.hh (oln_deduce): New.
* oln/core/gen/pset_compare.hh (intersects): New.
(op_leq_, op_less_): Rename as...
(op_subset_, op_strict_subset_): ...these.
(op_eq_, op_subset_, op_strict_subset_): New versions
for infty_pset.
(operator>=, operator>): Rely on op_subset_ and op_strict_subset_.
* oln/core/gen/pset.hh: Cosmetic changes.
* oln/core/gen/safe_image.hh (pset): Use infty_pset.
(impl_points): New.
* oln/core/internal/image_base.hh: Cosmetic change.
* oln/core/internal/point_base.hh (set_all): New.
core/equipment.hh | 3
core/gen/dpoints_piter.hh | 8 -
core/gen/image_pset_piter.hh | 26 ++---
core/gen/infty_pset.hh | 130 ++++++++++++++++++++++++++++
core/gen/pset.hh | 6 -
core/gen/pset_compare.hh | 139 +++++++++++++++++++++++--------
core/gen/safe_image.hh | 13 ++
core/gen/single_value_image.hh | 7 -
core/internal/box.hh | 12 +-
core/internal/f_grid_to_box.hh | 106 +++++++++++++++++++++++
core/internal/f_grid_to_plain_image.hh | 105 +++++++++++++++++++++++
core/internal/f_pset_to_plain_image.hh | 85 +++++++++++++++---
core/internal/image_base.hh | 2
core/internal/iterator_on_points_base.hh | 36 +++-----
core/internal/piter_adaptor.hh | 6 -
core/internal/point_base.hh | 61 ++-----------
core/internal/point_set_std_based.hh | 14 +--
core/rle/rle_pset.hh | 18 ++--
draw/bresenham.hh | 23 ++---
19 files changed, 615 insertions(+), 185 deletions(-)
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 921)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -100,7 +100,7 @@
/// number of point in the set
unsigned npts;
/// container of the set
- std_container con_;
+ std_container con_; // FIXME: Add a &.
/// pset box
fbbox_<point> fb_;
};
@@ -188,7 +188,7 @@
struct super_trait_< rle_pset_fwd_piter_<P> >
{
typedef rle_pset_fwd_piter_<P> current;
- typedef internal::iterator_on_points_base<current> ret;
+ typedef internal::iterator_on_points_base_<current> ret;
};
// Virtual types
@@ -206,9 +206,9 @@
** P must be a point type
*/
template <typename P>
- class rle_pset_fwd_piter_ : public internal::iterator_on_points_base<rle_pset_fwd_piter_<P> >
+ class rle_pset_fwd_piter_ : public internal::iterator_on_points_base_<rle_pset_fwd_piter_<P> >
{
- typedef internal::iterator_on_points_base< rle_pset_fwd_piter_<P> > super;
+ typedef internal::iterator_on_points_base_< rle_pset_fwd_piter_<P> > super;
typedef rle_pset_fwd_piter_<P> current;
public:
stc_using(point);
@@ -251,7 +251,7 @@
void
rle_pset_fwd_piter_<P>::impl_start()
{
- this->it_ = this->con_.begin();
+ this->it_ = this->con_.begin(); // FIXME: Test if (this->it_ != this->con_.end())...
this->ps_.start_ = this->it_->first;
this->ps_.index_ = 0;
}
@@ -326,7 +326,7 @@
struct super_trait_< rle_pset_bkd_piter_<P> >
{
typedef rle_pset_bkd_piter_<P> current;
- typedef internal::iterator_on_points_base<current> ret;
+ typedef internal::iterator_on_points_base_<current> ret;
};
// Virtual type
@@ -343,9 +343,9 @@
** P must be a point type
*/
template <typename P>
- class rle_pset_bkd_piter_ : public internal::iterator_on_points_base<rle_pset_bkd_piter_<P> >
+ class rle_pset_bkd_piter_ : public internal::iterator_on_points_base_<rle_pset_bkd_piter_<P> >
{
- typedef internal::iterator_on_points_base< rle_pset_bkd_piter_<P> > super;
+ typedef internal::iterator_on_points_base_< rle_pset_bkd_piter_<P> > super;
typedef rle_pset_bkd_piter_<P> current;
public:
stc_using(point);
@@ -386,7 +386,7 @@
void
rle_pset_bkd_piter_<P>::impl_start()
{
- this->it_ = this->con_.rbegin();
+ this->it_ = this->con_.rbegin(); // FIXME: Test if (this->it_ != this->con_.rend())...
this->ps_.start_ = this->it_->first;
this->ps_.index_ = this->it_->second - 1;
}
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 921)
+++ oln/core/equipment.hh (working copy)
@@ -35,9 +35,12 @@
# include <stc/scoop-alt.hh>
# endif
+
# define oln_typename_shortcut__(Type, Alias) typename Type::Alias
+# define oln_deduce(Type, Alias_1, Alias_2) typename Type::Alias_1::Alias_2
+
namespace oln
{
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 921)
+++ oln/core/gen/pset_compare.hh (working copy)
@@ -51,6 +51,13 @@
template <typename L, typename R>
bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
+ template <typename B1, typename B2>
+ bool intersects (const Box<B1>& box1, const Box<B2>& box2);
+
+ template <typename G>
+ class infty_pset;
+
+
# ifndef OLN_INCLUDE_ONLY
@@ -65,6 +72,13 @@
template <typename L, typename R>
bool op_eq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
+ // first quick test
+ if (lhs.npoints() != rhs.npoints())
+ return false;
+ // second quick test
+ if (not intersects(lhs.bbox(), rhs.bbox()))
+ return false;
+ // exhaustive test
oln_piter(L) pl(lhs);
oln_piter(R) pr(rhs);
for (pl.start(), pr.start();
@@ -89,13 +103,40 @@
return lhs.pmin() = rhs.pmin() and lhs.pmax() = rhs.pmax();
}
+ // Versions with infinite set.
+
+ template <typename S, typename G>
+ bool op_eq_(const Point_Set<S>&, const infty_pset<G>&)
+ {
+ return false;
+ }
+
+ template <typename G, typename S>
+ bool op_eq_(const infty_pset<G>&, const Point_Set<S>&)
+ {
+ return false;
+ }
+
+ template <typename G>
+ bool op_eq_(const infty_pset<G>&, const infty_pset<G>&)
+ {
+ return true;
+ }
+
// Point_Set L <= Point_Set R
+ // ------------------------------
+
+ // Generic version.
template <typename L, typename R>
- bool op_leq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ bool op_subset_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
- if (lhs.npoints() > rhs.npoints()) // quick test
+ // first quick test
+ if (lhs.npoints() > rhs.npoints())
+ return false;
+ // second quick test
+ if (not intersects(lhs.bbox(), rhs.bbox()))
return false;
// all points of lhs are IN rhs?
oln_piter(R) p_rhs(rhs);
@@ -111,63 +152,79 @@
return true;
}
-
- // Point_Set L < Point_Set R
+ // Version for Boxes.
template <typename L, typename R>
- bool op_less_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ bool op_subset_(const Box<L>& lhs, const Box<R>& rhs)
+ {
+ for (unsigned i = 0; i < L::n; ++i)
{
- return op_leq_(lhs, rhs) and lhs.npoints() < rhs.npoints();
+ if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i])
+ return false;
+ }
+ return true;
}
+ // Versions with infinite set.
+ template <typename S, typename G>
+ bool op_subset_(const Point_Set<S>&, const infty_pset<G>&)
+ {
+ return true;
+ }
+ template <typename G>
+ bool op_subset_(const infty_pset<G>&, const infty_pset<G>&)
+ {
+ return true;
+ }
+ template <typename G, typename S>
+ bool op_subset_(const infty_pset<G>&, const Point_Set<S>&)
+ {
+ return false;
+ }
- // Box L <= Box R.
+ // Point_Set L < Point_Set R
+ // -----------------------------
+
+ // Generic version.
template <typename L, typename R>
- bool op_leq_(const Box<L>& lhs, const Box<R>& rhs)
+ bool op_strict_subset_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
- for (unsigned i = 0; i < L::n; ++i)
- {
- if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i])
- return false;
- }
- return true;
+ return op_subset_(lhs, rhs) and lhs.npoints() != rhs.npoints();
}
- // Box L < Box R.
+ // Version for Boxes.
template <typename L, typename R>
- bool op_less_(const Box<L>& lhs, const Box<R>& rhs)
+ bool op_strict_subset_(const Box<L>& lhs, const Box<R>& rhs)
{
- return op_leq_(lhs, rhs) and lhs != rhs;
+ return op_subset_(lhs, rhs) and lhs != rhs;
}
- // Box L >= Box R.
+ // Versions with infinite set.
- template <typename L, typename R>
- bool op_geq_(const Box<L>& lhs, const Box<R>& rhs)
- {
- for (unsigned i = 0; i < L::n; ++i)
+ template <typename S, typename G>
+ bool op_strict_subset_(const Point_Set<S>&, const infty_pset<G>&)
{
- if (lhs.pmin()[i] > rhs.pmin()[i] or lhs.pmax()[i] < rhs.pmax()[i])
- return false;
- }
return true;
}
- // Box L > Box R.
-
- template <typename L, typename R>
- bool op_greater_(const Box<L>& lhs, const Box<R>& rhs)
+ template <typename G>
+ bool op_strict_subset_(const infty_pset<G>&, const infty_pset<G>&)
{
- return op_geq_(lhs, rhs) and lhs != rhs;
+ return false;
}
+ template <typename G, typename S>
+ bool op_strict_subset_(const infty_pset<G>&, const Point_Set<S>&)
+ {
+ return false;
+ }
} // end of namespace oln::impl
@@ -185,28 +242,42 @@
bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
assert_same_grid_<L, R>::check();
- return impl::op_leq_(exact(lhs), exact(rhs));
+ return impl::op_subset_(exact(lhs), exact(rhs));
}
template <typename L, typename R>
bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
assert_same_grid_<L, R>::check();
- return impl::op_less_(exact(lhs), exact(rhs));
+ return impl::op_strict_subset_(exact(lhs), exact(rhs));
}
template <typename L, typename R>
bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
assert_same_grid_<L, R>::check();
- return impl::op_geq_(exact(lhs), exact(rhs));
+ return impl::op_subset_(exact(rhs), exact(lhs));
}
template <typename L, typename R>
bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
assert_same_grid_<L, R>::check();
- return impl::op_greater_(exact(lhs), exact(rhs));
+ return impl::op_strict_subset_(exact(rhs), exact(lhs));
+ }
+
+ // Intersects.
+
+ template <typename B1, typename B2>
+ bool intersects (const Box<B1>& box1, const Box<B2>& box2)
+ {
+ assert_same_grid_<B1, B2>::check();
+ for (unsigned i = 0; i < B1::n; ++i)
+ {
+ if (box1.pmax()[i] < box2.pmin()[i] or box2.pmax()[i] < box1.pmin()[i])
+ return false;
+ }
+ return true;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 921)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -52,7 +52,7 @@
struct super_trait_< dpoints_fwd_piter_<P> >
{
typedef dpoints_fwd_piter_<P> current__;
- typedef internal::iterator_on_points_base<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
@@ -66,7 +66,7 @@
// Forward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_fwd_piter_ : public internal::iterator_on_points_base< dpoints_fwd_piter_<P> >,
+ class dpoints_fwd_piter_ : public internal::iterator_on_points_base_< dpoints_fwd_piter_<P> >,
public internal::dpoints_fwd_piter_impl_<P>
{
public:
@@ -99,7 +99,7 @@
struct super_trait_< dpoints_bkd_piter_<P> >
{
typedef dpoints_bkd_piter_<P> current__;
- typedef internal::iterator_on_points_base<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
@@ -113,7 +113,7 @@
/// Backward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_bkd_piter_ : public internal::iterator_on_points_base< dpoints_bkd_piter_<P> >,
+ class dpoints_bkd_piter_ : public internal::iterator_on_points_base_< dpoints_bkd_piter_<P> >,
public internal::dpoints_bkd_piter_impl_<P>
{
public:
Index: oln/core/gen/infty_pset.hh
--- oln/core/gen/infty_pset.hh (revision 0)
+++ oln/core/gen/infty_pset.hh (revision 0)
@@ -0,0 +1,130 @@
+// Copyright (C) 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
+// 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_GEN_INFTY_PSET_HH
+# define OLN_CORE_GEN_INFTY_PSET_HH
+
+# include <limits>
+# include <oln/core/concept/grid.hh>
+# include <oln/core/internal/f_grid_to_box.hh>
+# include <oln/core/internal/point_set_base.hh>
+
+
+namespace oln
+{
+
+ // Fwd decl.
+ template <typename G> class infty_pset;
+
+
+ // Super type.
+ template <typename G>
+ struct super_trait_< infty_pset<G> >
+ {
+ typedef infty_pset<G> current__;
+ typedef internal::point_set_base_<current__> ret;
+ };
+
+
+ // Virtual types.
+ template <typename G>
+ struct vtypes< infty_pset<G> >
+ {
+ typedef oln_f_grid_to_box(G) box;
+ typedef oln_point(box) point;
+
+ // disabled!
+ typedef void fwd_piter;
+ typedef void bkd_piter;
+ };
+
+
+ /// Infinite point set defined over a grid.
+
+ template <typename G>
+ class infty_pset : public internal::point_set_base_< infty_pset<G> >
+ {
+ typedef infty_pset<G> current;
+ typedef internal::point_set_base_<current> super;
+
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ infty_pset();
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const box& impl_bbox() const;
+
+ protected:
+ box b_;
+
+ }; // end of class oln::infty_pset<G>.
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename G>
+ infty_pset<G>::infty_pset()
+ {
+ typedef oln_coord(point) C;
+ point minus_infty, plus_infty;
+ minus_infty.set_all( std::numeric_limits<C>::min() );
+ plus_infty. set_all( std::numeric_limits<C>::max() );
+ this->b_ = init(from(minus_infty), to(plus_infty));
+ }
+
+ template <typename G>
+ unsigned
+ infty_pset<G>::impl_npoints() const
+ {
+ return std::numeric_limits<unsigned>::max();
+ }
+
+ template <typename G>
+ bool
+ infty_pset<G>::impl_has(const point&) const
+ {
+ return true;
+ }
+
+ template <typename G>
+ const typename infty_pset<G>::box&
+ infty_pset<G>::impl_bbox() const
+ {
+ return this->b_;
+ }
+
+#endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_INFTY_PSET_HH
Index: oln/core/gen/pset.hh
--- oln/core/gen/pset.hh (revision 921)
+++ oln/core/gen/pset.hh (working copy)
@@ -35,7 +35,7 @@
namespace oln
{
- /// Fwd decl.
+ // Fwd decl.
template <typename P> class pset_;
@@ -48,7 +48,7 @@
};
- /// Virtual types.
+ // Virtual types.
template <typename P>
struct vtypes< pset_<P> >
{
@@ -85,7 +85,7 @@
return *this;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/single_value_image.hh
--- oln/core/gen/single_value_image.hh (revision 921)
+++ oln/core/gen/single_value_image.hh (working copy)
@@ -30,7 +30,7 @@
# include <oln/core/internal/image_base.hh>
# include <oln/core/internal/utils.hh>
-# include <oln/core/internal/f_pset_plain.hh>
+# include <oln/core/internal/f_pset_to_plain_image.hh>
namespace oln
@@ -56,7 +56,7 @@
typedef internal::pair<Ps, T> data;
- typedef oln_f_pset_plain(Ps, T) plain;
+ typedef oln_f_pset_to_plain_image(Ps, T) plain;
typedef single_value_image<Ps, pl::value> skeleton;
};
@@ -79,7 +79,6 @@
typedef internal::image_base_<current> super;
public:
-
stc_using(point);
stc_using(rvalue);
stc_using(data);
@@ -119,7 +118,7 @@
single_value_image<Ps, T>::impl_owns_(const typename single_value_image<Ps, T>::point& p) const
{
assert(this->has_data());
- return this->data_->first.has(p);
+ return this->data_->first.has(p); // FIXME: or 'always true'?
}
template <typename Ps, typename T>
Index: oln/core/gen/image_pset_piter.hh
--- oln/core/gen/image_pset_piter.hh (revision 921)
+++ oln/core/gen/image_pset_piter.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef OLN_CORE_GEN_IMAGE_PSET_PITER_HH
# define OLN_CORE_GEN_IMAGE_PSET_PITER_HH
-# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
# include <oln/core/concept/point_set.hh>
# include <oln/core/concept/image.hh>
@@ -36,52 +36,52 @@
namespace oln
{
- /// Fwd decls.
+ // Fwd decls.
template <typename Ps> struct image_pset_fwd_piter_;
template <typename Ps> struct image_pset_bkd_piter_;
- /// Super types.
+ // Super types.
template <typename Ps>
struct super_trait_< image_pset_fwd_piter_<Ps> >
{
typedef image_pset_fwd_piter_<Ps> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
template <typename Ps>
struct super_trait_< image_pset_bkd_piter_<Ps> >
{
typedef image_pset_bkd_piter_<Ps> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
- /// Virtual types.
+ // Virtual types.
template <typename Ps>
struct vtypes< image_pset_fwd_piter_<Ps> >
{
- typedef typename Ps::point point;
+ typedef oln_point(Ps) point;
};
template <typename Ps>
struct vtypes< image_pset_bkd_piter_<Ps> >
{
- typedef typename Ps::point point;
+ typedef oln_point(Ps) point;
};
/// Class image_pset_fwd_piter_<Ps>.
template <typename Ps>
- class image_pset_fwd_piter_ : public Iterator_on_Points< image_pset_fwd_piter_<Ps> >,
+ class image_pset_fwd_piter_ : public internal::iterator_on_points_base_< image_pset_fwd_piter_<Ps> >,
private mlc::assert_< mlc_is_a(Ps, Point_Set) >
{
typedef image_pset_fwd_piter_<Ps> current;
- typedef Iterator_on_Points<current> super;
+ typedef internal::iterator_on_points_base_<current> super;
public:
stc_using(point);
@@ -106,11 +106,11 @@
/// Class image_pset_bkd_piter_<Ps>.
template <typename Ps>
- class image_pset_bkd_piter_ : public Iterator_on_Points< image_pset_bkd_piter_<Ps> >,
+ class image_pset_bkd_piter_ : public internal::iterator_on_points_base_< image_pset_bkd_piter_<Ps> >,
private mlc::assert_< mlc_is_a(Ps, Point_Set) >
{
typedef image_pset_fwd_piter_<Ps> current;
- typedef Iterator_on_Points<current> super;
+ typedef internal::iterator_on_points_base_<current> super;
public:
stc_using(point);
@@ -244,7 +244,7 @@
return i_.point_adr();
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/safe_image.hh
--- oln/core/gen/safe_image.hh (revision 921)
+++ oln/core/gen/safe_image.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_GEN_SAFE_IMAGE_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/gen/infty_pset.hh>
namespace oln
@@ -47,6 +48,7 @@
typedef behavior::identity behavior;
typedef internal::singleton<I> data;
+ typedef infty_pset< oln_grid(I) > pset;
typedef safe_image< oln_plain(I) > plain;
typedef safe_image< pl::rec<I> > skeleton;
@@ -76,13 +78,16 @@
stc_using(lvalue);
stc_using(value);
stc_using(data);
+ stc_using(pset);
stc_using(delegatee);
safe_image();
safe_image(Mutable_Image<I>& ima);
bool impl_owns_(const point& p) const;
+ const pset& impl_points() const;
+ // FIXME: Force this type to be read-only?
rvalue impl_read(const point& p) const;
lvalue impl_read_write(const point& p);
void impl_write(const point& p, const value& v);
@@ -126,6 +131,14 @@
}
template <typename I>
+ const typename safe_image<I>::pset&
+ safe_image<I>::impl_points() const
+ {
+ static infty_pset<oln_grid(I)> infty_;
+ return infty_;
+ }
+
+ template <typename I>
typename safe_image<I>::rvalue
safe_image<I>::impl_read(const typename safe_image<I>::point& p) const
{
Index: oln/core/internal/f_grid_to_plain_image.hh
--- oln/core/internal/f_grid_to_plain_image.hh (revision 0)
+++ oln/core/internal/f_grid_to_plain_image.hh (revision 0)
@@ -0,0 +1,105 @@
+// Copyright (C) 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
+// 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_INTERNAL_F_GRID_TO_PLAIN_IMAGE_HH
+# define OLN_CORE_INTERNAL_F_GRID_TO_PLAIN_IMAGE_HH
+
+# include <oln/core/concept/grid.hh>
+
+
+#define oln_f_grid_to_plain_image(G, T) typename oln::internal::f_grid_to_plain_image_< G, T >::ret
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+
+ // Grid types.
+
+ struct grid1d;
+
+ struct grid2d;
+ struct grid2d_hex;
+ struct grid2d_tri;
+
+ // FIXME: 3D...
+
+ // Image types.
+
+ template <typename T> class image1d;
+ template <typename T> class image2d;
+
+ /// \}
+
+
+
+ namespace internal
+ {
+
+ // Fwd decl.
+
+ template <typename G, typename T> struct f_grid_to_plain_image_;
+
+
+ /// \{
+ /// Definitions.
+
+ template <typename G, typename T>
+ struct grid_to_plain_image__;
+
+ template <typename T>
+ struct grid_to_plain_image__< grid1d, T >
+ {
+ typedef image1d<T> ret; // FIXME: or image1d_b<T>?
+ };
+
+ template <typename T>
+ struct grid_to_plain_image__< grid2d, T >
+ {
+ typedef image2d<T> ret; // FIXME: or image2d_b<T>?
+ };
+
+ // FIXME: 2D hex/tri, 3D...
+
+ /// \}
+
+
+ template <typename G, typename T>
+ struct f_grid_to_plain_image_ : private mlc::assert_< mlc_is_a(G, Grid) >,
+ public grid_to_plain_image__< G, T >
+
+ {
+ };
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_F_GRID_TO_PLAIN_IMAGE_HH
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 921)
+++ oln/core/internal/box.hh (working copy)
@@ -117,14 +117,14 @@
struct super_trait_< box_fwd_piter_<B> >
{
typedef box_fwd_piter_<B> current__;
- typedef internal::iterator_on_points_base<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
template <typename B>
struct super_trait_<box_bkd_piter_<B> >
{
typedef box_bkd_piter_<B> current__;
- typedef internal::iterator_on_points_base<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
@@ -146,11 +146,11 @@
/// Class box_fwd_piter_<P>.
template <typename B>
- class box_fwd_piter_ : public internal::iterator_on_points_base< box_fwd_piter_<B> >,
+ class box_fwd_piter_ : public internal::iterator_on_points_base_< box_fwd_piter_<B> >,
private mlc::assert_< mlc_is_a(B, Point_Set) >
{
typedef box_fwd_piter_<B> current;
- typedef Iterator_on_Points<current> super;
+ typedef internal::iterator_on_points_base_<current> super;
public:
stc_using(point);
@@ -172,11 +172,11 @@
/// Class box_bkd_piter_<B>.
template <typename B>
- class box_bkd_piter_ : public internal::iterator_on_points_base< box_bkd_piter_<B> >,
+ class box_bkd_piter_ : public internal::iterator_on_points_base_< box_bkd_piter_<B> >,
private mlc::assert_< mlc_is_a(B, Point_Set) >
{
typedef box_bkd_piter_<B> current;
- typedef Iterator_on_Points<current> super;
+ typedef internal::iterator_on_points_base_<current> super;
public:
stc_using(point);
Index: oln/core/internal/f_grid_to_box.hh
--- oln/core/internal/f_grid_to_box.hh (revision 0)
+++ oln/core/internal/f_grid_to_box.hh (revision 0)
@@ -0,0 +1,106 @@
+// Copyright (C) 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
+// 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_INTERNAL_F_GRID_TO_BOX_HH
+# define OLN_CORE_INTERNAL_F_GRID_TO_BOX_HH
+
+# include <oln/core/concept/grid.hh>
+
+
+#define oln_f_grid_to_box(G) typename oln::internal::f_grid_to_box_< G >::ret
+
+
+namespace oln
+{
+
+ /// \{
+ /// Forward declarations.
+
+ // Grid types.
+
+ struct grid1d;
+
+ struct grid2d;
+ struct grid2d_hex;
+ struct grid2d_tri;
+
+ // FIXME: 3D...
+
+ // Box types.
+
+ struct box1d;
+ struct box2d;
+ template <typename P> class gen_box;
+
+ /// \}
+
+
+
+ namespace internal
+ {
+
+ // Fwd decl.
+
+ template <typename G> struct f_grid_to_;
+
+
+ /// \{
+ /// Definitions.
+
+ template <typename G>
+ struct grid_to_box__;
+
+ template <>
+ struct grid_to_box__< grid1d >
+ {
+ typedef box1d ret;
+ };
+
+ template <>
+ struct grid_to_box__< grid2d >
+ {
+ typedef box2d ret;
+ };
+
+ // FIXME: 2D hex/tri, 3D...
+
+ /// \}
+
+
+ template <typename G>
+ struct f_grid_to_box_ : private mlc::assert_< mlc_is_a(G, Grid) >,
+ public grid_to_box__< G >
+
+ {
+ };
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_F_GRID_TO_BOX_HH
Index: oln/core/internal/point_set_std_based.hh
--- oln/core/internal/point_set_std_based.hh (revision 921)
+++ oln/core/internal/point_set_std_based.hh (working copy)
@@ -176,14 +176,14 @@
struct super_trait_< pset_std_based_fwd_piter_<C> >
{
typedef pset_std_based_fwd_piter_<C> current__;
- typedef internal::iterator_on_points_base<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
template <typename C>
struct super_trait_< pset_std_based_bkd_piter_<C> >
{
typedef pset_std_based_bkd_piter_<C> current__;
- typedef internal::iterator_on_points_base<current__> ret;
+ typedef internal::iterator_on_points_base_<current__> ret;
};
@@ -206,10 +206,10 @@
// Class pset_std_based_fwd_piter_<C>.
template <typename C>
- class pset_std_based_fwd_piter_ : public internal::iterator_on_points_base< pset_std_based_fwd_piter_<C> >
+ class pset_std_based_fwd_piter_ : public internal::iterator_on_points_base_< pset_std_based_fwd_piter_<C> >
{
typedef pset_std_based_fwd_piter_<C> current;
- typedef internal::iterator_on_points_base<current> super;
+ typedef internal::iterator_on_points_base_<current> super;
public:
stc_using(point);
@@ -235,10 +235,10 @@
// Class pset_std_based_bkd_piter_<C>.
template <typename C>
- class pset_std_based_bkd_piter_ : public internal::iterator_on_points_base< pset_std_based_bkd_piter_<C> >
+ class pset_std_based_bkd_piter_ : public internal::iterator_on_points_base_< pset_std_based_bkd_piter_<C> >
{
typedef pset_std_based_bkd_piter_<C> current;
- typedef internal::iterator_on_points_base<current> super;
+ typedef internal::iterator_on_points_base_<current> super;
public:
stc_using(point);
@@ -374,7 +374,7 @@
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 921)
+++ oln/core/internal/image_base.hh (working copy)
@@ -148,7 +148,7 @@
// Final.
typedef stc::final< stc::is<Image> > category;
- typedef stc::final <typename pset__::box> box;
+ typedef stc::final< oln_box(pset__) > box;
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< oln_dpoint(point__) > dpoint;
typedef stc::final< oln_fwd_piter(pset__) > fwd_piter;
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 921)
+++ oln/core/internal/point_base.hh (working copy)
@@ -95,6 +95,7 @@
typedef xtd::vec<n, coord> vec_t;
const vec_t& vec() const;
vec_t& vec();
+ void set_all(const coord& c);
protected:
point_base_();
@@ -148,15 +149,22 @@
}
template <typename Exact>
+ void
+ point_base_<Exact>::set_all(const typename point_base_<Exact>::coord& c)
+ {
+ v_.set_all(c);
+ }
+
+ template <typename Exact>
point_base_<Exact>::point_base_()
{
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
+ } // end of namespace oln::internal
- } // end of namespace oln::internal
template <typename Exact>
@@ -173,57 +181,10 @@
return ostr;
}
-# endif
-
-
-
-// /// internal::point_base_ + internal::dpoint_base_
-// template <typename P, typename D>
-// struct case_ < xtd::op_plus, mlc::pair_<P,D>,
-// oln::id::op_plus_pointnd_dpointnd >
-// : where_< mlc::and_< mlc_is_a(P, internal::point_base_),
-// mlc_is_a(D, internal::dpoint_base_) > >
-// {
-// typedef oln_vtype(P, coord) P_coord;
-// typedef oln_vtype(D, coord) D_coord;
-// typedef xtd_op_plus_trait(P_coord, D_coord) coord;
-// typedef oln_vtype(P, dim) dim;
-// typedef typename point_<mlc_value(dim), coord>::ret ret;
-// };
-
-
-// /// internal::point_base_ - internal::dpoint_base_
-// template <typename P, typename D>
-// struct case_ < xtd::op_minus, mlc::pair_<P,D>,
-// oln::id::op_minus_pointnd_dpointnd >
-// : where_< mlc::and_< mlc_is_a(P, internal::point_base_),
-// mlc_is_a(D, internal::dpoint_base_) > >
-// {
-// typedef oln_vtype(P, coord) P_coord;
-// typedef oln_vtype(D, coord) D_coord;
-// typedef xtd_op_minus_trait(P_coord, D_coord) coord;
-// typedef oln_vtype(P, dim) dim;
-// typedef typename point_<mlc_value(dim), coord>::ret ret;
-// };
-
-
-// /// internal::point_base_ - internal::point_base_
-// template <typename P1, typename P2>
-// struct case_ < xtd::op_minus, mlc::pair_<P1,P2>,
-// oln::id::op_minus_pointnd_pointnd >
-// : where_< mlc::and_< mlc_is_a(P1, internal::point_base_),
-// mlc_is_a(P2, internal::point_base_) > >
-// {
-// typedef oln_vtype(P1, coord) P1_coord;
-// typedef oln_vtype(P2, coord) P2_coord;
-// typedef xtd_op_minus_trait(P1_coord, P2_coord) coord;
-// typedef oln_vtype(P1, dim) dim;
-// typedef typename dpoint_<mlc_value(dim), coord>::ret ret;
-// };
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
-
#endif // ! OLN_CORE_INTERNAL_POINT_BASE_HH
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 921)
+++ oln/core/internal/piter_adaptor.hh (working copy)
@@ -43,7 +43,7 @@
template <typename Exact>
struct super_trait_< internal::piter_adaptor_<Exact> >
{
- typedef internal::iterator_on_points_base<Exact> ret;
+ typedef internal::iterator_on_points_base_<Exact> ret;
};
@@ -65,9 +65,9 @@
// defined over other types of iterator on points.
template <typename Exact>
- class piter_adaptor_ : public internal::iterator_on_points_base<Exact>
+ class piter_adaptor_ : public internal::iterator_on_points_base_<Exact>
{
- typedef internal::iterator_on_points_base<Exact> super;
+ typedef internal::iterator_on_points_base_<Exact> super;
public:
stc_using(point);
Index: oln/core/internal/f_pset_to_plain_image.hh
--- oln/core/internal/f_pset_to_plain_image.hh (revision 921)
+++ oln/core/internal/f_pset_to_plain_image.hh (working copy)
@@ -25,41 +25,96 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_INTERNAL_F_PSET_PLAIN_HH
-# define OLN_CORE_INTERNAL_F_PSET_PLAIN_HH
+#ifndef OLN_CORE_INTERNAL_F_PSET_TO_PLAIN_IMAGE_HH
+# define OLN_CORE_INTERNAL_F_PSET_TO_PLAIN_IMAGE_HH
# include <oln/core/concept/point_set.hh>
+# include <oln/core/internal/f_grid_to_plain_image.hh>
-#define oln_f_pset_plain(Ps, T) typename oln::internal::f_pset_plain_< Ps, T >::ret
+#define oln_f_pset_to_plain_image(Ps, T) typename oln::internal::f_pset_to_plain_image_< Ps, T >::ret
namespace oln
{
- // Fwd decls.
- struct grid2d;
- template <typename P> class box_;
+ /// \{
+ /// Forward declarations.
+
+ // point set types
+ template <typename P> class gen_box;
+ class box1d;
class box2d;
- template <typename T> class image2d;
- template <typename T> class image2d_b;
+ // FIXME: ...
+
+ // gen
+ struct such_as;
+ struct restricted_to;
+ template <typename L, typename OpName, typename R> class op_;
+
+ /// \}
+
namespace internal
{
- template <typename Gr, typename Ps, typename T>
- struct f_pset_plain__;
+ // Fwd decl.
+
+ template <typename Ps, typename T> struct f_pset_to_plain_image_;
+
+
+ /// \{
+ /// Definitions.
+
+ template <typename Ps, typename T>
+ struct pset_to_plain_image__
+ {
+ typedef oln_f_grid_to_plain_image(oln_grid(Ps), T) I;
+ typedef op_< I, restricted_to, Ps > ret;
+ };
+
+ template <typename Ps, typename T>
+ struct pset_to_plain_image__< const Ps, T >
+ :
+ public pset_to_plain_image__< Ps, T >
+ {
+ };
+
+ template <typename T>
+ struct pset_to_plain_image__< box1d, T >
+ {
+ typedef oln_f_grid_to_plain_image(grid1d, T) ret;
+ };
template <typename T>
- struct f_pset_plain__< grid2d, box2d, T >
+ struct pset_to_plain_image__< box2d, T >
+ {
+ typedef oln_f_grid_to_plain_image(grid2d, T) ret;
+ };
+
+ // ...
+
+ template <typename P, typename T>
+ struct pset_to_plain_image__< gen_box<P>, T >
{
- typedef image2d/*_b*/<T> ret; // FIXME: this type is not always known!
+ typedef oln_f_grid_to_plain_image(oln_grid(P), T) ret;
};
+ template <typename S, typename F, typename T>
+ struct pset_to_plain_image__< op_<S, such_as, F>, T >
+ {
+ typedef op_<S, such_as, F> Ps;
+ typedef typename f_pset_to_plain_image_<S, T>::ret I;
+ typedef op_<I, restricted_to, Ps> ret;
+ };
+
+ /// \}
+
+
template <typename Ps, typename T>
- struct f_pset_plain_ : private mlc::assert_< mlc_is_a(Ps, Point_Set) >,
- public f_pset_plain__< stc_type(Ps, grid), Ps, T >
+ struct f_pset_to_plain_image_ : private mlc::assert_< mlc_is_a(Ps, Point_Set) >,
+ public pset_to_plain_image__< Ps, T >
{
};
@@ -69,4 +124,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_INTERNAL_F_PSET_PLAIN_HH
+#endif // ! OLN_CORE_INTERNAL_F_PSET_TO_PLAIN_IMAGE_HH
Index: oln/core/internal/iterator_on_points_base.hh
--- oln/core/internal/iterator_on_points_base.hh (revision 921)
+++ oln/core/internal/iterator_on_points_base.hh (working copy)
@@ -30,60 +30,52 @@
# include <oln/core/concept/iterator_on_points.hh>
+
namespace oln
{
- // implementation
-
-
- // Forward Declarations
-
- namespace internal {
- template <typename Exact>
- struct iterator_on_points_base; // FIXME: End with '_'!
- }
+ // Fwd decl
+ namespace internal { template <typename Exact> struct iterator_on_points_base_; }
// Super type
-
template <typename Exact>
- struct super_trait_< internal::iterator_on_points_base<Exact> >
+ struct super_trait_< internal::iterator_on_points_base_<Exact> >
{
typedef Iterator_on_Points<Exact> ret;
};
// Virtual types
-
template <typename Exact>
- struct vtypes< internal::iterator_on_points_base<Exact> >
+ struct vtypes< internal::iterator_on_points_base_<Exact> >
{
+ typedef stc::final< stc::is<Iterator_on_Points> > category;
+
typedef stc::abstract point;
typedef stc_deferred(point) point__;
- typedef stc::final<typename point__::grid> grid;
- typedef stc::final<typename point__::coord> coord;
- typedef stc::final<typename point__::dim> dim;
- typedef stc::final<typename point__::dpoint> dpoint;
+ typedef stc::final< oln_grid(point__) > grid;
+ typedef stc::final< oln_coord(point__) > coord;
+ typedef stc::final< oln_dim(point__) > dim;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
};
namespace internal
{
- // iterator_on_points_base class
template <typename Exact>
- class iterator_on_points_base : public Iterator_on_Points<Exact>
+ class iterator_on_points_base_ : public Iterator_on_Points<Exact>
{
-
protected:
- iterator_on_points_base();
+ iterator_on_points_base_();
};
# ifndef OLN_INCLUDE_ONLY
template <typename Exact>
- iterator_on_points_base<Exact>::iterator_on_points_base()
+ iterator_on_points_base_<Exact>::iterator_on_points_base_()
{
}
Index: oln/draw/bresenham.hh
--- oln/draw/bresenham.hh (revision 921)
+++ oln/draw/bresenham.hh (working copy)
@@ -29,10 +29,9 @@
# define OLN_DRAW_BRESENHAM_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/gen/safe_image.hh>
# include <oln/core/2d/line2d.hh>
# include <oln/core/gen/single_value_image.hh>
-// # include <oln/level/paste.hh>
+# include <oln/level/paste.hh>
@@ -45,7 +44,7 @@
// Fwd decl.
template <typename I>
- void bresenham(Mutable_Image<I>& input,
+ void bresenham(Mutable_Image<I>& in_out,
const oln_point(I)& begin, const oln_point(I)& end,
const oln_value(I)& value);
@@ -56,18 +55,14 @@
{
template <typename I>
- void bresenham_(Mutable_Image<I>& input,
+ void bresenham_(Mutable_Image<I>& in_out,
const oln_point(I)& begin, const oln_point(I)& end,
const oln_value(I)& value)
{
- line2d l(begin, end);
- safe_image<I> input_(input);
-// // FIXME: rec pb.
-// single_value_image<typename I::pset, oln_value(I)> tmp(input.points(), value);
-// level::paste((tmp | l), input);
- typename line2d::piter p(l); // FIXME: Generalize with an 'assign' routine...
- for_all(p)
- input_(p) = value;
+ line2d line(begin, end);
+ single_value_image<line2d, oln_value(I)> line_image(line, value);
+ level::paste(line_image, in_out);
+ // FIXME: Make it as simple as level::paste(line2d(begin, end) + value, in_out);
}
} // end of namespace oln::draw::impl
@@ -75,11 +70,11 @@
// Facade.
template <typename I>
- void bresenham(Mutable_Image<I>& input,
+ void bresenham(Mutable_Image<I>& in_out,
const oln_point(I)& begin, const oln_point(I)& end,
const oln_value(I)& value)
{
- impl::bresenham_(exact(input), begin, end, value);
+ impl::bresenham_(exact(in_out), begin, end, value);
}
# endif // ! OLN_INCLUDE_ONLY
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Enforce impl check in concepts.
* oln/core/rle/rle_pset.hh (box, impl_bbox): Fix.
* oln/core/concept/iterator_on_points.hh,
* oln/core/concept/generator.hh,
* oln/core/concept/point.hh,
* oln/core/concept/iterator.hh,
* oln/core/concept/dpoint.hh,
* oln/core/concept/point_set.hh (check__): New.
* oln/core/gen/literal.hh (operator()): Use typedefs.
* oln/core/internal/f_pset_plain.hh (box2d) : Fix.
* oln/draw/bresenham.hh (fill): Move overload with values to...
* oln/level/fill.hh: ...this new file.
* oln/debug/fill.hh: New; extracted from oln/level/fill.hh.
* oln/level/paste.hh; New.
core/concept/dpoint.hh | 23 +++++++++-
core/concept/generator.hh | 10 ++++
core/concept/iterator.hh | 19 ++++++++
core/concept/iterator_on_points.hh | 18 +++++++-
core/concept/point.hh | 20 ++++++++
core/concept/point_set.hh | 15 ++++--
core/gen/literal.hh | 6 +-
core/internal/f_pset_plain.hh | 9 ++--
core/rle/rle_pset.hh | 8 +--
debug/fill.hh | 61 +++++++++++++++++++++++++++
draw/bresenham.hh | 5 ++
level/fill.hh | 72 ++++++++++++--------------------
level/paste.hh | 83 +++++++++++++++++++++++++++++++++++++
13 files changed, 284 insertions(+), 65 deletions(-)
Index: oln/debug/fill.hh
--- oln/debug/fill.hh (revision 0)
+++ oln/debug/fill.hh (revision 0)
@@ -0,0 +1,61 @@
+// Copyright (C) 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
+// 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_DEBUG_FILL_HH
+# define OLN_DEBUG_FILL_HH
+
+# include <oln/core/concept/image.hh>
+
+
+namespace oln
+{
+
+ namespace debug
+ {
+
+ template <typename I, typename V>
+ void fill(Mutable_Image<I>& input, const V values[]);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ void fill(Mutable_Image<I>& input, const oln_value(I)& value)
+ {
+ oln_piter(I) p(input.points());
+ for_all(p)
+ input(p) = value;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::debug
+
+} // end of namespace oln
+
+
+#endif // ! OLN_DEBUG_FILL_HH
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 920)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -32,13 +32,11 @@
# include <utility>
# include <oln/core/rle/rle_psite.hh>
-
# include <oln/core/internal/point_set_base.hh>
-
# include <oln/core/internal/iterator_on_points_base.hh>
-
# include <oln/core/gen/fbbox.hh>
+
namespace oln
{
@@ -61,7 +59,7 @@
{
typedef P point;
- typedef gen_box<P> box;
+ typedef typename f_box_from_point_<P>::ret box;
typedef rle_pset_fwd_piter_<P> fwd_piter;
typedef rle_pset_bkd_piter_<P> bkd_piter;
};
@@ -145,7 +143,7 @@
const typename rle_pset<P>::box&
rle_pset<P>::impl_bbox() const
{
- return fb_;
+ return fb_.box();
}
template <typename P>
Index: oln/core/concept/iterator_on_points.hh
--- oln/core/concept/iterator_on_points.hh (revision 920)
+++ oln/core/concept/iterator_on_points.hh (working copy)
@@ -50,12 +50,15 @@
point to_point() const;
const point* point_adr() const;
- // Default.
+ // Final.
operator point() const;
protected:
Iterator_on_Points();
+ private:
+ void check__() const;
+
}; // end of class oln::Iterator_on_Points<Exact>
@@ -91,6 +94,17 @@
Iterator_on_Points<Exact>::Iterator_on_Points()
{
mlc::assert_< mlc_is_a(typename Iterator_on_Points<Exact>::point, Point) >::check();
+ this->check__();
+ }
+
+ template <typename Exact>
+ void Iterator_on_Points<Exact>::check__() const
+ {
+ point (Exact::*impl_to_point_adr)() const = & Exact::impl_to_point;
+ impl_to_point_adr = 0;
+ const point* (Exact::*impl_point_adr_adr)() const = & Exact::impl_point_adr;
+ impl_point_adr_adr = 0;
+ // FIXME: & Exact::operator point...
}
template <typename Exact>
@@ -99,7 +113,7 @@
return ostr << pit.to_point();
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/generator.hh
--- oln/core/concept/generator.hh (revision 920)
+++ oln/core/concept/generator.hh (working copy)
@@ -41,6 +41,9 @@
{
protected:
Generator();
+
+ private:
+ void check__() const;
};
@@ -50,6 +53,13 @@
template <typename Exact>
Generator<Exact>::Generator()
{
+ this->check__();
+ }
+
+ template <typename Exact>
+ void Generator<Exact>::check__() const
+ {
+ // FIXME: Is it possible to check Exact's body?
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/concept/iterator.hh
--- oln/core/concept/iterator.hh (revision 920)
+++ oln/core/concept/iterator.hh (working copy)
@@ -54,6 +54,9 @@
protected:
Iterator();
+ private:
+ void check__() const;
+
}; // end of class oln::Iterator<Exact>
@@ -88,9 +91,23 @@
template <typename Exact>
Iterator<Exact>::Iterator()
{
+ this->check__();
+ }
+
+ template <typename Exact>
+ void Iterator<Exact>::check__() const
+ {
+ void (Exact::*impl_start_adr)() = & Exact::impl_start;
+ impl_start_adr = 0;
+ void (Exact::*impl_next_adr)() = & Exact::impl_next;
+ impl_next_adr = 0;
+ void (Exact::*impl_invalidate_adr)() = & Exact::impl_invalidate;
+ impl_invalidate_adr = 0;
+ bool (Exact::*impl_is_valid_adr)() const = & Exact::impl_is_valid;
+ impl_is_valid_adr = 0;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 920)
+++ oln/core/concept/point.hh (working copy)
@@ -69,6 +69,9 @@
protected:
Point();
+ private:
+ void check__() const;
+
}; // end of oln::Point<Exact>
@@ -158,12 +161,29 @@
template <typename Exact>
Point<Exact>::Point()
{
+ this->check__();
+ // FIXME: Uncomment!
// mlc::assert_defined_< oln_vtype(Exact, grid) >::check();
// mlc::assert_defined_< oln_vtype(Exact, dPoint) >::check();
// mlc::assert_defined_< oln_vtype(Exact, coord) >::check();
// mlc::assert_defined_< oln_vtype(Exact, dim) >::check();
}
+ template <typename Exact>
+ void Point<Exact>::check__() const
+ {
+ bool (Exact::*impl_op_equal_adr)(const Exact& rhs) const = & Exact::impl_op_equal_;
+ impl_op_equal_adr = 0;
+ bool (Exact::*impl_op_less_adr)(const Exact& rhs) const = & Exact::impl_op_less_;
+ impl_op_less_adr = 0;
+ Exact& (Exact::*impl_op_plus_equal_adr)(const dpoint& rhs) = & Exact::impl_op_plus_equal_;
+ impl_op_plus_equal_adr = 0;
+ Exact& (Exact::*impl_op_minus_equal_adr)(const dpoint& rhs) = & Exact::impl_op_minus_equal_;
+ impl_op_minus_equal_adr = 0;
+ dpoint (Exact::*impl_op_minus_adr)(const Exact& rhs) const = & Exact::impl_op_minus_;
+ impl_op_minus_adr = 0;
+ }
+
template <typename P>
typename P::dpoint
operator-(const Point<P>& lhs, const Point<P>& rhs)
Index: oln/core/concept/dpoint.hh
--- oln/core/concept/dpoint.hh (revision 920)
+++ oln/core/concept/dpoint.hh (working copy)
@@ -77,6 +77,9 @@
protected:
Dpoint();
+ private:
+ void check__() const;
+
}; // end of oln::Dpoint<Exact>
@@ -158,6 +161,8 @@
template <typename Exact>
Dpoint<Exact>::Dpoint()
{
+ this->check__();
+ // FIXME: Uncomment!
// mlc::assert_defined_< oln_vtype(Exact, grid) >::check();
// mlc::assert_defined_< oln_vtype(Exact, point) >::check();
// mlc::assert_defined_< oln_vtype(Exact, coord) >::check();
@@ -165,6 +170,22 @@
}
+ template <typename Exact>
+ void Dpoint<Exact>::check__() const
+ {
+ bool (Exact::*impl_op_equal_adr)(const Exact& rhs) const = & Exact::impl_op_equal_;
+ impl_op_equal_adr = 0;
+ bool (Exact::*impl_op_less_adr)(const Exact& rhs) const = & Exact::impl_op_less_;
+ impl_op_less_adr = 0;
+ Exact& (Exact::*impl_op_plus_equal_adr)(const Exact& rhs) = & Exact::impl_op_plus_equal_;
+ impl_op_plus_equal_adr = 0;
+ Exact& (Exact::*impl_op_minus_equal_adr)(const Exact& rhs) = & Exact::impl_op_minus_equal_;
+ impl_op_minus_equal_adr = 0;
+ Exact (Exact::*impl_op_unary_minus_adr)() const = & Exact::impl_op_unary_minus_;
+ impl_op_unary_minus_adr = 0;
+ }
+
+
/// \{
/// Operators.
@@ -184,7 +205,7 @@
/// \}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/point_set.hh
--- oln/core/concept/point_set.hh (revision 920)
+++ oln/core/concept/point_set.hh (working copy)
@@ -59,7 +59,9 @@
protected:
Point_Set();
- ~Point_Set();
+
+ private:
+ void check__() const;
}; // end of oln::Point_Set<Exact>
@@ -115,13 +117,18 @@
template <typename Exact>
Point_Set<Exact>::Point_Set()
{
+ this->check__();
}
template <typename Exact>
- Point_Set<Exact>::~Point_Set()
+ void Point_Set<Exact>::check__() const
{
- // FIXME: check method impls.
- // unsigned (Exact::*m)() const = & Exact::impl_npoints;
+ unsigned (Exact::*impl_npoints_adr)() const = & Exact::impl_npoints;
+ impl_npoints_adr = 0;
+ bool (Exact::*impl_has_adr)(const point& p) const = & Exact::impl_has;
+ impl_has_adr = 0;
+ const box& (Exact::*impl_bbox_adr)() const = & Exact::impl_bbox;
+ impl_bbox_adr = 0;
}
template <typename Exact>
Index: oln/core/gen/literal.hh
--- oln/core/gen/literal.hh (revision 920)
+++ oln/core/gen/literal.hh (working copy)
@@ -47,16 +47,16 @@
template <typename T>
struct literal_ : public Generator< literal_<T> >
{
- typedef T result;
+ typedef const T& result;
literal_(const T& val) : val_(val) {}
- const result& operator()() const
+ result operator()() const
{
return this->val_;
}
- const result& value() const
+ result value() const
{
return this->val_;
}
Index: oln/core/internal/f_pset_plain.hh
--- oln/core/internal/f_pset_plain.hh (revision 920)
+++ oln/core/internal/f_pset_plain.hh (working copy)
@@ -38,9 +38,10 @@
{
// Fwd decls.
- struct grid2d_rec;
+ struct grid2d;
template <typename P> class box_;
- typedef box_<point2d> box2d;
+ class box2d;
+ template <typename T> class image2d;
template <typename T> class image2d_b;
@@ -51,9 +52,9 @@
struct f_pset_plain__;
template <typename T>
- struct f_pset_plain__< grid2d_rec, box2d, T >
+ struct f_pset_plain__< grid2d, box2d, T >
{
- typedef image2d_b<T> ret;
+ typedef image2d/*_b*/<T> ret; // FIXME: this type is not always known!
};
template <typename Ps, typename T>
Index: oln/draw/bresenham.hh
--- oln/draw/bresenham.hh (revision 920)
+++ oln/draw/bresenham.hh (working copy)
@@ -31,6 +31,8 @@
# include <oln/core/concept/image.hh>
# include <oln/core/gen/safe_image.hh>
# include <oln/core/2d/line2d.hh>
+# include <oln/core/gen/single_value_image.hh>
+// # include <oln/level/paste.hh>
@@ -60,6 +62,9 @@
{
line2d l(begin, end);
safe_image<I> input_(input);
+// // FIXME: rec pb.
+// single_value_image<typename I::pset, oln_value(I)> tmp(input.points(), value);
+// level::paste((tmp | l), input);
typename line2d::piter p(l); // FIXME: Generalize with an 'assign' routine...
for_all(p)
input_(p) = value;
Index: oln/level/fill.hh
--- oln/level/fill.hh (revision 920)
+++ oln/level/fill.hh (working copy)
@@ -49,27 +49,24 @@
namespace level
{
- /// Fwd decls.
+ // Fwd decls.
template <typename I>
- void fill(Mutable_Image<I>& input, const oln_value(I)& value);
-
- template <typename I, typename V>
- void fill(Mutable_Image<I>& input, const V values[]);
+ void fill(Mutable_Image<I>& target, /* with */ const oln_value(I)& value);
template <typename I, typename J>
- void fill(Mutable_Image<I>& input, const Image<J>& ima);
+ void fill(Mutable_Image<I>& target, /* with */ const Image<J>& data);
template <typename I, typename F>
- void fill(Mutable_Image<I>& input, const Function_p2v<F>& fun);
+ void fill(Mutable_Image<I>& target, /* with */ const Function_p2v<F>& fun);
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(P));
+ void fill(Mutable_Image<I>& target, /* with */ V (*fun)(P));
// FIXME: Inactivated.
// template <typename I>
-// void fill(Value_Wise_Mutable_Image<I>& input, const oln_value(I)& value);
+// void fill(Value_Wise_Mutable_Image<I>& target, const oln_value(I)& value);
# ifndef OLN_INCLUDE_ONLY
@@ -79,45 +76,36 @@
{
template <typename I>
- void fill_from_value_(Mutable_Image<I>& input, const oln_value(I)& value)
- {
- oln_piter(I) p(input.points());
- for_all(p)
- input(p) = value;
- }
-
- template <typename I, typename V>
- void fill_from_values_(Mutable_Image<I>& input, const V values[])
+ void fill_from_value_(Mutable_Image<I>& target, const oln_value(I)& value)
{
- oln_piter(I) p(input.points());
- unsigned i = 0;
+ oln_piter(I) p(target.points());
for_all(p)
- input(p) = values[i++];
+ target(p) = value;
}
template <typename I, typename J>
- void fill_from_image_(Mutable_Image<I>& input, const Image<J>& ima)
+ void fill_from_image_(Mutable_Image<I>& target, const Image<J>& data)
{
- oln_piter(I) p(input.points());
+ oln_piter(I) p(target.points());
for_all(p)
- input(p) = ima(p);
+ target(p) = data(p);
}
template <typename I, typename F>
- void fill_from_function_(Mutable_Image<I>& input, const F& f)
+ void fill_from_function_(Mutable_Image<I>& target, const F& f)
{
- oln_piter(I) p(input.points());
+ oln_piter(I) p(target.points());
for_all(p)
- input(p) = f(p);
+ target(p) = f(p);
}
// template <typename I>
-// void fill_(Value_Wise_Mutable_Image<I>& input,
+// void fill_(Value_Wise_Mutable_Image<I>& target,
// const oln_value(I)& value)
// {
-// oln_viter(I) v(input);
+// oln_viter(I) v(target);
// for_all(v)
-// input.value_(v) = value;
+// target.value_(v) = value;
// }
} // end of namespace oln::level::impl
@@ -127,36 +115,30 @@
/// Facades.
template <typename I>
- void fill(Mutable_Image<I>& input, const oln_value(I)& value)
- {
- impl::fill_from_value_(exact(input), value);
- }
-
- template <typename I, typename V>
- void fill(Mutable_Image<I>& input, const V values[])
+ void fill(Mutable_Image<I>& target, const oln_value(I)& value)
{
- impl::fill_from_values_(exact(input), values);
+ impl::fill_from_value_(exact(target), value);
}
template <typename I, typename J>
- void fill(Mutable_Image<I>& input, const Image<J>& ima)
+ void fill(Mutable_Image<I>& target, const Image<J>& data)
{
assert_same_grid_<I, J>::check();
- precondition(input.points() <= ima.points());
- impl::fill_from_image_(exact(input), exact(ima));
+ precondition(target.points() <= data.points());
+ impl::fill_from_image_(exact(target), exact(data));
}
template <typename I, typename F>
- void fill(Mutable_Image<I>& input, const Function_p2v<F>& fun)
+ void fill(Mutable_Image<I>& target, const Function_p2v<F>& fun)
{
- impl::fill_from_function_(exact(input), exact(fun));
+ impl::fill_from_function_(exact(target), exact(fun));
}
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*f)(P))
+ void fill(Mutable_Image<I>& target, V (*f)(P))
{
mlc::assert_< mlc_is_a(P, Point) >::check(); // FIXME: Add err msg.
- impl::fill_from_function_(exact(input), functorize_p2v(f));
+ impl::fill_from_function_(exact(target), functorize_p2v(f));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/level/paste.hh
--- oln/level/paste.hh (revision 0)
+++ oln/level/paste.hh (revision 0)
@@ -0,0 +1,83 @@
+// Copyright (C) 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
+// 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_LEVEL_PASTE_HH
+# define OLN_LEVEL_PASTE_HH
+
+# include <oln/core/concept/image.hh>
+
+
+namespace oln
+{
+
+ namespace level
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename J>
+ void paste(const Image<I>& data, /* in */ Mutable_Image<J>& destination);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename J>
+ void paste_(const Image<I>& data, Mutable_Image<J>& destination)
+ {
+ oln_piter(I) p(data.points());
+ for_all(p)
+ destination(p) = data(p);
+ }
+
+ // FIXME: Fast version...
+
+ } // end of namespace oln::level::impl
+
+
+ // Facade.
+
+ template <typename I, typename J>
+ void paste(const Image<I>& data, Mutable_Image<J>& destination)
+ {
+ assert_same_grid_<I, J>::check();
+ precondition(data.points() <= destination.points());
+ impl::paste_(exact(data), exact(destination));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::level
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_PASTE_HH
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix CC_tarjan + test, sequential reconstruction.
* tests/algorithms/cc_tarjan.cc: .
* oln/morpho/reconstruction.hh: New.
* oln/morpho/cc_tarjan.hh: .
* oln/io/pnm.hh: .
oln/io/pnm.hh | 53 ++++++++++++++--------------
oln/morpho/cc_tarjan.hh | 9 +---
oln/morpho/reconstruction.hh | 78 ++++++++++++++++++++++++++++++++++++++++++
tests/algorithms/cc_tarjan.cc | 52 ++++++++++------------------
4 files changed, 128 insertions(+), 64 deletions(-)
Index: tests/algorithms/cc_tarjan.cc
--- tests/algorithms/cc_tarjan.cc (revision 919)
+++ tests/algorithms/cc_tarjan.cc (working copy)
@@ -4,42 +4,30 @@
#include <oln/morpho/cc_tarjan.hh>
-#include <oln/debug/print.hh>
-
-
-template <typename I>
-void set(I& ima,
- int i,
- int j)
-{
- oln_point(I) p(i, j);
- ima(p) = true;
-}
-
int main()
{
using namespace oln;
typedef image2d<bool> I;
I ima(3, 3);
- set(ima, 0, 0);
- set(ima, 0, 1);
- set(ima, 0, 2);
-
- set(ima, 2, 0);
- set(ima, 2, 1);
- set(ima, 2, 2);
-
- I out = morpho::cc_tarjan(ima + c4);
-
-// for (unsigned i; i < 3; i++)
-// for (unsigned j; j < 3; j++)
-// {
-// if (i == 0)
-// assert(ima(i, j) == 1);
-// if (i == 1)
-// assert(ima(i, j) == 0);
-// if (i == 2)
-// assert(ima(i, j) == 2);
-// }
+ ima.at(0, 0) = true;
+ ima.at(0, 1) = true;
+ ima.at(0, 2) = true;
+
+ ima.at(2, 0) = true;
+ ima.at(2, 1) = true;
+ ima.at(2, 2) = true;
+
+ image2d<unsigned int> out = (morpho::cc_tarjan(ima + c4)).image();
+
+ for (unsigned i = 0; i < 3; i++)
+ for (unsigned j = 0; j < 3; j++)
+ {
+ if (i == 0)
+ assert(out.at(i, j) == 1);
+ if (i == 1)
+ assert(out.at(i, j) == 0);
+ if (i == 2)
+ assert(out.at(i, j) == 2);
+ }
}
Index: oln/morpho/reconstruction.hh
--- oln/morpho/reconstruction.hh (revision 0)
+++ oln/morpho/reconstruction.hh (revision 0)
@@ -0,0 +1,78 @@
+// Copyright (C) 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
+// 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_MORPHO_RECONSTRUCTION_HH
+# define OLN_MORPHO_RECONSTRUCTION_HH
+
+#include <oln/accumulator/max.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ namespace impl
+ {
+
+ template <typename I , typename J>
+ void // FIXME : slow version.
+ reconstruction_(const Image_with_Nbh<I>& marker,
+ const Binary_Image<I>& mask)
+ {
+ // first
+ oln_fwd_piter(I) p(input.points());
+ for_all(p)
+ marker(p) = local(max, marker, p) && mask(p); // FIXME : local_sup.
+
+
+ // second
+ oln_bkd_piter(I) p(input.points());
+ for_all(p)
+ marker(p) = local(max, marker, p) && mask(p); // FIXME : local_inf.
+ }
+
+ } // end of namespace oln::morpho::impl
+
+ template <typename I , typename J>
+ void
+ reconstruction(const Image_with_Nbh<I>& marker,
+ const Binary_Image<J>& mask)
+ {
+ impl::reconstruction_(exact(mask), exact(marker));
+ }
+
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_DILATION_HH
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 919)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -10,7 +10,7 @@
// 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
+// You should have receiv 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.
@@ -70,18 +70,15 @@
oln_bkd_piter(I) p(input.points());
for_all(p)
{
+ parent(p) = p;
if ( input(p) )
{
- parent(p) = p;
oln_niter(I) n(p, input);
for_all(n)
{
- if ( input(n) )
- {
- if ( is_processed(n) )
+ if ( input(n) && is_processed(n) )
do_union(input ,n, p, parent);
}
- }
is_processed(p) = true;
}
}
Index: oln/io/pnm.hh
--- oln/io/pnm.hh (revision 919)
+++ oln/io/pnm.hh (working copy)
@@ -33,8 +33,9 @@
# include <fstream>
# include <string>
-# include <oln/basics2d.hh>
-
+# include <oln/core/2d/image2d.hh>
+# include <oln/core/2d/window2d.hh>
+# include <oln/core/2d/neighb2d.hh>
namespace oln {
@@ -117,7 +118,7 @@
oln_coord(I) cols = 0;
unsigned bits = 0;
unsigned char c = 0;
- oln_fwd_piter(I) p(ima.topo());
+ oln_fwd_piter(I) p(ima.points());
for_all(p)
{
if (bits == 0)
@@ -126,7 +127,7 @@
bits = 8;
}
ima(p) = (c & (1 << --bits)) ? false : true;
- if (++cols >= int(ima.bbox().ncols()))
+ if (++cols >= int(ima.max_col()))
cols = bits = 0;
}
}
@@ -136,7 +137,7 @@
template <typename I>
void load_pbm_ascii(std::ifstream& file, I& ima)
{
- oln_fwd_piter(I) p(ima.topo());
+ oln_fwd_piter(I) p(ima.points());
for_all(p)
ima(p) = (file.get() == '0');
}
@@ -162,7 +163,7 @@
template <typename I>
void load_pnm_raw_2d(std::ifstream& file, I& ima)
{
- int col = ima.pmin().col();
+ int col = ima.col();
size_t len = ima.bbox().ncols();
for (int row = ima.pmin().row(); row <= ima.pmax().row(); ++row)
file.read((char*)(ima.adr_at(row, col)),
@@ -195,26 +196,26 @@
}
- image2d<unsigned char> load_pgm(const std::string& filename)
- {
- std::ifstream file(filename.c_str());
- if (not file)
- {
- std::cerr << "error: file '" << filename
- << "' not found!";
- abort();
- }
- char type;
- int nrows, ncols;
- internal::read_pnm_header('2', '5', file, type, nrows, ncols);
- image2d<unsigned char> ima(nrows, ncols);
- if (type == '4')
- internal::load_pnm_raw_2d(file, ima);
- else
- // type == '1'
- internal::load_pnm_ascii(file, ima);
- return ima;
- }
+// image2d<unsigned char> load_pgm(const std::string& filename)
+// {
+// std::ifstream file(filename.c_str());
+// if (not file)
+// {
+// std::cerr << "error: file '" << filename
+// << "' not found!";
+// abort();
+// }
+// char type;
+// int nrows, ncols;
+// internal::read_pnm_header('2', '5', file, type, nrows, ncols);
+// image2d<unsigned char> ima(nrows, ncols);
+// if (type == '4')
+// internal::load_pnm_raw_2d(file, ima);
+// else
+// // type == '1'
+// internal::load_pnm_ascii(file, ima);
+// return ima;
+// }
} // end of namespace oln::io
1
0
919: Add line2d, bresenham, the safe_image morpher, and underlying types.
by Thierry Geraud 28 Mar '07
by Thierry Geraud 28 Mar '07
28 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add line2d, bresenham, the safe_image morpher, and underlying types.
* oln/core/2d/line2d.hh,
* oln/core/gen/safe_image.hh,
* oln/core/internal/pset_adaptor.hh,
* oln/draw,
* oln/draw/bresenham.hh: New.
* TODO: Augment.
* oln/core/concept/image.hh (read_, write_): New.
* oln/core/concept/image_identity.hh: Update.
* oln/core/concept/generalised_point.hh (include): Fix.
* oln/core/concept/point_set.hh (~Point_Set): New.
* oln/core/concept/value.hh: Cosmetic changes.
* oln/core/1d/array1d.hh (operator()): Remove.
(array1d_): Fix.
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh: Update.
* oln/core/1d/box1d.hh,
* oln/core/1d/point1d.hh,
* oln/core/2d/box2d.hh,
* oln/core/2d/point2d.hh,
* oln/core/gen/box.hh: Clean up.
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh (impl_write): New.
* oln/core/gen/pset_compare.hh (op_leq_): New.
* oln/core/gen/fbbox.hh (fbbox_): Fix.
(box_t): New.
(include): Add point_set_base.
* oln/core/gen/single_value_image.hh,
* oln/core/internal/box.hh: Cosmetic changes.
* oln/core/internal/point_set_base.hh (f_box_from_point_): New.
* oln/core/internal/op_image_restricted_to_pset.hh (impl_owns_): New.
* oln/core/internal/point_set_std_based.hh (box): New in vtypes.
(pset_std_based_fwd_piter_): Change inheritance to internal::iterator_on_points_base.
Make the constructor argument type more general.
(pset_std_based_bkd_piter_): Likewise.
* oln/core/internal/image_base.hh (operator |): Add non-const versions.
* oln/core/internal/iterator_on_points_base.hh: Add a FIXME.
* oln/value/builtin.hh: Fix.
TODO | 7
oln/core/1d/array1d.hh | 33 +---
oln/core/1d/box1d.hh | 6
oln/core/1d/image1d.hh | 17 +-
oln/core/1d/image1d_b.hh | 13 +
oln/core/1d/point1d.hh | 4
oln/core/2d/box2d.hh | 6
oln/core/2d/image2d.hh | 9 +
oln/core/2d/image2d_b.hh | 9 +
oln/core/2d/line2d.hh | 161 +++++++++++++++++++
oln/core/2d/point2d.hh | 6
oln/core/concept/generalised_point.hh | 3
oln/core/concept/image.hh | 20 ++
oln/core/concept/image_identity.hh | 18 +-
oln/core/concept/point_set.hh | 8
oln/core/concept/value.hh | 2
oln/core/gen/box.hh | 11 -
oln/core/gen/fbbox.hh | 19 +-
oln/core/gen/pset_compare.hh | 25 ++-
oln/core/gen/safe_image.hh | 187 +++++++++++++++++++++++
oln/core/gen/single_value_image.hh | 2
oln/core/internal/box.hh | 6
oln/core/internal/image_base.hh | 21 ++
oln/core/internal/iterator_on_points_base.hh | 2
oln/core/internal/op_image_restricted_to_pset.hh | 10 +
oln/core/internal/point_set_base.hh | 22 ++
oln/core/internal/point_set_std_based.hh | 31 ++-
oln/core/internal/pset_adaptor.hh | 135 ++++++++++++++++
oln/draw/bresenham.hh | 87 ++++++++++
oln/value/builtin.hh | 16 +
30 files changed, 804 insertions(+), 92 deletions(-)
Index: TODO
--- TODO (revision 918)
+++ TODO (working copy)
@@ -12,7 +12,7 @@
function, an accessor, a projection, etc.)
basics important routines: fill, assign, clone, unmorph (undress?),
-convert, ...
+convert, ... + add 'with' to disambiguate
torus and mask types, and the proper niter type deductions (with or
without virtual border)
@@ -30,7 +30,10 @@
meta-window type; for instance, ball, segment, etc.
-const promotions for op_<L,O,R> types
+const promotions for op_<L,O,R> types + result is Mutable only
+if the underlying type is not 'const'
+
+in image_identity.hh use 'current'
* Tiny improvements
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 918)
+++ oln/core/concept/image.hh (working copy)
@@ -133,6 +133,7 @@
bool owns_(const psite& p) const;
rvalue operator()(const psite& p) const;
+ rvalue read_(const psite& p) const;
const pset& points() const;
@@ -183,10 +184,12 @@
public automatic::get_impl<Mutable_Image, Exact>
{
stc_using_from(Image, psite);
+ stc_using_from(Image, value);
using Image<Exact>::operator();
stc_typename(lvalue);
lvalue operator()(const psite& p);
+ void write_(const psite& p, const value& v);
protected:
Mutable_Image();
@@ -438,6 +441,14 @@
}
template <typename Exact>
+ typename Image<Exact>::rvalue
+ Image<Exact>::read_(const typename Image<Exact>::psite& p) const
+ {
+ precondition(this->owns_(p));
+ return exact(this)->impl_read(p);
+ }
+
+ template <typename Exact>
const typename Image<Exact>::box&
Image<Exact>::bbox() const
{
@@ -502,6 +513,15 @@
}
template <typename Exact>
+ void
+ Mutable_Image<Exact>::write_(const typename Mutable_Image<Exact>::psite& p,
+ const typename Mutable_Image<Exact>::value& v)
+ {
+ precondition(this->owns_(p));
+ exact(this)->impl_write(p, v);
+ }
+
+ template <typename Exact>
Mutable_Image<Exact>::Mutable_Image()
{
}
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 918)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -85,7 +85,9 @@
{
stc_typename(psite);
stc_typename(lvalue);
+ stc_typename(value);
lvalue impl_read_write(const psite& p);
+ void impl_write(const psite& p, const value& v);
};
@@ -228,13 +230,25 @@
/// Concept-class "Mutable_Image".
+# define current set_impl< Mutable_Image, behavior::identity, Exact >
+
template <typename Exact>
- typename set_impl< Mutable_Image, behavior::identity, Exact >::lvalue
- set_impl< Mutable_Image, behavior::identity, Exact >::impl_read_write(const typename set_impl< Mutable_Image, behavior::identity, Exact >::psite& p)
+ typename current::lvalue
+ current::impl_read_write(const typename current::psite& p)
{
return exact(this)->image().operator()(p);
}
+ template <typename Exact>
+ void
+ current::impl_write(const typename current::psite& p,
+ const typename current::value& v)
+ {
+ return exact(this)->image().write_(p, v);
+ }
+
+# undef current
+
/// Concept-class "Fast_Image".
Index: oln/core/concept/generalised_point.hh
--- oln/core/concept/generalised_point.hh (revision 918)
+++ oln/core/concept/generalised_point.hh (working copy)
@@ -28,6 +28,9 @@
#ifndef OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
# define OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
+# include <oln/core/equipment.hh>
+
+
namespace oln
{
Index: oln/core/concept/point_set.hh
--- oln/core/concept/point_set.hh (revision 918)
+++ oln/core/concept/point_set.hh (working copy)
@@ -59,6 +59,7 @@
protected:
Point_Set();
+ ~Point_Set();
}; // end of oln::Point_Set<Exact>
@@ -117,6 +118,13 @@
}
template <typename Exact>
+ Point_Set<Exact>::~Point_Set()
+ {
+ // FIXME: check method impls.
+ // unsigned (Exact::*m)() const = & Exact::impl_npoints;
+ }
+
+ template <typename Exact>
Box<Exact>::Box()
{
}
Index: oln/core/concept/value.hh
--- oln/core/concept/value.hh (revision 918)
+++ oln/core/concept/value.hh (working copy)
@@ -70,7 +70,7 @@
{
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/1d/array1d.hh
--- oln/core/1d/array1d.hh (revision 918)
+++ oln/core/1d/array1d.hh (working copy)
@@ -59,11 +59,8 @@
/// Dtor.
~array1d_();
- const T& operator()(C i) const;
- T& operator()(C i);
-
- const T& operator[](std::size_t ind) const;
- T& operator[](std::size_t ind);
+ const T& operator[](C i) const;
+ T& operator[](C i);
bool has(C i) const;
@@ -119,36 +116,22 @@
}
template <typename T, typename C>
- const T& array1d_<T, C>::operator()(C i) const
+ const T& array1d_<T, C>::operator[](C i) const
{
+ precondition(buffer_ != 0);
precondition(has(i));
return buffer_[i];
}
template <typename T, typename C>
- T& array1d_<T, C>::operator()(C i)
+ T& array1d_<T, C>::operator[](C i)
{
+ precondition(buffer_ != 0);
precondition(has(i));
return buffer_[i];
}
template <typename T, typename C>
- const T& array1d_<T, C>::operator[](std::size_t ind) const
- {
- precondition(buffer_ != 0);
- precondition(ind < len_);
- return buffer_[ind];
- }
-
- template <typename T, typename C>
- T& array1d_<T, C>::operator[](std::size_t ind)
- {
- precondition(buffer_ != 0);
- precondition(ind < len_);
- return buffer_[ind];
- }
-
- template <typename T, typename C>
bool array1d_<T, C>::has(C i) const
{
return i >= imin_ and i <= imax_;
@@ -195,17 +178,19 @@
void array1d_<T, C>::allocate_()
{
buffer_ = new T[len_];
+ buffer_ -= imin_;
}
template <typename T, typename C>
void array1d_<T, C>::deallocate_()
{
precondition(buffer_ != 0);
+ buffer_ += imin_;
delete[] buffer_;
buffer_ = 0; // safety
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 918)
+++ oln/core/1d/image1d.hh (working copy)
@@ -95,6 +95,8 @@
T& impl_read_write(const point1d& p);
T& impl_index_read_write(unsigned i);
+ void impl_write(const point1d& p, const T& v);
+
std::size_t impl_npoints() const;
const box1d& impl_points() const;
@@ -135,7 +137,7 @@
const T& image1d<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
- return this->data_->first.operator()(p.ind());
+ return this->data_->first[p.ind()];
}
template <typename T>
@@ -143,14 +145,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->first.operator[](i);
+ return this->data_->first[i];
}
template <typename T>
T& image1d<T>::impl_read_write(const point1d& p)
{
assert(this->has_data());
- return this->data_->first.operator()(p.ind());
+ return this->data_->first[p.ind()];
}
template <typename T>
@@ -158,7 +160,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->first.operator[](i);
+ return this->data_->first[i];
+ }
+
+ template <typename T>
+ void image1d<T>::impl_write(const point1d& p, const T& v)
+ {
+ assert(this->has_data());
+ this->data_->first[p.ind()] = v;
}
template <typename T>
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 918)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -103,6 +103,8 @@
T& impl_read_write(const point1d& p);
T& impl_index_read_write(unsigned i);
+ void impl_write(const point1d& p, const T& v);
+
std::size_t impl_npoints() const;
const box1d& impl_points() const;
@@ -149,7 +151,7 @@
const T& image1d_b<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
- return this->data_->first(p.ind());
+ return this->data_->first[p.ind()];
}
template <typename T>
@@ -164,7 +166,7 @@
T& image1d_b<T>::impl_read_write(const point1d& p)
{
assert(this->has_data());
- return this->data_->first(p.ind());
+ return this->data_->first[p.ind()];
}
template <typename T>
@@ -176,6 +178,13 @@
}
template <typename T>
+ void image1d_b<T>::impl_write(const point1d& p, const T& v)
+ {
+ assert(this->has_data());
+ this->data_->first[p.ind()] = v;
+ }
+
+ template <typename T>
const box1d& image1d_b<T>::impl_points() const
{
assert(this->has_data());
Index: oln/core/1d/box1d.hh
--- oln/core/1d/box1d.hh (revision 918)
+++ oln/core/1d/box1d.hh (working copy)
@@ -35,14 +35,13 @@
namespace oln
{
- // Forward declarations
- struct box1d;
+ // Fwd decl.
+ class box1d;
// Super type
template <>
struct super_trait_< box1d >
{
- typedef box1d current;
typedef internal::box_<box1d> ret;
};
@@ -57,7 +56,6 @@
// Class box1d
class box1d : public internal::box_< box1d >
{
- typedef box1d current;
typedef internal::box_< box1d > super;
public:
// Note: we can't use stc_using because box1d isn't a templated class
Index: oln/core/1d/point1d.hh
--- oln/core/1d/point1d.hh (revision 918)
+++ oln/core/1d/point1d.hh (working copy)
@@ -37,8 +37,8 @@
{
- struct point1d;
- struct dpoint1d;
+ class point1d;
+ class dpoint1d;
/// Super type.
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 918)
+++ oln/core/2d/image2d.hh (working copy)
@@ -99,6 +99,8 @@
T& impl_index_read_write(unsigned i);
T& impl_at(int row, int col);
+ void impl_write(const point2d& p, const T& v);
+
std::size_t impl_npoints() const;
const box2d& impl_points() const;
@@ -192,6 +194,13 @@
}
template <typename T>
+ void image2d<T>::impl_write(const point2d& p, const T& v)
+ {
+ assert(this->has_data());
+ this->data_->first(p.row(), p.col()) = v;
+ }
+
+ template <typename T>
std::size_t image2d<T>::impl_npoints() const
{
// faster than the default code given by primitive_image_
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 918)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -104,6 +104,8 @@
T& impl_index_read_write(unsigned i);
T& impl_at(int row, int col);
+ void impl_write(const point2d& p, const T& v);
+
std::size_t impl_npoints() const;
const box2d& impl_points() const;
@@ -210,6 +212,13 @@
}
template <typename T>
+ void image2d_b<T>::impl_write(const point2d& p, const T& v)
+ {
+ assert(this->has_data());
+ this->data_->first(p.row(), p.col()) = v;
+ }
+
+ template <typename T>
const box2d& image2d_b<T>::impl_points() const
{
assert(this->has_data());
Index: oln/core/2d/line2d.hh
--- oln/core/2d/line2d.hh (revision 0)
+++ oln/core/2d/line2d.hh (revision 0)
@@ -0,0 +1,161 @@
+// Copyright (C) 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
+// 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_2D_LINE2D_HH
+# define OLN_CORE_2D_LINE2D_HH
+
+# include <oln/core/2d/box2d.hh>
+# include <oln/core/internal/pset_adaptor.hh>
+# include <oln/core/gen/pvec.hh>
+
+
+namespace oln
+{
+
+ // FIXME: Move it!
+ namespace util
+ {
+ template <typename T>
+ int sign(const T& t)
+ {
+ if (t != 0)
+ return t > 0 ? 1 : -1;
+ else
+ return 0;
+ }
+
+ } // end of namespace oln::util
+
+
+
+ // Fwd decl.
+ class line2d;
+
+
+ // Super type.
+ template <>
+ struct super_trait_< line2d >
+ {
+ typedef internal::pset_adaptor_<line2d> ret;
+ };
+
+
+ // Virtual types.
+ template <>
+ struct vtypes< line2d >
+ {
+ typedef pvec_<point2d> adapted;
+ };
+
+ class line2d : public internal::pset_adaptor_<line2d>
+ {
+ public:
+
+ line2d(const point2d& begin, const point2d& end);
+ const point2d& begin_point() const;
+ const point2d& end_point() const;
+
+ const pvec_<point2d>& pvec() const;
+ const std::vector<point2d>& con() const { return this->ps_.con(); }
+
+ protected:
+ point2d beg_, end_;
+ void compute_(); // FIXME: we also need a semi_open_line (without the end point)...
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ line2d::line2d(const point2d& begin,
+ const point2d& end)
+ : beg_(begin),
+ end_(end)
+ {
+ this->compute_();
+ }
+
+ const point2d&
+ line2d::begin_point() const
+ {
+ return this->beg_;
+ }
+
+ const point2d&
+ line2d::end_point() const
+ {
+ return this->end_;
+ }
+
+ void
+ line2d::compute_()
+ {
+ dpoint2d dp = this->end_ - this->beg_;
+ int
+ srow = util::sign(dp.row()), drow = std::abs(dp.row()), ddrow = 2 * drow,
+ scol = util::sign(dp.col()), dcol = std::abs(dp.col()), ddcol = 2 * dcol,
+ row = this->beg_.row(),
+ col = this->beg_.row();
+
+ if ( dcol > drow )
+ {
+ int e = ddrow - dcol;
+ for (int i = 0; i < dcol; ++i)
+ {
+ this->ps_.append(point2d(row, col));
+ while (e >= 0)
+ {
+ row += srow;
+ e -= ddcol;
+ }
+ col += scol;
+ e += ddrow;
+ }
+ }
+ else
+ {
+ int e = ddcol - drow;
+ for (int i = 0; i < drow; ++i)
+ {
+ this->ps_.append(point2d(row, col));
+ while (e >= 0)
+ {
+ col += scol;
+ e -= ddrow;
+ }
+ row += srow;
+ e += ddcol;
+ }
+ }
+ this->ps_.append(point2d(row, col));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+
+} // end of namespace oln
+
+#endif // ! OLN_CORE_2D_LINE2D_HH
Index: oln/core/2d/box2d.hh
--- oln/core/2d/box2d.hh (revision 918)
+++ oln/core/2d/box2d.hh (working copy)
@@ -36,14 +36,13 @@
namespace oln
{
- // Forward declarations
- struct box2d;
+ // Fwd decl.
+ class box2d;
// Super type
template <>
struct super_trait_< box2d >
{
- typedef box2d current;
typedef internal::box_<box2d> ret;
};
@@ -58,7 +57,6 @@
// Class box2d
class box2d : public internal::box_< box2d >
{
- typedef box2d current;
typedef internal::box_< box2d > super;
public:
// Note: we can't use stc_using because box2d isn't a templated class
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 918)
+++ oln/core/2d/point2d.hh (working copy)
@@ -37,8 +37,8 @@
{
- struct point2d;
- struct dpoint2d;
+ class point2d;
+ class dpoint2d;
/// Super type.
@@ -93,7 +93,7 @@
this->col() = dat->second.value;
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 918)
+++ oln/core/gen/pset_compare.hh (working copy)
@@ -90,18 +90,14 @@
}
- // Point_Set L < Point_Set R
- // -----------------------------
-
- // Generic version.
+ // Point_Set L <= Point_Set R
template <typename L, typename R>
- bool op_less_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ bool op_leq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
- if (lhs.npoints() >= rhs.npoints()) // quick test
+ if (lhs.npoints() > rhs.npoints()) // quick test
return false;
- // we have lhs.npoints() < rhs.npoints()
- // so we shall now test that all points of lhs are IN rhs
+ // all points of lhs are IN rhs?
oln_piter(R) p_rhs(rhs);
p_rhs.start();
oln_piter(L) p_lhs(lhs);
@@ -116,6 +112,19 @@
}
+ // Point_Set L < Point_Set R
+
+ template <typename L, typename R>
+ bool op_less_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ return op_leq_(lhs, rhs) and lhs.npoints() < rhs.npoints();
+ }
+
+
+
+
+
+
// Box L <= Box R.
Index: oln/core/gen/box.hh
--- oln/core/gen/box.hh (revision 918)
+++ oln/core/gen/box.hh (working copy)
@@ -38,11 +38,11 @@
{
- // Forward declarations.
+ // Fwd decl.
template <typename P> class gen_box;
- // Super type declaration.
+ // Super type.
template <typename P>
struct super_trait_< gen_box<P> >
{
@@ -51,7 +51,7 @@
};
- /// Virtual types associated to oln::gen_box<P>.
+ /// Virtual types.
template <typename P>
struct vtypes< gen_box<P> >
{
@@ -88,10 +88,6 @@
# ifndef OLN_INCLUDE_ONLY
-
- // -------------------- gen_box<P>
-
-
template <typename P>
gen_box<P>::gen_box()
{
@@ -118,7 +114,6 @@
# endif // !OLN_INCLUDE_ONLY
-
} // end of namespace oln
Index: oln/core/gen/fbbox.hh
--- oln/core/gen/fbbox.hh (revision 918)
+++ oln/core/gen/fbbox.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/gen/box.hh>
# include <oln/core/concept/point.hh>
+# include <oln/core/internal/point_set_base.hh>
namespace oln
@@ -48,17 +49,19 @@
public:
+ typedef typename f_box_from_point_<P>::ret box_t;
+
fbbox_();
- operator gen_box<P>() const;
+ operator box_t() const;
bool is_valid() const;
void flush();
fbbox_<P>& take(const P& p);
- const gen_box<P>& box() const;
+ const box_t& box() const;
private:
bool is_valid_;
- gen_box<P> b_;
+ box_t b_;
}; // end of class oln::fbbox_<P>
@@ -73,7 +76,7 @@
}
template <typename P>
- fbbox_<P>::operator gen_box<P>() const
+ fbbox_<P>::operator typename fbbox_<P>::box_t() const
{
precondition(this->is_valid_);
return this->b_;
@@ -92,7 +95,8 @@
}
template <typename P>
- fbbox_<P>& fbbox_<P>::take(const P& p)
+ fbbox_<P>&
+ fbbox_<P>::take(const P& p)
{
if (not this->is_valid_)
{
@@ -112,13 +116,14 @@
}
template <typename P>
- const gen_box<P>& fbbox_<P>::box() const
+ const typename fbbox_<P>::box_t&
+ fbbox_<P>::box() const
{
precondition(this->is_valid_);
return this->b_;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/single_value_image.hh
--- oln/core/gen/single_value_image.hh (revision 918)
+++ oln/core/gen/single_value_image.hh (working copy)
@@ -146,7 +146,7 @@
this->data_->second = new_value;
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/safe_image.hh
--- oln/core/gen/safe_image.hh (revision 0)
+++ oln/core/gen/safe_image.hh (revision 0)
@@ -0,0 +1,187 @@
+// Copyright (C) 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
+// 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_GEN_SAFE_IMAGE_HH
+# define OLN_CORE_GEN_SAFE_IMAGE_HH
+
+# include <oln/core/internal/image_base.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ template <typename I> class safe_image;
+
+
+ /// Virtual types.
+ template <typename I>
+ struct vtypes< safe_image<I> >
+ {
+ typedef I delegatee;
+ typedef behavior::identity behavior;
+
+ typedef internal::singleton<I> data;
+
+ typedef safe_image< oln_plain(I) > plain;
+ typedef safe_image< pl::rec<I> > skeleton;
+ };
+
+
+ /// Super type.
+ template <typename I>
+ struct super_trait_< safe_image<I> >
+ {
+ typedef safe_image<I> current;
+ typedef internal::single_image_morpher_<current> ret;
+ };
+
+
+ /// Class for images defined by a point set and a single value.
+
+ template <typename I>
+ class safe_image : public internal::single_image_morpher_< safe_image<I> >
+ {
+ typedef safe_image<I> current;
+ typedef internal::single_image_morpher_<current> super;
+ public:
+
+ stc_using(point);
+ stc_using(rvalue);
+ stc_using(lvalue);
+ stc_using(value);
+ stc_using(data);
+ stc_using(delegatee);
+
+ safe_image();
+ safe_image(Mutable_Image<I>& ima);
+
+ bool impl_owns_(const point& p) const;
+
+ rvalue impl_read(const point& p) const;
+ lvalue impl_read_write(const point& p);
+ void impl_write(const point& p, const value& v);
+
+ delegatee& impl_image();
+ const delegatee& impl_image() const;
+
+ }; // end of safe_image<I>
+
+
+
+ template <typename I>
+ safe_image<I> safe(Mutable_Image<I>& ima)
+ {
+ safe_image<I> tmp(ima);
+ return tmp;
+ }
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ safe_image<I>::safe_image()
+ {
+ }
+
+ template <typename I>
+ safe_image<I>::safe_image(Mutable_Image<I>& ima)
+ {
+ precondition(exact(ima).has_data());
+ this->data_ = new data(exact(ima));
+ }
+
+ template <typename I>
+ bool
+ safe_image<I>::impl_owns_(const typename safe_image<I>::point&) const
+ {
+ assert(this->has_data());
+ return true; // always!
+ }
+
+ template <typename I>
+ typename safe_image<I>::rvalue
+ safe_image<I>::impl_read(const typename safe_image<I>::point& p) const
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ static oln_value(I) tmp;
+ if (this->image().owns_(p))
+ return this->image()(p);
+ else
+ return tmp;
+ }
+
+ template <typename I>
+ typename safe_image<I>::lvalue
+ safe_image<I>::impl_read_write(const typename safe_image<I>::point& p)
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ static oln_value(I) tmp;
+ if (this->image().owns_(p))
+ return this->image()(p);
+ else
+ return tmp;
+ }
+
+ template <typename I>
+ void
+ safe_image<I>::impl_write(const typename safe_image<I>::point& p,
+ const typename safe_image<I>::value& v)
+ {
+ assert(this->has_data());
+ assert(this->image().has_data());
+ static oln_value(I) tmp;
+ if (this->image().owns_(p))
+ this->image().write_(p, v);
+ }
+
+ template <typename I>
+ typename safe_image<I>::delegatee&
+ safe_image<I>::impl_image()
+ {
+ assert(this->has_data());
+ return this->data_->value;
+ }
+
+ template <typename I>
+ const typename safe_image<I>::delegatee&
+ safe_image<I>::impl_image() const
+ {
+ assert(this->has_data());
+ return this->data_->value;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_SAFE_IMAGE_HH
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 918)
+++ oln/core/internal/box.hh (working copy)
@@ -61,7 +61,9 @@
namespace internal
{
- /// Generic box class based on a point class.
+
+ /// Base implementation class for box types.
+
template <typename Exact>
class box_ : public point_set_base_< Exact >
{
@@ -71,7 +73,6 @@
stc_using(point);
stc_using(box);
-
typedef internal::initializer_<
internal::pair< internal::from_t<point>, internal::to_t<point> >
> from_to_t;
@@ -82,7 +83,6 @@
public:
enum { n = mlc_value(dim__) };
-
unsigned impl_npoints() const;
bool impl_has(const point& p) const;
const Exact& impl_bbox() const;
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 918)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -34,6 +34,28 @@
namespace oln
{
+ // function : point -> box
+
+ template <typename P> class gen_box;
+
+ template <typename P>
+ struct f_box_from_point_ { typedef gen_box<P> ret; };
+
+ class point1d;
+ class box1d;
+
+ template <>
+ struct f_box_from_point_< point1d > { typedef box1d ret; };
+
+ class point2d;
+ class box2d;
+
+ template <>
+ struct f_box_from_point_< point2d > { typedef box2d ret; };
+
+ // FIXME: Move the code above elsewhere.
+
+
namespace internal
{
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 918)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -79,12 +79,14 @@
public:
stc_using(pset);
stc_using(box);
+ stc_using(psite);
stc_using(data);
stc_using(delegatee);
delegatee& impl_image();
const delegatee& impl_image() const;
+ bool impl_owns_(const psite& p) const;
const pset& impl_points() const;
protected:
@@ -134,6 +136,14 @@
}
template <typename I, typename S>
+ bool
+ current::impl_owns_(const typename current::psite& p) const
+ {
+ assert(this->has_data());
+ return this->has(p);
+ }
+
+ template <typename I, typename S>
typename current::delegatee&
current::impl_image()
{
Index: oln/core/internal/point_set_std_based.hh
--- oln/core/internal/point_set_std_based.hh (revision 918)
+++ oln/core/internal/point_set_std_based.hh (working copy)
@@ -32,7 +32,7 @@
# include <algorithm>
# include <oln/core/internal/point_set_base.hh>
-# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
# include <oln/core/gen/fbbox.hh>
@@ -61,9 +61,12 @@
typedef stc::abstract std_container;
typedef stc_deferred(std_container) std_container__;
- typedef stc::final< typename std_container__::value_type > point;
+ typedef typename std_container__::value_type point__;
+
+ typedef stc::final< point__ > point;
typedef stc::final< pset_std_based_fwd_piter_<std_container__> > fwd_piter;
typedef stc::final< pset_std_based_bkd_piter_<std_container__> > bkd_piter;
+ typedef stc::final< typename f_box_from_point_<point__>::ret > box;
};
@@ -173,14 +176,14 @@
struct super_trait_< pset_std_based_fwd_piter_<C> >
{
typedef pset_std_based_fwd_piter_<C> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
template <typename C>
struct super_trait_< pset_std_based_bkd_piter_<C> >
{
typedef pset_std_based_bkd_piter_<C> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -203,16 +206,16 @@
// Class pset_std_based_fwd_piter_<C>.
template <typename C>
- class pset_std_based_fwd_piter_ : public Iterator_on_Points< pset_std_based_fwd_piter_<C> >
+ class pset_std_based_fwd_piter_ : public internal::iterator_on_points_base< pset_std_based_fwd_piter_<C> >
{
typedef pset_std_based_fwd_piter_<C> current;
- typedef Iterator_on_Points<current> super;
+ typedef internal::iterator_on_points_base<current> super;
public:
stc_using(point);
template <typename Ps>
- pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& con);
+ pset_std_based_fwd_piter_(const Point_Set<Ps>& pset);
void impl_start();
void impl_next();
@@ -232,16 +235,16 @@
// Class pset_std_based_bkd_piter_<C>.
template <typename C>
- class pset_std_based_bkd_piter_ : public Iterator_on_Points< pset_std_based_bkd_piter_<C> >
+ class pset_std_based_bkd_piter_ : public internal::iterator_on_points_base< pset_std_based_bkd_piter_<C> >
{
typedef pset_std_based_bkd_piter_<C> current;
- typedef Iterator_on_Points<current> super;
+ typedef internal::iterator_on_points_base<current> super;
public:
stc_using(point);
template <typename Ps>
- pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts);
+ pset_std_based_bkd_piter_(const Point_Set<Ps>& pts);
void impl_start();
void impl_next();
@@ -268,8 +271,8 @@
template <typename C>
template <typename Ps>
- pset_std_based_fwd_piter_<C>::pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& pts)
- : con_(pts.con())
+ pset_std_based_fwd_piter_<C>::pset_std_based_fwd_piter_(const Point_Set<Ps>& pts)
+ : con_(exact(pts).con())
{
this->it_ = this->con_.end();
}
@@ -325,8 +328,8 @@
template <typename C>
template <typename Ps>
- pset_std_based_bkd_piter_<C>::pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts)
- : con_(pts.con())
+ pset_std_based_bkd_piter_<C>::pset_std_based_bkd_piter_(const Point_Set<Ps>& pts)
+ : con_(exact(pts).con())
{
this->it_ = this->con_.rend();
}
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 918)
+++ oln/core/internal/image_base.hh (working copy)
@@ -506,6 +506,17 @@
return tmp;
}
+ template <typename I, typename B, typename P>
+ op_<I, such_as, const fun_p2b_<B (*)(P)> >
+ operator | (Image<I>& ima, B (*f)(P))
+ {
+ typedef oln_strip_(P) P_;
+ mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
+ mlc::assert_equal_< P_, oln_point(I) >::check();
+ op_<I, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(ima), f);
+ return tmp;
+ }
+
// Specialization "Image such_as ima : P -> B".
@@ -519,6 +530,16 @@
return tmp;
}
+ template <typename I, typename J>
+ op_<I, such_as, const fun_p2b_< Binary_Image<J> > >
+ operator | (Image<I>& ima, const Binary_Image<J>& f_ima_b)
+ {
+ precondition(f_ima_b.points() >= ima.points());
+ mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
+ op_<I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b);
+ return tmp;
+ }
+
// FIXME: What about Mutable_Image so that "ima | something" can be left-value?
Index: oln/core/internal/pset_adaptor.hh
--- oln/core/internal/pset_adaptor.hh (revision 0)
+++ oln/core/internal/pset_adaptor.hh (revision 0)
@@ -0,0 +1,135 @@
+// Copyright (C) 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
+// 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_INTERNAL_PSET_ADAPTOR_HH
+# define OLN_CORE_INTERNAL_PSET_ADAPTOR_HH
+
+# include <oln/core/internal/point_set_base.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> class pset_adaptor_; }
+
+
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::pset_adaptor_<Exact> >
+ {
+ typedef internal::point_set_base_<Exact> ret;
+ };
+
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::pset_adaptor_<Exact> >
+ {
+ typedef stc::abstract adapted;
+
+ typedef stc_deferred(adapted) adapted__;
+ typedef stc::final< oln_point(adapted__) > point;
+ typedef stc::final< oln_fwd_piter(adapted__) > fwd_piter;
+ typedef stc::final< oln_bkd_piter(adapted__) > bkd_piter;
+ typedef stc::final< oln_box(adapted__) > box;
+ };
+
+
+ namespace internal
+ {
+
+ // Base implementation class for types of iterator on points
+ // defined over other types of iterator on points.
+
+ template <typename Exact>
+ class pset_adaptor_ : public internal::point_set_base_<Exact>
+ {
+ typedef internal::point_set_base_<Exact> super;
+ public:
+ stc_typename(adapted);
+
+ stc_using(point);
+ stc_using(box);
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const box& impl_bbox() const;
+
+ protected:
+ adapted ps_;
+ pset_adaptor_();
+ pset_adaptor_(const adapted& ps);
+
+ }; // end of class oln::internal::pset_adaptor_<Exact>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ pset_adaptor_<Exact>::pset_adaptor_()
+ : ps_()
+ {
+ }
+
+ template <typename Exact>
+ pset_adaptor_<Exact>::pset_adaptor_(const adapted& ps)
+ : ps_(ps)
+ {
+ }
+
+ template <typename Exact>
+ unsigned
+ pset_adaptor_<Exact>::impl_npoints() const
+ {
+ return this->ps_.npoints();
+ }
+
+ template <typename Exact>
+ bool
+ pset_adaptor_<Exact>::impl_has(const typename pset_adaptor_<Exact>::point& p) const
+ {
+ return this->ps_.has(p);
+ }
+
+ template <typename Exact>
+ const typename pset_adaptor_<Exact>::box&
+ pset_adaptor_<Exact>::impl_bbox() const
+ {
+ return this->ps_.bbox();
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_PSET_ADAPTOR_HH
Index: oln/core/internal/iterator_on_points_base.hh
--- oln/core/internal/iterator_on_points_base.hh (revision 918)
+++ oln/core/internal/iterator_on_points_base.hh (working copy)
@@ -40,7 +40,7 @@
namespace internal {
template <typename Exact>
- struct iterator_on_points_base;
+ struct iterator_on_points_base; // FIXME: End with '_'!
}
// Super type
Index: oln/draw/bresenham.hh
--- oln/draw/bresenham.hh (revision 0)
+++ oln/draw/bresenham.hh (revision 0)
@@ -0,0 +1,87 @@
+// Copyright (C) 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
+// 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_DRAW_BRESENHAM_HH
+# define OLN_DRAW_BRESENHAM_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/safe_image.hh>
+# include <oln/core/2d/line2d.hh>
+
+
+
+namespace oln
+{
+
+ namespace draw
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ void bresenham(Mutable_Image<I>& input,
+ const oln_point(I)& begin, const oln_point(I)& end,
+ const oln_value(I)& value);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I>
+ void bresenham_(Mutable_Image<I>& input,
+ const oln_point(I)& begin, const oln_point(I)& end,
+ const oln_value(I)& value)
+ {
+ line2d l(begin, end);
+ safe_image<I> input_(input);
+ typename line2d::piter p(l); // FIXME: Generalize with an 'assign' routine...
+ for_all(p)
+ input_(p) = value;
+ }
+
+ } // end of namespace oln::draw::impl
+
+ // Facade.
+
+ template <typename I>
+ void bresenham(Mutable_Image<I>& input,
+ const oln_point(I)& begin, const oln_point(I)& end,
+ const oln_value(I)& value)
+ {
+ impl::bresenham_(exact(input), begin, end, value);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::draw
+
+} // end of namespace oln
+
+
+#endif // ! OLN_DRAW_BRESENHAM_HH
Index: oln/value/builtin.hh
--- oln/value/builtin.hh (revision 918)
+++ oln/value/builtin.hh (working copy)
@@ -44,7 +44,7 @@
template <typename Exact>
struct vtypes< internal::builtin_base<Exact> >
{
- typedef stc::final< stc:is<Value> > category;
+ typedef stc::final< stc::is<Value> > category;
};
@@ -59,11 +59,21 @@
builtin_base();
};
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ builtin_base<Exact>::builtin_base()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace oln::internal
- // int
+ // int, float, ...
template <>
struct super_trait_< int >
@@ -90,6 +100,8 @@
typedef float ret;
};
+ // FIXME: To be continued...
+
} // end of namespace oln
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update cc_tarjan impl + facade.
* oln/morpho/cc_tarjan.hh: Up (shape).
cc_tarjan.hh | 45 +++++++++++++++++++--------------------------
1 file changed, 19 insertions(+), 26 deletions(-)
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 916)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_DILATION_HH
-# define OLN_MORPHO_DILATION_HH
+#ifndef OLN_MORPHO_CC_TARJAN_HH
+# define OLN_MORPHO_CC_TARJAN_HH
#include <oln/debug/print.hh>
@@ -36,21 +36,19 @@
namespace morpho
{
+ namespace impl
+ {
template <typename I>
oln_point(I) find_root(I& ima,
const oln_point(I)& x,
oln_plain_value(I, oln_point(I))& parent)
{
- std::cout << "enter_root( " << parent(x) << "," << x << " )" << std::endl;
-
if (parent(x) != x)
{
parent(x) = find_root(ima, parent(x), parent);
return parent(x);
}
return x;
-
- std::cout << "leave_root" << std::endl;
}
template <typename I>
@@ -81,17 +79,12 @@
if ( input(n) )
{
if ( is_processed(n) )
- {
do_union(input ,n, p, parent);
- std::cout << "union ("<< p << ") -> parent :" << std::endl;
- debug::print(parent);
- }
}
}
is_processed(p) = true;
}
}
- std::cout << "pass 1" << std::endl;
}
template <typename I>
@@ -100,26 +93,19 @@
oln_plain_value(I, unsigned)& output)
{
unsigned current_label = 0;
-
- // Second pass
oln_fwd_piter(I) p(input.points());
for_all(p)
{
- if ( input(p) )
- {
- if ( parent(p) == p )
+ if ( input(p) && parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
- std::cout << "output :" << std::endl;
- debug::print(output);
- }
}
}
template <typename I>
oln_plain_value(I, unsigned)
- cc_tarjan(const Image_with_Nbh<I>& input)
+ cc_tarjan_(const Image_with_Nbh<I>& input)
{
oln_plain_value(I, unsigned) output;
prepare(output, with, input);
@@ -127,24 +113,31 @@
oln_plain_value(I, oln_point(I)) parent;
prepare(parent, with, input);
- // Init
oln_plain(I) is_processed;
prepare(is_processed, with, input);
oln_piter(I) p1(input.points());
for_all(p1)
- is_processed(p1) = false; // FIXME : built with.
+ is_processed(p1) = false; // FIXME : built with ?.
first_pass(input, parent, is_processed);
-
second_pass(input, parent, output);
-
- ::oln::debug::print(parent);
return output;
}
+ } // end of namespace oln::morpho::impl
+
+ // Facades.
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Binary_Image<I>& input)
+ {
+ return impl::cc_tarjan_(exact(input));
+ }
+
} // end of namespace oln::morpho
} // end of namespace oln
-#endif // ! OLN_MORPHO_DILATION_HH
+#endif // ! OLN_MORPHO_CC_TARJAN_HH
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Add elementary cc_tarjan on Binary image.
* tests/algorithms/cc_tarjan.cc: New.
* tests/algorithms/Makefile.am: Updated for check.
* oln/morpho/cc_tarjan.hh: New.
* oln/morpho/cc_tarjan.cc: Remove.
* oln/level/apply.hh: .
oln/morpho/cc_tarjan.hh | 99 ++++++++++++++++++++++++++++++------------
tests/algorithms/Makefile.am | 4 +
tests/algorithms/cc_tarjan.cc | 45 +++++++++++++++++++
3 files changed, 119 insertions(+), 29 deletions(-)
Index: tests/algorithms/cc_tarjan.cc
--- tests/algorithms/cc_tarjan.cc (revision 0)
+++ tests/algorithms/cc_tarjan.cc (revision 0)
@@ -0,0 +1,45 @@
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/window2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/morpho/cc_tarjan.hh>
+
+#include <oln/debug/print.hh>
+
+
+template <typename I>
+void set(I& ima,
+ int i,
+ int j)
+{
+ oln_point(I) p(i, j);
+ ima(p) = true;
+}
+
+int main()
+{
+ using namespace oln;
+ typedef image2d<bool> I;
+ I ima(3, 3);
+
+ set(ima, 0, 0);
+ set(ima, 0, 1);
+ set(ima, 0, 2);
+
+ set(ima, 2, 0);
+ set(ima, 2, 1);
+ set(ima, 2, 2);
+
+ I out = morpho::cc_tarjan(ima + c4);
+
+// for (unsigned i; i < 3; i++)
+// for (unsigned j; j < 3; j++)
+// {
+// if (i == 0)
+// assert(ima(i, j) == 1);
+// if (i == 1)
+// assert(ima(i, j) == 0);
+// if (i == 2)
+// assert(ima(i, j) == 2);
+// }
+}
Index: tests/algorithms/Makefile.am
--- tests/algorithms/Makefile.am (revision 915)
+++ tests/algorithms/Makefile.am (working copy)
@@ -24,10 +24,12 @@
check_PROGRAMS = \
fill \
- basic_morpho
+ basic_morpho \
+ cc_tarjan
# Algorithms.
fill_SOURCES = fill.cc
basic_morpho_SOURCES = basic_morpho.cc
+cc_tarjan_SOURCES = cc_tarjan.cc
TESTS = $(check_PROGRAMS)
Index: oln/morpho/cc_tarjan.hh
--- oln/morpho/cc_tarjan.hh (revision 912)
+++ oln/morpho/cc_tarjan.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef OLN_MORPHO_DILATION_HH
# define OLN_MORPHO_DILATION_HH
+#include <oln/debug/print.hh>
+
namespace oln
{
@@ -35,70 +37,111 @@
{
template <typename I>
- oln_point(I) find_root(const oln_point(I)& x)
+ oln_point(I) find_root(I& ima,
+ const oln_point(I)& x,
+ oln_plain_value(I, oln_point(I))& parent)
{
- if (parent[x] != x)
+ std::cout << "enter_root( " << parent(x) << "," << x << " )" << std::endl;
+
+ if (parent(x) != x)
{
- parent[x] = find_root(parent[x]);
+ parent(x) = find_root(ima, parent(x), parent);
return parent(x);
}
return x;
+
+ std::cout << "leave_root" << std::endl;
}
template <typename I>
- void do_union(const oln_point(I)& n,
+ void do_union(I& ima,
+ const oln_point(I)& n,
const oln_point(I)& p,
- const oln_plain_value(I, oln_point(I))& parent)
+ oln_plain_value(I, oln_point(I))& parent)
{
- oln_point(I) r = find_root(n);
+ oln_point(I) r = find_root(ima, n, parent);
if (r != p)
parent(r) = p;
}
template <typename I>
- oln_plain_value(I, unsigned)
- cc_tarjan(const Binary_Image<I>& input)
+ void first_pass(const I& input,
+ oln_plain_value(I, oln_point(I))& parent,
+ oln_plain(I)& is_processed)
{
- oln_plain_value(I, unsigned) output;
- prepare(output, with, input);
-
- oln_plain_value(I, oln_point(I)) parent;
- prepare(parent, with, input);
-
- // Init
- unsigned current_label = 0;
- oln_plain(I) is_processed;
- prepare(is_processed, with, input);
- oln_piter(I) p(input.points());
- for_all(p)
- is_processed(p) = false; // FIXME : built with.
-
-
- // Fist pass
- oln_piter(I) p(input.points());
+ oln_bkd_piter(I) p(input.points());
for_all(p)
{
+ if ( input(p) )
+ {
+ parent(p) = p;
oln_niter(I) n(p, input);
for_all(n)
{
+ if ( input(n) )
+ {
if ( is_processed(n) )
- do_union(n, p, parent);
+ {
+ do_union(input ,n, p, parent);
+ std::cout << "union ("<< p << ") -> parent :" << std::endl;
+ debug::print(parent);
+ }
+ }
}
is_processed(p) = true;
}
+ }
+ std::cout << "pass 1" << std::endl;
+ }
+ template <typename I>
+ void second_pass(const I& input,
+ oln_plain_value(I, oln_point(I))& parent,
+ oln_plain_value(I, unsigned)& output)
+ {
+ unsigned current_label = 0;
// Second pass
- oln_piter(I) p2(input.points());
- for_all(p2)
+ oln_fwd_piter(I) p(input.points());
+ for_all(p)
+ {
+ if ( input(p) )
{
if ( parent(p) == p )
output(p) = ++current_label;
else
output(p) = output(parent(p));
+ std::cout << "output :" << std::endl;
+ debug::print(output);
+ }
}
}
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Image_with_Nbh<I>& input)
+ {
+ oln_plain_value(I, unsigned) output;
+ prepare(output, with, input);
+
+ oln_plain_value(I, oln_point(I)) parent;
+ prepare(parent, with, input);
+
+ // Init
+ oln_plain(I) is_processed;
+ prepare(is_processed, with, input);
+ oln_piter(I) p1(input.points());
+ for_all(p1)
+ is_processed(p1) = false; // FIXME : built with.
+
+ first_pass(input, parent, is_processed);
+
+ second_pass(input, parent, output);
+
+ ::oln::debug::print(parent);
+ return output;
+ }
+
} // end of namespace oln::morpho
} // end of namespace oln
Index: oln/level/apply.hh
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add traits and fix compile errors.
* oln/core/gen/traits.hh,
* oln/value/builtin.hh: New.
* oln/arith/plus.hh (include): Fix.
(set_trait_): New.
(operator +): Update sig and use 'prepare'.
* oln/arith/minus.hh: Likewise.
* oln/core/concept/image.hh (Fast_Image): Fix.
* oln/core/concept/point.hh (set_trait_): New.
(assert_same_point_): New.
* oln/core/concept/generalised_point.hh: Fix.
* oln/core/concept/dpoint.hh (set_trait_): New.
* oln/core/concept/operators.hh (include): Add
oln/core/gen/traits.hh.
* oln/core/init.hh: Cosmetic change.
* oln/core/2d/image2d_b.hh (prepare): Fix.
* oln/core/2d/box2d.hh (box2d): Fix.
* oln/core/gen/fun.hh (fun_p2b_, fun_v2v_): Add & to ctor arg.
(fun_p2v_, functorize_p2v): New.
* oln/core/internal/box.hh: Cosmetic changes.
* oln/core/internal/image_base.hh (operator |): Activate test.
* oln/core/internal/iterator_on_points_base.hh: Fix.
* oln/morpher/add_isubset.hh,
* oln/morpher/add_isubset.hxx,
* oln/morpher/add_neighborhood.hxx: Remove; obsolete.
* oln/level/fill.hh (include): Update.
(fill): Rename the internal routines as...
(fill_from_value_, fill_from_values_): ...these...
(fill_from_image_, fill_from_function_): ...and these.
(fill_): Activate.
(fill): Activate version for Function_p2v.
(fill): New version for Image.
arith/minus.hh | 35 +++--
arith/plus.hh | 33 +++--
core/2d/box2d.hh | 6
core/2d/image2d_b.hh | 2
core/concept/dpoint.hh | 23 +++
core/concept/generalised_point.hh | 11 -
core/concept/image.hh | 2
core/concept/operators.hh | 2
core/concept/point.hh | 38 +++++
core/gen/fun.hh | 65 +++++++++-
core/gen/traits.hh | 199 +++++++++++++++++++++++++++++++
core/init.hh | 2
core/internal/box.hh | 13 +-
core/internal/image_base.hh | 6
core/internal/iterator_on_points_base.hh | 7 -
level/fill.hh | 92 +++++++-------
value/builtin.hh | 98 +++++++++++++++
17 files changed, 534 insertions(+), 100 deletions(-)
Index: oln/level/fill.hh
--- oln/level/fill.hh (revision 914)
+++ oln/level/fill.hh (working copy)
@@ -29,8 +29,12 @@
#ifndef OLN_LEVEL_FILL_HH
# define OLN_LEVEL_FILL_HH
+#include <iostream>
+
# include <oln/core/concept/image.hh>
-// # include <oln/core/concept/function.hh>
+# include <oln/core/concept/point.hh>
+# include <oln/core/gen/fun.hh>
+
namespace oln
@@ -38,7 +42,7 @@
namespace ERROR
{
- struct FIRST_ARGUMENT_OF_oln_level_fill_IS_NOT_MUTABLE;
+ struct FIRST_ARGUMENT_OF_oln_level_fill_IS_NOT_MUTABLE; // FIXME: Use it!
}
@@ -53,16 +57,17 @@
template <typename I, typename V>
void fill(Mutable_Image<I>& input, const V values[]);
- template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(P));
+ template <typename I, typename J>
+ void fill(Mutable_Image<I>& input, const Image<J>& ima);
+ template <typename I, typename F>
+ void fill(Mutable_Image<I>& input, const Function_p2v<F>& fun);
+ template <typename I, typename V, typename P>
+ void fill(Mutable_Image<I>& input, V (*fun)(P));
// FIXME: Inactivated.
-// template <typename I, typename F>
-// void fill(Mutable_Image<I>& input, const abstract::fun_p2v<F>& fun);
-
// template <typename I>
// void fill(Value_Wise_Mutable_Image<I>& input, const oln_value(I)& value);
@@ -74,24 +79,15 @@
{
template <typename I>
- void fill(Mutable_Image<I>& input, const oln_value(I)& value)
+ void fill_from_value_(Mutable_Image<I>& input, const oln_value(I)& value)
{
oln_piter(I) p(input.points());
for_all(p)
input(p) = value;
}
-// template <typename I>
-// void fill(Value_Wise_Mutable_Image<I>& input,
-// const oln_value(I)& value)
-// {
-// oln_viter(I) v(input);
-// for_all(v)
-// input.value_(v) = value;
-// }
-
template <typename I, typename V>
- void fill(Mutable_Image<I>& input, const V values[])
+ void fill_from_values_(Mutable_Image<I>& input, const V values[])
{
oln_piter(I) p(input.points());
unsigned i = 0;
@@ -99,20 +95,29 @@
input(p) = values[i++];
}
- template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(P))
+ template <typename I, typename J>
+ void fill_from_image_(Mutable_Image<I>& input, const Image<J>& ima)
{
oln_piter(I) p(input.points());
for_all(p)
- input(p) = fun(p);
+ input(p) = ima(p);
}
-// template <typename I, typename F>
-// void fill(Mutable_Image<I>& input, const abstract::fun_p2v<F>& fun)
+ template <typename I, typename F>
+ void fill_from_function_(Mutable_Image<I>& input, const F& f)
+ {
+ oln_piter(I) p(input.points());
+ for_all(p)
+ input(p) = f(p);
+ }
+
+// template <typename I>
+// void fill_(Value_Wise_Mutable_Image<I>& input,
+// const oln_value(I)& value)
// {
-// oln_piter(I) p(input.points());
-// for_all(p)
-// input(p) = fun.exact()(p);
+// oln_viter(I) v(input);
+// for_all(v)
+// input.value_(v) = value;
// }
} // end of namespace oln::level::impl
@@ -124,34 +129,37 @@
template <typename I>
void fill(Mutable_Image<I>& input, const oln_value(I)& value)
{
- impl::fill(exact(input), value);
+ impl::fill_from_value_(exact(input), value);
}
template <typename I, typename V>
void fill(Mutable_Image<I>& input, const V values[])
{
- impl::fill(exact(input), values);
+ impl::fill_from_values_(exact(input), values);
}
- template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(P))
+ template <typename I, typename J>
+ void fill(Mutable_Image<I>& input, const Image<J>& ima)
{
- impl::fill(exact(input), fun);
+ assert_same_grid_<I, J>::check();
+ precondition(input.points() <= ima.points());
+ impl::fill_from_image_(exact(input), exact(ima));
}
-// template <typename I, typename F>
-// void fill(Mutable_Image<I>& input, const abstract::fun_p2v<F>& fun)
-// {
-// impl::fill(exact(input), fun);
-// }
+ template <typename I, typename F>
+ void fill(Mutable_Image<I>& input, const Function_p2v<F>& fun)
+ {
+ impl::fill_from_function_(exact(input), exact(fun));
+ }
-// template <typename I>
-// void fill(Value_Wise_Mutable_Image<I>& input, const oln_value(I)& value)
-// {
-// impl::fill(exact(input), value);
-// }
+ template <typename I, typename V, typename P>
+ void fill(Mutable_Image<I>& input, V (*f)(P))
+ {
+ mlc::assert_< mlc_is_a(P, Point) >::check(); // FIXME: Add err msg.
+ impl::fill_from_function_(exact(input), functorize_p2v(f));
+ }
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::level
Index: oln/arith/plus.hh
--- oln/arith/plus.hh (revision 914)
+++ oln/arith/plus.hh (working copy)
@@ -28,27 +28,40 @@
#ifndef OLN_ARITH_PLUS_HH
# define OLN_ARITH_PLUS_HH
+# include <oln/core/concept/image.hh>
+// # include <oln/core/internal/f_ch_value.hh>
+# include <oln/core/gen/traits.hh>
+
namespace oln
{
- namespace arith
+
+ // Trait.
+
+ template <typename I, typename J>
+ struct set_trait_< Image, I, plus_id, Image, J >
{
+ typedef oln_plus_trait(oln_value(I), oln_value(J)) V;
+ typedef oln_plain_value(I, V) ret;
+ };
// Fwd decl.
- template <typename I>
- oln_plain(I)
- operator + (const Image<I>& lhs, const Image<I>& rhs);
+ template <typename I, typename J>
+ oln_plus_trait(I, J)
+ operator + (const Image<I>& lhs, const Image<J>& rhs);
+
# ifndef OLN_INCLUDE_ONLY
- template <typename I>
- oln_plain(I)
- operator + (const Image<I>& lhs, const Image<I>& rhs)
+ template <typename I, typename J>
+ oln_plus_trait(I, J)
+ operator + (const Image<I>& lhs, const Image<J>& rhs)
{
- oln_plain(I) output;
- init(output, with, lhs);
+ precondition(lhs.points() = rhs.points());
+ oln_plus_trait(I, J) output;
+ prepare(output, with, lhs);
oln_piter(I) p(lhs.points());
for_all(p)
output(p) = lhs(p) + rhs(p);
@@ -57,8 +70,6 @@
# endif // ! OLN_INCLUDE_ONLY
- } // end of namespace oln::arith
-
} // end of namespace oln
#endif // ! OLN_ARITH_PLUS_HH
Index: oln/arith/minus.hh
--- oln/arith/minus.hh (revision 914)
+++ oln/arith/minus.hh (working copy)
@@ -28,27 +28,40 @@
#ifndef OLN_ARITH_MINUS_HH
# define OLN_ARITH_MINUS_HH
+# include <oln/core/concept/image.hh>
+// # include <oln/core/internal/f_ch_value.hh>
+# include <oln/core/gen/traits.hh>
+
namespace oln
{
-// namespace arith
-// {
+ // Trait.
+
+ template <typename I, typename J>
+ struct set_trait_< Image, I, minus_id, Image, J >
+ {
+ typedef oln_minus_trait(oln_value(I), oln_value(J)) V;
+ typedef oln_plain_value(I, V) ret;
+ };
+
// Fwd decl.
- template <typename I>
- oln_plain(I)
- operator - (const Image<I>& lhs, const Image<I>& rhs);
+ template <typename I, typename J>
+ oln_minus_trait(I, J)
+ operator - (const Image<I>& lhs, const Image<J>& rhs);
+
# ifndef OLN_INCLUDE_ONLY
- template <typename I>
- oln_plain(I)
- operator - (const Image<I>& lhs, const Image<I>& rhs)
+ template <typename I, typename J>
+ oln_minus_trait(I, J)
+ operator - (const Image<I>& lhs, const Image<J>& rhs)
{
- oln_plain(I) output;
- init(output, with, lhs);
+ precondition(lhs.points() = rhs.points());
+ oln_minus_trait(I, J) output;
+ prepare(output, with, lhs);
oln_piter(I) p(lhs.points());
for_all(p)
output(p) = lhs(p) - rhs(p);
@@ -57,8 +70,6 @@
# endif // ! OLN_INCLUDE_ONLY
-// } // end of namespace oln::arith
-
} // end of namespace oln
#endif // ! OLN_ARITH_MINUS_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 914)
+++ oln/core/concept/image.hh (working copy)
@@ -200,7 +200,7 @@
public automatic::get_impl<Fast_Image, Exact>
{
stc_using_from(Image, rvalue);
- stc_using_from(Image, lvalue);
+ stc_using_from(Mutable_Image, lvalue);
stc_typename(index);
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 914)
+++ oln/core/concept/point.hh (working copy)
@@ -72,9 +72,18 @@
}; // end of oln::Point<Exact>
+
/// Operator -.
+
template <typename P>
- typename P::dpoint operator-(const Point<P>& lhs, const Point<P>& rhs);
+ struct set_trait_< Point, P, minus_id, Point, P >
+ {
+ typedef typename P::dpoint ret;
+ };
+
+ template <typename P>
+ typename P::dpoint
+ operator - (const Point<P>& lhs, const Point<P>& rhs);
@@ -91,6 +100,28 @@
+ namespace ERROR
+ {
+
+ template < typename Type_1,
+ typename Type_2,
+ typename Point_1 = oln_point(Type_1),
+ typename Point_2 = oln_point(Type_2) >
+ struct both_types_should_have_the_same_point_
+ {
+ };
+
+ } // end of namespace oln::ERROR
+
+
+ template <typename T1, typename T2>
+ struct assert_same_point_
+ : public mlc::assert_< mlc::eq_<oln_point(T1), oln_point(T2)>,
+ ERROR::both_types_should_have_the_same_point_<T1, T2> >
+ {};
+
+
+
# ifndef OLN_INCLUDE_ONLY
@@ -134,12 +165,13 @@
}
template <typename P>
- typename P::dpoint operator-(const Point<P>& lhs, const Point<P>& rhs)
+ typename P::dpoint
+ operator-(const Point<P>& lhs, const Point<P>& rhs)
{
return lhs.op_minus_(exact(rhs));
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/generalised_point.hh
--- oln/core/concept/generalised_point.hh (revision 914)
+++ oln/core/concept/generalised_point.hh (working copy)
@@ -31,10 +31,6 @@
namespace oln
{
- /// FIXME: Instant value.
- // oln_decl_instant_value(point);
-
-
// Generalised_Point concept
template <typename Exact>
@@ -58,11 +54,10 @@
template <typename Exact>
Generalised_Point<Exact>::Generalised_Point()
{
- };
-
+ }
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
-}
+} // end of namespace oln
#endif // !OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
Index: oln/core/concept/dpoint.hh
--- oln/core/concept/dpoint.hh (revision 914)
+++ oln/core/concept/dpoint.hh (working copy)
@@ -80,12 +80,35 @@
}; // end of oln::Dpoint<Exact>
+ /// \{
+ /// Operator "Point - Dpoint".
+
+ template <typename P, typename D>
+ struct set_trait_< Point, P, minus_id, Dpoint, D >
+ {
+ typedef P ret;
+ };
+
template <typename P, typename D>
P operator-(const Point<P>& lhs, const Dpoint<D>& rhs);
+ /// \}
+
+
+ /// \{
+ /// Operator "Point + Dpoint".
+
+ template <typename P, typename D>
+ struct set_trait_< Point, P, plus_id, Dpoint, D >
+ {
+ typedef P ret;
+ };
+
template <typename P, typename D>
P operator+(const Point<P>& lhs, const Dpoint<D>& rhs);
+ /// \}
+
/// \{
/// Invalid operators.
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 914)
+++ oln/core/concept/operators.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_CONCEPT_OPERATORS_HH
# include <oln/core/equipment.hh>
+# include <oln/core/gen/traits.hh>
namespace oln
@@ -76,7 +77,6 @@
-
# ifndef OLN_INCLUDE_ONLY
template <typename L, typename R>
Index: oln/core/init.hh
--- oln/core/init.hh (revision 914)
+++ oln/core/init.hh (working copy)
@@ -181,7 +181,7 @@
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 914)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -250,7 +250,7 @@
bool box_ok = init(b, with, dat);
postcondition(box_ok);
unsigned border = 2; // FIXME: Use init!
- array2d_<T,int> ptr = new array2d_<T,int>(b.pmin().row() - border,
+ array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row() - border,
b.pmin().col() - border,
b.pmax().row() + border,
b.pmax().col() + border);
Index: oln/core/2d/box2d.hh
--- oln/core/2d/box2d.hh (revision 914)
+++ oln/core/2d/box2d.hh (working copy)
@@ -63,6 +63,7 @@
public:
// Note: we can't use stc_using because box2d isn't a templated class
typedef super::point point;
+ typedef super::from_to_t from_to_t;
box2d();
box2d(const box2d::from_to_t& dat);
@@ -102,9 +103,10 @@
}
template <typename D>
- box2d::box2d(const internal::initializer_<D>& data) :
- super(data)
+ box2d::box2d(const internal::initializer_<D>& data)
{
+ bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value());
+ postcondition(box_ok);
}
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 914)
+++ oln/core/gen/fun.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/internal/category_of.hh>
# include <oln/core/concept/function.hh>
# include <oln/core/concept/image.hh>
+# include <oln/core/concept/point.hh>
# include <oln/core/concept/value.hh>
@@ -41,6 +42,10 @@
+// FIXME: Separate defs and decls.
+
+
+
namespace oln
{
@@ -105,7 +110,7 @@
typedef oln_arg_of_(F) argument;
typedef oln_res_of_(F) result;
- fun_p2b_(F f) : f_(f) {}
+ fun_p2b_(const F& f) : f_(f) {}
result operator()(argument arg) const
{
@@ -138,6 +143,53 @@
+ // ----------------------------- fun_p2v_<F>
+
+
+ // Fwd decl.
+ template <typename F> struct fun_p2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F>
+ struct set_category_of_< fun_p2v_<F> >
+ {
+ typedef stc::is< Function_p2v > ret;
+ };
+ }
+
+ // Class.
+ template <typename F>
+ struct fun_p2v_ : public Function_p2v< fun_p2v_<F> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) result;
+
+ fun_p2v_(const F& f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return this->f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+
+ // functorize_p2v
+
+ template <typename V, typename P>
+ fun_p2v_<V (*)(P)>
+ functorize_p2v(V (*f)(P))
+ {
+ mlc::assert_< mlc_is_a(P, Point) >::check(); // FIXME: Add err msg.
+ fun_p2v_<V (*)(P)> tmp(f);
+ return tmp;
+ }
+
+
// ----------------------------- fun_v2v_<F>
@@ -161,7 +213,7 @@
typedef oln_arg_of_(F) argument;
typedef oln_res_of_(F) result;
- fun_v2v_(F f) : f_(f) {}
+ fun_v2v_(const F& f) : f_(f) {}
result operator()(argument arg) const
{
@@ -174,11 +226,12 @@
// functorize_v2v
- template <typename R, typename A>
- fun_v2v_<R (*)(A)>
- functorize_v2v(R (*f)(A))
+
+ template <typename Vr, typename Va>
+ fun_v2v_<Vr (*)(Va)>
+ functorize_v2v(Vr (*f)(Va))
{
- fun_v2v_<R (*)(A)> tmp(f);
+ fun_v2v_<Vr (*)(Va)> tmp(f);
return tmp;
}
Index: oln/core/gen/traits.hh
--- oln/core/gen/traits.hh (revision 0)
+++ oln/core/gen/traits.hh (revision 0)
@@ -0,0 +1,199 @@
+// Copyright (C) 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
+// 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_GEN_TRAITS_HH
+# define OLN_CORE_GEN_TRAITS_HH
+
+# include <oln/core/internal/category_of.hh>
+
+
+// arith
+
+# define oln_plus_trait(L, R) \
+ typename oln::get_trait_<L, oln::plus_id, R>::ret
+
+# define oln_minus_trait(L, R) \
+ typename oln::get_trait_<L, oln::minus_id, R>::ret
+
+# define oln_times_trait(L, R) \
+ typename oln::get_trait_<L, oln::times_id, R>::ret
+
+# define oln_div_trait(L, R) \
+ typename oln::get_trait_<L, oln::div_id, R>::ret
+
+# define oln_mod_trait(L, R) \
+ typename oln::get_trait_<L, oln::mod_id, R>::ret
+
+// cmp
+
+# define oln_eq_trait(L, R) \
+ typename oln::get_trait_<L, oln::eq_id, R>::ret
+
+# define oln_neq_trait(L, R) \
+ typename oln::get_trait_<L, oln::neq_id, R>::ret
+
+// ord
+
+# define oln_less_trait(L, R) \
+ typename oln::get_trait_<L, oln::less_id, R>::ret
+
+# define oln_leq_trait(L, R) \
+ typename oln::get_trait_<L, oln::leq_id, R>::ret
+
+# define oln_geq_trait(L, R) \
+ typename oln::get_trait_<L, oln::geq_id, R>::ret
+
+# define oln_greater_trait(L, R) \
+ typename oln::get_trait_<L, oln::greater_id, R>::ret
+
+// logic
+
+# define oln_and_trait(L, R) \
+ typename oln::get_trait_<L, oln::and_id, R>::ret
+
+# define oln_or_trait(L, R) \
+ typename oln::get_trait_<L, oln::or_id, R>::ret
+
+# define oln_xor_trait(L, R) \
+ typename oln::get_trait_<L, oln::xor_id, R>::ret
+
+
+
+
+
+
+
+
+# define oln_internal_specialize_bin_trait_bool_(Name) \
+ \
+ template <template <class> class Cl, typename L, \
+ template <class> class Cr, typename R> \
+ struct set_trait_< Cl, L, Name##_id, Cr, R > \
+ { \
+ typedef bool ret; \
+ }
+
+
+# define oln_internal_specialize_bin_trait_T_(Name) \
+ \
+ template <template <class> class Cl, typename T, \
+ template <class> class Cr> \
+ struct set_trait_< Cl, T, Name##_id, Cr, T > \
+ { \
+ typedef T ret; \
+ }
+
+
+
+
+namespace oln
+{
+
+ // set_trait_
+
+ template <template <class> class Cl, typename L,
+ typename Op,
+ template <class> class Cr, typename R>
+ struct set_trait_;
+
+
+ // ids
+
+ struct plus_id;
+ struct minus_id;
+ struct times_id;
+ struct div_id;
+ struct mod_id;
+
+ struct eq_id;
+ struct neq_id;
+
+ struct less_id;
+ struct leq_id;
+ struct geq_id;
+ struct greater_id;
+
+ struct and_id;
+ struct or_id;
+ struct xor_id;
+
+
+
+ // default (see oln/core/concept/operators.hh)
+
+ /*
+
+ oln_internal_specialize_bin_trait_T_(plus);
+ oln_internal_specialize_bin_trait_T_(minus);
+ oln_internal_specialize_bin_trait_T_(times);
+ oln_internal_specialize_bin_trait_T_(div);
+ oln_internal_specialize_bin_trait_T_(mod);
+
+ oln_internal_specialize_bin_trait_bool_(eq);
+ oln_internal_specialize_bin_trait_bool_(neq);
+
+ oln_internal_specialize_bin_trait_bool_(less);
+ oln_internal_specialize_bin_trait_bool_(leq);
+ oln_internal_specialize_bin_trait_bool_(geq);
+ oln_internal_specialize_bin_trait_bool_(greater);
+
+ oln_internal_specialize_bin_trait_T_(and);
+ oln_internal_specialize_bin_trait_T_(or);
+ oln_internal_specialize_bin_trait_T_(xor);
+
+ */
+
+
+ namespace internal
+ {
+
+ // get_trait_cat_
+
+ template <typename Cl, typename L, typename Op, typename Cr, typename R>
+ struct get_trait_cat__;
+
+ template < template <class> class Cl, typename L,
+ typename Op,
+ template <class> class Cr, typename R >
+ struct get_trait_cat__< stc::is<Cl>, L, Op, stc::is<Cr>, R >
+ {
+ typedef typename oln::set_trait_< Cl, L, Op, Cr, R >::ret ret;
+ };
+
+ } // end of namespace oln::internal
+
+
+ template <typename L, typename Op, typename R>
+ struct get_trait_ : public internal::get_trait_cat__< oln_category_of_(L), L, Op, oln_category_of_(R), R >
+ {
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_TRAITS_HH
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 914)
+++ oln/core/internal/box.hh (working copy)
@@ -199,11 +199,11 @@
# ifndef OLN_INCLUDE_ONLY
- namespace internal
- {
- // -------------------- box_<Exact>
+ // -------------------- internal::box_<Exact>
+ namespace internal
+ {
template <typename Exact>
box_<Exact>::box_()
@@ -293,7 +293,9 @@
{
return this->pmax_;
}
- }
+
+ } // end of namespace oln::internal
+
// -------------------- box_fwd_piter_<B>
@@ -421,7 +423,8 @@
return &p_;
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace oln
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 914)
+++ oln/core/internal/image_base.hh (working copy)
@@ -493,7 +493,7 @@
oln_decl_op_such_as(Image, Function_p2b);
- // Specialization.
+ // Specialization "Image such_as f : P -> B".
template <typename I, typename B, typename P>
op_<const I, such_as, const fun_p2b_<B (*)(P)> >
@@ -507,13 +507,13 @@
}
- // Specialization.
+ // Specialization "Image such_as ima : P -> B".
template <typename I, typename J>
op_<const I, such_as, const fun_p2b_< Binary_Image<J> > >
operator | (const Image<I>& ima, const Binary_Image<J>& f_ima_b)
{
- // FIXME: Activate precondition(f_ima_b.points() >= ima.points());
+ precondition(f_ima_b.points() >= ima.points());
mlc::assert_equal_< oln_point(I), oln_point(J) >::check();
op_<const I, such_as, const fun_p2b_< Binary_Image<J> > > tmp(exact(ima), f_ima_b);
return tmp;
Index: oln/core/internal/iterator_on_points_base.hh
--- oln/core/internal/iterator_on_points_base.hh (revision 914)
+++ oln/core/internal/iterator_on_points_base.hh (working copy)
@@ -41,7 +41,7 @@
namespace internal {
template <typename Exact>
struct iterator_on_points_base;
- };
+ }
// Super type
@@ -88,10 +88,9 @@
}
# endif // !OLN_INCLUDE_ONLY
-}
+ } // end of namespace oln::internal
-
-}
+} // end of namespace oln
#endif // !OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
Index: oln/value/builtin.hh
--- oln/value/builtin.hh (revision 0)
+++ oln/value/builtin.hh (revision 0)
@@ -0,0 +1,98 @@
+// Copyright (C) 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
+// 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_VALUE_BUILTIN_HH
+# define OLN_VALUE_BUILTIN_HH
+
+# include <oln/core/concept/value.hh>
+# include <oln/core/gen/traits.hh>
+
+
+namespace oln
+{
+
+
+ // Fwd decl.
+ namespace internal { template <typename Exact> struct builtin_base; }
+
+
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::builtin_base<Exact> >
+ {
+ typedef stc::final< stc:is<Value> > category;
+ };
+
+
+ namespace internal
+ {
+
+ // Base class for builtin types.
+ template <typename Exact>
+ struct builtin_base : public Value<Exact>
+ {
+ protected:
+ builtin_base();
+ };
+
+ } // end of namespace oln::internal
+
+
+
+ // int
+
+ template <>
+ struct super_trait_< int >
+ {
+ typedef internal::builtin_base<int> ret;
+ };
+
+ template <>
+ struct super_trait_< float >
+ {
+ typedef internal::builtin_base<float> ret;
+ };
+
+
+ template <typename Op>
+ struct set_trait_< Value, int, Op, Value, float >
+ {
+ typedef float ret;
+ };
+
+ template <typename Op>
+ struct set_trait_< Value, float, Op, Value, int >
+ {
+ typedef float ret;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_VALUE_BUILTIN_HH
+
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add generalised_point concept.
* tests/core/sparse_image.cc,
* tests/core/rle_image.cc: remove print from tests.
* oln/core/rle/rle_pset.hh, oln/core/concept/iterator_on_points.hh,
* oln/core/gen/dpoints_piter.hh, oln/core/internal/box.hh,
* oln/core/internal/piter_adaptor.hh: there are now derived from iterator_on_point_base class.
* oln/core/concept/iterator.hh: add virtual for diamond inheritance.
* oln/core/concept/point.hh: remove useless traits declarations.
(there are now declare in generalised_point_class).
* oln/core/concept/generalised_point.hh: New, generalised_point class.
* oln/core/internal/image_base.hh: remove dead code.
* oln/core/internal/iterator_on_points_base.hh: New iterator_on_point_base class for
factorize some code on point iterators.
oln/core/concept/generalised_point.hh | 68 ++++++++++++++++++
oln/core/concept/iterator.hh | 2
oln/core/concept/iterator_on_points.hh | 5 +
oln/core/concept/point.hh | 12 +--
oln/core/gen/dpoints_piter.hh | 9 +-
oln/core/internal/box.hh | 9 +-
oln/core/internal/image_base.hh | 2
oln/core/internal/iterator_on_points_base.hh | 97 +++++++++++++++++++++++++++
oln/core/internal/piter_adaptor.hh | 8 +-
oln/core/rle/rle_pset.hh | 14 +--
tests/core/rle_image.cc | 45 ------------
tests/core/sparse_image.cc | 37 ----------
12 files changed, 196 insertions(+), 112 deletions(-)
Index: tests/core/sparse_image.cc
--- tests/core/sparse_image.cc (revision 911)
+++ tests/core/sparse_image.cc (working copy)
@@ -6,37 +6,6 @@
#include <oln/core/sparse/sparse_image.hh>
#include <oln/core/encode/sparse_encode.hh>
-template <typename Ps>
-void test(const Ps& pset)
-{
- typename Ps::fwd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-template <typename Ps>
-void rtest(const Ps& pset)
-{
- typename Ps::bkd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-
- template <typename I>
- void print(I& ima)
-{
- typename I::piter it (ima.points());
-
- for (it.start(); it.is_valid(); it.next())
- {
- std::cout << (oln::point2d) it << std::endl;
- std::cout << ima(it) << std::endl;
- }
-}
-
int main()
{
@@ -46,7 +15,6 @@
oln::sparse_image<oln::point2d, int> sparse2;
ima2d(oln::point2d(0, 4)) = 5;
- oln::debug::print(ima2d);
std::vector<int> values;
int a =5;
@@ -58,12 +26,7 @@
sparse.insert(q, 3, values);
- oln::debug::print(sparse);
-
- std::cout << "encode sparse" << std::endl;
sparse2 = sparse_encode(ima2d);
- oln::debug::print(sparse2);
-
return 0;
}
Index: tests/core/rle_image.cc
--- tests/core/rle_image.cc (revision 911)
+++ tests/core/rle_image.cc (working copy)
@@ -7,38 +7,6 @@
#include <oln/core/encode/rle_encode.hh>
-template <typename Ps>
-void test(const Ps& pset)
-{
- typename Ps::fwd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-template <typename Ps>
-void rtest(const Ps& pset)
-{
- typename Ps::bkd_piter it (pset);
-
- for (it.start(); it.is_valid(); it.next())
- std::cout << it.to_point() << std::endl;
-}
-
-
- template <typename I>
- void print(I& ima)
-{
- typename I::piter it (ima.points());
-
- for (it.start(); it.is_valid(); it.next())
- {
- std::cout << (oln::point2d) it << std::endl;
- std::cout << ima(it) << std::endl;
- }
-}
-
-
int main()
{
oln::point2d p(0,1), q(2,2), r(3, 0);
@@ -51,24 +19,11 @@
rle.insert(p, 5, 4);
rle.insert(q, 8, 9);
- std::cout << my_set.has(q) << std::endl;
- test(my_set);
- std::cout << "reverse" << std::endl;
- rtest(my_set);
- std::cout << "ima" << std::endl;
- print(rle);
- oln::debug::print(rle);
- std::cout << rle.points().npoints() << std::endl;
-
- std::cout << "encode rle" << std::endl;
oln::image2d<int> ima2d (1, 5);
ima2d(oln::point2d(0, 4)) = 5;
- oln::debug::print(ima2d);
-
rle2 = rle_encode(ima2d);
- oln::debug::print(rle2);
return 0;
}
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 911)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -35,7 +35,7 @@
# include <oln/core/internal/point_set_base.hh>
-# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
# include <oln/core/gen/fbbox.hh>
@@ -190,7 +190,7 @@
struct super_trait_< rle_pset_fwd_piter_<P> >
{
typedef rle_pset_fwd_piter_<P> current;
- typedef Iterator_on_Points<current> ret;
+ typedef internal::iterator_on_points_base<current> ret;
};
// Virtual types
@@ -208,9 +208,9 @@
** P must be a point type
*/
template <typename P>
- class rle_pset_fwd_piter_ : public Iterator_on_Points<rle_pset_fwd_piter_<P> >
+ class rle_pset_fwd_piter_ : public internal::iterator_on_points_base<rle_pset_fwd_piter_<P> >
{
- typedef Iterator_on_Points< rle_pset_fwd_piter_<P> > super;
+ typedef internal::iterator_on_points_base< rle_pset_fwd_piter_<P> > super;
typedef rle_pset_fwd_piter_<P> current;
public:
stc_using(point);
@@ -328,7 +328,7 @@
struct super_trait_< rle_pset_bkd_piter_<P> >
{
typedef rle_pset_bkd_piter_<P> current;
- typedef Iterator_on_Points<current> ret;
+ typedef internal::iterator_on_points_base<current> ret;
};
// Virtual type
@@ -345,9 +345,9 @@
** P must be a point type
*/
template <typename P>
- class rle_pset_bkd_piter_ : public Iterator_on_Points<rle_pset_bkd_piter_<P> >
+ class rle_pset_bkd_piter_ : public internal::iterator_on_points_base<rle_pset_bkd_piter_<P> >
{
- typedef Iterator_on_Points< rle_pset_bkd_piter_<P> > super;
+ typedef internal::iterator_on_points_base< rle_pset_bkd_piter_<P> > super;
typedef rle_pset_bkd_piter_<P> current;
public:
stc_using(point);
Index: oln/core/concept/iterator_on_points.hh
--- oln/core/concept/iterator_on_points.hh (revision 911)
+++ oln/core/concept/iterator_on_points.hh (working copy)
@@ -30,6 +30,8 @@
# define OLN_CORE_CONCEPT_ITERATOR_ON_POINTS_HH
# include <ostream>
+
+# include <oln/core/concept/generalised_point.hh>
# include <oln/core/concept/iterator.hh>
# include <oln/core/concept/point.hh>
@@ -40,7 +42,8 @@
/// Concept-class "Iterator_on_Points".
template <typename Exact>
- struct Iterator_on_Points : public Iterator<Exact>
+ struct Iterator_on_Points : public Iterator<Exact>,
+ virtual public Generalised_Point<Exact>
{
stc_typename(point);
Index: oln/core/concept/iterator.hh
--- oln/core/concept/iterator.hh (revision 911)
+++ oln/core/concept/iterator.hh (working copy)
@@ -44,7 +44,7 @@
/// Concept-class "Iterator".
template <typename Exact>
- struct Iterator : public Any<Exact>
+ struct Iterator : virtual public Any<Exact>
{
void start();
void next();
Index: oln/core/concept/point.hh
--- oln/core/concept/point.hh (revision 911)
+++ oln/core/concept/point.hh (working copy)
@@ -30,11 +30,14 @@
# define OLN_CORE_CONCEPT_POINT_HH
# include <mlc/value.hh>
+
+# include <oln/core/concept/generalised_point.hh>
# include <oln/core/concept/grid.hh>
# include <oln/core/concept/operators.hh>
+
namespace oln
{
/// Instant value.
@@ -44,14 +47,9 @@
/// Concept-class "Point".
template <typename Exact>
- struct Point : public Any<Exact>
+ struct Point : public Generalised_Point<Exact>
{
- stc_typename(grid);
- stc_typename(dim);
- stc_typename(coord);
- stc_typename(dpoint);
-
- enum { n = mlc_value(dim) };
+ stc_using_from(Generalised_Point, dpoint);
/// Operator ==.
bool op_equal_(const Exact& rhs) const;
Index: oln/core/concept/generalised_point.hh
--- oln/core/concept/generalised_point.hh (revision 0)
+++ oln/core/concept/generalised_point.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 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
+// 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_CONCEPT_GENERALISED_POINTS_HH
+# define OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
+
+namespace oln
+{
+
+ /// FIXME: Instant value.
+ // oln_decl_instant_value(point);
+
+
+ // Generalised_Point concept
+
+ template <typename Exact>
+ struct Generalised_Point : virtual public Any<Exact>
+ {
+ stc_typename(grid);
+ stc_typename(dim);
+ stc_typename(coord);
+ stc_typename(dpoint);
+
+ enum { n = mlc_value(dim) };
+
+ protected:
+ Generalised_Point();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Generalised_Point<Exact>::Generalised_Point()
+ {
+ };
+
+
+# endif // OLN_INCLUDE_ONLY
+
+}
+
+#endif // !OLN_CORE_CONCEPT_GENERALISED_POINTS_HH
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 911)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -31,6 +31,7 @@
# include <oln/core/concept/window.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/concept/image.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
# include <oln/core/internal/dpoints_piter_impl.hh>
@@ -51,7 +52,7 @@
struct super_trait_< dpoints_fwd_piter_<P> >
{
typedef dpoints_fwd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -65,7 +66,7 @@
// Forward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
+ class dpoints_fwd_piter_ : public internal::iterator_on_points_base< dpoints_fwd_piter_<P> >,
public internal::dpoints_fwd_piter_impl_<P>
{
public:
@@ -98,7 +99,7 @@
struct super_trait_< dpoints_bkd_piter_<P> >
{
typedef dpoints_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -112,7 +113,7 @@
/// Backward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P> >,
+ class dpoints_bkd_piter_ : public internal::iterator_on_points_base< dpoints_bkd_piter_<P> >,
public internal::dpoints_bkd_piter_impl_<P>
{
public:
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 911)
+++ oln/core/internal/box.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_CORE_INTERNAL_BOX_HH
# include <oln/core/internal/point_set_base.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
namespace oln
@@ -116,14 +117,14 @@
struct super_trait_< box_fwd_piter_<B> >
{
typedef box_fwd_piter_<B> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
template <typename B>
struct super_trait_<box_bkd_piter_<B> >
{
typedef box_bkd_piter_<B> current__;
- typedef Iterator_on_Points<current__> ret;
+ typedef internal::iterator_on_points_base<current__> ret;
};
@@ -145,7 +146,7 @@
/// Class box_fwd_piter_<P>.
template <typename B>
- class box_fwd_piter_ : public Iterator_on_Points< box_fwd_piter_<B> >,
+ class box_fwd_piter_ : public internal::iterator_on_points_base< box_fwd_piter_<B> >,
private mlc::assert_< mlc_is_a(B, Point_Set) >
{
typedef box_fwd_piter_<B> current;
@@ -171,7 +172,7 @@
/// Class box_bkd_piter_<B>.
template <typename B>
- class box_bkd_piter_ : public Iterator_on_Points< box_bkd_piter_<B> >,
+ class box_bkd_piter_ : public internal::iterator_on_points_base< box_bkd_piter_<B> >,
private mlc::assert_< mlc_is_a(B, Point_Set) >
{
typedef box_bkd_piter_<B> current;
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 911)
+++ oln/core/internal/image_base.hh (working copy)
@@ -148,8 +148,6 @@
// Final.
typedef stc::final< stc::is<Image> > category;
- // FIXME:
- //typedef stc::final< box_<point__> > box;
typedef stc::final <typename pset__::box> box;
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< oln_dpoint(point__) > dpoint;
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 911)
+++ oln/core/internal/piter_adaptor.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
# define OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
-# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/internal/iterator_on_points_base.hh>
namespace oln
@@ -43,7 +43,7 @@
template <typename Exact>
struct super_trait_< internal::piter_adaptor_<Exact> >
{
- typedef Iterator_on_Points<Exact> ret;
+ typedef internal::iterator_on_points_base<Exact> ret;
};
@@ -65,9 +65,9 @@
// defined over other types of iterator on points.
template <typename Exact>
- class piter_adaptor_ : public Iterator_on_Points<Exact>
+ class piter_adaptor_ : public internal::iterator_on_points_base<Exact>
{
- typedef Iterator_on_Points<Exact> super;
+ typedef internal::iterator_on_points_base<Exact> super;
public:
stc_using(point);
Index: oln/core/internal/iterator_on_points_base.hh
--- oln/core/internal/iterator_on_points_base.hh (revision 0)
+++ oln/core/internal/iterator_on_points_base.hh (revision 0)
@@ -0,0 +1,97 @@
+// Copyright (C) 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
+// 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_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
+# define OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
+
+# include <oln/core/concept/iterator_on_points.hh>
+
+namespace oln
+{
+
+ // implementation
+
+
+ // Forward Declarations
+
+ namespace internal {
+ template <typename Exact>
+ struct iterator_on_points_base;
+ };
+
+ // Super type
+
+ template <typename Exact>
+ struct super_trait_< internal::iterator_on_points_base<Exact> >
+ {
+ typedef Iterator_on_Points<Exact> ret;
+ };
+
+ // Virtual types
+
+ template <typename Exact>
+ struct vtypes< internal::iterator_on_points_base<Exact> >
+ {
+ typedef stc::abstract point;
+
+ typedef stc_deferred(point) point__;
+ typedef stc::final<typename point__::grid> grid;
+ typedef stc::final<typename point__::coord> coord;
+ typedef stc::final<typename point__::dim> dim;
+ typedef stc::final<typename point__::dpoint> dpoint;
+ };
+
+
+
+namespace internal
+{
+ // iterator_on_points_base class
+
+ template <typename Exact>
+ class iterator_on_points_base : public Iterator_on_Points<Exact>
+ {
+
+ protected:
+ iterator_on_points_base();
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ iterator_on_points_base<Exact>::iterator_on_points_base()
+ {
+ }
+
+# endif // !OLN_INCLUDE_ONLY
+}
+
+
+
+}
+
+#endif // !OLN_CORE_INTERNAL_ITERATOR_ON_POINTS_BASE_HH
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix 'Make check morpho' / 'morpho'. draft cc_tarjan .
* olena/tests/algorithms/basic_morpho.cc: .
* olena/oln/morpho/dilation.hh: .
* olena/oln/morpho/cc_tarjan.cc: New.
* olena/oln/morpho/erosion.hh: .
* olena/oln/level/apply.hh: .
* olena/oln/core/2d/image2d.hh: .
* olena/oln/core/internal/image_base.hh: .
oln/core/2d/image2d.hh | 3 -
oln/core/internal/image_base.hh | 16 ++---
oln/level/apply.hh | 2
oln/morpho/cc_tarjan.cc | 107 +++++++++++++++++++++++++++++++++++++++
oln/morpho/dilation.hh | 25 +++++----
oln/morpho/erosion.hh | 25 +++++----
tests/algorithms/basic_morpho.cc | 60 ++++++---------------
7 files changed, 164 insertions(+), 74 deletions(-)
Index: olena/tests/algorithms/basic_morpho.cc
--- olena/tests/algorithms/basic_morpho.cc (revision 910)
+++ olena/tests/algorithms/basic_morpho.cc (working copy)
@@ -17,6 +17,15 @@
#include <oln/debug/print.hh>
+
+template <typename I>
+void my_test(I ima, int i)
+{
+ oln_piter(I) p1(ima.points());
+ for_all(p1)
+ assert(ima(p1) == i);
+}
+
int main()
{
using namespace oln;
@@ -31,54 +40,19 @@
for_all(p1)
ima(p1) = i++ % 2;
- std::cout << "ima" << std::endl;
- debug::print(ima);
+ my_test( (morpho::elementary_erosion(ima + c4)).image(), 0);
+ my_test( (morpho::elementary_dilation(ima + c4)).image(), 1 );
- I tmp = (morpho::elementary_erosion(ima + c4)).image();
- p1 = tmp.points();
- for_all(p1)
- assert(tmp(p1) == 0);
+ my_test( (morpho::elementary_opening(ima + c4)).image(), 0);
- // std::cout << "elementary_dilation" << std::endl;
- tmp = (morpho::elementary_dilation(ima + c4)).image();
- p1 = tmp.points();
- for_all(p1)
- assert(tmp(p1) == 1);
+ my_test( (morpho::elementary_closing(ima + c4)).image(), 1);
- // std::cout << "erosion_w" << std::endl;
- tmp = morpho::erosion(ima, win3x3);
- p1 = tmp.points();
- for_all(p1)
- assert(tmp(p1) == 0);
+ my_test( morpho::erosion(ima, win3x3), 0);
- // std::cout << "dilation_w" << std::endl;
- tmp = morpho::dilation(ima, win3x3);
- p1 = tmp.points();
- for_all(p1)
- assert(tmp(p1) == 1);
-
- // std::cout << "elementary_opening" << std::endl;
- tmp = (morpho::elementary_opening(ima + c4)).image();
- p1 = tmp.points();
- for_all(p1)
- assert(tmp(p1) == 0);
+ my_test( morpho::dilation(ima, win3x3), 1);
- // std::cout << "elementary_closing" << std::endl;
- tmp = (morpho::elementary_closing(ima + c4)).image();
- p1 = (tmp.points());
- for_all(p1)
- assert(tmp(p1) == 1);
+ my_test( morpho::opening(ima, win3x3), 0);
- // std::cout << "opening" << std::endl;
- tmp = morpho::opening(ima, win3x3);
- p1 = (tmp.points());
- for_all(p1)
- assert(tmp(p1) == 1);
-
- // std::cout << "closing" << std::endl;
- debug::print( morpho::closing(ima, win3x3) );
- p1 = (tmp.points());
- for_all(p1)
- assert(tmp(p1) == 1);
+ my_test( morpho::closing(ima, win3x3), 1);
}
Index: olena/oln/morpho/dilation.hh
--- olena/oln/morpho/dilation.hh (revision 910)
+++ olena/oln/morpho/dilation.hh (working copy)
@@ -54,21 +54,24 @@
template <typename I, typename W>
oln_plain(I)
- dilation_(const Image<I>& input, const Window<W>& win)
+ dilation_on_function_(const Image<I>&,
+ const I& input,
+ const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::max_<oln_value(I)> max;
return level::apply_local(max, input, win);
}
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
dilation_on_set_(const Image<I>&,
- const I& input)
+ const I& input,
+ const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::or_<oln_value(I)> accu_or;
- return level::apply_local(accu_or, input);
+ return level::apply_local(accu_or, input, win);
}
// FIXME: Add a fast version.
@@ -76,16 +79,18 @@
// Impl facade.
- template <typename I>
- oln_plain(I) dilation_(const Image<I>& input)
+ template <typename I, typename W>
+ oln_plain(I) dilation_(const Image<I>& input,
+ const Window<W>& win)
{
- return dilation_on_function_(exact(input), exact(input));
+ return dilation_on_function_(exact(input), exact(input), win);
}
- template <typename I>
- oln_plain(I) dilation_(const Binary_Image<I>& input)
+ template <typename I, typename W>
+ oln_plain(I) dilation_(const Binary_Image<I>& input,
+ const Window<W>& win)
{
- return dilation_on_set_(exact(input), exact(input));
+ return dilation_on_set_(exact(input), exact(input), win);
}
} // end of namespace oln::morpho::impl
Index: olena/oln/morpho/cc_tarjan.cc
--- olena/oln/morpho/cc_tarjan.cc (revision 0)
+++ olena/oln/morpho/cc_tarjan.cc (revision 0)
@@ -0,0 +1,107 @@
+// Copyright (C) 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
+// 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_MORPHO_DILATION_HH
+# define OLN_MORPHO_DILATION_HH
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ template <typename I>
+ oln_point(I) find_root(const oln_point(I)& x)
+ {
+ if (parent[x] != x)
+ {
+ parent[x] = find_root(parent[x]);
+ return parent(x);
+ }
+ return x;
+ }
+
+ template <typename I>
+ void do_union(const oln_point(I)& n,
+ const oln_point(I)& p,
+ const oln_plain_value(I, oln_point(I))& parent)
+ {
+ oln_point(I) r = find_root(n);
+ if (r != p)
+ parent(r) = p;
+ }
+
+ template <typename I>
+ oln_plain_value(I, unsigned)
+ cc_tarjan(const Binary_Image<I>& input)
+ {
+ oln_plain_value(I, unsigned) output;
+ prepare(output, with, input);
+
+ oln_plain_value(I, oln_point(I)) parent;
+ prepare(parent, with, input);
+
+ // Init
+ unsigned current_label = 0;
+ oln_plain(I) is_processed;
+ prepare(is_processed, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ is_processed(p) = false; // FIXME : built with.
+
+
+ // Fist pass
+ oln_piter(I) p(input.points());
+ for_all(p)
+ {
+ oln_niter(I) n(p, input);
+ for_all(n)
+ {
+ if ( is_processed(n) )
+ do_union(n, p, parent);
+ }
+ is_processed(p) = true;
+ }
+
+
+ // Second pass
+ oln_piter(I) p2(input.points());
+ for_all(p2)
+ {
+ if ( parent(p) == p )
+ output(p) = ++current_label;
+ else
+ output(p) = output(parent(p));
+ }
+ }
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_DILATION_HH
Index: olena/oln/morpho/erosion.hh
--- olena/oln/morpho/erosion.hh (revision 910)
+++ olena/oln/morpho/erosion.hh (working copy)
@@ -54,21 +54,24 @@
template <typename I, typename W>
oln_plain(I)
- erosion_(const Image<I>& input, const Window<W>& win)
+ erosion_on_function_(const Image<I>&,
+ const I& input,
+ const Window<W>& win)
{
border::fill(input, oln_max(oln_value(I)));
accumulator::min_<oln_value(I)> min;
return level::apply_local(min, input, win);
}
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
erosion_on_set_(const Image<I>&,
- const I& input)
+ const I& input,
+ const Window<W>& win)
{
border::fill(input, true);
accumulator::and_<oln_value(I)> accu_and;
- return level::apply_local(accu_and, input);
+ return level::apply_local(accu_and, input, win);
}
// FIXME: Add a fast version.
@@ -76,16 +79,18 @@
// Impl facade.
- template <typename I>
- oln_plain(I) erosion_(const Image<I>& input)
+ template <typename I, typename W>
+ oln_plain(I) erosion_(const Image<I>& input,
+ const Window<W>& win)
{
- return erosion_on_function_(exact(input), exact(input));
+ return erosion_on_function_(exact(input), exact(input), win);
}
- template <typename I>
- oln_plain(I) erosion_(const Binary_Image<I>& input)
+ template <typename I, typename W>
+ oln_plain(I) erosion_(const Binary_Image<I>& input,
+ const Window<W>& win)
{
- return erosion_on_set_(exact(input), exact(input));
+ return erosion_on_set_(exact(input), exact(input), win);
}
} // end of namespace oln::morpho::impl
Index: olena/oln/level/apply.hh
--- olena/oln/level/apply.hh (revision 910)
+++ olena/oln/level/apply.hh (working copy)
@@ -66,7 +66,7 @@
typedef typename F::result result;
oln_plain_value(I, result) output;
- init(output, with, input);
+ prepare(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
output(p) = f(input(p));
Index: olena/oln/core/2d/image2d.hh
--- olena/oln/core/2d/image2d.hh (revision 910)
+++ olena/oln/core/2d/image2d.hh (working copy)
@@ -213,8 +213,7 @@
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
- array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(), //FIXME
- //: *.
+ array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(),
b.pmin().col(),
b.pmax().row(),
b.pmax().col());
Index: olena/oln/core/internal/image_base.hh
--- olena/oln/core/internal/image_base.hh (revision 910)
+++ olena/oln/core/internal/image_base.hh (working copy)
@@ -434,21 +434,21 @@
// init
- template <typename P, typename I>
- bool init_(typename internal::image_base_<I>::box* this_, const internal::image_base_<I>& data);
+ template <typename I>
+ bool init_(typename I::box* this_, const internal::image_base_<I>& data);
template <typename Target, typename I>
bool init_(Any<Target>* this_, const internal::single_image_morpher_<I>& data);
- template <typename P, typename I> // for disambiguation purpose
+ template <typename I> // for disambiguation purpose
bool
- init_(typename internal::image_base_<I>::box** this_, const internal::single_image_morpher_<I>& data);
+ init_(typename I::box* this_, const internal::single_image_morpher_<I>& data);
# ifndef OLN_INCLUDE_ONLY
- template <typename P, typename I>
- bool init_(typename internal::image_base_<I>::box** this_, const internal::image_base_<I>& data)
+ template <typename I>
+ bool init_(typename I::box* this_, const internal::image_base_<I>& data)
{
*this_ = data.bbox();
return true;
@@ -460,9 +460,9 @@
return init(*this_, with, data.image());
}
- template <typename P, typename I>
+ template <typename I>
bool
- init_(typename internal::image_base_<I>::box** this_, const internal::single_image_morpher_<I>& data)
+ init_(typename I::box* this_, const internal::single_image_morpher_<I>& data)
{
*this_ = data.bbox();
return true;
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update point set hierarchy with Box.
* oln/level/apply_inplace.hh: Fix.
* oln/core/concept/point_set.hh (include): Update.
(operator<<): Add decl.
* oln/core/gen/pset_compare.hh (operator<=, op_leq_),
(operator>=, op_geq_, operator>, op_greater_): New.
* oln/core/internal/op_pset_such_as_fp2b.hh (box): New.
* oln/core/internal/box.hh (include): Update.
(pmin, pmax): Rename as...
(impl_pmin, impl_pmax): ...these.
(set_box): Remove; move code into...
(box): ...this ctor.
(box_fwd_piter_, box_bkd_piter_): Strengthen sigs;
Remove version without arg.
(b_): Add &.
* oln/core/internal/point_set_base.hh (point_set_selector_):
Simplify.
(super_trait_): Update.
(point_set_base_): Change inheritance to point_set_selector_.
* oln/core/internal/utils.hh (pair): New overload.
* oln/core/internal/op_image_restricted_to_pset.hh: Add
precondition and postconditions.
core/concept/point_set.hh | 15 +++--
core/gen/pset_compare.hh | 75 +++++++++++++++++++++++----
core/internal/box.hh | 74 ++++++--------------------
core/internal/op_image_restricted_to_pset.hh | 3 +
core/internal/op_pset_such_as_fp2b.hh | 1
core/internal/point_set_base.hh | 27 ++-------
core/internal/utils.hh | 28 +++++++++-
level/apply_inplace.hh | 4 -
8 files changed, 133 insertions(+), 94 deletions(-)
Index: oln/level/apply_inplace.hh
--- oln/level/apply_inplace.hh (revision 908)
+++ oln/level/apply_inplace.hh (working copy)
@@ -42,7 +42,7 @@
template <typename F, typename I>
void
- apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input);
template <typename R, typename A, typename I>
void
@@ -83,7 +83,7 @@
void
apply_inplace(R (*f)(A), Mutable_Image<I>& input)
{
- impl::apply_inplace_(functorize_v2v(fun), exact(input));
+ impl::apply_inplace_(functorize_v2v(f), exact(input));
}
# endif
Index: oln/core/concept/point_set.hh
--- oln/core/concept/point_set.hh (revision 908)
+++ oln/core/concept/point_set.hh (working copy)
@@ -29,8 +29,7 @@
# define OLN_CORE_CONCEPT_POINT_SET_HH
# include <iostream>
-# include <oln/core/concept/point.hh>
-# include <oln/core/concept/iterator.hh> // for "for_all"
+# include <oln/core/concept/iterator_on_points.hh>
namespace oln
@@ -85,6 +84,9 @@
template <typename Ps>
std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts);
+ template <typename B>
+ std::ostream& operator<<(std::ostream& ostr, const Box<B>& b);
+
# ifndef OLN_INCLUDE_ONLY
@@ -151,14 +153,19 @@
std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts)
{
ostr << "{ ";
- typename Ps::piter p(pts);
+ oln_piter(Ps) p(pts);
for_all(p)
ostr << p << ' '; // FIXME: Add ','?
return ostr << " }";
}
+ template <typename B>
+ std::ostream& operator<<(std::ostream& ostr, const Box<B>& b)
+ {
+ return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }";
+ }
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 908)
+++ oln/core/gen/pset_compare.hh (working copy)
@@ -42,6 +42,15 @@
template <typename L, typename R>
bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
+ template <typename L, typename R>
+ bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
+
+ template <typename L, typename R>
+ bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
+
+ template <typename L, typename R>
+ bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
+
# ifndef OLN_INCLUDE_ONLY
@@ -72,16 +81,13 @@
return true;
}
- /*
// Version for Boxes.
- FIXME: Activate.
template <typename L, typename R>
bool op_eq_(const Box<L>& lhs, const Box<R>& rhs)
{
return lhs.pmin() = rhs.pmin() and lhs.pmax() = rhs.pmax();
}
- */
// Point_Set L < Point_Set R
@@ -109,23 +115,49 @@
return true;
}
- /*
- // Version for Boxes.
- FIXME: Activate.
+
+ // Box L <= Box R.
+
template <typename L, typename R>
- bool op_less_(const Box<L>& lhs, const Box<R>& rhs)
+ bool op_leq_(const Box<L>& lhs, const Box<R>& rhs)
{
- // subset test (i.e., lhs <= rhs)
for (unsigned i = 0; i < L::n; ++i)
{
if (lhs.pmin()[i] < rhs.pmin()[i] or lhs.pmax()[i] > rhs.pmax()[i])
return false;
}
- // proper (strict) test
- return lhs != rhs;
+ return true;
+ }
+
+ // Box L < Box R.
+
+ template <typename L, typename R>
+ bool op_less_(const Box<L>& lhs, const Box<R>& rhs)
+ {
+ return op_leq_(lhs, rhs) and lhs != rhs;
+ }
+
+ // Box L >= Box R.
+
+ template <typename L, typename R>
+ bool op_geq_(const Box<L>& lhs, const Box<R>& rhs)
+ {
+ for (unsigned i = 0; i < L::n; ++i)
+ {
+ if (lhs.pmin()[i] > rhs.pmin()[i] or lhs.pmax()[i] < rhs.pmax()[i])
+ return false;
+ }
+ return true;
+ }
+
+ // Box L > Box R.
+
+ template <typename L, typename R>
+ bool op_greater_(const Box<L>& lhs, const Box<R>& rhs)
+ {
+ return op_geq_(lhs, rhs) and lhs != rhs;
}
- */
} // end of namespace oln::impl
@@ -141,12 +173,33 @@
}
template <typename L, typename R>
+ bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ assert_same_grid_<L, R>::check();
+ return impl::op_leq_(exact(lhs), exact(rhs));
+ }
+
+ template <typename L, typename R>
bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
assert_same_grid_<L, R>::check();
return impl::op_less_(exact(lhs), exact(rhs));
}
+ template <typename L, typename R>
+ bool operator >= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ assert_same_grid_<L, R>::check();
+ return impl::op_geq_(exact(lhs), exact(rhs));
+ }
+
+ template <typename L, typename R>
+ bool operator > (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ assert_same_grid_<L, R>::check();
+ return impl::op_greater_(exact(lhs), exact(rhs));
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 908)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy)
@@ -64,6 +64,7 @@
template <typename S, typename F>
struct vtypes< internal::current >
{
+ typedef oln_box(S) box;
typedef oln_point(S) point;
typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter;
typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter;
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 908)
+++ oln/core/internal/box.hh (working copy)
@@ -28,9 +28,6 @@
#ifndef OLN_CORE_INTERNAL_BOX_HH
# define OLN_CORE_INTERNAL_BOX_HH
-//# include <oln/core/concept/point.hh>
-# include <oln/core/concept/point_set.hh>
-# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/internal/point_set_base.hh>
@@ -89,10 +86,10 @@
bool impl_has(const point& p) const;
const Exact& impl_bbox() const;
- const point& pmin() const;
- point& pmin();
- const point& pmax() const;
- point& pmax();
+ const point& impl_pmin() const;
+ point& impl_pmin();
+ const point& impl_pmax() const;
+ point& impl_pmax();
protected:
box_();
@@ -105,11 +102,6 @@
}; // end of class oln::box_<P>
- template <typename Exact>
- std::ostream& operator<<(std::ostream& ostr, const box_<Exact>& b)
- {
- return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }";
- }
} // end of namespace internal
@@ -161,9 +153,7 @@
public:
stc_using(point);
- box_fwd_piter_();
- box_fwd_piter_(const B& b);
- void set_box(const B& b);
+ box_fwd_piter_(const Point_Set<B>& b);
void impl_start();
void impl_next();
@@ -173,8 +163,8 @@
const point* impl_point_adr() const;
private:
- B b_;
- point p_, nop_;
+ const B& b_;
+ point nop_, p_;
};
@@ -189,9 +179,7 @@
public:
stc_using(point);
- box_bkd_piter_();
- box_bkd_piter_(const B& b);
- void set_box(const B& b);
+ box_bkd_piter_(const Point_Set<B>& b);
void impl_start();
void impl_next();
@@ -201,8 +189,8 @@
const point* impl_point_adr() const;
private:
- B b_;
- point p_, nop_;
+ const B& b_;
+ point nop_, p_;
};
@@ -275,7 +263,7 @@
template <typename Exact>
const typename box_<Exact>::point&
- box_<Exact>::pmin() const
+ box_<Exact>::impl_pmin() const
{
for (unsigned i = 0; i < n; ++i)
invariant(this->pmin_[i] <= this->pmax_[i]);
@@ -284,7 +272,7 @@
template <typename Exact>
const typename box_<Exact>::point&
- box_<Exact>::pmax() const
+ box_<Exact>::impl_pmax() const
{
for (unsigned i = 0; i < n; ++i)
invariant(this->pmax_[i] >= this->pmin_[i]);
@@ -293,14 +281,14 @@
template <typename Exact>
typename box_<Exact>::point&
- box_<Exact>::pmin()
+ box_<Exact>::impl_pmin()
{
return this->pmin_;
}
template <typename Exact>
typename box_<Exact>::point&
- box_<Exact>::pmax()
+ box_<Exact>::impl_pmax()
{
return this->pmax_;
}
@@ -308,23 +296,10 @@
// -------------------- box_fwd_piter_<B>
-
- template <typename B>
- box_fwd_piter_<B>::box_fwd_piter_()
- {
- }
-
template <typename B>
- box_fwd_piter_<B>::box_fwd_piter_(const B& b)
+ box_fwd_piter_<B>::box_fwd_piter_(const Point_Set<B>& b)
+ : b_(exact(b))
{
- this->set_box(b);
- }
-
- template <typename B>
- void
- box_fwd_piter_<B>::set_box(const B& b)
- {
- b_ = b;
nop_ = b_.pmax();
++nop_[0];
p_ = nop_;
@@ -385,23 +360,10 @@
// -------------------- box_bkd_piter_<P>
-
- template <typename B>
- box_bkd_piter_<B>::box_bkd_piter_()
- {
- }
-
template <typename B>
- box_bkd_piter_<B>::box_bkd_piter_(const B& b)
- {
- this->set_box(b);
- }
-
- template <typename B>
- void
- box_bkd_piter_<B>::set_box(const B& b)
+ box_bkd_piter_<B>::box_bkd_piter_(const Point_Set<B>& b)
+ : b_(exact(b))
{
- b_ = b;
nop_ = b_.pmin();
--nop_[0];
p_ = nop_;
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 908)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -38,15 +38,12 @@
namespace internal
{
- template <bool Is_box, typename Exact>
- struct point_set_selector_;
-
- template <typename Exact>
- struct point_set_selector_< true, Exact > : public Box<Exact>
+ template <typename Box_ptr, typename Exact>
+ struct point_set_selector_ : public Point_Set<Exact>
{};
template <typename Exact>
- struct point_set_selector_< false, Exact > : public Point_Set<Exact>
+ struct point_set_selector_< Exact*, Exact > : public Box<Exact>
{};
} // end of namespace oln::internal
@@ -56,28 +53,20 @@
// point_set_base_ class
- /// Fwd decls.
+ // Fwd decls.
namespace internal { template <typename Exact> struct point_set_base_; }
template <typename P> class gen_box;
- /// Super type.
+ // Super type.
template <typename Exact>
struct super_trait_< internal::point_set_base_<Exact> >
{
- typedef Point_Set<Exact> ret;
-
- /*
- FIXME: Activate to replace the above code.
-
- typedef stc_deferred(box) box__;
- typedef mlc::eq_<box__, Exact> test__;
- typedef internal::point_set_selector_<mlc_bool(test__), Exact> ret;
- */
+ typedef internal::point_set_selector_< stc_deferred(box)*, Exact > ret;
};
- /// Virtual types.
+ // Virtual types.
template <typename Exact>
struct vtypes< internal::point_set_base_<Exact> >
{
@@ -101,7 +90,7 @@
/// Base class for point sets.
template <typename Exact>
- struct point_set_base_ : public Point_Set<Exact> // FIXME: Change inheritance.
+ struct point_set_base_ : public super_trait_< point_set_base_<Exact> >::ret
{
protected:
point_set_base_();
Index: oln/core/internal/utils.hh
--- oln/core/internal/utils.hh (revision 908)
+++ oln/core/internal/utils.hh (working copy)
@@ -96,10 +96,34 @@
};
template <typename T1, typename T2>
- struct pair< T1, T2* >;
+ struct pair< T1*, T2* >
+ {
+ typedef pair<T1*,T2*> self_t;
+
+ // Not impled.
+ pair();
+ pair(const self_t&);
+ void operator=(const self_t&);
+ // end of Not impled.
+
+ pair(T1* p_first, T2* p_second)
+ : first(*p_first),
+ second(*p_second)
+ {
+ precondition(p_first != 0);
+ precondition(p_second != 0);
+ }
+ T1& first;
+ T2& second;
+ ~pair()
+ {
+ delete &first;
+ delete &second;
+ }
+ };
template <typename T1, typename T2>
- struct pair< T1*, T2* >;
+ struct pair< T1, T2* >;
/// Simple triplet class.
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 908)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -129,6 +129,7 @@
template <typename I, typename S>
current::special_op_(I& ima, S& subset)
{
+ precondition(subset <= ima.points());
this->data_ = new data(ima, subset);
}
@@ -187,6 +188,7 @@
bool subset_ok = init(this_->data__()->second, with, dat);
postcondition(image_ok);
postcondition(subset_ok);
+ postcondition(this_->points() <= this_->image().points());
return image_ok and subset_ok;
}
@@ -202,6 +204,7 @@
bool subset_ok = init(target.data__()->second, with, dat);
postcondition(image_ok);
postcondition(subset_ok);
+ postcondition(target.points() <= target.image().points());
return image_ok and subset_ok;
}
1
0