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
24 Mar '07
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Adapt gen_box and point1d class to the new box hierarchy.
* tests/core/image1d.cc, oln/core/rle/rle_pset.hh,
* core/internal/point_set_base.hh: change vtypes.
* oln/core/1d/box1d.hh: box1d is know a real class.
* oln/core/2d/box2d.hh: add a constructor.
* oln/core/gen/box.hh: adapt gen_box.
* oln/core/internal/box.hh: fix a bug.
oln/core/1d/box1d.hh | 60 ++++++
oln/core/2d/box2d.hh | 12 -
oln/core/gen/box.hh | 344 +-----------------------------------
oln/core/internal/box.hh | 53 ++---
oln/core/internal/point_set_base.hh | 3
oln/core/rle/rle_pset.hh | 1
tests/core/image1d.cc | 1
7 files changed, 108 insertions(+), 366 deletions(-)
Index: tests/core/image1d.cc
--- tests/core/image1d.cc (revision 907)
+++ tests/core/image1d.cc (working copy)
@@ -38,6 +38,7 @@
// Fill a 1D image using its iterator.
image1d<char> ima1(3);
+ image1d<char>::box box1 = ima1.points();
image1d<char>::piter p1(ima1.points());
for_all(p1)
ima1(p1) = 1;
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 907)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -61,6 +61,7 @@
{
typedef P point;
+ typedef gen_box<P> box;
typedef rle_pset_fwd_piter_<P> fwd_piter;
typedef rle_pset_bkd_piter_<P> bkd_piter;
};
Index: oln/core/1d/box1d.hh
--- oln/core/1d/box1d.hh (revision 907)
+++ oln/core/1d/box1d.hh (working copy)
@@ -35,8 +35,64 @@
namespace oln
{
- // FIXME: box1d should be an actual type, not an alias...
- typedef gen_box<point1d> box1d;
+ // Forward declarations
+ struct box1d;
+
+ // Super type
+ template <>
+ struct super_trait_< box1d >
+ {
+ typedef box1d current;
+ typedef internal::box_<box1d> ret;
+ };
+
+ // Virtual types
+ template <>
+ struct vtypes<box1d>
+ {
+ typedef point1d point;
+ typedef box1d box;
+ };
+
+ // 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
+ typedef super::point point;
+
+ box1d();
+ box1d(const box1d::from_to_t& dat);
+ box1d(const point1d& pmin, const point1d& pmax);
+ template <typename D>
+ box1d(const internal::initializer_<D>& data);
+ };
+
+# ifndef OLN_INCLUDE_ONLY
+
+ box1d::box1d()
+ {
+ }
+
+ box1d::box1d(const box1d::from_to_t& dat) :
+ super(dat)
+ {
+ }
+
+ box1d::box1d(const point1d& pmin, const point1d& pmax) :
+ super(pmin, pmax)
+ {
+ }
+
+ template <typename D>
+ box1d::box1d(const internal::initializer_<D>& data) :
+ super(data)
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/box2d.hh
--- oln/core/2d/box2d.hh (revision 907)
+++ oln/core/2d/box2d.hh (working copy)
@@ -36,10 +36,6 @@
namespace oln
{
- // Fwd decl.
- template <typename P> class box_;
-
-
// Forward declarations
struct box2d;
@@ -71,6 +67,8 @@
box2d();
box2d(const box2d::from_to_t& dat);
box2d(const point2d& pmin, const point2d& pmax);
+ template <typename D>
+ box2d(const internal::initializer_<D>& data);
};
namespace internal
@@ -103,6 +101,12 @@
{
}
+ template <typename D>
+ box2d::box2d(const internal::initializer_<D>& data) :
+ super(data)
+ {
+ }
+
namespace internal
{
Index: oln/core/gen/box.hh
--- oln/core/gen/box.hh (revision 907)
+++ oln/core/gen/box.hh (working copy)
@@ -31,7 +31,7 @@
# include <oln/core/concept/point.hh>
# include <oln/core/concept/iterator_on_points.hh>
-# include <oln/core/internal/point_set_base.hh>
+# include <oln/core/internal/box.hh>
namespace oln
@@ -40,8 +40,6 @@
// Forward declarations.
template <typename P> class gen_box;
- template <typename P> class gen_box_fwd_piter_;
- template <typename P> class gen_box_bkd_piter_;
// Super type declaration.
@@ -49,7 +47,7 @@
struct super_trait_< gen_box<P> >
{
typedef gen_box<P> current__;
- typedef internal::point_set_base_<current__> ret;
+ typedef internal::box_<current__> ret;
};
@@ -58,150 +56,35 @@
struct vtypes< gen_box<P> >
{
typedef P point;
- typedef gen_box_fwd_piter_<P> fwd_piter;
- typedef gen_box_bkd_piter_<P> bkd_piter;
+ typedef gen_box<P> box;
};
/// Generic box class based on a point class.
template <typename P>
- class gen_box : public internal::point_set_base_< gen_box<P> >,
+ class gen_box : public internal::box_< gen_box<P> >,
private mlc::assert_< mlc_is_a(P, Point) >
{
typedef gen_box<P> current;
- typedef internal::point_set_base_<current> super;
-
- typedef internal::initializer_<
- internal::pair< internal::from_t<P>, internal::to_t<P> >
- > from_to_t;
-
+ typedef internal::box_<current> super;
public:
-
stc_using(point);
stc_using(box);
- private:
- typedef stc_type(point, dim) dim__;
- enum { n = mlc_value(dim__) };
public:
gen_box();
gen_box(const P& pmin, const P& pmax);
- gen_box(const from_to_t& data);
+ gen_box(const typename gen_box<P>::from_to_t& data);
template <typename D>
gen_box(const internal::initializer_<D>& data);
- unsigned impl_npoints() const;
- bool impl_has(const P& p) const;
- const gen_box<P>& impl_bbox() const;
-
- const P& pmin() const;
- P& pmin();
- const P& pmax() const;
- P& pmax();
-
- protected:
- point pmin_, pmax_;
-
}; // end of class oln::gen_box<P>
- template <typename P>
- std::ostream& operator<<(std::ostream& ostr, const gen_box<P>& b)
- {
- return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }";
- }
-
-
- // -------------------- iterators on gen_box<P>
-
-
-
-
- /// Super types.
-
- template <typename P>
- struct super_trait_< gen_box_fwd_piter_<P> >
- {
- typedef gen_box_fwd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
-
- template <typename P>
- struct super_trait_< gen_box_bkd_piter_<P> >
- {
- typedef gen_box_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
-
-
- /// Virtual types.
-
- template <typename P>
- struct vtypes< gen_box_fwd_piter_<P> >
- {
- typedef P point;
- };
-
- template <typename P>
- struct vtypes< gen_box_bkd_piter_<P> >
- {
- typedef P point;
- };
-
-
- /// Class gen_box_fwd_piter_<P>.
-
- template <typename P>
- class gen_box_fwd_piter_ : public Iterator_on_Points< gen_box_fwd_piter_<P> >,
- private mlc::assert_< mlc_is_a(P, Point) >
- {
- public:
- gen_box_fwd_piter_();
- gen_box_fwd_piter_(const Point_Set< gen_box<P> >& b);
- void set_box(const gen_box<P>& b);
-
- void impl_start();
- void impl_next();
- void impl_invalidate();
- bool impl_is_valid() const;
- P impl_to_point() const;
- const P* impl_point_adr() const;
-
- private:
- gen_box<P> b_;
- P p_, nop_;
- };
-
-
- /// Class gen_box_bkd_piter_<P>.
-
- template <typename P>
- class gen_box_bkd_piter_ : public Iterator_on_Points< gen_box_bkd_piter_<P> >,
- private mlc::assert_< mlc_is_a(P, Point) >
- {
- public:
- gen_box_bkd_piter_();
- gen_box_bkd_piter_(const Point_Set< gen_box<P> >& b);
- void set_box(const gen_box<P>& b);
-
- void impl_start();
- void impl_next();
- void impl_invalidate();
- bool impl_is_valid() const;
- P impl_to_point() const;
- const P* impl_point_adr() const;
-
- private:
- gen_box<P> b_;
- P p_, nop_;
- };
-
-
-
# ifndef OLN_INCLUDE_ONLY
@@ -215,225 +98,22 @@
}
template <typename P>
- gen_box<P>::gen_box(const P& pmin, const P& pmax)
+ gen_box<P>::gen_box(const P& pmin, const P& pmax) :
+ super(pmin, pmax)
{
- for (unsigned i = 0; i < n; ++i)
- precondition(pmax[i] >= pmin[i]);
- this->pmin_ = pmin;
- this->pmax_ = pmax;
}
template <typename P>
- gen_box<P>::gen_box(const typename gen_box<P>::from_to_t& dat)
+ gen_box<P>::gen_box(const typename gen_box<P>::from_to_t& data) :
+ super(data)
{
- this->pmin_ = dat->first.value;
- this->pmax_ = dat->second.value;
}
template <typename P>
template <typename D>
- gen_box<P>::gen_box(const internal::initializer_<D>& data)
- {
- bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value());
- postcondition(box_ok);
- }
-
- template <typename P>
- unsigned
- gen_box<P>::impl_npoints() const
- {
- unsigned count = 1;
- for (unsigned i = 0; i < n; ++i)
- count *= (this->pmax_[i] - this->pmin_[i] + 1);
- return count;
- }
-
- template <typename P>
- bool
- gen_box<P>::impl_has(const P& p) const
- {
- for (unsigned i = 0; i < n; ++i)
- if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i])
- return false;
- return true;
- }
-
- template <typename P>
- const gen_box<P>&
- gen_box<P>::impl_bbox() const
- {
- return *this;
- }
-
- template <typename P>
- const P&
- gen_box<P>::pmin() const
- {
- for (unsigned i = 0; i < n; ++i)
- invariant(this->pmin_[i] <= this->pmax_[i]);
- return this->pmin_;
- }
-
- template <typename P>
- const P&
- gen_box<P>::pmax() const
- {
- for (unsigned i = 0; i < n; ++i)
- invariant(this->pmax_[i] >= this->pmin_[i]);
- return this->pmax_;
- }
-
- template <typename P>
- P&
- gen_box<P>::pmin()
- {
- return this->pmin_;
- }
-
- template <typename P>
- P&
- gen_box<P>::pmax()
- {
- return this->pmax_;
- }
-
-
- // -------------------- gen_box_fwd_piter_<P>
-
-
- template <typename P>
- gen_box_fwd_piter_<P>::gen_box_fwd_piter_()
- {
- }
-
- template <typename P>
- gen_box_fwd_piter_<P>::gen_box_fwd_piter_(const Point_Set< gen_box<P> >& b)
- {
- this->set_box(exact(b));
- }
-
- template <typename P>
- void gen_box_fwd_piter_<P>::set_box(const gen_box<P>& b)
- {
- b_ = b;
- nop_ = b_.pmax();
- ++nop_[0];
- p_ = nop_;
- }
-
- template <typename P>
- void gen_box_fwd_piter_<P>::impl_start()
- {
- p_ = b_.pmin();
- }
-
- template <typename P>
- void gen_box_fwd_piter_<P>::impl_next()
- {
- for (int i = P::n - 1; i >= 0; --i)
- if (p_[i] == b_.pmax()[i])
- p_[i] = b_.pmin()[i];
- else
- {
- ++p_[i];
- break;
- }
- if (p_ == b_.pmin())
- p_ = nop_;
- }
-
- template <typename P>
- void gen_box_fwd_piter_<P>::impl_invalidate()
- {
- p_ = nop_;
- }
-
- template <typename P>
- bool gen_box_fwd_piter_<P>::impl_is_valid() const
- {
- return p_ != nop_;
- }
-
- template <typename P>
- P gen_box_fwd_piter_<P>::impl_to_point() const
- {
- return p_;
- }
-
- template <typename P>
- const P* gen_box_fwd_piter_<P>::impl_point_adr() const
- {
- return &p_;
- }
-
-
-
- // -------------------- gen_box_bkd_piter_<P>
-
-
- template <typename P>
- gen_box_bkd_piter_<P>::gen_box_bkd_piter_()
- {
- }
-
- template <typename P>
- gen_box_bkd_piter_<P>::gen_box_bkd_piter_(const Point_Set< gen_box<P> >& b)
- {
- this->set_box(exact(b));
- }
-
- template <typename P>
- void gen_box_bkd_piter_<P>::set_box(const gen_box<P>& b)
- {
- b_ = b;
- nop_ = b_.pmin();
- --nop_[0];
- p_ = nop_;
- }
-
- template <typename P>
- void gen_box_bkd_piter_<P>::impl_start()
- {
- p_ = b_.pmax();
- }
-
- template <typename P>
- void gen_box_bkd_piter_<P>::impl_next()
- {
- for (int i = P::n - 1; i >= 0; --i)
- if (p_[i] == b_.pmin()[i])
- p_[i] = b_.pmax()[i];
- else
- {
- --p_[i];
- break;
- }
- if (p_ == b_.pmax())
- p_ = nop_;
- }
-
- template <typename P>
- void gen_box_bkd_piter_<P>::impl_invalidate()
- {
- p_ = nop_;
- }
-
- template <typename P>
- bool gen_box_bkd_piter_<P>::impl_is_valid() const
- {
- return p_ != nop_;
- }
-
- template <typename P>
- P gen_box_bkd_piter_<P>::impl_to_point() const
- {
- return p_;
- }
-
- template <typename P>
- const P* gen_box_bkd_piter_<P>::impl_point_adr() const
+ gen_box<P>::gen_box(const internal::initializer_<D>& data) :
+ super(data)
{
- return &p_;
}
# endif // !OLN_INCLUDE_ONLY
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 907)
+++ oln/core/internal/box.hh (working copy)
@@ -39,18 +39,14 @@
// Forward declarations.
- namespace internal
- {
- template <typename Exact> class box_;
+ namespace internal { template <typename Exact> class box_; }
template <typename Exact> class box_fwd_piter_;
template <typename Exact> class box_bkd_piter_;
- }
// Super type declaration.
template <typename Exact>
struct super_trait_< internal::box_<Exact> >
{
- // typedef box_<Exact> current__;
typedef internal::point_set_base_<Exact> ret;
};
@@ -59,9 +55,8 @@
template <typename Exact>
struct vtypes< internal::box_<Exact> >
{
- //typedef point2d point;
- typedef stc::final< internal::box_fwd_piter_<Exact> > fwd_piter;
- typedef stc::final< internal::box_bkd_piter_<Exact> > bkd_piter;
+ typedef stc::final< box_fwd_piter_<Exact> > fwd_piter;
+ typedef stc::final< box_bkd_piter_<Exact> > bkd_piter;
};
@@ -103,6 +98,8 @@
box_();
box_(const point& pmin, const point& pmax);
box_(const from_to_t& data);
+ template <typename D>
+ box_(const internal::initializer_<D>& data);
point pmin_, pmax_;
@@ -121,20 +118,19 @@
-
/// Super types.
template <typename B>
- struct super_trait_< internal::box_fwd_piter_<B> >
+ struct super_trait_< box_fwd_piter_<B> >
{
- typedef internal::box_fwd_piter_<B> current__;
+ typedef box_fwd_piter_<B> current__;
typedef Iterator_on_Points<current__> ret;
};
template <typename B>
- struct super_trait_<internal:: box_bkd_piter_<B> >
+ struct super_trait_<box_bkd_piter_<B> >
{
- typedef internal::box_bkd_piter_<B> current__;
+ typedef box_bkd_piter_<B> current__;
typedef Iterator_on_Points<current__> ret;
};
@@ -142,20 +138,18 @@
/// Virtual types.
template <typename B>
- struct vtypes< internal::box_fwd_piter_<B> >
+ struct vtypes< box_fwd_piter_<B> >
{
typedef typename B::point point;
};
template <typename B>
- struct vtypes< internal::box_bkd_piter_<B> >
+ struct vtypes< box_bkd_piter_<B> >
{
typedef typename B::point point;
};
- namespace internal
- {
/// Class box_fwd_piter_<P>.
template <typename B>
@@ -168,7 +162,7 @@
stc_using(point);
box_fwd_piter_();
- box_fwd_piter_(const Point_Set< B >& b);
+ box_fwd_piter_(const B& b);
void set_box(const B& b);
void impl_start();
@@ -196,7 +190,7 @@
stc_using(point);
box_bkd_piter_();
- box_bkd_piter_(const Point_Set< B >& b);
+ box_bkd_piter_(const B& b);
void set_box(const B& b);
void impl_start();
@@ -216,6 +210,8 @@
# ifndef OLN_INCLUDE_ONLY
+ namespace internal
+ {
// -------------------- box_<Exact>
@@ -242,6 +238,13 @@
this->pmax_ = dat->second.value;
}
+ template <typename Exact>
+ template <typename D>
+ box_<Exact>::box_(const internal::initializer_<D>& data)
+ {
+ bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value());
+ postcondition(box_ok);
+ }
template <typename Exact>
unsigned
@@ -301,7 +304,7 @@
{
return this->pmax_;
}
-
+ }
// -------------------- box_fwd_piter_<B>
@@ -312,9 +315,9 @@
}
template <typename B>
- box_fwd_piter_<B>::box_fwd_piter_(const Point_Set< B >& b)
+ box_fwd_piter_<B>::box_fwd_piter_(const B& b)
{
- this->set_box(exact(b));
+ this->set_box(b);
}
template <typename B>
@@ -389,9 +392,9 @@
}
template <typename B>
- box_bkd_piter_<B>::box_bkd_piter_(const Point_Set< B >& b)
+ box_bkd_piter_<B>::box_bkd_piter_(const B& b)
{
- this->set_box(exact(b));
+ this->set_box(b);
}
template <typename B>
@@ -456,8 +459,6 @@
}
# endif // OLN_INCLUDE_ONLY
- } // end of namespace internal
-
} // end of namespace oln
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 907)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -84,13 +84,12 @@
typedef stc::abstract point;
typedef stc::abstract fwd_piter;
typedef stc::abstract bkd_piter;
+ typedef stc::abstract box;
typedef stc_deferred(point) point__;
typedef stc_deferred(fwd_piter) fwd_piter__;
typedef stc::final< stc::is<Point_Set> > category;
- //FIXME:
- typedef gen_box<point__> box;
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_piter__ > piter;
};
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add image level comparisons and better point set ones.
* oln/level/compare.hh: New.
* TODO: New "Rough list" and "Tiny improvements" sections.
* oln/core/concept/grid.hh
(both_types_should_have_the_same_grid_),
(assert_same_grid_): New.
* oln/core/concept/operators.hh: Separate defs from decls.
Fix dispatch using 'exact'.
* oln/core/gen/pset_compare.hh (guards): Remove.
(operator<=, impl_leq_): Replace by...
(operator<, impl_less_): ...these.
TODO | 50 ++++++++++++++
oln/core/concept/grid.hh | 21 ++++++
oln/core/concept/operators.hh | 141 +++++++++++++++++++-----------------------
oln/core/gen/pset_compare.hh | 54 +++++++---------
oln/level/compare.hh | 109 ++++++++++++++++++++++++++++++++
5 files changed, 271 insertions(+), 104 deletions(-)
Index: TODO
--- TODO (revision 906)
+++ TODO (working copy)
@@ -1,3 +1,53 @@
+
+
+* Rough list
+
+value types (including gray level types, label types, (bool, T) type,
+color types, etc.)
+
+op traits (for C types, oln value types, and also oln types such as
+points, etc.)
+
+image thru a function f (where f is pure, a bijection, a two-way
+function, an accessor, a projection, etc.)
+
+basics important routines: fill, assign, clone, unmorph (undress?),
+convert, ...
+
+torus and mask types, and the proper niter type deductions (with or
+without virtual border)
+
+virtual border adaptation and initialization policies
+
+safe type when image is mutable; question: can we have Mutable_Image&
+as argument when an image, a morpher, is created on the fly?
+
+io pnm
+
+draw routines
+
+window types such as lines, rectangles, and so on
+
+meta-window type; for instance, ball, segment, etc.
+
+const promotions for op_<L,O,R> types
+
+
+* Tiny improvements
+
+Replace point type comparison assertions by an explicit version
+(just like assert_same_grid_)
+
+
+
+* Some ideas
+
+Consider the morphological gradient "d(f) - e(f)", it is a combination
+of local functions; can we make it explicit? Advantage: no temp image
+created.
+
+
+
* Renaming
** point_accessibility
Index: oln/level/compare.hh
--- oln/level/compare.hh (revision 0)
+++ oln/level/compare.hh (revision 0)
@@ -0,0 +1,109 @@
+// 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_COMPARE_HH
+# define OLN_LEVEL_COMPARE_HH
+
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/pset_compare.hh>
+
+
+namespace oln
+{
+
+ // Fwd decls.
+
+ template <typename L, typename R>
+ bool operator = (const Image<L>& lhs, const Image<R>& rhs);
+
+ template <typename L, typename R>
+ bool operator < (const Image<L>& lhs, const Image<R>& rhs);
+
+
+# ifndef OLN_LNCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Image L = Image R
+ // ----------------------
+
+ // Generic version.
+
+ template <typename L, typename R>
+ bool op_eq_(const Image<L>& lhs, const Image<R>& rhs);
+ {
+ precondition(lhs.points() = rhs.points());
+ oln_piter(L) p(lhs.points());
+ for_all(p)
+ if (lhs(p) != rhs(p))
+ return false;
+ return true;
+ }
+
+
+ // Image L < Image R
+ // ---------------------
+
+ // Generic version.
+
+ template <typename L, typename R>
+ bool op_less_(const Image<L>& lhs, const Image<R>& rhs);
+ {
+ precondition(lhs.points() = rhs.points());
+ oln_piter(L) p(lhs.points());
+ for_all(p)
+ if (lhs(p) >= rhs(p))
+ return false;
+ return true;
+ }
+
+ } // end of namespace oln::level::impl
+
+
+ // Facades.
+
+ template <typename L, typename R>
+ bool operator = (const Image<L>& lhs, const Image<R>& rhs)
+ {
+ assert_same_grid_<L, R>::check();
+ return impl::op_eq_(exact(lhs), exact(rhs));
+ }
+
+ template <typename L, typename R>
+ bool operator < (const Image<L>& lhs, const Image<R>& rhs)
+ {
+ assert_same_grid_<L, R>::check();
+ return impl::op_less_(exact(lhs), exact(rhs));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_LEVEL_COMPARE_HH
Index: oln/core/concept/grid.hh
--- oln/core/concept/grid.hh (revision 906)
+++ oln/core/concept/grid.hh (working copy)
@@ -52,6 +52,27 @@
};
+ namespace ERROR
+ {
+
+ template < typename Type_1,
+ typename Type_2,
+ typename Grid_1 = oln_grid(Type_1),
+ typename Grid_2 = oln_grid(Type_2) >
+ struct both_types_should_have_the_same_grid_
+ {
+ };
+
+ } // end of namespace oln::ERROR
+
+
+ template <typename T1, typename T2>
+ struct assert_same_grid_
+ : public mlc::assert_< mlc::eq_<oln_grid(T1), oln_grid(T2)>,
+ ERROR::both_types_should_have_the_same_grid_<T1, T2> >
+ {};
+
+
} // end of namespace oln
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 906)
+++ oln/core/concept/operators.hh (working copy)
@@ -34,8 +34,50 @@
namespace oln
{
- /// \{
/// Operator = (default version).
+ template <typename L, typename R>
+ bool operator=(const Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator != (default version).
+ template <typename L, typename R>
+ bool operator!=(const Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator < (default version).
+ template <typename L, typename R>
+ bool operator< (const Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator > (default version).
+ template <typename L, typename R>
+ bool operator> (const Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator >= (default version).
+ template <typename L, typename R>
+ bool operator>=(const Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator <= (default version).
+ template <typename L, typename R>
+ bool operator<=(const Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator += (default version).
+ template <typename L, typename R>
+ L& operator+=(Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator + (default version).
+ template <typename T>
+ T operator+ (const Any<T>& lhs, const Any<T>& rhs);
+
+ /// Operator -= (default version).
+ template <typename L, typename R>
+ L& operator-=(Any<L>& lhs, const Any<R>& rhs);
+
+ /// Operator - (default version).
+ template <typename T>
+ T operator- (const Any<T>& rhs);
+
+
+
+
+# ifndef OLN_INCLUDE_ONLY
template <typename L, typename R>
bool operator=(const Any<L>& lhs, const Any<R>& rhs)
@@ -43,138 +85,87 @@
return exact(lhs).op_equal_(exact(rhs));
}
- /// \}
-
-
- /// \{
- /// Operator != (default version).
-
template <typename L, typename R>
bool operator!=(const Any<L>& lhs, const Any<R>& rhs)
{
- return not (lhs = rhs);
+ return not (exact(lhs) = exact(rhs));
}
- /// \}
-
-
- /// \{
- /// Operator < (default version).
-
template <typename L, typename R>
bool operator< (const Any<L>& lhs, const Any<R>& rhs)
{
return exact(lhs).op_less_(exact(rhs));
}
- /// \}
-
-
- /// \{
- /// Operator > (default version).
-
template <typename L, typename R>
bool operator> (const Any<L>& lhs, const Any<R>& rhs)
{
- return rhs < lhs;
+ return exact(rhs) < exact(lhs);
}
- /// \}
-
-
- /// \{
- /// Operator >= (default version).
-
template <typename L, typename R>
bool operator>=(const Any<L>& lhs, const Any<R>& rhs)
{
- return not (lhs < rhs);
+ return not (exact(lhs) < exact(rhs));
}
- /// \}
-
-
- /// \{
- /// Operator <= (default version).
-
template <typename L, typename R>
bool operator<=(const Any<L>& lhs, const Any<R>& rhs)
{
- return not (rhs < lhs);
+ return not (exact(rhs) < exact(lhs));
}
- /// \}
-
-
- /// \{
- /// Operator += (default version).
-
template <typename L, typename R>
L& operator+=(Any<L>& lhs, const Any<R>& rhs)
{
return exact(lhs).op_plus_equal_(exact(rhs));
}
- /// \}
-
-
- /// \{
- /// Operators + (default versions).
-
template <typename T>
T operator+ (const Any<T>& lhs, const Any<T>& rhs)
{
T tmp = exact(lhs);
- return tmp += rhs;
+ return tmp += exact(rhs);
}
-// template <typename L, typename R>
-// xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs)
-// {
-// return exact(lhs).op_plus_(exact(rhs));
-// }
-
- /// \}
-
-
- /// \{
- /// Operator -= (default version).
-
template <typename L, typename R>
L& operator-=(Any<L>& lhs, const Any<R>& rhs)
{
return exact(lhs).op_minus_equal_(exact(rhs));
}
- /// \}
-
-
- /// \{
- /// Operators - (default versions).
-
template <typename T>
T operator- (const Any<T>& rhs)
{
return exact(rhs).op_unary_minus_();
}
-/* template <typename T>
+ /*
+
+ FIXME: Activate?
+
+ template <typename L, typename R>
+ xtd_op_plus_trait(L, R) operator+ (const Any<L>& lhs, const Any<R>& rhs)
+ {
+ return exact(lhs).op_plus_(exact(rhs));
+ }
+
+ template <typename T>
T operator- (const Any<T>& lhs, const Any<T>& rhs)
{
T tmp = exact(lhs);
return tmp -= rhs;
}
-*/
-
-// template <typename L, typename R>
-// xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs)
-// {
-// return exact(lhs).op_minus_(exact(rhs));
-// }
- /// \}
+ template <typename L, typename R>
+ xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs)
+ {
+ return exact(lhs).op_minus_(exact(rhs));
+ }
+ */
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 906)
+++ oln/core/gen/pset_compare.hh (working copy)
@@ -40,15 +40,7 @@
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);
-
-
- // FIXME: Guards; without impl!
- template <typename L, typename R> bool operator < (const Point_Set<L>&, const Point_Set<R>&);
- template <typename L, typename R> bool operator > (const Point_Set<L>&, const Point_Set<R>&);
- template <typename L, typename R> bool operator >= (const Point_Set<L>&, const Point_Set<R>&);
- // end of FIXME
-
+ bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs);
# ifndef OLN_INCLUDE_ONLY
@@ -92,26 +84,26 @@
*/
- // Point_Set L <= Point_Set R
- // ------------------------------
+ // 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_less_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
- // quick test:
- if (lhs.npoints() > rhs.npoints())
+ if (lhs.npoints() >= rhs.npoints()) // quick test
return false;
- // final test:
- oln_piter(R) pr(rhs);
- pr.start();
- oln_piter(L) pl(lhs);
- for_all(pl)
- {
- while (pr.is_valid() and pr.to_point() != pl.to_point())
- pr.next();
- if (not pr.is_valid())
+ // we have lhs.npoints() < rhs.npoints()
+ // so we shall now test that all points of lhs are IN rhs
+ oln_piter(R) p_rhs(rhs);
+ p_rhs.start();
+ oln_piter(L) p_lhs(lhs);
+ for_all(p_lhs)
+ {
+ while (p_rhs.is_valid() and p_rhs.to_point() != p_lhs.to_point())
+ p_rhs.next();
+ if (not p_rhs.is_valid())
return false;
}
return true;
@@ -122,12 +114,16 @@
FIXME: Activate.
template <typename L, typename R>
- bool op_leq_(const Box<L>& lhs, const Box<R>& rhs)
+ bool op_less_(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;
- return true;
+ }
+ // proper (strict) test
+ return lhs != rhs;
}
*/
@@ -140,15 +136,15 @@
template <typename L, typename R>
bool operator = (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
- mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg.
+ assert_same_grid_<L, R>::check();
return impl::op_eq_(exact(lhs), exact(rhs));
}
template <typename L, typename R>
- bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ bool operator < (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
{
- mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg.
- return impl::op_leq_(exact(lhs), exact(rhs));
+ assert_same_grid_<L, R>::check();
+ return impl::op_less_(exact(lhs), exact(rhs));
}
# endif // ! OLN_INCLUDE_ONLY
1
0
I've got an error since last 2 patchs :
error: no matching function for call to 'init_(oln::box2d*, const oln::image2d<int>&)'
We look at it with nico but didn't manage to fix.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Morpho : Elementary versions.
* oln/morpho/elementary_gradient.hh: New.
* oln/morpho/elementary_gradient_external.hh: New.
* oln/morpho/elementary_laplace.hh: New.
* oln/morpho/gradient_internal.hh: .
* oln/morpho/gradient.hh: .
* oln/morpho/gradient_external.hh: .
* oln/morpho/laplace.hh: .
* oln/morpho/erosion.hh: .
* oln/morpho/elementary_gradient_internal.hh: New.
* oln/core/2d/image2d.hh: .
core/2d/image2d.hh | 3 -
morpho/elementary_gradient.hh | 84 +++++++++++++++++++++++++++++++++
morpho/elementary_gradient_external.hh | 83 ++++++++++++++++++++++++++++++++
morpho/elementary_gradient_internal.hh | 83 ++++++++++++++++++++++++++++++++
morpho/elementary_laplace.hh | 84 +++++++++++++++++++++++++++++++++
morpho/erosion.hh | 6 +-
morpho/gradient.hh | 25 +++++----
morpho/gradient_external.hh | 29 +++++------
morpho/gradient_internal.hh | 28 +++++------
morpho/laplace.hh | 23 +++++----
10 files changed, 395 insertions(+), 53 deletions(-)
Index: oln/morpho/elementary_gradient.hh
--- oln/morpho/elementary_gradient.hh (revision 0)
+++ oln/morpho/elementary_gradient.hh (revision 0)
@@ -0,0 +1,84 @@
+// 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_ELEMENTARY_GRADIENT_HH
+# define OLN_MORPHO_ELEMENTARY_GRADIENT_HH
+
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_(const Image_with_Nbh<I>& input)
+ {
+ return elementary_dilation(input) - elementary_erosion(input);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient(const Image_with_Nbh<I>& input)
+ {
+ return impl::elementary_gradient_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_GRADIENT_HH
Index: oln/morpho/elementary_gradient_external.hh
--- oln/morpho/elementary_gradient_external.hh (revision 0)
+++ oln/morpho/elementary_gradient_external.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_MORPHO_EXTERNAL_GRADIENT_HH
+# define OLN_MORPHO_EXTERNAL_GRADIENT_HH
+
+#include <oln/morpho/elementary_dilation.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_external(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_external_(const Image_with_Nbh<I>& input)
+ {
+ return elementary_dilation(input) - input;
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_external(const Image_with_Nbh<I>& input)
+ {
+ return impl::elementary_gradient_external_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_EXTERNAL_GRADIENT_HH
Index: oln/morpho/elementary_laplace.hh
--- oln/morpho/elementary_laplace.hh (revision 0)
+++ oln/morpho/elementary_laplace.hh (revision 0)
@@ -0,0 +1,84 @@
+// 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_ELEMENTARY_LAPLACE_HH
+# define OLN_MORPHO_ELEMENTARY_LAPLACE_HH
+
+#include <oln/morpho/elementary_gradient_external.hh>
+#include <oln/morpho/elementary_gradient_internal.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_laplace(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_laplace_(const Image_with_Nbh<I>& input)
+ {
+ return elementary_gradient_external(input) - elementary_gradient_internal(input);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_laplace(const Image_with_Nbh<I>& input)
+ {
+ return impl::elementary_laplace_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_LAPLACE_HH
Index: oln/morpho/gradient_internal.hh
--- oln/morpho/gradient_internal.hh (revision 905)
+++ oln/morpho/gradient_internal.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_INSIDE_GRADIENT_HH
-# define OLN_MORPHO_INSIDE_GRADIENT_HH
+#ifndef OLN_MORPHO_GRADIENT_INTERNAL_HH
+# define OLN_MORPHO_GRADIENT_INTERNAL_HH
-#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/erosion.hh>
#include <oln/arith/minus.hh>
namespace oln
@@ -39,9 +39,10 @@
// Fwd decl.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- inside_gradient(const Image_with_Nbh<I>& input);
+ gradient_internal(const Image<I>& input,
+ const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -51,26 +52,27 @@
// Generic version.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- inside_gradient_(const Image_with_Nbh<I>& input)
+ gradient_internal_(const Image<I>& input,
+ const Window<W>& win)
{
- return input - elementary_erosion(input);
+ return input - erosion(input, win);
}
- // FIXME: Add a fast version.
} // end of namespace oln::morpho::impl
// Facade.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- inside_gradient(const Image_with_Nbh<I>& input)
+ gradient_internal(const Image<I>& input,
+ const Window<W>& win)
{
- return impl::inside_gradient_(exact(input));
+ return impl::gradient_internal_(exact(input), win);
}
# endif // ! OLN_INCLUDE_ONLY
@@ -80,4 +82,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_INSIDE_GRADIENT_HH
+#endif // ! OLN_MORPHO_GRADIENT_INTERNAL_HH
Index: oln/morpho/gradient.hh
--- oln/morpho/gradient.hh (revision 905)
+++ oln/morpho/gradient.hh (working copy)
@@ -28,8 +28,8 @@
#ifndef OLN_MORPHO_GRADIENT_HH
# define OLN_MORPHO_GRADIENT_HH
-#include <oln/morpho/elementary_erosion.hh>
-#include <oln/morpho/elementary_dilation.hh>
+#include <oln/morpho/erosion.hh>
+#include <oln/morpho/dilation.hh>
#include <oln/arith/minus.hh>
namespace oln
@@ -40,9 +40,10 @@
// Fwd decl.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- gradient(const Image_with_Nbh<I>& input);
+ gradient(const Image<I>& input,
+ const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -52,26 +53,26 @@
// Generic version.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- gradient_(const Image_with_Nbh<I>& input)
+ gradient_(const Image<I>& input,
+ const Window<W>& win)
{
- return elementary_dilation(input) - elementary_erosion(input);
+ return dilation(input, win) - erosion(input, win);
}
- // FIXME: Add a fast version.
-
} // end of namespace oln::morpho::impl
// Facade.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- gradient(const Image_with_Nbh<I>& input)
+ gradient(const Image<I>& input,
+ const Window<W>& win)
{
- return impl::gradient_(exact(input));
+ return impl::gradient_(exact(input), win);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/gradient_external.hh
--- oln/morpho/gradient_external.hh (revision 905)
+++ oln/morpho/gradient_external.hh (working copy)
@@ -25,10 +25,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_EXTERNAL_GRADIENT_HH
-# define OLN_MORPHO_EXTERNAL_GRADIENT_HH
+#ifndef OLN_MORPHO_GRADIENT_EXTERNAL_HH
+# define OLN_MORPHO_GRADIENT_EXTERNAL_HH
-#include <oln/morpho/elementary_dilation.hh>
+#include <oln/morpho/dilation.hh>
#include <oln/arith/minus.hh>
namespace oln
@@ -39,9 +39,10 @@
// Fwd decl.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- external_gradient(const Image_with_Nbh<I>& input);
+ gradient_external(const Image<I>& input,
+ const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -51,26 +52,26 @@
// Generic version.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- external_gradient_(const Image_with_Nbh<I>& input)
+ gradient_external_(const Image<I>& input,
+ const Window<W>& win)
{
- return elementary_dilation(input) - input;
+ return dilation(input, win) - input;
}
- // FIXME: Add a fast version.
-
} // end of namespace oln::morpho::impl
// Facade.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- external_gradient(const Image_with_Nbh<I>& input)
+ gradient_external(const Image<I>& input,
+ const Window<W>& win)
{
- return impl::external_gradient_(exact(input));
+ return impl::gradient_external_(exact(input), win);
}
# endif // ! OLN_INCLUDE_ONLY
@@ -80,4 +81,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_EXTERNAL_GRADIENT_HH
+#endif // ! OLN_MORPHO_GRADIENT_EXTERNAL_HH
Index: oln/morpho/laplace.hh
--- oln/morpho/laplace.hh (revision 905)
+++ oln/morpho/laplace.hh (working copy)
@@ -28,8 +28,8 @@
#ifndef OLN_MORPHO_LAPLACE_HH
# define OLN_MORPHO_LAPLACE_HH
-#include <oln/morpho/gradient_external.hh>
-#include <oln/morpho/gradient_internal.hh>
+#include <oln/morpho/elementary_gradient_external.hh>
+#include <oln/morpho/elementary_gradient_internal.hh>
#include <oln/arith/minus.hh>
namespace oln
@@ -40,9 +40,10 @@
// Fwd decl.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- laplace(const Image_with_Nbh<I>& input);
+ laplace(const Image<I>& input,
+ const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -52,11 +53,12 @@
// Generic version.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- laplace_(const Image_with_Nbh<I>& input)
+ laplace_(const Image<I>& input,
+ const Window<W>& win)
{
- return external_gradient(input) - inside_gradient(input);
+ return gradient_external(input, win) - gradient_internal(input, win);
}
@@ -67,11 +69,12 @@
// Facade.
- template <typename I>
+ template <typename I, typename W>
oln_plain(I)
- laplace(const Image_with_Nbh<I>& input)
+ laplace(const Image<I>& input,
+ const Window<W>& win)
{
- return impl::laplace_(exact(input));
+ return impl::laplace_(exact(input), win);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 905)
+++ oln/morpho/erosion.hh (working copy)
@@ -30,7 +30,7 @@
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
-#include <oln/accumulator/max.hh>
+#include <oln/accumulator/min.hh>
namespace oln
{
@@ -56,7 +56,7 @@
oln_plain(I)
erosion_(const Image<I>& input, const Window<W>& win)
{
- border::fill(input, oln_min(oln_value(I)));
+ border::fill(input, oln_max(oln_value(I)));
accumulator::min_<oln_value(I)> min;
return level::apply_local(min, input, win);
}
@@ -66,7 +66,7 @@
erosion_on_set_(const Image<I>&,
const I& input)
{
- border::fill(input, oln_min(oln_value(I)));
+ border::fill(input, true);
accumulator::and_<oln_value(I)> accu_and;
return level::apply_local(accu_and, input);
}
Index: oln/morpho/elementary_gradient_internal.hh
--- oln/morpho/elementary_gradient_internal.hh (revision 0)
+++ oln/morpho/elementary_gradient_internal.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_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
+# define OLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
+
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_internal(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_internal_(const Image_with_Nbh<I>& input)
+ {
+ return input - elementary_erosion(input);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_gradient_internal(const Image_with_Nbh<I>& input)
+ {
+ return impl::elementary_gradient_internal_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_GRADIENT_INTERNAL_HH
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 905)
+++ oln/core/2d/image2d.hh (working copy)
@@ -213,7 +213,8 @@
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
- array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(),
+ array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(), //FIXME
+ //: *.
b.pmin().col(),
b.pmax().row(),
b.pmax().col());
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add Box and comparison operators between point sets.
* oln/core/gen/pset_compare.hh: New.
* oln/core/concept/point_set.hh (Box): New.
* oln/core/2d/box2d.hh (include): Remove gen/box.hh.
* oln/core/internal/point_set_base.hh
(point_set_selector_): New.
* oln/stc/scoop.hxx (super_trait_): Change dummy code.
core/2d/box2d.hh | 12 ---
core/concept/point_set.hh | 54 +++++++++++++
core/gen/pset_compare.hh | 159 ++++++++++++++++++++++++++++++++++++++++
core/internal/point_set_base.hh | 30 +++++++
stc/scoop.hxx | 12 ++-
5 files changed, 255 insertions(+), 12 deletions(-)
Index: oln/core/concept/point_set.hh
--- oln/core/concept/point_set.hh (revision 904)
+++ oln/core/concept/point_set.hh (working copy)
@@ -64,6 +64,24 @@
}; // end of oln::Point_Set<Exact>
+ /// Concept-class "Box".
+
+ template <typename Exact>
+ struct Box : public Point_Set<Exact>
+ {
+ stc_using_from(Point_Set, point);
+
+ const point& pmin() const;
+ point& pmin();
+ const point& pmax() const;
+ point& pmax();
+
+ protected:
+ Box();
+
+ }; // end of oln::Box<Exact>
+
+
template <typename Ps>
std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts);
@@ -96,6 +114,38 @@
{
}
+ template <typename Exact>
+ Box<Exact>::Box()
+ {
+ }
+
+ template <typename Exact>
+ const typename Box<Exact>::point&
+ Box<Exact>::pmin() const
+ {
+ return exact(this)->impl_pmin();
+ }
+
+ template <typename Exact>
+ typename Box<Exact>::point&
+ Box<Exact>::pmin()
+ {
+ return exact(this)->impl_pmin();
+ }
+
+ template <typename Exact>
+ const typename Box<Exact>::point&
+ Box<Exact>::pmax() const
+ {
+ return exact(this)->impl_pmax();
+ }
+
+ template <typename Exact>
+ typename Box<Exact>::point&
+ Box<Exact>::pmax()
+ {
+ return exact(this)->impl_pmax();
+ }
template <typename Ps>
std::ostream& operator<<(std::ostream& ostr, const Point_Set<Ps>& pts)
@@ -114,4 +164,8 @@
} // end of namespace oln
+// FIXME: Bad?
+# include <oln/core/gen/pset_compare.hh>
+
+
#endif // ! OLN_CORE_CONCEPT_POINT_SET_HH
Index: oln/core/2d/box2d.hh
--- oln/core/2d/box2d.hh (revision 904)
+++ oln/core/2d/box2d.hh (working copy)
@@ -86,17 +86,9 @@
} // end of namespace oln::internal
-} // end of namespace oln
-
-
-# include <oln/core/gen/box.hh>
-
# ifndef OLN_INCLUDE_ONLY
-namespace oln
-{
-
box2d::box2d()
{
}
@@ -144,10 +136,10 @@
} // end of namespace oln::internal
-} // end of namespace oln
+# endif // ! OLN_INCLUDE_ONLY
-# endif // OLN_INCLUDE_ONLY
+} // end of namespace oln
#endif // ! OLN_CORE_2D_BOX2D_HH
Index: oln/core/gen/pset_compare.hh
--- oln/core/gen/pset_compare.hh (revision 0)
+++ oln/core/gen/pset_compare.hh (revision 0)
@@ -0,0 +1,159 @@
+// 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_PSET_COMPARE_HH
+# define OLN_CORE_GEN_PSET_COMPARE_HH
+
+# include <oln/core/concept/point_set.hh>
+
+
+namespace oln
+{
+
+ // Fwd decls.
+
+ 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);
+
+
+ // FIXME: Guards; without impl!
+ template <typename L, typename R> bool operator < (const Point_Set<L>&, const Point_Set<R>&);
+ template <typename L, typename R> bool operator > (const Point_Set<L>&, const Point_Set<R>&);
+ template <typename L, typename R> bool operator >= (const Point_Set<L>&, const Point_Set<R>&);
+ // end of FIXME
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Point_Set L = Point_Set R
+ // ------------------------------
+
+ // Generic version.
+
+ template <typename L, typename R>
+ bool op_eq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ oln_piter(L) pl(lhs);
+ oln_piter(R) pr(rhs);
+ for (pl.start(), pr.start();
+ pl.is_valid();
+ pl.next(), pr.next())
+ {
+ if (not pr.is_valid()) // while pl is valid
+ return false;
+ if (pl.to_point() != pr.to_point())
+ return false;
+ }
+ if (pr.is_valid()) // while pl is not valid
+ return false;
+ 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
+ // ------------------------------
+
+ // Generic version.
+
+ template <typename L, typename R>
+ bool op_leq_(const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ // quick test:
+ if (lhs.npoints() > rhs.npoints())
+ return false;
+ // final test:
+ oln_piter(R) pr(rhs);
+ pr.start();
+ oln_piter(L) pl(lhs);
+ for_all(pl)
+ {
+ while (pr.is_valid() and pr.to_point() != pl.to_point())
+ pr.next();
+ if (not pr.is_valid())
+ return false;
+ }
+ return true;
+ }
+
+ /*
+ // Version for Boxes.
+
+ FIXME: Activate.
+ template <typename L, typename R>
+ bool op_leq_(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;
+ }
+ */
+
+
+ } // end of namespace oln::impl
+
+
+ // Facades.
+
+ template <typename L, typename R>
+ bool operator = (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg.
+ return impl::op_eq_(exact(lhs), exact(rhs));
+ }
+
+ template <typename L, typename R>
+ bool operator <= (const Point_Set<L>& lhs, const Point_Set<R>& rhs)
+ {
+ mlc::assert_equal_< oln_grid(L), oln_grid(R) >::check(); // FIXME: Add err msg.
+ return impl::op_leq_(exact(lhs), exact(rhs));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_PSET_COMPARE_HH
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 904)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -34,8 +34,28 @@
namespace oln
{
+
+ 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 Exact>
+ struct point_set_selector_< false, Exact > : public Point_Set<Exact>
+ {};
+
+ } // end of namespace oln::internal
+
+
+
// point_set_base_ class
+
/// Fwd decls.
namespace internal { template <typename Exact> struct point_set_base_; }
template <typename P> class gen_box;
@@ -46,6 +66,14 @@
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;
+ */
};
@@ -74,7 +102,7 @@
/// Base class for point sets.
template <typename Exact>
- struct point_set_base_ : public Point_Set<Exact>
+ struct point_set_base_ : public Point_Set<Exact> // FIXME: Change inheritance.
{
protected:
point_set_base_();
Index: oln/stc/scoop.hxx
--- oln/stc/scoop.hxx (revision 904)
+++ oln/stc/scoop.hxx (working copy)
@@ -88,7 +88,10 @@
/* super_trait_ */
template <typename from_type>
-struct super_trait_;
+struct super_trait_
+{
+ typedef mlc::none ret;
+};
template <typename from_type>
@@ -96,6 +99,11 @@
{
};
+
+/*
+
+ FIXME: Inactivate since dummy code (many class are not Abstractions but abstraction<Exact>).
+
template <template <class> class abstraction, typename Exact>
struct super_trait_< abstraction<Exact> >
{
@@ -109,6 +117,8 @@
typedef mlc::none ret;
};
+*/
+
1
0
23 Mar '07
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Mopho : Top_hat_white, top_hat_black, Fix Opening, Renaming.
* oln/morpho/inside_gradient.hh: Remove.
* oln/morpho/gradient_internal.hh: New.
* oln/morpho/top_hat_black.hh: New.
* oln/morpho/closing.hh: Fixed.
* oln/morpho/top_hat_white.hh: New.
* oln/morpho/opening.hh: Fixed.
* oln/morpho/external_gradient.hh: Remove.
* oln/morpho/gradient_external.hh: New.
* oln/morpho/laplace.hh: .
closing.hh | 4 +-
laplace.hh | 4 +-
opening.hh | 8 ++---
top_hat_black.hh | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
top_hat_white.hh | 87 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 183 insertions(+), 8 deletions(-)
Index: oln/morpho/top_hat_black.hh
--- oln/morpho/top_hat_black.hh (revision 0)
+++ oln/morpho/top_hat_black.hh (revision 0)
@@ -0,0 +1,88 @@
+// 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_TOP_HAT_BLACK_HH
+# define OLN_MORPHO_TOP_HAT_BLACK_HH
+
+#include <oln/morpho/opening.hh>
+#include <oln/morpho/closing.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ top_hat_black(const Image<I>& input,
+ const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ top_hat_black_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return closing(input, win) - input;
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ top_hat_black(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return impl::top_hat_black_(exact(input), win);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_TOP_HAT_BLACK_HH
+
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 903)
+++ oln/morpho/closing.hh (working copy)
@@ -28,8 +28,8 @@
#ifndef OLN_MORPHO_CLOSING_HH
# define OLN_MORPHO_CLOSING_HH
-#include <oln/morpho/elementary_erosion.hh>
-#include <oln/morpho/elementary_dilation.hh>
+#include <oln/morpho/erosion.hh>
+#include <oln/morpho/dilation.hh>
namespace oln
{
Index: oln/morpho/top_hat_white.hh
--- oln/morpho/top_hat_white.hh (revision 0)
+++ oln/morpho/top_hat_white.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_MORPHO_TOP_HAT_WHITE_HH
+# define OLN_MORPHO_TOP_HAT_WHITE_HH
+
+#include <oln/morpho/opening.hh>
+#include <oln/morpho/closing.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ top_hat_white(const Image<I>& input,
+ const Window<W>& win);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ top_hat_white_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return input - opening(input, win);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ top_hat_white(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return impl::top_hat_white_(exact(input), win);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_TOP_HAT_WHITE_HH
+
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 903)
+++ oln/morpho/opening.hh (working copy)
@@ -28,8 +28,8 @@
#ifndef OLN_MORPHO_OPENING_HH
# define OLN_MORPHO_OPENING_HH
-#include <oln/morpho/elementary_erosion.hh>
-#include <oln/morpho/elementary_dilation.hh>
+#include <oln/morpho/erosion.hh>
+#include <oln/morpho/dilation.hh>
namespace oln
{
@@ -56,8 +56,8 @@
opening_(const Image<I>& input,
const Window<W>& win)
{
- oln_plain(I) tmp = morpho::dilation(input, win);
- return morpho::erosion(tmp, win); // FIXME : inverse(win).
+ oln_plain(I) tmp = morpho::erosion(input, win);
+ return morpho::dilation(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
Index: oln/morpho/laplace.hh
--- oln/morpho/laplace.hh (revision 903)
+++ oln/morpho/laplace.hh (working copy)
@@ -28,8 +28,8 @@
#ifndef OLN_MORPHO_LAPLACE_HH
# define OLN_MORPHO_LAPLACE_HH
-#include <oln/morpho/external_gradient.hh>
-#include <oln/morpho/inside_gradient.hh>
+#include <oln/morpho/gradient_external.hh>
+#include <oln/morpho/gradient_internal.hh>
#include <oln/arith/minus.hh>
namespace oln
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Add internal::box_ and box2d classes.
* oln/core/rle/rle_image.hh, oln/core/sparse/sparse_image.hh
* oln/core/encode/sparse_encode.hh, oln/core/encode/rle_encode.hh: change licence and header name
* oln/core/1d/box1d.hh: move box_ to gen_box
* oln/core/2d/box2d.hh: box2d is know a real class
* oln/core/gen/box.hh: rename box_ class as gen_box
* oln/core/gen/fbbox.hh: move box_ to gen_box
* oln/core/internal/box.hh: New class internal::box_
* oln/core/internal/point_set_base.hh, oln/core/internal/image_base.hh: .
* oln/core/internal/point_set_std_based.hh: Change vtypes
1d/box1d.hh | 2
2d/box2d.hh | 50 ++++
encode/rle_encode.hh | 1
encode/sparse_encode.hh | 9
gen/box.hh | 142 ++++++-------
gen/fbbox.hh | 10
internal/box.hh | 464 +++++++++++++++++++++++++++++++++++++++++++++
internal/image_base.hh | 14 -
internal/point_set_base.hh | 7
rle/rle_image.hh | 3
sparse/sparse_image.hh | 12 -
11 files changed, 620 insertions(+), 94 deletions(-)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 902)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA
-// Research and Development Laboratory
+// 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
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 902)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
+// 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
@@ -25,9 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
+
#ifndef OLN_CORE_GEN_SPARSE_IMAGE_HH
# define OLN_CORE_GEN_SPARSE_IMAGE_HH
+
# include <vector>
# include <map>
@@ -64,12 +66,17 @@
typedef rle_pset<point> pset;
- //FIXME:
+ //FIXME: set correct trait
typedef mlc::none plain;
typedef std::pair< pset, std::map<point, std::vector<value> > > data;
};
+ /*!
+ ** \class sparse_image
+ ** \brief represent an image not plain
+ **
+ */
template < typename P, typename T>
class sparse_image : public internal::primitive_image_< sparse_image<P, T> >
{
@@ -159,3 +166,4 @@
} // end of namespace oln
#endif // ! OLN_CORE_GEN_SPARSE_IMAGE_HH
+
Index: oln/core/encode/sparse_encode.hh
--- oln/core/encode/sparse_encode.hh (revision 902)
+++ oln/core/encode/sparse_encode.hh (working copy)
@@ -52,9 +52,12 @@
sparse_image<typename I::point, typename I::value> output;
typename I::piter p(input.points());
unsigned len = 1;
- typename I::coord old = 1; /*!< old point first dim coordinate */
- typename I::point rstart; /*!< range pointstart */
- std::vector<typename I::value> values; /*!< range value */
+ /// old point first dim coordinate
+ typename I::coord old = 1;
+ /// range pointstart
+ typename I::point rstart;
+ /// range value
+ std::vector<typename I::value> values;
p.start();
if (!p.is_valid())
Index: oln/core/encode/rle_encode.hh
--- oln/core/encode/rle_encode.hh (revision 902)
+++ oln/core/encode/rle_encode.hh (working copy)
@@ -33,6 +33,7 @@
# include <oln/core/rle/rle_image.hh>
+
namespace oln
{
Index: oln/core/1d/box1d.hh
--- oln/core/1d/box1d.hh (revision 902)
+++ oln/core/1d/box1d.hh (working copy)
@@ -36,7 +36,7 @@
{
// FIXME: box1d should be an actual type, not an alias...
- typedef box_<point1d> box1d;
+ typedef gen_box<point1d> box1d;
} // end of namespace oln
Index: oln/core/2d/box2d.hh
--- oln/core/2d/box2d.hh (revision 902)
+++ oln/core/2d/box2d.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/concept/point_set.hh> // for internal::tag::box_t
# include <oln/core/2d/point2d.hh>
+# include <oln/core/internal/box.hh>
namespace oln
@@ -39,11 +40,39 @@
template <typename P> class box_;
- // FIXME: box2d should be an actual type, not an alias...
- typedef box_<point2d> box2d;
+ // Forward declarations
+ struct box2d;
+ // Super type
+ template <>
+ struct super_trait_< box2d >
+ {
+ typedef box2d current;
+ typedef internal::box_<box2d> ret;
+ };
+
+ // Virtual types
+ template <>
+ struct vtypes<box2d>
+ {
+ typedef point2d point;
+ typedef box2d box;
+ };
+
+ // 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
+ typedef super::point point;
+
+ box2d();
+ box2d(const box2d::from_to_t& dat);
+ box2d(const point2d& pmin, const point2d& pmax);
+ };
- /// init__
namespace internal
{
@@ -68,6 +97,21 @@
namespace oln
{
+ box2d::box2d()
+ {
+ }
+
+ box2d::box2d(const box2d::from_to_t& dat) :
+ super(dat)
+ {
+ }
+
+ box2d::box2d(const point2d& pmin, const point2d& pmax) :
+ super(pmin, pmax)
+ {
+ }
+
+
namespace internal
{
Index: oln/core/gen/box.hh
--- oln/core/gen/box.hh (revision 902)
+++ oln/core/gen/box.hh (working copy)
@@ -39,37 +39,37 @@
// Forward declarations.
- template <typename P> class box_;
- template <typename P> class box_fwd_piter_;
- template <typename P> class box_bkd_piter_;
+ template <typename P> class gen_box;
+ template <typename P> class gen_box_fwd_piter_;
+ template <typename P> class gen_box_bkd_piter_;
// Super type declaration.
template <typename P>
- struct super_trait_< box_<P> >
+ struct super_trait_< gen_box<P> >
{
- typedef box_<P> current__;
+ typedef gen_box<P> current__;
typedef internal::point_set_base_<current__> ret;
};
- /// Virtual types associated to oln::box_<P>.
+ /// Virtual types associated to oln::gen_box<P>.
template <typename P>
- struct vtypes< box_<P> >
+ struct vtypes< gen_box<P> >
{
typedef P point;
- typedef box_fwd_piter_<P> fwd_piter;
- typedef box_bkd_piter_<P> bkd_piter;
+ typedef gen_box_fwd_piter_<P> fwd_piter;
+ typedef gen_box_bkd_piter_<P> bkd_piter;
};
/// Generic box class based on a point class.
template <typename P>
- class box_ : public internal::point_set_base_< box_<P> >,
+ class gen_box : public internal::point_set_base_< gen_box<P> >,
private mlc::assert_< mlc_is_a(P, Point) >
{
- typedef box_<P> current;
+ typedef gen_box<P> current;
typedef internal::point_set_base_<current> super;
typedef internal::initializer_<
@@ -87,16 +87,16 @@
public:
- box_();
- box_(const P& pmin, const P& pmax);
- box_(const from_to_t& data);
+ gen_box();
+ gen_box(const P& pmin, const P& pmax);
+ gen_box(const from_to_t& data);
template <typename D>
- box_(const internal::initializer_<D>& data);
+ gen_box(const internal::initializer_<D>& data);
unsigned impl_npoints() const;
bool impl_has(const P& p) const;
- const box_<P>& impl_bbox() const;
+ const gen_box<P>& impl_bbox() const;
const P& pmin() const;
P& pmin();
@@ -106,17 +106,17 @@
protected:
point pmin_, pmax_;
- }; // end of class oln::box_<P>
+ }; // end of class oln::gen_box<P>
template <typename P>
- std::ostream& operator<<(std::ostream& ostr, const box_<P>& b)
+ std::ostream& operator<<(std::ostream& ostr, const gen_box<P>& b)
{
return ostr << "{ " << b.pmin() << " .. " << b.pmax() << " }";
}
- // -------------------- iterators on box_<P>
+ // -------------------- iterators on gen_box<P>
@@ -124,16 +124,16 @@
/// Super types.
template <typename P>
- struct super_trait_< box_fwd_piter_<P> >
+ struct super_trait_< gen_box_fwd_piter_<P> >
{
- typedef box_fwd_piter_<P> current__;
+ typedef gen_box_fwd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
template <typename P>
- struct super_trait_< box_bkd_piter_<P> >
+ struct super_trait_< gen_box_bkd_piter_<P> >
{
- typedef box_bkd_piter_<P> current__;
+ typedef gen_box_bkd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
@@ -141,28 +141,28 @@
/// Virtual types.
template <typename P>
- struct vtypes< box_fwd_piter_<P> >
+ struct vtypes< gen_box_fwd_piter_<P> >
{
typedef P point;
};
template <typename P>
- struct vtypes< box_bkd_piter_<P> >
+ struct vtypes< gen_box_bkd_piter_<P> >
{
typedef P point;
};
- /// Class box_fwd_piter_<P>.
+ /// Class gen_box_fwd_piter_<P>.
template <typename P>
- class box_fwd_piter_ : public Iterator_on_Points< box_fwd_piter_<P> >,
+ class gen_box_fwd_piter_ : public Iterator_on_Points< gen_box_fwd_piter_<P> >,
private mlc::assert_< mlc_is_a(P, Point) >
{
public:
- box_fwd_piter_();
- box_fwd_piter_(const Point_Set< box_<P> >& b);
- void set_box(const box_<P>& b);
+ gen_box_fwd_piter_();
+ gen_box_fwd_piter_(const Point_Set< gen_box<P> >& b);
+ void set_box(const gen_box<P>& b);
void impl_start();
void impl_next();
@@ -172,21 +172,21 @@
const P* impl_point_adr() const;
private:
- box_<P> b_;
+ gen_box<P> b_;
P p_, nop_;
};
- /// Class box_bkd_piter_<P>.
+ /// Class gen_box_bkd_piter_<P>.
template <typename P>
- class box_bkd_piter_ : public Iterator_on_Points< box_bkd_piter_<P> >,
+ class gen_box_bkd_piter_ : public Iterator_on_Points< gen_box_bkd_piter_<P> >,
private mlc::assert_< mlc_is_a(P, Point) >
{
public:
- box_bkd_piter_();
- box_bkd_piter_(const Point_Set< box_<P> >& b);
- void set_box(const box_<P>& b);
+ gen_box_bkd_piter_();
+ gen_box_bkd_piter_(const Point_Set< gen_box<P> >& b);
+ void set_box(const gen_box<P>& b);
void impl_start();
void impl_next();
@@ -196,7 +196,7 @@
const P* impl_point_adr() const;
private:
- box_<P> b_;
+ gen_box<P> b_;
P p_, nop_;
};
@@ -206,16 +206,16 @@
# ifndef OLN_INCLUDE_ONLY
- // -------------------- box_<P>
+ // -------------------- gen_box<P>
template <typename P>
- box_<P>::box_()
+ gen_box<P>::gen_box()
{
}
template <typename P>
- box_<P>::box_(const P& pmin, const P& pmax)
+ gen_box<P>::gen_box(const P& pmin, const P& pmax)
{
for (unsigned i = 0; i < n; ++i)
precondition(pmax[i] >= pmin[i]);
@@ -224,7 +224,7 @@
}
template <typename P>
- box_<P>::box_(const typename box_<P>::from_to_t& dat)
+ gen_box<P>::gen_box(const typename gen_box<P>::from_to_t& dat)
{
this->pmin_ = dat->first.value;
this->pmax_ = dat->second.value;
@@ -232,7 +232,7 @@
template <typename P>
template <typename D>
- box_<P>::box_(const internal::initializer_<D>& data)
+ gen_box<P>::gen_box(const internal::initializer_<D>& data)
{
bool box_ok = internal::init__(internal::tag::box_t(), *this, data.value());
postcondition(box_ok);
@@ -240,7 +240,7 @@
template <typename P>
unsigned
- box_<P>::impl_npoints() const
+ gen_box<P>::impl_npoints() const
{
unsigned count = 1;
for (unsigned i = 0; i < n; ++i)
@@ -250,7 +250,7 @@
template <typename P>
bool
- box_<P>::impl_has(const P& p) const
+ gen_box<P>::impl_has(const P& p) const
{
for (unsigned i = 0; i < n; ++i)
if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i])
@@ -259,15 +259,15 @@
}
template <typename P>
- const box_<P>&
- box_<P>::impl_bbox() const
+ const gen_box<P>&
+ gen_box<P>::impl_bbox() const
{
return *this;
}
template <typename P>
const P&
- box_<P>::pmin() const
+ gen_box<P>::pmin() const
{
for (unsigned i = 0; i < n; ++i)
invariant(this->pmin_[i] <= this->pmax_[i]);
@@ -276,7 +276,7 @@
template <typename P>
const P&
- box_<P>::pmax() const
+ gen_box<P>::pmax() const
{
for (unsigned i = 0; i < n; ++i)
invariant(this->pmax_[i] >= this->pmin_[i]);
@@ -285,35 +285,35 @@
template <typename P>
P&
- box_<P>::pmin()
+ gen_box<P>::pmin()
{
return this->pmin_;
}
template <typename P>
P&
- box_<P>::pmax()
+ gen_box<P>::pmax()
{
return this->pmax_;
}
- // -------------------- box_fwd_piter_<P>
+ // -------------------- gen_box_fwd_piter_<P>
template <typename P>
- box_fwd_piter_<P>::box_fwd_piter_()
+ gen_box_fwd_piter_<P>::gen_box_fwd_piter_()
{
}
template <typename P>
- box_fwd_piter_<P>::box_fwd_piter_(const Point_Set< box_<P> >& b)
+ gen_box_fwd_piter_<P>::gen_box_fwd_piter_(const Point_Set< gen_box<P> >& b)
{
this->set_box(exact(b));
}
template <typename P>
- void box_fwd_piter_<P>::set_box(const box_<P>& b)
+ void gen_box_fwd_piter_<P>::set_box(const gen_box<P>& b)
{
b_ = b;
nop_ = b_.pmax();
@@ -322,13 +322,13 @@
}
template <typename P>
- void box_fwd_piter_<P>::impl_start()
+ void gen_box_fwd_piter_<P>::impl_start()
{
p_ = b_.pmin();
}
template <typename P>
- void box_fwd_piter_<P>::impl_next()
+ void gen_box_fwd_piter_<P>::impl_next()
{
for (int i = P::n - 1; i >= 0; --i)
if (p_[i] == b_.pmax()[i])
@@ -343,47 +343,47 @@
}
template <typename P>
- void box_fwd_piter_<P>::impl_invalidate()
+ void gen_box_fwd_piter_<P>::impl_invalidate()
{
p_ = nop_;
}
template <typename P>
- bool box_fwd_piter_<P>::impl_is_valid() const
+ bool gen_box_fwd_piter_<P>::impl_is_valid() const
{
return p_ != nop_;
}
template <typename P>
- P box_fwd_piter_<P>::impl_to_point() const
+ P gen_box_fwd_piter_<P>::impl_to_point() const
{
return p_;
}
template <typename P>
- const P* box_fwd_piter_<P>::impl_point_adr() const
+ const P* gen_box_fwd_piter_<P>::impl_point_adr() const
{
return &p_;
}
- // -------------------- box_bkd_piter_<P>
+ // -------------------- gen_box_bkd_piter_<P>
template <typename P>
- box_bkd_piter_<P>::box_bkd_piter_()
+ gen_box_bkd_piter_<P>::gen_box_bkd_piter_()
{
}
template <typename P>
- box_bkd_piter_<P>::box_bkd_piter_(const Point_Set< box_<P> >& b)
+ gen_box_bkd_piter_<P>::gen_box_bkd_piter_(const Point_Set< gen_box<P> >& b)
{
this->set_box(exact(b));
}
template <typename P>
- void box_bkd_piter_<P>::set_box(const box_<P>& b)
+ void gen_box_bkd_piter_<P>::set_box(const gen_box<P>& b)
{
b_ = b;
nop_ = b_.pmin();
@@ -392,13 +392,13 @@
}
template <typename P>
- void box_bkd_piter_<P>::impl_start()
+ void gen_box_bkd_piter_<P>::impl_start()
{
p_ = b_.pmax();
}
template <typename P>
- void box_bkd_piter_<P>::impl_next()
+ void gen_box_bkd_piter_<P>::impl_next()
{
for (int i = P::n - 1; i >= 0; --i)
if (p_[i] == b_.pmin()[i])
@@ -413,30 +413,30 @@
}
template <typename P>
- void box_bkd_piter_<P>::impl_invalidate()
+ void gen_box_bkd_piter_<P>::impl_invalidate()
{
p_ = nop_;
}
template <typename P>
- bool box_bkd_piter_<P>::impl_is_valid() const
+ bool gen_box_bkd_piter_<P>::impl_is_valid() const
{
return p_ != nop_;
}
template <typename P>
- P box_bkd_piter_<P>::impl_to_point() const
+ P gen_box_bkd_piter_<P>::impl_to_point() const
{
return p_;
}
template <typename P>
- const P* box_bkd_piter_<P>::impl_point_adr() const
+ const P* gen_box_bkd_piter_<P>::impl_point_adr() const
{
return &p_;
}
-# endif // OLN_INCLUDE_ONLY
+# endif // !OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/gen/fbbox.hh
--- oln/core/gen/fbbox.hh (revision 902)
+++ oln/core/gen/fbbox.hh (working copy)
@@ -49,16 +49,16 @@
public:
fbbox_();
- operator box_<P>() const;
+ operator gen_box<P>() const;
bool is_valid() const;
void flush();
fbbox_<P>& take(const P& p);
- const box_<P>& box() const;
+ const gen_box<P>& box() const;
private:
bool is_valid_;
- box_<P> b_;
+ gen_box<P> b_;
}; // end of class oln::fbbox_<P>
@@ -73,7 +73,7 @@
}
template <typename P>
- fbbox_<P>::operator box_<P>() const
+ fbbox_<P>::operator gen_box<P>() const
{
precondition(this->is_valid_);
return this->b_;
@@ -112,7 +112,7 @@
}
template <typename P>
- const box_<P>& fbbox_<P>::box() const
+ const gen_box<P>& fbbox_<P>::box() const
{
precondition(this->is_valid_);
return this->b_;
Index: oln/core/internal/box.hh
--- oln/core/internal/box.hh (revision 0)
+++ oln/core/internal/box.hh (revision 0)
@@ -0,0 +1,464 @@
+// 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_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>
+
+
+namespace oln
+{
+
+
+ // Forward declarations.
+ namespace internal
+ {
+ template <typename Exact> class box_;
+ template <typename Exact> class box_fwd_piter_;
+ template <typename Exact> class box_bkd_piter_;
+ }
+
+ // Super type declaration.
+ template <typename Exact>
+ struct super_trait_< internal::box_<Exact> >
+ {
+ // typedef box_<Exact> current__;
+ typedef internal::point_set_base_<Exact> ret;
+ };
+
+
+ /// Virtual types associated to oln::box_<P>.
+ template <typename Exact>
+ struct vtypes< internal::box_<Exact> >
+ {
+ //typedef point2d point;
+ typedef stc::final< internal::box_fwd_piter_<Exact> > fwd_piter;
+ typedef stc::final< internal::box_bkd_piter_<Exact> > bkd_piter;
+ };
+
+
+
+ namespace internal
+ {
+ /// Generic box class based on a point class.
+ template <typename Exact>
+ class box_ : public point_set_base_< Exact >
+ {
+ typedef box_<Exact> current;
+ typedef point_set_base_<Exact> super;
+ public:
+ stc_using(point);
+ stc_using(box);
+
+
+ typedef internal::initializer_<
+ internal::pair< internal::from_t<point>, internal::to_t<point> >
+ > from_to_t;
+
+ private:
+ typedef stc_type(point, dim) dim__;
+
+ public:
+ enum { n = mlc_value(dim__) };
+
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const Exact& impl_bbox() const;
+
+ const point& pmin() const;
+ point& pmin();
+ const point& pmax() const;
+ point& pmax();
+
+ protected:
+ box_();
+ box_(const point& pmin, const point& pmax);
+ box_(const from_to_t& data);
+
+ point pmin_, pmax_;
+
+ }; // 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
+
+
+ // -------------------- iterators on box_<Exact>
+
+
+
+
+ /// Super types.
+
+ template <typename B>
+ struct super_trait_< internal::box_fwd_piter_<B> >
+ {
+ typedef internal::box_fwd_piter_<B> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
+
+ template <typename B>
+ struct super_trait_<internal:: box_bkd_piter_<B> >
+ {
+ typedef internal::box_bkd_piter_<B> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
+
+
+ /// Virtual types.
+
+ template <typename B>
+ struct vtypes< internal::box_fwd_piter_<B> >
+ {
+ typedef typename B::point point;
+ };
+
+ template <typename B>
+ struct vtypes< internal::box_bkd_piter_<B> >
+ {
+ typedef typename B::point point;
+ };
+
+
+ namespace internal
+ {
+ /// Class box_fwd_piter_<P>.
+
+ template <typename B>
+ class box_fwd_piter_ : public Iterator_on_Points< 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;
+ public:
+ stc_using(point);
+
+ box_fwd_piter_();
+ box_fwd_piter_(const Point_Set< B >& b);
+ void set_box(const B& b);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ private:
+ B b_;
+ point p_, nop_;
+ };
+
+
+ /// Class box_bkd_piter_<B>.
+
+ template <typename B>
+ class box_bkd_piter_ : public Iterator_on_Points< 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;
+ public:
+ stc_using(point);
+
+ box_bkd_piter_();
+ box_bkd_piter_(const Point_Set< B >& b);
+ void set_box(const B& b);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ private:
+ B b_;
+ point p_, nop_;
+ };
+
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+ // -------------------- box_<Exact>
+
+
+ template <typename Exact>
+ box_<Exact>::box_()
+ {
+ }
+
+ template <typename Exact>
+ box_<Exact>::box_(const box_<Exact>::point& pmin,
+ const box_<Exact>::point& pmax)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ precondition(pmax[i] >= pmin[i]);
+ this->pmin_ = pmin;
+ this->pmax_ = pmax;
+ }
+
+ template <typename P>
+ box_<P>::box_(const typename box_<P>::from_to_t& dat)
+ {
+ this->pmin_ = dat->first.value;
+ this->pmax_ = dat->second.value;
+ }
+
+
+ template <typename Exact>
+ unsigned
+ box_<Exact>::impl_npoints() const
+ {
+ unsigned count = 1;
+ for (unsigned i = 0; i < n; ++i)
+ count *= (this->pmax_[i] - this->pmin_[i] + 1);
+ return count;
+ }
+
+ template <typename Exact>
+ bool
+ box_<Exact>::impl_has(const box_<Exact>::point& p) const
+ {
+ for (unsigned i = 0; i < n; ++i)
+ if (p[i] < this->pmin_[i] or p[i] > this->pmax_[i])
+ return false;
+ return true;
+ }
+
+ template <typename Exact>
+ const Exact&
+ box_<Exact>::impl_bbox() const
+ {
+ return *exact(this);
+ }
+
+ template <typename Exact>
+ const typename box_<Exact>::point&
+ box_<Exact>::pmin() const
+ {
+ for (unsigned i = 0; i < n; ++i)
+ invariant(this->pmin_[i] <= this->pmax_[i]);
+ return this->pmin_;
+ }
+
+ template <typename Exact>
+ const typename box_<Exact>::point&
+ box_<Exact>::pmax() const
+ {
+ for (unsigned i = 0; i < n; ++i)
+ invariant(this->pmax_[i] >= this->pmin_[i]);
+ return this->pmax_;
+ }
+
+ template <typename Exact>
+ typename box_<Exact>::point&
+ box_<Exact>::pmin()
+ {
+ return this->pmin_;
+ }
+
+ template <typename Exact>
+ typename box_<Exact>::point&
+ box_<Exact>::pmax()
+ {
+ return this->pmax_;
+ }
+
+
+ // -------------------- 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 Point_Set< B >& b)
+ {
+ this->set_box(exact(b));
+ }
+
+ template <typename B>
+ void
+ box_fwd_piter_<B>::set_box(const B& b)
+ {
+ b_ = b;
+ nop_ = b_.pmax();
+ ++nop_[0];
+ p_ = nop_;
+ }
+
+ template <typename B>
+ void
+ box_fwd_piter_<B>::impl_start()
+ {
+ p_ = b_.pmin();
+ }
+
+ template <typename B>
+ void
+ box_fwd_piter_<B>::impl_next()
+ {
+ for (int i = B::n - 1; i >= 0; --i)
+ if (p_[i] == b_.pmax()[i])
+ p_[i] = b_.pmin()[i];
+ else
+ {
+ ++p_[i];
+ break;
+ }
+ if (p_ == b_.pmin())
+ p_ = nop_;
+ }
+
+ template <typename B>
+ void
+ box_fwd_piter_<B>::impl_invalidate()
+ {
+ p_ = nop_;
+ }
+
+ template <typename B>
+ bool
+ box_fwd_piter_<B>::impl_is_valid() const
+ {
+ return p_ != nop_;
+ }
+
+ template <typename B>
+ typename box_fwd_piter_<B>::point
+ box_fwd_piter_<B>::impl_to_point() const
+ {
+ return p_;
+ }
+
+ template <typename B>
+ const typename box_fwd_piter_<B>::point*
+ box_fwd_piter_<B>::impl_point_adr() const
+ {
+ return &p_;
+ }
+
+
+
+ // -------------------- 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 Point_Set< B >& b)
+ {
+ this->set_box(exact(b));
+ }
+
+ template <typename B>
+ void
+ box_bkd_piter_<B>::set_box(const B& b)
+ {
+ b_ = b;
+ nop_ = b_.pmin();
+ --nop_[0];
+ p_ = nop_;
+ }
+
+ template <typename B>
+ void
+ box_bkd_piter_<B>::impl_start()
+ {
+ p_ = b_.pmax();
+ }
+
+ template <typename B>
+ void
+ box_bkd_piter_<B>::impl_next()
+ {
+ for (int i = B::n - 1; i >= 0; --i)
+ if (p_[i] == b_.pmin()[i])
+ p_[i] = b_.pmax()[i];
+ else
+ {
+ --p_[i];
+ break;
+ }
+ if (p_ == b_.pmax())
+ p_ = nop_;
+ }
+
+ template <typename B>
+ void
+ box_bkd_piter_<B>::impl_invalidate()
+ {
+ p_ = nop_;
+ }
+
+ template <typename B>
+ bool
+ box_bkd_piter_<B>::impl_is_valid() const
+ {
+ return p_ != nop_;
+ }
+
+ template <typename B>
+ typename box_bkd_piter_<B>::point
+ box_bkd_piter_<B>::impl_to_point() const
+ {
+ return p_;
+ }
+
+ template <typename B>
+ const typename box_bkd_piter_<B>::point*
+ box_bkd_piter_<B>::impl_point_adr() const
+ {
+ return &p_;
+ }
+
+# endif // OLN_INCLUDE_ONLY
+ } // end of namespace internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_BOX_HH
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 902)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -34,9 +34,11 @@
namespace oln
{
+ // point_set_base_ class
+
/// Fwd decls.
namespace internal { template <typename Exact> struct point_set_base_; }
- template <typename P> class box_;
+ template <typename P> class gen_box;
/// Super type.
@@ -59,7 +61,8 @@
typedef stc_deferred(fwd_piter) fwd_piter__;
typedef stc::final< stc::is<Point_Set> > category;
- typedef stc::final< box_<point__> > box;
+ //FIXME:
+ typedef gen_box<point__> box;
typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_piter__ > piter;
};
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 902)
+++ oln/core/internal/image_base.hh (working copy)
@@ -148,7 +148,9 @@
// Final.
typedef stc::final< stc::is<Image> > category;
- typedef stc::final< box_<point__> > box;
+ // 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;
typedef stc::final< oln_fwd_piter(pset__) > fwd_piter;
@@ -433,19 +435,20 @@
// init
template <typename P, typename I>
- bool init_(box_<P>* this_, const internal::image_base_<I>& data);
+ bool init_(typename internal::image_base_<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
- bool init_(box_<P>* this_, const internal::single_image_morpher_<I>& data);
+ bool
+ init_(typename internal::image_base_<I>::box** this_, const internal::single_image_morpher_<I>& data);
# ifndef OLN_INCLUDE_ONLY
template <typename P, typename I>
- bool init_(box_<P>* this_, const internal::image_base_<I>& data)
+ bool init_(typename internal::image_base_<I>::box** this_, const internal::image_base_<I>& data)
{
*this_ = data.bbox();
return true;
@@ -458,7 +461,8 @@
}
template <typename P, typename I>
- bool init_(box_<P>* this_, const internal::single_image_morpher_<I>& data)
+ bool
+ init_(typename internal::image_base_<I>::box** this_, const internal::single_image_morpher_<I>& data)
{
*this_ = data.bbox();
return true;
Index: oln/core/internal/point_set_std_based.hh
1
0
23 Mar '07
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Morpho : Gradient, gradient+ gradient-, Laplace. Arith : +, -.
* oln/morpho/laplace.hh: New.
* oln/morpho/inside_gradient.hh: New.
* oln/morpho/gradient.hh: New.
* oln/morpho/external_gradient.hh: New.
* oln/arith: New.
* oln/arith/plus.hh: New.
* oln/arith/minus.hh: New.
* oln/core/concept/operators.hh: .
* oln/core/2d/image2d.hh: .
arith/minus.hh | 64 +++++++++++++++++++++++++++++++++
arith/plus.hh | 64 +++++++++++++++++++++++++++++++++
core/2d/image2d.hh | 2 -
core/concept/operators.hh | 3 +
morpho/external_gradient.hh | 83 +++++++++++++++++++++++++++++++++++++++++++
morpho/gradient.hh | 84 ++++++++++++++++++++++++++++++++++++++++++++
morpho/inside_gradient.hh | 83 +++++++++++++++++++++++++++++++++++++++++++
morpho/laplace.hh | 84 ++++++++++++++++++++++++++++++++++++++++++++
8 files changed, 465 insertions(+), 2 deletions(-)
Index: oln/morpho/laplace.hh
--- oln/morpho/laplace.hh (revision 0)
+++ oln/morpho/laplace.hh (revision 0)
@@ -0,0 +1,84 @@
+// 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_LAPLACE_HH
+# define OLN_MORPHO_LAPLACE_HH
+
+#include <oln/morpho/external_gradient.hh>
+#include <oln/morpho/inside_gradient.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ laplace(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ laplace_(const Image_with_Nbh<I>& input)
+ {
+ return external_gradient(input) - inside_gradient(input);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ laplace(const Image_with_Nbh<I>& input)
+ {
+ return impl::laplace_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_LAPLACE_HH
Index: oln/morpho/inside_gradient.hh
--- oln/morpho/inside_gradient.hh (revision 0)
+++ oln/morpho/inside_gradient.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_MORPHO_INSIDE_GRADIENT_HH
+# define OLN_MORPHO_INSIDE_GRADIENT_HH
+
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ inside_gradient(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ inside_gradient_(const Image_with_Nbh<I>& input)
+ {
+ return input - elementary_erosion(input);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ inside_gradient(const Image_with_Nbh<I>& input)
+ {
+ return impl::inside_gradient_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_INSIDE_GRADIENT_HH
Index: oln/morpho/gradient.hh
--- oln/morpho/gradient.hh (revision 0)
+++ oln/morpho/gradient.hh (revision 0)
@@ -0,0 +1,84 @@
+// 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_GRADIENT_HH
+# define OLN_MORPHO_GRADIENT_HH
+
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ gradient(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ gradient_(const Image_with_Nbh<I>& input)
+ {
+ return elementary_dilation(input) - elementary_erosion(input);
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ gradient(const Image_with_Nbh<I>& input)
+ {
+ return impl::gradient_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_GRADIENT_HH
Index: oln/morpho/external_gradient.hh
--- oln/morpho/external_gradient.hh (revision 0)
+++ oln/morpho/external_gradient.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_MORPHO_EXTERNAL_GRADIENT_HH
+# define OLN_MORPHO_EXTERNAL_GRADIENT_HH
+
+#include <oln/morpho/elementary_dilation.hh>
+#include <oln/arith/minus.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ external_gradient(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ external_gradient_(const Image_with_Nbh<I>& input)
+ {
+ return elementary_dilation(input) - input;
+ }
+
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ external_gradient(const Image_with_Nbh<I>& input)
+ {
+ return impl::external_gradient_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_EXTERNAL_GRADIENT_HH
Index: oln/arith/plus.hh
--- oln/arith/plus.hh (revision 0)
+++ oln/arith/plus.hh (revision 0)
@@ -0,0 +1,64 @@
+// 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_ARITH_PLUS_HH
+# define OLN_ARITH_PLUS_HH
+
+
+namespace oln
+{
+
+ namespace arith
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ operator + (const Image<I>& lhs, const Image<I>& rhs);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ oln_plain(I)
+ operator + (const Image<I>& lhs, const Image<I>& rhs)
+ {
+ oln_plain(I) output;
+ init(output, with, lhs);
+ oln_piter(I) p(lhs.points());
+ for_all(p)
+ output(p) = lhs(p) + rhs(p);
+ return output;
+ }
+
+# 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 0)
+++ oln/arith/minus.hh (revision 0)
@@ -0,0 +1,64 @@
+// 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_ARITH_MINUS_HH
+# define OLN_ARITH_MINUS_HH
+
+
+namespace oln
+{
+
+// namespace arith
+// {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ operator - (const Image<I>& lhs, const Image<I>& rhs);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I>
+ oln_plain(I)
+ operator - (const Image<I>& lhs, const Image<I>& rhs)
+ {
+ oln_plain(I) output;
+ init(output, with, lhs);
+ oln_piter(I) p(lhs.points());
+ for_all(p)
+ output(p) = lhs(p) - rhs(p);
+ return output;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+// } // end of namespace oln::arith
+
+} // end of namespace oln
+
+#endif // ! OLN_ARITH_MINUS_HH
Index: oln/core/concept/operators.hh
--- oln/core/concept/operators.hh (revision 901)
+++ oln/core/concept/operators.hh (working copy)
@@ -158,12 +158,13 @@
return exact(rhs).op_unary_minus_();
}
- template <typename T>
+/* template <typename T>
T operator- (const Any<T>& lhs, const Any<T>& rhs)
{
T tmp = exact(lhs);
return tmp -= rhs;
}
+*/
// template <typename L, typename R>
// xtd_op_minus_trait(L, R) operator- (const Any<L>& lhs, const Any<R>& rhs)
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 901)
+++ oln/core/2d/image2d.hh (working copy)
@@ -213,7 +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(),
+ array2d_<T,int>* ptr = new array2d_<T,int>(b.pmin().row(),
b.pmin().col(),
b.pmax().row(),
b.pmax().col());
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add pw_value and operators on functions.
* oln/core/concept/generator.hh,
* oln/core/gen/literal.hh,
* oln/core/gen/fun_ops.hh: New.
* tests/core/image1d.cc,
* tests/core/pw_value.cc: Update.
* tests/core/Makefile.am (check_PROGRAMS): Clean.
Add image1d and pw_value.
* oln/level/fill.hh: Remove too restrictive const&.
* oln/core/equipment.hh (result, oln_result, oln_rvalue): New.
* oln/core/gen/pw_value.hh: Update.
* oln/core/gen/fun.hh (fun_p2b_): New specialization for binary
images.
* oln/core/internal/image_base.hh (operator|): Likewise.
Add a FIXME as a reminder.
oln/core/concept/generator.hh | 60 +++++++
oln/core/equipment.hh | 4
oln/core/gen/fun.hh | 22 ++
oln/core/gen/fun_ops.hh | 325 ++++++++++++++++++++++++++++++++++++++++
oln/core/gen/literal.hh | 158 +++++++++++++++++++
oln/core/gen/pw_value.hh | 80 ++++-----
oln/core/internal/image_base.hh | 17 ++
oln/level/fill.hh | 6
tests/core/Makefile.am | 20 +-
tests/core/image1d.cc | 24 +-
tests/core/pw_value.cc | 14 -
11 files changed, 653 insertions(+), 77 deletions(-)
Index: tests/core/image1d.cc
--- tests/core/image1d.cc (revision 900)
+++ tests/core/image1d.cc (working copy)
@@ -28,33 +28,33 @@
/// Test oln::image1d.
#include <cassert>
-// FIXME: We should not include oln/basics1d.hh, but
-// oln/core/1d/image1d.hh (and oln/core/1d/neigh1d.hh ?).
-#include <oln/basics1d.hh>
+#include <oln/core/1d/image1d.hh>
#include <oln/level/fill.hh>
int
main()
{
+ using namespace oln;
+
// Fill a 1D image using its iterator.
- oln::image1d<char> ima1(3);
- oln_vtype_(oln::image1d<char>, piter) p1(ima1.topo());
+ image1d<char> ima1(3);
+ image1d<char>::piter p1(ima1.points());
for_all(p1)
ima1(p1) = 1;
// Fill a 1D image using a classic loop.
- oln::image1d<int> ima2(ima1.topo());
+ image1d<int> ima2(ima1.points());
for (unsigned i = 0; i < 3; ++i)
- ima2(oln::point1d(i)) = 2;
+ ima2(i) = 2;
- // Fill a 1D image using the routine oln::level::fill.
- oln::image1d<long> ima3(ima1.topo());
- oln::level::fill(ima3, 3);
+ // Fill a 1D image using the routine level::fill.
+ image1d<long> ima3(ima1.points());
+ level::fill(ima3, 3);
// Add the three images.
- oln::image1d<long> sum(ima1.topo());
- oln_vtype_(oln::image1d<long>, piter) p(sum.topo());
+ image1d<long> sum(ima1.points());
+ image1d<long>::piter p(sum.points());
for_all(p)
sum(p) = ima1(p) + ima2(p) + ima3(p);
// And check the sum.
Index: tests/core/pw_value.cc
--- tests/core/pw_value.cc (revision 900)
+++ tests/core/pw_value.cc (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2006, 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
@@ -29,9 +29,9 @@
#include <cassert>
-#include <oln/basics2d.hh>
+#include <oln/core/2d/image2d.hh>
#include <oln/core/gen/pw_value.hh>
-
+#include <oln/debug/iota.hh>
int main()
@@ -39,12 +39,12 @@
using namespace oln;
point2d p(0,0);
- image2d<int> ima1(3,3);
- ima1(p) = 1;
+ image2d<double> ima1(3,3);
+ ima1(p) = 1.;
- image2d<float> ima2(3,3);
+ image2d<double> ima2(3,3);
ima2(p) = 2.3;
- double d = ((pw_value(ima1) + 4 * pw_value(ima2)) / .2)(p);
+ double d = ((pw_value(ima1) + pw_value(ima2) * literal(4.)) / literal(.2))(p);
assert(d > 50.9999 and d < 51.0001);
}
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 900)
+++ tests/core/Makefile.am (working copy)
@@ -19,31 +19,35 @@
check_PROGRAMS = \
- rle_image \
- sparse_image \
apply \
+ at \
dpoint2d \
- point2d \
grid \
+ image1d \
image2d \
neighb2d \
npoints \
+ point2d \
+ pw_value \
+ rle_image \
+ sparse_image \
subset \
- window2d \
- at
+ window2d
# Images and auxiliary structures.
dpoint2d_SOURCES = dpoint2d.cc
-point2d_SOURCES = point2d.cc
grid_SOURCES = grid.cc
+image1d_SOURCES = image1d.cc
image2d_SOURCES = image2d.cc
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
-subset_SOURCES = subset.cc
-window2d_SOURCES = window2d.cc
+point2d_SOURCES = point2d.cc
+pw_value_SOURCES = pw_value.cc
rle_image_SOURCES = rle_image.cc
sparse_image_SOURCES = sparse_image.cc
+subset_SOURCES = subset.cc
+window2d_SOURCES = window2d.cc
# Methods.
at_SOURCES = at.cc
Index: oln/level/fill.hh
--- oln/level/fill.hh (revision 900)
+++ oln/level/fill.hh (working copy)
@@ -54,7 +54,7 @@
void fill(Mutable_Image<I>& input, const V values[]);
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(const P&));
+ void fill(Mutable_Image<I>& input, V (*fun)(P));
@@ -100,7 +100,7 @@
}
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(const P&))
+ void fill(Mutable_Image<I>& input, V (*fun)(P))
{
oln_piter(I) p(input.points());
for_all(p)
@@ -134,7 +134,7 @@
}
template <typename I, typename V, typename P>
- void fill(Mutable_Image<I>& input, V (*fun)(const P&))
+ void fill(Mutable_Image<I>& input, V (*fun)(P))
{
impl::fill(exact(input), fun);
}
Index: oln/core/concept/generator.hh
--- oln/core/concept/generator.hh (revision 0)
+++ oln/core/concept/generator.hh (revision 0)
@@ -0,0 +1,60 @@
+// 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_GENERATOR_HH
+# define OLN_CORE_CONCEPT_GENERATOR_HH
+
+# include <oln/core/concept/function.hh>
+
+
+namespace oln
+{
+
+ // void -> Value.
+
+ template <typename Exact>
+ struct Generator : public Function<Exact>
+ {
+ protected:
+ Generator();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Generator<Exact>::Generator()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_GENERATOR_HH
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 900)
+++ oln/core/equipment.hh (working copy)
@@ -131,10 +131,14 @@
# define oln_qiter(T) oln_typename_shortcut__(T, qiter)
// r
+ stc_decl_associated_type( result );
stc_decl_associated_type( right );
stc_decl_associated_type( rvalue );
stc_decl_associated_type( rvaluep );
+# define oln_result(T) oln_typename_shortcut__(T, result)
+# define oln_rvalue(T) oln_typename_shortcut__(T, rvalue)
+
// s
stc_decl_associated_type( std_container );
stc_decl_associated_type( skeleton );
Index: oln/core/gen/pw_value.hh
--- oln/core/gen/pw_value.hh (revision 900)
+++ oln/core/gen/pw_value.hh (working copy)
@@ -1,4 +1,5 @@
-// Copyright (C) 2005, 2006 EPITA Research and Development Laboratory
+// Copyright (C) 2005, 2006, 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
@@ -28,79 +29,68 @@
#ifndef OLN_CORE_GEN_PW_VALUE_HH
# define OLN_CORE_GEN_PW_VALUE_HH
-# include <oln/core/abstract/image.hh>
-# include <xtd/abstract/meta_nary_fun.hh>
-# include <xtd/math.hh>
+# include <oln/core/concept/image.hh>
+# include <oln/core/gen/fun_ops.hh>
-
-namespace xtd
+namespace oln
{
- // Fwd decl.
- template <typename I>
- class pw_value_type;
-
-
- template <typename I, typename A>
- struct res_< pw_value_type<I>, A >
+ namespace ERROR
{
- typedef oln_rvalue(I) ret;
- };
+ template <typename I>
+ struct pw_value_works_on_images_not_on_;
+ } // end of namespace oln::ERROR
template <typename I>
- class pw_value_type : public xtd::abstract::meta_nary_fun_< 1, pw_value_type<I> >
+ class pw_value_ : public Function_p2v< pw_value_<I> >,
+ private mlc::assert_< mlc_is_a(I, Image),
+ ERROR::pw_value_works_on_images_not_on_<I> >
{
public:
+ typedef oln_point(I) argument; // FIXME: psite?
+ typedef oln_value(I) result;
- pw_value_type(const I& ima);
-
- template <typename P>
- oln_rvalue(I) impl_calc(const P& p) const;
+ pw_value_(const Point_Wise_Accessible_Image<I>& ima);
+ oln_value(I) operator()(const oln_point(I)& p) const;
protected:
-
- const I ima_;
+ const I& ima_;
};
+ template <typename I>
+ pw_value_<I>
+ pw_value(const Image<I>& ima);
+
+
# ifndef OLN_INCLUDE_ONLY
template <typename I>
- template <typename A>
- oln_rvalue(I)
- pw_value_type<I>::impl_calc(const A& a) const
- {
- mlc::assert_< mlc::or_< mlc_is_a(A, oln::abstract::point),
- mlc_is_a(A, oln::abstract::iterator_on_points) > >::check();
- return ima_(a);
+ pw_value_<I>::pw_value_(const Point_Wise_Accessible_Image<I>& ima)
+ : ima_(exact(ima))
+ {
}
template <typename I>
- pw_value_type<I>::pw_value_type(const I& ima)
- : ima_(ima)
+ oln_value(I)
+ pw_value_<I>::operator()(const oln_point(I)& p) const
{
+ precondition(this->ima_.owns_(p));
+ return this->ima_(p);
}
-# endif
-
-
-} // end of namespace xtd
-
-
-namespace oln
-{
-
template <typename I>
- xtd::m1expr_< xtd::pw_value_type<I>, xtd::arg_<1> >
- pw_value(const abstract::image<I>& ima)
+ pw_value_<I>
+ pw_value(const Point_Wise_Accessible_Image<I>& ima)
{
- xtd::pw_value_type<I> pwv(ima.exact());
- using xtd::_1;
- return pwv(_1); // expects one argument (for instance a point) or an expression :)
+ pw_value_<I> tmp(ima);
+ return tmp;
}
+# endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace oln
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 900)
+++ oln/core/gen/fun.hh (working copy)
@@ -30,7 +30,7 @@
# include <oln/core/internal/category_of.hh>
# include <oln/core/concept/function.hh>
-# include <oln/core/concept/point.hh>
+# include <oln/core/concept/image.hh>
# include <oln/core/concept/value.hh>
@@ -116,6 +116,25 @@
F f_;
};
+ // Specialization.
+ template <typename I>
+ struct fun_p2b_< Binary_Image<I> > : public Function_p2b< fun_p2b_< Binary_Image<I> > >
+ {
+ typedef const oln_point(I)& argument;
+ typedef oln_rvalue(I) result;
+
+ fun_p2b_(const Binary_Image<I>& ima)
+ : ima_(exact(ima))
+ {}
+
+ result operator()(argument arg) const
+ {
+ return this->ima_(arg);
+ }
+
+ private:
+ I ima_;
+ };
@@ -164,7 +183,6 @@
}
-
} // end of namespace oln
Index: oln/core/gen/literal.hh
--- oln/core/gen/literal.hh (revision 0)
+++ oln/core/gen/literal.hh (revision 0)
@@ -0,0 +1,158 @@
+// 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_LITERAL_HH
+# define OLN_CORE_GEN_LITERAL_HH
+
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/generator.hh>
+# include <oln/core/concept/point.hh>
+# include <oln/core/concept/value.hh>
+
+
+
+
+namespace oln
+{
+
+
+
+ // ----------------------------- literal_<T>
+
+
+ template <typename T>
+ struct literal_ : public Generator< literal_<T> >
+ {
+ typedef T result;
+
+ literal_(const T& val) : val_(val) {}
+
+ const result& operator()() const
+ {
+ return this->val_;
+ }
+
+ const result& value() const
+ {
+ return this->val_;
+ }
+
+ private:
+ T val_;
+ };
+
+
+ // literal
+ template <typename T>
+ literal_<T>
+ literal(const T& val)
+ {
+ literal_<T> tmp(val);
+ return tmp;
+ }
+
+
+ // ----------------------------- lit_p2v_<P,T>
+
+
+ // Fwd decl.
+ template <typename P, typename T> struct lit_p2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename P, typename T>
+ struct set_category_of_< lit_p2v_<P,T> >
+ {
+ typedef stc::is< Function_p2v > ret;
+ };
+ }
+
+ // Class.
+ template <typename P, typename T>
+ struct lit_p2v_ : public Function_p2v< lit_p2v_<P,T> >
+ {
+ typedef P argument;
+ typedef T result;
+
+ lit_p2v_(const T& val)
+ : val_(val)
+ {
+ }
+
+ result operator()(argument) const
+ {
+ return this->val_;
+ }
+
+ private:
+ T val_;
+ };
+
+
+ // ----------------------------- lit_p2b_<P,B>
+
+
+ // Fwd decl.
+ template <typename P, typename B> struct lit_p2b_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename P, typename B>
+ struct set_category_of_< lit_p2b_<P,B> >
+ {
+ typedef stc::is< Function_p2b > ret;
+ };
+ }
+
+ // Class.
+ template <typename P, typename B>
+ struct lit_p2b_ : public Function_p2b< lit_p2b_<P,B> >
+ {
+ typedef P argument;
+ typedef B result;
+
+ lit_p2b_(const B& val)
+ : val_(val)
+ {
+ }
+
+ result operator()(argument) const
+ {
+ return this->val_;
+ }
+
+ private:
+ B val_;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_LITERAL_HH
Index: oln/core/gen/fun_ops.hh
--- oln/core/gen/fun_ops.hh (revision 0)
+++ oln/core/gen/fun_ops.hh (revision 0)
@@ -0,0 +1,325 @@
+// 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_FUN_OPS_HH
+# define OLN_CORE_GEN_FUN_OPS_HH
+
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/point.hh>
+# include <oln/core/gen/literal.hh>
+
+
+
+# define oln_decl_p2v_cmp_(Name, Sym) \
+ \
+ template <typename L, typename R> struct p2v_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename L, typename R> \
+ struct set_category_of_< p2v_##Name##_<L,R> > \
+ { \
+ typedef stc::is< Function_p2b > ret; \
+ }; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct p2v_##Name##_ : public Function_p2b< p2v_##Name##_<L,R> > \
+ { \
+ typedef oln_arg_of_(L) argument; \
+ typedef bool result; /* FIXME: trait! */ \
+ \
+ p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ : left_(exact(left)), \
+ right_(exact(right)) \
+ { \
+ } \
+ bool operator()(argument arg) const \
+ { \
+ return this->left_(arg) Sym this->right_(arg); \
+ } \
+ private: \
+ L left_; \
+ R right_; \
+ }; \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L,R> \
+ operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ mlc::assert_equal_< oln_argument(L), oln_argument(R) >::check(); \
+ p2v_##Name##_<L,R> tmp(left, right); \
+ return tmp; \
+ } \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \
+ operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ lit_p2v_<oln_argument(L), R> right_(right.value()); \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+# define oln_decl_p2v_arith_(Name, Sym) \
+ \
+ template <typename L, typename R> struct p2v_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename L, typename R> \
+ struct set_category_of_< p2v_##Name##_<L,R> > \
+ { \
+ typedef stc::is< Function_p2v > ret; \
+ }; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<L,R> > \
+ { \
+ typedef oln_arg_of_(L) argument; \
+ typedef oln_res_of_(L) result; /* FIXME: trait! */ \
+ \
+ p2v_##Name##_(const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ : left_(exact(left)), \
+ right_(exact(right)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return this->left_(arg) Sym this->right_(arg); \
+ } \
+ private: \
+ L left_; \
+ R right_; \
+ }; \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L,R> \
+ operator Sym (const Function_p2v<L>& left, const Function_p2v<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ p2v_##Name##_<L,R> tmp(left, right); \
+ return tmp; \
+ } \
+ \
+ template <typename L, typename R> \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > \
+ operator Sym (const Function_p2v<L>& left, const literal_<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ lit_p2v_<oln_argument(L), R> right_(right.value()); \
+ p2v_##Name##_<L, lit_p2v_<oln_argument(L), R> > tmp(left, right_); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+# define oln_decl_p2v_un_(Name, Sym) \
+ \
+ template <typename T> struct p2v_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename T> \
+ struct set_category_of_< p2v_##Name##_<T> > \
+ { \
+ typedef stc::is< Function_p2v > ret; \
+ }; \
+ } \
+ \
+ template <typename T> \
+ struct p2v_##Name##_ : public Function_p2v< p2v_##Name##_<T> > \
+ { \
+ typedef oln_arg_of_(T) argument; \
+ typedef oln_res_of_(T) result; /* FIXME: trait! */ \
+ \
+ p2v_##Name##_(const Function_p2v<T>& oper) \
+ : oper_(exact(oper)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return Sym this->oper_(arg); \
+ } \
+ private: \
+ T oper_; \
+ }; \
+ \
+ template <typename T> \
+ p2v_##Name##_<T> \
+ operator Sym (const Function_p2v<T>& oper) \
+ { \
+ p2v_##Name##_<T> tmp(oper); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+# define oln_decl_p2b_bin_(Name, Sym) \
+ \
+ template <typename L, typename R> struct p2b_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename L, typename R> \
+ struct set_category_of_< p2b_##Name##_<L,R> > \
+ { \
+ typedef stc::is< Function_p2b > ret; \
+ }; \
+ } \
+ \
+ template <typename L, typename R> \
+ struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<L,R> > \
+ { \
+ typedef oln_arg_of_(L) argument; \
+ typedef oln_res_of_(L) result; \
+ \
+ p2b_##Name##_(const Function_p2b<L>& left, const Function_p2b<R>& right) \
+ : left_(exact(left)), \
+ right_(exact(right)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return this->left_(arg) Sym this->right_(arg); \
+ } \
+ private: \
+ L left_; \
+ R right_; \
+ }; \
+ \
+ template <typename L, typename R> \
+ p2b_##Name##_<L,R> \
+ operator Sym (const Function_p2b<L>& left, const Function_p2b<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ mlc::assert_< mlc_is_a(oln_argument(R), Point) >::check(); \
+ p2b_##Name##_<L,R> tmp(left, right); \
+ return tmp; \
+ } \
+ \
+ template <typename L, typename R> \
+ p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > \
+ operator Sym (const Function_p2b<L>& left, const literal_<R>& right) \
+ { \
+ mlc::assert_< mlc_is_a(oln_argument(L), Point) >::check(); \
+ lit_p2b_<oln_argument(L), R> right_(right.value()); \
+ p2b_##Name##_<L, lit_p2b_<oln_argument(L), R> > tmp(left, right_); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+
+# define oln_decl_p2b_un_(Name, Sym) \
+ \
+ template <typename T> struct p2b_##Name##_; \
+ \
+ namespace internal \
+ { \
+ template <typename T> \
+ struct set_category_of_< p2b_##Name##_<T> > \
+ { \
+ typedef stc::is< Function_p2b > ret; \
+ }; \
+ } \
+ \
+ template <typename T> \
+ struct p2b_##Name##_ : public Function_p2b< p2b_##Name##_<T> > \
+ { \
+ typedef oln_arg_of_(T) argument; \
+ typedef oln_res_of_(T) result; /* FIXME: trait! */ \
+ \
+ p2b_##Name##_(const Function_p2b<T>& oper) \
+ : oper_(exact(oper)) \
+ { \
+ } \
+ result operator()(argument arg) const \
+ { \
+ return Sym this->oper_(arg); \
+ } \
+ private: \
+ T oper_; \
+ }; \
+ \
+ template <typename T> \
+ p2b_##Name##_<T> \
+ operator Sym (const Function_p2b<T>& oper) \
+ { \
+ p2b_##Name##_<T> tmp(oper); \
+ return tmp; \
+ } \
+ \
+ struct e_n_d___w_i_t_h___s_e_m_i_c_o_l_u_m_n
+
+
+
+namespace oln
+{
+
+ oln_decl_p2v_cmp_( eq, = );
+ oln_decl_p2v_cmp_( not_eq, != );
+ oln_decl_p2v_cmp_( less, < );
+ oln_decl_p2v_cmp_( leq, <= );
+ oln_decl_p2v_cmp_( greater, > );
+ oln_decl_p2v_cmp_( geq, >= );
+
+ oln_decl_p2v_arith_( plus, + );
+ oln_decl_p2v_arith_( minus, - );
+ oln_decl_p2v_arith_( times, * );
+ oln_decl_p2v_arith_( div, / );
+ oln_decl_p2v_arith_( mod, % );
+
+ oln_decl_p2v_un_( uminus, - );
+
+ oln_decl_p2b_bin_( and, && );
+ oln_decl_p2b_bin_( or, || );
+ oln_decl_p2b_bin_( xor, ^ );
+ // FIXME: nand, nor, xnor?
+
+ oln_decl_p2b_un_( not, ! );
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_FUN_OPS_HH
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 900)
+++ oln/core/internal/image_base.hh (working copy)
@@ -504,6 +504,23 @@
return tmp;
}
+
+ // Specialization.
+
+ 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());
+ 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;
+ }
+
+
+ // FIXME: What about Mutable_Image so that "ima | something" can be left-value?
+
+
} // end of namespace oln
/// \}
1
0
Re: [Olena-patches] 881: New test for rle_class and sparse_image class.
by Thierry GERAUD 23 Mar '07
by Thierry GERAUD 23 Mar '07
23 Mar '07
Nicolas Ballas wrote:
>
> Index: ChangeLog
> from Nicolas Ballas <ballas(a)lrde.epita.fr>
>
> New test for rle_class and sparse_image class.
>
> * tests/core/sparse_image.cc: New.
> * tests/core/rle_image.cc: New.
> * tests/core/Makefile.am: Update
> ...
tests should be quiet
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Optimize the return of Image::points().
* oln/debug/iota.hh: Update.
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh: Add assertions; Fix include.
* oln/core/gen/niter_has.hh (pset_): Add &.
* oln/core/concept/image.hh (bbox, points, impl_points): Add &.
* oln/core/concept/image_identity.hh,
* oln/core/rle/rle_image.hh,
* oln/core/sparse/sparse_image.hh,
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh,
* oln/core/internal/op_image_restricted_to_pset.hh (impl_points):
Update.
* oln/basics1d.hh,
* oln/basics2d.hh: Remove; obsolete.
* oln/core/internal/utils.hh (pair, triplet): New specializations.
* oln/core/1d/array1d.hh,
* oln/core/2d/array2d.hh: Add method decls without impl.
* oln/core/1d/image1d.hh,
* oln/core/1d/image1d_b.hh,
* oln/core/2d/image2d.hh,
* oln/core/2d/image2d_b.hh: Make use of pair and triplet.
core/1d/array1d.hh | 7 +
core/1d/image1d.hh | 35 ++++-----
core/1d/image1d_b.hh | 20 ++---
core/2d/array2d.hh | 8 ++
core/2d/image2d.hh | 49 +++++++-----
core/2d/image2d_b.hh | 104 ++++++++++-----------------
core/concept/image.hh | 9 +-
core/concept/image_identity.hh | 4 -
core/gen/niter_has.hh | 2
core/internal/op_image_restricted_to_pset.hh | 4 -
core/internal/utils.hh | 75 +++++++++++++++++--
core/rle/rle_image.hh | 17 ++--
core/sparse/sparse_image.hh | 25 ++++--
debug/iota.hh | 4 -
14 files changed, 216 insertions(+), 147 deletions(-)
Index: oln/debug/iota.hh
--- oln/debug/iota.hh (revision 899)
+++ oln/debug/iota.hh (working copy)
@@ -41,8 +41,8 @@
template <typename I>
void iota(Mutable_Image<I>& in_out)
{
- typename I::value v = 0;
- typename I::fwd_piter p(in_out.points());
+ oln_value(I) v = 0;
+ oln_fwd_piter(I) p(in_out.points());
for_all(p)
in_out(p) = v++;
}
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 899)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -26,12 +26,10 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_IMAGE_HH
-# define OLN_CORE_RLE_RLE_IMAGE_HH
+#ifndef OLN_CORE_GEN_RLE_IMAGE_HH
+# define OLN_CORE_GEN_RLE_IMAGE_HH
# include <map>
-# include <utility>
-
# include <oln/core/internal/image_base.hh>
# include <oln/core/rle/rle_psite.hh>
@@ -97,7 +95,7 @@
rle_image();
/// pset impl_points() const : return image pset
- pset impl_points() const;
+ const pset& impl_points() const;
/// bool impl_owns_(const psite& p) const : same has impl_has
bool impl_owns_(const psite& p) const;
/// void insert(const point& p, unsigned len, value val) : insert a new range on the image
@@ -118,9 +116,10 @@
}
template <typename P, typename T>
- typename rle_image<P, T>::pset
+ const typename rle_image<P, T>::pset&
rle_image<P, T>::impl_points() const
{
+ assert(this->has_data());
return this->data_->first;
}
@@ -128,6 +127,7 @@
bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const
{
+ assert(this->has_data());
return this->data_->first.has(p.start_);
}
@@ -136,6 +136,7 @@
rle_image<P, T>::insert(const typename rle_image<P, T>::point& p,
unsigned len, rle_image<P, T>::value val)
{
+ assert(this->has_data());
this->data_->first.insert(p, len);
this->data_->second[p] = val;
}
@@ -144,6 +145,7 @@
typename rle_image<P, T>::rvalue
rle_image<P, T>::impl_read(const rle_image<P, T>::psite& ps) const
{
+ assert(this->has_data());
typename std::map<point, value>::const_iterator irun;
irun = this->data_->second.find(ps.start_);
@@ -156,6 +158,7 @@
typename rle_image<P, T>::lvalue
rle_image<P, T>::impl_read_write(const rle_image<P, T>::psite& ps)
{
+ assert(this->has_data());
typename std::map<point, value>::iterator irun;
irun = this->data_->second.find(ps.start_);
@@ -168,4 +171,4 @@
} // end of namespace oln
-#endif // !OLN_CORE_RLE_RLE_IMAGE_HH
+#endif // ! OLN_CORE_GEN_RLE_IMAGE_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 899)
+++ oln/core/concept/image.hh (working copy)
@@ -134,10 +134,10 @@
bool owns_(const psite& p) const;
rvalue operator()(const psite& p) const;
- pset points() const;
+ const pset& points() const;
// With final impl:
- box bbox() const;
+ const box& bbox() const;
protected:
Image();
@@ -438,14 +438,14 @@
}
template <typename Exact>
- typename Image<Exact>::box
+ const typename Image<Exact>::box&
Image<Exact>::bbox() const
{
return this->points().bbox(); // Final impl.
}
template <typename Exact>
- typename Image<Exact>::pset
+ const typename Image<Exact>::pset&
Image<Exact>::points() const
{
return exact(this)->impl_points();
@@ -512,7 +512,6 @@
bool
Point_Wise_Accessible_Image<Exact>::has(const typename Point_Wise_Accessible_Image<Exact>::point& p) const
{
- // FIXME: precondition(this->owns_(p)); ?
return this->points().has(p);
}
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 899)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -54,7 +54,7 @@
bool impl_owns_(const psite& p) const;
rvalue impl_read(const psite& p) const;
- pset impl_points() const;
+ const pset& impl_points() const;
};
@@ -192,7 +192,7 @@
}
template <typename Exact>
- typename set_impl< Image, behavior::identity, Exact >::pset
+ const typename set_impl< Image, behavior::identity, Exact >::pset&
set_impl< Image, behavior::identity, Exact >::impl_points() const
{
return exact(this)->image().points();
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 899)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -25,10 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SPARSE_IMAGE_HH_
-# define SPARSE_IMAGE_HH_
+#ifndef OLN_CORE_GEN_SPARSE_IMAGE_HH
+# define OLN_CORE_GEN_SPARSE_IMAGE_HH
# include <vector>
+# include <map>
+
+# include <oln/core/internal/image_base.hh>
+
+
namespace oln
{
@@ -82,7 +87,7 @@
sparse_image();
- pset impl_points() const;
+ const pset& impl_points() const;
bool impl_owns_(const psite& p) const;
void insert(const point& p, unsigned len, const std::vector<value>& val);
rvalue impl_read(const psite& p) const;
@@ -90,8 +95,8 @@
};
-# ifndef OLN_INCLUDE_ONLY
+# ifndef OLN_INCLUDE_ONLY
template <typename P, typename T>
sparse_image<P, T>::sparse_image()
@@ -100,9 +105,10 @@
}
template <typename P, typename T>
- typename sparse_image<P, T>::pset
+ const typename sparse_image<P, T>::pset&
sparse_image<P, T>::impl_points() const
{
+ assert(this->has_data());
return this->data_->first;
}
@@ -110,6 +116,7 @@
bool
sparse_image<P, T>::impl_owns_(const typename sparse_image<P, T>::psite& p) const
{
+ assert(this->has_data());
return this->data_->first.has(p.start_);
}
@@ -117,6 +124,7 @@
void
sparse_image<P, T>::insert(const point& p, unsigned len, const std::vector<typename sparse_image<P, T>::value>& val)
{
+ assert(this->has_data());
this->data_->first.insert(p, len);
this->data_->second[p] = val;
}
@@ -125,6 +133,7 @@
typename sparse_image<P, T>::rvalue
sparse_image<P, T>::impl_read(const sparse_image<P, T>::psite& ps) const
{
+ assert(this->has_data());
typename std::map<point, std::vector<value> >::const_iterator irun;
irun.operator= (this->data_->second.find(ps.start_));
@@ -136,6 +145,7 @@
typename sparse_image<P, T>::lvalue
sparse_image<P, T>::impl_read_write(const sparse_image<P, T>::psite& ps)
{
+ assert(this->has_data());
typename std::map<point, std::vector<value> >::iterator irun;
irun.operator= (this->data_->second.find(ps.start_));
@@ -143,10 +153,9 @@
return irun->second[ps.index_];
}
-
-# endif /* !OLN_INCLUDE_ONLY */
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
-#endif /* !SPARSE_IMAGE_HH_ */
+#endif // ! OLN_CORE_GEN_SPARSE_IMAGE_HH
Index: oln/core/1d/array1d.hh
--- oln/core/1d/array1d.hh (revision 899)
+++ oln/core/1d/array1d.hh (working copy)
@@ -43,6 +43,13 @@
{
public:
+ // Not impled.
+ array1d_();
+ array1d_(const array1d_<T,C>& rhs);
+ void operator=(const array1d_<T,C>&);
+ // end of Not impled.
+
+
/// Ctor.
array1d_(C imin, C imax);
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 899)
+++ oln/core/1d/image1d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_1D_IMAGE1D_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/1d/array1d.hh>
# include <oln/core/1d/box1d.hh>
@@ -41,7 +42,7 @@
template <typename T> class image1d;
- /// Virtual types.
+ // Virtual types.
template <typename T>
struct vtypes< image1d<T> >
{
@@ -55,14 +56,14 @@
typedef T& lvalue;
typedef box1d pset;
- typedef array1d_<value, coord> data;
+ typedef internal::pair< array1d_<value, coord>*, box1d > data;
typedef image1d<T> plain;
typedef image1d<pl::value> skeleton;
};
- /// Super type.
+ // Super type.
template <typename T>
struct super_trait_< image1d<T> >
{
@@ -78,6 +79,7 @@
{
typedef image1d<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array1d_<T, int> array_t;
public:
stc_using(data);
@@ -95,7 +97,7 @@
std::size_t impl_npoints() const;
- box1d impl_points() const;
+ const box1d& impl_points() const;
};
@@ -110,28 +112,30 @@
template <typename T>
image1d<T>::image1d(const box1d& b)
{
- this->data_ = new data(b.pmin().ind(), b.pmax().ind());
+ this->data_ = new data(new array_t(b.pmin().ind(), b.pmax().ind()),
+ b);
}
template <typename T>
image1d<T>::image1d(unsigned n)
{
precondition(n != 0);
- this->data_ = new data(0, n - 1);
+ this->data_ = new data(new array_t(0, n - 1),
+ box1d(0, n - 1));
}
template <typename T>
bool image1d<T>::impl_owns_(const point1d& p) const
{
assert(this->has_data());
- return this->data_->has(p.ind());
+ return this->data_->first.has(p.ind());
}
template <typename T>
const T& image1d<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
- return this->data_->operator()(p.ind());
+ return this->data_->first.operator()(p.ind());
}
template <typename T>
@@ -139,14 +143,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first.operator[](i);
}
template <typename T>
T& image1d<T>::impl_read_write(const point1d& p)
{
assert(this->has_data());
- return this->data_->operator()(p.ind());
+ return this->data_->first.operator()(p.ind());
}
template <typename T>
@@ -154,7 +158,7 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first.operator[](i);
}
template <typename T>
@@ -162,18 +166,17 @@
{
// faster than the default code given by primitive_image_
assert(this->has_data());
- return this->data_->ncells();
+ return this->data_->first.ncells();
}
template <typename T>
- box1d image1d<T>::impl_points() const
+ const box1d& image1d<T>::impl_points() const
{
assert(this->has_data());
- box1d b(this->data_->imin(), this->data_->imax());
- return b;
+ return this->data_->second;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 899)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -46,7 +46,7 @@
template <typename T> class image1d_b;
- /// Virtual types.
+ // Virtual types.
template <typename T>
struct vtypes< image1d_b<T> >
{
@@ -60,9 +60,9 @@
typedef T& lvalue;
typedef box1d pset;
- typedef internal::triplet< array1d_<T, int>,
+ typedef internal::triplet< array1d_<T, int>*,
unsigned,
- box_<point1d> > data;
+ box1d > data;
typedef mlc::true_ vborder;
@@ -71,7 +71,7 @@
};
- /// Super type.
+ // Super type.
template <typename T>
struct super_trait_< image1d_b<T> >
{
@@ -80,7 +80,7 @@
};
- /// General 1D image class.
+ /// General 1D image class with an external virtual border.
template <typename T>
class image1d_b : public internal::plain_primitive_image_< image1d_b<T> >
@@ -105,7 +105,7 @@
std::size_t impl_npoints() const;
- box1d impl_points() const;
+ const box1d& impl_points() const;
unsigned impl_border() const;
};
@@ -122,7 +122,7 @@
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned border)
{
- this->data_ = new data(array_t(b.pmin().ind() - border,
+ this->data_ = new data(new array_t(b.pmin().ind() - border,
b.pmax().ind() + border),
border,
b);
@@ -132,7 +132,7 @@
image1d_b<T>::image1d_b(unsigned n, unsigned border)
{
precondition(n != 0);
- this->data_ = new data(array_t(- border,
+ this->data_ = new data(new array_t(- border,
n - 1 + border),
border,
box1d(0, n - 1));
@@ -176,7 +176,7 @@
}
template <typename T>
- box1d image1d_b<T>::impl_points() const
+ const box1d& image1d_b<T>::impl_points() const
{
assert(this->has_data());
return this->data_->third;
@@ -189,7 +189,7 @@
return this->data_->second;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 899)
+++ oln/core/2d/array2d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_ARRAY2D_HH
# include <cstddef>
+# include <iostream>
# include <mlc/contract.hh>
@@ -43,6 +44,13 @@
{
public:
+ // Not impled.
+ array2d_();
+ array2d_(const array2d_<T,C>& rhs);
+ void operator=(const array2d_<T,C>&);
+ // end of Not impled.
+
+
/// Ctor.
array2d_(C imin, C jmin, C imax, C jmax);
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 899)
+++ oln/core/2d/image2d.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_IMAGE2D_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
@@ -55,7 +56,7 @@
typedef T& lvalue;
typedef box2d pset;
- typedef array2d_<value, coord> data;
+ typedef internal::pair< array2d_<value, coord>*, box2d > data;
typedef image2d<T> plain;
typedef image2d<pl::value> skeleton;
@@ -78,6 +79,7 @@
{
typedef image2d<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array2d_<T, int> array_t;
public:
stc_using(data);
@@ -99,7 +101,7 @@
std::size_t impl_npoints() const;
- box2d impl_points() const;
+ const box2d& impl_points() const;
};
template <typename T, typename D>
@@ -116,36 +118,40 @@
template <typename T>
image2d<T>::image2d(const box2d& b)
{
- this->data_ = new data(b.pmin().row(), b.pmin().col(),
- b.pmax().row(), b.pmax().col());
+ this->data_ = new data(new array_t(b.pmin().row(), b.pmin().col(),
+ b.pmax().row(), b.pmax().col()),
+ b);
}
template <typename T>
image2d<T>::image2d(unsigned nrows, unsigned ncols)
{
precondition(nrows != 0 and ncols != 0);
- this->data_ = new data(0, 0, nrows - 1, ncols - 1);
+ this->data_ = new data(new array_t(0, 0,
+ nrows - 1, ncols - 1),
+ box2d(point2d(0, 0),
+ point2d(nrows - 1, ncols - 1)));
}
template <typename T>
bool image2d<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
- return this->data_->has(p.row(), p.col());
+ return this->data_->first.has(p.row(), p.col());
}
template <typename T>
bool image2d<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->has(row, col);
+ return this->data_->first.has(row, col);
}
template <typename T>
const T& image2d<T>::impl_read(const point2d& p) const
{
assert(this->has_data());
- return this->data_->operator()(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -153,21 +159,21 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first[i];
}
template <typename T>
const T& image2d<T>::impl_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->operator()(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
T& image2d<T>::impl_read_write(const point2d& p)
{
assert(this->has_data());
- return this->data_->operator()(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -175,14 +181,14 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->operator[](i);
+ return this->data_->first[i];
}
template <typename T>
T& image2d<T>::impl_at(int row, int col)
{
assert(this->has_data());
- return this->data_->operator()(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
@@ -190,18 +196,14 @@
{
// faster than the default code given by primitive_image_
assert(this->has_data());
- return this->data_->ncells();
+ return this->data_->first.ncells();
}
template <typename T>
- box2d image2d<T>::impl_points() const
+ const box2d& image2d<T>::impl_points() const
{
assert(this->has_data());
- point2d
- pmin(this->data_->imin(), this->data_->jmin()),
- pmax(this->data_->imax(), this->data_->jmax());
- box2d b(pmin, pmax);
- return b;
+ return this->data_->second;
}
template <typename T, typename D>
@@ -211,8 +213,11 @@
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
- target.data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(),
- b.pmax().row(), b.pmax().col());
+ array2d_<T,int> ptr = new array2d_<T,int>(b.pmin().row(),
+ b.pmin().col(),
+ b.pmax().row(),
+ b.pmax().col());
+ target.data__() = new typename image2d<T>::data(ptr, b);
return box_ok;
}
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 899)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -30,6 +30,7 @@
# define OLN_CORE_2D_IMAGE2D_B_HH
# include <oln/core/internal/image_base.hh>
+# include <oln/core/internal/utils.hh>
# include <oln/core/2d/array2d.hh>
# include <oln/core/2d/box2d.hh>
@@ -38,49 +39,6 @@
{
- // FIXME: Move it!
-
- namespace internal
- {
-
-
- template <typename P, typename T>
- struct f_point_value_to_array_;
-
- template <typename T>
- struct f_point_value_to_array_< point2d, T >
- {
- typedef array2d_<T, int> ret;
- };
-
-
- template <typename P, typename T>
- struct array_b_
- {
- typedef typename f_point_value_to_array_<P, T>::ret array_t;
- typedef typename P::coord coord;
-
- array_b_(const P& pmin, const P& pmax, unsigned border)
- : array(pmin.row() - border, pmin.col() - border,
- pmax.row() + border, pmax.col() + border),
- border(border),
- box(pmin, pmax)
- {
- }
-
- array_t array;
- unsigned border;
- box_<P> box;
- };
-
-
- } // end of namespace oln::internal
-
-
- // end of FIXME
-
-
-
// Fwd decl.
template <typename T> class image2d_b;
@@ -99,14 +57,14 @@
typedef T& lvalue;
typedef box2d pset;
- typedef internal::array_b_<point2d, T> data;
+ typedef internal::triplet< array2d_<T, int>*,
+ unsigned,
+ box2d > data;
typedef mlc::true_ vborder;
typedef image2d_b<T> plain;
typedef image2d_b<pl::value> skeleton;
-
- // FIXME: wrong qiter!!!
};
@@ -126,6 +84,7 @@
{
typedef image2d_b<T> current;
typedef internal::plain_primitive_image_<current> super;
+ typedef array2d_<T, int> array_t;
public:
stc_using(data);
@@ -147,7 +106,7 @@
std::size_t impl_npoints() const;
- box2d impl_points() const;
+ const box2d& impl_points() const;
unsigned impl_border() const;
std::size_t pad(const dpoint2d& dp) const;
@@ -156,6 +115,10 @@
// template <typename T, typename D>
// bool init_(image2d_b<T>* this_, const D& dat);
+ template <typename T, typename D>
+ bool prepare(image2d_b<T>& target, with_t, const D& dat);
+
+
# ifndef OLN_INCLUDE_ONLY
@@ -167,37 +130,46 @@
template <typename T>
image2d_b<T>::image2d_b(const box2d& b, unsigned border)
{
- this->data_ = new data(b.pmin(), b.pmax(), border);
+ this->data_ = new data(new array_t(b.pmin().row() - border,
+ b.pmin().col() - border,
+ b.pmax().row() + border,
+ b.pmax().col() + border),
+ border,
+ b);
}
template <typename T>
image2d_b<T>::image2d_b(unsigned nrows, unsigned ncols, unsigned border)
{
precondition(nrows != 0 and ncols != 0);
- this->data_ = new data(point2d(0, 0),
- point2d(nrows - 1, ncols - 1),
- border);
+ this->data_ = new data(new array_t(- border,
+ - border,
+ nrows - 1 + border,
+ ncols - 1 + border),
+ border,
+ box2d(point2d(0, 0),
+ point2d(nrows - 1, ncols - 1)));
}
template <typename T>
bool image2d_b<T>::impl_owns_(const point2d& p) const
{
assert(this->has_data());
- return this->data_->array.has(p.row(), p.col());
+ return this->data_->first.has(p.row(), p.col());
}
template <typename T>
bool image2d_b<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->array.has(row, col);
+ return this->data_->first.has(row, col);
}
template <typename T>
const T& image2d_b<T>::impl_read(const point2d& p) const
{
assert(this->has_data());
- return this->data_->array(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -205,21 +177,21 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->array[i];
+ return this->data_->first[i];
}
template <typename T>
const T& image2d_b<T>::impl_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->array(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
T& image2d_b<T>::impl_read_write(const point2d& p)
{
assert(this->has_data());
- return this->data_->array(p.row(), p.col());
+ return this->data_->first(p.row(), p.col());
}
template <typename T>
@@ -227,35 +199,35 @@
{
assert(this->has_data());
assert(i < this->npoints());
- return this->data_->array[i];
+ return this->data_->first[i];
}
template <typename T>
T& image2d_b<T>::impl_at(int row, int col)
{
assert(this->has_data());
- return this->data_->array(row, col);
+ return this->data_->first(row, col);
}
template <typename T>
- box2d image2d_b<T>::impl_points() const
+ const box2d& image2d_b<T>::impl_points() const
{
assert(this->has_data());
- return this->data_->box;
+ return this->data_->third;
}
template <typename T>
unsigned image2d_b<T>::impl_border() const
{
assert(this->has_data());
- return this->data_->border;
+ return this->data_->second;
}
template <typename T>
std::size_t image2d_b<T>::pad(const dpoint2d& dp) const
{
assert(this->has_data());
- return this->data_->array.row_pad() * dp.row() + dp.col();
+ return this->data_->first.row_pad() * dp.row() + dp.col();
}
// template <typename T, typename D>
@@ -278,7 +250,11 @@
bool box_ok = init(b, with, dat);
postcondition(box_ok);
unsigned border = 2; // FIXME: Use init!
- target.data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), 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);
+ target.data__() = new typename image2d_b<T>::data(ptr, border, b);
return box_ok;
}
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 899)
+++ oln/core/gen/niter_has.hh (working copy)
@@ -78,7 +78,7 @@
protected:
- const Ps pset_;
+ const Ps& pset_;
}; // end of class oln::niter_has_<P>
Index: oln/core/internal/utils.hh
--- oln/core/internal/utils.hh (revision 899)
+++ oln/core/internal/utils.hh (working copy)
@@ -28,6 +28,8 @@
#ifndef OLN_CORE_INTERNAL_UTILS_HH
# define OLN_CORE_INTERNAL_UTILS_HH
+# include <mlc/contract.hh>
+
namespace oln
{
@@ -36,10 +38,6 @@
{
- // FIXME: Rename attributes as first / second / third / fourth?
-
-
-
/// Simple singleton class.
template <typename T>
@@ -47,12 +45,15 @@
{
singleton()
{}
- singleton(T value)
+ singleton(const T& value)
: value(value)
{}
T value;
};
+ template <typename T>
+ struct singleton< T* >;
+
/// Simple pair class.
@@ -61,7 +62,7 @@
{
pair()
{}
- pair(T1 first, T2 second)
+ pair(const T1& first, const T2& second)
: first(first),
second(second)
{}
@@ -69,6 +70,37 @@
T2 second;
};
+ template <typename T1, typename 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, const T2& second)
+ : first(*p_first),
+ second(second)
+ {
+ precondition(p_first != 0);
+ }
+ T1& first;
+ T2 second;
+ ~pair()
+ {
+ delete &first;
+ }
+ };
+
+ template <typename T1, typename T2>
+ struct pair< T1, T2* >;
+
+ template <typename T1, typename T2>
+ struct pair< T1*, T2* >;
+
/// Simple triplet class.
@@ -77,7 +109,7 @@
{
triplet()
{}
- triplet(T1 first, T2 second, T3 third)
+ triplet(const T1& first, const T2& second, const T3& third)
: first(first),
second(second),
third(third)
@@ -87,6 +119,33 @@
T3 third;
};
+ template <typename T1, typename T2, typename T3>
+ struct triplet< T1*, T2, T3 >
+ {
+ typedef triplet<T1*,T2,T3> self_t;
+
+ // Not impled.
+ triplet();
+ triplet(const self_t&);
+ void operator=(const self_t&);
+ // end of Not impled.
+
+ triplet(T1* p_first, const T2& second, const T3& third)
+ : first(*p_first),
+ second(second),
+ third(third)
+ {
+ precondition(p_first != 0);
+ }
+ T1& first;
+ T2 second;
+ T3 third;
+ ~triplet()
+ {
+ delete &first;
+ }
+ };
+
/// Simple quartet class.
@@ -95,7 +154,7 @@
{
quartet()
{}
- quartet(T1 first, T2 second, T3 third, T4 fourth)
+ quartet(const T1& first, const T2& second, const T3& third, const T4& fourth)
: first(first),
second(second),
third(third),
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 899)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -85,7 +85,7 @@
delegatee& impl_image();
const delegatee& impl_image() const;
- pset impl_points() const;
+ const pset& impl_points() const;
protected:
special_op_();
@@ -149,7 +149,7 @@
}
template <typename I, typename S>
- typename current::pset
+ const typename current::pset&
current::impl_points() const
{
assert(this->has_data());
1
0