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
899: Add type of 'image such_as f:b->p' and factor Image::has as final.
by Thierry Geraud 22 Mar '07
by Thierry Geraud 22 Mar '07
22 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add type of 'image such_as f:b->p' and factor Image::has as final.
* tests/core/neighb2d.cc: Fix.
* oln/core/internal/op_image_such_as_fp2b.hh: New.
* oln/core/gen/pset_such_as.hh: Remove; obsolete.
* oln/core/concept/image.hh (has): New final impl.
(Point_Wise_Accessible_Image): Remove get_impl inheritance.
* oln/core/concept/image_identity.hh: Update.
* 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/gen/single_value_image.hh (impl_has): Remove.
* oln/core/internal/op_pset_such_as_fp2b.hh (point): New vtype.
(point): Remove this vtype from iterators.
* oln/core/internal/point_set_base.hh: Cosmetic.
* oln/core/internal/op_image_restricted_to_pset.hh: Cosmetic.
* oln/core/internal/image_base.hh (oln_decl_op_such_as): New version
for "Image such_as Function_p2b".
(operator |): New specialization for C functions.
oln/core/1d/image1d.hh | 9 -
oln/core/1d/image1d_b.hh | 9 -
oln/core/2d/image2d.hh | 8 -
oln/core/2d/image2d_b.hh | 10 --
oln/core/concept/image.hh | 7 -
oln/core/concept/image_identity.hh | 20 ----
oln/core/gen/single_value_image.hh | 9 -
oln/core/internal/image_base.hh | 22 ++++
oln/core/internal/op_image_restricted_to_pset.hh | 11 --
oln/core/internal/op_image_such_as_fp2b.hh | 114 +++++++++++++++++++++++
oln/core/internal/op_pset_such_as_fp2b.hh | 11 +-
oln/core/internal/point_set_base.hh | 3
oln/core/rle/rle_image.hh | 9 -
oln/core/sparse/sparse_image.hh | 8 -
tests/core/neighb2d.cc | 2
15 files changed, 151 insertions(+), 101 deletions(-)
Index: tests/core/neighb2d.cc
--- tests/core/neighb2d.cc (revision 898)
+++ tests/core/neighb2d.cc (working copy)
@@ -38,7 +38,7 @@
unsigned run(const oln::Image_with_Nbh<I>& input)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input.nbhood());
+ oln_niter(I) n(p, input);
unsigned count = 0;
for_all(p)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 898)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -98,8 +98,6 @@
/// pset impl_points() const : return image pset
pset impl_points() const;
- /// bool impl_has(const point& p) const : rle_image has p?
- bool impl_has(const point& p) 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
@@ -128,13 +126,6 @@
template <typename P, typename T>
bool
- rle_image<P, T>::impl_has(const typename rle_image<P, T>::point& p) const
- {
- return this->data_->first.has(p);
- }
-
- template <typename P, typename T>
- bool
rle_image<P, T>::impl_owns_(const typename rle_image<P, T>::psite& p) const
{
return this->data_->first.has(p.start_);
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 898)
+++ oln/core/concept/image.hh (working copy)
@@ -217,11 +217,11 @@
/// Concept-class "Point_Wise_Accessible_Image".
template <typename Exact>
- struct Point_Wise_Accessible_Image : public virtual Image<Exact>,
- public automatic::get_impl<Point_Wise_Accessible_Image, Exact>
+ struct Point_Wise_Accessible_Image : public virtual Image<Exact>
{
stc_using_from(Image, point);
+ // final
bool has(const point& p) const;
protected:
@@ -512,7 +512,8 @@
bool
Point_Wise_Accessible_Image<Exact>::has(const typename Point_Wise_Accessible_Image<Exact>::point& p) const
{
- return exact(this)->impl_has(p);
+ // FIXME: precondition(this->owns_(p)); ?
+ return this->points().has(p);
}
template <typename Exact>
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 898)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -104,16 +104,6 @@
};
- /// Concept-class "Point_Wise_Accessible_Image".
-
- template <typename Exact>
- struct set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact > : public virtual Any<Exact>
- {
- stc_typename(point);
- bool impl_has(const point& p) const;
- };
-
-
/// Concept-class "Value_Wise_Accessible_Image".
template <typename Exact>
@@ -270,16 +260,6 @@
}
- /// Concept-class "Point_Wise_Accessible_Image".
-
- template <typename Exact>
- bool
- set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact >::impl_has(const typename set_impl< Point_Wise_Accessible_Image, behavior::identity, Exact >::point& p) const
- {
- return exact(this)->image().has(p);
- }
-
-
/// Concept-class "Value_Wise_Accessible_Image".
template <typename Exact>
Index: oln/core/sparse/sparse_image.hh
--- oln/core/sparse/sparse_image.hh (revision 898)
+++ oln/core/sparse/sparse_image.hh (working copy)
@@ -83,7 +83,6 @@
sparse_image();
pset impl_points() const;
- bool impl_has(const point& p) 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;
@@ -109,13 +108,6 @@
template <typename P, typename T>
bool
- sparse_image<P, T>::impl_has(const typename sparse_image<P, T>::point& p) const
- {
- return this->data_->first.has(p);
- }
-
- template <typename P, typename T>
- bool
sparse_image<P, T>::impl_owns_(const typename sparse_image<P, T>::psite& p) const
{
return this->data_->first.has(p.start_);
Index: oln/core/1d/image1d.hh
--- oln/core/1d/image1d.hh (revision 898)
+++ oln/core/1d/image1d.hh (working copy)
@@ -87,8 +87,6 @@
bool impl_owns_(const point1d& p) const;
- bool impl_has(const point1d& p) const;
-
const T& impl_read(const point1d& p) const;
const T& impl_index_read(unsigned i) const;
@@ -130,13 +128,6 @@
}
template <typename T>
- bool image1d<T>::impl_has(const point1d& p) const
- {
- assert(this->has_data());
- return this->data_->has(p.ind());
- }
-
- template <typename T>
const T& image1d<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 898)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -97,8 +97,6 @@
bool impl_owns_(const point1d& p) const;
- bool impl_has(const point1d& p) const;
-
const T& impl_read(const point1d& p) const;
const T& impl_index_read(unsigned i) const;
@@ -148,13 +146,6 @@
}
template <typename T>
- bool image1d_b<T>::impl_has(const point1d& p) const
- {
- assert(this->has_data());
- return this->data_->third.has(p);
- }
-
- template <typename T>
const T& image1d_b<T>::impl_read(const point1d& p) const
{
assert(this->has_data());
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 898)
+++ oln/core/2d/image2d.hh (working copy)
@@ -87,7 +87,6 @@
bool impl_owns_(const point2d& p) const;
- bool impl_has(const point2d& p) const;
bool impl_has_at(int row, int col) const;
const T& impl_read(const point2d& p) const;
@@ -136,13 +135,6 @@
}
template <typename T>
- bool image2d<T>::impl_has(const point2d& p) const
- {
- assert(this->has_data());
- return this->data_->has(p.row(), p.col());
- }
-
- template <typename T>
bool image2d<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 898)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -135,7 +135,6 @@
bool impl_owns_(const point2d& p) const;
- bool impl_has(const point2d& p) const;
bool impl_has_at(int row, int col) const;
const T& impl_read(const point2d& p) const;
@@ -188,17 +187,10 @@
}
template <typename T>
- bool image2d_b<T>::impl_has(const point2d& p) const
- {
- assert(this->has_data());
- return this->data_->box.has(p);
- }
-
- template <typename T>
bool image2d_b<T>::impl_has_at(int row, int col) const
{
assert(this->has_data());
- return this->data_->box.has(point2d(row, col));
+ return this->data_->array.has(row, col);
}
template <typename T>
Index: oln/core/gen/single_value_image.hh
--- oln/core/gen/single_value_image.hh (revision 898)
+++ oln/core/gen/single_value_image.hh (working copy)
@@ -89,7 +89,6 @@
single_value_image(const Ps& ps, const T& val);
bool impl_owns_(const point& p) const;
- bool impl_has (const point& p) const;
rvalue impl_read(const point&) const;
@@ -124,14 +123,6 @@
}
template <typename Ps, typename T>
- bool
- single_value_image<Ps, T>::impl_has(const typename single_value_image<Ps, T>::point& p) const
- {
- assert(this->has_data());
- return this->data_->first.has(p);
- }
-
- template <typename Ps, typename T>
typename single_value_image<Ps, T>::rvalue
single_value_image<Ps, T>::impl_read(const typename single_value_image<Ps, T>::point&) const
{
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 898)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy)
@@ -42,7 +42,7 @@
special_op_< stc::is<Point_Set>, S, such_as, stc::is<Function_p2b>, F >
- /// Fwd decls.
+ // Fwd decls.
namespace internal
{
template <typename S, typename F> class current;
@@ -52,7 +52,7 @@
- /// Super type.
+ // Super type.
template <typename S, typename F>
struct super_trait_< internal::current >
{
@@ -60,10 +60,11 @@
};
- /// Virtual types.
+ // Virtual types.
template <typename S, typename F>
struct vtypes< internal::current >
{
+ typedef oln_point(S) point;
typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter;
typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter;
};
@@ -72,7 +73,7 @@
namespace internal
{
- /// Implementation class the result of "Point_Set S | Function_p2b F".
+ /// Implementation class for the result of "Point_Set S | Function_p2b F".
template <typename S, typename F>
class current
@@ -197,7 +198,6 @@
template <typename S, typename F>
struct vtypes< current >
{
- typedef typename S::point point;
typedef typename S::fwd_piter adapted;
};
@@ -274,7 +274,6 @@
template <typename S, typename F>
struct vtypes< current >
{
- typedef typename S::point point;
typedef typename S::fwd_piter adapted;
};
Index: oln/core/internal/op_image_such_as_fp2b.hh
--- oln/core/internal/op_image_such_as_fp2b.hh (revision 0)
+++ oln/core/internal/op_image_such_as_fp2b.hh (revision 0)
@@ -0,0 +1,114 @@
+// 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_OP_IMAGE_SUCH_AS_FP2B_HH
+# define OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH
+
+# include <oln/core/internal/op_image_restricted_to_pset.hh>
+# include <oln/core/internal/op_pset_such_as_fp2b.hh>
+
+
+namespace oln
+{
+
+
+# define current \
+ special_op_< stc::is<Image>, I, such_as, stc::is<Function_p2b>, F >
+
+
+ // Fwd decl.
+ namespace internal { template <typename I, typename F> class current; }
+
+
+ // Super type.
+ template <typename I, typename F>
+ struct super_trait_< internal::current >
+ {
+ typedef op_< const oln_pset(I), such_as, F > S;
+ typedef internal::special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, const S > ret;
+ };
+
+
+# define super \
+ super_trait_< internal::current >::ret
+
+
+ // Virtual types.
+ template <typename I, typename F>
+ struct vtypes< internal::current >
+ {
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class for the result of "Image I | Function_p2b F".
+
+ template <typename I, typename F>
+ class current : public super
+ {
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ protected:
+ special_op_();
+ special_op_(I& ima, F& f);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename I, typename F>
+ current::special_op_()
+ {
+ }
+
+ template <typename I, typename F>
+ current::special_op_(I& ima, F& f)
+ : super(ima, (ima.points() | f))
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
+
+
+ // Fixme: Activate init
+
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_IMAGE_SUCH_AS_FP2B_HH
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 898)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -111,8 +111,7 @@
template <typename S, typename B, typename P>
op_<const S, such_as, const fun_p2b_<B (*)(P)> >
- operator | (const Point_Set<S>& lhs,
- B (*f)(P))
+ operator | (const Point_Set<S>& lhs, B (*f)(P))
{
typedef oln_strip_(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 898)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -40,12 +40,7 @@
special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S >
-// /// Fwd decls.
-// template <typename Exact> struct Image;
-// template <typename Exact> struct Point_Set;
-
-
- /// Super type.
+ // Super type.
template <typename I, typename S>
struct super_trait_< internal::current >
{
@@ -53,7 +48,7 @@
};
- /// Virtual types.
+ // Virtual types.
template <typename I, typename S>
struct vtypes< internal::current >
{
@@ -73,7 +68,7 @@
namespace internal
{
- /// Implementation class the result of "Image I | Point_Set S".
+ /// Implementation class for the result of "Image I | Point_Set S".
template <typename I, typename S>
class special_op_< stc::is<Image>, I, restricted_to, stc::is<Point_Set>, S >
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 898)
+++ oln/core/internal/image_base.hh (working copy)
@@ -477,11 +477,33 @@
# include <oln/core/internal/f_ch_value.hh>
# include <oln/core/internal/op_image_restricted_to_pset.hh>
+# include <oln/core/internal/op_image_such_as_fp2b.hh>
namespace oln
{
+ // Image | Point_Set ( ima restricted_to pset )
+
oln_decl_op_restricted_to(Image, Point_Set);
+
+ // Image | Function_p2b ( ima such_as "f : p -> b"
+ // is ima restricted_to (ima.points such_as f) )
+ oln_decl_op_such_as(Image, Function_p2b);
+
+
+ // Specialization.
+
+ template <typename I, typename B, typename P>
+ op_<const I, such_as, const fun_p2b_<B (*)(P)> >
+ operator | (const Image<I>& ima, B (*f)(P))
+ {
+ typedef oln_strip_(P) P_;
+ mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
+ mlc::assert_equal_< P_, oln_point(I) >::check();
+ op_<const I, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(ima), f);
+ return tmp;
+ }
+
} // end of namespace oln
/// \}
1
0
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Make check : test basic morpho.
* olena/tests/algorithms/Makefile.am: .
* olena/tests/algorithms/basic_morpho.cc: New.
Makefile.am | 5 ++-
basic_morpho.cc | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
2 files changed, 87 insertions(+), 2 deletions(-)
Index: olena/tests/algorithms/Makefile.am
--- olena/tests/algorithms/Makefile.am (revision 897)
+++ olena/tests/algorithms/Makefile.am (working copy)
@@ -23,10 +23,11 @@
check_PROGRAMS = \
- fill
+ fill \
+ basic_morpho
# Algorithms.
fill_SOURCES = fill.cc
-
+basic_morpho_SOURCES = basic_morpho.cc
TESTS = $(check_PROGRAMS)
Index: olena/tests/algorithms/basic_morpho.cc
--- olena/tests/algorithms/basic_morpho.cc (revision 0)
+++ olena/tests/algorithms/basic_morpho.cc (revision 0)
@@ -0,0 +1,84 @@
+
+#include <oln/core/2d/image2d.hh>
+#include <oln/core/2d/window2d.hh>
+#include <oln/core/2d/neighb2d.hh>
+
+#include <oln/morpho/elementary_dilation.hh>
+#include <oln/morpho/elementary_erosion.hh>
+
+#include <oln/morpho/dilation.hh>
+#include <oln/morpho/erosion.hh>
+
+#include <oln/morpho/opening.hh>
+#include <oln/morpho/closing.hh>
+
+#include <oln/morpho/elementary_closing.hh>
+#include <oln/morpho/elementary_opening.hh>
+
+#include <oln/debug/print.hh>
+
+int main()
+{
+ using namespace oln;
+
+ int i = 0;
+
+ typedef image2d<bool> I;
+
+ I ima(5, 5);
+
+ I::piter p1(ima.points());
+ for_all(p1)
+ ima(p1) = i++ % 2;
+
+ std::cout << "ima" << std::endl;
+ debug::print(ima);
+
+
+ I tmp = (morpho::elementary_erosion(ima + c4)).image();
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 0);
+
+ // std::cout << "elementary_dilation" << std::endl;
+ tmp = (morpho::elementary_dilation(ima + c4)).image();
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "erosion_w" << std::endl;
+ tmp = morpho::erosion(ima, win3x3);
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 0);
+
+ // std::cout << "dilation_w" << std::endl;
+ tmp = morpho::dilation(ima, win3x3);
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "elementary_opening" << std::endl;
+ tmp = (morpho::elementary_opening(ima + c4)).image();
+ p1 = tmp.points();
+ for_all(p1)
+ assert(tmp(p1) == 0);
+
+ // std::cout << "elementary_closing" << std::endl;
+ tmp = (morpho::elementary_closing(ima + c4)).image();
+ p1 = (tmp.points());
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "opening" << std::endl;
+ tmp = morpho::opening(ima, win3x3);
+ p1 = (tmp.points());
+ for_all(p1)
+ assert(tmp(p1) == 1);
+
+ // std::cout << "closing" << std::endl;
+ debug::print( morpho::closing(ima, win3x3) );
+ p1 = (tmp.points());
+ for_all(p1)
+ assert(tmp(p1) == 1);
+}
1
0
ima
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
1 0 1 0 1
0 1 0 1 0
elementary_erosion
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
elementary_dilation
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
erosion_w
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
dilation_w
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
elementary_opening
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
elementary_closing
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
opening
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
closing
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
1 1 1 1 1
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Basic Morpho : Tested OK.
* oln/core/2d/image2d.hh: .
* oln/morpho/elementary_erosion.hh: .
* oln/morpho/elementary_closing.hh: .
* oln/morpho/elementary_opening.hh: .
* oln/morpho/erosion.hh: .
* oln/morpho/closing.hh: .
* oln/morpho/opening.hh: .
* oln/level/local.hh: .
* oln/level/apply_local.hh: .
level/apply_local.hh | 28 ++++++++++++
level/local.hh | 100 ++++++++++++++++++++++---------------------
morpho/closing.hh | 5 --
morpho/elementary_closing.hh | 6 --
morpho/elementary_erosion.hh | 3 -
morpho/elementary_opening.hh | 6 --
morpho/erosion.hh | 2
morpho/opening.hh | 6 +-
8 files changed, 91 insertions(+), 65 deletions(-)
Index: oln/core/2d/image2d.hh
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 896)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -65,12 +65,11 @@
template <typename I>
oln_plain(I)
elementary_erosion_on_set_(const Image<I>&,
- const I&)
+ const I& input)
{
border::fill(input, oln_max(oln_value(I)));
accumulator::and_<oln_value(I)> accu_and;
return level::apply_local(accu_and, input);
- return tmp;
}
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 896)
+++ oln/morpho/elementary_closing.hh (working copy)
@@ -52,11 +52,9 @@
template <typename I>
oln_plain(I)
- elementary_closing_(const Image<I>& input);
+ elementary_closing_(const Image_with_Nbh<I>& input)
{
- oln_plain(I) tmp;
- tmp = elementary_dilation(input);
- return elementary_erosion(tmp);
+ return elementary_erosion( elementary_dilation(input) );
}
// FIXME: Add a fast version.
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 896)
+++ oln/morpho/elementary_opening.hh (working copy)
@@ -52,11 +52,9 @@
template <typename I>
oln_plain(I)
- elementary_opening_(const Image<I>& input);
+ elementary_opening_(const Image_with_Nbh<I>& input)
{
- oln_plain(I) tmp;
- tmp = elementary_erosion(input);
- return elementary_dilation(tmp);
+ return morpho::elementary_dilation( morpho::elementary_erosion(input) );
}
// FIXME: Add a fast version.
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 896)
+++ oln/morpho/erosion.hh (working copy)
@@ -58,7 +58,7 @@
{
border::fill(input, oln_min(oln_value(I)));
accumulator::min_<oln_value(I)> min;
- return level::apply_local(max, input, win);
+ return level::apply_local(min, input, win);
}
template <typename I>
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 896)
+++ oln/morpho/closing.hh (working copy)
@@ -56,14 +56,13 @@
closing_(const Image<I>& input,
const Window<W>& win)
{
- oln_plain(I) = elementary_dilation(input, win);
- return elementary_erosion(tmp, win); // FIXME : inverse(win).
+ oln_plain(I) tmp = morpho::dilation(input, win);
+ return morpho::erosion(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
-
} // end of namespace oln::morpho::impl
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 896)
+++ oln/morpho/opening.hh (working copy)
@@ -56,8 +56,8 @@
opening_(const Image<I>& input,
const Window<W>& win)
{
- oln_plain(I) = elementary_dilation(input, win);
- return elementary_erosion(tmp, win); // FIXME : inverse(win).
+ oln_plain(I) tmp = morpho::dilation(input, win);
+ return morpho::erosion(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
@@ -71,7 +71,7 @@
oln_plain(I)
opening(const Image<I>& input, const Window<W>& win)
{
- return impl::opening_(exact(input), exact(win));
+ return impl::opening_(exact(input), win);
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/level/local.hh
--- oln/level/local.hh (revision 896)
+++ oln/level/local.hh (working copy)
@@ -59,6 +59,8 @@
namespace impl
{
+ /// Neigborhood.
+
// Generic version with neighborhood.
template <typename A, typename I>
@@ -70,36 +72,18 @@
f.init_with(input(p));
oln_niter(I) n(p, input);
for_all(n)
+ {
f(input(n));
- return f.value();
}
-
-
- // FIXME: Generic version with nbh given as argument?
-
- // Generic version with window.
-
- template <typename A, typename I, typename W>
- typename A::result
- local_(const A& f,
- const Image<I>& input,
- const oln_point(I)& p,
- const Window<W>& win)
- {
- f.init();
- oln_qiter(W) q(p, win);
- for_all(q)
- f(input(q));
return f.value();
}
-
// Optimised version for OR operator with neighborhood.
template <typename B, typename I>
B
- local_(const accumulator::or_<B>& f,
- const Binary_Image<I>& input,
+ local_(const oln::accumulator::or_<B>& f,
+ const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
@@ -115,55 +99,74 @@
return f.value();
}
+ // Optimised version for AND operator with neighborhood.
- // Optimised version for OR operator with window.
-
- template <typename B, typename I, typename W>
+ template <typename B, typename I>
B
- local_(const accumulator::or_<B>& f,
- const Binary_Image<I>& input,
+ local_(const accumulator::and_< B > f,
+ const Image_with_Nbh<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input);
+ for_all(n)
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == false)
+ return false;
+ }
+ return f.value();
+ }
+
+ // FIXME: Generic version with nbh given as argument?
+
+
+
+ /// On Window.
+
+ // Generic version with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_(const A& f,
+ const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
f.init_with(input(p));
- if (f.value() == true)
- return true;
oln_qiter(W) q(p, win);
for_all(q)
- {
+ if (input.owns_(q))
f(input(q));
- if (f.value() == true)
- return true;
- }
return f.value();
}
+ // Optimised version for OR operator with window.
- // FIXME : same function for OR.
-
- // Optimised version for AND operator with neighborhood.
-
- template <typename B, typename I>
+ template <typename B, typename I, typename W>
B
- local_(const accumulator::and_< B > f,
+ local_(const oln::accumulator::or_<B>& f,
const Binary_Image<I>& input,
- const oln_point(I)& p)
+ const oln_point(I)& p,
+ const Window<W>& win)
{
f.init_with(input(p));
- oln_niter(I) n(p, input);
- for_all(n)
+ if (f.value() == true)
+ return true;
+ oln_qiter(W) q(p, win);
+ for_all(q)
{
- f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (input.owns_(q))
+ f(input(q));
if (f.value() == true)
return true;
}
return f.value();
}
-
// Optimised version for AND operator with window.
- template <typename A, typename I, typename W>
+ template <typename B, typename I, typename W>
B
local_(const accumulator::and_< B > f,
const Image<I>& input,
@@ -174,9 +177,10 @@
oln_qiter(W) q(p, win);
for_all(q)
{
+ if (input.owns_(q))
f(input(q));
- if (f.value() == true)
- return true;
+ if (f.value() == false)
+ return false;
}
return f.value();
}
@@ -192,7 +196,7 @@
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
- return impl::local_(exact(f), input, p);
+ return impl::local_(exact(f), exact(input), p);
}
template <typename A, typename I, typename W>
@@ -202,7 +206,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- return impl::local_(exact(f), input, p, win);
+ return impl::local_(exact(f), exact(input), p, win);
}
#endif // ! OLN_INCLUDE_ONLY
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 896)
+++ oln/level/apply_local.hh (working copy)
@@ -47,6 +47,11 @@
apply_local(const Accumulator<F>& f,
const Image_with_Nbh<I>& input);
+ template <typename F, typename I, typename W>
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& f,
+ const Image<I>& input,
+ const Window<W>& win);
# ifndef OLN_INCLUDE_ONLY
@@ -68,6 +73,20 @@
return output;
}
+ template <typename F, typename I, typename W>
+ oln_plain_value(I, typename F::result)
+ apply_local_(const Accumulator<F>& f,
+ const Image<I>& input,
+ const Window<W>& win)
+ {
+ oln_plain_value(I, typename F::result) output;
+ prepare(output, with, input);
+ oln_piter(I) p(input.points());
+ for_all(p)
+ output(p) = level::local(f, input, p, win);
+ return output;
+ }
+
} // end of namespace oln::level::impl
@@ -81,6 +100,15 @@
return impl::apply_local_(exact(f), exact(input));
}
+ template <typename F, typename I, typename W>
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& f,
+ const Image<I>& input,
+ const Window<W>& win)
+ {
+ return impl::apply_local_(exact(f), exact(input), win);
+ }
+
# endif
} // end of namespace oln::level
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Provide more suitable niter classes.
* oln/core/gen/niter_has.hh: New.
* oln/debug/print_nbh.hh (impl): Remove; useless.
* oln/core/concept/image.hh (Image_with_Nbh): Overload nbhood
access.
* oln/core/concept/image_identity.hh: Update.
* oln/core/equipment.hh (oln_pset): New.
* oln/core/internal/piter_adaptor.hh (point): Set final.
* oln/core/internal/op_pset_such_as_fp2b.hh (point): Remove.
* oln/core/internal/op_image_plus_nbh.hh (include): Update.
(fwd_niter, bkd_niter): Update.
core/concept/image.hh | 12 ++-
core/concept/image_identity.hh | 12 ++-
core/equipment.hh | 1
core/gen/niter_has.hh | 126 ++++++++++++++++++++++++++++++++++
core/internal/op_image_plus_nbh.hh | 22 ++++-
core/internal/op_pset_such_as_fp2b.hh | 1
core/internal/piter_adaptor.hh | 4 -
debug/print_nbh.hh | 38 ----------
8 files changed, 168 insertions(+), 48 deletions(-)
Index: oln/debug/print_nbh.hh
--- oln/debug/print_nbh.hh (revision 895)
+++ oln/debug/print_nbh.hh (working copy)
@@ -45,14 +45,10 @@
# ifndef OLN_INCLUDE_ONLY
- namespace impl
- {
-
- // Image
+ // Generic version.
template <typename I>
- void print_nbh(const Image<I>&,
- const I& input, std::ostream& ostr)
+ void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr = std::cout)
{
oln_piter(I) p(input.points());
oln_niter(I) n(p, input);
@@ -60,41 +56,11 @@
{
ostr << input(p) << ": ";
for_all(n)
- if (input.owns_(n))
ostr << input(n) << " ";
ostr << std::endl;
}
}
-
- // Point_Wise_Accessible_Image
-
- template <typename I>
- void print_nbh(const Point_Wise_Accessible_Image<I>&,
- const I& input, std::ostream& ostr)
- {
- oln_piter(I) p(input.points());
- oln_niter(I) n(p, input);
- for_all(p)
- {
- ostr << input(p) << ": ";
- for_all(n)
- if (input.has(n))
- ostr << input(n) << " ";
- ostr << std::endl;
- }
- }
-
- } // end of namespace oln::debug::impl
-
-
- // facade
- template <typename I>
- void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr)
- {
- impl::print_nbh(exact(input), exact(input), ostr);
- }
-
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 895)
+++ oln/core/concept/image.hh (working copy)
@@ -156,7 +156,8 @@
stc_typename(bkd_niter);
typedef fwd_niter niter;
- nbh nbhood() const;
+ const nbh& nbhood() const;
+ nbh& nbhood();
protected:
Image_with_Nbh();
@@ -458,13 +459,20 @@
// ----------------------------------- Image_with_Nbh<Exact>
template <typename Exact>
- typename Image_with_Nbh<Exact>::nbh
+ const typename Image_with_Nbh<Exact>::nbh&
Image_with_Nbh<Exact>::nbhood() const
{
return exact(this)->impl_nbhood();
}
template <typename Exact>
+ typename Image_with_Nbh<Exact>::nbh&
+ Image_with_Nbh<Exact>::nbhood()
+ {
+ return exact(this)->impl_nbhood();
+ }
+
+ template <typename Exact>
Image_with_Nbh<Exact>::Image_with_Nbh()
{
}
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 895)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -64,7 +64,8 @@
struct set_impl< Image_with_Nbh, behavior::identity, Exact > : public virtual Any<Exact>
{
stc_typename(nbh);
- nbh impl_nbhood() const;
+ const nbh& impl_nbhood() const;
+ nbh& impl_nbhood();
};
@@ -211,12 +212,19 @@
/// Concept-class "Image_with_Nbh".
template <typename Exact>
- typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh
+ const typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh&
set_impl< Image_with_Nbh, behavior::identity, Exact >::impl_nbhood() const
{
return exact(this)->image().nbhood();
}
+ template <typename Exact>
+ typename set_impl< Image_with_Nbh, behavior::identity, Exact >::nbh&
+ set_impl< Image_with_Nbh, behavior::identity, Exact >::impl_nbhood()
+ {
+ return exact(this)->image().nbhood();
+ }
+
/// Concept-class "Image_with_Border".
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 895)
+++ oln/core/equipment.hh (working copy)
@@ -123,6 +123,7 @@
# define oln_piter(T) oln_typename_shortcut__(T, piter)
# define oln_plain(T) oln_typename_shortcut__(T, plain)
# define oln_point(T) oln_typename_shortcut__(T, point)
+# define oln_pset(T) oln_typename_shortcut__(T, pset)
// q
stc_decl_associated_type( qiter );
Index: oln/core/gen/niter_has.hh
--- oln/core/gen/niter_has.hh (revision 0)
+++ oln/core/gen/niter_has.hh (revision 0)
@@ -0,0 +1,126 @@
+// 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_NITER_HAS_HH
+# define OLN_CORE_GEN_NITER_HAS_HH
+
+# include <oln/core/internal/piter_adaptor.hh>
+# include <oln/core/gen/dpoints_piter.hh>
+
+
+namespace oln
+{
+
+
+# define current niter_has_<It, Ps>
+ // --------------------
+
+# define super internal::piter_adaptor_< current >
+
+
+ // Fwd decl.
+ template <typename It, typename Ps> class niter_has_;
+
+
+ // Super type.
+ template <typename It, typename Ps>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual type.
+ template <typename It, typename Ps>
+ struct vtypes< current >
+ {
+ typedef It adapted;
+ };
+
+
+ // Forward point iterator class on a set of dpoints.
+ template <typename It, typename Ps>
+ class niter_has_ : public super
+ {
+ public:
+
+ // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
+
+ template <typename Pl, typename I>
+ niter_has_(const Pl& p, const Image_with_Nbh<I>& ima);
+
+ void impl_start();
+ void impl_next();
+
+ protected:
+
+ const Ps pset_;
+
+ }; // end of class oln::niter_has_<P>
+
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename It, typename Ps>
+ template <typename Pl, typename I>
+ current::niter_has_(const Pl& p, const Image_with_Nbh<I>& ima)
+ :
+ super( It(p, ima) ),
+ pset_( ima.points() )
+ {
+ }
+
+ template <typename It, typename Ps>
+ void
+ current::impl_start()
+ {
+ this->p_.start();
+ while (this->p_.is_valid() and not this->pset_.has(this->p_))
+ this->p_.next();
+ }
+
+ template <typename It, typename Ps>
+ void
+ current::impl_next()
+ {
+ do
+ this->p_.next();
+ while (this->p_.is_valid() and not this->pset_.has(this->p_));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_NITER_HAS_HH
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 895)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (working copy)
@@ -64,7 +64,6 @@
template <typename S, typename F>
struct vtypes< internal::current >
{
- typedef typename S::point point;
typedef pset_such_as_fp2b_fwd_piter_<S, F> fwd_piter;
typedef pset_such_as_fp2b_bkd_piter_<S, F> bkd_piter;
};
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 895)
+++ oln/core/internal/piter_adaptor.hh (working copy)
@@ -51,8 +51,10 @@
template <typename Exact>
struct vtypes< internal::piter_adaptor_<Exact> >
{
- typedef stc::abstract point;
typedef stc::abstract adapted;
+
+ typedef stc_deferred(adapted) adapted__;
+ typedef stc::final< oln_point(adapted__) > point;
};
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 895)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -29,9 +29,10 @@
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# include <oln/core/concept/neighborhood.hh>
+# include <oln/core/internal/image_base.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
-# include <oln/core/internal/image_base.hh>
+# include <oln/core/gen/niter_has.hh>
namespace oln
@@ -62,14 +63,15 @@
struct vtypes< internal::current >
{
typedef op_<I, plus, N> Exact;
- typedef stc_type(I, point) point__;
typedef I delegatee;
typedef internal::pair<I,N> data;
typedef N nbh;
- typedef dpoints_fwd_piter_<point__> fwd_niter;
- typedef dpoints_bkd_piter_<point__> bkd_niter;
+
+ // FIXME: Wrong!
+ typedef niter_has_< dpoints_fwd_piter_<oln_point(I)>, oln_pset(I) > fwd_niter;
+ typedef niter_has_< dpoints_bkd_piter_<oln_point(I)>, oln_pset(I) > bkd_niter;
typedef op_<oln_plain(I), plus, N> plain;
typedef op_<pl::rec<I>, plus, N> skeleton;
@@ -96,7 +98,7 @@
delegatee& impl_image();
const delegatee& impl_image() const;
- nbh impl_nbhood() const;
+ const nbh& impl_nbhood() const;
nbh& impl_nbhood();
protected:
@@ -160,13 +162,21 @@
}
template <typename I, typename N>
- typename current::nbh
+ const typename current::nbh&
current::impl_nbhood() const
{
assert(this->has_data());
return this->data_->second;
}
+ template <typename I, typename N>
+ typename current::nbh&
+ current::impl_nbhood()
+ {
+ assert(this->has_data());
+ return this->data_->second;
+ }
+
} // end of namespace oln::internal
1
0
Modification in algorithm specialization (function/set).
Correction of major order errors in opening / closing.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Fix : Opening, Closing, erosion, dilation.
* oln/morpho/elementary_erosion.hh: .
* oln/morpho/dilation.hh: .
* oln/morpho/elementary_closing.hh: .
* oln/morpho/elementary_opening.hh: .
* oln/morpho/erosion.hh: .
* oln/morpho/closing.hh: New.
* oln/morpho/opening.hh: .
* oln/level/local.hh: .
level/local.hh | 46 +++++++++++++----------
morpho/closing.hh | 86 +++++++++++++++++++++++++++++++++++++++++++
morpho/dilation.hh | 25 ++++++++++++
morpho/elementary_closing.hh | 22 +++++------
morpho/elementary_erosion.hh | 5 +-
morpho/elementary_opening.hh | 22 +++++------
morpho/erosion.hh | 32 ++++++++++++++--
morpho/opening.hh | 9 +---
8 files changed, 192 insertions(+), 55 deletions(-)
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 894)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -67,8 +67,9 @@
elementary_erosion_on_set_(const Image<I>&,
const I&)
{
- oln_plain(I) tmp;
- std::cerr << "morpho::impl::elementary_erosion_on_set_ is not yet impled!" << std::endl;
+ border::fill(input, oln_max(oln_value(I)));
+ accumulator::and_<oln_value(I)> accu_and;
+ return level::apply_local(accu_and, input);
return tmp;
}
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 894)
+++ oln/morpho/dilation.hh (working copy)
@@ -61,8 +61,33 @@
return level::apply_local(max, input, win);
}
+ template <typename I>
+ oln_plain(I)
+ dilation_on_set_(const Image<I>&,
+ const I& input)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::or_<oln_value(I)> accu_or;
+ return level::apply_local(accu_or, input);
+ }
+
// FIXME: Add a fast version.
+
+ // Impl facade.
+
+ template <typename I>
+ oln_plain(I) dilation_(const Image<I>& input)
+ {
+ return dilation_on_function_(exact(input), exact(input));
+ }
+
+ template <typename I>
+ oln_plain(I) dilation_(const Binary_Image<I>& input)
+ {
+ return dilation_on_set_(exact(input), exact(input));
+ }
+
} // end of namespace oln::morpho::impl
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 894)
+++ oln/morpho/elementary_closing.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_MORPHO_ELEMENTARY_CLOSING_HH
# define OLN_MORPHO_ELEMENTARY_CLOSING_HH
-#include <oln/level/apply_local.hh>
-#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
@@ -41,10 +39,9 @@
// Fwd decl.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_closing(const Image<I>& input, const Window<W>& win);
-
+ elementary_closing(const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -53,12 +50,13 @@
// Generic version.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_closing_(const Image<I>& input,
- const Window<W>& win)
+ elementary_closing_(const Image<I>& input);
{
- return elementary_erosion(elementary_dilation(input, win), win); // FIXME : memory
+ oln_plain(I) tmp;
+ tmp = elementary_dilation(input);
+ return elementary_erosion(tmp);
}
// FIXME: Add a fast version.
@@ -68,11 +66,11 @@
// Facade.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_closing(const Image<I>& input, const Window<W>& win)
+ elementary_closing(const Image_with_Nbh<I>& input)
{
- return impl::elementary_closing_(exact(input), exact(win));
+ return impl::elementary_closing_(exact(input));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 894)
+++ oln/morpho/elementary_opening.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_MORPHO_ELEMENTARY_OPENING_HH
# define OLN_MORPHO_ELEMENTARY_OPENING_HH
-#include <oln/level/apply_local.hh>
-#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
@@ -41,10 +39,9 @@
// Fwd decl.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_opening(const Image<I>& input, const Window<W>& win);
-
+ elementary_opening(const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -53,12 +50,13 @@
// Generic version.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_opening_(const Image<I>& input,
- const Window<W>& win)
+ elementary_opening_(const Image<I>& input);
{
- return elementary_dilation(elementary_erosion(input, win), win); // FIXME : memory
+ oln_plain(I) tmp;
+ tmp = elementary_erosion(input);
+ return elementary_dilation(tmp);
}
// FIXME: Add a fast version.
@@ -68,11 +66,11 @@
// Facade.
- template <typename I, typename W>
+ template <typename I>
oln_plain(I)
- elementary_opening(const Image<I>& input, const Window<W>& win)
+ elementary_opening(const Image_with_Nbh<I>& input)
{
- return impl::elementary_opening_(exact(input), exact(win));
+ return impl::elementary_opening_(exact(input));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 894)
+++ oln/morpho/erosion.hh (working copy)
@@ -30,7 +30,7 @@
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
-#include <oln/accumulator/min.hh>
+#include <oln/accumulator/max.hh>
namespace oln
{
@@ -54,16 +54,40 @@
template <typename I, typename W>
oln_plain(I)
- elementary_erosion_(const Image<I>& input,
- const Window<W>& win)
+ erosion_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::min_<oln_value(I)> min;
- return level::apply_local(min, input, win);
+ return level::apply_local(max, input, win);
+ }
+
+ template <typename I>
+ oln_plain(I)
+ erosion_on_set_(const Image<I>&,
+ const I& input)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::and_<oln_value(I)> accu_and;
+ return level::apply_local(accu_and, input);
}
// FIXME: Add a fast version.
+
+ // Impl facade.
+
+ template <typename I>
+ oln_plain(I) erosion_(const Image<I>& input)
+ {
+ return erosion_on_function_(exact(input), exact(input));
+ }
+
+ template <typename I>
+ oln_plain(I) erosion_(const Binary_Image<I>& input)
+ {
+ return erosion_on_set_(exact(input), exact(input));
+ }
+
} // end of namespace oln::morpho::impl
Index: oln/morpho/closing.hh
--- oln/morpho/closing.hh (revision 0)
+++ oln/morpho/closing.hh (revision 0)
@@ -0,0 +1,86 @@
+// 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_CLOSING_HH
+# define OLN_MORPHO_CLOSING_HH
+
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ closing(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ closing_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ oln_plain(I) = elementary_dilation(input, win);
+ return elementary_erosion(tmp, win); // FIXME : inverse(win).
+ }
+
+ // FIXME: Add a fast version.
+
+
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ closing(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::closing_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_CLOSING_HH
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 894)
+++ oln/morpho/opening.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_MORPHO_OPENING_HH
# define OLN_MORPHO_OPENING_HH
-#include <oln/level/apply_local.hh>
-#include <oln/border/fill.hh>
#include <oln/morpho/elementary_erosion.hh>
#include <oln/morpho/elementary_dilation.hh>
@@ -58,9 +56,8 @@
opening_(const Image<I>& input,
const Window<W>& win)
{
- border::fill(input, oln_min(oln_value(I)));
- accumulator::max_<oln_value(I)> max;
- return level::apply_local(max, input, win);
+ oln_plain(I) = elementary_dilation(input, win);
+ return elementary_erosion(tmp, win); // FIXME : inverse(win).
}
// FIXME: Add a fast version.
@@ -84,4 +81,4 @@
} // end of namespace oln
-#endif // ! OLN_MORPHO_DILATION_HH
+#endif // ! OLN_MORPHO_OPENING_HH
Index: oln/level/local.hh
--- oln/level/local.hh (revision 894)
+++ oln/level/local.hh (working copy)
@@ -115,22 +115,26 @@
return f.value();
}
- /*
// Optimised version for OR operator with window.
- template <typename A, typename I, typename W>
- typename A::result
- local_(const accumulator::or_<oln_value(I)>& f,
+ template <typename B, typename I, typename W>
+ B
+ local_(const accumulator::or_<B>& f,
const Binary_Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
- f.init();
+ f.init_with(input(p));
+ if (f.value() == true)
+ return true;
oln_qiter(W) q(p, win);
for_all(q)
- if (f(input(q)) == f.ultimate)
- return (f.ultimate);
+ {
+ f(input(q));
+ if (f.value() == true)
+ return true;
+ }
return f.value();
}
@@ -139,17 +143,20 @@
// Optimised version for AND operator with neighborhood.
- template <typename A, typename I>
- typename A::result
- local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ template <typename B, typename I>
+ B
+ local_(const accumulator::and_< B > f,
const Binary_Image<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
oln_niter(I) n(p, input);
for_all(n)
- if (f(input(n)) == f.ultimate)
- return (f.ultimate);
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() == true)
+ return true;
+ }
return f.value();
}
@@ -157,22 +164,23 @@
// Optimised version for AND operator with window.
template <typename A, typename I, typename W>
- typename A::result
- local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ B
+ local_(const accumulator::and_< B > f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
- f.init();
+ f.init_with(input(p));
oln_qiter(W) q(p, win);
for_all(q)
- if (f(input(q)) == f.ultimate)
- return (f.ultimate);
+ {
+ f(input(q));
+ if (f.value() == true)
+ return true;
+ }
return f.value();
}
- */
-
} // end of namespace oln::level::impl
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Factor code for iterators on dpoints and update.
* oln/core/internal/dpoints_piter_impl.hh: New; copy of...
* oln/core/internal/dpoints_piter.hh: ...this.
* oln/debug/print_nbh.hh: Update.
* oln/core/gen/dpoints_piter.hh (dpoints_fwd_piter_): Overload.
Update inheritance.
(dpoints_bkd_piter_): Update.
(include): Update.
* oln/core/internal/image_selectors.hh (Image_mutability): Add
FIXME.
* oln/core/internal/op_image_plus_nbh.hh: Better commentary.
Minor fixes.
* oln/accumulator/and.hh (include): Remove max_value.hh.
(init): Use 'true'.
(operator()): Use 'and'.
* oln/accumulator/or.hh (include): Remove max_value.hh.
(ultimate): Remove.
(init): Use 'false'.
(operator()): Use 'or'.
* oln/core/concept/accumulator.hh: Add FIXME.
* oln/core/internal/max_value.hh (oln_min): Remove.
* oln/core/internal/min_value.hh: Add FIXME.
* oln/morpho/dilation.hh: Fix.
* oln/level/local.hh (local_): Update 'or on nbh' version.
(local_): Inactivate other optimized versions.
accumulator/and.hh | 6
accumulator/or.hh | 8 -
core/concept/accumulator.hh | 2
core/gen/dpoints_piter.hh | 222 ++++++++++--------------------------
core/internal/dpoints_piter_impl.hh | 166 ++++++++++----------------
core/internal/image_selectors.hh | 2
core/internal/max_value.hh | 1
core/internal/min_value.hh | 2
core/internal/op_image_plus_nbh.hh | 2
debug/print_nbh.hh | 4
level/local.hh | 29 ++--
morpho/dilation.hh | 3
12 files changed, 157 insertions(+), 290 deletions(-)
Index: oln/accumulator/and.hh
--- oln/accumulator/and.hh (revision 893)
+++ oln/accumulator/and.hh (working copy)
@@ -29,7 +29,6 @@
# define OLN_ACCUMULATOR_AND_HH
# include <oln/core/concept/accumulator.hh>
-# include <oln/core/internal/max_value.hh>
namespace oln
@@ -68,7 +67,7 @@
void
and_<T>::init() const
{
- this->val_ = oln_min(T);
+ this->val_ = true;
}
template <typename T>
@@ -82,8 +81,7 @@
void
and_<T>::operator()(const T& val) const
{
- if (val < this->val_)
- this->val_ = val;
+ this->val_ = this->val_ and val;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/accumulator/or.hh
--- oln/accumulator/or.hh (revision 893)
+++ oln/accumulator/or.hh (working copy)
@@ -29,7 +29,6 @@
# define OLN_ACCUMULATOR_OR_HH
# include <oln/core/concept/accumulator.hh>
-# include <oln/core/internal/max_value.hh>
namespace oln
@@ -51,7 +50,6 @@
void operator()(const T& val) const;
- mutable T ultimate;
private:
mutable T val_;
};
@@ -69,8 +67,7 @@
void
or_<T>::init() const
{
- this->val_ = oln_min(T);
- this->ultimate = oln_max(T);
+ this->val_ = false;
}
template <typename T>
@@ -84,8 +81,7 @@
void
or_<T>::operator()(const T& val) const
{
- if (val < this->val_)
- this->val_ = val;
+ this->val_ = this->val_ or val;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/debug/print_nbh.hh
--- oln/debug/print_nbh.hh (revision 893)
+++ oln/debug/print_nbh.hh (working copy)
@@ -55,7 +55,7 @@
const I& input, std::ostream& ostr)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input.nbhood());
+ oln_niter(I) n(p, input);
for_all(p)
{
ostr << input(p) << ": ";
@@ -74,7 +74,7 @@
const I& input, std::ostream& ostr)
{
oln_piter(I) p(input.points());
- oln_niter(I) n(p, input.nbhood());
+ oln_niter(I) n(p, input);
for_all(p)
{
ostr << input(p) << ": ";
Index: oln/core/concept/accumulator.hh
--- oln/core/concept/accumulator.hh (revision 893)
+++ oln/core/concept/accumulator.hh (working copy)
@@ -60,7 +60,7 @@
Accumulator<Exact>::init_with(const T& val) const
{
exact(this)->init();
- exact(this)->operator()(val);
+ exact(this)->operator()(val); // FIXME: Change to ->take(val)?
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/core/gen/dpoints_piter.hh
--- oln/core/gen/dpoints_piter.hh (revision 893)
+++ oln/core/gen/dpoints_piter.hh (working copy)
@@ -28,121 +28,105 @@
#ifndef OLN_CORE_GEN_DPOINTS_PITER_HH
# define OLN_CORE_GEN_DPOINTS_PITER_HH
-# include <oln/core/concept/iterator_on_points.hh>
-# include <oln/core/internal/dpoints_impl.hh>
+# include <oln/core/concept/window.hh>
+# include <oln/core/concept/neighborhood.hh>
+# include <oln/core/concept/image.hh>
+# include <oln/core/internal/dpoints_piter_impl.hh>
namespace oln
{
- /// Fwd decls.
+ // --------------------------- dpoints_fwd_piter_<P>
+
+
+
+ // Fwd decl.
template <typename P> class dpoints_fwd_piter_;
- template <typename P> class dpoints_bkd_piter_;
- // Super types.
+ // Super type.
template <typename P>
struct super_trait_< dpoints_fwd_piter_<P> >
{
typedef dpoints_fwd_piter_<P> current__;
typedef Iterator_on_Points<current__> ret;
};
- template <typename P>
- struct super_trait_< dpoints_bkd_piter_<P> >
- {
- typedef dpoints_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
- /// Virtual types.
+ // Virtual type.
template <typename P>
struct vtypes< dpoints_fwd_piter_<P> >
{
typedef P point;
};
- template <typename P>
- struct vtypes< dpoints_bkd_piter_<P> >
- {
- typedef P point;
- };
-
- namespace internal
- {
-
- /// Class to factor some code.
-
+ // Forward point iterator class on a set of dpoints.
template <typename P>
- class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) >
+ class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
+ public internal::dpoints_fwd_piter_impl_<P>
{
public:
- dpoints_piter_impl_(const dpoints_piter_impl_&);
- void operator=(const dpoints_piter_impl_&);
-
- void impl_invalidate();
+ // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
- bool impl_is_valid() const;
+ template <typename Pl, typename W>
+ dpoints_fwd_piter_(const Pl& p, const Window<W>& win);
- P impl_to_point() const;
+ template <typename Pl, typename I>
+ dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
- const P* impl_point_adr() const;
+ template <typename Pl, typename N>
+ dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh);
- protected:
+ }; // end of class oln::dpoints_fwd_piter_<P>
- const P* p_ref_;
- std::vector<typename P::dpoint> dps_;
- unsigned n_, i_;
- P p_;
- // Ctor.
- template <typename Pl>
- dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data);
- void update_p_();
- };
+ // --------------------------- dpoints_bkd_piter_<P>
- } // end of namespace oln::internal
+ // Fwd decl.
+ template <typename P> class dpoints_bkd_piter_;
- /// Forward point iterator class on a set of dpoints.
+ // Super type.
template <typename P>
- class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ struct super_trait_< dpoints_bkd_piter_<P> >
{
- public:
-
- template <typename Pl, typename X>
- dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh);
-
- void impl_start();
-
- void impl_next();
+ typedef dpoints_bkd_piter_<P> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
- }; // end of class oln::dpoints_fwd_piter_<P>
+ // Virtual type.
+ template <typename P>
+ struct vtypes< dpoints_bkd_piter_<P> >
+ {
+ typedef P point;
+ };
/// Backward point iterator class on a set of dpoints.
-
template <typename P>
class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ public internal::dpoints_bkd_piter_impl_<P>
{
public:
- template <typename Pl, typename X>
- dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh);
+ // FIXME: Strenghten sigs (Pl is either a Point or an Iterator_on_Points).
+
+ template <typename Pl, typename W>
+ dpoints_bkd_piter_(const Pl& p, const Window<W>& win);
- void impl_start();
+ template <typename Pl, typename I>
+ dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima);
- void impl_next();
+ template <typename Pl, typename N>
+ dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh);
}; // end of class oln::dpoints_bkd_piter_<P>
@@ -150,128 +134,56 @@
# ifndef OLN_INCLUDE_ONLY
- namespace internal
- {
-
- template <typename Pl>
- const Pl* point_adr_(const Point<Pl>& p)
- {
- return exact(&p);
- }
-
- template <typename Pl>
- const typename Pl::point* point_adr_(const Iterator_on_Points<Pl>& p)
- {
- return p.point_adr();
- }
-
- template <typename P>
- template <typename Pl>
- dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data)
- {
- p_ref_ = point_adr_(ref);
- dps_ = data.dpoints();
- n_ = data.size();
- i_ = n_;
- postcondition(n_ != 0);
- }
-
- template <typename P>
- void
- dpoints_piter_impl_<P>::impl_invalidate()
- {
- i_ = n_;
- }
-
- template <typename P>
- bool
- dpoints_piter_impl_<P>::impl_is_valid() const
- {
- return i_ != n_;
- }
-
- template <typename P>
- P
- dpoints_piter_impl_<P>::impl_to_point() const
- {
- return p_;
- }
-
- template <typename P>
- const P*
- dpoints_piter_impl_<P>::impl_point_adr() const
- {
- return &p_;
- }
-
- template <typename P>
- void
- dpoints_piter_impl_<P>::update_p_()
- {
- p_ = *p_ref_+ dps_[i_];
- }
-
- } // end of namespace oln::internal
-
-
// fwd
template <typename P>
- template <typename Pl, typename X>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh)
+ template <typename Pl, typename W>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Window<W>& win)
:
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(win))
{
}
template <typename P>
- void
- dpoints_fwd_piter_<P>::impl_start()
+ template <typename Pl, typename I>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, ima.nbhood())
{
- this->i_ = 0;
- this->update_p_();
}
template <typename P>
- void
- dpoints_fwd_piter_<P>::impl_next()
+ template <typename Pl, typename N>
+ dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const Neighborhood<N>& nbh)
+ :
+ internal::dpoints_fwd_piter_impl_<P>(p, exact(nbh))
{
- if (++this->i_ = this->n_)
- return;
- this->update_p_();
}
-
// bkd
template <typename P>
- template <typename Pl, typename X>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh)
+ template <typename Pl, typename W>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Window<W>& win)
:
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(win))
{
}
template <typename P>
- void
- dpoints_bkd_piter_<P>::impl_start()
+ template <typename Pl, typename I>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Image_with_Nbh<I>& ima)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, ima.nbhood())
{
- this->i_ = this->n_ - 1;
- this->update_p_();
}
template <typename P>
- void
- dpoints_bkd_piter_<P>::impl_next()
- {
- if (this->i_ = 0)
+ template <typename Pl, typename N>
+ dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const Neighborhood<N>& nbh)
+ :
+ internal::dpoints_bkd_piter_impl_<P>(p, exact(nbh))
{
- this->i_ = this->n_;
- return;
- }
- --this->i_;
- this->update_p_();
}
# endif
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 893)
+++ oln/core/internal/max_value.hh (working copy)
@@ -31,7 +31,6 @@
# include <limits>
#define oln_max(T) std::numeric_limits< T >::max() // FIXME std lib
-#define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
#endif // ! OLN_CORE_INTERNAL_MAX_VALUE_HH
Index: oln/core/internal/dpoints_piter_impl.hh
--- oln/core/internal/dpoints_piter_impl.hh (revision 892)
+++ oln/core/internal/dpoints_piter_impl.hh (working copy)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_GEN_DPOINTS_PITER_HH
-# define OLN_CORE_GEN_DPOINTS_PITER_HH
+#ifndef OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
+# define OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
# include <oln/core/concept/iterator_on_points.hh>
# include <oln/core/internal/dpoints_impl.hh>
@@ -35,123 +35,79 @@
namespace oln
{
-
- /// Fwd decls.
- template <typename P> class dpoints_fwd_piter_;
- template <typename P> class dpoints_bkd_piter_;
-
-
- // Super types.
- template <typename P>
- struct super_trait_< dpoints_fwd_piter_<P> >
- {
- typedef dpoints_fwd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
- template <typename P>
- struct super_trait_< dpoints_bkd_piter_<P> >
- {
- typedef dpoints_bkd_piter_<P> current__;
- typedef Iterator_on_Points<current__> ret;
- };
-
-
- /// Virtual types.
- template <typename P>
- struct vtypes< dpoints_fwd_piter_<P> >
- {
- typedef P point;
- };
- template <typename P>
- struct vtypes< dpoints_bkd_piter_<P> >
- {
- typedef P point;
- };
-
-
-
namespace internal
{
- /// Class to factor some code.
+ /// Classes to factor code for iterators based on vector of dpoints.
template <typename P>
- class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) >
+ class dpoints_piter_impl_ : private mlc::assert_< mlc_is_a(P, Point) > // FIXME: Add err msg.
{
public:
-
- dpoints_piter_impl_(const dpoints_piter_impl_&);
- void operator=(const dpoints_piter_impl_&);
+ // dpoints_piter_impl_(const dpoints_piter_impl_&);
void impl_invalidate();
-
bool impl_is_valid() const;
P impl_to_point() const;
-
const P* impl_point_adr() const;
protected:
- const P* p_ref_;
- std::vector<typename P::dpoint> dps_;
- unsigned n_, i_;
- P p_;
-
- // Ctor.
template <typename Pl>
- dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data);
+ dpoints_piter_impl_(const Pl& p_ref,
+ const std::vector<typename P::dpoint>& dps);
void update_p_();
- };
-
- } // end of namespace oln::internal
+ const P* p_ref_;
+ const std::vector<typename P::dpoint>& dps_;
+ unsigned n_, i_;
+ P p_;
+ };
- /// Forward point iterator class on a set of dpoints.
+ // fwd
template <typename P>
- class dpoints_fwd_piter_ : public Iterator_on_Points< dpoints_fwd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ class dpoints_fwd_piter_impl_ : public dpoints_piter_impl_<P>
{
public:
- template <typename Pl, typename X>
- dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh);
-
void impl_start();
-
void impl_next();
- }; // end of class oln::dpoints_fwd_piter_<P>
+ protected:
+ template <typename Pl>
+ dpoints_fwd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data);
+ };
- /// Backward point iterator class on a set of dpoints.
+ // bkd
template <typename P>
- class dpoints_bkd_piter_ : public Iterator_on_Points< dpoints_bkd_piter_<P> >,
- public internal::dpoints_piter_impl_<P>
+ class dpoints_bkd_piter_impl_ : public dpoints_piter_impl_<P>
{
public:
- template <typename Pl, typename X>
- dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh);
-
void impl_start();
-
void impl_next();
- }; // end of class oln::dpoints_bkd_piter_<P>
+ protected:
+
+ template <typename Pl>
+ dpoints_bkd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data);
+ };
# ifndef OLN_INCLUDE_ONLY
- namespace internal
- {
+
+ // point_adr_
template <typename Pl>
const Pl* point_adr_(const Point<Pl>& p)
@@ -165,69 +121,70 @@
return p.point_adr();
}
+
+ // dpoints_piter_impl_<P>
+
template <typename P>
template <typename Pl>
- dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& ref,
- const internal::dpoints_impl_<typename P::dpoint>& data)
+ dpoints_piter_impl_<P>::dpoints_piter_impl_(const Pl& p_ref,
+ const std::vector<typename P::dpoint>& dps)
+ : p_ref_(point_adr_(p_ref)),
+ dps_(dps),
+ n_(dps.size()),
+ i_(n_)
{
- p_ref_ = point_adr_(ref);
- dps_ = data.dpoints();
- n_ = data.size();
- i_ = n_;
- postcondition(n_ != 0);
+ precondition(dps.size() != 0);
}
template <typename P>
void
dpoints_piter_impl_<P>::impl_invalidate()
{
- i_ = n_;
+ this->i_ = this->n_;
}
template <typename P>
bool
dpoints_piter_impl_<P>::impl_is_valid() const
{
- return i_ != n_;
+ return this->i_ != this->n_;
}
template <typename P>
P
dpoints_piter_impl_<P>::impl_to_point() const
{
- return p_;
+ return this->p_;
}
template <typename P>
const P*
dpoints_piter_impl_<P>::impl_point_adr() const
{
- return &p_;
+ return &(this->p_);
}
template <typename P>
void
dpoints_piter_impl_<P>::update_p_()
{
- p_ = *p_ref_+ dps_[i_];
+ this->p_ = *(this->p_ref_) + this->dps_[i_];
}
- } // end of namespace oln::internal
-
- // fwd
+ // dpoints_fwd_piter_impl_<P>
template <typename P>
- template <typename Pl, typename X>
- dpoints_fwd_piter_<P>::dpoints_fwd_piter_(const Pl& p, const X& win_or_nbh)
- :
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ template <typename Pl>
+ dpoints_fwd_piter_impl_<P>::dpoints_fwd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data)
+ : dpoints_piter_impl_<P>(p_ref, data.dpoints())
{
}
template <typename P>
void
- dpoints_fwd_piter_<P>::impl_start()
+ dpoints_fwd_piter_impl_<P>::impl_start()
{
this->i_ = 0;
this->update_p_();
@@ -235,7 +192,7 @@
template <typename P>
void
- dpoints_fwd_piter_<P>::impl_next()
+ dpoints_fwd_piter_impl_<P>::impl_next()
{
if (++this->i_ = this->n_)
return;
@@ -243,19 +200,19 @@
}
- // bkd
+ // dpoints_bkd_piter_impl_<P>
template <typename P>
- template <typename Pl, typename X>
- dpoints_bkd_piter_<P>::dpoints_bkd_piter_(const Pl& p, const X& win_or_nbh)
- :
- internal::dpoints_piter_impl_<P>(p, exact(win_or_nbh))
+ template <typename Pl>
+ dpoints_bkd_piter_impl_<P>::dpoints_bkd_piter_impl_(const Pl& p_ref,
+ const dpoints_impl_<typename P::dpoint>& data)
+ : dpoints_piter_impl_<P>(p_ref, data.dpoints())
{
}
template <typename P>
void
- dpoints_bkd_piter_<P>::impl_start()
+ dpoints_bkd_piter_impl_<P>::impl_start()
{
this->i_ = this->n_ - 1;
this->update_p_();
@@ -263,7 +220,7 @@
template <typename P>
void
- dpoints_bkd_piter_<P>::impl_next()
+ dpoints_bkd_piter_impl_<P>::impl_next()
{
if (this->i_ = 0)
{
@@ -271,12 +228,13 @@
return;
}
--this->i_;
- this->update_p_();
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::internal
} // end of namespace oln
-#endif // ! OLN_CORE_GEN_DPOINTS_PITER_HH
+#endif // ! OLN_CORE_INTERNAL_DPOINTS_PITER_IMPL_HH
Index: oln/core/internal/image_selectors.hh
--- oln/core/internal/image_selectors.hh (revision 893)
+++ oln/core/internal/image_selectors.hh (working copy)
@@ -56,7 +56,7 @@
struct case_< Image_mutability, Exact, 2 >
:
where_< mlc::and_< stc_type_is_found(lvalue),
- stc_type_is_found(index) > >
+ stc_type_is_found(index) > > // FIXME: Wrong!
{
typedef Fast_Image<Exact> ret;
};
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 893)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -79,7 +79,7 @@
namespace internal
{
- /// Implementation class the result of "Image I + Neighborhood N".
+ /// Implementation class for the result of "Image I + Neighborhood N".
template <typename I, typename N>
class current
Index: oln/core/internal/min_value.hh
--- oln/core/internal/min_value.hh (revision 893)
+++ oln/core/internal/min_value.hh (working copy)
@@ -30,6 +30,6 @@
# include <limits>
-# define oln_min(T) std::numeric_limits< T >::min()
+# define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
# endif // ! OLN_CORE_INTERNAL_MIN_VALUE_HH
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 893)
+++ oln/morpho/dilation.hh (working copy)
@@ -54,8 +54,7 @@
template <typename I, typename W>
oln_plain(I)
- elementary_dilation_(const Image<I>& input,
- const Window<W>& win)
+ dilation_(const Image<I>& input, const Window<W>& win)
{
border::fill(input, oln_min(oln_value(I)));
accumulator::max_<oln_value(I)> max;
Index: oln/level/local.hh
--- oln/level/local.hh (revision 893)
+++ oln/level/local.hh (working copy)
@@ -68,8 +68,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
- // 'input'!
+ oln_niter(I) n(p, input);
for_all(n)
f(input(n));
return f.value();
@@ -97,27 +96,32 @@
// Optimised version for OR operator with neighborhood.
- template <typename A, typename I>
- typename A::result
- local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ template <typename B, typename I>
+ B
+ local_(const accumulator::or_<B>& f,
const Binary_Image<I>& input,
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
- // 'input'!
+ if (f.value() = true)
+ return true;
+ oln_niter(I) n(p, input);
for_all(n)
- if (f(input(n)) = f.ultimate)
- return (f.ultimate);
+ {
+ f(input(n)); // FIXME: Change to f.take(input(n))?
+ if (f.value() = true)
+ return true;
+ }
return f.value();
}
+ /*
// Optimised version for OR operator with window.
template <typename A, typename I, typename W>
typename A::result
- local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ local_(const accumulator::or_<oln_value(I)>& f,
const Binary_Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
@@ -142,8 +146,7 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
- // 'input'!
+ oln_niter(I) n(p, input);
for_all(n)
if (f(input(n)) = f.ultimate)
return (f.ultimate);
@@ -168,6 +171,8 @@
return f.value();
}
+ */
+
} // end of namespace oln::level::impl
1
0
21 Mar '07
nonconst.hh doesn't exist but was (maybe is) still included.
image2d<bool> + morpho compile but error at execution
: Assertion `this->owns_(p)' failed.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Algo MorphoMath : and, or, opening, closing, elementary algo.
* oln/accumulator/and.hh: New.
* oln/accumulator/or.hh: New.
* oln/core/internal/max_value.hh,
* oln/core/internal/op_image_plus_nbh.hh,
* oln/morpho/elementary_erosion.hh,
* oln/morpho/dilation.hh: Update.
* oln/morpho/elementary_closing.hh,
* oln/morpho/elementary_opening.hh: New.
* oln/morpho/elementary_dilation.hh: Update.
* oln/morpho/erosion.hh: New.
* oln/morpho/opening.hh: New.
* oln/level/local.hh: .
accumulator/and.hh | 95 ++++++++++++++++++++++++++++++++++++
accumulator/or.hh | 97 +++++++++++++++++++++++++++++++++++++
core/internal/max_value.hh | 4 +
core/internal/op_image_plus_nbh.hh | 1
level/local.hh | 81 +++++++++++++++++++++++++++++-
morpho/dilation.hh | 2
morpho/elementary_closing.hh | 85 ++++++++++++++++++++++++++++++++
morpho/elementary_dilation.hh | 10 +--
morpho/elementary_erosion.hh | 1
morpho/elementary_opening.hh | 85 ++++++++++++++++++++++++++++++++
morpho/erosion.hh | 86 ++++++++++++++++++++++++++++++++
morpho/opening.hh | 87 +++++++++++++++++++++++++++++++++
12 files changed, 623 insertions(+), 11 deletions(-)
Index: oln/accumulator/and.hh
--- oln/accumulator/and.hh (revision 0)
+++ oln/accumulator/and.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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_ACCUMULATOR_AND_HH
+# define OLN_ACCUMULATOR_AND_HH
+
+# include <oln/core/concept/accumulator.hh>
+# include <oln/core/internal/max_value.hh>
+
+
+namespace oln
+{
+
+ namespace accumulator
+ {
+
+ template <typename T>
+ struct and_ : public Accumulator< and_<T> >
+ {
+ typedef T argument;
+ typedef T result;
+
+ and_();
+
+ void init() const;
+ const T& value() const;
+
+ void operator()(const T& val) const;
+
+ private:
+ mutable T val_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ and_<T>::and_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ and_<T>::init() const
+ {
+ this->val_ = oln_min(T);
+ }
+
+ template <typename T>
+ const T&
+ and_<T>::value() const
+ {
+ return this->val_;
+ }
+
+ template <typename T>
+ void
+ and_<T>::operator()(const T& val) const
+ {
+ if (val < this->val_)
+ this->val_ = val;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_AND_HH
Index: oln/accumulator/or.hh
--- oln/accumulator/or.hh (revision 0)
+++ oln/accumulator/or.hh (revision 0)
@@ -0,0 +1,97 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_ACCUMULATOR_OR_HH
+# define OLN_ACCUMULATOR_OR_HH
+
+# include <oln/core/concept/accumulator.hh>
+# include <oln/core/internal/max_value.hh>
+
+
+namespace oln
+{
+
+ namespace accumulator
+ {
+
+ template <typename T>
+ struct or_ : public Accumulator< or_<T> >
+ {
+ typedef T argument;
+ typedef T result;
+
+ or_();
+
+ void init() const;
+ const T& value() const;
+
+ void operator()(const T& val) const;
+
+ mutable T ultimate;
+ private:
+ mutable T val_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ or_<T>::or_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ or_<T>::init() const
+ {
+ this->val_ = oln_min(T);
+ this->ultimate = oln_max(T);
+ }
+
+ template <typename T>
+ const T&
+ or_<T>::value() const
+ {
+ return this->val_;
+ }
+
+ template <typename T>
+ void
+ or_<T>::operator()(const T& val) const
+ {
+ if (val < this->val_)
+ this->val_ = val;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_OR_HH
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 892)
+++ oln/core/internal/max_value.hh (working copy)
@@ -30,6 +30,8 @@
# include <limits>
-# define oln_max(T) std::numeric_limits< T >::max()
+#define oln_max(T) std::numeric_limits< T >::max() // FIXME std lib
+#define oln_min(T) std::numeric_limits< T >::min() // FIXME std lib
#endif // ! OLN_CORE_INTERNAL_MAX_VALUE_HH
+
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 892)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -28,7 +28,6 @@
#ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
-# include <mlc/unconst.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 892)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -32,7 +32,6 @@
#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
-
namespace oln
{
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 892)
+++ oln/morpho/dilation.hh (working copy)
@@ -32,6 +32,8 @@
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
+namespace oln
+{
namespace morpho
{
Index: oln/morpho/elementary_closing.hh
--- oln/morpho/elementary_closing.hh (revision 0)
+++ oln/morpho/elementary_closing.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_CLOSING_HH
+# define OLN_MORPHO_ELEMENTARY_CLOSING_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_closing(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_closing_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return elementary_erosion(elementary_dilation(input, win), win); // FIXME : memory
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_closing(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::elementary_closing_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_CLOSING_HH
Index: oln/morpho/elementary_opening.hh
--- oln/morpho/elementary_opening.hh (revision 0)
+++ oln/morpho/elementary_opening.hh (revision 0)
@@ -0,0 +1,85 @@
+// 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_OPENING_HH
+# define OLN_MORPHO_ELEMENTARY_OPENING_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_opening(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_opening_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ return elementary_dilation(elementary_erosion(input, win), win); // FIXME : memory
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_opening(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::elementary_opening_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_OPENING_HH
Index: oln/morpho/elementary_dilation.hh
--- oln/morpho/elementary_dilation.hh (revision 892)
+++ oln/morpho/elementary_dilation.hh (working copy)
@@ -31,7 +31,7 @@
#include <oln/level/apply_local.hh>
#include <oln/border/fill.hh>
#include <oln/accumulator/max.hh>
-
+#include <oln/accumulator/or.hh>
namespace oln
{
@@ -66,11 +66,11 @@
template <typename I>
oln_plain(I)
elementary_dilation_on_set_(const Image<I>&,
- const I&)
+ const I& input)
{
- oln_plain(I) tmp;
- std::cerr << "morpho::impl::elementary_dilation_on_set_ is not yet impled!" << std::endl;
- return tmp;
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::or_<oln_value(I)> accu_or;
+ return level::apply_local(accu_or, input);
}
// FIXME: Add a fast version.
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 0)
+++ oln/morpho/erosion.hh (revision 0)
@@ -0,0 +1,86 @@
+// 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_EROSION_HH
+# define OLN_MORPHO_EROSION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/accumulator/min.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ erosion(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ elementary_erosion_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::min_<oln_value(I)> min;
+ return level::apply_local(min, input, win);
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ erosion(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::erosion_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_EROSION_HH
Index: oln/morpho/opening.hh
--- oln/morpho/opening.hh (revision 0)
+++ oln/morpho/opening.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_OPENING_HH
+# define OLN_MORPHO_OPENING_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/morpho/elementary_erosion.hh>
+#include <oln/morpho/elementary_dilation.hh>
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ opening(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ opening_(const Image<I>& input,
+ const Window<W>& win)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::max_<oln_value(I)> max;
+ return level::apply_local(max, input, win);
+ }
+
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ opening(const Image<I>& input, const Window<W>& win)
+ {
+ return impl::opening_(exact(input), exact(win));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_DILATION_HH
Index: oln/level/local.hh
--- oln/level/local.hh (revision 892)
+++ oln/level/local.hh (working copy)
@@ -31,7 +31,8 @@
# include <oln/core/concept/image.hh>
# include <oln/core/concept/window.hh>
# include <oln/core/concept/accumulator.hh>
-
+# include <oln/accumulator/or.hh>
+# include <oln/accumulator/and.hh>
namespace oln
{
@@ -67,7 +68,8 @@
const oln_point(I)& p)
{
f.init_with(input(p));
- oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
+ // 'input'!
for_all(n)
f(input(n));
return f.value();
@@ -76,7 +78,6 @@
// FIXME: Generic version with nbh given as argument?
-
// Generic version with window.
template <typename A, typename I, typename W>
@@ -93,6 +94,80 @@
return f.value();
}
+
+ // Optimised version for OR operator with neighborhood.
+
+ template <typename A, typename I>
+ typename A::result
+ local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
+ // 'input'!
+ for_all(n)
+ if (f(input(n)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
+
+ // Optimised version for OR operator with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_(const ::oln::accumulator::or_< oln_value(I) > f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init();
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (f(input(q)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
+
+ // FIXME : same function for OR.
+
+ // Optimised version for AND operator with neighborhood.
+
+ template <typename A, typename I>
+ typename A::result
+ local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ const Binary_Image<I>& input,
+ const oln_point(I)& p)
+ {
+ f.init_with(input(p));
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be
+ // 'input'!
+ for_all(n)
+ if (f(input(n)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
+
+ // Optimised version for AND operator with window.
+
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_(const ::oln::accumulator::and_< oln_value(I) > f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ f.init();
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ if (f(input(q)) == f.ultimate)
+ return (f.ultimate);
+ return f.value();
+ }
+
} // end of namespace oln::level::impl
1
0
21 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add image selection about different kinds of values and update.
* oln/core/concept/image.hh (Gray_Level_Image, Color_Image)
(Label_Image, Binary_Image, String_Image)
(Deformation_Field_Image, Data_Image): New.
* oln/core/internal/max_value.hh: Fix.
* oln/core/internal/image_selectors.hh (Image_value_kind): New.
* oln/morpho/dilation.hh: Fix.
* oln/morpho/elementary_erosion.hh (elementary_erosion_): Rename as...
(elementary_erosion_on_function_): ...this.
(elementary_erosion_on_set_): New.
(elementary_erosion_): Dispatch over function/set.
(elementary_erosion): Update.
* oln/level/local.hh (A): Rename as...
(F): ...this.
* oln/accumulator/max.hh,
* oln/core/internal/min_value.hh,
* oln/morpho/elementary_dilation.hh: New.
* oln/value/greylevel.hh: Rename as...
* oln/value/graylevel.hh: ...this.
(greylevel_, greylevel): Rename as...
(graylevel_, graylevel): ...these.
* oln/value/default.hh (greylevel): Rename as...
(graylevel): ...this.
* oln/value/all.hh (include): Update.
* oln/value/bin.hh (bin): Change from greylevel_<1> to
graylevel_<1>.
* oln/value/tags.hh (is_grey_level): Rename as...
(is_gray_level): ...this.
accumulator/max.hh | 95 ++++++++++++++++++
core/concept/image.hh | 113 ++++++++++++++++++++++
core/internal/image_selectors.hh | 53 ++++++++++
core/internal/max_value.hh | 12 --
core/internal/min_value.hh | 35 ++++++
level/local.hh | 18 +--
morpho/dilation.hh | 79 +++++++++++++--
morpho/elementary_dilation.hh | 112 ++++++++++++++++++++++
morpho/elementary_erosion.hh | 28 ++++-
value/all.hh | 2
value/bin.hh | 4
value/default.hh | 10 -
value/graylevel.hh | 198 +++++++++++++++++++--------------------
value/tags.hh | 30 ++++-
14 files changed, 640 insertions(+), 149 deletions(-)
Index: oln/accumulator/max.hh
--- oln/accumulator/max.hh (revision 0)
+++ oln/accumulator/max.hh (revision 0)
@@ -0,0 +1,95 @@
+// 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_ACCUMULATOR_MAX_HH
+# define OLN_ACCUMULATOR_MAX_HH
+
+# include <oln/core/concept/accumulator.hh>
+# include <oln/core/internal/min_value.hh>
+
+
+namespace oln
+{
+
+ namespace accumulator
+ {
+
+ template <typename T>
+ struct max_ : public Accumulator< max_<T> >
+ {
+ typedef T argument;
+ typedef T result;
+
+ max_();
+
+ void init() const;
+ const T& value() const;
+
+ void operator()(const T& val) const;
+
+ private:
+ mutable T val_;
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ max_<T>::max_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ max_<T>::init() const
+ {
+ this->val_ = oln_min(T);
+ }
+
+ template <typename T>
+ const T&
+ max_<T>::value() const
+ {
+ return this->val_;
+ }
+
+ template <typename T>
+ void
+ max_<T>::operator()(const T& val) const
+ {
+ if (val > this->val_)
+ this->val_ = val;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_MAX_HH
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 891)
+++ oln/core/concept/image.hh (working copy)
@@ -351,6 +351,69 @@
+ /// Concept-class "Gray_Level_Image".
+
+ template <typename Exact>
+ struct Gray_Level_Image : public virtual Image<Exact>
+ {
+ protected:
+ Gray_Level_Image();
+ };
+
+ /// Concept-class "Color_Image".
+
+ template <typename Exact>
+ struct Color_Image : public virtual Image<Exact>
+ {
+ protected:
+ Color_Image();
+ };
+
+ /// Concept-class "Label_Image".
+
+ template <typename Exact>
+ struct Label_Image : public virtual Image<Exact>
+ {
+ protected:
+ Label_Image();
+ };
+
+ /// Concept-class "Binary_Image".
+
+ template <typename Exact>
+ struct Binary_Image : public Label_Image<Exact>
+ {
+ protected:
+ Binary_Image();
+ };
+
+ /// Concept-class "String_Image".
+
+ template <typename Exact>
+ struct String_Image : public Label_Image<Exact>
+ {
+ protected:
+ String_Image();
+ };
+
+ /// Concept-class "Deformation_Field_Image".
+
+ template <typename Exact>
+ struct Deformation_Field_Image : public virtual Image<Exact>
+ {
+ protected:
+ Deformation_Field_Image();
+ };
+
+ /// Concept-class "Data_Image".
+
+ template <typename Exact>
+ struct Data_Image : public virtual Image<Exact>
+ {
+ protected:
+ Data_Image();
+ };
+
@@ -613,6 +676,56 @@
{
}
+ // ----------------------------------- Gray_Level_Image<Exact>
+
+ template <typename Exact>
+ Gray_Level_Image<Exact>::Gray_Level_Image()
+ {
+ }
+
+ // ----------------------------------- Color_Image<Exact>
+
+ template <typename Exact>
+ Color_Image<Exact>::Color_Image()
+ {
+ }
+
+ // ----------------------------------- Label_Image<Exact>
+
+ template <typename Exact>
+ Label_Image<Exact>::Label_Image()
+ {
+ }
+
+ // ----------------------------------- Binary_Image<Exact>
+
+ template <typename Exact>
+ Binary_Image<Exact>::Binary_Image()
+ {
+ }
+
+ // ----------------------------------- String_Image<Exact>
+
+ template <typename Exact>
+ String_Image<Exact>::String_Image()
+ {
+ }
+
+ // ----------------------------------- Deformation_Field_Image<Exact>
+
+ template <typename Exact>
+ Deformation_Field_Image<Exact>::Deformation_Field_Image()
+ {
+ }
+
+ // ----------------------------------- Data_Image<Exact>
+
+ template <typename Exact>
+ Data_Image<Exact>::Data_Image()
+ {
+ }
+
+
# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 891)
+++ oln/core/internal/max_value.hh (working copy)
@@ -25,17 +25,11 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_INTERNAL_MAX_VALUE_HH_
-# define OLN_CORE_INTERNAL_MAX_VALUE_HH_
+#ifndef OLN_CORE_INTERNAL_MAX_VALUE_HH
+# define OLN_CORE_INTERNAL_MAX_VALUE_HH
-#include <cassert>
#include <limits>
-namespace oln
-{
-
#define oln_max(T) std::numeric_limits<T>::max()
-}
-
-#endif /* !OLN_CORE_INTERNAL_MAX_VALUE_HH_ */
+#endif // ! OLN_CORE_INTERNAL_MAX_VALUE_HH
Index: oln/core/internal/image_selectors.hh
--- oln/core/internal/image_selectors.hh (revision 891)
+++ oln/core/internal/image_selectors.hh (working copy)
@@ -30,6 +30,7 @@
# include <oln/core/concept/image.hh>
# include <oln/core/2d/grid2d.hh>
+# include <oln/value/tags.hh>
namespace oln
@@ -136,6 +137,58 @@
};
+ // 6. value kind
+
+ typedef selector<Image, 6> Image_value_kind;
+
+ template <typename Exact>
+ struct case_< Image_value_kind, Exact, 1 >
+ :
+ where_< value::is_gray_level<stc_get_type(value)> >
+ {
+ typedef Gray_Level_Image<Exact> ret;
+ };
+
+ template <typename Exact>
+ struct case_< Image_value_kind, Exact, 2 >
+ :
+ where_< value::is_binary<stc_get_type(value)> >
+ {
+ typedef Binary_Image<Exact> ret;
+ };
+
+ template <typename Exact>
+ struct case_< Image_value_kind, Exact, 3 >
+ :
+ where_< value::is_string<stc_get_type(value)> >
+ {
+ typedef String_Image<Exact> ret;
+ };
+
+ template <typename Exact>
+ struct case_< Image_value_kind, Exact, 4 >
+ :
+ where_< value::is_label<stc_get_type(value)> >
+ {
+ typedef Label_Image<Exact> ret;
+ };
+
+ template <typename Exact>
+ struct case_< Image_value_kind, Exact, 5 >
+ :
+ where_< value::is_color<stc_get_type(value)> >
+ {
+ typedef Color_Image<Exact> ret;
+ };
+
+ // FIXME: Deformation_Field_Image
+
+ template <typename Exact>
+ struct default_case_< Image_value_kind, Exact >
+ {
+ typedef Data_Image<Exact> ret;
+ };
+
} // end of namespace oln::internal
Index: oln/core/internal/min_value.hh
--- oln/core/internal/min_value.hh (revision 0)
+++ oln/core/internal/min_value.hh (revision 0)
@@ -0,0 +1,35 @@
+// 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_MIN_VALUE_HH
+# define OLN_CORE_INTERNAL_MIN_VALUE_HH
+
+# include <limits>
+
+# define oln_min(T) std::numeric_limits< T >::min()
+
+# endif // ! OLN_CORE_INTERNAL_MIN_VALUE_HH
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 891)
+++ oln/morpho/dilation.hh (working copy)
@@ -1,29 +1,84 @@
-#ifndef OLN_MORPHOMATH_DILATATION_HH_
-# define OLN_MORPHOMATH_DILATATION_HH_
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_MORPHO_DILATION_HH
+# define OLN_MORPHO_DILATION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/accumulator/max.hh>
-// Facade.
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I, typename W>
+ oln_plain(I)
+ dilation(const Image<I>& input, const Window<W>& win);
+
+
+# ifndef OLN_INCLUDE_ONLY
namespace impl
{
- /// Generic version
+ // Generic version.
template <typename I, typename W>
- I dilatation(const Image<I>& input)
+ oln_plain(I)
+ elementary_dilation_(const Image<I>& input,
+ const Window<W>& win)
{
- max_<oln_value(I)> max;
- return apply(max, input);
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::max_<oln_value(I)> max;
+ return level::apply_local(max, input, win);
}
-}
+ // FIXME: Add a fast version.
+
+ } // end of namespace oln::morpho::impl
-/// Facade.
+ // Facade.
template <typename I, typename W>
-I erosion(const Image<I>& input)
+ oln_plain(I)
+ dilation(const Image<I>& input, const Window<W>& win)
{
- return impl::dilatation(exact(input));
+ return impl::dilation_(exact(input), exact(win));
}
-#endif /* !OLN_MORPHOMATH_DILATATION_HH_ */
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_DILATION_HH
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 891)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -55,7 +55,7 @@
template <typename I>
oln_plain(I)
- elementary_erosion_(const Image<I>&,
+ elementary_erosion_on_function_(const Image<I>&,
const I& input)
{
border::fill(input, oln_max(oln_value(I)));
@@ -63,13 +63,22 @@
return level::apply_local(min, input);
}
+ template <typename I>
+ oln_plain(I)
+ elementary_erosion_on_set_(const Image<I>&,
+ const I&)
+ {
+ oln_plain(I) tmp;
+ std::cerr << "morpho::impl::elementary_erosion_on_set_ is not yet impled!" << std::endl;
+ return tmp;
+ }
// Fast version.
// template <typename I>
// oln_plain(I)
-// elementary_erosion_(const /*Fast_*/Image<I>&,
+// elementary_erosion_on_function_(const /*Fast_*/Image<I>&,
// const I& input)
// {
// std::cout << "fast" << std::endl;
@@ -100,6 +109,19 @@
// }
+ // Impl facade.
+
+ template <typename I>
+ oln_plain(I) elementary_erosion_(const Image<I>& input)
+ {
+ return elementary_erosion_on_function_(exact(input), exact(input));
+ }
+
+ template <typename I>
+ oln_plain(I) elementary_erosion_(const Binary_Image<I>& input)
+ {
+ return elementary_erosion_on_set_(exact(input), exact(input));
+ }
} // end of namespace oln::morpho::impl
@@ -111,7 +133,7 @@
oln_plain(I)
elementary_erosion(const Image_with_Nbh<I>& input)
{
- return impl::elementary_erosion_(exact(input), exact(input));
+ return impl::elementary_erosion_(exact(input));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/morpho/elementary_dilation.hh
--- oln/morpho/elementary_dilation.hh (revision 0)
+++ oln/morpho/elementary_dilation.hh (revision 0)
@@ -0,0 +1,112 @@
+// 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_DILATION_HH
+# define OLN_MORPHO_ELEMENTARY_DILATION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
+#include <oln/accumulator/max.hh>
+
+
+namespace oln
+{
+
+ namespace morpho
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_dilation(const Image_with_Nbh<I>& input);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ // Generic version.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_dilation_on_function_(const Image<I>&,
+ const I& input)
+ {
+ border::fill(input, oln_min(oln_value(I)));
+ accumulator::max_<oln_value(I)> max;
+ return level::apply_local(max, input);
+ }
+
+ template <typename I>
+ oln_plain(I)
+ elementary_dilation_on_set_(const Image<I>&,
+ const I&)
+ {
+ oln_plain(I) tmp;
+ std::cerr << "morpho::impl::elementary_dilation_on_set_ is not yet impled!" << std::endl;
+ return tmp;
+ }
+
+ // FIXME: Add a fast version.
+
+
+ // Impl facade.
+
+ template <typename I>
+ oln_plain(I) elementary_dilation_(const Image<I>& input)
+ {
+ return elementary_dilation_on_function_(exact(input), exact(input));
+ }
+
+ template <typename I>
+ oln_plain(I) elementary_dilation_(const Binary_Image<I>& input)
+ {
+ return elementary_dilation_on_set_(exact(input), exact(input));
+ }
+
+ } // end of namespace oln::morpho::impl
+
+
+ // Facade.
+
+ template <typename I>
+ oln_plain(I)
+ elementary_dilation(const Image_with_Nbh<I>& input)
+ {
+ return impl::elementary_dilation_(exact(input));
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
+
+#endif // ! OLN_MORPHO_ELEMENTARY_DILATION_HH
Index: oln/level/local.hh
--- oln/level/local.hh (revision 891)
+++ oln/level/local.hh (working copy)
@@ -45,9 +45,9 @@
const Image_with_Nbh<I>& input,
const oln_point(I)& p);
- template <typename F, typename I, typename W>
- typename F::result
- local(const Accumulator<F>& f,
+ template <typename A, typename I, typename W>
+ typename A::result
+ local(const Accumulator<A>& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win);
@@ -79,9 +79,9 @@
// Generic version with window.
- template <typename F, typename I, typename W>
- typename F::result
- local_(const F& f,
+ template <typename A, typename I, typename W>
+ typename A::result
+ local_(const A& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
@@ -107,9 +107,9 @@
return impl::local_(exact(f), input, p);
}
- template <typename F, typename I, typename W>
- typename F::result
- local(const Accumulator<F>& f,
+ template <typename A, typename I, typename W>
+ typename A::result
+ local(const Accumulator<A>& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
Index: oln/value/default.hh
--- oln/value/default.hh (revision 891)
+++ oln/value/default.hh (working copy)
@@ -28,7 +28,7 @@
#ifndef OLN_VALUE_DEFAULT_HH
# define OLN_VALUE_DEFAULT_HH
-# include <oln/value/greylevel.hh>
+# include <oln/value/graylevel.hh>
namespace oln
@@ -38,16 +38,16 @@
{
/// White.
- extern const greylevel white;
+ extern const graylevel white;
/// Black.
- extern const greylevel black;
+ extern const graylevel black;
# ifndef OLN_INCLUDE_ONLY
- const greylevel white = greylevel(1, 1);
- const greylevel black = greylevel(1, 0);
+ const graylevel white = graylevel(1, 1);
+ const graylevel black = graylevel(1, 0);
# endif
Index: oln/value/all.hh
--- oln/value/all.hh (revision 891)
+++ oln/value/all.hh (working copy)
@@ -31,7 +31,7 @@
# include <oln/value/tags.hh>
-# include <oln/value/greylevel.hh>
+# include <oln/value/graylevel.hh>
# include <oln/value/bin.hh>
# include <oln/value/default.hh>
Index: oln/value/bin.hh
--- oln/value/bin.hh (revision 891)
+++ oln/value/bin.hh (working copy)
@@ -31,7 +31,7 @@
# include <mlc/bexpr.hh>
# include <xtd/optraits.hh>
# include <xtd/valtraits.hh>
-# include <oln/value/greylevel.hh>
+# include <oln/value/graylevel.hh>
namespace oln
@@ -40,7 +40,7 @@
namespace value
{
- typedef greylevel_<1> bin;
+ typedef graylevel_<1> bin;
// Binary ops.
Index: oln/value/graylevel.hh
--- oln/value/graylevel.hh (revision 891)
+++ oln/value/graylevel.hh (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
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_VALUE_GREYLEVEL_HH
-# define OLN_CORE_VALUE_GREYLEVEL_HH
+#ifndef OLN_CORE_VALUE_GRAYLEVEL_HH
+# define OLN_CORE_VALUE_GRAYLEVEL_HH
# include <iostream>
# include <mlc/contract.hh>
@@ -58,22 +58,22 @@
/// Fwd decl.
- class greylevel;
+ class graylevel;
- /// General grey-level class on n bits.
+ /// General gray-level class on n bits.
template <unsigned nbits>
- class greylevel_ : public oln::abstract::value
+ class graylevel_ : public oln::abstract::value
{
typedef typename internal::encoding<nbits>::ret encoding_t;
public:
/// Ctor.
- greylevel_();
+ graylevel_();
/// Ctor.
- explicit greylevel_(const typename internal::encoding<nbits>::ret& val);
+ explicit graylevel_(const typename internal::encoding<nbits>::ret& val);
/// Access to std type.
typename internal::encoding<nbits>::ret value() const;
@@ -81,14 +81,14 @@
/// Op encoding_t.
operator typename internal::encoding<nbits>::ret() const;
- /// Op greylevel.
- operator greylevel() const;
+ /// Op graylevel.
+ operator graylevel() const;
/// Op<.
- bool operator<(const greylevel_<nbits>& rhs) const;
+ bool operator<(const graylevel_<nbits>& rhs) const;
/// Op=.
- bool operator=(const greylevel_<nbits>& rhs) const;
+ bool operator=(const graylevel_<nbits>& rhs) const;
protected:
encoding_t val_;
@@ -97,50 +97,50 @@
/// Op<<.
template <unsigned nbits>
- std::ostream& operator<<(std::ostream& ostr, const greylevel_<nbits>& g);
+ std::ostream& operator<<(std::ostream& ostr, const graylevel_<nbits>& g);
/// Aliases.
- typedef greylevel_<8> gl8;
- typedef greylevel_<16> gl16;
- typedef greylevel_<32> gl32;
+ typedef graylevel_<8> gl8;
+ typedef graylevel_<16> gl16;
+ typedef graylevel_<32> gl32;
template <unsigned nbits, unsigned mbits>
- bool operator=(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs);
+ bool operator=(const graylevel_<nbits>& lhs, const graylevel_<mbits>& rhs);
template <unsigned nbits, unsigned mbits>
- greylevel operator+(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs);
+ graylevel operator+(const graylevel_<nbits>& lhs, const graylevel_<mbits>& rhs);
template <unsigned nbits, unsigned mbits>
- greylevel operator-(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs);
+ graylevel operator-(const graylevel_<nbits>& lhs, const graylevel_<mbits>& rhs);
template <unsigned nbits>
- greylevel operator*(int s, const greylevel_<nbits>& rhs);
+ graylevel operator*(int s, const graylevel_<nbits>& rhs);
template <unsigned nbits>
- greylevel operator*(const greylevel_<nbits>& lhs, int s);
+ graylevel operator*(const graylevel_<nbits>& lhs, int s);
template <unsigned nbits>
- greylevel operator/(const greylevel_<nbits>& lhs, int s);
+ graylevel operator/(const graylevel_<nbits>& lhs, int s);
- /// General grey-level class where n bits is not know at compile-time.
- /// This class is used for exchange between grey-level types purpose.
- class greylevel : public oln::abstract::value
+ /// General gray-level class where n bits is not know at compile-time.
+ /// This class is used for exchange between gray-level types purpose.
+ class graylevel : public oln::abstract::value
{
public:
/// Ctor.
- greylevel();
+ graylevel();
/// Ctor.
template <unsigned n>
- greylevel(const greylevel_<n>& val);
+ graylevel(const graylevel_<n>& val);
/// Ctor.
- greylevel(unsigned nbits, unsigned long val);
+ graylevel(unsigned nbits, unsigned long val);
/// Access to std type.
unsigned long value() const;
@@ -149,14 +149,14 @@
void set_nbits(unsigned nbits);
- greylevel to_nbits(unsigned nbits) const;
+ graylevel to_nbits(unsigned nbits) const;
template <unsigned n>
- operator greylevel_<n>() const;
+ operator graylevel_<n>() const;
- bool operator<(const greylevel& rhs) const;
+ bool operator<(const graylevel& rhs) const;
- bool operator=(const greylevel& rhs) const;
+ bool operator=(const graylevel& rhs) const;
protected:
unsigned nbits_;
@@ -164,144 +164,144 @@
};
- std::ostream& operator<<(std::ostream& ostr, const greylevel& g);
+ std::ostream& operator<<(std::ostream& ostr, const graylevel& g);
- greylevel operator+(const greylevel& lhs, const greylevel& rhs);
- greylevel operator-(const greylevel& lhs, const greylevel& rhs);
+ graylevel operator+(const graylevel& lhs, const graylevel& rhs);
+ graylevel operator-(const graylevel& lhs, const graylevel& rhs);
- greylevel operator*(int s, const greylevel& rhs);
- greylevel operator*(const greylevel& lhs, int s);
+ graylevel operator*(int s, const graylevel& rhs);
+ graylevel operator*(const graylevel& lhs, int s);
- greylevel operator/(const greylevel& lhs, int s);
+ graylevel operator/(const graylevel& lhs, int s);
# ifndef OLN_INCLUDE_ONLY
- // Greylevel_<nbits>.
+ // Graylevel_<nbits>.
template <unsigned nbits>
- greylevel_<nbits>::greylevel_()
+ graylevel_<nbits>::graylevel_()
{
}
template <unsigned nbits>
- greylevel_<nbits>::greylevel_(const typename internal::encoding<nbits>::ret& val)
+ graylevel_<nbits>::graylevel_(const typename internal::encoding<nbits>::ret& val)
: val_(val)
{
}
template <unsigned nbits>
typename internal::encoding<nbits>::ret
- greylevel_<nbits>::value() const
+ graylevel_<nbits>::value() const
{
return val_;
}
template <unsigned nbits>
- greylevel_<nbits>::operator greylevel() const
+ graylevel_<nbits>::operator graylevel() const
{
- greylevel tmp(nbits, val_);
+ graylevel tmp(nbits, val_);
return tmp;
}
template <unsigned nbits>
- greylevel_<nbits>::operator typename internal::encoding<nbits>::ret() const
+ graylevel_<nbits>::operator typename internal::encoding<nbits>::ret() const
{
return val_;
}
template <unsigned nbits>
- bool greylevel_<nbits>::operator<(const greylevel_<nbits>& rhs) const
+ bool graylevel_<nbits>::operator<(const graylevel_<nbits>& rhs) const
{
return val_ < rhs.val_;
}
template <unsigned nbits>
- bool greylevel_<nbits>::operator=(const greylevel_<nbits>& rhs) const
+ bool graylevel_<nbits>::operator=(const graylevel_<nbits>& rhs) const
{
return val_ = rhs.val_;
}
template <unsigned nbits>
- std::ostream& operator<<(std::ostream& ostr, const greylevel_<nbits>& g)
+ std::ostream& operator<<(std::ostream& ostr, const graylevel_<nbits>& g)
{
return ostr << g.value();
}
template <unsigned nbits, unsigned mbits>
- bool operator=(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs)
+ bool operator=(const graylevel_<nbits>& lhs, const graylevel_<mbits>& rhs)
{
- return greylevel(lhs) = greylevel(rhs);
+ return graylevel(lhs) = graylevel(rhs);
}
template <unsigned nbits, unsigned mbits>
- greylevel operator+(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs)
+ graylevel operator+(const graylevel_<nbits>& lhs, const graylevel_<mbits>& rhs)
{
- return greylevel(lhs) + greylevel(rhs);
+ return graylevel(lhs) + graylevel(rhs);
}
template <unsigned nbits, unsigned mbits>
- greylevel operator-(const greylevel_<nbits>& lhs, const greylevel_<mbits>& rhs)
+ graylevel operator-(const graylevel_<nbits>& lhs, const graylevel_<mbits>& rhs)
{
- return greylevel(lhs) - greylevel(rhs);
+ return graylevel(lhs) - graylevel(rhs);
}
template <unsigned nbits>
- greylevel operator*(int s, const greylevel_<nbits>& rhs)
+ graylevel operator*(int s, const graylevel_<nbits>& rhs)
{
precondition(s >= 0);
- greylevel tmp(nbits, s * rhs.value());
+ graylevel tmp(nbits, s * rhs.value());
return tmp;
}
template <unsigned nbits>
- greylevel operator*(const greylevel_<nbits>& lhs, int s)
+ graylevel operator*(const graylevel_<nbits>& lhs, int s)
{
precondition(s >= 0);
- greylevel tmp(nbits, lhs.value() * s);
+ graylevel tmp(nbits, lhs.value() * s);
return tmp;
}
template <unsigned nbits>
- greylevel operator/(const greylevel_<nbits>& lhs, int s)
+ graylevel operator/(const graylevel_<nbits>& lhs, int s)
{
precondition(s > 0);
- greylevel tmp(nbits, lhs.value() / s);
+ graylevel tmp(nbits, lhs.value() / s);
return tmp;
}
- // Greylevel.
+ // Graylevel.
- greylevel::greylevel()
+ graylevel::graylevel()
: nbits_(0)
{
}
template <unsigned n>
- greylevel::greylevel(const greylevel_<n>& g)
+ graylevel::graylevel(const graylevel_<n>& g)
: nbits_(n),
val_(g.value())
{
}
- greylevel::greylevel(unsigned nbits, unsigned long val)
+ graylevel::graylevel(unsigned nbits, unsigned long val)
: nbits_(nbits),
val_(val)
{
}
- unsigned long greylevel::value() const
+ unsigned long graylevel::value() const
{
invariant(nbits_ != 0);
return val_;
}
- unsigned greylevel::nbits() const
+ unsigned graylevel::nbits() const
{
return nbits_;
}
@@ -337,7 +337,7 @@
} // end of oln::value::internal
- void greylevel::set_nbits(unsigned nbits)
+ void graylevel::set_nbits(unsigned nbits)
{
precondition(nbits != 0);
invariant(nbits_ != 0);
@@ -356,26 +356,26 @@
}
- greylevel greylevel::to_nbits(unsigned nbits) const
+ graylevel graylevel::to_nbits(unsigned nbits) const
{
precondition(nbits != 0);
invariant(nbits_ != 0);
- greylevel tmp(*this);
+ graylevel tmp(*this);
tmp.set_nbits(nbits);
return tmp;
}
template <unsigned n>
- greylevel::operator greylevel_<n>() const
+ graylevel::operator graylevel_<n>() const
{
precondition(nbits_ != 0);
- greylevel_<n> tmp(internal::convert<n>(nbits_, val_));
+ graylevel_<n> tmp(internal::convert<n>(nbits_, val_));
assert(tmp.value() < internal::two_pow_(n));
return tmp;
}
- bool greylevel::operator<(const greylevel& rhs) const
+ bool graylevel::operator<(const graylevel& rhs) const
{
precondition(nbits_ != 0 and rhs.nbits() != 0);
if (rhs.nbits() = nbits_)
@@ -386,7 +386,7 @@
return this->to_nbits(rhs.nbits()).value() < rhs.value();
}
- bool greylevel::operator=(const greylevel& rhs) const
+ bool graylevel::operator=(const graylevel& rhs) const
{
precondition(nbits_ != 0 and rhs.nbits() != 0);
if (rhs.nbits() = nbits_)
@@ -397,36 +397,36 @@
return this->to_nbits(rhs.nbits()).value() = rhs.value();
}
- std::ostream& operator<<(std::ostream& ostr, const greylevel& g)
+ std::ostream& operator<<(std::ostream& ostr, const graylevel& g)
{
return ostr << g.value() << '/' << g.nbits() << "nbits";
}
- greylevel operator+(const greylevel& lhs, const greylevel& rhs)
+ graylevel operator+(const graylevel& lhs, const graylevel& rhs)
{
precondition(lhs.nbits() != 0 and rhs.nbits() != 0);
if (lhs.nbits() > rhs.nbits())
{
- greylevel tmp(lhs.nbits(),
+ graylevel tmp(lhs.nbits(),
lhs.value() + rhs.to_nbits(lhs.nbits()).value());
return tmp;
}
else
{
- greylevel tmp(rhs.nbits(),
+ graylevel tmp(rhs.nbits(),
lhs.to_nbits(rhs.nbits()).value() + rhs.value());
return tmp;
}
}
- greylevel operator-(const greylevel& lhs, const greylevel& rhs)
+ graylevel operator-(const graylevel& lhs, const graylevel& rhs)
{
precondition(lhs.nbits() != 0 and rhs.nbits() != 0);
if (lhs.nbits() > rhs.nbits())
{
unsigned long l = rhs.to_nbits(lhs.nbits()).value();
assert(lhs.value() >= l);
- greylevel tmp(lhs.nbits(),
+ graylevel tmp(lhs.nbits(),
lhs.value() - l);
return tmp;
}
@@ -434,30 +434,30 @@
{
unsigned long l = lhs.to_nbits(rhs.nbits()).value();
assert(l >= rhs.value());
- greylevel tmp(rhs.nbits(),
+ graylevel tmp(rhs.nbits(),
l - rhs.value());
return tmp;
}
}
- greylevel operator*(int s, const greylevel& rhs)
+ graylevel operator*(int s, const graylevel& rhs)
{
precondition(s >= 0);
- greylevel tmp(rhs.nbits(), rhs.value() * s);
+ graylevel tmp(rhs.nbits(), rhs.value() * s);
return tmp;
}
- greylevel operator*(const greylevel& lhs, int s)
+ graylevel operator*(const graylevel& lhs, int s)
{
precondition(s >= 0);
- greylevel tmp(lhs.nbits(), lhs.value() * s);
+ graylevel tmp(lhs.nbits(), lhs.value() * s);
return tmp;
}
- greylevel operator/(const greylevel& lhs, int s)
+ graylevel operator/(const graylevel& lhs, int s)
{
precondition(s > 0);
- greylevel tmp(lhs.nbits(), lhs.value() / s);
+ graylevel tmp(lhs.nbits(), lhs.value() / s);
return tmp;
}
@@ -473,32 +473,32 @@
namespace xtd
{
- using oln::value::greylevel;
+ using oln::value::graylevel;
- template <> struct set_trait_<op_plus, greylevel, greylevel> { typedef greylevel ret; };
- template <> struct set_trait_<op_minus, greylevel, greylevel> { typedef greylevel ret; };
- template <> struct set_trait_<op_mult, int, greylevel> { typedef greylevel ret; };
- template <> struct set_trait_<op_mult, greylevel, int > { typedef greylevel ret; };
- template <> struct set_trait_<op_div, greylevel, int > { typedef greylevel ret; };
+ template <> struct set_trait_<op_plus, graylevel, graylevel> { typedef graylevel ret; };
+ template <> struct set_trait_<op_minus, graylevel, graylevel> { typedef graylevel ret; };
+ template <> struct set_trait_<op_mult, int, graylevel> { typedef graylevel ret; };
+ template <> struct set_trait_<op_mult, graylevel, int > { typedef graylevel ret; };
+ template <> struct set_trait_<op_div, graylevel, int > { typedef graylevel ret; };
- using oln::value::greylevel_;
+ using oln::value::graylevel_;
template <unsigned nbits, unsigned mbits>
- struct set_trait_< op_plus, greylevel_<nbits>, greylevel_<mbits> > { typedef greylevel ret; };
+ struct set_trait_< op_plus, graylevel_<nbits>, graylevel_<mbits> > { typedef graylevel ret; };
template <unsigned nbits, unsigned mbits>
- struct set_trait_< op_minus, greylevel_<nbits>, greylevel_<mbits> > { typedef greylevel ret; };
+ struct set_trait_< op_minus, graylevel_<nbits>, graylevel_<mbits> > { typedef graylevel ret; };
template <unsigned nbits>
- struct set_trait_< op_mult, int, greylevel_<nbits> > { typedef greylevel ret; };
+ struct set_trait_< op_mult, int, graylevel_<nbits> > { typedef graylevel ret; };
template <unsigned nbits>
- struct set_trait_< op_mult, greylevel_<nbits>, int > { typedef greylevel ret; };
+ struct set_trait_< op_mult, graylevel_<nbits>, int > { typedef graylevel ret; };
template <unsigned nbits>
- struct set_trait_< op_div, greylevel_<nbits>, int > { typedef greylevel ret; };
+ struct set_trait_< op_div, graylevel_<nbits>, int > { typedef graylevel ret; };
} // end of namespace xtd
-#endif // ! OLN_CORE_VALUE_GREYLEVEL_HH
+#endif // ! OLN_CORE_VALUE_GRAYLEVEL_HH
Index: oln/value/tags.hh
--- oln/value/tags.hh (revision 891)
+++ oln/value/tags.hh (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
@@ -28,6 +28,7 @@
#ifndef OLN_VALUE_TAGS_HH
# define OLN_VALUE_TAGS_HH
+# include <string>
# include <mlc/bexpr.hh>
@@ -55,22 +56,22 @@
struct is_color < color::rgb_<T> > : public mlc::bexpr_<true> {};
- // Grey-level trait.
+ // Gray-level trait.
template <typename T>
- struct is_grey_level : public mlc::bexpr_<false>
+ struct is_gray_level : public mlc::bexpr_<false>
{};
template <unsigned nbits>
- class greylevel_;
+ class graylevel_;
template <unsigned nbits>
- struct is_grey_level < greylevel_<nbits> > : public mlc::bexpr_<true> {};
+ struct is_gray_level < graylevel_<nbits> > : public mlc::bexpr_<true> {};
- class greylevel;
+ class graylevel;
template <>
- struct is_grey_level < greylevel > : public mlc::bexpr_<true> {};
+ struct is_gray_level < graylevel > : public mlc::bexpr_<true> {};
// Binary trait.
@@ -83,16 +84,27 @@
template <>
struct is_binary < bool > : public mlc::bexpr_<true> {};
- typedef greylevel_<1> bin;
+ typedef graylevel_<1> bin;
template <>
struct is_binary < bin > : public mlc::bexpr_<true> {};
+ // String trait.
+
+ template <typename T>
+ struct is_string : public mlc::bexpr_<false>
+ {
+ };
+
+ template <>
+ struct is_string < std::string > : public mlc::bexpr_<true> {};
+
+
// Label trait.
template <typename T>
- struct is_label : public mlc::bexpr_<false>
+ struct is_label : public mlc::or_< is_binary<T>, is_string<T> >
{
};
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Handle virtual borders.
* oln/morpher/add_neighborhood.hh: Remove; obsolete.
* oln/border/fill.hh: New.
* oln/accumulator/min.hh (operator()): Untemplate.
* oln/debug/print_nbh.hh: Use macros.
* oln/debug/println.hh (println): Remove unuseful exact.
* oln/core/concept/image.hh (Image_with_Border): New.
* oln/core/concept/image_identity.hh (set_impl): New version.
* oln/core/concept/accumulator.hh (init_with): New.
* oln/core/1d/image1d_b.hh (vborder): New.
(border): Rename as...
(impl_border): ...this.
* oln/core/2d/image2d_b.hh: Likewise.
* oln/core/2d/array2d.hh (row_pad): New.
* oln/core/equipment.hh (vborder): New.
* oln/core/internal/image_selectors.hh (Image_border): New.
* oln/morpho/elementary_erosion.hh (elementary_erosion_): Handle border.
(elementary_erosion_): New version; fast, to be activated.
(include): Add border/fill.hh.
* oln/level/local.hh (init): Replace this call by...
(init_with): ...this.
accumulator/min.hh | 14 +---
border/fill.hh | 135 +++++++++++++++++++++++++++++++++++++++
core/1d/image1d_b.hh | 6 +
core/2d/array2d.hh | 6 +
core/2d/image2d_b.hh | 14 +++-
core/concept/accumulator.hh | 11 +++
core/concept/image.hh | 26 +++++++
core/concept/image_identity.hh | 19 +++++
core/equipment.hh | 1
core/internal/image_selectors.hh | 13 +++
debug/print_nbh.hh | 11 ++-
debug/println.hh | 2
level/local.hh | 2
morpho/elementary_erosion.hh | 48 +++++++++++++
14 files changed, 287 insertions(+), 21 deletions(-)
Index: oln/accumulator/min.hh
--- oln/accumulator/min.hh (revision 890)
+++ oln/accumulator/min.hh (working copy)
@@ -47,10 +47,9 @@
min_();
void init() const;
- result value() const;
+ const T& value() const;
- template <typename U>
- void operator()(U i) const;
+ void operator()(const T& val) const;
private:
mutable T val_;
@@ -73,19 +72,18 @@
}
template <typename T>
- typename min_<T>::result
+ const T&
min_<T>::value() const
{
return this->val_;
}
template <typename T>
- template <typename U>
void
- min_<T>::operator()(U i) const
+ min_<T>::operator()(const T& val) const
{
- if (i < this->val_)
- this->val_ = static_cast<T>(i);
+ if (val < this->val_)
+ this->val_ = val;
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/debug/print_nbh.hh
--- oln/debug/print_nbh.hh (revision 890)
+++ oln/debug/print_nbh.hh (working copy)
@@ -43,6 +43,8 @@
void print_nbh(const Image_with_Nbh<I>& input, std::ostream& ostr = std::cout);
+# ifndef OLN_INCLUDE_ONLY
+
namespace impl
{
@@ -52,8 +54,8 @@
void print_nbh(const Image<I>&,
const I& input, std::ostream& ostr)
{
- typename I::fwd_piter p(input.points());
- typename I::fwd_niter n(p, input.nbhood());
+ oln_piter(I) p(input.points());
+ oln_niter(I) n(p, input.nbhood());
for_all(p)
{
ostr << input(p) << ": ";
@@ -71,8 +73,8 @@
void print_nbh(const Point_Wise_Accessible_Image<I>&,
const I& input, std::ostream& ostr)
{
- typename I::fwd_piter p(input.points());
- typename I::fwd_niter n(p, input.nbhood());
+ oln_piter(I) p(input.points());
+ oln_niter(I) n(p, input.nbhood());
for_all(p)
{
ostr << input(p) << ": ";
@@ -93,6 +95,7 @@
impl::print_nbh(exact(input), exact(input), ostr);
}
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln::debug
Index: oln/debug/println.hh
--- oln/debug/println.hh (revision 890)
+++ oln/debug/println.hh (working copy)
@@ -46,7 +46,7 @@
template <typename I>
void println(const Image<I>& input, std::ostream& ostr)
{
- print(exact(input), ostr);
+ debug::print(input, ostr);
ostr << std::endl;
}
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 890)
+++ oln/core/concept/image.hh (working copy)
@@ -163,6 +163,18 @@
};
+ /// Concept-class "Image_with_Border".
+
+ template <typename Exact>
+ struct Image_with_Border : public virtual Image<Exact>,
+ public automatic::get_impl<Image_with_Border, Exact>
+ {
+ unsigned border() const;
+ protected:
+ Image_with_Border();
+ };
+
+
/// Concept-class "Mutable_Image".
template <typename Exact>
@@ -394,6 +406,20 @@
{
}
+ // ----------------------------------- Image_with_Border<Exact>
+
+ template <typename Exact>
+ unsigned
+ Image_with_Border<Exact>::border() const
+ {
+ return exact(this)->impl_border();
+ }
+
+ template <typename Exact>
+ Image_with_Border<Exact>::Image_with_Border()
+ {
+ }
+
// ----------------------------------- Mutable_Image<Exact>
template <typename Exact>
Index: oln/core/concept/image_identity.hh
--- oln/core/concept/image_identity.hh (revision 890)
+++ oln/core/concept/image_identity.hh (working copy)
@@ -68,6 +68,15 @@
};
+ /// Concept-class "Image_with_Border".
+
+ template <typename Exact>
+ struct set_impl< Image_with_Border, behavior::identity, Exact > : public virtual Any<Exact>
+ {
+ unsigned impl_border() const;
+ };
+
+
/// Concept-class "Mutable_Image".
template <typename Exact>
@@ -209,6 +218,16 @@
}
+ /// Concept-class "Image_with_Border".
+
+ template <typename Exact>
+ unsigned
+ set_impl< Image_with_Border, behavior::identity, Exact >::impl_border() const
+ {
+ return exact(this)->image().border();
+ }
+
+
/// Concept-class "Mutable_Image".
template <typename Exact>
Index: oln/core/concept/accumulator.hh
--- oln/core/concept/accumulator.hh (revision 890)
+++ oln/core/concept/accumulator.hh (working copy)
@@ -39,6 +39,8 @@
template <typename Exact>
struct Accumulator : public Function<Exact>
{
+ template <typename T>
+ void init_with(const T& val) const;
protected:
Accumulator();
};
@@ -52,6 +54,15 @@
{
}
+ template <typename Exact>
+ template <typename T>
+ void
+ Accumulator<Exact>::init_with(const T& val) const
+ {
+ exact(this)->init();
+ exact(this)->operator()(val);
+ }
+
# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/1d/image1d_b.hh
--- oln/core/1d/image1d_b.hh (revision 890)
+++ oln/core/1d/image1d_b.hh (working copy)
@@ -64,6 +64,8 @@
unsigned,
box_<point1d> > data;
+ typedef mlc::true_ vborder;
+
typedef image1d_b<T> plain;
typedef image1d_b<pl::value> skeleton;
};
@@ -107,7 +109,7 @@
box1d impl_points() const;
- unsigned border() const;
+ unsigned impl_border() const;
};
@@ -190,7 +192,7 @@
}
template <typename T>
- unsigned image1d_b<T>::border() const
+ unsigned image1d_b<T>::impl_border() const
{
assert(this->has_data());
return this->data_->second;
Index: oln/core/2d/array2d.hh
--- oln/core/2d/array2d.hh (revision 890)
+++ oln/core/2d/array2d.hh (working copy)
@@ -71,6 +71,12 @@
const T* buffer() const;
T* buffer();
+ std::size_t row_pad() const
+ {
+ precondition(buffer_ != 0 and array_ != 0);
+ return &(array_[imin_+1][jmin_]) - &(array_[imin_][jmin_]);
+ }
+
protected:
C imin_, jmin_, imax_, jmax_;
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 890)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -101,6 +101,8 @@
typedef box2d pset;
typedef internal::array_b_<point2d, T> data;
+ typedef mlc::true_ vborder;
+
typedef image2d_b<T> plain;
typedef image2d_b<pl::value> skeleton;
@@ -148,7 +150,8 @@
box2d impl_points() const;
- unsigned border() const;
+ unsigned impl_border() const;
+ std::size_t pad(const dpoint2d& dp) const;
};
// template <typename T, typename D>
@@ -250,12 +253,19 @@
}
template <typename T>
- unsigned image2d_b<T>::border() const
+ unsigned image2d_b<T>::impl_border() const
{
assert(this->has_data());
return this->data_->border;
}
+ 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();
+ }
+
// template <typename T, typename D>
// bool init_(image2d_b<T>* this_, const D& dat)
// {
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 890)
+++ oln/core/equipment.hh (working copy)
@@ -143,6 +143,7 @@
// v
stc_decl_associated_type( value );
+ stc_decl_associated_type( vborder );
stc_decl_associated_type( vsite );
# define oln_value(T) oln_typename_shortcut__(T, value)
Index: oln/core/internal/image_selectors.hh
--- oln/core/internal/image_selectors.hh (revision 890)
+++ oln/core/internal/image_selectors.hh (working copy)
@@ -123,6 +123,19 @@
};
+ // 5. border
+
+ typedef selector<Image, 5> Image_border;
+
+ template <typename Exact>
+ struct case_< Image_border, Exact, 1 >
+ :
+ where_< stc_type_is_found(vborder) >
+ {
+ typedef Image_with_Border<Exact> ret;
+ };
+
+
} // end of namespace oln::internal
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 890)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -29,6 +29,7 @@
# define OLN_MORPHO_ELEMENTARY_EROSION_HH
#include <oln/level/apply_local.hh>
+#include <oln/border/fill.hh>
#include <oln/accumulator/min.hh>
@@ -50,16 +51,57 @@
namespace impl
{
- /// Generic version
+ // Generic version.
template <typename I>
oln_plain(I)
- elementary_erosion_(const Image_with_Nbh<I>& input)
+ elementary_erosion_(const Image<I>&,
+ const I& input)
{
+ border::fill(input, oln_max(oln_value(I)));
accumulator::min_<oln_value(I)> min;
return level::apply_local(min, input);
}
+
+
+ // Fast version.
+
+// template <typename I>
+// oln_plain(I)
+// elementary_erosion_(const /*Fast_*/Image<I>&,
+// const I& input)
+// {
+// std::cout << "fast" << std::endl;
+
+// typedef oln_value(I) T;
+// border::fill(input, oln_max(T));
+// accumulator::min_<T> min;
+
+// oln_plain(I) output;
+// prepare(output, with, input);
+
+// unsigned n = input.nbhood().size();
+// T* jump = new T[n];
+// for (unsigned i = 0; i < n; ++i)
+// jump[i] = input.image().pad(input.nbhood()[i]); // FIXME: pad is in Fast...
+
+// oln_piter(I) p(input.points());
+// for_all(p)
+// {
+// const T* ptr = & input(p);
+// min.init_with(*ptr);
+// for (unsigned i = 0; i < n; ++i)
+// min(*(ptr + jump[i]));
+// output(p) = min.value();
+// }
+// delete[] jump;
+// return output;
+// }
+
+
+
+
} // end of namespace oln::morpho::impl
@@ -69,7 +111,7 @@
oln_plain(I)
elementary_erosion(const Image_with_Nbh<I>& input)
{
- return impl::elementary_erosion_(exact(input));
+ return impl::elementary_erosion_(exact(input), exact(input));
}
# endif // ! OLN_INCLUDE_ONLY
Index: oln/level/local.hh
--- oln/level/local.hh (revision 890)
+++ oln/level/local.hh (working copy)
@@ -66,7 +66,7 @@
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
- f.init();
+ f.init_with(input(p));
oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
for_all(n)
f(input(n));
Index: oln/border/fill.hh
--- oln/border/fill.hh (revision 0)
+++ oln/border/fill.hh (revision 0)
@@ -0,0 +1,135 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_BORDER_FILL_HH
+# define OLN_BORDER_FILL_HH
+
+# include <oln/core/concept/image.hh>
+
+
+namespace oln
+{
+
+ namespace border
+ {
+
+ // Fwd decl.
+
+ template <typename I>
+ void fill(const Image<I>& input, const oln_value(I)& value);
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+# ifdef OLN_ENV_2D
+
+ template <typename I>
+ void fill_2D_(I& input, const oln_value(I)& value)
+ {
+ oln_point(I)
+ pmin(input.min_row() - input.border(),
+ input.min_col() - input.border()),
+ pmax(input.max_row() + input.border(),
+ input.max_col() + input.border());
+ if (not input.owns_(pmin) or not input.owns_(pmax))
+ return;
+ oln_coord(I) row, col;
+ for (col = pmin.col(); col <= pmax.col(); ++col)
+ {
+ // top
+ for (row = input.min_row() - input.border();
+ row <= input.min_row() - 1;
+ ++row)
+ input.at(row, col) = value;
+ // bot
+ for (row = input.max_row() + 1;
+ row <= input.max_row() + int(input.border());
+ ++row)
+ input.at(row, col) = value;
+ }
+ for (row = input.min_row();
+ row <= input.max_row();
+ ++row)
+ {
+ // left
+ for (col = input.min_col() - input.border();
+ col <= input.min_col() - 1;
+ ++col)
+ input.at(row, col) = value;
+ // right
+ for (col = input.max_col() + 1;
+ col <= input.max_col() + int(input.border());
+ ++col)
+ input.at(row, col) = value;
+ }
+ }
+
+ template <typename I>
+ void fill_nD_(Image_2D<I>& input, const oln_value(I)& value)
+ {
+ fill_2D_(exact(input), value);
+ }
+
+# endif // OLN_ENV_2D
+
+
+ template <typename I>
+ void fill_(const Image_with_Border<I>& input, const oln_value(I)& value)
+ {
+ // FIXME: Requires also Point_Wise_Accessible_Image, Mutable_Image...
+ I& input_ = const_cast<I&>(exact(input));
+ fill_nD_(input_, value);
+ }
+
+ template <typename I>
+ void fill_(const Image<I>&, const oln_value(I)&)
+ {
+ // no-op
+ }
+
+ } // end of namespace oln::border::impl
+
+
+ // Facade.
+
+ template <typename I>
+ void fill(const Image<I>& input, const oln_value(I)& value)
+ {
+ impl::fill_(exact(input), value);
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::border
+
+} // end of namespace oln
+
+
+#endif // ! OLN_BORDER_FILL_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Introduce 'prepare' to initialize image structures.
* oln/core/concept/image.hh (Image_2D): Add min_row, max_row,
min_col, and max_col.
* oln/debug/print.hh: Update.
* oln/level/apply_local.hh (init): Replace by prepare.
* oln/core/init.hh: Fix.
* oln/core/equipment.hh (oln_box): New.
* oln/core/2d/neighb2d.hh: Unconst objects.
* oln/core/2d/image2d.hh (init_): Rename as...
(prepare): ...this.
* oln/core/2d/image2d_b.hh: Likewise.
* oln/core/internal/op_image_restricted_to_pset.hh: Likewise.
* oln/core/internal/op_image_plus_nbh.hh: Likewise.
* oln/core/internal/image_base.hh (init_): New overload.
core/2d/image2d.hh | 10 ++--
core/2d/image2d_b.hh | 24 +++++++---
core/2d/neighb2d.hh | 16 +++----
core/concept/image.hh | 34 +++++++++++++++
core/equipment.hh | 1
core/init.hh | 4 -
core/internal/image_base.hh | 16 +++++--
core/internal/op_image_plus_nbh.hh | 50 +++++++++++++++-------
core/internal/op_image_restricted_to_pset.hh | 61 ++++++++++++++++++---------
debug/print.hh | 8 +--
level/apply_local.hh | 2
11 files changed, 161 insertions(+), 65 deletions(-)
Index: oln/debug/print.hh
--- oln/debug/print.hh (revision 889)
+++ oln/debug/print.hh (working copy)
@@ -100,11 +100,11 @@
std::ostream& ostr)
{
const oln_coord(I)
- min_row = input.bbox().pmin().row(),
- max_row = input.bbox().pmax().row();
+ min_row = input.min_row(),
+ max_row = input.max_row();
const oln_coord(I)
- min_col = input.bbox().pmin().col(),
- max_col = input.bbox().pmax().col();
+ min_col = input.min_col(),
+ max_col = input.max_col();
for (oln_coord(I) row = min_row; row <= max_row; ++row)
{
for (oln_coord(I) col = min_col; col <= max_col; ++col)
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 889)
+++ oln/level/apply_local.hh (working copy)
@@ -61,7 +61,7 @@
const Image_with_Nbh<I>& input)
{
oln_plain_value(I, typename F::result) output;
- init(output, with, input);
+ prepare(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
output(p) = level::local(f, input, p);
Index: oln/core/concept/image.hh
--- oln/core/concept/image.hh (revision 889)
+++ oln/core/concept/image.hh (working copy)
@@ -269,6 +269,12 @@
{
stc_typename(coord);
+ // final
+ coord min_row() const;
+ coord max_row() const;
+ coord min_col() const;
+ coord max_col() const;
+
protected:
Image_2D();
};
@@ -487,6 +493,34 @@
{
}
+ template <typename Exact>
+ typename Image_2D<Exact>::coord
+ Image_2D<Exact>::min_row() const
+ {
+ return this->bbox().pmin().row();
+ }
+
+ template <typename Exact>
+ typename Image_2D<Exact>::coord
+ Image_2D<Exact>::max_row() const
+ {
+ return this->bbox().pmax().row();
+ }
+
+ template <typename Exact>
+ typename Image_2D<Exact>::coord
+ Image_2D<Exact>::min_col() const
+ {
+ return this->bbox().pmin().col();
+ }
+
+ template <typename Exact>
+ typename Image_2D<Exact>::coord
+ Image_2D<Exact>::max_col() const
+ {
+ return this->bbox().pmax().col();
+ }
+
// ----------------------------------- Image_3D<Exact>
template <typename Exact>
Index: oln/core/init.hh
--- oln/core/init.hh (revision 889)
+++ oln/core/init.hh (working copy)
@@ -162,7 +162,7 @@
template <typename Target, typename Data>
bool init(Any<Target>& target, with_t, Any<Data>& data)
{
- return init(target, const_cast<const Data&>(data));
+ return init(target, with, const_cast<const Any<Data>&>(data));
}
@@ -174,7 +174,7 @@
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Any<Target>&, with_t, const Any<Data>&)
+ bool init(const Any<Target>& target, with_t, const Any<Data>& data)
{
mlc::abort_< Target, ERROR::initialization_of_temporary_or_const_object_<Target> >::check();
return false;
Index: oln/core/2d/neighb2d.hh
--- oln/core/2d/neighb2d.hh (revision 889)
+++ oln/core/2d/neighb2d.hh (working copy)
@@ -101,10 +101,10 @@
} // end of namespace oln::internal
- extern const neighb2d c4;
- extern const neighb2d c8;
- extern const neighb2d c2r;
- extern const neighb2d c2c;
+ extern neighb2d c4;
+ extern neighb2d c8;
+ extern neighb2d c2r;
+ extern neighb2d c2c;
# ifndef OLN_INCLUDE_ONLY
@@ -121,10 +121,10 @@
# endif // OLN_ENABLE_DEFAULT
- const neighb2d c4 = internal::mk_c4();
- const neighb2d c8 = internal::mk_c8();
- const neighb2d c2r = internal::mk_c2_row();
- const neighb2d c2c = internal::mk_c2_col();
+ neighb2d c4 = internal::mk_c4();
+ neighb2d c8 = internal::mk_c8();
+ neighb2d c2r = internal::mk_c2_row();
+ neighb2d c2c = internal::mk_c2_col();
# endif // OLN_INCLUDE_ONLY
Index: oln/core/2d/image2d.hh
--- oln/core/2d/image2d.hh (revision 889)
+++ oln/core/2d/image2d.hh (working copy)
@@ -104,7 +104,7 @@
};
template <typename T, typename D>
- bool init_(image2d<T>* this_, const D& dat);
+ bool prepare(image2d<T>& target, with_t, const D& dat);
# ifndef OLN_INCLUDE_ONLY
@@ -213,18 +213,18 @@
}
template <typename T, typename D>
- bool init_(image2d<T>* this_, const D& dat)
+ bool prepare(image2d<T>& target, with_t, const D& dat)
{
- precondition(not this_->has_data());
+ precondition(not target.has_data());
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
- this_->data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(),
+ target.data__() = new typename image2d<T>::data(b.pmin().row(), b.pmin().col(),
b.pmax().row(), b.pmax().col());
return box_ok;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/2d/image2d_b.hh
--- oln/core/2d/image2d_b.hh (revision 889)
+++ oln/core/2d/image2d_b.hh (working copy)
@@ -151,8 +151,8 @@
unsigned border() const;
};
- template <typename T, typename D>
- bool init_(image2d_b<T>* this_, const D& dat);
+// template <typename T, typename D>
+// bool init_(image2d_b<T>* this_, const D& dat);
# ifndef OLN_INCLUDE_ONLY
@@ -256,19 +256,31 @@
return this->data_->border;
}
+// template <typename T, typename D>
+// bool init_(image2d_b<T>* this_, const D& dat)
+// {
+// precondition(not this_->has_data());
+// box2d b;
+// bool box_ok = init(b, with, dat);
+// postcondition(box_ok);
+// unsigned border = 2; // FIXME: Use init!
+// this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border);
+// return box_ok;
+// }
+
template <typename T, typename D>
- bool init_(image2d_b<T>* this_, const D& dat)
+ bool prepare(image2d_b<T>& target, with_t, const D& dat)
{
- precondition(not this_->has_data());
+ precondition(not target.has_data());
box2d b;
bool box_ok = init(b, with, dat);
postcondition(box_ok);
unsigned border = 2; // FIXME: Use init!
- this_->data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border);
+ target.data__() = new typename image2d_b<T>::data(b.pmin(), b.pmax(), border);
return box_ok;
}
-# endif
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 889)
+++ oln/core/equipment.hh (working copy)
@@ -64,6 +64,7 @@
# define oln_bkd_niter(T) oln_typename_shortcut__(T, bkd_niter)
# define oln_bkd_piter(T) oln_typename_shortcut__(T, bkd_piter)
# define oln_bkd_qiter(T) oln_typename_shortcut__(T, bkd_qiter)
+# define oln_box(T) oln_typename_shortcut__(T, box)
// c
stc_decl_associated_type( coord );
Index: oln/core/internal/op_image_restricted_to_pset.hh
--- oln/core/internal/op_image_restricted_to_pset.hh (revision 889)
+++ oln/core/internal/op_image_restricted_to_pset.hh (working copy)
@@ -102,19 +102,23 @@
// init
- template <typename I, typename S, typename D>
- bool init_(internal::current* target, const D& dat);
-
template <typename S, typename I>
- bool init(Point_Set<S>& target,
- with_t,
+ bool init_(Point_Set<S>* this_,
const internal::current& dat);
template <typename I, typename S>
- bool init(Image<I>& target,
- with_t,
+ bool init_(Image<I>* this_,
const internal::current& dat);
+ template <typename I, typename S, typename D>
+ bool init_(internal::current* this_, const D& dat);
+
+ // prepare
+
+ template <typename I, typename S, typename D>
+ bool prepare(internal::current& target, with_t, const D& dat);
+
+
# ifndef OLN_INCLUDE_ONLY
@@ -160,8 +164,25 @@
} // end of namespace oln::internal
+
// init
+ template <typename S, typename I>
+ bool init_(Point_Set<S>* this_,
+ const internal::current& data)
+ {
+ exact(*this_) = data.points();
+ return true;
+ }
+
+ template <typename I, typename S>
+ bool init_(Image<I>* this_,
+ const internal::current& data)
+ {
+ exact(*this_) = data.image();
+ return true;
+ }
+
template <typename I, typename S, typename D>
bool init_(internal::current* this_, const D& dat)
{
@@ -174,23 +195,23 @@
return image_ok and subset_ok;
}
- template <typename S, typename I>
- bool init_(Point_Set<S>* this_,
- const internal::current& data)
- {
- *this_ = data.points();
- return true;
- }
- template <typename I, typename S>
- bool init(Image<I>* this_,
- const internal::current& data)
+ // prepare
+
+ template <typename I, typename S, typename D>
+ bool prepare(internal::current& target, with_t, const D& dat)
{
- *this_ = data.image();
- return true;
+ precondition(not target.has_data());
+ target.data__() = new typename op_<I, restricted_to, S>::data;
+ bool image_ok = prepare(target.data__()->first, with, dat);
+ bool subset_ok = init(target.data__()->second, with, dat);
+ postcondition(image_ok);
+ postcondition(subset_ok);
+ return image_ok and subset_ok;
}
-# endif // OLN_INCLUDE_ONLY
+
+# endif // ! OLN_INCLUDE_ONLY
# undef current
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 889)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -28,6 +28,7 @@
#ifndef OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
# define OLN_CORE_INTERNAL_OP_IMAGE_PLUS_NBH_HH
+# include <mlc/unconst.hh>
# include <oln/core/concept/neighborhood.hh>
# include <oln/core/gen/op.hh>
# include <oln/core/gen/dpoints_piter.hh>
@@ -107,19 +108,22 @@
} // end of namespace oln::internal
+ // prepare
+
+ template <typename I, typename N, typename D>
+ bool prepare(internal::current& target, with_t, const D& dat);
+
// init
template <typename I, typename N, typename D>
bool init_(internal::current* target, const D& dat);
template <typename N, typename I>
- bool init(Neighborhood<N>& target,
- with_t,
+ bool init_(Neighborhood<N>* this_,
const internal::current& dat);
template <typename I, typename N>
- bool init(Image<I>& target,
- with_t,
+ bool init_(Image<I>* this_,
const internal::current& dat);
@@ -169,6 +173,22 @@
// init
+ template <typename N, typename I>
+ bool init_(Neighborhood<N>* this_,
+ const internal::current& data)
+ {
+ exact(*this_) = data.nbhood();
+ return true;
+ }
+
+ template <typename I, typename N>
+ bool init_(Image<I>* this_,
+ const internal::current& data)
+ {
+ exact(*this_) = data.image();
+ return true;
+ }
+
template <typename I, typename N, typename D>
bool init_(internal::current* this_, const D& dat)
{
@@ -181,20 +201,18 @@
return ima_ok and nbh_ok;
}
- template <typename N, typename I>
- bool init_(Neighborhood<N>* this_,
- const internal::current& data)
- {
- *this_ = data.nbhood();
- return true;
- }
+ // prepare
- template <typename I, typename N>
- bool init(Image<I>* this_,
- const internal::current& data)
+ template <typename I, typename N, typename D>
+ bool prepare(internal::current& target, with_t, const D& dat)
{
- *this_ = data.image();
- return true;
+ precondition(not target.has_data());
+ target.data__() = new typename op_<I, plus, N>::data;
+ bool ima_ok = prepare(target.data__()->first, with, dat);
+ bool nbh_ok = init(target.data__()->second, with, dat);
+ postcondition(ima_ok);
+ postcondition(nbh_ok);
+ return ima_ok and nbh_ok;
}
# endif // OLN_INCLUDE_ONLY
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 889)
+++ oln/core/internal/image_base.hh (working copy)
@@ -436,7 +436,10 @@
bool init_(box_<P>* this_, const internal::image_base_<I>& data);
template <typename Target, typename I>
- bool init_(Target* this_, const internal::single_image_morpher_<I>& data);
+ 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);
# ifndef OLN_INCLUDE_ONLY
@@ -449,12 +452,19 @@
}
template <typename Target, typename I>
- bool init_(Target* this_, const internal::single_image_morpher_<I>& data)
+ bool init_(Any<Target>* this_, const internal::single_image_morpher_<I>& data)
{
return init(*this_, with, data.image());
}
-# endif // OLN_INCLUDE_ONLY
+ template <typename P, typename I>
+ bool init_(box_<P>* this_, const internal::single_image_morpher_<I>& data)
+ {
+ *this_ = data.bbox();
+ return true;
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
1
0