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
March 2007
- 7 participants
- 73 discussions
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
Index: ChangeLog
from Alexandre Abraham <abraham(a)lrde.epita.fr>
Fix mini-oln, add mutable image type and rgb value.
* samples/mini-oln/mini-oln.cc,
samples/mini-oln/concept-c++/mini-oln.cc : code for image3d tests,
new lvalue_t and rvalue_t vtypes for mutable images.
* samples/mini-oln/mini-oln.cc,
(oln::Image::rvalue_t) : New typedef.
(oln::Image) : operator() now return a rvalue_t as it is a read
only Image by default
(oln::Image2d), (oln::Image3d) : operator() is now inherited
from oln::Image.
(oln::Mutable_Image) : New.
(oln::Mutable_Image::lvalue) : New typedef.
(oln::switch_image_base_mutable) : New.
(oln::image2d) : split impl_op_parens into two versions returning
rvalue_t and lvalue_t.
(oln::rgb) : new type.
(oln::Iterator3d) : New.
(oln::niter3d) : New.
(oln::Image3d) : New.
* samples/mini-oln/concept-c++/mini-oln.cc:
(oln::concepts::Image::rvalue_t) : New typedef.
(oln::concetps::Image) : operator() now return a rvalue_t as it is
a read only Image by default
(oln::concepts::Mutable_Image) : New.
(oln::concetps::Mutable_Image::lvalue) : New typedef.
(oln::image_mutability_switch) : New.
(oln::image2d) : split impl_op_parens into two versions returning
rvalue_t and lvalue_t.
(oln::Iterator3d) : New.
(oln::niter3d) : New.
(oln::Image3d) : New.
concept-c++/mini-oln.cc | 292 +++++++++++++++++++++++++++++++++--------
mini-oln.cc | 339 ++++++++++++++++++++++++++++++++++++++++++------
2 files changed, 538 insertions(+), 93 deletions(-)
Index: samples/mini-oln/mini-oln.cc
--- samples/mini-oln/mini-oln.cc (revision 888)
+++ samples/mini-oln/mini-oln.cc (working copy)
@@ -33,7 +33,7 @@
#include <mlc/case.hh>
#include <stc/any.hh>
#include <stc/scoop.hh>
-
+#include <iostream>
/*-------------.
| Equipement. |
@@ -47,7 +47,7 @@
typename oln_type_of_(FromType, Alias)
// Add equipment
-stc_scoop_equipment_for_namespace(oln);
+stc_scoop_equipment_for_namespace(oln)
mlc_case_equipment_for_namespace(oln);
// Virtual types declaration.
@@ -56,6 +56,8 @@
mlc_decl_typedef(point_type);
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
+ mlc_decl_typedef(rvalue_type);
+ mlc_decl_typedef(lvalue_type);
mlc_decl_typedef(nbh_type);
mlc_decl_typedef(niter_type);
@@ -118,9 +120,9 @@
struct Image : public stc::any<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
+ typedef oln_type_of(E, rvalue) rvalue_t;
- value_t& operator ()(point_t& p)
+ rvalue_t operator ()(point_t& p) const
{
return this->exact().impl_op_parens(p);
}
@@ -137,16 +139,18 @@
// --------- //
template <typename E>
- struct Image2d : public Image<E>
+ struct Image2d : public virtual Image<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
+ // inherited from Image
+
+ // typedef oln_type_of(E, rvalue) rvalue_t;
+
+ // rvalue_t& operator ()(point_t& p)
+ // {
+ // return this->exact().impl_op_parens(p);
+ // }
int nrows_get() const
{
@@ -165,16 +169,18 @@
// --------- //
template <typename E>
- struct Image3d : public Image<E>
+ struct Image3d : public virtual Image<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
+ // inherited from Image
+
+ // typedef oln_type_of(E, rvalue) rvalue_t;
+
+ // rvalue_t& operator ()(point_t& p)
+ // {
+ // return this->exact().impl_op_parens(p);
+ // }
int nrows_get() const
{
@@ -193,12 +199,29 @@
};
+ // ------------- //
+ // Mutable_Image //
+ // ------------- //
+
+ template <typename E>
+ struct Mutable_Image : public virtual Image<E>
+ {
+ typedef oln_type_of(E, point) point_t;
+ typedef oln_type_of(E, lvalue) lvalue_t;
+
+ lvalue_t operator ()(point_t& p)
+ {
+ return this->exact().impl_op_parens(p);
+ }
+ };
+
+
// ------------------------- //
// Image_with_neighborhood. //
// ------------------------- //
template <typename E>
- struct Image_with_neighborhood : public Image<E>
+ struct Image_with_neighborhood : public virtual Image<E>
{
typedef oln_type_of(E, nbh) nbh_t;
typedef oln_type_of(E, niter) niter_t;
@@ -249,6 +272,25 @@
typedef Image<E> ret;
};
+ // ----------------- //
+ // Mutability Switch //
+ // ----------------- //
+
+ // Tag.
+ struct switch_image_base_mutable;
+
+ template <typename E>
+ struct case_<switch_image_base_mutable, E, 1> :
+ public mlc::where_ < mlc::is_found_< stc_vtype(oln, E, lvalue) > >
+ {
+ typedef Mutable_Image<E> ret;
+ };
+
+ template <typename E>
+ struct default_case_<switch_image_base_mutable, E>
+ {
+ typedef Image<E> ret;
+ };
// ------------ //
// Image base. //
@@ -269,13 +311,16 @@
typedef stc::abstract point_type;
typedef stc::abstract iter_type;
typedef stc::abstract value_type;
+ typedef stc::abstract rvalue_type;
+ typedef stc::abstract lvalue_type;
typedef mlc::none niter_type;
typedef mlc::none nbh_type;
};
template <typename E>
- struct image_base : public switch_<switch_image_base, E>::ret
+ struct image_base : public virtual switch_<switch_image_base, E>::ret,
+ public virtual switch_<switch_image_base_mutable, E>::ret
{
image_base()
{
@@ -362,7 +407,7 @@
return p.row < nrows;
}
- point_t& impl_op_point_type()
+ point_t impl_op_point_type() const
{
return p;
}
@@ -393,6 +438,8 @@
typedef point2d point_type;
typedef iterator2d iter_type;
typedef T value_type;
+ typedef value_type rvalue_type;
+ typedef value_type& lvalue_type;
};
template <typename T>
@@ -402,18 +449,24 @@
typedef oln_type_of(self_t, point) point_t;
typedef oln_type_of(self_t, iter) iter_t;
typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
image2d(int nrows, int ncols) :
- data (0),
nrows (nrows),
- ncols (ncols)
+ ncols (ncols),
+ data (nrows * ncols)
{
- data = new std::vector<value_t>;
}
- value_t& impl_op_parens(const point_t& p)
+ rvalue_t impl_op_parens(const point_t& p) const
{
- return this->data[p.row * nrows + p.col];
+ return this->data[p.row * ncols + p.col];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
+ {
+ return this->data[p.row * ncols + p.col];
}
int impl_nrows_get() const
@@ -433,12 +486,11 @@
}
protected:
- std::vector<value_t>* data;
int nrows;
int ncols;
+ std::vector<value_t> data;
};
-
// ----------------- //
// Neighborhood 2d. //
// ----------------- //
@@ -451,6 +503,172 @@
};
+ // ------------- //
+ // Iterator 3d. //
+ // ------------- //
+
+ // Forward declarations.
+ struct iterator3d;
+ template <typename T> struct image3d;
+
+ template<>
+ struct set_super_type<iterator3d>
+ {
+ typedef mlc::none ret;
+ };
+
+ template <>
+ struct vtypes<iterator3d>
+ {
+ typedef point3d point_type;
+ };
+
+ struct iterator3d : public Iterator<iterator3d>
+ {
+ typedef oln_type_of_(iterator3d, point) point_t;
+
+ template <typename T>
+ iterator3d(image3d<T>& ima) :
+ nrows (ima.nrows_get()),
+ ncols (ima.ncols_get()),
+ nslis (ima.nslis_get())
+ {
+ }
+
+ void impl_start()
+ {
+ p.row = 0;
+ p.col = 0;
+ p.sli = 0;
+ }
+
+ void impl_next()
+ {
+ p.sli = p.sli + 1;
+
+ if (p.sli == nslis)
+ {
+ p.sli = 0;
+ p.col = p.col + 1;
+ }
+
+ if (p.col == ncols)
+ {
+ p.col = 0;
+ p.row = p.row + 1;
+ }
+ }
+
+ bool impl_is_valid() const
+ {
+ return p.row < nrows;
+ }
+
+ point_t impl_op_point_type() const
+ {
+ return p;
+ }
+
+ protected:
+ int nrows;
+ int ncols;
+ int nslis;
+ point_t p;
+ };
+
+ // ---------- //
+ // Image 3d. //
+ // ---------- //
+
+ // Forward declaration.
+ template <typename T> struct image3d;
+
+ template<typename T>
+ struct set_super_type< image3d<T> >
+ {
+ typedef image_base< image3d<T> > ret;
+ };
+
+ template <typename T>
+ struct vtypes< image3d<T> >
+ {
+ typedef point3d point_type;
+ typedef iterator3d iter_type;
+ typedef T value_type;
+ typedef value_type rvalue_type;
+ typedef value_type& lvalue_type;
+ };
+
+ template <typename T>
+ struct image3d : public image_base< image3d<T> >
+ {
+ typedef image3d<T> self_t;
+ typedef oln_type_of(self_t, point) point_t;
+ typedef oln_type_of(self_t, iter) iter_t;
+ typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
+
+ image3d(int nrows, int ncols, int nslis) :
+ nrows (nrows),
+ ncols (ncols),
+ nslis (nslis),
+ data (nrows * ncols * nslis)
+ {
+ }
+
+ rvalue_t impl_op_parens(const point_t& p) const
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ int impl_nrows_get() const
+ {
+ return nrows;
+ }
+
+ int impl_ncols_get() const
+ {
+ return ncols;
+ }
+
+ int nslis_get() const
+ {
+ return nslis;
+ }
+
+ bool impl_has(point_t& p) const
+ {
+ assert(!!data);
+ return p.row >= 0 && p.row < nrows && p.col >= 0 && p.col < ncols
+ && p.sli >= 0 && p.sli < nslis;
+ }
+
+ protected:
+ int nrows;
+ int ncols;
+ int nslis;
+ std::vector<value_t> data;
+ };
+
+
+ // ----------------- //
+ // Neighborhood 3d. //
+ // ----------------- //
+
+ struct niter3d {};
+
+ struct neighborhood3d
+ {
+ typedef niter3d niter_type;
+ };
+
+
// --------------- //
// Image morpher. //
// --------------- //
@@ -542,8 +760,32 @@
return res;
}
+ template <typename T>
+ struct rgb
+ {
+ public:
+ rgb () : data_(3) {}
+ T& r_get() { return data_[0]; }
+ T& g_get() { return data_[1]; }
+ T& b_get() { return data_[2]; }
+ T r_get() const { return data_[0]; }
+ T g_get() const { return data_[1]; }
+ T b_get() const { return data_[2]; }
+ T& operator[] (int i) { assert(i >= 0 && i < 3); return data_[i]; }
+ T operator[] (int i) const { assert(i >= 0 && i < 3); return data_[i]; }
+
+ private:
+ std::vector<T> data_;
+ };
+
} // End of namespace oln.
+/*-----------------.
+| Useful Typedefs |
+`-----------------*/
+
+//template <typename T>
+//typedef image2d< rgb<T> > image2d_rgb<T>;
/*--------------.
| Client code. |
@@ -554,24 +796,47 @@
using namespace oln;
point2d p;
- typedef image2d<int> ima_t;
- ima_t ima1(10, 10);
+ typedef image2d<int> ima_2D_t;
+ ima_2D_t ima1(10, 10);
- iterator2d it(ima1);
+ iterator2d it_2D(ima1);
- typedef neighborhood2d nbh_t;
+ typedef neighborhood2d nbh_2D_t;
// A type of image with neighborhood2d.
- typedef plus<ima_t, nbh_t> ima_wih_nbh_t;
- neighborhood2d nbh;
- ima_wih_nbh_t ima2(ima1, nbh);
+ typedef plus<ima_2D_t, nbh_2D_t> ima_wih_nbh_2D_t;
+ neighborhood2d nbh_2D;
+ ima_wih_nbh_2D_t ima2(ima1, nbh_2D);
// Another way to build an image with neigborhood.
- ima_wih_nbh_t ima3 = ima1 + nbh;
+ ima_wih_nbh_2D_t ima3 = ima1 + nbh_2D;
- // FIXME: Same with 3d.
+ // Same with 3d.
point3d q;
+ typedef image3d<int> ima_3D_t;
+ ima_3D_t ima1_3D(2, 2, 2);
+
+ iterator3d it_3D(ima1_3D);
+
+ typedef neighborhood3d nbh_3D_t;
+
+ // A type of image with neighborhood3d.
+ typedef plus<ima_3D_t, nbh_3D_t> ima_wih_nbh_3D_t;
+ neighborhood3d nbh_3D;
+ ima_wih_nbh_3D_t ima2_3D(ima1_3D, nbh_3D);
+ // Another way to build an image with neigborhood.
+ ima_wih_nbh_3D_t ima3_3D = ima1_3D + nbh_3D;
+
+ std::cout << "Show a 3D Image" << std::endl;
+ for (it_3D.start(); it_3D.is_valid(); it_3D.next())
+ {
+ point3d runner = it_3D;
+ std::cout << "[" << runner.row << ", " << runner.col << ", " << runner.sli << "] " << ima1_3D(runner) << std::endl;
+ }
// ...
+
+ rgb<int> tst;
+ std::cout << tst.r_get();
}
Index: samples/mini-oln/concept-c++/mini-oln.cc
--- samples/mini-oln/concept-c++/mini-oln.cc (revision 888)
+++ samples/mini-oln/concept-c++/mini-oln.cc (working copy)
@@ -49,7 +49,7 @@
typename oln_type_of_(FromType, Alias)
// Add equipment
-stc_scoop_equipment_for_namespace(oln);
+stc_scoop_equipment_for_namespace(oln)
mlc_case_equipment_for_namespace(oln);
// Virtual types declaration.
@@ -58,6 +58,8 @@
mlc_decl_typedef(point_type);
mlc_decl_typedef(iter_type);
mlc_decl_typedef(value_type);
+ mlc_decl_typedef(rvalue_type);
+ mlc_decl_typedef(lvalue_type);
mlc_decl_typedef(nbh_type);
mlc_decl_typedef(niter_type);
@@ -73,37 +75,20 @@
namespace concepts
{
- // These concepts are not automatic (i.e., prefixed with `auto'),
- // since we cannot rely on type signatures for them. For instance,
- // using only structural conformance, oln::point3d could be a model
- // of concepts::Point2d!
- concept Point2d<typename P>
+ auto concept Point<typename I>
{
typename coord_type;
- // For simplicity purpose, the canonical model of
- // concepts::Point2d -- oln::point2d -- does not expose its
- // interface through methods (that's bad OO software engineering
- // practice, but hey, we're just prototyping here). Therefore we
- // cannot express sigatures on row and col accesses, since C++0x
- // concepts forbid attribute (member) signatures.
- };
-
- concept Point3d<typename P>
- {
- typename coord_type;
- // Same remark as above for concepts::Point2d regarding member
- // signatures.
};
auto concept Image<typename I>
{
typename point_t;
typename iter_t;
- typename value_t;
+ typename rvalue_t;
// ConceptGCC doesn't support operator signatures yet.
#if 0
- value_t& I::operator ()(point_t&);
+ rvalue_t I::operator ()(point_t&) const;
#endif
bool I::has(const point_t&) const;
};
@@ -121,6 +106,16 @@
int I::nslis_get() const;
};
+ auto concept Mutable_Image<typename I> : Image<I>
+ {
+ typename lvalue_t;
+
+ // ConceptGCC doesn't support operator signatures yet.
+#if 0
+ lvalue_t I::operator ()(point_t&);
+#endif
+ };
+
} // End of namespace oln::concepts.
} // End of namespace oln.
@@ -182,9 +177,9 @@
struct Image : public stc::any<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
+ typedef oln_type_of(E, rvalue) rvalue_t;
- value_t& operator ()(point_t& p)
+ rvalue_t operator ()(point_t& p) const
{
return this->exact().impl_op_parens(p);
}
@@ -204,13 +199,6 @@
struct Image2d : public Image<E>
{
typedef oln_type_of(E, point) point_t;
- typedef oln_type_of(E, value) value_t;
-
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
int nrows_get() const
{
@@ -234,12 +222,6 @@
typedef oln_type_of(E, point) point_t;
typedef oln_type_of(E, value) value_t;
- // FIXME: delete?
- value_t& operator ()(point_t& p)
- {
- return this->exact().impl_op_parens(p);
- }
-
int nrows_get() const
{
return this->exact().impl_nrows_get();
@@ -273,6 +255,22 @@
}
};
+ // ------------- //
+ // Mutable_Image //
+ // ------------- //
+
+ template <typename E>
+ struct Mutable_image : public Image<E>
+ {
+ typedef oln_type_of(E, lvalue) lvalue_t;
+ typedef oln_type_of(E, point) point_t;
+
+ lvalue_t operator ()(point_t& p)
+ {
+ return this->exact().impl_op_parens(p);
+ }
+ };
+
} // End of namespace oln.
@@ -301,7 +299,7 @@
// Concept-based overloading for Image2d.
template <typename E>
- requires concepts::Point2d< oln_type_of(E, point) >
+ requires concepts::Point< oln_type_of(E, point) >
struct image_dimension_switch<E> : public oln::Image2d<E>
{
public:
@@ -315,7 +313,7 @@
// Concept-based overloading for Image3d.
template <typename E>
- requires concepts::Point3d< oln_type_of(E, point) >
+ requires concepts::Point< oln_type_of(E, point) >
struct image_dimension_switch<E> : public oln::Image3d<E>
{
public:
@@ -327,6 +325,26 @@
}
};
+ // ----------------- //
+ // Mutability Switch //
+ // ----------------- //
+
+ // Forward Declaration
+ template <typename E> struct image_mutability_switch;
+
+ template <typename E>
+ requires concepts::Mutable_Image<E>
+ struct image_mutability_switch : public oln::Mutable_Image<E>
+ {
+ public:
+ image_dimension_switch()
+ {
+ std::cout << "image_mutability_switch<E> "
+ << "requires oln::concepts::Mutable_Image<E>"
+ << std::endl;
+ }
+ };
+
// ------------ //
// Image base. //
@@ -388,21 +406,6 @@
coord_type sli;
};
- // Explicitly map point2d and point3d to their concepts.
- namespace concepts
- {
- concept_map Point2d<oln::point2d>
- {
- typedef oln::point2d::coord_type coord_type;
- };
-
- concept_map Point3d<oln::point3d>
- {
- typedef oln::point2d::coord_type coord_type;
- };
-
- } // End of namespace oln::concepts
-
// ------------- //
// Iterator 2d. //
@@ -488,6 +491,8 @@
typedef point2d point_type;
typedef iterator2d iter_type;
typedef T value_type;
+ typedef T rvalue_type;
+ typedef T& lvalue_type;
};
template <typename T>
@@ -497,16 +502,23 @@
typedef oln_type_of(self_t, point) point_t;
typedef oln_type_of(self_t, iter) iter_t;
typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
image2d(int nrows, int ncols) :
data (0),
nrows (nrows),
ncols (ncols)
{
- data = new std::vector<value_t>;
+ data = new value_t[nrows * ncols];
}
- value_t& impl_op_parens(const point_t& p)
+ rvalue_t impl_op_parens(const point_t& p) const
+ {
+ return this->data[p.row * nrows + p.col];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
{
return this->data[p.row * nrows + p.col];
}
@@ -528,7 +540,7 @@
}
protected:
- std::vector<value_t>* data;
+ value_t* data;
int nrows;
int ncols;
};
@@ -546,6 +558,174 @@
};
+ // ------------- //
+ // Iterator 3d. //
+ // ------------- //
+
+ // Forward declarations.
+ struct iterator3d;
+ template <typename T> struct image3d;
+
+ template<>
+ struct set_super_type<iterator3d>
+ {
+ typedef mlc::none ret;
+ };
+
+ template <>
+ struct vtypes<iterator3d>
+ {
+ typedef point3d point_type;
+ };
+
+ struct iterator3d : public Iterator<iterator3d>
+ {
+ typedef oln_type_of_(iterator2d, point) point_t;
+
+ template <typename T>
+ iterator3d(image3d<T>& ima) :
+ nrows (ima.nrows_get()),
+ ncols (ima.ncols_get()).
+ nslis (ima.nslis_get())
+ {
+ }
+
+ void impl_start()
+ {
+ p.row = 0;
+ p.col = 0;
+ p.sli = 0;
+ }
+
+ void impl_next()
+ {
+ p.sli = p.sli + 1;
+
+ if (p.sli == nslis)
+ {
+ p.sli = 0;
+ p.col = p.col + 1;
+ }
+
+ if (p.col == ncols)
+ {
+ p.col = 0;
+ p.row = p.row + 1;
+ }
+ }
+
+ bool impl_is_valid() const
+ {
+ return p.row < nrows;
+ }
+
+ point_t& impl_op_point_type()
+ {
+ return p;
+ }
+
+ protected:
+ int nrows;
+ int ncols;
+ int nslis;
+ point_t p;
+ };
+
+
+ // ---------- //
+ // Image 3d. //
+ // ---------- //
+
+ // Forward declaration.
+ template <typename T> struct image3d;
+
+ template<typename T>
+ struct set_super_type< image3d<T> >
+ {
+ typedef image_base< image3d<T> > ret;
+ };
+
+ template <typename T>
+ struct vtypes< image3d<T> >
+ {
+ typedef point3d point_type;
+ typedef iterator3d iter_type;
+ typedef T value_type;
+ typedef T rvalue_type;
+ typedef T& lvalue_type;
+ };
+
+ template <typename T>
+ struct image3d : public image_base< image3d<T> >
+ {
+ typedef image2d<T> self_t;
+ typedef oln_type_of(self_t, point) point_t;
+ typedef oln_type_of(self_t, iter) iter_t;
+ typedef oln_type_of(self_t, value) value_t;
+ typedef oln_type_of(self_t, rvalue) rvalue_t;
+ typedef oln_type_of(self_t, lvalue) lvalue_t;
+
+ image3d(int nrows, int ncols, int nslis) :
+ data (0),
+ nrows (nrows),
+ ncols (ncols),
+ nslis (nslis)
+ {
+ data = new value_t[nrows * ncols * nslis];
+ }
+
+ rvalue_t impl_op_parens(const point_t& p) const
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ lvalue_t impl_op_parens(const point_t& p)
+ {
+ return this->data[p.row * ncols * nslis + p.col * nslis + p.sli];
+ }
+
+ int impl_nrows_get() const
+ {
+ return nrows;
+ }
+
+ int impl_ncols_get() const
+ {
+ return ncols;
+ }
+
+ int impl_nslis_get() const
+ {
+ return nslis;
+ }
+
+ bool impl_has(point_t& p) const
+ {
+ assert(!!data);
+ return p.row >= 0 && p.row < nrows && p.col >= 0 && p.col < ncols
+ && p.sli >= 0 && p.sli < nslis;
+ }
+
+ protected:
+ value_t* data;
+ int nrows;
+ int ncols;
+ int nslis;
+ };
+
+
+ // ----------------- //
+ // Neighborhood 3d. //
+ // ----------------- //
+
+ struct niter3d {};
+
+ struct neighborhood3d
+ {
+ typedef niter3d niter_type;
+ };
+
+
// --------------- //
// Image morpher. //
// --------------- //
1
0
19 Mar '07
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Clean-up morpho, accumulators, and vtypes in base classes.
* oln/morpho/erosion.hh: Rename as...
* oln/morpho/elementary_erosion.hh: ...this.
(erosion): Rename as...
(elementary_erosion): ...this and update.
* oln/core/concept/function.hh (Accumulator): Move to...
* oln/core/concept/accumulator.hh: ...this new file.
* oln/accumulator/: New.
* oln/function/min.hh: Rename as...
* oln/accumulator/min.hh: ...this.
Split decls and defs.
* oln/core/internal/dpoint_nd.hh: Remove; obsolete.
* oln/level/apply.hh (apply_local): Uncomment and move to...
* oln/level/apply_local.hh: ...this new file.
* oln/level/apply.hh (apply_inplace): Uncomment and move to...
* oln/level/apply_inplace.hh: ...this new file.
* oln/level/local.hh: Fix sigs.
* oln/core/init.hh (init): Strengthen sigs with Any.
* oln/core/equipment.hh (argument, oln_argument): New.
(oln_dim, oln_dpoint, oln_grid): New.
(include): Reject init.hh to end of file.
* oln/core/gen/fun.hh (fun_v2v_, functorize_v2v): New.
* oln/core/internal/point_base.hh,
* oln/core/internal/dpoint_base.hh,
* oln/core/internal/point_set_base.hh,
* oln/core/internal/window_base.hh,
* oln/core/internal/neighborhood_base.hh,
* oln/core/internal/image_base.hh: Simplify type deductions.
accumulator/min.hh | 58 ++++++++++---
core/concept/accumulator.hh | 60 +++++++++++++
core/concept/function.hh | 12 --
core/equipment.hh | 18 +++-
core/gen/fun.hh | 51 +++++++++++
core/init.hh | 26 ++---
core/internal/dpoint_base.hh | 2
core/internal/image_base.hh | 9 --
core/internal/neighborhood_base.hh | 2
core/internal/point_base.hh | 2
core/internal/point_set_base.hh | 5 -
core/internal/window_base.hh | 2
level/apply.hh | 143 ++++----------------------------
level/apply_inplace.hh | 162 +++++--------------------------------
level/apply_local.hh | 153 ++++------------------------------
level/local.hh | 38 +++-----
morpho/elementary_erosion.hh | 42 +++++----
17 files changed, 300 insertions(+), 485 deletions(-)
Index: oln/accumulator/min.hh
--- oln/accumulator/min.hh (revision 0)
+++ oln/accumulator/min.hh (working copy)
@@ -25,43 +25,73 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef _FUNCTION_MIN_HH
-# define _FUNCTION_MIN_HH
+#ifndef OLN_ACCUMULATOR_MIN_HH
+# define OLN_ACCUMULATOR_MIN_HH
-#include <oln/core/concept/functions.hh>
+# include <oln/core/concept/accumulator.hh>
#include <oln/core/internal/max_value.hh>
namespace oln
{
- namespace function
+ namespace accumulator
{
template <typename T>
- struct min_ : public oln::Accumulator< min_<T> >
+ struct min_ : public Accumulator< min_<T> >
{
typedef T argument;
typedef T result;
- min_() { this->init(); }
+ min_();
- void init() const { val_ = oln_max(T); }
- result value() const { return val_; }
+ void init() const;
+ result value() const;
template <typename U>
- void operator()(U i) const
- {
- if (i < val_)
- val_ = static_cast<T>(i);
- }
+ void operator()(U i) const;
private:
mutable T val_;
};
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename T>
+ min_<T>::min_()
+ {
+ this->init();
+ }
+
+ template <typename T>
+ void
+ min_<T>::init() const
+ {
+ this->val_ = oln_max(T);
+ }
+
+ template <typename T>
+ typename min_<T>::result
+ min_<T>::value() const
+ {
+ return this->val_;
}
+ template <typename T>
+ template <typename U>
+ void
+ min_<T>::operator()(U i) const
+ {
+ if (i < this->val_)
+ this->val_ = static_cast<T>(i);
}
-#endif // ! OLN_FUNCTION_MIN_HH
+# endif // ! OLN_INCLUDE_ONLY
+
+ } // end of namespace oln::accumulator
+
+} // end of namespace oln
+
+#endif // ! OLN_ACCUMULATOR_MIN_HH
Index: oln/morpho/elementary_erosion.hh
--- oln/morpho/elementary_erosion.hh (revision 886)
+++ oln/morpho/elementary_erosion.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -26,11 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHO_EROSION_HH
-# define OLN_MORPHO_EROSION_HH
+#ifndef OLN_MORPHO_ELEMENTARY_EROSION_HH
+# define OLN_MORPHO_ELEMENTARY_EROSION_HH
+
+#include <oln/level/apply_local.hh>
+#include <oln/accumulator/min.hh>
-#include <oln/level/local.hh>
-#include <oln/function/min.hh>
namespace oln
{
@@ -38,8 +38,12 @@
namespace morpho
{
+ // Fwd decl.
+
template <typename I>
- I erosion(const Image_with_Nbh<I>& input);
+ oln_plain(I)
+ elementary_erosion(const Image_with_Nbh<I>& input);
+
# ifndef OLN_INCLUDE_ONLY
@@ -49,24 +53,30 @@
/// Generic version
template <typename I>
- I erosion(const Image_with_Nbh<I>& input)
+ oln_plain(I)
+ elementary_erosion_(const Image_with_Nbh<I>& input)
{
- function::min_<oln_value(I)> min;
- return ::oln::level::apply_local(min, input);
- }
+ accumulator::min_<oln_value(I)> min;
+ return level::apply_local(min, input);
}
+ } // end of namespace oln::morpho::impl
+
+
// Facade.
template <typename I>
- I erosion(const Image_with_Nbh<I>& input)
+ oln_plain(I)
+ elementary_erosion(const Image_with_Nbh<I>& input)
{
- return impl::erosion(exact(input));
+ return impl::elementary_erosion_(exact(input));
}
#endif // ! OLN_INCLUDE_ONLY
- } // end of namespace
-}
+ } // end of namespace oln::morpho
+
+} // end of namespace oln
+
-#endif // ! OLN_MORPHO_EROSION_HH
+#endif // ! OLN_MORPHO_ELEMENTARY_EROSION_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 887)
+++ oln/level/apply.hh (working copy)
@@ -30,9 +30,9 @@
# define OLN_LEVEL_APPLY_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
+# include <oln/core/gen/fun.hh>
# include <oln/core/internal/f_ch_value.hh>
-# include <oln/level/local.hh>
+
namespace oln
{
@@ -40,24 +40,15 @@
namespace level
{
- /// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
-
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
+ /// Fwd decls.
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply(const Function_v2v<F>& f, const Image<I>& input);
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+ template <typename R, typename A, typename I>
+ oln_plain_value(I, R)
+ apply(R (*f)(A), const Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,138 +56,42 @@
namespace impl
{
- /// apply
+ // Generic version.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
+ apply_(const F& f, const Image<I>& input)
{
- typedef typename F::result result;
typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
-
- template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
- {
typedef typename F::result result;
- typedef typename F::argument argument;
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
+ oln_plain_value(I, result) output;
+ init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = level::local(f, input, p);
+ output(p) = f(input(p));
return output;
}
-
-// /// Generic version.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_plain_value(I, typename F::result_value) output(input.topo());
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// output(p) = fun.exact()(input(p));
-// return output;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
-
- /// Apply.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ /// Facades.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
+ apply(const Function_v2v<F>& f, const Image<I>& input)
{
- return impl::apply(f, exact(input));
+ return impl::apply_(exact(f), exact(input));
}
- /// Apply local
-
template <typename R, typename A, typename I>
oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
- const Image_with_Nbh<I>& input)
+ apply(R (*f)(A), const Image<I>& input)
{
- return impl::apply_local(fun, input);
+ return impl::apply_(functorize_v2v(f), exact(input));
}
-// /// Facade.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply(input, fun);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
# endif
Index: oln/level/local.hh
--- oln/level/local.hh (revision 887)
+++ oln/level/local.hh (working copy)
@@ -29,11 +29,9 @@
# define OLN_LEVEL_LOCAL_HH
#include <oln/core/concept/image.hh>
-#include <oln/core/concept/point.hh>
-#include <oln/core/concept/functions.hh>
#include <oln/core/concept/window.hh>
-#include <oln/core/concept/iterator.hh> // bizarre
-#include <oln/core/equipment.hh>
+# include <oln/core/concept/accumulator.hh>
+
namespace oln
{
@@ -42,7 +40,7 @@
{
template <typename A, typename I>
- int //typename A::result
+ typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p);
@@ -54,37 +52,32 @@
const oln_point(I)& p,
const Window<W>& win);
+
# ifndef OLN_INCLUDE_ONLY
namespace impl
{
- /// Local Apply on neighborhood (nbh included in image).
+ // Generic version with neighborhood.
template <typename A, typename I>
- int//typename A::result
+ typename A::result
local_(const A& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
f.init();
- oln_niter(I) n(p, input.points());
+ oln_niter(I) n(p, input.nbhood()); // FIXME: 2nd arg should be 'input'!
for_all(n)
f(input(n));
return f.value();
}
- /// Local Apply on neighborhood (nhb given as argument).
-
- // ...FIXME
+ // FIXME: Generic version with nbh given as argument?
- /// Local Apply on window (window included in image).
-
- // ...FIXME
-
- /// Local Apply on window (window is given).
+ // Generic version with window.
template <typename F, typename I, typename W>
typename F::result
@@ -97,16 +90,16 @@
oln_qiter(W) q(p, win);
for_all(q)
f(input(q));
-
return f.value();
}
- }
+ } // end of namespace oln::level::impl
+
- /// Facades.
+ // Facades.
template <typename A, typename I>
- int//typename A::result
+ typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
@@ -126,7 +119,8 @@
#endif // ! OLN_INCLUDE_ONLY
- }
-}
+ } // end of namespace oln::level
+
+} // end of namespace oln
#endif // ! OLN_LEVEL_LOCAL_HH
Index: oln/level/apply_local.hh
--- oln/level/apply_local.hh (revision 886)
+++ oln/level/apply_local.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -26,14 +25,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_LEVEL_APPLY_HH
-# define OLN_LEVEL_APPLY_HH
+#ifndef OLN_LEVEL_APPLY_LOCAL_HH
+# define OLN_LEVEL_APPLY_LOCAL_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
+# include <oln/core/concept/accumulator.hh>
# include <oln/core/internal/f_ch_value.hh>
# include <oln/level/local.hh>
+
namespace oln
{
@@ -41,23 +41,11 @@
{
/// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
-
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
-
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& f,
+ const Image_with_Nbh<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,139 +53,34 @@
namespace impl
{
- /// apply
+ // Generic version.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
- {
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
-
- template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
+ apply_local_(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
+ oln_plain_value(I, typename F::result) output;
+ init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
output(p) = level::local(f, input, p);
return output;
}
-
-// /// Generic version.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_plain_value(I, typename F::result_value) output(input.topo());
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// output(p) = fun.exact()(input(p));
-// return output;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
- /// Apply.
-
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ // Facade.
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
- {
- return impl::apply(f, exact(input));
- }
-
- /// Apply local
-
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
+ apply_local(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
- return impl::apply_local(fun, input);
+ return impl::apply_local_(exact(f), exact(input));
}
-// /// Facade.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply(input, fun);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
# endif
} // end of namespace oln::level
@@ -205,4 +88,4 @@
} // end of namespace oln
-#endif // ! OLN_LEVEL_APPLY_HH
+#endif // ! OLN_LEVEL_APPLY_LOCAL_HH
Index: oln/level/apply_inplace.hh
--- oln/level/apply_inplace.hh (revision 886)
+++ oln/level/apply_inplace.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -26,13 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_LEVEL_APPLY_HH
-# define OLN_LEVEL_APPLY_HH
+#ifndef OLN_LEVEL_APPLY_INPLACE_HH
+# define OLN_LEVEL_APPLY_INPLACE_HH
# include <oln/core/concept/image.hh>
-# include <oln/core/concept/iterator.hh>
-# include <oln/core/internal/f_ch_value.hh>
-# include <oln/level/local.hh>
+# include <oln/core/gen/fun.hh>
+
namespace oln
{
@@ -40,24 +38,15 @@
namespace level
{
- /// Fwd decl.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input);
+ /// Fwd decls.
+ template <typename F, typename I>
+ void
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
-// /// Fwd decl.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun);
-
-// /// Fwd decl.
-// template <typename I, typename V>
-// void apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&));
-
-// /// Fwd decl.
-// template <typename I, typename F>
-// void apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun);
+ template <typename R, typename A, typename I>
+ void
+ apply_inplace(R (*f)(A), Mutable_Image<I>& input);
# ifndef OLN_INCLUDE_ONLY
@@ -65,139 +54,38 @@
namespace impl
{
- /// apply
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply( F& f, const Image<I>& input)
- {
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- oln_ch_value(I, result) output(input.points());
- oln_piter(I) p(input.points());
- for_all(p)
- output(p) = f( static_cast< argument >(input(p)) );
- return output;
- }
-
-
- /// apply_local
+ // Generic version.
template <typename F, typename I>
- I apply_local(const Accumulator<F>& f,
- const Image_with_Nbh<I>& input)
+ void
+ apply_inplace_(const F& f, Mutable_Image<I>& input)
{
- typedef typename F::result result;
- typedef typename F::argument argument;
-
- typename I::delegatee out(input.points());
- I output(out, input.nbhood());
- // I output(exact(input).image(), input.nbhood());
- // FIXME: init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = level::local(f, input, p);
- return output;
+ input(p) = f(input(p));
+ // FIXME: input(p) = static_cast<oln_value(I)>( f_( static_cast<oln_argument(F)>(input(p)) ) );
}
-// /// Generic version.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_plain_value(I, typename F::result_value) output(input.topo());
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// output(p) = fun.exact()(input(p));
-// return output;
-// }
-
-
-// /// Generic version.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun(input(p));
-// }
-
-// /// Generic version.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// oln_piter(I) p(input.topo());
-// for_all(p)
-// input(p) = fun.exact()(input(p));
-// }
-
} // end of namespace oln::level::impl
- /// Facades.
- //----------------------------
-
- /// Apply.
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply(fun, exact(input));
- }
+ /// Facades.
template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply(F& f, const Image<I>& input)
+ void
+ apply_inplace(const Function_v2v<F>& f, Mutable_Image<I>& input)
{
- return impl::apply(f, exact(input));
+ impl::apply_inplace_(exact(f), exact(input));
}
- /// Apply local
-
template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply_local(R (*fun)(A), const Image<I>& input)
- {
- return impl::apply_local(fun, exact(input));
- }
-
- template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
- const Image_with_Nbh<I>& input)
+ void
+ apply_inplace(R (*f)(A), Mutable_Image<I>& input)
{
- return impl::apply_local(fun, input);
+ impl::apply_inplace_(functorize_v2v(fun), exact(input));
}
-// /// Facade.
-// template <typename I, typename F>
-// oln_plain_value(I, typename F::result_value)
-// apply(const abstract::image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply(input, fun);
-// }
-
-
-// /// Facade.
-// template <typename I, typename V>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, V (*fun)(const oln_value(I)&))
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
-// /// Facade.
-// template <typename I, typename F>
-// void
-// apply_inplace(abstract::mutable_image<I>& input, const abstract::fun_v2v<F>& fun)
-// {
-// return impl::apply_inplace(input, fun);
-// }
-
# endif
} // end of namespace oln::level
@@ -205,4 +93,4 @@
} // end of namespace oln
-#endif // ! OLN_LEVEL_APPLY_HH
+#endif // ! OLN_LEVEL_APPLY_INPLACE_HH
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 887)
+++ oln/core/concept/function.hh (working copy)
@@ -90,16 +90,6 @@
};
- // Values -> Value.
-
- template <typename Exact>
- struct Accumulator : public Function<Exact>
- {
- protected:
- Accumulator();
- };
-
-
/*
// Value1 -> Value2 *and* Value2 -> Value1.
@@ -187,7 +177,7 @@
{
}
-# endif // OLN_INCLUDE_ONLY
+# endif // ! OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/concept/accumulator.hh
--- oln/core/concept/accumulator.hh (revision 0)
+++ oln/core/concept/accumulator.hh (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_CONCEPT_ACCUMULATOR_HH
+# define OLN_CORE_CONCEPT_ACCUMULATOR_HH
+
+# include <oln/core/concept/function.hh>
+
+
+namespace oln
+{
+
+ // Values -> Value.
+
+ template <typename Exact>
+ struct Accumulator : public Function<Exact>
+ {
+ protected:
+ Accumulator();
+ };
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ Accumulator<Exact>::Accumulator()
+ {
+ }
+
+# endif // ! OLN_INCLUDE_ONLY
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_CONCEPT_ACCUMULATOR_HH
Index: oln/core/init.hh
--- oln/core/init.hh (revision 887)
+++ oln/core/init.hh (working copy)
@@ -84,19 +84,19 @@
// Regular version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, const Data& data);
+ bool init(Any<Target>& target, with_t, const Any<Data>& data);
// Assignment.
template <typename T>
- bool init(T& target, with_t, const T& data);
+ bool init(Any<T>& target, with_t, const Any<T>& data);
- // Unconst data version.
+ // Unconst->const data version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, Data& data);
+ bool init(Any<Target>& target, with_t, Any<Data>& data);
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Target& target, with_t, const Data& data);
+ bool init(const Any<Target>& target, with_t, const Any<Data>& data);
@@ -145,24 +145,24 @@
// Regular version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, const Data& data)
+ bool init(Any<Target>& target, with_t, const Any<Data>& data)
{
- return init_(&target, data);
+ return init_(exact(&target), exact(data));
}
// Assignment.
template <typename T>
- bool init(T& target, with_t, const T& data)
+ bool init(Any<T>& target, with_t, const Any<T>& data)
{
- target = data;
+ exact(target) = exact(data);
return true;
}
- // Unconst data version.
+ // Unconst->const data version.
template <typename Target, typename Data>
- bool init(Target& target, with_t, Data& data)
+ bool init(Any<Target>& target, with_t, Any<Data>& data)
{
- return init_(&target, const_cast<const Data&>(data));
+ return init(target, const_cast<const Data&>(data));
}
@@ -174,7 +174,7 @@
// Guard: we cannot have "const Target".
template <typename Target, typename Data>
- bool init(const Target&, with_t, const Data&)
+ bool init(const Any<Target>&, with_t, const Any<Data>&)
{
mlc::abort_< Target, ERROR::initialization_of_temporary_or_const_object_<Target> >::check();
return false;
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 887)
+++ oln/core/equipment.hh (working copy)
@@ -34,7 +34,6 @@
# else
# include <stc/scoop-alt.hh>
# endif
-# include <oln/core/init.hh>
# define oln_typename_shortcut__(Type, Alias) typename Type::Alias
@@ -52,6 +51,9 @@
// a
stc_decl_associated_type( adapted );
+ stc_decl_associated_type( argument );
+
+# define oln_argument(T) oln_typename_shortcut__(T, argument)
// b
stc_decl_associated_type( bkd_niter );
@@ -74,6 +76,9 @@
stc_decl_associated_type( dim );
stc_decl_associated_type( dpoint );
+# define oln_dim(T) oln_typename_shortcut__(T, dim)
+# define oln_dpoint(T) oln_typename_shortcut__(T, dpoint)
+
// f
stc_decl_associated_type( fwd_niter );
stc_decl_associated_type( fwd_piter );
@@ -86,6 +91,8 @@
// g
stc_decl_associated_type( grid );
+# define oln_grid(T) oln_typename_shortcut__(T, grid)
+
// i
stc_decl_associated_type( index );
@@ -144,5 +151,14 @@
+/// \{
+/// FIXME: Bad!
+
+# include <oln/core/init.hh>
+
+/// \}
+
+
+
#endif // ! OLN_CORE_EQUIPMENT_HH
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 887)
+++ oln/core/gen/fun.hh (working copy)
@@ -82,6 +82,9 @@
+ // ----------------------------- fun_p2b_<F>
+
+
// Fwd decl.
template <typename F> struct fun_p2b_;
@@ -114,6 +117,54 @@
};
+
+
+ // ----------------------------- fun_v2v_<F>
+
+
+ // Fwd decl.
+ template <typename F> struct fun_v2v_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F>
+ struct set_category_of_< fun_v2v_<F> >
+ {
+ typedef stc::is< Function_v2v > ret;
+ };
+ }
+
+ // Class.
+ template <typename F>
+ struct fun_v2v_ : public Function_v2v< fun_v2v_<F> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) result;
+
+ fun_v2v_(F f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return this->f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+
+ // functorize_v2v
+ template <typename R, typename A>
+ fun_v2v_<R (*)(A)>
+ functorize_v2v(R (*f)(A))
+ {
+ fun_v2v_<R (*)(A)> tmp(f);
+ return tmp;
+ }
+
+
+
} // end of namespace oln
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 887)
+++ oln/core/internal/point_base.hh (working copy)
@@ -57,7 +57,7 @@
typedef stc_deferred(grid) grid__;
// Final:
- typedef stc::final<typename grid__::dim> dim; // FIXME: Propagate this kind of changes.
+ typedef stc::final< oln_dim(grid__) > dim;
typedef stc::final< stc::is<Point> > category;
};
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 887)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -54,7 +54,7 @@
typedef stc::abstract grid;
typedef stc_deferred(grid) grid__;
- typedef stc::final<stc_type(grid__, dim)> dim;
+ typedef stc::final< oln_dim(grid__) > dim;
typedef stc::abstract coord;
typedef stc::abstract point; // FIXME: Just like in point_base.hh
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 887)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -59,9 +59,8 @@
typedef stc_deferred(fwd_piter) fwd_piter__;
typedef stc::final< stc::is<Point_Set> > category;
-
typedef stc::final< box_<point__> > box;
- typedef stc::final<stc_type(point__, grid)> grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final<fwd_piter__> piter;
};
@@ -117,7 +116,7 @@
{
typedef oln_strip_(P) P_;
mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
- mlc::assert_equal_< P_, typename S::point >::check();
+ mlc::assert_equal_< P_, oln_point(S) >::check();
op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f);
return tmp;
}
Index: oln/core/internal/window_base.hh
--- oln/core/internal/window_base.hh (revision 887)
+++ oln/core/internal/window_base.hh (working copy)
@@ -58,7 +58,7 @@
typedef stc_deferred(point) point__;
typedef stc_deferred(fwd_qiter) fwd_qiter__;
- typedef stc::final< stc_type(point__, grid) > grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< fwd_qiter__ > qiter;
};
Index: oln/core/internal/neighborhood_base.hh
--- oln/core/internal/neighborhood_base.hh (revision 887)
+++ oln/core/internal/neighborhood_base.hh (working copy)
@@ -55,7 +55,7 @@
typedef stc::abstract point;
typedef stc_deferred(point) point__;
- typedef stc::final< stc_type(point__, grid) > grid;
+ typedef stc::final< oln_grid(point__) > grid;
typedef stc::final< stc::is<Neighborhood> > category;
};
Index: oln/core/internal/image_base.hh
--- oln/core/internal/image_base.hh (revision 887)
+++ oln/core/internal/image_base.hh (working copy)
@@ -149,10 +149,10 @@
typedef stc::final< stc::is<Image> > category;
typedef stc::final< box_<point__> > box;
- typedef stc::final< stc_type(point__, grid) > grid;
- typedef stc::final< stc_type(point__, dpoint) > dpoint;
- typedef stc::final< typename pset__::fwd_piter > fwd_piter;
- typedef stc::final< typename pset__::bkd_piter > bkd_piter;
+ typedef stc::final< oln_grid(point__) > grid;
+ typedef stc::final< oln_dpoint(point__) > dpoint;
+ typedef stc::final< oln_fwd_piter(pset__) > fwd_piter;
+ typedef stc::final< oln_bkd_piter(pset__) > bkd_piter;
typedef fwd_piter piter;
};
@@ -432,7 +432,6 @@
// init
-
template <typename P, typename I>
bool init_(box_<P>* this_, const internal::image_base_<I>& data);
1
0
Index: ChangeLog
from Nicolas Ballas <ballas(a)lrde.epita.fr>
Clean code.
* oln/core/rle/rle_image.hh, oln/core/rle/rle_psite.hh,
* oln/core/rle/rle_pset.hh, oln/core/encode/sparse_encode.hh: .
* oln/core/encode/rle_encode.hh: clean code, add comments, change comments form...
encode/rle_encode.hh | 12 +++++----
encode/sparse_encode.hh | 15 ++++++-----
rle/rle_image.hh | 30 ++++++++++++-----------
rle/rle_pset.hh | 61 +++++++++++++++++++++++++-----------------------
rle/rle_psite.hh | 19 +++++++-------
5 files changed, 73 insertions(+), 64 deletions(-)
Index: oln/core/rle/rle_image.hh
--- oln/core/rle/rle_image.hh (revision 886)
+++ oln/core/rle/rle_image.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
+// Copyright (C) 2007 EPITA
// Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_IMAGE_HH_
-# define OLN_CORE_RLE_RLE_IMAGE_HH_
+#ifndef OLN_CORE_RLE_RLE_IMAGE_HH
+# define OLN_CORE_RLE_RLE_IMAGE_HH
# include <map>
# include <utility>
@@ -78,13 +78,6 @@
** \class rle_image
** \brief rle image (use a pair of point range and value as representation)
**
- ** method:
- ** pset impl_points() const : return image pset
- ** bool impl_has(const point& p) const : rle_image has p?
- ** bool impl_owns_(const psite& p) const : same has impl_has
- ** void insert(const point& p, unsigned len, value val) : insert a new range on the image
- ** rvalue impl_read(const psite& p) const : return value associated to psite (for reading)
- ** lvalue impl_read_write(const psite& p) : lvalue impl_read_write(const psite& p) (for writing)
*/
template < typename P, typename T>
class rle_image : public internal::primitive_image_< rle_image<P, T> >
@@ -103,11 +96,17 @@
rle_image();
+ /// 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
void insert(const point& p, unsigned len, value val);
+ /// rvalue impl_read(const psite& p) const : return value associated to psite (for reading)
rvalue impl_read(const psite& p) const;
+ /// lvalue impl_read_write(const psite& p) : lvalue impl_read_write(const psite& p) (for writing)
lvalue impl_read_write(const psite& p);
};
@@ -143,7 +142,8 @@
template <typename P, typename T>
void
- rle_image<P, T>::insert(const typename rle_image<P, T>::point& p, unsigned len, rle_image<P, T>::value val)
+ rle_image<P, T>::insert(const typename rle_image<P, T>::point& p,
+ unsigned len, rle_image<P, T>::value val)
{
this->data_->first.insert(p, len);
this->data_->second[p] = val;
@@ -156,7 +156,8 @@
typename std::map<point, value>::const_iterator irun;
irun = this->data_->second.find(ps.start_);
- assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
+ assert(irun != this->data_->second.end() &&
+ ps.index_ < this->data_->first.range_len_(ps.start_));
return irun->second;
}
@@ -167,7 +168,8 @@
typename std::map<point, value>::iterator irun;
irun = this->data_->second.find(ps.start_);
- assert(irun != this->data_->second.end() && ps.index_ < this->data_->first.range_len_(ps.start_));
+ assert(irun != this->data_->second.end() &&
+ ps.index_ < this->data_->first.range_len_(ps.start_));
return irun->second;
}
@@ -175,4 +177,4 @@
} // end of namespace oln
-#endif /* !OLN_CORE_RLE_RLE_IMAGE_HH_ */
+#endif // !OLN_CORE_RLE_RLE_IMAGE_HH
Index: oln/core/rle/rle_psite.hh
--- oln/core/rle/rle_psite.hh (revision 886)
+++ oln/core/rle/rle_psite.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_PSITE_HH_
-# define OLN_CORE_RLE_RLE_PSITE_HH_
+#ifndef OLN_CORE_RLE_RLE_PSITE_HH
+# define OLN_CORE_RLE_RLE_PSITE_HH
# include <map>
@@ -44,9 +44,6 @@
** \brief psite for rle image
**
** Note: P must be a point type
- ** method:
- ** to_point: convert the psite to corresponding point
- ** operator P(): convert psite to the corresponding point
*/
template <typename P>
class rle_psite
@@ -54,11 +51,15 @@
public:
rle_psite();
+ // to_point: convert the psite to corresponding point
P to_point() const;
+ // operator P(): convert psite to the corresponding point
operator P () const;
- P start_; /*!< start of the range which contains the psite */
- unsigned index_; /*!< index of the point in the range */
+ /// start of the range which contains the psite
+ P start_;
+ /// index of the point in the range
+ unsigned index_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -88,4 +89,4 @@
//end of class rle_psite
}
-#endif /* !OLN_CORE_RLE_RLE_PSITE_HH_ */
+#endif // !OLN_CORE_RLE_RLE_PSITE_HH
Index: oln/core/rle/rle_pset.hh
--- oln/core/rle/rle_pset.hh (revision 886)
+++ oln/core/rle/rle_pset.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2006, 2007 EPITA Research and Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_RLE_RLE_PSET_HH_
-# define OLN_CORE_RLE_RLE_PSET_HH_
+#ifndef OLN_CORE_RLE_RLE_PSET_HH
+# define OLN_CORE_RLE_RLE_PSET_HH
# include <set>
# include <utility>
@@ -71,13 +71,6 @@
** \brief pset correspoding to the rle_image class
**
** Note: P must be a point type
- ** method:
- ** unsigned impl_npoints() const : return number of point in the point set
- ** const box& impl_bbox() const : return a box which includes all poin into the set
- ** void insert(const P& p, unsigned len): insert a new range on the point set
- ** bool impl_has(const P& p) const : if p include in the set
- ** const std_container& con() const : return the container of the point
- **
*/
template <typename P>
class rle_pset : public internal::point_set_base_<rle_pset <P> >
@@ -92,17 +85,25 @@
rle_pset();
+ /// unsigned impl_npoints() const : return number of point in the point set
unsigned impl_npoints() const;
+ /// const box& impl_bbox() const : return a box which includes all poin into the set
const box& impl_bbox() const;
+ /// void insert(const P& p, unsigned len): insert a new range on the point set
void insert(const P& p, unsigned len);
+ /// bool impl_has(const P& p) const : if p include in the set
bool impl_has(const P& p) const;
+ /// const std_container& con() const : return the container of the point
const std_container& con() const;
unsigned range_len_(const P& range_len_) const;
protected:
- unsigned npts; /*!< number of point in the set*/
- std_container con_; /*!< container of the set*/
- fbbox_<point> fb_; /*!< pset box*/
+ /// number of point in the set
+ unsigned npts;
+ /// container of the set
+ std_container con_;
+ /// pset box
+ fbbox_<point> fb_;
};
@@ -204,12 +205,6 @@
** \brief foward iterator for rle_pset
**
** P must be a point type
- ** method:
- ** void impl_start(): set the iterator to the start of pset
- ** void impl_next(): go to next point
- ** void impl_invalidate(): invalidate iterator
- ** void impl_valid(): is the iterator valid?
- ** + conversions methods
*/
template <typename P>
class rle_pset_fwd_piter_ : public Iterator_on_Points< rle_pset_fwd_piter_<P> >
@@ -221,11 +216,16 @@
rle_pset_fwd_piter_(const rle_pset<P>& con);
+ /// void impl_start(): set the iterator to the start of pset
void impl_start();
+ /// void impl_next(): go to next point
void impl_next();
+ /// void impl_invalidate(): invalidate iterator
void impl_invalidate();
+ /// void impl_valid(): is the iterator valid?
bool impl_is_valid() const;
+ /// conversion method
const rle_psite<P>& impl_to_psite() const;
point impl_to_point() const;
const point* impl_psite_adr() const;
@@ -235,13 +235,15 @@
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_iterator it_;
- rle_psite<P> ps_; /*!< current point */
+ /// current point
+ rle_psite<P> ps_;
};
# ifndef OLN_INCLUDE_ONLY
template <typename P>
- rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& cont) : con_(cont.con())
+ rle_pset_fwd_piter_<P>::rle_pset_fwd_piter_(const rle_pset<P>& cont) :
+ con_(cont.con())
{
this->it_ = this->con_.end();
}
@@ -340,12 +342,6 @@
** \brief backward iterator for rle_pset
**
** P must be a point type
- ** method:
- ** void impl_start(): set the iterator to the start of pset
- ** void impl_next(): go to next point
- ** void impl_invalidate(): invalidate iterator
- ** void impl_valid(): is the iterator valid?
- ** + conversion method
*/
template <typename P>
class rle_pset_bkd_piter_ : public Iterator_on_Points< rle_pset_bkd_piter_<P> >
@@ -357,10 +353,16 @@
rle_pset_bkd_piter_(const rle_pset<P>& con);
+ /// void impl_start(): set the iterator to the start of pset
void impl_start();
+ /// void impl_next(): go to next point
void impl_next();
+ /// void impl_invalidate(): invalidate iterator
void impl_invalidate();
+ /// void impl_valid(): is the iterator valid?
bool impl_is_valid() const;
+
+ /// conversion methods
const rle_psite<P>& impl_to_psite() const;
point impl_to_point() const;
const point* impl_psite_adr() const;
@@ -369,7 +371,8 @@
protected:
const typename rle_pset<P>::std_container& con_;
typename rle_pset<P>::std_container::const_reverse_iterator it_;
- rle_psite<P> ps_; /*!< current point*/
+ /// current point
+ rle_psite<P> ps_;
};
# ifndef OLN_INCLUDE_ONLY
@@ -454,4 +457,4 @@
} // end of namespace oln
-#endif /* !OLN_CORE_RLE_RLE_PSET_HH_ */
+#endif // !OLN_CORE_RLE_RLE_PSET_HH
Index: oln/core/encode/sparse_encode.hh
--- oln/core/encode/sparse_encode.hh (revision 886)
+++ oln/core/encode/sparse_encode.hh (working copy)
@@ -1,4 +1,4 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
+// Copyright (C) 2007 EPITA
// Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef SPARSE_ENCODE_HH_
-# define SPARSE_ENCODE_HH_
+#ifndef OLN_CORE_ENCODE_SPARSE_ENCODE_HH
+# define OLN_CORE_ENCODE_SPARSE_ENCODE_HH
# include <oln/core/concept/image.hh>
@@ -61,16 +61,17 @@
return output;
rstart = p;
+
//FIXME: is it generall ?
old = (p.to_point())[0];
- values.push_back(input(p.to_point()));
+ values.push_back(input(p));
p.next();
while (p.is_valid())
{
if ((p.to_point())[0] - 1 == old)
{
++len;
- values.push_back(input(p.to_point()));
+ values.push_back(input(p));
}
else
{
@@ -78,7 +79,7 @@
rstart = p;
len = 1;
values.clear();
- values.push_back(input(p.to_point()));
+ values.push_back(input(p));
}
old = (p.to_point())[0];
p.next();
@@ -88,4 +89,4 @@
}
}
-#endif /* !SPARSE_ENCODE_HH_ */
+#endif // !OLN_CORE_ENCODE_SPARSE_ENCODE_HH
Index: oln/core/encode/rle_encode.hh
--- oln/core/encode/rle_encode.hh (revision 886)
+++ oln/core/encode/rle_encode.hh (working copy)
@@ -26,8 +26,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef RLE_ENCODE_HH_
-# define RLE_ENCODE_HH_
+#ifndef OLN_CORE_ENCODE_RLE_ENCODE_HH
+# define OLN_CORE_ENCODE_RLE_ENCODE_HH
# include <oln/core/concept/image.hh>
@@ -50,8 +50,10 @@
rle_image<typename I::point, typename I::value> output;
typename I::piter p (input.points());
unsigned len = 1;
- typename I::point rstart; /*!< range pointstart */
- typename I::value rvalue; /*!< range value */
+ /// range point start
+ typename I::point rstart;
+ /// range value
+ typename I::value rvalue;
p.start();
if (!p.is_valid())
@@ -78,4 +80,4 @@
}
} // end of namespace oln
-#endif /* !RLE_ENCODE_HH_ */
+#endif /* !OLN_CORE_ENCODE_RLE_ENCODE_HH */
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/olena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the type of 'point set such as f : point -> bool.
* oln/core/concept/functions.hh: Rename as...
* oln/core/concept/function.hh: ...this.
* oln/core/gen/piter_isubset.hh: Rename as...
* oln/core/internal/piter_adaptor.hh: ...this.
* oln/core/gen/fun.hh: New.
* oln/core/internal/op_pset_such_as_fp2b.hh: New.
* oln/core/concept/value.hh (Boolean): New.
* oln/core/2d/grid2d.hh (grid2d_rec): Rename as...
(grid2d): ...this.
(grid2d): Rename as...
(grid2d_rec): ...this.
* oln/core/2d/point2d.hh: Cosmetic change.
* oln/core/equipment.hh (adapted): New.
* oln/core/gen/op.hh (category_of_): Move to...
* oln/core/internal/category_of.hh: ...this new file.
* oln/core/internal/point_base.hh: Add commentary.
* oln/core/internal/dpoint_base.hh (vtypes): Add category.
* oln/core/internal/point_set_base.hh (operator|): New.
(include): Update.
* oln/core/internal/op_image_plus_nbh.hh: Cosmetic change.
* oln/core/internal/special_op.hh (include): Remove image_base.hh.
2d/grid2d.hh | 10 -
2d/point2d.hh | 2
concept/function.hh | 30 ++-
concept/value.hh | 18 +
equipment.hh | 4
gen/fun.hh | 120 ++++++++++++
gen/op.hh | 22 --
gen/pset_such_as.hh | 380 +++++++++++++++++++++++++++++++++++++++
internal/category_of.hh | 124 ++++++++++++
internal/dpoint_base.hh | 4
internal/op_image_plus_nbh.hh | 2
internal/op_pset_such_as_fp2b.hh | 336 ++++++++++++++++++++++++++++++++++
internal/piter_adaptor.hh | 147 +++++----------
internal/point_base.hh | 10 -
internal/point_set_base.hh | 35 +++
internal/special_op.hh | 2
16 files changed, 1119 insertions(+), 127 deletions(-)
Index: oln/core/concept/function.hh
--- oln/core/concept/function.hh (revision 877)
+++ oln/core/concept/function.hh (working copy)
@@ -25,15 +25,18 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_CONCEPT_FUNCTIONS_HH
-# define OLN_CORE_CONCEPT_FUNCTIONS_HH
+#ifndef OLN_CORE_CONCEPT_FUNCTION_HH
+# define OLN_CORE_CONCEPT_FUNCTION_HH
# include <oln/core/equipment.hh>
+
+
namespace oln
{
+
/*
// Fwd decl.
@@ -46,6 +49,10 @@
*/
template <typename Exact>
+ struct Function;
+
+
+ template <typename Exact>
struct Function : public Any<Exact>
{
protected:
@@ -63,6 +70,16 @@
};
+ // Point -> bool.
+
+ template <typename Exact>
+ struct Function_p2b : public Function<Exact>
+ {
+ protected:
+ Function_p2b();
+ };
+
+
// Value -> Value.
template <typename Exact>
@@ -73,7 +90,7 @@
};
- // Neighborhood -> Value.
+ // Values -> Value.
template <typename Exact>
struct Accumulator : public Function<Exact>
@@ -137,6 +154,11 @@
}
template <typename Exact>
+ Function_p2b<Exact>::Function_p2b()
+ {
+ }
+
+ template <typename Exact>
Function_p2v<Exact>::Function_p2v()
{
}
@@ -170,4 +192,4 @@
} // end of namespace oln
-#endif // ! OLN_CORE_CONCEPT_FUNCTIONS_HH
+#endif // ! OLN_CORE_CONCEPT_FUNCTION_HH
Index: oln/core/concept/value.hh
--- oln/core/concept/value.hh (revision 885)
+++ oln/core/concept/value.hh (working copy)
@@ -44,14 +44,32 @@
Value();
};
+ /// Concept-class "Boolean".
+
+ template <typename Exact>
+ struct Boolean : public Value<Exact>
+ {
+ protected:
+ Boolean();
+ };
+
# ifndef OLN_INCLUDE_ONLY
+ // Value.
+
template <typename Exact>
Value<Exact>::Value()
{
}
+ // Boolean.
+
+ template <typename Exact>
+ Boolean<Exact>::Boolean()
+ {
+ }
+
# endif
} // end of namespace oln
Index: oln/core/2d/grid2d.hh
--- oln/core/2d/grid2d.hh (revision 885)
+++ oln/core/2d/grid2d.hh (working copy)
@@ -53,7 +53,7 @@
/// Fwd decls.
template <typename Exact> struct Grid_2D;
- struct grid2d_rec;
+ struct grid2d;
struct grid2d_hex;
struct grid2d_tri;
@@ -83,9 +83,9 @@
/// Super types.
template<>
- struct super_trait_< grid2d_rec >
+ struct super_trait_< grid2d >
{
- typedef Grid_2D< grid2d_rec > ret;
+ typedef Grid_2D< grid2d > ret;
};
template<>
@@ -107,10 +107,10 @@
/// Rectangular grid struct.
- struct grid2d_rec : public Grid_2D< grid2d_rec >
+ struct grid2d : public Grid_2D< grid2d >
{};
- typedef grid2d_rec grid2d; // for short
+ typedef grid2d grid2d_rec; // more explicit
/// Hexagonal grid struct.
Index: oln/core/2d/point2d.hh
--- oln/core/2d/point2d.hh (revision 885)
+++ oln/core/2d/point2d.hh (working copy)
@@ -93,7 +93,7 @@
this->col() = dat->second.value;
}
-# endif
+# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/equipment.hh
--- oln/core/equipment.hh (revision 885)
+++ oln/core/equipment.hh (working copy)
@@ -49,6 +49,10 @@
# include <stc/scoop-alt.inc>
# endif
+ // a
+
+ stc_decl_associated_type( adapted );
+
// b
stc_decl_associated_type( bkd_niter );
stc_decl_associated_type( bkd_piter );
Index: oln/core/gen/fun.hh
--- oln/core/gen/fun.hh (revision 0)
+++ oln/core/gen/fun.hh (revision 0)
@@ -0,0 +1,120 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_CORE_GEN_FUN_HH
+# define OLN_CORE_GEN_FUN_HH
+
+# include <oln/core/internal/category_of.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/point.hh>
+# include <oln/core/concept/value.hh>
+
+
+
+// FIXME: Add "fun" to names below.
+# define oln_arg_of_(T) typename oln::internal::argument_of_< T >::ret
+# define oln_res_of_(T) typename oln::internal::result_of_< T >::ret
+
+
+
+namespace oln
+{
+
+
+ namespace internal
+ {
+
+ // result_of_
+
+ template <typename F>
+ struct result_of_
+ {
+ typedef typename F::result ret;
+ };
+
+ template <typename R, typename A>
+ struct result_of_< R (*)(A) >
+ {
+ typedef R ret;
+ };
+
+
+ // argument_of_
+
+ template <typename F>
+ struct argument_of_
+ {
+ typedef typename F::argument ret;
+ };
+
+ template <typename R, typename A>
+ struct argument_of_< R (*)(A) >
+ {
+ typedef A ret;
+ };
+
+
+ } // end of namespace oln::internal
+
+
+
+ // Fwd decl.
+ template <typename F> struct fun_p2b_;
+
+ // Category.
+ namespace internal
+ {
+ template <typename F>
+ struct set_category_of_< fun_p2b_<F> >
+ {
+ typedef stc::is< Function_p2b > ret;
+ };
+ }
+
+ // Class.
+ template <typename F>
+ struct fun_p2b_ : public Function_p2b< fun_p2b_<F> >
+ {
+ typedef oln_arg_of_(F) argument;
+ typedef oln_res_of_(F) result;
+
+ fun_p2b_(F f) : f_(f) {}
+
+ result operator()(argument arg) const
+ {
+ return this->f_(arg);
+ }
+
+ private:
+ F f_;
+ };
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_GEN_FUN_HH
Index: oln/core/gen/op.hh
--- oln/core/gen/op.hh (revision 885)
+++ oln/core/gen/op.hh (working copy)
@@ -29,6 +29,9 @@
# define OLN_CORE_GEN_OP_HH
# include <oln/core/internal/special_op.hh>
+# include <oln/core/internal/category_of.hh>
+# include <oln/core/concept/function.hh>
+# include <oln/core/concept/value.hh>
@@ -78,28 +81,10 @@
-
-# define oln_category_of_(Type) typename oln::internal::category_of_<Type>::ret
-
-
namespace oln
{
- namespace internal
- {
- template <typename T>
- struct category_of_
- {
- typedef stc_type(T, category) ret;
- };
-
- // ...
-
- } // end of namespace oln::internal
-
-
-
/// \{
/// Operator Names.
@@ -111,6 +96,7 @@
+
// Fwd decl.
template <typename L, typename OpName, typename R> class op_;
Index: oln/core/gen/pset_such_as.hh
--- oln/core/gen/pset_such_as.hh (revision 0)
+++ oln/core/gen/pset_such_as.hh (revision 0)
@@ -0,0 +1,380 @@
+// 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_POINT_SET_STD_BASED_HH
+# define OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH
+
+# include <ostream>
+# include <algorithm>
+
+# include <oln/core/internal/point_set_base.hh>
+# include <oln/core/concept/iterator_on_points.hh>
+# include <oln/core/gen/fbbox.hh>
+
+
+namespace oln
+{
+
+
+ /// Fwd decl.
+ namespace internal { template <typename Exact> struct point_set_std_based_; }
+ template <typename P> class pset_std_based_fwd_piter_;
+ template <typename P> class pset_std_based_bkd_piter_;
+
+
+ /// Super type.
+ template <typename Exact>
+ struct super_trait_< internal::point_set_std_based_<Exact> >
+ {
+ typedef internal::point_set_base_<Exact> ret;
+ };
+
+
+ /// Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::point_set_std_based_<Exact> >
+ {
+ typedef stc::abstract std_container;
+
+ typedef stc_deferred(std_container) std_container__;
+ typedef stc::final< typename std_container__::value_type > point;
+ typedef stc::final< pset_std_based_fwd_piter_<std_container__> > fwd_piter;
+ typedef stc::final< pset_std_based_bkd_piter_<std_container__> > bkd_piter;
+ };
+
+
+ namespace internal
+ {
+
+ /// Base class for point sets defined over std containers.
+
+ template <typename Exact>
+ struct point_set_std_based_ : public point_set_base_<Exact>
+ {
+ typedef point_set_base_<Exact> super;
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const box& impl_bbox() const;
+
+ stc_typename(std_container);
+ const std_container& con() const;
+
+ protected:
+
+ point_set_std_based_();
+
+ void take_(const point& p);
+
+ std_container con_;
+ fbbox_<point> fb_;
+
+ }; // end of class point_set_std_based_<Exact>
+
+
+ template <typename Exact>
+ std::ostream& operator<<(std::ostream& ostr,
+ const point_set_std_based_<Exact>& pts)
+ {
+ typename Exact::fwd_piter i(pts);
+ ostr << "{ ";
+ for_all(i)
+ ostr << i.to_point() << ' ';
+ ostr << "}";
+ return ostr;
+ }
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename Exact>
+ unsigned
+ point_set_std_based_<Exact>::impl_npoints() const
+ {
+ return this->con_.size();
+ }
+
+ template <typename Exact>
+ bool
+ point_set_std_based_<Exact>::impl_has(const typename point_set_std_based_<Exact>::point& p) const
+ {
+ return std::find(this->con_.begin(), this->con_.end(), p) != this->con_.end();
+ }
+
+ template <typename Exact>
+ const typename point_set_std_based_<Exact>::box&
+ point_set_std_based_<Exact>::impl_bbox() const
+ {
+ precondition(this->fb_.is_valid());
+ return this->fb_.box();
+ }
+
+ template <typename Exact>
+ point_set_std_based_<Exact>::point_set_std_based_()
+ {
+ }
+
+ template <typename Exact>
+ void
+ point_set_std_based_<Exact>::take_(const typename point_set_std_based_<Exact>::point& p)
+ {
+ this->fb_.take(p);
+ }
+
+ template <typename Exact>
+ const typename point_set_std_based_<Exact>::std_container&
+ point_set_std_based_<Exact>::con() const
+ {
+ return this->con_;
+ }
+
+# endif
+
+ } // end of namespace oln::internal
+
+
+
+
+ // -------------------- iterators on classes deriving from internal::point_set_std_based_<Exact>
+
+
+
+ // Super types.
+
+ template <typename C>
+ struct super_trait_< pset_std_based_fwd_piter_<C> >
+ {
+ typedef pset_std_based_fwd_piter_<C> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
+
+ template <typename C>
+ struct super_trait_< pset_std_based_bkd_piter_<C> >
+ {
+ typedef pset_std_based_bkd_piter_<C> current__;
+ typedef Iterator_on_Points<current__> ret;
+ };
+
+
+
+ /// Virtual types.
+
+ template <typename C>
+ struct vtypes< pset_std_based_fwd_piter_<C> >
+ {
+ typedef typename C::value_type point;
+ };
+
+ template <typename C>
+ struct vtypes< pset_std_based_bkd_piter_<C> >
+ {
+ typedef typename C::value_type point;
+ };
+
+
+ // Class pset_std_based_fwd_piter_<C>.
+
+ template <typename C>
+ class pset_std_based_fwd_piter_ : public Iterator_on_Points< pset_std_based_fwd_piter_<C> >
+ {
+ typedef pset_std_based_fwd_piter_<C> current;
+ typedef Iterator_on_Points<current> super;
+ public:
+
+ stc_using(point);
+
+ template <typename Ps>
+ pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& con);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ private:
+
+ const C& con_;
+ typename C::const_iterator it_;
+
+ }; // end of class pset_std_based_fwd_piter_<C>
+
+
+ // Class pset_std_based_bkd_piter_<C>.
+
+ template <typename C>
+ class pset_std_based_bkd_piter_ : public Iterator_on_Points< pset_std_based_bkd_piter_<C> >
+ {
+ typedef pset_std_based_bkd_piter_<C> current;
+ typedef Iterator_on_Points<current> super;
+ public:
+
+ stc_using(point);
+
+ template <typename Ps>
+ pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts);
+
+ void impl_start();
+ void impl_next();
+ void impl_invalidate();
+ bool impl_is_valid() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
+
+ private:
+
+ const C& con_;
+ typename C::const_reverse_iterator it_;
+
+ }; // end of class pset_std_based_bkd_piter_<C>
+
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+
+
+ // -------------------- pset_std_based_fwd_piter_<C>
+
+
+ template <typename C>
+ template <typename Ps>
+ pset_std_based_fwd_piter_<C>::pset_std_based_fwd_piter_(const internal::point_set_std_based_<Ps>& pts)
+ : con_(pts.con())
+ {
+ this->it_ = this->con_.end();
+ }
+
+ template <typename C>
+ void pset_std_based_fwd_piter_<C>::impl_start()
+ {
+ this->it_ = this->con_.begin();
+ }
+
+ template <typename C>
+ void pset_std_based_fwd_piter_<C>::impl_next()
+ {
+ ++this->it_;
+ }
+
+ template <typename C>
+ void pset_std_based_fwd_piter_<C>::impl_invalidate()
+ {
+ this->it_ = this->con_.end();
+ }
+
+ template <typename C>
+ bool pset_std_based_fwd_piter_<C>::impl_is_valid() const
+ {
+ return this->it_ != this->con_.end();
+ }
+
+ template <typename C>
+ typename pset_std_based_fwd_piter_<C>::point
+ pset_std_based_fwd_piter_<C>::impl_to_point() const
+ {
+ return *this->it_;
+ }
+
+ template <typename C>
+ const typename pset_std_based_fwd_piter_<C>::point*
+ pset_std_based_fwd_piter_<C>::impl_point_adr() const
+ {
+ return &(*(this->it_));
+ // FIXME: "&(*it_)" is not always correct because the std does not
+ // ensure that "*it_" is dereferenceable (Cf. std trivial iterator
+ // concept). However, "::point_adr()" is only required so that an
+ // iterator based on another iterator (e.g., a niter constructed
+ // from a piter) can stick to the point location of the latter.
+ // This is not required for iterators on point set so this method
+ // should be optional.
+ }
+
+
+ // -------------------- pset_std_based_bkd_piter_<C>
+
+
+ template <typename C>
+ template <typename Ps>
+ pset_std_based_bkd_piter_<C>::pset_std_based_bkd_piter_(const internal::point_set_std_based_<Ps>& pts)
+ : con_(pts.con())
+ {
+ this->it_ = this->con_.rend();
+ }
+
+ template <typename C>
+ void pset_std_based_bkd_piter_<C>::impl_start()
+ {
+ this->it_ = this->con_.rbegin();
+ }
+
+ template <typename C>
+ void pset_std_based_bkd_piter_<C>::impl_next()
+ {
+ ++this->it_;
+ }
+
+ template <typename C>
+ void pset_std_based_bkd_piter_<C>::impl_invalidate()
+ {
+ this->it_ = this->con_.rend();
+ }
+
+ template <typename C>
+ bool pset_std_based_bkd_piter_<C>::impl_is_valid() const
+ {
+ return this->it_ != this->con_.rend();
+ }
+
+ template <typename C>
+ typename pset_std_based_bkd_piter_<C>::point
+ pset_std_based_bkd_piter_<C>::impl_to_point() const
+ {
+ return *this->it_;
+ }
+
+ template <typename C>
+ const typename pset_std_based_bkd_piter_<C>::point*
+ pset_std_based_bkd_piter_<C>::impl_point_adr() const
+ {
+ return &(*(this->it_));
+ // FIXME: Read comments in pset_std_based_fwd_piter_<C>.
+ }
+
+
+# endif
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_POINT_SET_STD_BASED_HH
Index: oln/core/internal/point_base.hh
--- oln/core/internal/point_base.hh (revision 885)
+++ oln/core/internal/point_base.hh (working copy)
@@ -50,13 +50,15 @@
template <typename Exact>
struct vtypes< internal::point_base_<Exact> >
{
- typedef stc::abstract grid;
+ typedef stc::abstract grid; // FIXME: Could be defined and final?
+ typedef stc::abstract coord; // FIXME: Likewise?
+ typedef stc::abstract dpoint;
typedef stc_deferred(grid) grid__;
- typedef stc::final<stc_type(grid__, dim)> dim;
- typedef stc::abstract coord;
- typedef stc::abstract dpoint;
+ // Final:
+ typedef stc::final<typename grid__::dim> dim; // FIXME: Propagate this kind of changes.
+ typedef stc::final< stc::is<Point> > category;
};
Index: oln/core/internal/op_pset_such_as_fp2b.hh
--- oln/core/internal/op_pset_such_as_fp2b.hh (revision 0)
+++ oln/core/internal/op_pset_such_as_fp2b.hh (revision 0)
@@ -0,0 +1,336 @@
+// 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_PSET_SUCH_AS_FP2B_HH
+# define OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH
+
+# include <oln/core/concept/function.hh>
+# include <oln/core/gen/op.hh>
+# include <oln/core/internal/piter_adaptor.hh>
+# include <oln/core/internal/point_set_base.hh>
+
+
+namespace oln
+{
+
+
+# define current \
+ special_op_< stc::is<Point_Set>, S, such_as, stc::is<Function_p2b>, F >
+
+
+ /// Fwd decls.
+ namespace internal
+ {
+ template <typename S, typename F> class current;
+ }
+ template <typename S, typename F> class pset_such_as_fp2b_fwd_piter_;
+ template <typename S, typename F> class pset_such_as_fp2b_bkd_piter_;
+
+
+
+ /// Super type.
+ template <typename S, typename F>
+ struct super_trait_< internal::current >
+ {
+ typedef internal::point_set_base_< op_<S, such_as, F> > ret;
+ };
+
+
+ /// Virtual types.
+ 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;
+ };
+
+
+ namespace internal
+ {
+
+ /// Implementation class the result of "Point_Set S | Function_p2b F".
+
+ template <typename S, typename F>
+ class current
+ :
+ public internal::point_set_base_< op_<S, such_as, F> >
+ {
+ typedef internal::point_set_base_< op_<S, such_as, F> > super;
+ public:
+
+ stc_using(point);
+ stc_using(box);
+
+ unsigned impl_npoints() const;
+ bool impl_has(const point& p) const;
+ const box& impl_bbox() const;
+
+ const S& adapted_() const;
+ F fun_() const;
+
+ protected:
+ special_op_();
+ special_op_(S& pset, F& f);
+
+ S pset_;
+ F f_;
+
+ // template <typename D>
+ // friend
+ // bool init_(internal::current* this_, const D& dat);
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ current::special_op_()
+ {
+ }
+
+ template <typename S, typename F>
+ current::special_op_(S& pset, F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+ template <typename S, typename F>
+ unsigned
+ current::impl_npoints() const
+ {
+ return 0; // FIXME: Wrong!!!
+ }
+
+ template <typename S, typename F>
+ bool
+ current::impl_has(const typename current::point& p) const
+ {
+ return this->pset_.has(p) and this->f_(p);
+ }
+
+ template <typename S, typename F>
+ const typename current::box&
+ current::impl_bbox() const
+ {
+ return this->pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ current::adapted_() const
+ {
+ return this->pset_;
+ }
+
+ template <typename S, typename F>
+ F current::fun_() const
+ {
+ return this->f_;
+ }
+
+# endif
+
+ } // end of namespace oln::internal
+
+
+// // Fixme: Activate init
+
+// template <typename S, typename F, typename D>
+// bool init_(internal::current* this_, const D& dat)
+// {
+// bool pset_ok = init(this_->pset_, with, dat);
+// bool fun_ok = init(this_->f_, with, dat);
+// postcondition(pset_ok);
+// postcondition(fun_ok);
+// return pset_ok and fun_ok;
+// }
+
+
+# undef current
+
+
+
+
+
+
+
+# define current pset_such_as_fp2b_fwd_piter_<S, F>
+ // ----------------------------------
+
+# define super internal::piter_adaptor_< current >
+
+
+ // Super type.
+ template <typename S, typename F>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename S, typename F>
+ struct vtypes< current >
+ {
+ typedef typename S::point point;
+ typedef typename S::fwd_piter adapted;
+ };
+
+
+ // Class.
+ template <typename S, typename F>
+ class pset_such_as_fp2b_fwd_piter_ : public super
+ {
+ public:
+
+ pset_such_as_fp2b_fwd_piter_();
+ pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset);
+
+ void impl_start();
+ void impl_next();
+
+ private:
+ F f_;
+
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ current::pset_such_as_fp2b_fwd_piter_(const Point_Set< op_<S, such_as, F> >& pset)
+ : super(exact(pset).adapted_()),
+ f_(exact(pset).fun_())
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_start()
+ {
+ this->p_.start();
+ while (this->p_.is_valid() and not f_(this->p_))
+ this->p_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_next()
+ {
+ do
+ this->p_.next();
+ while (this->p_.is_valid() and not f_(this->p_));
+ }
+
+# endif // OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+
+
+
+
+# define current pset_such_as_fp2b_bkd_piter_<S, F>
+ // ----------------------------------
+
+# define super internal::piter_adaptor_< current >
+
+
+ // Super type.
+ template <typename S, typename F>
+ struct super_trait_< current >
+ {
+ typedef super ret;
+ };
+
+
+ // Virtual types.
+ template <typename S, typename F>
+ struct vtypes< current >
+ {
+ typedef typename S::point point;
+ typedef typename S::fwd_piter adapted;
+ };
+
+
+ // Class.
+ template <typename S, typename F>
+ class pset_such_as_fp2b_bkd_piter_ : public super
+ {
+ public:
+
+ pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset);
+
+ void impl_start();
+ void impl_next();
+
+ private:
+ F f_;
+
+ };
+
+
+# ifndef OLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ current::pset_such_as_fp2b_bkd_piter_(const Point_Set< op_<S, such_as, F> >& pset)
+ : super(exact(pset).adapted_()),
+ f_(exact(pset).fun_())
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_start()
+ {
+ this->p_.start();
+ while (this->p_.is_valid() and not f_(this->p_))
+ this->p_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ current::impl_next()
+ {
+ do
+ this->p_.next();
+ while (this->p_.is_valid() and not f_(this->p_));
+ }
+
+# endif // OLN_INCLUDE_ONLY
+
+# undef super
+# undef current
+
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_OP_PSET_SUCH_AS_FP2B_HH
Index: oln/core/internal/dpoint_base.hh
--- oln/core/internal/dpoint_base.hh (revision 885)
+++ oln/core/internal/dpoint_base.hh (working copy)
@@ -57,7 +57,9 @@
typedef stc::final<stc_type(grid__, dim)> dim;
typedef stc::abstract coord;
- typedef stc::abstract point;
+ typedef stc::abstract point; // FIXME: Just like in point_base.hh
+
+ typedef stc::final< stc::is<Dpoint> > category;
};
Index: oln/core/internal/piter_adaptor.hh
--- oln/core/internal/piter_adaptor.hh (revision 879)
+++ oln/core/internal/piter_adaptor.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,159 +25,124 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_CORE_GEN_PITER_ISUBSET_HH
-# define OLN_CORE_GEN_PITER_ISUBSET_HH
+#ifndef OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
+# define OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
-# include <oln/core/abstract/iterator_on_points.hh>
-# include <oln/core/abstract/topology.hh>
-# include <oln/core/gen/topo_add_isubset.hh>
+# include <oln/core/concept/iterator_on_points.hh>
namespace oln
{
- // Forward declaration.
- template <typename piter_t, typename isubset_t> class piter_isubset_;
+ // Fwd decl.
+ namespace internal { template <typename Exact> class piter_adaptor_; }
- // Super type declaration.
- template <typename piter_t, typename isubset_t>
- struct set_super_type< piter_isubset_<piter_t, isubset_t> >
+ // Super type.
+ template <typename Exact>
+ struct super_trait_< internal::piter_adaptor_<Exact> >
{
- typedef piter_isubset_<piter_t, isubset_t> self_t;
- typedef abstract::iterator_on_points<self_t> ret;
+ typedef Iterator_on_Points<Exact> ret;
};
- /// Virtual types associated to oln::piter_isubset_<piter_t, isubset_t>.
- template <typename piter_t, typename isubset_t>
- struct vtypes< piter_isubset_<piter_t, isubset_t> >
+ // Virtual types.
+ template <typename Exact>
+ struct vtypes< internal::piter_adaptor_<Exact> >
{
- typedef oln_vtype(piter_t, point) point_type;
- typedef oln_vtype(piter_t, grid) grid_type;
-
- typedef topo_add_isubset<oln_vtype(piter_t, topo), isubset_t> topo_type;
+ typedef stc::abstract point;
+ typedef stc::abstract adapted;
};
-
- /// Abstract forward point iterator class.
- template <typename piter_t, typename isubset_t>
- class piter_isubset_ : public abstract::iterator_on_points< piter_isubset_<piter_t, isubset_t> >
+ namespace internal
{
- typedef piter_isubset_<piter_t, isubset_t> self_t;
- typedef abstract::iterator_on_points<self_t> super_t;
- typedef oln_vtype(self_t, topo) topo_t;
- typedef oln_vtype(self_t, point) point_t;
+ // Base implementation class for types of iterator on points
+ // defined over other types of iterator on points.
+ template <typename Exact>
+ class piter_adaptor_ : public Iterator_on_Points<Exact>
+ {
+ typedef Iterator_on_Points<Exact> super;
public:
- template <typename T>
- piter_isubset_(const abstract::topology<T>& topo);
+ stc_using(point);
+ stc_typename(adapted);
- template <typename P, typename T>
- piter_isubset_(const P& p, const abstract::topology<T>& topo);
+ piter_adaptor_(adapted p);
+ // Default impl is delegation.
void impl_start();
-
void impl_next();
-
void impl_invalidate();
-
bool impl_is_valid() const;
-
- point_t impl_to_point() const;
-
- const point_t* impl_point_adr() const;
-
- const topo_t topo() const;
+ point impl_to_point() const;
+ const point* impl_point_adr() const;
protected:
+ adapted p_;
- piter_t p_;
- isubset_t isubset_; // Cpy.
-
- }; // end of class oln::piter_isubset_<point>
+ }; // end of class oln::internal::piter_adaptor_<Exact>
# ifndef OLN_INCLUDE_ONLY
- template <typename piter_t, typename isubset_t>
- template <typename T>
- piter_isubset_<piter_t, isubset_t>::piter_isubset_(const abstract::topology<T>& topo)
- : p_(topo),
- isubset_(topo.exact().subset())
- {
- }
-
- template <typename piter_t, typename isubset_t>
- template <typename P, typename T>
- piter_isubset_<piter_t, isubset_t>::piter_isubset_(const P& p, const abstract::topology<T>& topo)
- : p_(p, topo),
- isubset_(topo.exact().subset())
+ template <typename Exact>
+ piter_adaptor_<Exact>::piter_adaptor_(adapted p)
+ : p_(p)
{
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
void
- piter_isubset_<piter_t, isubset_t>::impl_start()
+ piter_adaptor_<Exact>::impl_start()
{
- p_.start();
- while (p_.is_valid() and isubset_(p_) = false)
- p_.next();
+ this->p_.start();
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
void
- piter_isubset_<piter_t, isubset_t>::impl_next()
+ piter_adaptor_<Exact>::impl_next()
{
- do
- p_.next();
- while (p_.is_valid() and isubset_(p_) = false);
+ this->p_.next();
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
void
- piter_isubset_<piter_t, isubset_t>::impl_invalidate()
+ piter_adaptor_<Exact>::impl_invalidate()
{
- p_.invalidate();
+ this->p_.invalidate();
}
- template <typename piter_t, typename isubset_t>
+ template <typename Exact>
bool
- piter_isubset_<piter_t, isubset_t>::impl_is_valid() const
+ piter_adaptor_<Exact>::impl_is_valid() const
{
- return p_.is_valid();
+ return this->p_.is_valid();
}
- template <typename piter_t, typename isubset_t>
- typename piter_isubset_<piter_t, isubset_t>::point_t
- piter_isubset_<piter_t, isubset_t>::impl_to_point() const
+ template <typename Exact>
+ typename piter_adaptor_<Exact>::point
+ piter_adaptor_<Exact>::impl_to_point() const
{
- return p_.to_point();
+ return this->p_.to_point();
}
- template <typename piter_t, typename isubset_t>
- const typename piter_isubset_<piter_t, isubset_t>::point_t*
- piter_isubset_<piter_t, isubset_t>::impl_point_adr() const
+ template <typename Exact>
+ const typename piter_adaptor_<Exact>::point*
+ piter_adaptor_<Exact>::impl_point_adr() const
{
- return p_.point_adr();
- }
-
- template <typename piter_t, typename isubset_t>
- const typename piter_isubset_<piter_t, isubset_t>::topo_t
- piter_isubset_<piter_t, isubset_t>::topo() const
- {
- topo_t tmp(p_.topo(), isubset_);
- return tmp;
+ return this->p_.point_adr();
}
# endif
+ } // end of namespace oln::internal
+
} // end of namespace oln
-#endif // ! OLN_CORE_GEN_PITER_ISUBSET_HH
+#endif // ! OLN_CORE_INTERNAL_PITER_ADAPTOR_HH
Index: oln/core/internal/point_set_base.hh
--- oln/core/internal/point_set_base.hh (revision 885)
+++ oln/core/internal/point_set_base.hh (working copy)
@@ -93,4 +93,39 @@
} // end of namespace oln
+
+/// \{
+/// FIXME: Bad!
+
+# include <oln/core/gen/fun.hh>
+# include <oln/core/internal/op_pset_such_as_fp2b.hh>
+
+namespace oln
+{
+
+ // Point_Set | Function.
+
+ oln_decl_op_such_as(Point_Set, Function_p2b);
+
+
+ // Specialization.
+
+ 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))
+ {
+ typedef oln_strip_(P) P_;
+ mlc::assert_< mlc_is_a(P_, Point) >::check(); // FIXME: Add err msg.
+ mlc::assert_equal_< P_, typename S::point >::check();
+ op_<const S, such_as, const fun_p2b_<B (*)(P)> > tmp(exact(lhs), f);
+ return tmp;
+ }
+
+
+} // end of namespace oln
+
+/// \}
+
+
#endif // ! OLN_CORE_INTERNAL_POINT_SET_BASE_HH
Index: oln/core/internal/category_of.hh
--- oln/core/internal/category_of.hh (revision 0)
+++ oln/core/internal/category_of.hh (revision 0)
@@ -0,0 +1,124 @@
+// 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
+// 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_CATEGORY_OF_HH
+# define OLN_CORE_INTERNAL_CATEGORY_OF_HH
+
+
+# define oln_category_of_(Type) typename oln::internal::category_of_< Type >::ret
+# define oln_strip_(Type) typename oln::internal::strip_< Type >::ret
+
+
+namespace oln
+{
+
+ // Fwd decls.
+ template <typename Exact> struct Boolean;
+
+
+
+ namespace internal
+ {
+
+ // Strip_
+
+
+ template <typename T>
+ struct strip_
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct strip_< T* >
+ {
+ typedef typename strip_<T>::ret ret;
+ };
+
+ template <typename T>
+ struct strip_< T& >
+ {
+ typedef typename strip_<T>::ret ret;
+ };
+
+ template <typename T>
+ struct strip_< const T >
+ {
+ typedef typename strip_<T>::ret ret;
+ };
+
+
+
+
+ // Category_of_
+
+
+ template <typename T>
+ struct set_category_of_
+ {
+ typedef stc_type(T, category) ret;
+ };
+
+ template <>
+ struct set_category_of_< bool >
+ {
+ typedef stc::is< Boolean > ret;
+ };
+
+
+ template <typename T>
+ struct category_of_
+ {
+ typedef typename strip_<T>::ret T_;
+ typedef typename set_category_of_<T_>::ret ret;
+ };
+
+ // ...
+
+
+
+
+ // only_if_
+
+ template < typename Ret,
+ typename Check_1,
+ typename Check_2 = void,
+ typename Check_3 = void,
+ typename Check_4 = void >
+ struct only_if_
+ {
+ typedef Ret ret;
+ };
+
+
+
+ } // end of namespace oln::internal
+
+} // end of namespace oln
+
+
+#endif // ! OLN_CORE_INTERNAL_CATEGORY_OF_HH
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 885)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -82,7 +82,7 @@
/// Implementation class the result of "Image I + Neighborhood N".
template <typename I, typename N>
- class special_op_< stc::is<Image>, I, plus, stc::is<Neighborhood>, N >
+ class current
:
public internal::image_extension_< op_<I, plus, N> >,
private mlc::assert_< mlc_is_not_a(I, Image_with_Nbh) > // FIXME: Add err msg.
Index: oln/core/internal/special_op.hh
--- oln/core/internal/special_op.hh (revision 885)
+++ oln/core/internal/special_op.hh (working copy)
@@ -28,8 +28,6 @@
#ifndef OLN_CORE_INTERNAL_SPECIAL_OP_HH
# define OLN_CORE_INTERNAL_SPECIAL_OP_HH
-# include <oln/core/internal/image_base.hh>
-
namespace oln
{
1
0
I had some probleme with neighborhood image initialisation from another image_with_nbh. See erosion.hh and apply.hh
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update : erosion (bring some error to light).
* oln/morpho,
* oln/morpho/dilation.hh: New.
* oln/morpho/dilatation.hh: Remove.
* oln/morpho/erosion.hh: .
* oln/function/min.hh: .
* oln/level/apply.hh: .
* oln/level/local.hh: .
* oln/core/concept/functions.hh: .
* oln/core/internal/op_image_plus_nbh.hh: .
* oln/morphomath,
* oln/morphomath/dilatation.hh,
* oln/morphomath/erosion.hh: Remove.
core/concept/functions.hh | 5 +++++
core/internal/op_image_plus_nbh.hh | 1 +
function/min.hh | 2 +-
level/apply.hh | 12 +++++++-----
level/local.hh | 18 +++++++++---------
morpho/dilation.hh | 29 +++++++++++++++++++++++++++++
morpho/erosion.hh | 12 +++++++++---
7 files changed, 61 insertions(+), 18 deletions(-)
Index: oln/morpho/dilation.hh
--- oln/morpho/dilation.hh (revision 0)
+++ oln/morpho/dilation.hh (revision 0)
@@ -0,0 +1,29 @@
+#ifndef OLN_MORPHOMATH_DILATATION_HH_
+# define OLN_MORPHOMATH_DILATATION_HH_
+
+// Facade.
+
+namespace impl
+{
+
+ /// Generic version
+
+ template <typename I, typename W>
+ I dilatation(const Image<I>& input)
+ {
+ max_<oln_value(I)> max;
+ return apply(max, input);
+ }
+
+}
+
+
+/// Facade.
+
+template <typename I, typename W>
+I erosion(const Image<I>& input)
+{
+ return impl::dilatation(exact(input));
+}
+
+#endif /* !OLN_MORPHOMATH_DILATATION_HH_ */
Index: oln/morpho/erosion.hh
--- oln/morpho/erosion.hh (revision 884)
+++ oln/morpho/erosion.hh (working copy)
@@ -38,16 +38,20 @@
namespace morpho
{
+ template <typename I>
+ I erosion(const Image_with_Nbh<I>& input);
+
+# ifndef OLN_INCLUDE_ONLY
+
namespace impl
{
/// Generic version
template <typename I>
- I erosion(Image_with_Nbh<I>& input)
+ I erosion(const Image_with_Nbh<I>& input)
{
function::min_<oln_value(I)> min;
-
return ::oln::level::apply_local(min, input);
}
}
@@ -55,11 +59,13 @@
// Facade.
template <typename I>
- I erosion(Image_with_Nbh<I>& input)
+ I erosion(const Image_with_Nbh<I>& input)
{
return impl::erosion(exact(input));
}
+#endif // ! OLN_INCLUDE_ONLY
+
} // end of namespace
}
Index: oln/function/min.hh
--- oln/function/min.hh (revision 884)
+++ oln/function/min.hh (working copy)
@@ -46,7 +46,7 @@
min_() { this->init(); }
- void init() { val_ = oln_max(T); }
+ void init() const { val_ = oln_max(T); }
result value() const { return val_; }
template <typename U>
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 884)
+++ oln/level/apply.hh (working copy)
@@ -85,17 +85,19 @@
/// apply_local
template <typename F, typename I>
- oln_plain_value(I, typename F::result)
- apply_local(const Accumulator<F>& fun,
+ I apply_local(const Accumulator<F>& f,
const Image_with_Nbh<I>& input)
{
typedef typename F::result result;
typedef typename F::argument argument;
- oln_ch_value(I, argument) output(input.points());
+ typename I::delegatee out(input.points());
+ I output(out, input.nbhood());
+ // I output(exact(input).image(), input.nbhood());
+ // FIXME: init(output, with, input);
oln_piter(I) p(input.points());
for_all(p)
- output(p) = local(fun, input, p);
+ output(p) = level::local(f, input, p);
return output;
}
@@ -168,7 +170,7 @@
apply_local(const Accumulator<F>& fun,
const Image_with_Nbh<I>& input)
{
- return impl::apply_local(fun, exact(input));
+ return impl::apply_local(fun, input);
}
// /// Facade.
Index: oln/level/local.hh
--- oln/level/local.hh (revision 884)
+++ oln/level/local.hh (working copy)
@@ -5,8 +5,8 @@
// 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
+// 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.
//
@@ -42,7 +42,7 @@
{
template <typename A, typename I>
- typename A::result
+ int //typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p);
@@ -62,8 +62,8 @@
/// Local Apply on neighborhood (nbh included in image).
template <typename A, typename I>
- typename A::result
- local(const Accumulator<A>& f,
+ int//typename A::result
+ local_(const A& f,
const Image_with_Nbh<I>& input,
const oln_point(I)& p)
{
@@ -88,7 +88,7 @@
template <typename F, typename I, typename W>
typename F::result
- local(const Accumulator<F>& f,
+ local_(const F& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
@@ -106,12 +106,12 @@
/// Facades.
template <typename A, typename I>
- typename A::result
+ int//typename A::result
local(const Accumulator<A>& f,
const Image_with_Nbh<I>& input,
const oln_point( I )& p)
{
- return impl::local(f, input, p);
+ return impl::local_(exact(f), input, p);
}
template <typename F, typename I, typename W>
@@ -121,7 +121,7 @@
const oln_point(I)& p,
const Window<W>& win)
{
- return impl::local(f, input, p, win);
+ return impl::local_(exact(f), input, p, win);
}
#endif // ! OLN_INCLUDE_ONLY
Index: oln/core/concept/functions.hh
--- oln/core/concept/functions.hh (revision 884)
+++ oln/core/concept/functions.hh (working copy)
@@ -165,6 +165,11 @@
{
}
+ template <typename Exact>
+ Accumulator<Exact>::Accumulator()
+ {
+ }
+
# endif // OLN_INCLUDE_ONLY
} // end of namespace oln
Index: oln/core/internal/op_image_plus_nbh.hh
--- oln/core/internal/op_image_plus_nbh.hh (revision 884)
+++ oln/core/internal/op_image_plus_nbh.hh (working copy)
@@ -97,6 +97,7 @@
const delegatee& impl_image() const;
nbh impl_nbhood() const;
+ nbh& impl_nbhood();
protected:
special_op_();
1
0
16 Mar '07
Roland Levillain wrote:
> Note: In order to avoid writing even more boring messages, I sometimes
> make remarks or ...
Thanks for all your advice ;)
1
0
884: Update : Norme, Sanity, apply of user functors. erosion not yet usable.
by Ugo Jardonnet 16 Mar '07
by Ugo Jardonnet 16 Mar '07
16 Mar '07
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update : Norme, Sanity, apply of user functors. erosion not yet usable.
* oln/function/min.hh: .
* oln/level/apply.hh: .
* oln/level/local.hh: .
* oln/core/concept/functions.hh: .
* oln/core/internal/max_value.hh: .
* oln/morphomath/erosion.hh: .
core/internal/max_value.hh | 1
function/min.hh | 39 ++++++++---------
level/apply.hh | 71 ++++++++++---------------------
level/local.hh | 102 ++++++++++++++++++++++++++++++---------------
morphomath/erosion.hh | 27 +++++++----
5 files changed, 129 insertions(+), 111 deletions(-)
Index: oln/function/min.hh
--- oln/function/min.hh (revision 883)
+++ oln/function/min.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -26,32 +25,29 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_FUNCTION_MIN_HH_
-# define OLN_FUNCTION_MIN_HH_
+#ifndef _FUNCTION_MIN_HH
+# define _FUNCTION_MIN_HH
+
+#include <oln/core/concept/functions.hh>
+#include <oln/core/internal/max_value.hh>
+
namespace oln
{
- template <typename T>
- struct min_ : oln::Function< min_<T> >
+ namespace function
{
- typedef T argument;
- typedef void result;
- min_()
+ template <typename T>
+ struct min_ : public oln::Accumulator< min_<T> >
{
- init();
- }
+ typedef T argument;
+ typedef T result;
- void init()
- {
- val_ = oln_max_value(T);
- }
+ min_() { this->init(); }
- T value() const
- {
- return val_;
- }
+ void init() { val_ = oln_max(T); }
+ result value() const { return val_; }
template <typename U>
void operator()(U i) const
@@ -59,10 +55,13 @@
if (i < val_)
val_ = static_cast<T>(i);
}
+
private:
mutable T val_;
};
}
-#endif /* !OLN_FUNCTION_MIN_HH_ */
+}
+
+#endif // ! OLN_FUNCTION_MIN_HH
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 883)
+++ oln/level/apply.hh (working copy)
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006 EPITA Research and
-// Development Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007 EPITA
+// Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -30,7 +30,9 @@
# define OLN_LEVEL_APPLY_HH
# include <oln/core/concept/image.hh>
-
+# include <oln/core/concept/iterator.hh>
+# include <oln/core/internal/f_ch_value.hh>
+# include <oln/level/local.hh>
namespace oln
{
@@ -63,63 +65,37 @@
namespace impl
{
- template < typename F >
- struct result
- {
- typedef typename F::result ret;
- };
-
- template < typename R (*fun)(A) >
- struct result
- {
- typedef typename R ret;
- };
-
- template < typename F >
- struct argument
- {
- typedef typename F::argument ret;
- };
-
- template < typename R (*fun)(A) >
- struct argument
- {
- typedef typename A ret;
- };
-
-
- // APPLY //
- //---------
+ /// apply
template <typename F, typename I>
- oln_plain_value(I, result<typename F>::ret)
- apply(const F& fun, const Image<I>& input)
+ oln_plain_value(I, typename F::result)
+ apply( F& f, const Image<I>& input)
{
- typedef argument<typename F>::ret A;
- typedef result<typename F>::ret R;
+ typedef typename F::result result;
+ typedef typename F::argument argument;
- oln_ch_value(I, R) output(input.points());
+ oln_ch_value(I, result) output(input.points());
oln_piter(I) p(input.points());
for_all(p)
- output(p) = fun( static_cast<A>(input(p)) );
+ output(p) = f( static_cast< argument >(input(p)) );
return output;
}
- // APPLY_LOCAL //
- //---------------
+ /// apply_local
template <typename F, typename I>
- oln_plain_value(I, result<typename F>::ret)
- apply_local(const F& fun, const Image<I>& input)
+ oln_plain_value(I, typename F::result)
+ apply_local(const Accumulator<F>& fun,
+ const Image_with_Nbh<I>& input)
{
- typedef argument<typename F>::ret A;
- typedef result<typename F>::ret R;
+ typedef typename F::result result;
+ typedef typename F::argument argument;
- oln_ch_value(I, R) output(input.points());
+ oln_ch_value(I, argument) output(input.points());
oln_piter(I) p(input.points());
for_all(p)
- output(p) = local_apply(fun, input, p);
+ output(p) = local(fun, input, p);
return output;
}
@@ -173,9 +149,9 @@
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply(const F& fun, const Image<I>& input)
+ apply(F& f, const Image<I>& input)
{
- return impl::apply(fun, exact(input));
+ return impl::apply(f, exact(input));
}
/// Apply local
@@ -189,7 +165,8 @@
template <typename F, typename I>
oln_plain_value(I, typename F::result)
- apply_local(const F& fun, const Image<I>& input)
+ apply_local(const Accumulator<F>& fun,
+ const Image_with_Nbh<I>& input)
{
return impl::apply_local(fun, exact(input));
}
Index: oln/level/local.hh
--- oln/level/local.hh (revision 883)
+++ oln/level/local.hh (working copy)
@@ -1,5 +1,4 @@
-// Copyright (C) 2007 EPITA Research and
-// Development Laboratory
+// Copyright (C) 2007 EPITA Research and Development Laboratory
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -16,81 +15,118 @@
// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
// Boston, MA 02111-1307, USA.
//
-// As a special exception, you may use this file as part of a free
-// software library without restriction. Specifically, if other files
-// instantiate templates or use macros or inline functions from this
-// file, or you compile this file and link it with other files to
-// produce an executable, this file does not by itself cause the
-// resulting executable to be covered by the GNU General Public
-// License. This exception does not however invalidate any other
-// reasons why the executable file might be covered by the GNU General
-// Public License.
-
-#ifndef OLN_LEVEL_LOCAL_HH_
-# define OLN_LEVEL_LOCAL_HH_
+// As a special exception, you may
+// use this file as part of a free software library without
+// restriction. Specifically, if other files instantiate templates or
+// use macros or inline functions from this file, or you compile this
+// file and link it with other files to produce an executable, this
+// file does not by itself cause the resulting executable to be
+// covered by the GNU General Public License. This exception does not
+// however invalidate any other reasons why the executable file might
+// be covered by the GNU General Public License.
+
+#ifndef OLN_LEVEL_LOCAL_HH
+# define OLN_LEVEL_LOCAL_HH
+
+#include <oln/core/concept/image.hh>
+#include <oln/core/concept/point.hh>
+#include <oln/core/concept/functions.hh>
+#include <oln/core/concept/window.hh>
+#include <oln/core/concept/iterator.hh> // bizarre
+#include <oln/core/equipment.hh>
namespace oln
{
- namespace impl
+ namespace level
{
- // LOCAL APPLICATION ON NBH //
- //----------------------------
+ template <typename A, typename I>
+ typename A::result
+ local(const Accumulator<A>& f,
+ 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,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win);
+
+# ifndef OLN_INCLUDE_ONLY
+
+ namespace impl
+ {
/// Local Apply on neighborhood ( nbh included in image ).
- template <typename R, typename A, typename I>
+ template <typename A, typename I>
typename A::result
- local_apply(const Accumulator< A >& fun,
+ local(const Accumulator<A>& f,
const Image_with_Nbh< I >& input,
const oln_point( I )& p)
{
- fun.init();
+ f.init();
oln_niter(I) n(p, input.points());
for_all(n)
- fun(input(n));
- return fun.value();
+ f(input(n));
+ return f.value();
}
- /// Local Apply on neighborhood ( nhb has to be given ).
+ /// Local Apply on neighborhood (nhb given as argument).
// ...FIXME
- // LOCAL APPLICATION ON WINDOW //
- //-------------------------------
-
/// Local Apply on window ( window included in image).
// ...FIXME
-
/// Local Apply on window ( window is given ).
template <typename F, typename I, typename W>
typename F::result
- local_apply(const Accumulator<F>& fun,
+ local(const Accumulator<F>& f,
const Image<I>& input,
const oln_point(I)& p,
const Window<W>& win)
{
- fun.init();
+ f.init();
oln_qiter(W) q(p, win);
for_all(q)
- fun(input(q));
- return fun.value();
+ f(input(q));
+
+ return f.value();
}
}
/// Facades.
- local_apply( )
+ template <typename A, typename I>
+ typename A::result
+ local(const Accumulator<A>& f,
+ const Image_with_Nbh<I>& input,
+ const oln_point( I )& p)
{
+ return impl::local(f, input, p);
+ }
+ template <typename F, typename I, typename W>
+ typename F::result
+ local(const Accumulator<F>& f,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ return impl::local(f, input, p, win);
}
+#endif // ! OLN_INCLUDE_ONLY
+
+ }
}
-#endif /* !OLN_LEVEL_LOCAL_HH_ */
+
+#endif // ! OLN_LEVEL_LOCAL_HH
Index: oln/core/concept/functions.hh
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 883)
+++ oln/core/internal/max_value.hh (working copy)
@@ -30,7 +30,6 @@
#include <cassert>
#include <limits>
-#include <iostream>
namespace oln
{
Index: oln/morphomath/erosion.hh
--- oln/morphomath/erosion.hh (revision 883)
+++ oln/morphomath/erosion.hh (working copy)
@@ -26,34 +26,41 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef OLN_MORPHOMATH_EROSION_HH_
-# define OLN_MORPHOMATH_EROSION_HH_
+#ifndef OLN_MORPHO_EROSION_HH
+# define OLN_MORPHO_EROSION_HH
-#include <oln/fonction/min.hh>
#include <oln/level/local.hh>
+#include <oln/function/min.hh>
namespace oln
{
+
+ namespace morpho
+ {
+
namespace impl
{
/// Generic version
- template <typename I, typename W>
- I erosion(const Image<I>& input)
+ template <typename I>
+ I erosion(Image_with_Nbh<I>& input)
{
- min_<oln_value(I)> min;
- return apply(min, input);
+ function::min_<oln_value(I)> min;
+
+ return ::oln::level::apply_local(min, input);
}
}
// Facade.
- template <typename I, typename W>
- I erosion(const Point_Wise_Accessible_Image<I>& input)
+ template <typename I>
+ I erosion(Image_with_Nbh<I>& input)
{
return impl::erosion(exact(input));
}
+
+ } // end of namespace
}
-#endif /* !OLN_MORPHOMATH_EROSION_HH_ */
+#endif // ! OLN_MORPHO_EROSION_HH
1
0