Note: In order to avoid writing even more boring messages, I sometimes
make remarks or give advice once in the patch, although it might apply
to several spots. Don't forget to propagate the fixes throughout
the whole patch! Thanks in advance.
Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr> writes:
max and min value for any type can be obtain with std
lib yet.
Index: ChangeLog
from Ugo Jardonnet <ugo.jardonnet(a)lrde.epita.fr>
Update and add : apply, local canvas.
You did not mention the addition of the first mathematical
morphological filters! :)
(And no space before colons!)
* tests/core/Makefile.am: .
* oln/function: New.
* oln/function/min.hh: New.
* oln/level/apply.hh: .
* oln/level/local.hh: New.
* oln/core/concept/image.hh: .
* oln/core/concept/functions.hh: .
* oln/core/internal/max_value.hh: New.
* oln/morphomath: New.
* oln/morphomath/dilatation.hh: New.
* oln/morphomath/erosion.hh: New.
Please, don't leave empty entries. If you want to factor a
description for several files, use commas (see how other ChangeLog
entries do that).
If a file doesn't deserve a description for the changes made to it
(space adjustment, etc.), simply don't mention it in the ChangeLog.
Index: tests/core/Makefile.am
--- tests/core/Makefile.am (revision 874)
+++ tests/core/Makefile.am (working copy)
@@ -37,7 +37,6 @@
neighb2d_SOURCES = neighb2d.cc
npoints_SOURCES = npoints.cc
window2d_SOURCES = window2d.cc
-neighb2d_SOURCES = neighb2d.cc
# Methods.
at_SOURCES = at.cc
Index: oln/function/min.hh
--- oln/function/min.hh (revision 0)
+++ oln/function/min.hh (revision 0)
@@ -0,0 +1,68 @@
+// Copyright (C) 2007 EPITA Research and
+// Development Laboratory
When you can, please reformat the first line of the copyright header
so that it fits on a single line. Of course, if the line is larger
than 80 characters, break it.
+//
+// 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_FUNCTION_MIN_HH_
+# define OLN_FUNCTION_MIN_HH_
Olena's header guards should not be followed by an underscore. In the
current case, you should have written
#ifndef OLN_FUNCTION_MIN_HH
# define OLN_FUNCTION_MIN_HH
Also, please don't use space to align the macro names.
+
+namespace oln
+{
+
+ template <typename T>
+ struct min_ : oln::Function< min_<T> >
+ {
+ typedef T argument;
+ typedef void result;
We do not use the same coding style as EPITA. The preferred way to
declare variables is:
typedef T argument;
typedef void result;
Optionally, you can align the names if the inferred layout looks
indisputably better. We sometimes do this for virtual types
declarations. But the default style is the previous one.
+
+ min_()
+ {
+ init();
+ }
+
+ void init()
+ {
+ val_ = oln_max_value(T);
+ }
+
+ T value() const
+ {
+ return val_;
+ }
+
+ template <typename U>
+ void operator()(U i) const
+ {
+ if (i < val_)
+ val_ = static_cast<T>(i);
+ }
+ private:
+ mutable T val_;
+ };
+
+}
+
+#endif /* !OLN_FUNCTION_MIN_HH_ */
Preferred ending guard style:
#endif // ! OLN_FUNCTION_MIN_HH
Otherwise, good!
Index: oln/level/apply.hh
--- oln/level/apply.hh (revision 874)
+++ oln/level/apply.hh (working copy)
@@ -63,16 +63,63 @@
namespace impl
{
- /// Generic version.
+ template < typename F >
+ struct result
+ {
+ typedef typename F::result ret;
+ };
- template <typename R, typename A, typename I>
- oln_plain_value(I, R)
- apply(R (*fun)(A), const Image<I>& input)
+ 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;
+ };
The spacing is quite odd here.
+
+
+ // APPLY //
+ //---------
If you want to produce beautiful comments, I suggest you have a look a
rebox.el (available from my account : ~levill_r/emacs/rebox.el).
+
+ template <typename F, typename I>
+ oln_plain_value(I, result<typename F>::ret)
+ apply(const F& fun, const Image<I>& input)
+ {
+ typedef argument<typename F>::ret A;
+ typedef result<typename F>::ret R;
Likewise, strange spacing.
+
+ oln_ch_value(I, R) output(input.points());
+ oln_piter(I) p(input.points());
+ for_all(p)
+ output(p) = fun( static_cast<A>(input(p)) );
+ return output;
+ }
+
+
+ // 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, R) output(input.points());
+ typedef argument<typename F>::ret A;
+ typedef result<typename F>::ret R;
+
+ oln_ch_value(I, R) output(input.points());
oln_piter(I) p(input.points());
for_all(p)
- output(p) = fun(input(p));
+ output(p) = local_apply(fun, input, p);
return output;
}
@@ -112,8 +159,11 @@
} // end of namespace oln::level::impl
+ /// Facades.
+ //----------------------------
+
+ /// Apply.
- /// Facade.
template <typename R, typename A, typename I>
oln_plain_value(I, R)
apply(R (*fun)(A), const Image<I>& input)
@@ -121,6 +171,29 @@
return impl::apply(fun, exact(input));
}
+ template <typename F, typename I>
+ oln_plain_value(I, typename F::result)
+ apply(const F& fun, const Image<I>& input)
+ {
+ return impl::apply(fun, 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 F& fun, const Image<I>& input)
+ {
+ return impl::apply_local(fun, exact(input));
+ }
+
// /// Facade.
// template <typename I, typename F>
// oln_plain_value(I, typename F::result_value)
That seems good!
Index: oln/level/local.hh
--- oln/level/local.hh (revision 0)
+++ oln/level/local.hh (revision 0)
@@ -0,0 +1,96 @@
+// Copyright (C) 2007 EPITA Research and
+// Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef OLN_LEVEL_LOCAL_HH_
+# define OLN_LEVEL_LOCAL_HH_
+
+namespace oln
+{
+
+ namespace impl
+ {
+
+ // LOCAL APPLICATION ON NBH //
+ //----------------------------
+
+ /// Local Apply on neighborhood ( nbh included in image ).
There should be no space after an opening parenthesis as well as
before a closing one.
+
+ template <typename R, typename A, typename I>
+ typename A::result
+ local_apply(const Accumulator< A >& fun,
+ const Image_with_Nbh< I >& input,
+ const oln_point( I )& p)
As for local variables, avoid aligning argument names vertically, as
it's a pain to maintain.
+ {
+ fun.init();
+ oln_niter(I) n(p, input.points());
+ for_all(n)
+ fun(input(n));
+ return fun.value();
+ }
+
+
+ /// Local Apply on neighborhood ( nhb has to be given ).
+
+ // ...FIXME
+
+
+ // LOCAL APPLICATION ON WINDOW //
+ //-------------------------------
If you want to group a set of things under a common name, I suggest
you use Doxygen's grouping tags instead :
/// Local application on window.
/// \{
// ... (enclose things here)
/// \}
The documentation produced by Doxygen will take them into account (you
can have a look at
http://www.lrde.epita.fr/~akim/compil/tc-doc/classbind_1_1BindVisitor.html
to see how it looks for the Tiger Compiler).
+
+ /// 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,
+ const Image<I>& input,
+ const oln_point(I)& p,
+ const Window<W>& win)
+ {
+ fun.init();
+ oln_qiter(W) q(p, win);
+ for_all(q)
+ fun(input(q));
+ return fun.value();
+ }
+
+ }
+
+ /// Facades.
+
+ local_apply( )
+ {
+
+ }
Hum, I suspect something is missing here. :) If so, add something
like
// FIXME: To do.
within the parentheses.
+
+}
+#endif /* !OLN_LEVEL_LOCAL_HH_ */
Index: oln/core/concept/image.hh
That's strange: is there really no diff for this file?
Index: oln/core/concept/functions.hh
--- oln/core/concept/functions.hh (revision 874)
+++ oln/core/concept/functions.hh (working copy)
@@ -73,6 +73,16 @@
};
+ // Neighborhood -> Value.
In fact, such a function could also be applied to a window, so that
comment is not exact.
+
+ template <typename Exact>
+ struct Accumulator : public Function<Exact>
+ {
+ protected:
+ Accumulator();
+ };
+
+
/*
// Value1 -> Value2 *and* Value2 -> Value1.
Index: oln/core/internal/max_value.hh
--- oln/core/internal/max_value.hh (revision 0)
+++ oln/core/internal/max_value.hh (revision 0)
@@ -0,0 +1,42 @@
+// 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_MAX_VALUE_HH_
+# define OLN_CORE_INTERNAL_MAX_VALUE_HH_
+
+#include <cassert>
+#include <limits>
+#include <iostream>
+
+namespace oln
+{
+
+#define oln_max(T) std::numeric_limits< T >::max()
+
+}
+
+#endif /* !OLN_CORE_INTERNAL_MAX_VALUE_HH_ */
Index: oln/morphomath/dilatation.hh
--- oln/morphomath/dilatation.hh (revision 0)
+++ oln/morphomath/dilatation.hh (revision 0)
The directory should be named `morpho', not `morphomath'. And we use
English terms as identifiers, so it should be `dilation', not
`dilatation'. You can have a look a Pierre Soille's book in the
library if you need the right names
(
https://www.lrde.epita.fr/openbiblio/shared/biblio_view.php?bibid=230&t…)pac).
By the way, each time you create, rename or delete a file within
Olena, you must update olena/oln/Makefile.am.
@@ -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_ */
Good.
Index: oln/morphomath/erosion.hh
--- oln/morphomath/erosion.hh (revision 0)
+++ oln/morphomath/erosion.hh (revision 0)
@@ -0,0 +1,59 @@
+// 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_MORPHOMATH_EROSION_HH_
+# define OLN_MORPHOMATH_EROSION_HH_
+
+#include <oln/fonction/min.hh>
+#include <oln/level/local.hh>
+
+namespace oln
+{
+ namespace impl
+ {
+
+ /// Generic version
+
+ template <typename I, typename W>
+ I erosion(const Image<I>& input)
+ {
+ min_<oln_value(I)> min;
+ return apply(min, input);
+ }
+ }
+
+ // Facade.
+
+ template <typename I, typename W>
+ I erosion(const Point_Wise_Accessible_Image<I>& input)
+ {
+ return impl::erosion(exact(input));
+ }
+}
+
+#endif /* !OLN_MORPHOMATH_EROSION_HH_ */
Don't forget to propagate the fixes.
Nice patch!