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
August 2007
- 2 participants
- 18 discussions
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add local convolution.
* mln/core/concept/doc/generalized_pixel.hh,
* mln/core/concept/generalized_pixel.hh,
* mln/core/internal/pixel_impl.hh (ima): New.
* mln/core/concept/doc/generalized_pixel.hh,
* mln/core/concept/doc/pixel_iterator.hh
* mln/core/concept/generalized_pixel.hh,
* mln/core/concept/pixel_iterator.hh,
* mln/core/dpoints_pixter.hh (ctor): Better sig.
(center_value): Rename as...
(center_val): ...this.
* mln/core/internal/pixel_impl.hh (operator*): Rename as...
(val): ...this.
* mln/debug/iota.hh,
* mln/histo/compute.hh,
* mln/level/apply.hh,
* mln/level/assign.hh,
* mln/level/fast_median.hh,
* mln/level/take.hh,
* mln/level/transform.hh,
* mln/linear/convolve.hh,
: Update.
* mln/core/pixel.hh (is_valid): Disambiguate.
(include): Fix.
* mln/linear/local: New directory.
* mln/linear/local/convolve.hh: New.
* mln/make/pixel.hh: New.
* mln/metal/const.hh: New.
* tests/decorated_image.cc: Fix warning.
* tests/local_convolve.cc: New.
* tests/pixel.cc: Update and augment.
* tests/pixter_point2d.cc: Rename as...
* tests/pixter2d_b.cc: ...this.
Clean, update, and augment.
* tests/pixter_dpoint2d.cc: Rename as...
* tests/dpoints_pixter.cc: ...this.
Clean, update, and augment.
mln/core/concept/doc/generalized_pixel.hh | 9 +
mln/core/concept/doc/pixel_iterator.hh | 4
mln/core/concept/generalized_pixel.hh | 14 +-
mln/core/concept/pixel_iterator.hh | 4
mln/core/dpoints_pixter.hh | 26 ++--
mln/core/internal/pixel_impl.hh | 35 +++++-
mln/core/macros.hh | 1
mln/core/pixel.hh | 12 +-
mln/debug/iota.hh | 2
mln/histo/compute.hh | 2
mln/level/apply.hh | 2
mln/level/assign.hh | 2
mln/level/fast_median.hh | 14 +-
mln/level/take.hh | 2
mln/level/transform.hh | 4
mln/linear/convolve.hh | 16 +-
mln/linear/local/convolve.hh | 174 ++++++++++++++++++++++++++++++
mln/make/pixel.hh | 78 +++++++++++++
mln/metal/const.hh | 58 ++++++++++
tests/decorated_image.cc | 2
tests/dpoints_pixter.cc | 67 ++++++-----
tests/fast_median.cc | 8 -
tests/local_convolve.cc | 78 +++++++++++++
tests/pixel.cc | 13 +-
tests/pixter2d_b.cc | 76 +++++++++----
25 files changed, 589 insertions(+), 114 deletions(-)
Index: tests/local_convolve.cc
--- tests/local_convolve.cc (revision 0)
+++ tests/local_convolve.cc (revision 0)
@@ -0,0 +1,78 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/*! \file tests/convolve.cc
+ *
+ * \brief Tests on mln::linear::convolve.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/core/w_window2d_int.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/core/pixel.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/pw/cst.hh>
+#include <mln/border/thickness.hh>
+#include <mln/linear/local/convolve.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ const unsigned size = 3;
+ border::thickness = size - 1;
+
+ image2d_b<int_u8> ima(size, size);
+ debug::iota(ima);
+
+ point2d p = make::point2d(1,1);
+ w_window2d_int w_win = make::w_window(win::rectangle2d(size, size),
+ pw::cst(1));
+
+ int res;
+ {
+ linear::local::convolve(ima, p, w_win, res);
+ mln_assertion(res = size*size * (size*size + 1) / 2);
+ }
+
+ {
+ typedef image2d_b<int_u8> I;
+ linear::local::convolve(pixel<const I>(ima, p), w_win, res);
+ linear::local::convolve(pixel<I>(ima, p), w_win, res);
+ }
+ {
+ linear::local::convolve(make::pixel(ima, p), w_win, res);
+ mln_assertion(res = size*size * (size*size + 1) / 2);
+ }
+
+ res = 0;
+}
Index: tests/fast_median.cc
--- tests/fast_median.cc (revision 1053)
+++ tests/fast_median.cc (working copy)
@@ -57,16 +57,16 @@
{
mln_qixter(I, W) qix(input, win, p);
for_all(qix)
- std::cout << *qix << ' ';
- std::cout << " : " << qix.center_value() << std::endl;
+ std::cout << qix.val() << ' ';
+ std::cout << " : " << qix.center_val() << std::endl;
}
{
pixel<I> pix(input, p);
mln_qixter(I, W) qix(input, win, pix);
for_all(qix)
- std::cout << *qix << ' ';
- std::cout << " : " << qix.center_value() << std::endl;
+ std::cout << qix.val() << ' ';
+ std::cout << " : " << qix.center_val() << std::endl;
}
}
Index: tests/decorated_image.cc
--- tests/decorated_image.cc (revision 1053)
+++ tests/decorated_image.cc (working copy)
@@ -39,7 +39,7 @@
template <typename I>
struct counter
{
- void reading(const I& ima, const mln_psite(I)& p) const
+ void reading(const I&, const mln_psite(I)&) const
{
++count_read;
}
Index: tests/pixter2d_b.cc
--- tests/pixter2d_b.cc (revision 1053)
+++ tests/pixter2d_b.cc (working copy)
@@ -25,38 +25,70 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#include <cassert>
-#include <mln/core/image2d_b.hh>
+/*! \file tests/pixter2d_b.cc
+ *
+ * \brief Tests on mln::fwd_pixter2d_b.
+ */
+#include <mln/core/image2d_b.hh>
-int
-main()
-{
- using namespace mln;
- typedef image2d_b<int> I;
- I ima(20, 20);
+const unsigned size = 20;
+const int v = 51;
- mln_piter_(I) p(ima.domain());
- mln_pixter_(I) pix(ima);
- int i = 0;
+template <typename I>
+void test_fill(I& ima)
+{
+ mln_pixter(I) pxl(ima);
+ unsigned i = 0;
+ for_all(pxl)
+ {
+ ++i;
+ pxl.val() = v;
+ }
+ mln_assertion(i = size * size);
+ mln_assertion(! pxl.is_valid());
+ mln_piter(I) p(ima.domain());
for_all(p)
- ima(p) = i++;
- i = 0;
+ mln_assertion(ima(p) = v);
+}
- for_all(pix)
+
+template <typename I>
+void test_const(const I& imac, I& ima)
+{
{
- mln_assertion(*pix = i ++);
- *pix = 5;
+ mln_pixter(const I) pxl(imac); // const is mandatory
+ pxl.start();
+ mln_assertion(pxl.val() = v);
+ // pxl.val() = v; // error is OK since pixter on 'const I'
+ }
+ {
+ // mln_pixter(I) pxl_(imac); // error is OK since mutable I but const imac
+ mln_pixter(I) pxl(ima);
+ pxl.start();
+ pxl.val() = 2 * pxl.val();
+ mln_assertion(pxl.val() = 2 * v);
+ }
+ {
+ mln_pixter(const I) pxl(ima); // const promotion is OK
+ pxl.start();
+ mln_assertion(pxl.val() = 2 * v);
+ // pxl.val() = v; // error is OK since pixter on 'const I'
+ }
}
- for_all(p)
- mln_assertion(ima(p) = 5);
- pix.start();
- mln_assertion(pix.is_valid());
- pix.invalidate();
- mln_assertion(! pix.is_valid());
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(size, size);
+
+ test_fill(ima);
+ test_const(ima, ima);
}
Index: tests/dpoints_pixter.cc
--- tests/dpoints_pixter.cc (revision 1053)
+++ tests/dpoints_pixter.cc (working copy)
@@ -25,49 +25,56 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/pixter_dpoint2d.cc
+/*! \file tests/dpoints_pixter.cc
*
* \brief Test on mln::dpoints_fwd_pixter.
*/
-#include <cassert>
-#include <iostream>
-
#include <mln/core/image2d_b.hh>
-#include <mln/core/window.hh>
-#include <mln/core/dpoints_pixter.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/make/pixel.hh>
-#include <mln/level/fill.hh>
-int main()
+template <typename I, typename W>
+void test_fill(I& ima, const W& win)
{
- using namespace mln;
+ mln_piter(I) p(ima.domain());
+ mln_qixter(I, W) q(ima, win, p);
+ for_all(p)
+ {
+ unsigned i = 0;
+ for_all(q)
+ ++i, q.val() = 51;
+ mln_assertion(i = 9);
+ }
+}
- typedef image2d_b<int> I;
- typedef I::dpoint D;
- typedef window<D> W;
- typedef dpoints_fwd_pixter<I> qixter;
+// FIXME: test promotion and other constructions
- const unsigned size = 20;
- I ima(size, size);
- const int value = 51;
- level::fill(ima, value);
-
- W win;
- win
- .insert(make::dpoint2d(0, -1))
- .insert(make::dpoint2d(0, -1))
- .insert(make::dpoint2d(1, 0))
- .insert(make::dpoint2d(1, 0));
+template <typename P, typename W>
+void test_pixel(const P& pxl, const W& win)
+{
+ mln_qixter(mln_image(P), W) q(pxl, win);
+ for_all(q)
+ q.val() = 2 * q.val();
+}
- mln_piter_(I) p(ima.domain());
- qixter qix(ima, win, p);
- for_all(p)
- if (p[0] > 0 && p[1] > 0 && p[0] < int(size - 1) && p[1] < int(size - 1))
- for_all(qix)
- mln_assertion(*qix = value);
+
+int main()
+{
+ using namespace mln;
+
+ border::thickness = 1;
+ typedef image2d_b<int> I;
+ I ima(5, 5);
+
+ win::rectangle2d rect(3, 3);
+ point2d p = make::point2d(1, 1);
+
+ test_fill(ima, rect);
+ test_pixel(make::pixel(ima, p), rect);
}
Index: tests/pixel.cc
--- tests/pixel.cc (revision 1053)
+++ tests/pixel.cc (working copy)
@@ -30,8 +30,9 @@
* \brief Tests on mln::pixel.
*/
-#include <mln/core/pixel.hh>
#include <mln/core/image2d_b.hh>
+#include <mln/core/pixel.hh>
+#include <mln/metal/equal.hh>
int main()
@@ -43,18 +44,22 @@
{
pixel<I> pxl(ima, make::point2d(1, 1));
- *pxl = 51;
+ pxl.val() = 51;
mln_assertion(ima.at(1, 1) = 51);
}
{
pixel<const I> pxl(ima, make::point2d(1, 1));
ima.at(1, 1) = 51;
- mln_assertion(*pxl = 51);
+ mln_assertion(pxl.val() = 51);
// hopefully the code below does not compile:
- // *pxl = 0;
+ // pxl.val() = 0;
// assignment of read-only location
}
+ {
+ mln::metal::equal< mln_image_(pixel<I>), I >::check();
+ mln::metal::equal< mln_image_(pixel<const I>), const I >::check();
+ }
}
Index: mln/histo/compute.hh
--- mln/histo/compute.hh (revision 1053)
+++ mln/histo/compute.hh (working copy)
@@ -71,7 +71,7 @@
data<mln_vset(I)> h(input.values());
mln_pixter(const I) p(input);
for_all(p)
- ++h(*p);
+ ++h(p.val());
return h;
}
Index: mln/debug/iota.hh
--- mln/debug/iota.hh (revision 1053)
+++ mln/debug/iota.hh (working copy)
@@ -69,7 +69,7 @@
I& input = exact(input_);
mln_pixter(I) p(input);
for_all(p)
- *p = ++i;
+ p.val() = ++i;
}
} // end of namespace mln::debug::impl
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1053)
+++ mln/core/macros.hh (working copy)
@@ -94,6 +94,7 @@
/// Shortcut to access the image type associated to T.
# define mln_image(T) typename T::image
+# define mln_image_(T) T::image
// l
Index: mln/core/dpoints_pixter.hh
--- mln/core/dpoints_pixter.hh (revision 1053)
+++ mln/core/dpoints_pixter.hh (working copy)
@@ -71,14 +71,12 @@
/*! \brief Constructor.
*
- * \param[in] image Image subject to iteration.
+ * \param[in] pxl_ref Center (generalized) pixel to iterate around.
* \param[in] dps Object that can provide a set of delta-points.
- * \param[in] p_ref Center (generalized) pixel to iterate around.
*/
template <typename Dps, typename Pref>
- dpoints_fwd_pixter(I& image,
- const Dps& dps,
- const Generalized_Pixel<Pref>& p_ref);
+ dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref,
+ const Dps& dps);
/// Start an iteration.
void start();
@@ -97,7 +95,7 @@
void update();
/// The value around which this iterator moves.
- const mln_value(I)& center_value() const;
+ const mln_value(I)& center_val() const;
private:
@@ -140,23 +138,23 @@
init_(dps);
}
-
template <typename I>
template <typename Dps, typename Pref>
- dpoints_fwd_pixter<I>::dpoints_fwd_pixter(I& image,
- const Dps& dps,
- const Generalized_Pixel<Pref>& p_ref)
- : super_(image)
+ dpoints_fwd_pixter<I>::dpoints_fwd_pixter(const Generalized_Pixel<Pref>& pxl_ref_,
+ const Dps& dps)
+ : super_(internal::force_exact<Pref>(pxl_ref_).ima())
{
- mln_precondition(image.has_data());
+ const Pref& pxl_ref = internal::force_exact<Pref>(pxl_ref_);
+ mln_precondition(pxl_ref.ima().has_data());
p_ref_ = 0;
- value_ref_ = internal::force_exact<Pref>(p_ref).address_();
+ // potential promotion from (T**) to (const T**) shall be forced:
+ value_ref_ = (mln_qlf_value(I)**)(void*)(pxl_ref.address_());
init_(dps);
}
template <typename I>
const mln_value(I)&
- dpoints_fwd_pixter<I>::center_value() const
+ dpoints_fwd_pixter<I>::center_val() const
{
mln_invariant(value_ref_ != 0 || p_ref_ != 0);
if (p_ref_)
Index: mln/core/internal/pixel_impl.hh
--- mln/core/internal/pixel_impl.hh (revision 1053)
+++ mln/core/internal/pixel_impl.hh (working copy)
@@ -67,10 +67,14 @@
/// pixel iterator value.
- lvalue operator*();
+ lvalue val();
/// Get the pixel iterator value.
- rvalue operator*() const;
+ rvalue val() const;
+
+
+ /// Give the pixel image.
+ I& ima() const;
/// Address of the current iterator value/pixel.
@@ -113,7 +117,11 @@
/// Get the pixel iterator value.
- rvalue operator*() const;
+ rvalue val() const;
+
+
+ /// Give the pixel image.
+ const I& ima() const;
/// Address of the current iterator value/pixel.
@@ -155,7 +163,7 @@
template <typename I, typename E>
mln_lvalue(I)
- pixel_impl_<I, E>::operator*()
+ pixel_impl_<I, E>::val()
{
mln_precondition(is_valid_());
return *value_ptr_;
@@ -163,13 +171,21 @@
template <typename I, typename E>
mln_rvalue(I)
- pixel_impl_<I, E>::operator*() const
+ pixel_impl_<I, E>::val() const
{
mln_precondition(is_valid_());
return *value_ptr_;
}
template <typename I, typename E>
+ I&
+ pixel_impl_<I, E>::ima() const
+ {
+ // a const pixel, yet a mutable image
+ return const_cast<I&>(image_);
+ }
+
+ template <typename I, typename E>
mln_value(I) **
pixel_impl_<I, E>::address_() const
{
@@ -195,13 +211,20 @@
template <typename I, typename E>
mln_rvalue(I)
- pixel_impl_<const I, E>::operator*() const
+ pixel_impl_<const I, E>::val() const
{
mln_precondition(is_valid_());
return *value_ptr_;
}
template <typename I, typename E>
+ const I&
+ pixel_impl_<const I, E>::ima() const
+ {
+ return image_;
+ }
+
+ template <typename I, typename E>
const mln_value(I) **
pixel_impl_<const I, E>::address_() const
{
Index: mln/core/pixel.hh
--- mln/core/pixel.hh (revision 1053)
+++ mln/core/pixel.hh (working copy)
@@ -96,12 +96,11 @@
bool
pixel<I>::is_valid() const
{
- I& ima = this->image_;
- if (this->value_ptr_ = 0 || ! ima.has_data())
+ if (this->value_ptr_ = 0 || ! this->image_.has_data())
return false;
- int o = this->value_ptr_ - ima.buffer();
- mln_point(I) p = ima.point_at_offset(o);
- return ima.owns_(p);
+ int o = this->value_ptr_ - this->image_.buffer();
+ mln_point(I) p = this->image_.point_at_offset(o);
+ return this->image_.owns_(p);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -109,4 +108,7 @@
} // end of namespace mln
+# include <mln/make/pixel.hh>
+
+
#endif // ! MLN_CORE_PIXEL_HH
Index: mln/core/concept/pixel_iterator.hh
--- mln/core/concept/pixel_iterator.hh (revision 1053)
+++ mln/core/concept/pixel_iterator.hh (working copy)
@@ -57,7 +57,7 @@
only if the iterator is constructed on a mutable image:
typedef lvalue;
- lvalue operator*();
+ lvalue val();
*/
protected:
Pixel_Iterator();
@@ -70,7 +70,7 @@
Pixel_Iterator<E>::Pixel_Iterator()
{
// typedef mln_lvalue(E) lvalue;
-// lvalue (E::*m)() = & E::operator*;
+// lvalue (E::*m)() = & E::val;
// m = 0;
}
Index: mln/core/concept/generalized_pixel.hh
--- mln/core/concept/generalized_pixel.hh (revision 1053)
+++ mln/core/concept/generalized_pixel.hh (working copy)
@@ -62,9 +62,10 @@
/*
typedef value;
typedef rvalue;
- typedef image;
+ typedef image; // is const or not
- rvalue operator*() const;
+ rvalue val() const;
+ image& ima() const;
mln_qlf_value(image)** address_() const;
*/
protected:
@@ -80,13 +81,16 @@
typedef mln_value(E) value;
typedef mln_rvalue(E) rvalue;
- rvalue (E::*m1)() const = & E::operator*;
+ rvalue (E::*m1)() const = & E::val;
m1 = 0;
typedef mln_image(E) image;
-
- mln_qlf_value(image)** (E::*m2)() const = & E::address_;
+ // FIXME: check "without &"
+ image& (E::*m2)() const = & E::ima;
m2 = 0;
+
+ mln_qlf_value(image)** (E::*m3)() const = & E::address_;
+ m3 = 0;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/pixel_iterator.hh
--- mln/core/concept/doc/pixel_iterator.hh (revision 1053)
+++ mln/core/concept/doc/pixel_iterator.hh (working copy)
@@ -47,12 +47,12 @@
*/
typedef void lvalue;
- /*! \brief Dereference operator.
+ /*! \brief Give the pixel value.
*
* \return The current pixel value; this value cannot be
* modified.
*/
- lvalue operator*() const;
+ lvalue val() const;
protected:
Pixel_Iterator();
Index: mln/core/concept/doc/generalized_pixel.hh
--- mln/core/concept/doc/generalized_pixel.hh (revision 1053)
+++ mln/core/concept/doc/generalized_pixel.hh (working copy)
@@ -61,7 +61,14 @@
*
* \return A read-only value.
*/
- rvalue operator*() const;
+ rvalue val() const;
+
+ /*! \brief Give the image of this generalized pixel.
+ *
+ * The constness of a pixel object is not transmitted to the
+ * underlying image.
+ */
+ image& ima() const;
/*! \brief Give a hook to the value address.
*
Index: mln/metal/const.hh
--- mln/metal/const.hh (revision 0)
+++ mln/metal/const.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 MLN_METAL_CONST_HH
+# define MLN_METAL_CONST_HH
+
+
+# define mlc_const(T) typename mln::metal::const_< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct const_
+ {
+ typedef const T ret;
+ };
+
+ template <typename T>
+ struct const_< const T >
+ {
+ typedef const T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_CONST_HH
Index: mln/level/take.hh
--- mln/level/take.hh (revision 1053)
+++ mln/level/take.hh (working copy)
@@ -77,7 +77,7 @@
const I& input = exact(input_);
mln_pixter(const I) pxl(input);
for_all(pxl)
- a.take(*pxl);
+ a.take(pxl.val());
}
} // end of namespace mln::level::impl
Index: mln/level/assign.hh
--- mln/level/assign.hh (revision 1053)
+++ mln/level/assign.hh (working copy)
@@ -80,7 +80,7 @@
mln_pixter(L) lhs(target);
mln_pixter(const R) rhs(data);
for_all_2(lhs, rhs)
- *lhs = *rhs;
+ lhs.val() = rhs.val();
}
} // end of namespace mln::level::impl
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 1053)
+++ mln/level/apply.hh (working copy)
@@ -86,7 +86,7 @@
mln_pixter(const I) pxl(input);
for_all(pxl)
- f(input(*pxl));
+ f(pxl.val());
return f;
}
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 1053)
+++ mln/level/fast_median.hh (working copy)
@@ -99,7 +99,7 @@
{
mln_qixter(const I, W) q(input, win, p);
for_all(q)
- med.take(*q);
+ med.take(q.val());
}
int& row = p.row();
@@ -114,10 +114,10 @@
// "go down"
for_all(q_top)
- med.untake(*q_top);
+ med.untake(q_top.val());
for_all(q_bot)
- med.take(*q_bot);
+ med.take(q_bot.val());
output(p) = med.to_value();
@@ -127,9 +127,9 @@
{
++col;
for_all(q_fm)
- med.untake(*q_fm);
+ med.untake(q_fm.val());
for_all(q_fp)
- med.take(*q_fp);
+ med.take(q_fp.val());
output(p) = med.to_value();
}
else
@@ -138,9 +138,9 @@
{
--col;
for_all(q_bm)
- med.untake(*q_bm);
+ med.untake(q_bm.val());
for_all(q_bp)
- med.take(*q_bp);
+ med.take(q_bp.val());
output(p) = med.to_value();
}
// change browsing
Index: mln/level/transform.hh
--- mln/level/transform.hh (revision 1053)
+++ mln/level/transform.hh (working copy)
@@ -31,6 +31,8 @@
/*! \file mln/level/transform.hh
*
* \brief Transform the contents of an image into another one.
+ *
+ * \todo Clean this file + overload with pixel iterators.
*/
# include <mln/core/concept/image.hh>
@@ -110,7 +112,7 @@
// po.start();
// for_all(pi)
// {
-// *po = lut(*pi);
+// po.val() = lut(pi.val());
// po.next();
// }
// }
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1053)
+++ mln/linear/convolve.hh (working copy)
@@ -46,11 +46,14 @@
namespace linear
{
- /*! Convolution of image \p input by the weighted window \p win.
+ /*! Convolution of image \p input by the weighted window \p w_win.
*
* \warning Computation of \p output(p) is performed with the
* value type of \p output.
*
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ *
* \pre output.domain = input.domain
*/
template <typename I, typename W, typename O>
@@ -97,26 +100,29 @@
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
- mln_qixter(const I, W) q(input, w_win, p);
+ mln_qixter(const I, W) q(p, w_win);
for_all_2(p, p_out)
{
mln_value(O) v = 0;
unsigned i = 0;
for_all(q)
- v += w_win.w(i++) * *q;
- *p_out = v;
+ v += w_win.w(i++) * q.val();
+ p_out.val() = v;
}
}
} // end of namespace mln::linear::impl
+
+ // Facade.
+
template <typename I, typename W, typename O>
void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::convolve(exact(input), - exact(w_win), exact(output));
+ impl::convolve(exact(input), exact(w_win), exact(output));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/local/convolve.hh
--- mln/linear/local/convolve.hh (revision 0)
+++ mln/linear/local/convolve.hh (revision 0)
@@ -0,0 +1,174 @@
+// 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 MLN_LINEAR_LOCAL_CONVOLVE_HH
+# define MLN_LINEAR_LOCAL_CONVOLVE_HH
+
+/*! \file mln/linear/local/convolve.hh
+ *
+ * \brief Local convolution at a point.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/concept/generalized_point.hh>
+# include <mln/core/concept/generalized_pixel.hh>
+# include <mln/core/concept/weighted_window.hh>
+# include <mln/metal/const.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ namespace local
+ {
+
+ /*! Local convolution of image \p input at point \p p by the
+ * weighted window \p w_win.
+ *
+ * \warning Computation of the \p result is performed with the
+ * type \c R.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ */
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Image<I>& input,
+ const Generalized_Point<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result);
+
+
+ /*! Local convolution around (generalized) pixel \p by the
+ * weighted window \p w_win.
+ *
+ * \warning Computation of the \p result is performed with the
+ * type \c R.
+ *
+ * \warning The weighted window is used as-is, considering that
+ * its symmetrization is handled by the client.
+ */
+ template <typename P, typename W, typename R>
+ void convolve(const Generalized_Pixel<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Image<I>& input_,
+ const Generalized_Point<P>& p_,
+ const W& w_win,
+ R& result)
+ {
+ const I& input = exact(input_);
+ const P& p = internal::force_exact<P>(p_);
+
+ R tmp = 0; // FIXME: zero?
+ mln_qiter(W) q(w_win, p);
+ for_all(q) if (input.has(q))
+ tmp += input(q) * q.w();
+ result = tmp;
+ }
+
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Fast_Image<I>& input_,
+ const Generalized_Point<P>& p_,
+ const W& w_win,
+ R& result)
+ {
+ const I& input = exact(input_);
+ const P& p = internal::force_exact<P>(p_);
+
+ mln_precondition(input.border() >= w_win.delta());
+
+ R tmp = 0;
+ unsigned i = 0;
+ mln_qixter(const I, W) q(input, w_win, p);
+ for_all(q)
+ tmp += w_win.w(i++) * q.val();
+ result = tmp;
+ }
+
+ template <typename P, typename W, typename R>
+ void convolve(const Generalized_Pixel<P>& p_,
+ const W& w_win,
+ R& result)
+ {
+ const P& p = internal::force_exact<P>(p_);
+ mln_precondition(p.ima().border() >= w_win.delta());
+
+ R tmp = 0;
+ unsigned i = 0;
+ // FIXME: mln_qixter(const P, W) should work
+ // FIXME: so make the trait make this job...
+ mln_qixter(mlc_const(mln_image(P)), W) q(p, w_win);
+ for_all(q)
+ tmp += w_win.w(i++) * q.val();
+ result = tmp;
+ }
+
+ } // end of namespace mln::linear::impl
+
+
+ // Facades.
+
+ template <typename I, typename P, typename W, typename R>
+ void convolve(const Image<I>& input,
+ const Generalized_Point<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result)
+ {
+ mln_precondition(exact(input).has_data());
+ impl::convolve(exact(input), p, exact(w_win), result);
+ }
+
+ template <typename P, typename W, typename R>
+ void convolve(const Generalized_Pixel<P>& p,
+ const Weighted_Window<W>& w_win,
+ R& result)
+ {
+ impl::convolve(p, exact(w_win), result);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear::local
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LOCAL_CONVOLVE_HH
Index: mln/make/pixel.hh
--- mln/make/pixel.hh (revision 0)
+++ mln/make/pixel.hh (revision 0)
@@ -0,0 +1,78 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_PIXEL_HH
+# define MLN_MAKE_PIXEL_HH
+
+/*! \file mln/make/pixel.hh
+ *
+ * \brief Routine to construct an mln::pixel.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/pixel.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /// Create an mln::pixel from a constant image \p ima and a point \p p.
+ template <typename I>
+ mln::pixel<const I> pixel(const Image<I>& ima, const mln_point(I)& p);
+
+ /// Create an mln::pixel from a mutable image \p ima and a point \p p.
+ template <typename I>
+ mln::pixel<I> pixel(Image<I>& ima, const mln_point(I)& p);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln::pixel<const I> pixel(const Image<I>& ima, const mln_point(I)& p)
+ {
+ mln::pixel<const I> tmp(exact(ima), p);
+ return tmp;
+ }
+
+ template <typename I>
+ mln::pixel<I> pixel(Image<I>& ima, const mln_point(I)& p)
+ {
+ mln::pixel<I> tmp(exact(ima), p);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_PIXEL_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add proper inheritance to functions.
* mln/core/concept/doc/neighborhood.hh,
* mln/core/concept/neighborhood.hh,
* mln/core/neighb.hh (point): New.
* mln/convert/to_image.hh
(helper_dim_, helper_image_from_): New in mln::internal.
(image_from_): New in mln.
(mln_image_from): New macro.
(to_image): Fix; now generalized.
* mln/metal/all.hh: New.
* mln/metal/equal.hh: Update.
(mlc_equal): New.
* mln/metal/if.hh: New.
* mln/metal/is_a.hh: New.
* mln/metal/unptr.hh: New.
* mln/metal/unqualif.hh: New.
* mln/metal/unref.hh: New.
* mln/core/concept/function.hh (result): New in Function_p2b.
* mln/fun/internal: New directory.
* mln/pw/cst.hh: Precise inheritance.
* mln/pw/value.hh: Likewise.
(select_function_): Move to...
* mln/fun/internal/selector.hh: ...this new file.
(select_function_): Rename as...
(selector_): ...this.
* mln/fun/c.hh: New.
* mln/convert/to_fun.hh: New.
* mln/convert/to_window.hh (to_window): New overload.
* mln/estim/mean.hh (mean): New overload.
* mln/estim/sum.hh: New.
* mln/level/run.hh: Rename as...
* mln/level/compute.hh: ...this.
(run): Rename as...
(compute): ...this.
* tests/w_window2d_int.cc: Augment.
mln/convert/to_fun.hh | 77 ++++++++++++++++
mln/convert/to_image.hh | 59 ++++++++++--
mln/convert/to_window.hh | 29 ++++--
mln/core/concept/doc/neighborhood.hh | 3
mln/core/concept/function.hh | 1
mln/core/concept/neighborhood.hh | 2
mln/core/neighb.hh | 3
mln/estim/mean.hh | 28 +++++
mln/estim/sum.hh | 88 ++++++++++++++++++
mln/fun/c.hh | 85 +++++++++++++++++
mln/fun/internal/selector.hh | 168 +++++++++++++++++++++++++++++++++++
mln/level/compute.hh | 18 +--
mln/metal/all.hh | 58 ++++++++++++
mln/metal/equal.hh | 16 +--
mln/metal/if.hh | 85 +++++++++++++++++
mln/metal/is_a.hh | 88 ++++++++++++++++++
mln/metal/unptr.hh | 58 ++++++++++++
mln/metal/unqualif.hh | 58 ++++++++++++
mln/metal/unref.hh | 58 ++++++++++++
mln/pw/cst.hh | 13 +-
mln/pw/value.hh | 21 ----
tests/pw_value.cc | 1
tests/w_window2d_int.cc | 24 +++--
23 files changed, 968 insertions(+), 73 deletions(-)
Index: tests/w_window2d_int.cc
--- tests/w_window2d_int.cc (revision 1052)
+++ tests/w_window2d_int.cc (working copy)
@@ -35,23 +35,22 @@
#include <mln/convert/to_image.hh>
#include <mln/convert/to_w_window.hh>
-#include <mln/debug/println.hh>
+#include <mln/convert/to_fun.hh>
+#include <mln/estim/sum.hh>
-struct my_f : mln::Function_p2v< my_f >
-{
- typedef int result;
- int operator()(const mln::point2d& p) const
+
+int f(mln::point2d p)
{
return p.row() + p.col();
}
-};
int main()
{
using namespace mln;
+ {
int ws[] = { -1, 0, 1,
-2, 0, 2,
-1, 0, 1 };
@@ -60,7 +59,16 @@
image2d_b<int> ima = convert::to_image(w_win);
w_window2d_int w_win_2 = convert::to_w_window(ima);
mln_assertion(w_win_2 = w_win);
+ }
+
+ {
+ w_window2d_int w_win = make::w_window(win::rectangle2d(3, 5),
+ convert::to_fun(f));
+ // -3 -2 -1 0 +1
+ // -2 -1 0 +1 +2
+ // -1 0 +1 +2 +3
+ image2d_b<int> ima = convert::to_image(w_win);
+ mln_assertion(estim::sum(ima) = 0);
+ }
- w_window2d_int tmp = make::w_window(win::rectangle2d(3, 5), my_f());
- debug::println(convert::to_image(tmp));
}
Index: tests/pw_value.cc
--- tests/pw_value.cc (revision 1052)
+++ tests/pw_value.cc (working copy)
@@ -43,6 +43,5 @@
image2d_b<int> ima(3, 3);
point2d p = make::point2d(1, 1);
ima(p) = 51;
-
mln_assertion( (pw::value(ima) = pw::cst(51))(p) = true );
}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 1052)
+++ mln/convert/to_image.hh (working copy)
@@ -45,36 +45,73 @@
# include <mln/level/fill.hh>
+# define mln_image_from(Src, Value) typename mln::image_from_< Src, Value >::ret
+
+
+
namespace mln
{
+ // FIXME: Move elsewhere.
+ namespace internal
+ {
+
+ template <typename T>
+ struct helper_dim_
+ {
+ typedef mln_point(T) P;
+ enum { value = P::dim };
+ };
+
+ template <unsigned dim, typename V> struct helper_image_from_;
+
+ template <typename V>
+ struct helper_image_from_< 2, V >
+ {
+ typedef image2d_b<V> ret;
+ };
+
+ } // end of namespace mln::internal
+
+
+ // FIXME: Doc + move elsewhere!
+ template <typename T, typename V>
+ struct image_from_
+ {
+ enum { dim = internal::helper_dim_<T>::value };
+ typedef typename internal::helper_image_from_< dim, V >::ret ret;
+ };
+
+
+
namespace convert
{
+
/// Convert a point set \p pset into a binary image.
template <typename S>
- image2d_b<bool> to_image(const Point_Set<S>& pset);
+ mln_image_from(S, bool) to_image(const Point_Set<S>& pset);
/// Convert a window \p win into a binary image.
template <typename W>
- image2d_b<bool> to_image(const Window<W>& win);
+ mln_image_from(W, bool) to_image(const Window<W>& win);
/// Convert a neighborhood \p nbh into a binary image.
template <typename N>
- image2d_b<bool> to_image(const Neighborhood<N>& nbh);
+ mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh);
/// Convert a weighted window \p w_win into an image.
template <typename W>
- image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
+ mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win);
# ifndef MLN_INCLUDE_ONLY
template <typename S>
- image2d_b<bool> to_image(const Point_Set<S>& pset_)
+ mln_image_from(S, bool) to_image(const Point_Set<S>& pset_)
{
const S& pset = exact(pset_);
- image2d_b<bool> ima(pset.bbox());
+ mln_image_from(S, bool) ima(pset.bbox());
level::fill(ima, false);
mln_piter(S) p(pset);
for_all(p)
@@ -83,14 +120,14 @@
}
template <typename W>
- image2d_b<bool> to_image(const Window<W>& win_)
+ mln_image_from(W, bool) to_image(const Window<W>& win_)
{
const W& win = exact(win_);
mln_precondition(! win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(win);
- image2d_b<bool> ima(b);
+ mln_image_from(W, bool) ima(b);
level::fill(ima, false);
mln_qiter(W) q(win, P::zero);
for_all(q)
@@ -99,20 +136,20 @@
}
template <typename N>
- image2d_b<bool> to_image(const Neighborhood<N>& nbh)
+ mln_image_from(N, bool) to_image(const Neighborhood<N>& nbh)
{
return to_image(convert::to_window(nbh));
}
template <typename W>
- image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
+ mln_image_from(W, mln_weight(W)) to_image(const Weighted_Window<W>& w_win_)
{
const W& w_win = exact(w_win_);
mln_precondition(! w_win.is_empty());
typedef mln_point(W) P;
box2d b = geom::bbox(w_win);
- image2d_b<mln_weight(W)> ima(b);
+ mln_image_from(W, mln_weight(W)) ima(b);
mln_qiter(W) q(w_win, P::zero);
for_all(q)
ima(q) = q.w();
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1052)
+++ mln/convert/to_window.hh (working copy)
@@ -33,9 +33,10 @@
* \brief Conversions to mln::window.
*/
-# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
namespace mln
@@ -48,9 +49,13 @@
template <typename N>
window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
- /// Convert a binary image \p input into a window.
+ /// Convert a binary image \p ima into a window.
template <typename I>
- window<mln_dpoint(I)> to_window(const Image<I>& input);
+ window<mln_dpoint(I)> to_window(const Image<I>& ima);
+
+ /// Convert a point set \p pset into a window.
+ template <typename S, typename F>
+ window<mln_dpoint(S)> to_window(const Point_Set<S>& pset);
# ifndef MLN_INCLUDE_ONLY
@@ -69,21 +74,27 @@
}
template <typename I>
- window<mln_dpoint(I)> to_window(const Image<I>& input_)
+ window<mln_dpoint(I)> to_window(const Image<I>& ima_)
{
- const I& input = exact(input_);
- mln_precondition(input.has_data());
- // FIXME: Check that input is binary!
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+ // FIXME: Check that ima is binary!
typedef mln_dpoint(I) D;
typedef mln_point(D) P;
window<D> win;
- mln_piter(I) p(input.domain());
+ mln_piter(I) p(ima.domain());
for_all(p)
- if (input(p))
+ if (ima(p))
win.insert(p - P::zero);
return win;
}
+ template <typename S, typename F>
+ window<mln_dpoint(S)> to_window(const Point_Set<S>& pset)
+ {
+ return to_window(pw::cst(true) | pset);
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_fun.hh
--- mln/convert/to_fun.hh (revision 0)
+++ mln/convert/to_fun.hh (revision 0)
@@ -0,0 +1,77 @@
+// 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 MLN_CONVERT_TO_FUN_HH
+# define MLN_CONVERT_TO_FUN_HH
+
+/*! \file mln/convert/to_fun.hh
+ *
+ * \brief Conversions towards some mln::Function.
+ */
+
+# include <mln/pw/value.hh>
+# include <mln/fun/c.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert a C unary function into an mln::fun::C.
+ template <typename R, typename A>
+ fun::C<R(*)(A)> to_fun(R (*f)(A));
+
+ /// Convert an image into a function.
+ template <typename I>
+ pw::value_<I> to_fun(const Image<I>& ima);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R, typename A>
+ fun::C<R(*)(A)> to_fun(R (*f_)(A))
+ {
+ fun::C<R(*)(A)> f(f_);
+ return f;
+ }
+
+ template <typename I>
+ pw::value_<I> to_fun(const Image<I>& ima)
+ {
+ return pw::value(ima);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_FUN_HH
Index: mln/estim/sum.hh
--- mln/estim/sum.hh (revision 0)
+++ mln/estim/sum.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ESTIM_SUM_HH
+# define MLN_ESTIM_SUM_HH
+
+/*! \file mln/estim/sum.hh
+ *
+ * \brief Compute the sum pixel value.
+ */
+
+# include <mln/accu/sum.hh>
+# include <mln/level/compute.hh>
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+ /*! \brief Compute the sum value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \return The sum value.
+ */
+ template <typename I>
+ mln_sum(mln_value(I)) sum(const Image<I>& input);
+
+
+ /*! \brief Compute the sum value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] result The sum value.
+ */
+ template <typename I, typename S>
+ void sum(const Image<I>& input, S& result);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ mln_sum(mln_value(I)) sum(const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ return level::compute(input, accu::sum<mln_value(I)>()).to_value();
+ }
+
+ template <typename I, typename S>
+ void sum(const Image<I>& input, S& result)
+ {
+ mln_precondition(exact(input).has_data());
+ result = level::compute(input,
+ accu::sum<mln_value(I), S>()).to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_SUM_HH
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1052)
+++ mln/estim/mean.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/accu/mean.hh>
-# include <mln/level/run.hh>
+# include <mln/level/compute.hh>
namespace mln
@@ -46,20 +46,40 @@
/*! \brief Compute the mean value of the pixels of image \p input.
*
* \param[in] input The image.
+ * \return The mean value.
*/
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input);
+ /*! \brief Compute the mean value of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] result The mean value.
+ *
+ * The free parameter \c S is the type used to compute the
+ * summation.
+ */
+ template <typename S, typename I, typename M>
+ void mean(const Image<I>& input, M& result);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input)
{
mln_precondition(exact(input).has_data());
- typedef mln_value(I) V;
- typedef mln_sum(V) S;
- return level::run(input, accu::mean<V, S>()).to_value();
+ return level::compute(input,
+ accu::mean<mln_value(I)>()).to_value();
+ }
+
+ template <typename S, typename I, typename M>
+ void mean(const Image<I>& input, M& result)
+ {
+ mln_precondition(exact(input).has_data());
+ result = level::compute(input,
+ accu::mean<mln_value(I), S, M>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/pw/cst.hh
--- mln/pw/cst.hh (revision 1052)
+++ mln/pw/cst.hh (working copy)
@@ -33,7 +33,7 @@
* \brief FIXME.
*/
-# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
namespace mln
@@ -45,11 +45,12 @@
// FIXME: Doc!
template <typename T>
- struct cst_ : public Function_p2v< cst_<T> >
+ struct cst_
+ : fun::internal::selector_p2_<T, cst_<T> >::ret
{
typedef T result;
- cst_(T t);
+ cst_(const T& t);
template <typename P>
T operator()(const P&) const;
@@ -62,7 +63,7 @@
// FIXME: Doc!
template <typename T>
- cst_<T> cst(T t);
+ cst_<T> cst(const T& t);
# ifndef MLN_INCLUDE_ONLY
@@ -70,7 +71,7 @@
// pw::cst_<T>
template <typename T>
- cst_<T>::cst_(T t)
+ cst_<T>::cst_(const T& t)
: t_(t)
{
}
@@ -86,7 +87,7 @@
// pw::cst(t)
template <typename T>
- cst_<T> cst(T t)
+ cst_<T> cst(const T& t)
{
cst_<T> tmp(t);
return tmp;
Index: mln/pw/value.hh
--- mln/pw/value.hh (revision 1052)
+++ mln/pw/value.hh (working copy)
@@ -33,9 +33,8 @@
* \brief FIXME.
*/
-# include <mln/core/concept/function.hh>
+# include <mln/fun/internal/selector.hh>
# include <mln/core/concept/image.hh>
-# include <mln/value/props.hh>
@@ -45,26 +44,12 @@
namespace pw
{
- // FIXME: Move!
-
- namespace internal
- {
-
- template <typename K, typename E>
- struct select_function_ : Function_p2v<E>
- {};
-
- template <typename E>
- struct select_function_< value::binary_kind, E > : Function_p2b<E>
- {};
-
- } // end of namespace mln::pw::internal
-
// FIXME: Doc!
template <typename I>
- struct value_ : public internal::select_function_< mln_value_kind(I), value_<I> >
+ struct value_
+ : fun::internal::selector_p2_< mln_value(I), value_<I> >::ret
{
typedef mln_value(I) result;
value_(const I& ima);
Index: mln/core/neighb.hh
--- mln/core/neighb.hh (revision 1052)
+++ mln/core/neighb.hh (working copy)
@@ -58,6 +58,9 @@
/// Dpoint associated type.
typedef D dpoint;
+ /// Point associated type.
+ typedef mln_point(D) point;
+
/*! \brief Point_Iterator type to browse the points of a generic
* neighborhood w.r.t. the ordering of delta-points.
*/
Index: mln/core/concept/function.hh
--- mln/core/concept/function.hh (revision 1052)
+++ mln/core/concept/function.hh (working copy)
@@ -99,6 +99,7 @@
template <typename E>
struct Function_p2b : public Function_p2v<E>
{
+ typedef bool result;
protected:
Function_p2b();
};
Index: mln/core/concept/neighborhood.hh
--- mln/core/concept/neighborhood.hh (revision 1052)
+++ mln/core/concept/neighborhood.hh (working copy)
@@ -52,6 +52,7 @@
typedef bkd_niter;
typedef dpoint;
+ typedef point;
*/
protected:
@@ -68,6 +69,7 @@
typedef mln_fwd_niter(E) fwd_niter;
typedef mln_bkd_niter(E) bkd_niter;
typedef mln_dpoint(E) dpoint;
+ typedef mln_point(E) point;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/neighborhood.hh
--- mln/core/concept/doc/neighborhood.hh (revision 1052)
+++ mln/core/concept/doc/neighborhood.hh (working copy)
@@ -59,6 +59,9 @@
/// Dpoint associated type.
typedef void dpoint;
+
+ /// Point associated type.
+ typedef void point;
};
} // end of namespace mln::doc
Index: mln/fun/c.hh
--- mln/fun/c.hh (revision 0)
+++ mln/fun/c.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_FUN_C_HH
+# define MLN_FUN_C_HH
+
+/*! \file mln/fun/c.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/fun/internal/selector.hh>
+# include <mln/metal/unqualif.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ template <typename F> struct C;
+
+
+ // FIXME: Doc!
+ template <typename R, typename A>
+ struct C< R (*)(A) >
+ :
+ fun::internal::selector_< R, A, C<R(*)(A)> >::ret
+ {
+ C(R (*f)(A));
+ typedef R result;
+ R operator()(const mlc_unqualif(A)& a) const;
+ protected:
+ R (*f_)(A);
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename R, typename A>
+ C<R(*)(A)>::C(R (*f)(A))
+ : f_(f)
+ {
+ }
+
+ template <typename R, typename A>
+ R
+ C<R(*)(A)>::operator()(const mlc_unqualif(A)& a) const
+ {
+ return f_(a);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_P2B_C_HH
Index: mln/fun/internal/selector.hh
--- mln/fun/internal/selector.hh (revision 0)
+++ mln/fun/internal/selector.hh (revision 0)
@@ -0,0 +1,168 @@
+// 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 MLN_FUN_INTERNAL_SELECTOR_HH
+# define MLN_FUN_INTERNAL_SELECTOR_HH
+
+/*! \file mln/fun/internal/selector.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+# include <mln/core/concept/point.hh>
+# include <mln/metal/unqualif.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/is_a.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace internal
+ {
+
+ // Function_v2v
+ // |
+ // + -- Function_i2v
+ // |
+ // + -- Function_p2v
+ // |
+ // + -- Function_p2b
+ // |
+ // + -- Function_p2p
+
+ enum
+ {
+ b_,
+ i_,
+ p_,
+ v_
+ };
+
+ template <int arg, int res, typename E> struct helper_selector_;
+
+ // no b2* type => v2v type
+ template <typename E>
+ struct helper_selector_< b_, b_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, i_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, p_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< b_, v_, E > { typedef Function_v2v<E> ret; };
+
+ // i2* => only i2v type
+ template <typename E>
+ struct helper_selector_< i_, b_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, i_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, p_, E > { typedef Function_i2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< i_, v_, E > { typedef Function_i2v<E> ret; };
+
+ // p2*
+ template <typename E>
+ struct helper_selector_< p_, b_, E > { typedef Function_p2b<E> ret; };
+ template <typename E>
+ struct helper_selector_< p_, i_, E > { typedef Function_p2v<E> ret; }; // no p2i type => p2v
+ template <typename E>
+ struct helper_selector_< p_, p_, E > { typedef Function_p2p<E> ret; };
+ template <typename E>
+ struct helper_selector_< p_, v_, E > { typedef Function_p2v<E> ret; };
+
+ // v2* => only v2v type
+ template <typename E>
+ struct helper_selector_< v_, b_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, i_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, p_, E > { typedef Function_v2v<E> ret; };
+ template <typename E>
+ struct helper_selector_< v_, v_, E > { typedef Function_v2v<E> ret; };
+
+
+ // tag_
+
+ template <typename T> struct tag_;
+
+ template <>
+ struct tag_< bool >
+ {
+ enum { value = b_ };
+ };
+
+ template <>
+ struct tag_< unsigned >
+ {
+ enum { value = i_ };
+ };
+
+ template <typename T>
+ struct tag_
+ {
+ enum { value = mlc_is_a(T, Point)::to_bool
+ ? p_
+ : v_ };
+ };
+
+
+ template <typename R_, typename A_, typename E>
+ struct selector_
+ {
+ typedef mlc_unqualif(R_) R;
+ typedef mlc_unqualif(A_) A;
+ enum { arg = tag_<A>::value,
+ res = tag_<R>::value };
+ typedef typename helper_selector_<arg, res, E>::ret ret;
+ private:
+ selector_();
+ };
+
+
+ template <typename R_, typename E>
+ struct selector_p2_
+ {
+ typedef mlc_unqualif(R_) R;
+ enum { res = tag_<R>::value };
+ typedef typename helper_selector_<p_, res, E>::ret ret;
+ private:
+ selector_p2_();
+ };
+
+ } // end of namespace mln::fun::internal
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_INTERNAL_SELECTOR_HH
Index: mln/metal/unqualif.hh
--- mln/metal/unqualif.hh (revision 0)
+++ mln/metal/unqualif.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 MLN_METAL_UNQUALIF_HH
+# define MLN_METAL_UNQUALIF_HH
+
+# include <mln/metal/unconst.hh>
+# include <mln/metal/unptr.hh>
+# include <mln/metal/unref.hh>
+
+
+# define mlc_unqualif(T) typename mln::metal::unqualif< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unqualif
+ {
+ typedef mlc_unref(T) tmp1;
+ typedef mlc_unconst(tmp1) tmp2;
+ typedef mlc_unptr(tmp2) ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNQUALIF_HH
Index: mln/metal/if.hh
--- mln/metal/if.hh (revision 0)
+++ mln/metal/if.hh (revision 0)
@@ -0,0 +1,85 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_METAL_IF_HH
+# define MLN_CORE_METAL_IF_HH
+
+/*! \file mln/metal/if.hh
+ *
+ * \brief Definition of an "if-then-else" expression type.
+ */
+
+# include <mln/metal/bool.hh>
+
+# define mlc_if(Cond, Then, Else) typename mln::metal::if_< Cond, Then, Else >::ret
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace internal
+ {
+
+ template <bool cond, typename Then, typename Else>
+ struct helper_if_;
+
+ template <typename Then, typename Else>
+ struct helper_if_< true, Then, Else >
+ {
+ typedef Then ret;
+ };
+
+ template <typename Then, typename Else>
+ struct helper_if_< false, Then, Else >
+ {
+ typedef Else ret;
+ };
+
+ } // end of namespace mln::metal::internal
+
+
+ /*! \brief "if-then-else" expression.
+ *
+ * FIXME: Doc!
+ */
+ template <typename Cond, typename Then, typename Else>
+ struct if_ : internal::helper_if_< Cond::value, Then, Else >
+ {
+ // ret is inherited.
+ };
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IF_HH
Index: mln/metal/equal.hh
--- mln/metal/equal.hh (revision 1052)
+++ mln/metal/equal.hh (working copy)
@@ -28,6 +28,11 @@
#ifndef MLN_METAL_EQUAL_HH
# define MLN_METAL_EQUAL_HH
+# include <mln/metal/bool.hh>
+
+
+# define mlc_equal(T1, T2) mln::metal::equal< T1, T2 >
+
namespace mln
{
@@ -36,15 +41,12 @@
{
template <typename T1, typename T2>
- struct equal
- {
- };
+ struct equal : false_
+ {};
template <typename T>
- struct equal< T, T >
- {
- static void check() {}
- };
+ struct equal< T, T > : true_
+ {};
} // end of namespace mln::metal
Index: mln/metal/unptr.hh
--- mln/metal/unptr.hh (revision 0)
+++ mln/metal/unptr.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 MLN_METAL_UNPTR_HH
+# define MLN_METAL_UNPTR_HH
+
+
+# define mlc_unptr(T) typename mln::metal::unptr< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unptr
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unptr< T* >
+ {
+ typedef mlc_unptr(T) ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNPTR_HH
Index: mln/metal/all.hh
--- mln/metal/all.hh (revision 0)
+++ mln/metal/all.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 MLN_METAL_ALL_HH
+# define MLN_METAL_ALL_HH
+
+/*! \file mln/metal/all.hh
+ *
+ * \brief File that includes all meta-programming tools.
+ */
+
+namespace mln
+{
+
+ /// Namespace of meta-programming tools.
+ namespace metal {}
+
+} // end of namespace mln
+
+
+# include <mln/metal/bexpr.hh> // <- bool.hh
+# include <mln/metal/equal.hh>
+# include <mln/metal/if.hh>
+# include <mln/metal/is_a.hh>
+# include <mln/metal/math.hh>
+# include <mln/metal/none.hh>
+# include <mln/metal/unqualif.hh> // <- unconst.hh, unptr.hh, unref.hh
+# include <mln/metal/vec.hh>
+
+# include <mln/metal/same_coord.hh>
+# include <mln/metal/same_point.hh>
+
+
+#endif // ! MLN_METAL_ALL_HH
Index: mln/metal/is_a.hh
--- mln/metal/is_a.hh (revision 0)
+++ mln/metal/is_a.hh (revision 0)
@@ -0,0 +1,88 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_METAL_IS_A_HH
+# define MLN_CORE_METAL_IS_A_HH
+
+/*! \file mln/metal/is_a.hh
+ *
+ * \brief Definition of a type that means "is_a".
+ */
+
+
+# define mlc_is_a(T, U) mln::metal::is_a< T, U >
+
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace internal
+ {
+
+ typedef char yes_;
+ struct no_ { char dummy[2]; };
+
+ template <typename T>
+ struct make_
+ {
+ static T* ptr();
+ };
+
+ template <typename T, template <class> class U>
+ struct helper_is_a_
+ {
+
+ template<class V>
+ static yes_ selector(U<V>*);
+ static no_ selector(...);
+ };
+
+ } // end of namespace mln::metal::internal
+
+
+
+ /*! \brief "is_a" check.
+ *
+ * FIXME: Doc!
+ */
+ template <typename T, template <class> class U>
+ struct is_a : bool_<( sizeof( internal::helper_is_a_<T,U>::selector(internal::make_<T>::ptr()) )
+ =
+ sizeof( internal::yes_ ) )>::type
+ {};
+
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_METAL_IS_A_HH
Index: mln/metal/unref.hh
--- mln/metal/unref.hh (revision 0)
+++ mln/metal/unref.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 MLN_METAL_UNREF_HH
+# define MLN_METAL_UNREF_HH
+
+
+# define mlc_unref(T) typename mln::metal::unref< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unref
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unref< T& >
+ {
+ typedef T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNREF_HH
Index: mln/level/compute.hh
--- mln/level/compute.hh (revision 1052)
+++ mln/level/compute.hh (working copy)
@@ -25,12 +25,12 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_LEVEL_RUN_HH
-# define MLN_LEVEL_RUN_HH
+#ifndef MLN_LEVEL_COMPUTE_HH
+# define MLN_LEVEL_COMPUTE_HH
-/*! \file mln/level/run.hh
+/*! \file mln/level/compute.hh
*
- * \brief Run an accumulator onto image pixel values.
+ * \brief Compute an accumulator onto image pixel values.
*/
# include <mln/level/take.hh>
@@ -42,26 +42,26 @@
namespace level
{
- /*! Run an accumulator onto the pixel values of the image \p input.
+ /*! Compute an accumulator onto the pixel values of the image \p input.
*
* \param[in] input The input image.
* \param[in] a The accumulator.
* \return A resulting accumulator.
*
- * This routine runs: \n
+ * This routine computes: \n
* res = \p a \n
* res.init() \n
* level::take(res, \p input) \n
* return res \n
*/
template <typename I, typename A>
- A run(const Image<I>& input, const Accumulator<A>& a);
+ A compute(const Image<I>& input, const Accumulator<A>& a);
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename A>
- A run(const Image<I>& input, const Accumulator<A>& a)
+ A compute(const Image<I>& input, const Accumulator<A>& a)
{
A res = exact(a);
res.init();
@@ -76,4 +76,4 @@
} // end of namespace mln
-#endif // ! MLN_LEVEL_RUN_HH
+#endif // ! MLN_LEVEL_COMPUTE_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add some linear filters and augment related tools.
* mln/linear/convolve.hh: Add doc.
* mln/linear/log.hh (LoG_7x7, LoG_13x13, LoG_17x17): New.
* mln/linear/lap.hh: New.
* tests/linear_lap.cc: New.
* mln/convert/to_dpoint.hh: Add postcondition.
* mln/convert/to_w_window.hh: New.
* mln/core/w_window2d_float.hh: New.
* mln/make/w_window.hh: New.
* mln/make/w_window2d_int.hh: Remove; useless.
* mln/core/concept/doc/weighted_window.hh: Augment doc.
(weight, window): Rename as...
(w, win): ...these.
(weight, window): New associated types.
* mln/core/concept/weighted_window.hh: Update.
* mln/core/window.hh (window_): Rename as...
(window): ...this.
* mln/core/w_window.hh (w_window_): Rename as...
(w_window): ...this.
(insert): Swap args; add precondition.
Update.
* mln/convert/to_image.hh,
* mln/convert/to_window.hh,
* mln/geom/pmin_pmax.hh,
* mln/geom/bbox.hh: New overload.
* mln/core/window2d.hh,
* mln/core/w_window2d_int.hh,
* mln/linear/convolve.hh,
* mln/make/w_window2d.hh,
* tests/convolve.cc,
* tests/pixter_dpoint2d.cc,
* tests/w_window2d_int.cc: Update.
mln/convert/to_dpoint.hh | 8 +-
mln/convert/to_image.hh | 21 +++++
mln/convert/to_w_window.hh | 76 +++++++++++++++++++++
mln/convert/to_window.hh | 29 +++++++-
mln/core/concept/doc/weighted_window.hh | 16 ++++
mln/core/concept/weighted_window.hh | 17 +++-
mln/core/macros.hh | 10 ++
mln/core/w_window.hh | 114 +++++++++++++++++++++-----------
mln/core/w_window2d_float.hh | 56 +++++++++++++++
mln/core/w_window2d_int.hh | 4 -
mln/core/window.hh | 46 ++++++------
mln/core/window2d.hh | 2
mln/estim/min_max.hh | 2
mln/geom/bbox.hh | 17 ++++
mln/geom/pmin_pmax.hh | 17 ++++
mln/linear/convolve.hh | 27 ++++---
mln/linear/lap.hh | 113 +++++++++++++++++++++++++++++++
mln/linear/log.hh | 89 +++++++++++++++++++++++-
mln/make/w_window.hh | 86 ++++++++++++++++++++++++
mln/make/w_window2d.hh | 15 ++--
tests/convolve.cc | 5 -
tests/linear_lap.cc | 51 ++++++++++++++
tests/pixter_dpoint2d.cc | 2
tests/w_window2d_int.cc | 27 ++++---
24 files changed, 730 insertions(+), 120 deletions(-)
Index: tests/convolve.cc
--- tests/convolve.cc (revision 1051)
+++ tests/convolve.cc (working copy)
@@ -38,8 +38,7 @@
#include <mln/math/round.hh>
#include <mln/level/transform.hh>
-#include <mln/core/w_window.hh>
-#include <mln/make/w_window2d.hh>
+#include <mln/core/w_window2d_float.hh>
#include <mln/border/thickness.hh>
#include <mln/linear/convolve.hh>
@@ -60,7 +59,7 @@
.04, .04, .04, .04, .04,
.04, .04, .04, .04, .04,
.04, .04, .04, .04, .04 };
- w_window_<dpoint2d,float> w = make::w_window2d(ws);
+ w_window2d_float w = make::w_window2d(ws);
image2d_b<float> tmp(lena.domain());
linear::convolve(lena, w, tmp);
Index: tests/w_window2d_int.cc
--- tests/w_window2d_int.cc (revision 1051)
+++ tests/w_window2d_int.cc (working copy)
@@ -31,18 +31,21 @@
*/
#include <mln/core/w_window2d_int.hh>
+#include <mln/core/win/rectangle2d.hh>
+#include <mln/convert/to_image.hh>
+#include <mln/convert/to_w_window.hh>
+#include <mln/debug/println.hh>
-template <typename W, typename P>
-void test(const W& w, const P& p)
+struct my_f : mln::Function_p2v< my_f >
{
- mln_qiter(W) q(w, p);
- for_all(q)
- std::cout << q << ':' << q.weight() << ' ';
- std::cout << std::endl;
+ typedef int result;
+ int operator()(const mln::point2d& p) const
+ {
+ return p.row() + p.col();
}
-
+};
int main()
@@ -52,8 +55,12 @@
int ws[] = { -1, 0, 1,
-2, 0, 2,
-1, 0, 1 };
- w_window2d_int ww = make::w_window2d_int(ws);
- std::cout << ww << std::endl;
+ w_window2d_int w_win = make::w_window2d(ws);
+
+ image2d_b<int> ima = convert::to_image(w_win);
+ w_window2d_int w_win_2 = convert::to_w_window(ima);
+ mln_assertion(w_win_2 = w_win);
- test(ww, make::point2d(0,0));
+ w_window2d_int tmp = make::w_window(win::rectangle2d(3, 5), my_f());
+ debug::println(convert::to_image(tmp));
}
Index: tests/pixter_dpoint2d.cc
--- tests/pixter_dpoint2d.cc (revision 1051)
+++ tests/pixter_dpoint2d.cc (working copy)
@@ -46,7 +46,7 @@
typedef image2d_b<int> I;
typedef I::dpoint D;
- typedef window_<D> W;
+ typedef window<D> W;
typedef dpoints_fwd_pixter<I> qixter;
Index: tests/linear_lap.cc
--- tests/linear_lap.cc (revision 0)
+++ tests/linear_lap.cc (revision 0)
@@ -0,0 +1,51 @@
+// 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.
+
+/*! \file tests/linear_lAP.cc
+ *
+ * \brief Tests on mln::linear::lap_4.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+#include <mln/io/load_pgm.hh>
+
+#include <mln/border/thickness.hh>
+#include <mln/linear/lap.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ border::thickness = 1;
+
+ image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
+ image2d_b<int> tmp(lena.domain());
+ linear::lap_4(lena, tmp);
+}
Index: mln/convert/to_image.hh
--- mln/convert/to_image.hh (revision 1051)
+++ mln/convert/to_image.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/window.hh>
+# include <mln/core/concept/weighted_window.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/convert/to_window.hh>
@@ -62,6 +63,10 @@
template <typename N>
image2d_b<bool> to_image(const Neighborhood<N>& nbh);
+ /// Convert a weighted window \p w_win into an image.
+ template <typename W>
+ image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win);
+
# ifndef MLN_INCLUDE_ONLY
@@ -99,6 +104,22 @@
return to_image(convert::to_window(nbh));
}
+ template <typename W>
+ image2d_b<mln_weight(W)> to_image(const Weighted_Window<W>& w_win_)
+ {
+ const W& w_win = exact(w_win_);
+ mln_precondition(! w_win.is_empty());
+
+ typedef mln_point(W) P;
+ box2d b = geom::bbox(w_win);
+ image2d_b<mln_weight(W)> ima(b);
+ mln_qiter(W) q(w_win, P::zero);
+ for_all(q)
+ ima(q) = q.w();
+ return ima;
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_window.hh
--- mln/convert/to_window.hh (revision 1051)
+++ mln/convert/to_window.hh (working copy)
@@ -30,9 +30,10 @@
/*! \file mln/convert/to_window.hh
*
- * \brief Convertions to mln::Window.
+ * \brief Conversions to mln::window.
*/
+# include <mln/core/concept/image.hh>
# include <mln/core/concept/neighborhood.hh>
# include <mln/core/window.hh>
@@ -45,24 +46,44 @@
/// Convert a neighborhood \p nbh into a window.
template <typename N>
- window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+ window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh);
+
+ /// Convert a binary image \p input into a window.
+ template <typename I>
+ window<mln_dpoint(I)> to_window(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
template <typename N>
- window_<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
+ window<mln_dpoint(N)> to_window(const Neighborhood<N>& nbh_)
{
const N& nbh = exact(nbh_);
typedef mln_dpoint(N) D;
typedef mln_point(D) P;
- window_<D> win;
+ window<D> win;
mln_niter(N) n(nbh, P::zero);
for_all(n)
win.insert(n - P::zero);
return win;
}
+ template <typename I>
+ window<mln_dpoint(I)> to_window(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_precondition(input.has_data());
+ // FIXME: Check that input is binary!
+ typedef mln_dpoint(I) D;
+ typedef mln_point(D) P;
+ window<D> win;
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p))
+ win.insert(p - P::zero);
+ return win;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::convert
Index: mln/convert/to_dpoint.hh
--- mln/convert/to_dpoint.hh (revision 1051)
+++ mln/convert/to_dpoint.hh (working copy)
@@ -53,10 +53,12 @@
mln_dpoint(P) to_dpoint(const Generalized_Point<P>& p_)
{
const P& p = internal::force_exact<P>(p_);
- mln_dpoint(P) tmp;
+ mln_dpoint(P) dp;
for (unsigned i = 0; i < P::dim; ++i)
- tmp[i] = p[i];
- return tmp;
+ dp[i] = p[i];
+ typedef mln_point(P) P_;
+ mln_postcondition(dp = p - P_::zero);
+ return dp;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/convert/to_w_window.hh
--- mln/convert/to_w_window.hh (revision 0)
+++ mln/convert/to_w_window.hh (revision 0)
@@ -0,0 +1,76 @@
+// 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 MLN_CONVERT_TO_W_WINDOW_HH
+# define MLN_CONVERT_TO_W_WINDOW_HH
+
+/*! \file mln/convert/to_w_window.hh
+ *
+ * \brief Conversions to mln::w_window.
+ */
+
+# include <mln/core/concept/image.hh>
+# include <mln/core/window.hh>
+
+
+namespace mln
+{
+
+ namespace convert
+ {
+
+ /// Convert an image \p input into a weighted window.
+ template <typename I>
+ w_window<mln_dpoint(I), mln_value(I)> to_w_window(const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ w_window<mln_dpoint(I), mln_value(I)> to_w_window(const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_precondition(input.has_data());
+ // FIXME: Check that input is scalar?
+ typedef mln_dpoint(I) D;
+ typedef mln_point(D) P;
+ w_window<D, mln_value(I)> w_win;
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ if (input(p) != 0)
+ w_win.insert(input(p), p - P::zero);
+ return w_win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::convert
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CONVERT_TO_W_WINDOW_HH
Index: mln/estim/min_max.hh
--- mln/estim/min_max.hh (revision 1051)
+++ mln/estim/min_max.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/estim/min_max.hh
*
- * \brief Compute the min_max pixel value.
+ * \brief Compute the min and max pixel values of an image.
*/
# include <mln/accu/min_max.hh>
Index: mln/geom/pmin_pmax.hh
--- mln/geom/pmin_pmax.hh (revision 1051)
+++ mln/geom/pmin_pmax.hh (working copy)
@@ -51,6 +51,13 @@
pmin_pmax(const Point_Iterator<I>& p);
+ /// Compute the minimum and maximum points, \p pmin and \p max,
+ /// when browsing with iterator \p p.
+ template <typename I>
+ void
+ pmin_pmax(const Point_Iterator<I>& p, mln_point(I)& pmin, mln_point(I)& pmax);
+
+
# ifndef MLN_INCLUDE_ONLY
@@ -80,6 +87,16 @@
return tmp;
}
+ template <typename I>
+ void
+ pmin_pmax(const Point_Iterator<I>& p, mln_point(I)& pmin, mln_point(I)& pmax)
+ {
+ typedef mln_point(I) P;
+ std::pair<P, P> tmp = pmin_pmax(p);
+ pmin = tmp.first;
+ pmax = tmp.second;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::geom
Index: mln/geom/bbox.hh
--- mln/geom/bbox.hh (revision 1051)
+++ mln/geom/bbox.hh (working copy)
@@ -37,6 +37,7 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/window.hh>
+# include <mln/core/concept/weighted_window.hh>
# include <mln/geom/pmin_pmax.hh>
@@ -47,12 +48,18 @@
{
- /// Compute the precise bounding box of a window \p win centered
- /// at the origin.
+ /// Compute the precise bounding box of a window \p win when
+ /// centered at the origin.
template <typename W>
box_<mln_point(W)> bbox(const Window<W>& win);
+ /// Compute the precise bounding box of a weighted window \p w_win
+ /// when centered at the origin.
+ template <typename W>
+ box_<mln_point(W)> bbox(const Weighted_Window<W>& w_win);
+
+
/// Compute the precise bounding box of a point set \p pset.
template <typename S>
box_<mln_point(S)> bbox(const Point_Set<S>& pset);
@@ -80,6 +87,12 @@
return tmp;
}
+ template <typename W>
+ box_<mln_point(W)> bbox(const Weighted_Window<W>& w_win)
+ {
+ return bbox(exact(w_win).win());
+ }
+
template <typename S>
box_<mln_point(S)> bbox(const Point_Set<S>& pset_)
{
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1051)
+++ mln/core/macros.hh (working copy)
@@ -161,6 +161,16 @@
# define mln_viter(T) typename T::fwd_viter
+// w
+
+/// Shortcut to access the weight type associated to T.
+# define mln_weight(T) typename T::weight
+
+/// Shortcut to access the window type associated to T.
+# define mln_window(T) typename T::window
+
+
+
Index: mln/core/w_window.hh
--- mln/core/w_window.hh (revision 1051)
+++ mln/core/w_window.hh (working copy)
@@ -30,13 +30,13 @@
/*! \file mln/core/w_window.hh
*
- * \brief Definition of the generic weighted window class mln::w_window_.
+ * \brief Definition of the generic weighted window class mln::w_window.
*/
# include <map>
-# include <mln/core/concept/weighted_window.hh>
# include <mln/core/window.hh>
+# include <mln/core/concept/weighted_window.hh>
namespace mln
@@ -54,7 +54,7 @@
* the type of weights.
*/
template <typename D, typename W>
- struct w_window_ : public Weighted_Window< w_window_<D,W> >
+ struct w_window : public Weighted_Window< w_window<D,W> >
{
/// Point associated type.
typedef mln_point(D) point;
@@ -62,6 +62,12 @@
/// Dpoint associated type.
typedef D dpoint;
+ /// Weight associated type.
+ typedef W weight;
+
+ /// Window associated type.
+ typedef mln::window<D> window;
+
/// Point_Iterator type to browse (forward) the points of a generic w_window.
typedef with_w_< dpoints_fwd_piter<D>, W > fwd_qiter;
@@ -71,15 +77,15 @@
/// Constructor without argument.
- w_window_();
+ w_window();
- /// Insert a delta-point \p d and its associated weight \p w.
- w_window_<D,W>& insert(const D& d, const W& w);
+ /// Insert a couple of weight \p w and delta-point \p d.
+ w_window<D,W>& insert(const W& w, const D& d);
/// Give the \p i-th weight.
- W weight(unsigned i) const;
+ W w(unsigned i) const;
/// Give access to the vector of weights.
const std::vector<W>& weights() const;
@@ -95,22 +101,31 @@
const std::vector<D>& vect() const;
/// Give the corresponding window.
- const window_<D>& window() const;
+ const mln::window<D>& win() const;
/// Give the symmetrical w_window.
- w_window_<D,W> sym_() const;
+ w_window<D,W> sym_() const;
protected:
- window_<D> win_;
+ mln::window<D> win_;
std::vector<W> wei_;
};
- /// Print a weighted window \p wwin into an output stream \p ostr.
+ /* \brief Print a weighted window \p w_win into an output stream \p ostr.
+ * \relates mln::w_window
+ */
template <typename D, typename W>
- std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin);
+ std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win);
+
+
+ /* \brief Equality test between two weighted windows \p lhs and \p rhs.
+ * \relates mln::w_window
+ */
+ template <typename D, typename Wl, typename Wr>
+ bool operator=(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs);
@@ -122,7 +137,7 @@
template <typename Ds, typename P>
with_w_(const Ds& ds, const P& p);
- W weight() const;
+ W w() const;
protected:
const std::vector<W> wei_;
@@ -146,39 +161,30 @@
template <typename It, typename W>
W
- with_w_<It,W>::weight() const
+ with_w_<It,W>::w() const
{
mln_precondition(this->i_ < wei_.size());
return wei_[this->i_];
}
- // w_window_<D,W>
-
- template <typename D, typename W>
- std::ostream& operator<<(std::ostream& ostr, const w_window_<D,W>& wwin)
- {
- ostr << '[';
- for (unsigned i = 0; i < wwin.window().ndpoints(); ++i)
- ostr << wwin.vect()[i] << ':' << wwin.weight(i) << ' ';
- return ostr << ']';
- }
+ // w_window<D,W>
template <typename D, typename W>
- w_window_<D,W>::w_window_()
+ w_window<D,W>::w_window()
{
}
template <typename D, typename W>
- const window_<D>&
- w_window_<D,W>::window() const
+ const mln::window<D>&
+ w_window<D,W>::win() const
{
return win_;
}
template <typename D, typename W>
const D&
- w_window_<D,W>::dp(unsigned i) const
+ w_window<D,W>::dp(unsigned i) const
{
mln_precondition(i < win_.ndpoints());
mln_invariant(wei_.size() = win_.ndpoints());
@@ -187,7 +193,7 @@
template <typename D, typename W>
unsigned
- w_window_<D,W>::ndpoints() const
+ w_window<D,W>::ndpoints() const
{
mln_invariant(wei_.size() = win_.ndpoints());
return win_.ndpoints();
@@ -195,21 +201,21 @@
template <typename D, typename W>
const std::vector<D>&
- w_window_<D,W>::vect() const
+ w_window<D,W>::vect() const
{
return win_.vect();
}
template <typename D, typename W>
const std::vector<W>&
- w_window_<D,W>::weights() const
+ w_window<D,W>::weights() const
{
return wei_;
}
template <typename D, typename W>
W
- w_window_<D,W>::weight(unsigned i) const
+ w_window<D,W>::w(unsigned i) const
{
mln_precondition(i < wei_.size());
mln_invariant(wei_.size() = win_.ndpoints());
@@ -217,12 +223,13 @@
}
template <typename D, typename W>
- w_window_<D,W>&
- w_window_<D,W>::insert(const D& d, const W& w)
+ w_window<D,W>&
+ w_window<D,W>::insert(const W& w, const D& d)
{
mln_invariant(wei_.size() = win_.ndpoints());
+ mln_precondition(! win_.has(d));
- if (win_.has(d))
+ if (w = W(0)) // FIXME: Implicit restriction "W scalar"...
// no-op
return *this;
@@ -244,19 +251,48 @@
return *this;
}
-
template <typename D, typename W>
- w_window_<D,W>
- w_window_<D,W>::sym_() const
+ w_window<D,W>
+ w_window<D,W>::sym_() const
{
- w_window_<D,W> tmp(*this);
+ w_window<D,W> tmp(*this);
tmp.win_ = - this->win_;
return *this;
}
+ // operators
+
+ template <typename D, typename W>
+ std::ostream& operator<<(std::ostream& ostr, const w_window<D,W>& w_win)
+ {
+ ostr << '[';
+ for (unsigned i = 0; i < w_win.win().ndpoints(); ++i)
+ ostr << w_win.vect()[i] << ':' << w_win.w(i) << ' ';
+ return ostr << ']';
+ }
+
+ template <typename D, typename Wl, typename Wr>
+ bool operator=(const w_window<D,Wl>& lhs, const w_window<D,Wr>& rhs)
+ {
+ if (lhs.ndpoints() != rhs.ndpoints())
+ return false;
+ if (lhs.win() != rhs.win())
+ return false;
+ const std::vector<Wl>& wl = lhs.weights();
+ const std::vector<Wr>& wr = rhs.weights();
+ mln_assertion(wl.size() = wr.size());
+ for (unsigned i = 0; i < wl.size(); ++i)
+ if (wr[i] != wl[i])
+ return false;
+ return true;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
+# include <mln/make/w_window.hh>
+
+
#endif // ! MLN_CORE_W_WINDOW_HH
Index: mln/core/window.hh
--- mln/core/window.hh (revision 1051)
+++ mln/core/window.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/core/window.hh
*
- * \brief Definition of the generic window class mln::window_.
+ * \brief Definition of the generic window class mln::window.
*/
# include <mln/core/concept/window.hh>
@@ -56,10 +56,10 @@
* parameter is \c D, type of delta-point.
*/
template <typename D>
- class window_ : public Window< window_<D> >,
- public internal::dpoints_base_<D, window_<D> >
+ class window : public Window< window<D> >,
+ public internal::dpoints_base_<D, window<D> >
{
- typedef internal::dpoints_base_<D, window_<D> > super_;
+ typedef internal::dpoints_base_<D, window<D> > super_;
public:
/*! \brief Point_Iterator type to browse the points of a generic window
@@ -77,7 +77,7 @@
*
* The constructed window is empty.
*/
- window_();
+ window();
/*! \brief Test if the window is symmetric.
@@ -85,10 +85,10 @@
bool is_symmetric() const;
/// Insert a delta-point \p dp.
- window_<D>& insert(const D& dp);
+ window<D>& insert(const D& dp);
/// Give the symmetrical window.
- window_<D> sym_() const;
+ window<D> sym_() const;
protected:
@@ -100,40 +100,40 @@
/// Shift a window \p win with a delta-point \p dp.
template <typename W>
- window_<mln_dpoint(W)> operator+(const Window<W>& win,
+ window<mln_dpoint(W)> operator+(const Window<W>& win,
const mln_dpoint(W)& dp);
/// Shift a window \p win with the delta-point (-\p dp).
template <typename W>
- window_<mln_dpoint(W)> operator-(const Window<W>& win,
+ window<mln_dpoint(W)> operator-(const Window<W>& win,
const mln_dpoint(W)& dp);
/// Substract \p rhs from \p lhs.
// FIXME: Give details!
template <typename Wl, typename Wr>
- window_<mln_dpoint(Wl)> operator-(const Window<Wl>& lhs,
+ window<mln_dpoint(Wl)> operator-(const Window<Wl>& lhs,
const Window<Wr>& rhs);
# ifndef MLN_INCLUDE_ONLY
- // window_<D>
+ // window<D>
template <typename D>
- window_<D>::window_()
+ window<D>::window()
{
}
template <typename D>
- bool window_<D>::is_symmetric() const
+ bool window<D>::is_symmetric() const
{
return this->sym_() = *this;
}
template <typename D>
- window_<D>&
- window_<D>::insert(const D& dp)
+ window<D>&
+ window<D>::insert(const D& dp)
{
mln_precondition(! has(dp));
this->super_::insert(dp);
@@ -141,10 +141,10 @@
}
template <typename D>
- window_<D>
- window_<D>::sym_() const
+ window<D>
+ window<D>::sym_() const
{
- window_<D> tmp;
+ window<D> tmp;
const unsigned n = this->ndpoints();
for (unsigned i = 0; i < n; ++i)
tmp.insert(- this->dp(i));
@@ -155,11 +155,11 @@
// operators
template <typename W>
- window_<mln_dpoint(W)> operator+(const Window<W>& win,
+ window<mln_dpoint(W)> operator+(const Window<W>& win,
const mln_dpoint(W)& dp)
{
typedef mln_point(W) P;
- window_<mln_dpoint(W)> tmp;
+ window<mln_dpoint(W)> tmp;
mln_qiter(W) q(win, P::zero);
for_all(q)
tmp.insert(convert::to_dpoint(q) + dp);
@@ -167,18 +167,18 @@
}
template <typename W>
- window_<mln_dpoint(W)> operator-(const Window<W>& win,
+ window<mln_dpoint(W)> operator-(const Window<W>& win,
const mln_dpoint(W)& dp)
{
return win + (-dp);
}
template <typename W, typename Wr>
- window_<mln_dpoint(W)> operator-(const Window<W>& lhs,
+ window<mln_dpoint(W)> operator-(const Window<W>& lhs,
const Window<Wr>& rhs)
{
typedef mln_point(W) P;
- window_<mln_dpoint(W)> tmp;
+ window<mln_dpoint(W)> tmp;
mln_qiter(W) q(lhs, P::zero);
for_all(q)
{
Index: mln/core/window2d.hh
--- mln/core/window2d.hh (revision 1051)
+++ mln/core/window2d.hh (working copy)
@@ -44,7 +44,7 @@
/*! \brief Type alias for a window with arbitrary shape, defined on
* the 2D square grid with integer coordinates.
*/
- typedef window_<dpoint2d> window2d;
+ typedef window<dpoint2d> window2d;
} // end of namespace mln
Index: mln/core/concept/weighted_window.hh
--- mln/core/concept/weighted_window.hh (revision 1051)
+++ mln/core/concept/weighted_window.hh (working copy)
@@ -55,6 +55,8 @@
typedef point;
typedef dpoint;
+ typedef weight;
+ typedef window;
E sym_() const;
*/
@@ -62,13 +64,13 @@
/// Test if the weighted window is empty; final method.
bool is_empty() const
{
- return exact(this)->window().is_empty();
+ return exact(this)->win().is_empty();
}
/// Test if the weighted window is centered; final method.
bool is_centered() const
{
- return exact(this)->window().is_centered();
+ return exact(this)->win().is_centered();
}
// FIXME: Remove because too ambiguous: bool is_symmetric() const
@@ -76,7 +78,7 @@
/// Give the maximum coordinate gap.
unsigned delta() const
{
- return exact(this)->window().delta();
+ return exact(this)->win().delta();
}
protected:
@@ -99,12 +101,17 @@
{
typedef mln_point(E) point;
typedef mln_dpoint(E) dpoint;
+ typedef mln_weight(E) weight;
+ typedef mln_window(E) window;
typedef mln_fwd_qiter(E) fwd_qiter;
typedef mln_bkd_qiter(E) bkd_qiter;
- E (E::*m_)() const = & E::sym_;
- m_ = 0;
+ E (E::*m1)() const = & E::sym_;
+ m1 = 0;
+
+ const window& (E::*m2)() const = & E::win;
+ m2 = 0;
}
template <typename W>
Index: mln/core/concept/doc/weighted_window.hh
--- mln/core/concept/doc/weighted_window.hh (revision 1051)
+++ mln/core/concept/doc/weighted_window.hh (working copy)
@@ -56,6 +56,18 @@
*/
typedef void bkd_qiter;
+ /// Point associated type.
+ typedef void point;
+
+ /// Dpoint associated type.
+ typedef void dpoint;
+
+ /// Weight associated type.
+ typedef void weight;
+
+ /// Window associated type.
+ typedef void window;
+
/*! \brief Test if the weighted window is empty.
*
* A weighted_window of null size is empty.
@@ -73,6 +85,10 @@
*/
unsigned delta() const;
+ /*! \brief Give the corresponding window.
+ */
+ const window& win() const;
+
/*! \brief Give the symmetrical weighted_window.
*/
E sym_() const;
Index: mln/core/w_window2d_int.hh
--- mln/core/w_window2d_int.hh (revision 1051)
+++ mln/core/w_window2d_int.hh (working copy)
@@ -44,13 +44,13 @@
* on the 2D square grid (with integer coordinates) and whose
* weights are integers.
*/
- typedef w_window_<dpoint2d, int> w_window2d_int;
+ typedef w_window<dpoint2d, int> w_window2d_int;
} // end of namespace mln
-# include <mln/make/w_window2d_int.hh>
+# include <mln/make/w_window2d.hh>
#endif // ! MLN_CORE_W_WINDOW2D_INT_HH
Index: mln/core/w_window2d_float.hh
--- mln/core/w_window2d_float.hh (revision 0)
+++ mln/core/w_window2d_float.hh (revision 0)
@@ -0,0 +1,56 @@
+// 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 MLN_CORE_W_WINDOW2D_FLOAT_HH
+# define MLN_CORE_W_WINDOW2D_FLOAT_HH
+
+/*! \file mln/core/w_window2d_float.hh
+ *
+ * \brief Definition of the mln::w_window2d_float alias.
+ */
+
+# include <mln/core/w_window.hh>
+# include <mln/core/dpoint2d.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Type alias for a w_window with arbitrary shape, defined
+ * on the 2D square grid (with integer coordinates) and whose
+ * weights are floating values.
+ */
+ typedef w_window<dpoint2d, float> w_window2d_float;
+
+
+} // end of namespace mln
+
+
+# include <mln/make/w_window2d.hh>
+
+
+#endif // ! MLN_CORE_W_WINDOW2D_FLOAT_HH
Index: mln/linear/log.hh
--- mln/linear/log.hh (revision 1051)
+++ mln/linear/log.hh (working copy)
@@ -34,7 +34,7 @@
*/
# include <mln/linear/convolve.hh>
-# include <mln/make/w_window2d_int.hh>
+# include <mln/make/w_window2d.hh>
@@ -47,21 +47,96 @@
template <typename I, typename O>
void LoG_5x5(const Image<I>& input, Image<O>& output);
+ template <typename I, typename O>
+ void LoG_7x7(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void LoG_13x13(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void LoG_17x17(const Image<I>& input, Image<O>& output);
+
# ifndef MLN_INCLUDE_ONLY
// LoG_5x5 (Cf. Sonka et al., pages 85-86)
+ // This is also a "mexican hat".
template <typename I, typename O>
void LoG_5x5(const Image<I>& input, Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- int ws[] = { 0, 0, -1, 0, 0,
- 0, -1, -2, -1, 0,
+ int ws[] = { +0, 0, -1, 0, 0,
+ +0, -1, -2, -1, 0,
-1, -2, 16, -2, -1,
- 0, -1, -2, -1, 0,
- 0, 0, -1, 0, 0 };
- convolve(input, make::w_window2d_int(ws), output);
+ +0, -1, -2, -1, 0,
+ +0, 0, -1, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ // LoG 7x7 (Cf. Russ, p. 250)
+
+ template <typename I, typename O>
+ void LoG_7x7(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +0, 0, -1, -1, -1, 0, 0,
+ +0, -1, -3, -3, -3, -1, 0,
+ -1, -3, 0, 7, 0, -3, -1,
+ -1, -3, 7, 24, 7, -3, -1,
+ -1, -3, 0, 7, 0, -3, -1,
+ +0, -1, -3, -3, -3, -1, 0,
+ +0, 0, -1, -1, -1, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ // LoG 13x13 (Cf. Russ, p. 250)
+
+ template <typename I, typename O>
+ void LoG_13x13(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0,
+ +0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+ +0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+ +0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
+ +0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
+ -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
+ -1, -2, -4, -2, 6, 19, 24, 19, 6, -2, -4, -2, -1,
+ -1, -2, -3, -3, 4, 14, 19, 14, 4, -3, -3, -2, -1,
+ +0, -1, -3, -3, -1, 4, 6, 4, -1, -3, -3, -1, 0,
+ +0, -1, -2, -3, -3, -3, -2, -3, -3, -3, -2, -1, 0,
+ +0, 0, -2, -2, -3, -3, -4, -3, -3, -2, -2, 0, 0,
+ +0, 0, 0, -1, -1, -2, -2, -2, -1, -1, 0, 0, 0,
+ +0, 0, 0, 0, 0, -1, -1, -1, 0, 0, 0, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+
+ // LoG 17x17 (Cf. Sonka et al., pages 85-86)
+
+ template <typename I, typename O>
+ void LoG_17x17(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0,
+ +0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
+ +0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
+ +0, 0,-1,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,-1, 0, 0,
+ +0,-1,-1,-2,-3,-3,-3,-2,-3,-2,-3,-3,-3,-2,-1,-1, 0,
+ +0,-1,-2,-3,-3,-3, 0, 2, 4, 2, 0,-3,-3,-3,-2,-1, 0,
+ -1,-1,-3,-3,-3, 0, 4,10,12,10, 4, 0,-3,-3,-3,-1,-1,
+ -1,-1,-3,-3,-2, 2,10,18,21,18,10, 2,-2,-3,-3,-1,-1,
+ -1,-1,-3,-3,-3, 4,12,21,24,21,12, 4,-3,-3,-3,-1,-1,
+ -1,-1,-3,-3,-2, 2,10,18,21,18,10, 2,-2,-3,-3,-1,-1,
+ -1,-1,-3,-3,-3, 0, 4,10,12,10, 4, 0,-3,-3,-3,-1,-1,
+ +0,-1,-2,-3,-3,-3, 0, 2, 4, 2, 0,-3,-3,-3,-2,-1, 0,
+ +0,-1,-1,-2,-3,-3,-3,-2,-3,-2,-3,-3,-3,-2,-1,-1, 0,
+ +0, 0,-1,-1,-2,-3,-3,-3,-3,-3,-3,-3,-2,-1,-1, 0, 0,
+ +0, 0,-1,-1,-1,-2,-3,-3,-3,-3,-3,-2,-1,-1,-1, 0, 0,
+ +0, 0, 0, 0,-1,-1,-1,-1,-1,-1,-1,-1,-1, 0, 0, 0, 0,
+ +0, 0, 0, 0, 0, 0,-1,-1,-1,-1,-1, 0, 0, 0, 0, 0, 0 };
+ convolve(input, make::w_window2d(ws), output);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -71,4 +146,4 @@
} // end of namespace mln
-#endif // ! MLN_LINEAR_CONVOLVE_HH
+#endif // ! MLN_LINEAR_LOG_HH
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1051)
+++ mln/linear/convolve.hh (working copy)
@@ -48,10 +48,13 @@
/*! Convolution of image \p input by the weighted window \p win.
*
+ * \warning Computation of \p output(p) is performed with the
+ * value type of \p output.
+ *
* \pre output.domain = input.domain
*/
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input, const Weighted_Window<W>& win,
+ void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
Image<O>& output);
@@ -61,47 +64,47 @@
{
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input_, const Weighted_Window<W>& win_,
+ void convolve(const Image<I>& input_, const Weighted_Window<W>& w_win_,
Image<O>& output_)
{
const I& input = exact(input_);
- const W& win = exact(win_);
+ const W& w_win = exact(w_win_);
O& output = exact(output_);
mln_piter(I) p(input.domain());
- mln_qiter(W) q(win, p);
+ mln_qiter(W) q(w_win, p);
for_all(p)
{
mln_value(O) v = 0;
for_all(q) if (input.has(q))
- v += input(q) * q.weight();
+ v += input(q) * q.w();
output(p) = v;
}
}
template <typename I, typename W, typename O>
- void convolve(const Fast_Image<I>& input_, const Weighted_Window<W>& win_,
+ void convolve(const Fast_Image<I>& input_, const Weighted_Window<W>& w_win_,
Fast_Image<O>& output_)
{
const I& input = exact(input_);
- const W& win = exact(win_);
+ const W& w_win = exact(w_win_);
O& output = exact(output_);
- border::resize(input, win.delta());
+ border::resize(input, w_win.delta());
border::duplicate(input);
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
- mln_qixter(const I, W) q(input, win, p);
+ mln_qixter(const I, W) q(input, w_win, p);
for_all_2(p, p_out)
{
mln_value(O) v = 0;
unsigned i = 0;
for_all(q)
- v += win.weight(i++) * *q;
+ v += w_win.w(i++) * *q;
*p_out = v;
}
}
@@ -109,11 +112,11 @@
} // end of namespace mln::linear::impl
template <typename I, typename W, typename O>
- void convolve(const Image<I>& input, const Weighted_Window<W>& win,
+ void convolve(const Image<I>& input, const Weighted_Window<W>& w_win,
Image<O>& output)
{
mln_precondition(exact(output).domain() = exact(input).domain());
- impl::convolve(exact(input), exact(win), exact(output));
+ impl::convolve(exact(input), - exact(w_win), exact(output));
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/linear/lap.hh
--- mln/linear/lap.hh (revision 0)
+++ mln/linear/lap.hh (revision 0)
@@ -0,0 +1,113 @@
+// 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 MLN_LINEAR_LAP_HH
+# define MLN_LINEAR_LAP_HH
+
+/*! \file mln/linear/lap.hh
+ *
+ * \brief Laplacian.
+ */
+
+# include <mln/linear/convolve.hh>
+# include <mln/make/w_window2d.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ // FIXME: Doc!
+
+ template <typename I, typename O>
+ void lap_4(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void lap_8(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void lap_x(const Image<I>& input, Image<O>& output);
+
+ template <typename I, typename O>
+ void lap_o(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // Laplacian operators (Cf. Sonka et al., p. 81)
+
+ template <typename I, typename O>
+ void lap_4(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { 0, 1, 0,
+ 1, -4, 1,
+ 0, 1, 0 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ template <typename I, typename O>
+ void lap_8(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { 1, 1, 1,
+ 1, -8, 1,
+ 1, 1, 1 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ template <typename I, typename O>
+ void lap_x(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { +2, -1, +2,
+ -1, -4, -1,
+ +2, -1, +2 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+ template <typename I, typename O>
+ void lap_o(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { -1, +2, -1,
+ +2, -4, +2,
+ -1, +2, -1 };
+ convolve(input, make::w_window2d(ws), output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_LAP_HH
Index: mln/make/w_window2d.hh
--- mln/make/w_window2d.hh (revision 1051)
+++ mln/make/w_window2d.hh (working copy)
@@ -30,12 +30,13 @@
/*! \file mln/make/w_window2d.hh
*
- * \brief Routine to create an mln::w_window_ in the 2D case.
+ * \brief Routine to create an mln::w_window in the 2D case.
*/
# include <cmath>
+
# include <mln/core/w_window.hh>
-# include <mln/make/dpoint2d.hh>
+# include <mln/core/dpoint2d.hh>
namespace mln
@@ -44,7 +45,7 @@
namespace make
{
- /*! \brief Create a mln::w_window_ in the 2D case.
+ /*! \brief Create a 2D mln::w_window from an array of weights.
*
* \param[in] weights Array.
*
@@ -53,24 +54,24 @@
* \return A 2D weighted window.
*/
template <typename W, unsigned M>
- mln::w_window_<mln::dpoint2d, W> w_window2d(W (&weights)[M]);
+ mln::w_window<mln::dpoint2d, W> w_window2d(W (&weights)[M]);
# ifndef MLN_INCLUDE_ONLY
template <typename W, unsigned M>
- mln::w_window_<mln::dpoint2d, W>
+ mln::w_window<mln::dpoint2d, W>
w_window2d(W (&weights)[M])
{
int h = unsigned(std::sqrt(float(M))) / 2;
mln_precondition((2 * h + 1) * (2 * h + 1) = M);
- mln::w_window_<mln::dpoint2d, W> tmp;
+ mln::w_window<mln::dpoint2d, W> tmp;
unsigned i = 0;
for (int row = - h; row <= h; ++row)
for (int col = - h; col <= h; ++col)
{
if (weights[i] != 0)
- tmp.insert(make::dpoint2d(row, col), weights[i]);
+ tmp.insert(weights[i], make::dpoint2d(row, col));
i++;
}
return tmp;
Index: mln/make/w_window.hh
--- mln/make/w_window.hh (revision 0)
+++ mln/make/w_window.hh (revision 0)
@@ -0,0 +1,86 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_MAKE_W_WINDOW_HH
+# define MLN_MAKE_W_WINDOW_HH
+
+/*! \file mln/make/w_window.hh
+ *
+ * \brief Routine to create a mln::w_window.
+ */
+
+# include <mln/core/concept/window.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/core/w_window.hh>
+
+
+namespace mln
+{
+
+ namespace make
+ {
+
+ /*! \brief Create a mln::w_window from a window and a weight
+ * function.
+ *
+ * \param[in] weights Array.
+ *
+ * \pre The array size, \c M, has to be a square of an odd integer.
+ *
+ * \return A weighted window.
+ */
+ template <typename W, typename F>
+ mln::w_window<mln_dpoint(W), mln_result(F)> w_window(const Window<W>& win,
+ const Function_p2v<F>& wei);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename W, typename F>
+ mln::w_window<mln_dpoint(W), mln_result(F)> w_window(const Window<W>& win_,
+ const Function_p2v<F>& wei_)
+ {
+ const W& win = exact(win_);
+ const F& wei = exact(wei_);
+ mln_precondition(! win.is_empty());
+ typedef mln_dpoint(W) D;
+ typedef mln_point(D) P;
+ mln::w_window<D, mln_result(F)> w_win;
+ mln_qiter(W) q(win, P::zero);
+ for_all(q)
+ w_win.insert(wei(q), q - P::zero);
+ return w_win;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::make
+
+} // end of namespace mln
+
+
+#endif // ! MLN_MAKE_W_WINDOW_HH
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update accus and add LoG filter.
* mln/core/concept/accumulator.hh (merge): New.
* mln/core/concept/doc/accumulator.hh
(take): New; overload.
* mln/accu/bbox.hh,
* mln/accu/count.hh,
* mln/accu/histo.hh,
* mln/accu/max.hh,
* mln/accu/mean.hh,
* mln/accu/min.hh,
* mln/accu/sum.hh (operator+=): Rename as...
(take): ...this.
(conversion): Remove operator; too risky.
Update.
* mln/estim/mean.hh: Update.
* mln/level/fast_median.hh: Update.
* mln/level/median.hh: Update.
* mln/level/naive/median.hh: Update.
* mln/morpho/erosion.hh: Update.
* mln/border/duplicate.hh,
* mln/border/fill.hh,
* mln/border/mirror.hh,
* mln/border/resize.hh: Add fixme.
* mln/io/load_pgm,
* mln/io/save_pgm: Fix for g++-2.95.
* mln/linear/convolve.hh: Use border.
* tests/convolve.cc: Update.
* mln/accu/min_max.hh: New.
* mln/estim/min_max.hh: New.
* mln/fun/v2v/linear.hh: New.
* mln/level/stretch.hh: New.
* mln/linear/log.hh: New.
* mln/value/props.hh (epsilon): New.
* tests/linear_log.cc: New.
mln/accu/bbox.hh | 33 ++++++--
mln/accu/count.hh | 28 ++----
mln/accu/histo.hh | 10 ++
mln/accu/max.hh | 16 ++-
mln/accu/mean.hh | 34 +++-----
mln/accu/median.hh | 29 +++++--
mln/accu/min.hh | 21 ++---
mln/accu/min_max.hh | 147 ++++++++++++++++++++++++++++++++++++
mln/accu/sum.hh | 30 ++-----
mln/border/duplicate.hh | 5 -
mln/border/fill.hh | 5 -
mln/border/mirror.hh | 5 -
mln/border/resize.hh | 7 +
mln/core/concept/accumulator.hh | 25 ++++++
mln/core/concept/doc/accumulator.hh | 3
mln/estim/mean.hh | 3
mln/estim/min_max.hh | 78 +++++++++++++++++++
mln/fun/v2v/linear.hh | 93 ++++++++++++++++++++++
mln/io/load_pgm.hh | 26 +++++-
mln/io/save_pgm.hh | 29 +++++--
mln/level/fast_median.hh | 6 -
mln/level/median.hh | 12 +-
mln/level/naive/median.hh | 2
mln/level/stretch.hh | 100 ++++++++++++++++++++++++
mln/level/to_enc.hh | 4
mln/linear/convolve.hh | 5 +
mln/linear/log.hh | 74 ++++++++++++++++++
mln/morpho/erosion.hh | 2
mln/value/props.hh | 10 +-
mln/value/stack.hh | 2
tests/convolve.cc | 3
tests/linear_log.cc | 71 +++++++++++++++++
32 files changed, 794 insertions(+), 124 deletions(-)
Index: tests/convolve.cc
--- tests/convolve.cc (revision 1050)
+++ tests/convolve.cc (working copy)
@@ -40,6 +40,7 @@
#include <mln/core/w_window.hh>
#include <mln/make/w_window2d.hh>
+#include <mln/border/thickness.hh>
#include <mln/linear/convolve.hh>
@@ -48,6 +49,8 @@
using namespace mln;
using value::int_u8;
+ border::thickness = 2;
+
image2d_b<int_u8>
lena = io::load_pgm("../img/lena.pgm"),
out(lena.domain());
Index: tests/linear_log.cc
--- tests/linear_log.cc (revision 0)
+++ tests/linear_log.cc (revision 0)
@@ -0,0 +1,71 @@
+// 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.
+
+/*! \file tests/linear_log.cc
+ *
+ * \brief Tests on mln::linear::log.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/io/load_pgm.hh>
+#include <mln/io/save_pgm.hh>
+
+#include <mln/border/thickness.hh>
+#include <mln/linear/log.hh>
+
+#include <mln/estim/min_max.hh>
+#include <mln/level/stretch.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ border::thickness = 2;
+
+ image2d_b<int_u8> lena = io::load_pgm("../img/lena.pgm");
+
+ image2d_b<int> tmp(lena.domain());
+ linear::LoG_5x5(lena, tmp);
+ {
+ int min, max;
+ estim::min_max(tmp, min, max);
+ mln_assertion(min = -929 && max = 1458);
+ }
+
+ image2d_b<int_u8> out(lena.domain());
+ level::stretch(tmp, out);
+ io::save_pgm(out, "out.pgm");
+ {
+ int_u8 min, max;
+ estim::min_max(out, min, max);
+ mln_assertion(min = 0 && max = 255);
+ }
+}
Index: mln/estim/min_max.hh
--- mln/estim/min_max.hh (revision 0)
+++ mln/estim/min_max.hh (revision 0)
@@ -0,0 +1,78 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_ESTIM_MIN_MAX_HH
+# define MLN_ESTIM_MIN_MAX_HH
+
+/*! \file mln/estim/min_max.hh
+ *
+ * \brief Compute the min_max pixel value.
+ */
+
+# include <mln/accu/min_max.hh>
+# include <mln/level/take.hh>
+
+
+namespace mln
+{
+
+ namespace estim
+ {
+
+ /*! \brief Compute the min and max values of the pixels of image \p input.
+ *
+ * \param[in] input The image.
+ * \param[out] min The minimum pixel value of \p input.
+ * \param[out] max The maximum pixel value of \p input.
+ */
+ template <typename I>
+ void min_max(const Image<I>& input,
+ mln_value(I)& min, mln_value(I)& max);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I>
+ void min_max(const Image<I>& input,
+ mln_value(I)& min, mln_value(I)& max)
+ {
+ mln_precondition(exact(input).has_data());
+ accu::min_max<mln_value(I)> a;
+ a.init();
+ level::take(a, input);
+ min = a.min();
+ max = a.max();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::estim
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ESTIM_MIN_MAX_HH
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1050)
+++ mln/estim/mean.hh (working copy)
@@ -56,9 +56,10 @@
template <typename I>
mln_sum(mln_value(I)) mean(const Image<I>& input)
{
+ mln_precondition(exact(input).has_data());
typedef mln_value(I) V;
typedef mln_sum(V) S;
- return level::run(input, accu::mean<V, S>());
+ return level::run(input, accu::mean<V, S>()).to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/concept/doc/accumulator.hh
--- mln/core/concept/doc/accumulator.hh (revision 1050)
+++ mln/core/concept/doc/accumulator.hh (working copy)
@@ -49,6 +49,9 @@
/// Take into account a value \p v (an element).
void take(const value& v);
+
+ /// Take into account another accumulator \p other.
+ void take(const E& other);
};
} // end of namespace mln::doc
Index: mln/core/concept/accumulator.hh
--- mln/core/concept/accumulator.hh (revision 1050)
+++ mln/core/concept/accumulator.hh (working copy)
@@ -54,12 +54,27 @@
typedef value;
void init();
void take(const value& v);
+ void take(const E& other);
*/
protected:
Accumulator();
};
+ /*! \brief Merge two accumulators.
+ *
+ * The parameter \a E is the accumulator exact type.
+ *
+ * \param[in] lhs An accumulator.
+ * \param[in] rhs Another accumulator.
+ * \result A temporary accumulator.
+ *
+ * \see relates mln::Accumulator
+ */
+ template <typename E>
+ E merge(const Accumulator<E>& lhs, const Accumulator<E>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
@@ -70,6 +85,16 @@
m1 = 0;
void (E::*m2)(const value&) = & E::take;
m2 = 0;
+ void (E::*m3)(const E&) = & E::take;
+ m3 = 0;
+ }
+
+ template <typename E>
+ E merge(const Accumulator<E>& lhs, const Accumulator<E>& rhs)
+ {
+ E tmp(exact(lhs));
+ tmp.take(exact(rhs));
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/fun/v2v/linear.hh
--- mln/fun/v2v/linear.hh (revision 0)
+++ mln/fun/v2v/linear.hh (revision 0)
@@ -0,0 +1,93 @@
+// 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 MLN_FUN_V2V_LINEAR_HH
+# define MLN_FUN_V2V_LINEAR_HH
+
+/*! \file mln/fun/v2v/linear.hh
+ *
+ * \brief FIXME.
+ */
+
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ namespace fun
+ {
+
+ namespace v2v
+ {
+
+ /*! Linear function.
+ *
+ * f(v) = a * v + b.
+ *
+ * \c V is the type of input values; \c T is the type used to
+ * compute the result; \c R is the result type.
+ *
+ * By defaut, \c T is \c V and \c R is \c T.
+ */
+ template <typename V, typename T = V, typename R = T>
+ struct linear : public Function_v2v< linear<V,T,R> >
+ {
+ typedef R result;
+ R operator()(const V& v) const;
+
+ linear(T a, T b);
+ T a, b;
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V, typename T, typename R>
+ linear<V,T,R>::linear(T a, T b)
+ : a(a),
+ b(b)
+ {
+ }
+
+ template <typename V, typename T, typename R>
+ R
+ linear<V,T,R>::operator()(const V& v) const
+ {
+ return R(a * T(v) + b);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::fun::v2v
+
+ } // end of namespace mln::fun
+
+} // end of namespace mln
+
+
+#endif // ! MLN_FUN_V2V_LINEAR_HH
Index: mln/morpho/erosion.hh
--- mln/morpho/erosion.hh (revision 1050)
+++ mln/morpho/erosion.hh (working copy)
@@ -70,7 +70,7 @@
min.init();
for_all(q) if (input.has(q))
min.take(input(q));
- output(p) = min;
+ output(p) = min.to_value();
}
}
Index: mln/level/median.hh
--- mln/level/median.hh (revision 1050)
+++ mln/level/median.hh (working copy)
@@ -122,7 +122,7 @@
med.untake(input(q_dm));
for_all(q_dp) if (input.has(q_dp))
med.take(input(q_dp));
- output(p) = med;
+ output(p) = med.to_value();
}
void fwd()
@@ -131,7 +131,7 @@
med.untake(input(q_fm));
for_all(q_fp) if (input.has(q_fp))
med.take(input(q_fp));
- output(p) = med;
+ output(p) = med.to_value();
}
void bkd()
@@ -140,7 +140,7 @@
med.untake(input(q_bm));
for_all(q_bp) if (input.has(q_bp))
med.take(input(q_bp));
- output(p) = med;
+ output(p) = med.to_value();
}
}; // end of median_functor
@@ -192,7 +192,7 @@
for (col = min_col; col <= min_col + half; ++col, ++ct)
{
med.take(input(pt));
- output(p) = med;
+ output(p) = med.to_value();
}
// middle columns (both take and untake)
@@ -201,14 +201,14 @@
{
med.take(input(pt));
med.untake(input(pu));
- output(p) = med;
+ output(p) = med.to_value();
}
// right columns (now just untake old points)
for (; col <= max_col; ++cu, ++col)
{
med.untake(input(pu));
- output(p) = med;
+ output(p) = med.to_value();
}
}
}
Index: mln/level/naive/median.hh
--- mln/level/naive/median.hh (revision 1050)
+++ mln/level/naive/median.hh (working copy)
@@ -85,7 +85,7 @@
med.init();
for_all(q) if (input.has(q))
med.take(input(q));
- output(p) = med;
+ output(p) = med.to_value();
}
}
Index: mln/level/to_enc.hh
--- mln/level/to_enc.hh (revision 1050)
+++ mln/level/to_enc.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/level/to_enc.hh
*
- * \brief Transform with fun::to_enc the contents of an image into
+ * \brief Transform with fun::v2v::enc the contents of an image into
* another one.
*/
@@ -60,7 +60,7 @@
template <typename I, typename O>
void to_enc(const Image<I>& input, Image<O>& output)
{
- mln_precondition(exact(output).domain() >= exact(input).domain());
+ mln_precondition(exact(output).domain() = exact(input).domain());
level::transform(input, fun::v2v::enc< mln_value(I) >(), output);
}
Index: mln/level/fast_median.hh
--- mln/level/fast_median.hh (revision 1050)
+++ mln/level/fast_median.hh (working copy)
@@ -119,7 +119,7 @@
for_all(q_bot)
med.take(*q_bot);
- output(p) = med;
+ output(p) = med.to_value();
if (fwd)
// browse line fwd
@@ -130,7 +130,7 @@
med.untake(*q_fm);
for_all(q_fp)
med.take(*q_fp);
- output(p) = med;
+ output(p) = med.to_value();
}
else
// browse line bkd
@@ -141,7 +141,7 @@
med.untake(*q_bm);
for_all(q_bp)
med.take(*q_bp);
- output(p) = med;
+ output(p) = med.to_value();
}
// change browsing
fwd = ! fwd;
Index: mln/level/stretch.hh
--- mln/level/stretch.hh (revision 0)
+++ mln/level/stretch.hh (revision 0)
@@ -0,0 +1,100 @@
+// 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 MLN_LEVEL_STRETCH_HH
+# define MLN_LEVEL_STRETCH_HH
+
+/*! \file mln/level/stretch.hh
+ *
+ * \brief Transform with fun::stretch the contents of an image into
+ * another one.
+ */
+
+# include <mln/estim/min_max.hh>
+# include <mln/value/int_u.hh>
+# include <mln/fun/v2v/linear.hh>
+# include <mln/level/transform.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Stretch the values of \p input so that they can be stored in \p output.
+ *
+ * \param[in] input The input image.
+ * \param[out] output The result image.
+ *
+ * \pre \p output.domain = \p input.domain
+ */
+ template <typename I, typename O>
+ void stretch(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <unsigned n, typename I, typename O>
+ void stretch(value::int_u<n>,
+ const Image<I>& input, Image<O>& output)
+ {
+ mln_value(I) min_, max_;
+ estim::min_max(input, min_, max_);
+ if (max_ = min_)
+ return; // FIXME
+ float min = float(min_), max = float(max_);
+ const float epsilon = value::props<float>::epsilon;
+ float m = 0.0f - 0.5f + epsilon;
+ float M = mln_max(value::int_u<n>) + 0.5f - epsilon;
+ float a = (M - m) / (max - min);
+ float b = (m * max - M * min) / (max - min);
+ fun::v2v::linear<float, float, int> f(a, b);
+ level::transform(input, f, output);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ template <typename I, typename O>
+ void stretch(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ impl::stretch(mln_value(O)(), input, output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_STRETCH_HH
Index: mln/io/save_pgm.hh
--- mln/io/save_pgm.hh (revision 1050)
+++ mln/io/save_pgm.hh (working copy)
@@ -55,15 +55,32 @@
file << "# olena" << std::endl;
file << ima.ncols() << ' ' << ima.nrows() << std::endl;
file << "255" << std::endl;
- point2d p = make::point2d(ima.domain().pmin().row(),
- ima.domain().pmin().col());
- size_t len = ima.ncols() * sizeof(unsigned char);
- for (;
- p.row() <= ima.domain().pmax().row();
- ++p.row())
+ const int
+ min_row = ima.domain().pmin().row(),
+ max_row = ima.domain().pmax().row();
+ point2d p;
+ if (sizeof(value::int_u8) = 1)
{
+ p.col() = ima.domain().pmin().col();
+ size_t len = ima.ncols();
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
file.write((char*)(& ima(p)), len);
}
+ else
+ {
+ // FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!!
+ const int
+ min_col = ima.domain().pmin().col(),
+ max_col = ima.domain().pmax().col();
+ std::cout << min_row << ' ' << max_row << std::endl;
+ std::cout << min_col << ' ' << max_col << std::endl;
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
+ for (p.col() = min_col; p.col() <= max_col; ++p.col())
+ {
+ unsigned char c = ima(p);
+ file.write((char*)(&c), 1);
+ }
+ }
}
} // end of namespace mln::io
Index: mln/io/load_pgm.hh
--- mln/io/load_pgm.hh (revision 1050)
+++ mln/io/load_pgm.hh (working copy)
@@ -135,13 +135,30 @@
void load_pgm_raw_2d(std::ifstream& file, I& ima)
{
point2d p = make::point2d(0, ima.domain().pmin().col());
- size_t len = ima.ncols() * sizeof(mln_value(I));
- for (p.row() = ima.domain().pmin().row();
- p.row() <= ima.domain().pmax().row();
- ++p.row())
+ typedef mln_value(I) V;
+ const mln_coord(I)
+ min_row = ima.domain().pmin().row(),
+ max_row = ima.domain().pmax().row();
+ if (sizeof(V) = 1)
{
+ size_t len = ima.ncols() * sizeof(mln_enc(V));
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
file.read((char*)(& ima(p)), len);
}
+ else
+ {
+ // FIXME: code for g++-2.95 when sizeof(int_u8) = 2!!!
+ const mln_coord(I)
+ min_col = ima.domain().pmin().col(),
+ max_col = ima.domain().pmax().col();
+ for (p.row() = min_row; p.row() <= max_row; ++p.row())
+ for (p.col() = min_col; p.col() <= max_col; ++p.col())
+ {
+ unsigned char c;
+ file.read((char*)(&c), 1);
+ ima(p) = c;
+ }
+ }
}
@@ -160,6 +177,7 @@
char type;
int nrows, ncols;
internal::read_pnm_header('2', '5', file, type, nrows, ncols);
+
image2d_b<value::int_u8> ima(nrows, ncols);
if (type = '5')
internal::load_pgm_raw_2d(file, ima);
Index: mln/linear/log.hh
--- mln/linear/log.hh (revision 0)
+++ mln/linear/log.hh (revision 0)
@@ -0,0 +1,74 @@
+// 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 MLN_LINEAR_LOG_HH
+# define MLN_LINEAR_LOG_HH
+
+/*! \file mln/linear/log.hh
+ *
+ * \brief Laplacian of Gaussian.
+ */
+
+# include <mln/linear/convolve.hh>
+# include <mln/make/w_window2d_int.hh>
+
+
+
+namespace mln
+{
+
+ namespace linear
+ {
+
+ template <typename I, typename O>
+ void LoG_5x5(const Image<I>& input, Image<O>& output);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // LoG_5x5 (Cf. Sonka et al., pages 85-86)
+
+ template <typename I, typename O>
+ void LoG_5x5(const Image<I>& input, Image<O>& output)
+ {
+ mln_precondition(exact(output).domain() = exact(input).domain());
+ int ws[] = { 0, 0, -1, 0, 0,
+ 0, -1, -2, -1, 0,
+ -1, -2, 16, -2, -1,
+ 0, -1, -2, -1, 0,
+ 0, 0, -1, 0, 0 };
+ convolve(input, make::w_window2d_int(ws), output);
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::linear
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LINEAR_CONVOLVE_HH
Index: mln/linear/convolve.hh
--- mln/linear/convolve.hh (revision 1050)
+++ mln/linear/convolve.hh (working copy)
@@ -35,6 +35,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/concept/weighted_window.hh>
+# include <mln/border/resize.hh>
+# include <mln/border/duplicate.hh>
@@ -86,6 +88,9 @@
const W& win = exact(win_);
O& output = exact(output_);
+ border::resize(input, win.delta());
+ border::duplicate(input);
+
mln_pixter(O) p_out(output);
mln_pixter(const I) p(input);
Index: mln/accu/min.hh
--- mln/accu/min.hh (revision 1050)
+++ mln/accu/min.hh (working copy)
@@ -54,10 +54,11 @@
typedef V value;
min();
+
void take(const value& v);
+ void take(const min<V>& other);
void init();
- operator V() const;
V to_value() const;
protected:
@@ -76,23 +77,25 @@
}
template <typename V>
- void min<V>::take(const value& v)
+ void
+ min<V>::init()
{
- if (v < v_)
- v_ = v;
+ v_ = mln_max(V);
}
template <typename V>
- void
- min<V>::init()
+ void min<V>::take(const value& v)
{
- v_ = mln_max(V);
+ if (v < v_)
+ v_ = v;
}
template <typename V>
- min<V>::operator V() const
+ void
+ min<V>::take(const min<V>& other)
{
- return v_;
+ if (other.v_ < v_)
+ v_ = other.v_;
}
template <typename V>
Index: mln/accu/sum.hh
--- mln/accu/sum.hh (revision 1050)
+++ mln/accu/sum.hh (working copy)
@@ -56,14 +56,13 @@
typedef V value;
sum();
- void take(const value& v);
+
void init();
+ void take(const value& v);
+ void take(const sum<V,S>& other);
- operator S() const;
S to_value() const;
- sum<V,S>& operator+=(const sum<V,S>& rhs);
-
protected:
S sum_;
@@ -80,12 +79,6 @@
}
template <typename V, typename S>
- void sum<V,S>::take(const value& v)
- {
- sum_ += v;
- }
-
- template <typename V, typename S>
void
sum<V,S>::init()
{
@@ -93,24 +86,23 @@
}
template <typename V, typename S>
- sum<V,S>::operator S() const
+ void sum<V,S>::take(const value& v)
{
- return to_value;
+ sum_ += v;
}
template <typename V, typename S>
- S
- sum<V,S>::to_value() const
+ void
+ sum<V,S>::take(const sum<V,S>& other)
{
- return sum_;
+ sum_ += other.sum_;
}
template <typename V, typename S>
- sum<V,S>&
- sum<V,S>::operator+=(const sum<V,S>& rhs)
+ S
+ sum<V,S>::to_value() const
{
- sum_ += rhs.sum_;
- return *this;
+ return sum_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/accu/max.hh
--- mln/accu/max.hh (revision 1050)
+++ mln/accu/max.hh (working copy)
@@ -54,10 +54,11 @@
typedef V value;
max();
+
void take(const value& v);
+ void take(const max<V>& other);
void init();
- operator V() const;
V to_value() const;
protected:
@@ -76,7 +77,8 @@
}
template <typename V>
- void max<V>::take(const value& v)
+ void
+ max<V>::take(const value& v)
{
if (v > v_)
v_ = v;
@@ -84,15 +86,17 @@
template <typename V>
void
- max<V>::init()
+ max<V>::take(const max<V>& other)
{
- v_ = mln_min(V);
+ if (other.v_ > v_)
+ v_ = other.v_;
}
template <typename V>
- max<V>::operator V() const
+ void
+ max<V>::init()
{
- return v_;
+ v_ = mln_min(V);
}
template <typename V>
Index: mln/accu/histo.hh
--- mln/accu/histo.hh (revision 1050)
+++ mln/accu/histo.hh (working copy)
@@ -59,6 +59,7 @@
typedef mln_value(S) value;
void take(const value& v);
+ void take(const histo<S>& other);
void untake(const value& v);
void init();
@@ -113,6 +114,15 @@
template <typename S>
void
+ histo<S>::take(const histo<S>& other)
+ {
+ for (unsigned i = 0; i < h_.size(); ++i)
+ h_[i] += other.h_[i];
+ sum_ += other.sum_;
+ }
+
+ template <typename S>
+ void
histo<S>::untake(const value& v)
{
mln_precondition(h_[s_.index_of(v)] > 0);
Index: mln/accu/count.hh
--- mln/accu/count.hh (revision 1050)
+++ mln/accu/count.hh (working copy)
@@ -51,14 +51,13 @@
typedef V value;
count();
- void take(const value&);
+
void init();
+ void take(const value&);
+ void take(const count<V>& other);
- operator std::size_t() const;
std::size_t to_value() const;
- count<V>& operator+=(const count<V>& rhs);
-
protected:
std::size_t count_;
@@ -76,22 +75,23 @@
template <typename V>
void
- count<V>::take(const value&)
+ count<V>::init()
{
- ++count_;
+ count_ = 0;
}
template <typename V>
void
- count<V>::init()
+ count<V>::take(const value&)
{
- count_ = 0;
+ ++count_;
}
template <typename V>
- count<V>::operator std::size_t() const
+ void
+ count<V>::take(const count<V>& other)
{
- return to_value();
+ count_ += other.count_;
}
template <typename V>
@@ -101,14 +101,6 @@
return count_;
}
- template <typename V>
- count<V>&
- count<V>::operator+=(const count<V>& rhs)
- {
- count_ += rhs.count_;
- return *this;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/accu/min_max.hh
--- mln/accu/min_max.hh (revision 0)
+++ mln/accu/min_max.hh (revision 0)
@@ -0,0 +1,147 @@
+// 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 MLN_ACCU_MIN_MAX_HH
+# define MLN_ACCU_MIN_MAX_HH
+
+/*! \file mln/accu/min_max.hh
+ *
+ * \brief Define an accumulator that computes a min and a max.
+ */
+
+# include <utility>
+
+# include <mln/accu/min.hh>
+# include <mln/accu/max.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic min and max accumulator class.
+ *
+ * The parameter \c V is the type of values.
+ */
+ template <typename V>
+ struct min_max : public Accumulator< min_max<V> >
+ {
+ typedef V value;
+
+ min_max();
+
+ void take(const value& v);
+ void take(const min_max<V>& other);
+ void init();
+
+ V min() const;
+ V max() const;
+
+ std::pair<V,V> to_value() const;
+ void values(V& min, V& max) const;
+
+ protected:
+
+ accu::min<V> min_;
+ accu::max<V> max_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ min_max<V>::min_max()
+ {
+ init();
+ }
+
+ template <typename V>
+ void
+ min_max<V>::init()
+ {
+ min_.init();
+ max_.init();
+ }
+
+ template <typename V>
+ void min_max<V>::take(const value& v)
+ {
+ min_.take(v);
+ max_.take(v);
+ }
+
+ template <typename V>
+ void
+ min_max<V>::take(const min_max<V>& other)
+ {
+ min_.take(other.min_);
+ max_.take(other.max_);
+ }
+
+ template <typename V>
+ V
+ min_max<V>::min() const
+ {
+ return min_.to_value();
+ }
+
+ template <typename V>
+ V
+ min_max<V>::max() const
+ {
+ return max_.to_value();
+ }
+
+ template <typename V>
+ std::pair<V,V>
+ min_max<V>::to_value() const
+ {
+ std::pair<V,V> tmp(min_.to_value(),
+ max_.to_value());
+ return tmp;
+ }
+
+ template <typename V>
+ void
+ min_max<V>::values(V& min, V& max) const
+ {
+ min = min_.to_value();
+ max = max_.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_MIN_MAX_HH
Index: mln/accu/bbox.hh
--- mln/accu/bbox.hh (revision 1050)
+++ mln/accu/bbox.hh (working copy)
@@ -54,10 +54,11 @@
typedef P value;
bbox();
+
void take(const P& p);
+ void take(const bbox<P>& other);
void init();
- operator box_<P>() const;
const box_<P>& to_value() const;
bool is_valid() const;
@@ -79,7 +80,8 @@
}
template <typename P>
- void bbox<P>::take(const P& p)
+ void
+ bbox<P>::take(const P& p)
{
if (! is_valid_)
{
@@ -97,16 +99,33 @@
template <typename P>
void
- bbox<P>::init()
+ bbox<P>::take(const bbox<P>& other)
{
- is_valid_ = false;
+ if (! other.is_valid_)
+ {
+ // no-op
+ return;
+ }
+ if (! this->is_valid_)
+ {
+ // 'other' makes '*this' valid
+ *this = other;
+ return;
+ }
+ // both are valids so:
+ const box_<P>& o_b = other.b_;
+ for (unsigned i = 0; i < P::dim; ++i)
+ if (o_b.pmin()[i] < b_.pmin()[i])
+ b_.pmin()[i] = o_b.pmin()[i];
+ else if (o_b.pmax()[i] > b_.pmax()[i])
+ b_.pmax()[i] = o_b.pmax()[i];
}
template <typename P>
- bbox<P>::operator box_<P>() const
+ void
+ bbox<P>::init()
{
- mln_precondition(is_valid_);
- return b_;
+ is_valid_ = false;
}
template <typename P>
Index: mln/accu/median.hh
--- mln/accu/median.hh (revision 1050)
+++ mln/accu/median.hh (working copy)
@@ -55,13 +55,13 @@
median(const Value_Set<S>& s);
median();
+ void init();
void take(const value& v);
+ void take(const median<S>& other);
void untake(const value& v);
- void init();
unsigned card() const { return h_.sum(); }
- operator mln_value(S) () const;
value to_value() const;
const accu::histo<S>& histo() const;
@@ -119,6 +119,25 @@
template <typename S>
void
+ median<S>::take(const median<S>& other)
+ {
+ // h_
+ h_.take(other.h_);
+
+ // sum_minus_
+ for (unsigned i = 0; i < i_; ++i)
+ sum_minus_ += other.h_[i];
+
+ // sum_plus_
+ for (unsigned i = i_ + 1; i < h_.nvalues(); ++i)
+ sum_plus_ += other.h_[i];
+
+ if (valid_)
+ valid_ = false;
+ }
+
+ template <typename S>
+ void
median<S>::untake(const value& v)
{
mln_precondition(h_(v) != 0);
@@ -203,12 +222,6 @@
}
template <typename S>
- median<S>::operator mln_value(S) () const
- {
- return to_value();
- }
-
- template <typename S>
typename median<S>::value
median<S>::to_value() const
{
Index: mln/accu/mean.hh
--- mln/accu/mean.hh (revision 1050)
+++ mln/accu/mean.hh (working copy)
@@ -60,14 +60,13 @@
typedef V value;
mean();
- void take(const value& v);
+
void init();
+ void take(const value& v);
+ void take(const mean<V,S,M>& other);
- operator M() const;
M to_value() const;
- mean<V,S,M>& operator+=(const mean<V,S,M>& rhs);
-
protected:
accu::count<V> count_;
@@ -85,13 +84,6 @@
}
template <typename V, typename S, typename M>
- void mean<V,S,M>::take(const value& v)
- {
- count_.take(v);
- sum_.take(v);
- }
-
- template <typename V, typename S, typename M>
void
mean<V,S,M>::init()
{
@@ -100,25 +92,25 @@
}
template <typename V, typename S, typename M>
- mean<V,S,M>::operator M() const
+ void mean<V,S,M>::take(const value& v)
{
- return to_value();
+ count_.take(v);
+ sum_.take(v);
}
template <typename V, typename S, typename M>
- M
- mean<V,S,M>::to_value() const
+ void
+ mean<V,S,M>::take(const mean<V,S,M>& other)
{
- return sum_.to_value() / count_.to_value();
+ count_.take(other.count_);
+ sum_.take(other.sum_);
}
template <typename V, typename S, typename M>
- mean<V,S,M>&
- mean<V,S,M>::operator+=(const mean<V,S,M>& rhs)
+ M
+ mean<V,S,M>::to_value() const
{
- count_ += rhs.count_;
- sum_ += rhs.sum_;
- return *this;
+ return sum_.to_value() / count_.to_value();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1050)
+++ mln/value/props.hh (working copy)
@@ -203,8 +203,9 @@
template <>
struct props<float>
{
- static const float min() { return FLT_MIN; }
- static const float max() { return FLT_MAX; }
+ static const float min = FLT_MIN;
+ static const float max = FLT_MAX;
+ static const float epsilon = 0.00001f;
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef float sum;
@@ -213,8 +214,9 @@
template <>
struct props<double>
{
- static const double min() { return DBL_MIN; }
- static const double max() { return DBL_MAX; }
+ static const double min = DBL_MIN;
+ static const double max = DBL_MAX;
+ static const double epsilon = 0.0000001;
typedef data_kind kind;
static const std::size_t card_ = 0;
typedef double sum;
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 1050)
+++ mln/value/stack.hh (working copy)
@@ -143,11 +143,13 @@
stack_image<2, const I>
stack(const Image<I>& ima1, const Image<I>& ima2);
+
template <typename I>
stack_image<2, I>
stack(Image<I>& ima1, Image<I>& ima2);
+
# ifndef MLN_INCLUDE_ONLY
// stack_image<n, I>
Index: mln/border/resize.hh
--- mln/border/resize.hh (revision 1050)
+++ mln/border/resize.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -65,10 +66,12 @@
void resize(const Fast_Image<I>& ima_, unsigned thickness)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
+ mln_precondition(ima.has_data());
if (ima.border() >= thickness)
return;
- mln_invariant(0); // FIXME: NYI
+ internal::fixme();
+ mln_postcondition(ima.border() >= thickness);
+ return;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/fill.hh
--- mln/border/fill.hh (revision 1050)
+++ mln/border/fill.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -62,8 +63,8 @@
void fill(const Fast_Image<I>& ima_, const mln_value(I)& v)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
- mln_invariant(0); // FIXME: NYI
+ mln_precondition(ima.has_data());
+ internal::fixme();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/duplicate.hh
--- mln/border/duplicate.hh (revision 1050)
+++ mln/border/duplicate.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -61,8 +62,8 @@
void duplicate(const Fast_Image<I>& ima_)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
- mln_invariant(0); // FIXME: NYI
+ mln_precondition(ima.has_data());
+ internal::fixme();
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/border/mirror.hh
--- mln/border/mirror.hh (revision 1050)
+++ mln/border/mirror.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/image.hh>
+# include <mln/core/internal/fixme.hh>
namespace mln
@@ -61,8 +62,8 @@
void mirror(const Fast_Image<I>& ima_)
{
const I& ima = exact(ima_);
- mln_precondition(ima_.has_data());
- mln_invariant(0); // FIXME: NYI
+ mln_precondition(ima.has_data());
+ internal::fixme();
}
# endif // ! MLN_INCLUDE_ONLY
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add 'decorated image' morpher.
* mln/core/decorated_image.hh: New.
* mln/core/internal/image_adaptor.hh (adaptee): New.
* mln/metal/unconst.hh: New.
* mln/metal/vec.hh (vec): New ctors.
(operator=): New.
* mln/metal/make: New directory.
* mln/metal/make/vec.hh: New.
* mln/value/proxy: New.
* mln/value/stack.hh (helper_stack_image_lvalue_): New.
(read_, write_): New.
(operator()): Fix.
(stack): New overload for n=2 and I mutable.
* tests/decorated_image.cc: New.
* tests/stack.cc: Augment.
mln/core/decorated_image.hh | 208 ++++++++++++++++++++++
mln/core/internal/image_adaptor.hh | 20 ++
mln/core/safe.hh | 2
mln/metal/make/vec.hh | 108 +++++++++++
mln/metal/unconst.hh | 58 ++++++
mln/metal/vec.hh | 33 +++
mln/value/proxy.hh | 335 +++++++++++++++++++++++++++++++++++++
mln/value/stack.hh | 102 +++++++++--
tests/decorated_image.cc | 67 +++++++
tests/stack.cc | 13 -
10 files changed, 927 insertions(+), 19 deletions(-)
Index: tests/stack.cc
--- tests/stack.cc (revision 1049)
+++ tests/stack.cc (working copy)
@@ -42,8 +42,13 @@
typedef image2d_b<int> I;
- I ima(2, 3);
- debug::iota(ima);
- debug::println(ima);
- debug::println(value::stack(ima, ima));
+ box2d b = make::box2d(1, 1);
+ image2d_b<int> ima5(b), ima1(b);
+
+ point2d p = make::point2d(0, 0);
+ metal::vec<2, int> v = metal::make::vec(5, 1);
+
+ value::stack(ima5, ima1)(p) = v;
+ mln_assertion(value::stack(ima5, ima1)(p) = v);
+ mln_assertion(ima5(p) = 5 && ima1(p) = 1);
}
Index: tests/decorated_image.cc
--- tests/decorated_image.cc (revision 0)
+++ tests/decorated_image.cc (revision 0)
@@ -0,0 +1,67 @@
+// 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.
+
+/*! \file tests/decorated_image.cc
+ *
+ * \brief Tests on mln::decorated_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/decorated_image.hh>
+
+
+unsigned count_read = 0, count_write = 0;
+
+template <typename I>
+struct counter
+{
+ void reading(const I& ima, const mln_psite(I)& p) const
+ {
+ ++count_read;
+ }
+ void writing(I&, const mln_psite(I)&, const mln_value(I)&)
+ {
+ ++count_write;
+ }
+};
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ I ima(1, 1);
+ point2d p = make::point2d(0, 0);
+
+ decorated_image< I, counter<I> > ima_ = decorate(ima, counter<I>());
+ ima_(p) = ima_(p) = 51;
+ mln_assertion(count_read = 1 && count_write = 2);
+
+ const I& imac = ima;
+ decorated_image< const I, counter<I> > cima_ = decorate(imac, counter<I>());
+}
Index: mln/core/decorated_image.hh
--- mln/core/decorated_image.hh (revision 0)
+++ mln/core/decorated_image.hh (revision 0)
@@ -0,0 +1,208 @@
+// 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 MLN_CORE_DECORATED_IMAGE_HH
+# define MLN_CORE_DECORATED_IMAGE_HH
+
+# include <mln/core/internal/image_adaptor.hh>
+# include <mln/value/proxy.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ template <typename I, typename D>
+ class decorated_image : public internal::image_adaptor_< I, decorated_image<I,D> >
+ {
+ typedef decorated_image<I, D> self_;
+ typedef internal::image_adaptor_< I, self_ > super_;
+ public:
+
+ decorated_image(I& ima, const D& deco);
+ ~decorated_image();
+
+ typedef mln_value(I) value;
+ typedef mln::value::proxy<const self_> rvalue;
+ typedef mln::value::proxy<self_> lvalue;
+
+ rvalue operator()(const mln_psite(I)& p) const;
+ lvalue operator()(const mln_psite(I)& p);
+
+ mln_value(I) read_(const mln_psite(I)& p) const;
+ void write_(const mln_psite(I)& p, const mln_value(I)& v);
+
+ template <typename V>
+ struct change_value
+ {
+ typedef decorated_image<mln_ch_value(I, V), D> ret;
+ };
+
+ /// Const promotion via convertion.
+ operator decorated_image<const I, D>() const;
+
+ /// Give the decoration.
+ const D& decoration() const;
+
+ /// Give the decoration.
+ D& decoration();
+
+ protected:
+ D deco_;
+ };
+
+
+
+ template <typename I, typename D>
+ decorated_image<I,D> decorate(Image<I>& ima,
+ const D& decoration);
+
+ template <typename I, typename D>
+ decorated_image<const I, D> decorate(const Image<I>& ima,
+ const D& decoration);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // decorated_image<I,D>
+
+ template <typename I, typename D>
+ decorated_image<I,D>::decorated_image(I& ima, const D& deco)
+ : super_(ima),
+ deco_(deco)
+ {
+ }
+
+ template <typename I, typename D>
+ decorated_image<I,D>::~decorated_image()
+ {
+ void (D::*mr)(const I&, const mln_psite(I)&) const = & D::reading;
+ mr = 0;
+ typedef mlc_unconst(I) I_;
+ void (D::*mw)(I_&, const mln_psite(I_)&, const mln_value(I_)&) = & D::writing;
+ mw = 0;
+ }
+
+ template <typename I, typename D>
+ mln::value::proxy< const decorated_image<I,D> >
+ decorated_image<I,D>::operator()(const mln_psite(I)& p) const
+ {
+ rvalue tmp(*this, p);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ mln::value::proxy< decorated_image<I,D> >
+ decorated_image<I,D>::operator()(const mln_psite(I)& p)
+ {
+ lvalue tmp(*this, p);
+ return tmp;
+ }
+
+ namespace internal
+ {
+
+ template <typename I, typename D>
+ void
+ helper_decorated_image_write_(decorated_image<I,D>& ima,
+ const mln_psite(I)& p, const mln_value(I)& v)
+ {
+ ima.decoration().writing(ima.adaptee(), p, v);
+ ima.adaptee()(p) = v;
+ }
+
+ template <typename I, typename D>
+ void
+ helper_decorated_image_write_(decorated_image<const I,D>&,
+ const mln_psite(I)&, const mln_value(I)&)
+ // FIXME: Static assertion instead.
+ ;
+
+ } // end of namespace mln::internal
+
+ template <typename I, typename D>
+ void
+ decorated_image<I,D>::write_(const mln_psite(I)& p, const mln_value(I)& v)
+ {
+ internal::helper_decorated_image_write_(*this, p, v);
+ }
+
+ template <typename I, typename D>
+ mln_value(I)
+ decorated_image<I,D>::read_(const mln_psite(I)& p) const
+ {
+ deco_.reading(this->adaptee_, p);
+ return this->adaptee_(p);
+ }
+
+ template <typename I, typename D>
+ decorated_image<I,D>::operator decorated_image<const I, D>() const
+ {
+ decorated_image<const I, D> tmp(this->adaptee_, deco_);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ const D&
+ decorated_image<I,D>::decoration() const
+ {
+ return deco_;
+ }
+
+ template <typename I, typename D>
+ D&
+ decorated_image<I,D>::decoration()
+ {
+ return deco_;
+ }
+
+ // decorate
+
+ template <typename I, typename D>
+ decorated_image<I, D> decorate(Image<I>& ima,
+ const D& decoration)
+ {
+ decorated_image<I, D> tmp(exact(ima), decoration);
+ return tmp;
+ }
+
+ template <typename I, typename D>
+ decorated_image<const I, D> decorate(const Image<I>& ima,
+ const D& decoration)
+ {
+ decorated_image<const I, D> tmp(exact(ima), decoration);
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_DECORATED_IMAGE_HH
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1049)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -92,6 +92,12 @@
/// Convertion to the underlying (adapted) image.
operator I() const;
+ /// Give the adaptee (underlying adapted) image.
+ const I& adaptee() const;
+
+ /// Give the adaptee (underlying adapted) image.
+ I& adaptee();
+
protected:
I& adaptee_;
@@ -104,6 +110,20 @@
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename E, typename S>
+ const I&
+ image_adaptor_<I,E,S>::adaptee() const
+ {
+ return adaptee_;
+ }
+
+ template <typename I, typename E, typename S>
+ I&
+ image_adaptor_<I,E,S>::adaptee()
+ {
+ return adaptee_;
+ }
+
+ template <typename I, typename E, typename S>
image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
: adaptee_(adaptee)
{
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1049)
+++ mln/core/safe.hh (working copy)
@@ -80,7 +80,7 @@
template <typename I>
safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
- : super_(exact(ima)),
+ : super_(ima),
default_value_(default_value)
{
}
Index: mln/metal/unconst.hh
--- mln/metal/unconst.hh (revision 0)
+++ mln/metal/unconst.hh (revision 0)
@@ -0,0 +1,58 @@
+// 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 MLN_METAL_UNCONST_HH
+# define MLN_METAL_UNCONST_HH
+
+
+# define mlc_unconst(T) typename mln::metal::unconst< T >::ret
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ template <typename T>
+ struct unconst
+ {
+ typedef T ret;
+ };
+
+ template <typename T>
+ struct unconst< const T >
+ {
+ typedef T ret;
+ };
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+#endif // ! MLN_METAL_UNCONST_HH
Index: mln/metal/vec.hh
--- mln/metal/vec.hh (revision 1049)
+++ mln/metal/vec.hh (working copy)
@@ -47,6 +47,9 @@
enum { dim = n };
typedef T coord;
+ vec();
+ vec(T (&values)[n]);
+
T& operator[](unsigned i);
T operator[](unsigned i) const;
@@ -59,9 +62,25 @@
std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v);
+ template <unsigned n, typename T>
+ bool operator=(const vec<n,T>& lhs, const vec<n,T>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <unsigned n, typename T>
+ vec<n,T>::vec()
+ {
+ }
+
+ template <unsigned n, typename T>
+ vec<n,T>::vec(T (&values)[n])
+ {
+ for (unsigned i = 0; i < n; ++i)
+ coord_[i] = values[i];
+ }
+
+ template <unsigned n, typename T>
T&
vec<n,T>::operator[](unsigned i)
{
@@ -77,6 +96,8 @@
return coord_[i];
}
+ // operators
+
template <unsigned n, typename T>
std::ostream& operator<<(std::ostream& ostr, const vec<n,T>& v)
{
@@ -86,6 +107,15 @@
return ostr << ']';
}
+ template <unsigned n, typename T>
+ bool operator=(const vec<n,T>& lhs, const vec<n,T>& rhs)
+ {
+ for (unsigned i = 0; i < n; ++i)
+ if (lhs[i] != rhs[i])
+ return false;
+ return true;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
@@ -94,4 +124,7 @@
} // end of namespace mln
+# include <mln/metal/make/vec.hh>
+
+
#endif // ! MLN_CORE_METAL_VEC_HH
Index: mln/metal/make/vec.hh
--- mln/metal/make/vec.hh (revision 0)
+++ mln/metal/make/vec.hh (revision 0)
@@ -0,0 +1,108 @@
+// 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 MLN_CORE_METAL_MAKE_VEC_HH
+# define MLN_CORE_METAL_MAKE_VEC_HH
+
+# include <mln/metal/vec.hh>
+
+
+namespace mln
+{
+
+ namespace metal
+ {
+
+ namespace make
+ {
+
+ template <typename T>
+ mln::metal::vec<1,T> vec(T c0);
+
+ template <typename T>
+ mln::metal::vec<2,T> vec(T c0, T c1);
+
+ template <typename T>
+ mln::metal::vec<3,T> vec(T c0, T c1, T c2);
+
+ template <typename T>
+ mln::metal::vec<4,T> vec(T c0, T c1, T c2, T c3);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ mln::metal::vec<1,T> vec(T c0)
+ {
+ mln::metal::vec<1,T> tmp;
+ tmp[0] = c0;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<2,T> vec(T c0, T c1)
+ {
+ mln::metal::vec<2,T> tmp;
+ tmp[0] = c0;
+ tmp[1] = c1;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<3,T> vec(T c0, T c1, T c2)
+ {
+ mln::metal::vec<3,T> tmp;
+ tmp[0] = c0;
+ tmp[1] = c1;
+ tmp[2] = c2;
+ return tmp;
+ }
+
+ template <typename T>
+ mln::metal::vec<4,T> vec(T c0, T c1, T c2, T c3)
+ {
+ mln::metal::vec<4,T> tmp;
+ tmp[0] = c0;
+ tmp[1] = c1;
+ tmp[2] = c2;
+ tmp[3] = c3;
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::metal::make
+
+ } // end of namespace mln::metal
+
+} // end of namespace mln
+
+
+# include <mln/metal/make/vec.hh>
+
+
+#endif // ! MLN_CORE_METAL_MAKE_VEC_HH
Index: mln/value/proxy.hh
--- mln/value/proxy.hh (revision 0)
+++ mln/value/proxy.hh (revision 0)
@@ -0,0 +1,335 @@
+// 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 MLN_VALUE_PROXY_HH
+# define MLN_VALUE_PROXY_HH
+
+/*! \file mln/value/proxy.hh
+ *
+ * \brief Define a generic proxy class for an image pixel value.
+ */
+
+# include <mln/core/concept/value.hh>
+# include <mln/value/props.hh>
+# include <mln/metal/unconst.hh>
+
+
+namespace mln
+{
+
+ namespace value
+ {
+
+
+ /*! \brief Generic proxy class for an image pixel value.
+ *
+ * The parameter \c I is an image type.
+ */
+ template <typename I>
+ class proxy : public Value< proxy<I> >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef void enc; // FIXME
+
+ /// Equivalent associated type.
+ typedef mln_value(I) equiv;
+
+ /// Constructor.
+ proxy(I& ima, const mln_psite(I)& p);
+
+ /// Destructor.
+ ~proxy();
+
+ /// Assignment (write access); general version.
+ template <typename V>
+ proxy<I>& operator=(const V& v);
+
+ /// Assignment (write access); replacement for default op.
+ proxy<I>& operator=(const proxy<I>& rhs);
+
+ /// Assignment (write access); with other proxy.
+ template <typename II>
+ proxy<I>& operator=(const proxy<II>& rhs);
+
+ /// Convertion (read access); general version.
+ template <typename V>
+ operator V() const;
+
+ /// Convertion (read access); precise version.
+ operator mln_value(I)() const;
+
+ /// Explicit read access.
+ mln_value(I) to_value() const;
+
+ protected:
+ I& ima_;
+ mln_psite(I) p_;
+ };
+
+
+
+ /*! \brief Generic proxy class for an image pixel value.
+ *
+ * The parameter \c I is an image type.
+ */
+ template <typename I>
+ class proxy< const I > : public Value< proxy<const I> >
+ {
+ public:
+
+ /// Encoding associated type.
+ typedef void enc; // FIXME
+
+ /// Equivalent associated type.
+ typedef mln_value(I) equiv;
+
+ /// Constructor.
+ proxy(const I& ima, const mln_psite(I)& p);
+
+ /// Destructor.
+ ~proxy();
+
+ /// Convertion (read access); general version.
+ template <typename V>
+ operator V() const;
+
+ /// Convertion (read access); precise version.
+ operator mln_value(I)() const;
+
+ /// Explicit read access.
+ mln_value(I) to_value() const;
+
+ protected:
+ const I& ima_;
+ mln_psite(I) p_;
+ };
+
+
+
+ template <typename I>
+ bool operator=(const proxy<I>& lhs, const mln_value(I)& rhs);
+
+ template <typename I>
+ bool operator=(const mln_value(I)& lhs, const proxy<I>& rhs);
+
+ template <typename I, typename J>
+ bool operator=(const proxy<I>& lhs, const proxy<J>& rhs);
+
+
+ template <typename I>
+ bool operator<(const proxy<I>& lhs, const mln_value(I)& rhs);
+
+ template <typename I>
+ bool operator<(const mln_value(I)& lhs, const proxy<I>& rhs);
+
+ template <typename I, typename J>
+ bool operator<(const proxy<I>& lhs, const proxy<J>& rhs);
+
+
+ // FIXME: Ops such as +=, etc.
+
+
+
+ template <typename I>
+ struct props< proxy<I> > : public props< mln_value(I) >
+ {
+ // Contents is inherited.
+ };
+
+
+
+ /*! \brief Print a value proxy \p x into the output stream \p ostr.
+ *
+ * \param[in,out] ostr An output stream.
+ * \param[in] x A value proxy.
+ *
+ * \return The modified output stream \p ostr.
+ */
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const proxy<I>& x);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ // proxy<I>
+
+ template <typename I>
+ proxy<I>::proxy(I& ima, const mln_psite(I)& p)
+ : ima_(ima),
+ p_(p)
+ {
+ }
+
+ template <typename I>
+ proxy<I>::~proxy()
+ {
+ mln_value(I) (I::*mr)(const mln_psite(I)&) const = & I::read_;
+ mr = 0;
+ void (I::*mw)(const mln_psite(I)&, const mln_value(I)&) = & I::write_;
+ mw = 0;
+ }
+
+ template <typename I>
+ template <typename V>
+ proxy<I>&
+ proxy<I>::operator=(const V& v)
+ {
+ ima_.write_(p_, v);
+ return *this;
+ }
+
+ template <typename I>
+ proxy<I>&
+ proxy<I>::operator=(const proxy<I>& rhs)
+ {
+ this->operator=(rhs.to_value());
+ return *this;
+ }
+
+ template <typename I>
+ template <typename II>
+ proxy<I>&
+ proxy<I>::operator=(const proxy<II>& rhs)
+ {
+ this->operator=(rhs.to_value());
+ return *this;
+ }
+
+ template <typename I>
+ template <typename V>
+ proxy<I>::operator V() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ proxy<I>::operator mln_value(I)() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ mln_value(I)
+ proxy<I>::to_value() const
+ {
+ return ima_.read_(p_);
+ }
+
+ // proxy<const I>
+
+ template <typename I>
+ proxy<const I>::proxy(const I& ima, const mln_psite(I)& p)
+ : ima_(ima),
+ p_(p)
+ {
+ }
+
+ template <typename I>
+ proxy<const I>::~proxy()
+ {
+ mln_value(I) (I::*mr)(const mln_psite(I)&) const = & I::read_;
+ mr = 0;
+ }
+
+ template <typename I>
+ template <typename V>
+ proxy<const I>::operator V() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ proxy<const I>::operator mln_value(I)() const
+ {
+ return ima_.read_(p_);
+ }
+
+ template <typename I>
+ mln_value(I)
+ proxy<const I>::to_value() const
+ {
+ return ima_.read_(p_);
+ }
+
+ // operator <<
+
+ template <typename I>
+ std::ostream& operator<<(std::ostream& ostr, const proxy<I>& x)
+ {
+ return ostr << x.to_value();
+ }
+
+ // operator =
+
+ template <typename I>
+ bool operator=(const proxy<I>& lhs, const mln_value(I)& rhs)
+ {
+ return lhs.to_value() = rhs;
+ }
+
+ template <typename I>
+ bool operator=(const mln_value(I)& lhs, const proxy<I>& rhs)
+ {
+ return lhs = rhs.to_value();
+ }
+
+ template <typename I, typename J>
+ bool operator=(const proxy<I>& lhs, const proxy<J>& rhs)
+ {
+ return lhs.to_value() = rhs.to_value();
+ }
+
+ // operator <
+
+ template <typename I>
+ bool operator<(const proxy<I>& lhs, const mln_value(I)& rhs)
+ {
+ return lhs.to_value() < rhs;
+ }
+
+ template <typename I>
+ bool operator<(const mln_value(I)& lhs, const proxy<I>& rhs)
+ {
+ return lhs < rhs.to_value();
+ }
+
+ template <typename I, typename J>
+ bool operator<(const proxy<I>& lhs, const proxy<J>& rhs)
+ {
+ return lhs.to_value() < rhs.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::value
+
+} // end of namespace mln
+
+
+#endif // ! MLN_VALUE_INT_U_HH
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 1049)
+++ mln/value/stack.hh (working copy)
@@ -36,6 +36,7 @@
# include <mln/core/internal/image_base.hh>
# include <mln/metal/vec.hh>
# include <mln/value/set.hh>
+# include <mln/value/proxy.hh>
namespace mln
@@ -44,6 +45,37 @@
namespace value
{
+ // Fwd decl.
+ template <unsigned n, typename I> struct stack_image;
+
+
+ namespace internal
+ {
+
+ template <unsigned n, typename I>
+ struct helper_stack_image_lvalue_
+ {
+ typedef value::proxy< stack_image<n,I> > ret;
+ static ret make(stack_image<n,I>& ima, const mln_psite(I)& p)
+ {
+ ret tmp(ima, p);
+ return tmp;
+ }
+ };
+
+ template <unsigned n, typename I>
+ struct helper_stack_image_lvalue_< n, const I >
+ {
+ typedef metal::vec<n, mln_value(I)> ret;
+ static ret make(stack_image<n, const I>& ima, const mln_psite(I)& p)
+ {
+ return ima.read_(p);
+ }
+ };
+
+ } // end of namespace mln::value::internal
+
+
/*! \brief FIXME
*
*/
@@ -63,7 +95,7 @@
typedef value rvalue;
/// Return type of read-write access.
- typedef void lvalue; // FIXME
+ typedef typename internal::helper_stack_image_lvalue_<n,I>::ret lvalue;
/// Value set associated type.
typedef mln::value::set<value> vset;
@@ -84,9 +116,11 @@
/// Read-only access of pixel value at point site \p p.
rvalue operator()(const psite& p) const;
+ value read_(const psite& p) const;
/// Read-write access of pixel value at point site \p p.
- void operator()(const psite&);
+ lvalue operator()(const psite&);
+ void write_(const psite& p, const value& v);
/// Give the set of values of the image.
const vset& values() const;
@@ -107,20 +141,17 @@
template <typename I>
stack_image<2,const I>
- stack(const Image<I>& ima1, const Image<I>& ima2)
- {
- mln_precondition(exact(ima1).domain() = exact(ima2).domain());
- metal::vec<2, const I*> imas;
- imas[0] = & exact(ima1);
- imas[1] = & exact(ima2);
- stack_image<2, const I> tmp(imas);
- return tmp;
- }
+ stack(const Image<I>& ima1, const Image<I>& ima2);
+ template <typename I>
+ stack_image<2, I>
+ stack(Image<I>& ima1, Image<I>& ima2);
# ifndef MLN_INCLUDE_ONLY
+ // stack_image<n, I>
+
template <unsigned n, typename I>
stack_image<n,I>::stack_image(const metal::vec<n,I*>& imas)
: imas_(imas)
@@ -158,7 +189,7 @@
template <unsigned n, typename I>
metal::vec<n, mln_value(I)>
- stack_image<n,I>::operator()(const psite& p) const
+ stack_image<n,I>::read_(const psite& p) const
{
mln_precondition(this->owns_(p));
metal::vec<n, mln_value(I)> tmp;
@@ -168,10 +199,27 @@
}
template <unsigned n, typename I>
+ metal::vec<n, mln_value(I)>
+ stack_image<n,I>::operator()(const psite& p) const
+ {
+ return read_(p);
+ }
+
+ template <unsigned n, typename I>
void
- stack_image<n,I>::operator()(const psite&)
+ stack_image<n,I>::write_(const psite& p, const value& v)
+ {
+ mln_precondition(this->owns_(p));
+ // FIXME!!!
+ for (unsigned i = 0; i < n; ++i)
+ imas_[i]->operator()(p) = v[i];
+ }
+
+ template <unsigned n, typename I>
+ typename stack_image<n,I>::lvalue
+ stack_image<n,I>::operator()(const psite& p)
{
- mln_invariant(0); // FIXME: Turn into a compile-time error...
+ return internal::helper_stack_image_lvalue_<n,I>::make(*this, p);
}
template <unsigned n, typename I>
@@ -181,6 +229,32 @@
return vset::the();
}
+ // stack(..)
+
+ template <typename I>
+ stack_image<2, const I>
+ stack(const Image<I>& ima1, const Image<I>& ima2)
+ {
+ mln_precondition(exact(ima1).domain() = exact(ima2).domain());
+ metal::vec<2, const I*> imas;
+ imas[0] = & exact(ima1);
+ imas[1] = & exact(ima2);
+ stack_image<2, const I> tmp(imas);
+ return tmp;
+ }
+
+ template <typename I>
+ stack_image<2, I>
+ stack(Image<I>& ima1, Image<I>& ima2)
+ {
+ mln_precondition(exact(ima1).domain() = exact(ima2).domain());
+ metal::vec<2, I*> imas;
+ imas[0] = & exact(ima1);
+ imas[1] = & exact(ima2);
+ stack_image<2, I> tmp(imas);
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::value
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Handle const promotion for morphers.
* mln/core/internal/image_adaptor.hh (operator I): New.
(pset_): Remove; uncompatible with temporary pset.
(domain): Change sig.
* mln/core/inplace.hh: New.
* tests/line2d.cc: Augment; use inplace.
* mln/core/sub_image.hh: New.
* tests/sub_image.cc: New.
* mln/core/safe.hh (safe): New overload; const version.
(safe_image): Update.
(default_value): New.
(operator safe_image<const I>): New.
* tests/safe_image.cc: Augment.
* mln/core/queue_p.hh (push): Fix missing return.
* mln/core/internal/image_base.hh: Add doc.
* mln/core/pset_if_piter.hh (fixme): Remove include; useless.
* mln/core/vec_p_piter.hh: Likewise.
* mln/make/box2d: Change arg list (all min first).
* tests/to_image.cc: Update.
mln/core/image_if.hh | 10 ++
mln/core/inplace.hh | 63 ++++++++++++++++++
mln/core/internal/image_adaptor.hh | 19 +++--
mln/core/internal/image_base.hh | 27 +++++--
mln/core/pset_if_piter.hh | 1
mln/core/queue_p.hh | 1
mln/core/safe.hh | 62 +++++++++++++----
mln/core/sub_image.hh | 129 +++++++++++++++++++++++++++++++++++++
mln/core/vec_p_piter.hh | 1
mln/make/box2d.hh | 10 +-
tests/line2d.cc | 9 ++
tests/safe_image.cc | 30 +++++++-
tests/sub_image.cc | 53 +++++++++++++++
tests/to_image.cc | 4 -
14 files changed, 378 insertions(+), 41 deletions(-)
Index: tests/sub_image.cc
--- tests/sub_image.cc (revision 0)
+++ tests/sub_image.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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.
+
+/*! \file tests/sub_image.cc
+ *
+ * \brief Tests on mln::sub_image.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/inplace.hh>
+
+#include <mln/level/fill.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(8, 8);
+ level::fill(ima, 0);
+ debug::println(ima);
+
+ level::fill(inplace(ima | make::box2d(1,1, 3,3)), 5);
+ level::fill(inplace(ima | make::box2d(4,4, 6,6)), 1);
+
+ debug::println(ima);
+}
Index: tests/line2d.cc
--- tests/line2d.cc (revision 1048)
+++ tests/line2d.cc (working copy)
@@ -33,10 +33,13 @@
#include <iterator>
#include <mln/core/image2d_b.hh>
+#include <mln/core/sub_image.hh>
+#include <mln/core/inplace.hh>
#include <mln/level/fill.hh>
#include <mln/level/compare.hh>
#include <mln/draw/line.hh>
+#include <mln/debug/println.hh>
int main()
@@ -56,4 +59,10 @@
level::paste(pw::cst(true) | l, ima2);
mln_assertion(ima2 = ima);
+
+ image2d_b<bool> ima3(10,10);
+ level::fill(ima3, false);
+ level::fill(inplace(ima3 | l), true);
+
+ mln_assertion(ima3 = ima);
}
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1048)
+++ tests/to_image.cc (working copy)
@@ -47,9 +47,9 @@
{
using namespace mln;
- box2d box_3x3 = make::box2d(-1,+1, -1,+1);
+ box2d box_3x3 = make::box2d(-1,-1, +1,+1);
// ^^^^^ ^^^^^
- // rows cols
+ // from to
// center point
// V
Index: tests/safe_image.cc
--- tests/safe_image.cc (revision 1048)
+++ tests/safe_image.cc (working copy)
@@ -32,7 +32,6 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/safe.hh>
-#include <mln/level/paste.hh>
int main()
@@ -41,9 +40,30 @@
typedef image2d_b<int> I;
I ima(1, 1);
- safe_image<I> ima_ = safe(ima);
+ point2d
+ in = make::point2d(0, 0),
+ out = make::point2d(-999, -999);
+
+ {
+ safe_image<I> ima_ = safe(ima, 7);
+
+ ima_(in) = 51;
+ mln_assertion(ima_(in) = 51);
+
+ ima_(out) = 0;
+ mln_assertion(ima_(out) = 7);
+
+ // test "image_adaptor_<..>::operator I() const"
+ I ima2 = ima_;
+ const I ima3 = ima_;
+ }
+
+ {
+ safe_image<const I> ima_ = safe(ima, 7);
+
+ ima(in) = 51;
+ mln_assertion(ima_(in) = 51);
+ mln_assertion(ima_(out) = 7);
+ }
- point2d p = make::point2d(-5, -1);
- ima_(p) = 0;
- level::paste(ima, ima_);
}
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 1048)
+++ mln/core/image_if.hh (working copy)
@@ -66,6 +66,9 @@
typedef image_if<mln_ch_value(I,T), F> ret;
};
+ /// Const promotion via convertion.
+ operator image_if<const I, F>() const;
+
protected:
pset pset_;
@@ -110,6 +113,13 @@
return pset_;
}
+ template <typename I, typename F>
+ image_if<I,F>::operator image_if<const I, F>() const
+ {
+ image_if<const I, F> tmp(this->adaptee_, this->f_);
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 1048)
+++ mln/core/queue_p.hh (working copy)
@@ -196,6 +196,7 @@
vect_needs_update_ = true;
bb_needs_update_ = true;
}
+ return *this;
}
template <typename P>
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1048)
+++ mln/core/safe.hh (working copy)
@@ -37,14 +37,17 @@
// FIXME: Doc!
template <typename I>
- struct safe_image : public internal::image_adaptor_< I, safe_image<I> >
+ class safe_image : public internal::image_adaptor_< I, safe_image<I> >
{
- typedef internal::image_adaptor_< I, safe_image<I> > super;
+ typedef internal::image_adaptor_< I, safe_image<I> > super_;
+ public:
- safe_image(Image<I>& ima);
+ safe_image(I& ima, const mln_value(I)& default_value);
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
- mln_lvalue(I) operator()(const mln_psite(I)& p);
+
+ typedef typename super_::lvalue lvalue;
+ lvalue operator()(const mln_psite(I)& p);
template <typename U>
struct change_value
@@ -52,20 +55,33 @@
typedef safe_image<mln_ch_value(I, U)> ret;
};
+ /// Const promotion via convertion.
+ operator safe_image<const I>() const;
+
+ protected:
+ mln_value(I) default_value_;
};
template <typename I>
- safe_image<I> safe(Image<I>& ima);
+ safe_image<I> safe(Image<I>& ima,
+ mln_value(I) default_value = mln_value(I)());
+
+ template <typename I>
+ safe_image<const I> safe(const Image<I>& ima,
+ mln_value(I) default_value = mln_value(I)());
# ifndef MLN_INCLUDE_ONLY
+ // safe_image<I>
+
template <typename I>
- safe_image<I>::safe_image(Image<I>& ima)
- : super(exact(ima))
+ safe_image<I>::safe_image(I& ima, const mln_value(I)& default_value)
+ : super_(exact(ima)),
+ default_value_(default_value)
{
}
@@ -73,26 +89,44 @@
mln_rvalue(I)
safe_image<I>::operator()(const mln_psite(I)& p) const
{
- static mln_value(I) tmp;
if (! this->owns_(p))
- return tmp;
+ return default_value_;
return this->adaptee_(p);
}
template <typename I>
- mln_lvalue(I)
+ typename safe_image<I>::lvalue
safe_image<I>::operator()(const mln_psite(I)& p)
{
- static mln_value(I) tmp;
+ static mln_value(I) forget_it_;
if (! this->owns_(p))
- return tmp;
+ // so default_value_ is returned but cannot be modified
+ return forget_it_ = default_value_;
return this->adaptee_(p);
}
template <typename I>
- safe_image<I> safe(Image<I>& ima)
+ safe_image<I>::operator safe_image<const I>() const
+ {
+ safe_image<const I> tmp(this->adaptee_, default_value_);
+ return tmp;
+ }
+
+ // safe
+
+ template <typename I>
+ safe_image<I> safe(Image<I>& ima,
+ mln_value(I) default_value)
+ {
+ safe_image<I> tmp(exact(ima), default_value);
+ return tmp;
+ }
+
+ template <typename I>
+ safe_image<const I> safe(const Image<I>& ima,
+ mln_value(I) default_value)
{
- safe_image<I> tmp(ima);
+ safe_image<const I> tmp(exact(ima), default_value);
return tmp;
}
Index: mln/core/internal/image_adaptor.hh
--- mln/core/internal/image_adaptor.hh (revision 1048)
+++ mln/core/internal/image_adaptor.hh (working copy)
@@ -78,7 +78,7 @@
bool owns_(const psite& p) const;
/// Give the definition domain.
- const S& domain() const;
+ const mln_pset(I)& domain() const;
/// Give the set of values.
const vset& values() const;
@@ -89,6 +89,8 @@
/// Read-write access of pixel value at point site \p p.
lvalue operator()(const psite& p);
+ /// Convertion to the underlying (adapted) image.
+ operator I() const;
protected:
I& adaptee_;
@@ -97,13 +99,17 @@
image_adaptor_(I& adaptee);
};
- // FIXME: image_const_adaptor_
-
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename E, typename S>
+ image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
+ : adaptee_(adaptee)
+ {
+ }
+
+ template <typename I, typename E, typename S>
bool image_adaptor_<I,E,S>::has_data() const
{
return adaptee_.has_data();
@@ -117,7 +123,7 @@
}
template <typename I, typename E, typename S>
- const S&
+ const mln_pset(I)&
image_adaptor_<I,E,S>::domain() const
{
mln_precondition(exact(this)->has_data());
@@ -148,9 +154,10 @@
}
template <typename I, typename E, typename S>
- image_adaptor_<I,E,S>::image_adaptor_(I& adaptee)
- : adaptee_(adaptee)
+ image_adaptor_<I,E,S>::operator I() const
{
+ mln_precondition(exact(this)->has_data());
+ return adaptee_;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/core/internal/image_base.hh
--- mln/core/internal/image_base.hh (revision 1048)
+++ mln/core/internal/image_base.hh (working copy)
@@ -43,6 +43,11 @@
{
+ /*! \brief Return the lvalue type when an image with type \c I is
+ * morphed.
+ *
+ * \internal
+ */
template <typename I>
struct morpher_lvalue_
{
@@ -56,7 +61,10 @@
};
-
+ /*! \brief Selector for image inheritance (fast or regular).
+ *
+ * \internal
+ */
template <typename Is_fast, typename E>
struct select_image_concept_;
@@ -77,7 +85,9 @@
* \internal
*/
template <typename S, typename E>
- struct image_base_ : public select_image_concept_< typename trait::is_fast<E>::ret,
+ struct image_base_
+
+ : public select_image_concept_< typename trait::is_fast<E>::ret,
E >
{
/// Point_Set associated type.
@@ -113,6 +123,9 @@
/// Give the number of points of the image domain.
std::size_t npoints() const;
+
+ // FIXME: Add owns_(p) based on has(p)?
+
protected:
image_base_();
};
@@ -121,6 +134,11 @@
# ifndef MLN_INCLUDE_ONLY
template <typename S, typename E>
+ image_base_<S,E>::image_base_()
+ {
+ }
+
+ template <typename S, typename E>
bool
image_base_<S,E>::has(const psite& p) const
{
@@ -144,11 +162,6 @@
return exact(this)->domain().npoints();
}
- template <typename S, typename E>
- image_base_<S,E>::image_base_()
- {
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
Index: mln/core/sub_image.hh
--- mln/core/sub_image.hh (revision 0)
+++ mln/core/sub_image.hh (revision 0)
@@ -0,0 +1,129 @@
+// 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 MLN_CORE_SUB_IMAGE_HH
+# define MLN_CORE_SUB_IMAGE_HH
+
+# include <mln/core/internal/image_adaptor.hh>
+
+
+namespace mln
+{
+
+ // FIXME: Doc!
+
+ template <typename I, typename S>
+ class sub_image : public internal::image_adaptor_< I,
+ sub_image<I,S>,
+ S >
+ {
+ typedef internal::image_adaptor_<I, sub_image<I,S>, S> super_;
+ public:
+
+ sub_image(I& ima, const S& pset);
+
+ bool owns_(const mln_psite(I)& p) const;
+
+ template <typename U>
+ struct change_value
+ {
+ typedef internal::fixme ret;
+ };
+
+ const S& domain() const;
+
+ /// Const promotion via convertion.
+ operator sub_image<const I, S>() const;
+
+ protected:
+ const S& pset_;
+ };
+
+
+
+ template <typename I, typename S>
+ sub_image<const I, S> operator|(const Image<I>& ima, const Point_Set<S>& pset);
+
+ template <typename I, typename S>
+ sub_image<I, S> operator|(Image<I>& ima, const Point_Set<S>& pset);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename S>
+ sub_image<I,S>::sub_image(I& ima, const S& pset)
+ : super_(ima),
+ pset_(pset)
+ {
+ }
+
+ template <typename I, typename S>
+ bool
+ sub_image<I,S>::owns_(const mln_psite(I)& p) const
+ {
+ return this->domain().has(p);
+ }
+
+ template <typename I, typename S>
+ const S&
+ sub_image<I,S>::domain() const
+ {
+ return pset_;
+ }
+
+ template <typename I, typename S>
+ sub_image<I,S>::operator sub_image<const I, S>() const
+ {
+ sub_image<const I, S> tmp(this->adaptee_, this->pset_);
+ return tmp;
+ }
+
+ // operator
+
+ template <typename I, typename S>
+ sub_image<const I, S>
+ operator|(const Image<I>& ima, const Point_Set<S>& pset)
+ {
+ sub_image<const I, S> tmp(exact(ima), exact(pset));
+ return tmp;
+ }
+
+ template <typename I, typename S>
+ sub_image<I, S>
+ operator|(Image<I>& ima, const Point_Set<S>& pset)
+ {
+ sub_image<I, S> tmp(exact(ima), exact(pset));
+ return tmp;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SUB_IMAGE_HH
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 1048)
+++ mln/core/pset_if_piter.hh (working copy)
@@ -35,7 +35,6 @@
# include <mln/core/concept/point_iterator.hh>
# include <mln/core/internal/piter_adaptor.hh>
-# include <mln/core/internal/fixme.hh>
# include <mln/core/pset_if.hh>
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 1048)
+++ mln/core/vec_p_piter.hh (working copy)
@@ -34,7 +34,6 @@
*/
# include <mln/core/vec_p.hh>
-# include <mln/core/internal/fixme.hh>
namespace mln
Index: mln/core/inplace.hh
--- mln/core/inplace.hh (revision 0)
+++ mln/core/inplace.hh (revision 0)
@@ -0,0 +1,63 @@
+// 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 MLN_CORE_INPLACE_HH
+# define MLN_CORE_INPLACE_HH
+
+/*! \file mln/core/inplace.hh
+ * \brief Definition of the mln::inplace routine.
+ */
+
+# include <mln/core/exact.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Routine to make temporary objects become mutable.
+ *
+ * \warning This routine is not safe! FIXME: Explain.
+ */
+ template <typename E>
+ E& inplace(const Object<E>& temp);
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename E>
+ E& inplace(const Object<E>& temp)
+ {
+ return const_cast<E&>( exact(temp) );
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INPLACE_HH
Index: mln/make/box2d.hh
--- mln/make/box2d.hh (revision 1048)
+++ mln/make/box2d.hh (working copy)
@@ -60,16 +60,16 @@
* \overload
*
* \param[in] min_row Index of the top most row.
- * \param[in] max_row Index of the botton most row.
* \param[in] min_col Index of the left most column.
+ * \param[in] max_row Index of the botton most row.
* \param[in] max_col Index of the right most column.
*
* \pre \p max_row >= \p min_row and \p max_col >= \p min_col.
*
* \return A 2D box.
*/
- mln::box2d box2d(int min_row, int max_row,
- int min_col, int max_col);
+ mln::box2d box2d(int min_row, int min_col,
+ int max_row, int max_col);
# ifndef MLN_INCLUDE_ONLY
@@ -82,8 +82,8 @@
return tmp;
}
- mln::box2d box2d(int min_row, int max_row,
- int min_col, int max_col)
+ mln::box2d box2d(int min_row, int min_col,
+ int max_row, int max_col)
{
mln_precondition(max_row >= min_row && max_col >= min_col);
mln::box2d tmp(make::point2d(min_row, min_col),
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Renaming.
* mln/core/fimage.hh,
* tests/fimage.cc: Rename as...
* mln/pw/image.hh,
* tests/pw_image.cc: ...these.
* mln/pw/all.hh,
* mln/draw/line.hh,
* tests/line2d.cc: Update.
* mln/core/pqueue.hh,
* mln/core/pvec.hh,
* mln/core/pvec_piter.hh,
* mln/core/pset.hh,
* tests/pqueue.cc,
* tests/pset.cc: Rename as...
* mln/core/queue_p.hh,
* mln/core/vec_p.hh,
* mln/core/vec_p_piter.hh,
* mln/core/set_p.hh,
* tests/queue_p.cc,
* tests/set_p.cc: ...these.
* mln/core/line2d.hh: Update.
* mln/core/psubset.hh,
* mln/core/psubset_piter.hh,
* mln/core/subimage.hh,
* tests/psubset.cc,
* tests/subimage.cc: Rename as...
* mln/core/pset_if.hh,
* mln/core/pset_if_piter.hh,
* mln/core/image_if.hh,
* tests/pset_if.cc,
* tests/image_if.cc: ...these.
* tests/to_image.cc: Update.
* mln/accu/counter.hh: Rename as...
* mln/accu/count.hh: ...this.
* mln/accu/count.hh,
* mln/accu/mean.hh,
* mln/accu/sum.hh (operator+=): New.
* mln/value/props.hh (mln_sum, sum): New.
* mln/accu/mean.hh,
* mln/accu/sum.hh,
* mln/value/int_u.hh,
* mln/value/int_s.hh: Update.
* mln/level/apply.hh: Move accumulator version into...
* mln/level/take.hh: ...this new file.
* mln/level/run.hh: New.
* mln/estim/mean.hh: Update.
* mln/core/internal/set_of.hh (operator=): Remove;
too error-prone.
* mln/core/concept/window.hh (operator=): New.
* tests/rectangle2d.cc: Fix.
mln/accu/count.hh | 119 ++++++++++++++++++++
mln/accu/mean.hh | 26 +++-
mln/accu/sum.hh | 19 ++-
mln/core/concept/window.hh | 28 ++++
mln/core/image_if.hh | 118 ++++++++++++++++++++
mln/core/internal/set_of.hh | 22 ---
mln/core/line2d.hh | 6 -
mln/core/pset_if.hh | 191 +++++++++++++++++++++++++++++++++
mln/core/pset_if_piter.hh | 125 +++++++++++++++++++++
mln/core/queue_p.hh | 253 ++++++++++++++++++++++++++++++++++++++++++++
mln/core/set_p.hh | 162 ++++++++++++++++++++++++++++
mln/core/vec_p.hh | 208 ++++++++++++++++++++++++++++++++++++
mln/core/vec_p_piter.hh | 172 +++++++++++++++++++++++++++++
mln/draw/line.hh | 30 +----
mln/estim/mean.hh | 28 +---
mln/level/apply.hh | 51 ++++----
mln/level/run.hh | 79 +++++++++++++
mln/level/take.hh | 102 +++++++++++++++++
mln/pw/all.hh | 1
mln/pw/image.hh | 192 +++++++++++++++++++++++++++++++++
mln/value/int_s.hh | 1
mln/value/int_u.hh | 1
mln/value/props.hh | 13 ++
tests/image_if.cc | 46 ++++++++
tests/line2d.cc | 7 -
tests/mean.cc | 53 +++++++++
tests/pset_if.cc | 45 +++++++
tests/pw_image.cc | 44 +++++++
tests/queue_p.cc | 57 +++++++++
tests/rectangle2d.cc | 2
tests/set_p.cc | 59 ++++++++++
tests/to_image.cc | 2
32 files changed, 2152 insertions(+), 110 deletions(-)
Index: tests/set_p.cc
--- tests/set_p.cc (revision 0)
+++ tests/set_p.cc (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.
+
+/*! \file tests/set_p.cc
+ *
+ * \brief Tests on mln::set_p.
+ */
+
+#include <iterator>
+
+#include <mln/core/point2d.hh>
+#include <mln/core/set_p.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ set_p<point2d> ps;
+ ps
+ .insert(make::point2d(6, 9))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(4, 2))
+ .insert(make::point2d(5, 1));
+ mln_assertion(ps.npoints() = 3);
+
+ std::cout << ps.bbox() << std::endl;
+
+ std::copy(ps.vect().begin(), ps.vect().end(),
+ std::ostream_iterator<point2d>(std::cout, " "));
+ std::cout << std::endl;
+
+
+}
Index: tests/line2d.cc
--- tests/line2d.cc (revision 1047)
+++ tests/line2d.cc (working copy)
@@ -35,13 +35,8 @@
#include <mln/core/image2d_b.hh>
#include <mln/level/fill.hh>
-#include <mln/draw/line.hh>
-#include <mln/debug/println.hh>
-
-#include <mln/core/fimage.hh>
-#include <mln/pw/cst.hh>
-#include <mln/level/paste.hh>
#include <mln/level/compare.hh>
+#include <mln/draw/line.hh>
int main()
Index: tests/mean.cc
--- tests/mean.cc (revision 0)
+++ tests/mean.cc (revision 0)
@@ -0,0 +1,53 @@
+// 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.
+
+/*! \file tests/assign.cc
+ *
+ * \brief Tests on mln::level::assign.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/value/int_u8.hh>
+
+#include <mln/debug/iota.hh>
+#include <mln/estim/mean.hh>
+
+
+int main()
+{
+ using namespace mln;
+ using value::int_u8;
+
+ image2d_b<int_u8> ima(3, 3);
+ debug::iota(ima);
+ // 1 2 3
+ // 4 5 6
+ // 7 8 9
+ mln_assertion(estim::mean(ima) = 5);
+
+ // FIXME: Add example on accu::mean used several times.
+}
Index: tests/to_image.cc
--- tests/to_image.cc (revision 1047)
+++ tests/to_image.cc (working copy)
@@ -32,7 +32,7 @@
#include <mln/core/image2d_b.hh>
#include <mln/core/window2d.hh>
-#include <mln/core/psubset.hh>
+#include <mln/core/pset_if.hh>
#include <mln/fun/p2b/chess.hh>
#include <mln/level/compare.hh>
Index: tests/pw_image.cc
--- tests/pw_image.cc (revision 0)
+++ tests/pw_image.cc (revision 0)
@@ -0,0 +1,44 @@
+// 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.
+
+/*! \file tests/fimage.cc
+ *
+ * \brief Tests on mln::fimage.
+ */
+
+#include <mln/fun/p2b/chess.hh>
+#include <mln/core/box2d.hh>
+#include <mln/pw/image.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ debug::println( fun::p2b::chess | make::box2d(8, 8) );
+}
Index: tests/rectangle2d.cc
--- tests/rectangle2d.cc (revision 1047)
+++ tests/rectangle2d.cc (working copy)
@@ -44,6 +44,6 @@
mln_assertion(rec.is_centered());
mln_assertion(rec.is_symmetric());
mln_assertion(rec = -rec);
- mln_assertion(rec.nelements() = h * w);
+ mln_assertion(rec.ndpoints() = h * w);
}
Index: tests/image_if.cc
--- tests/image_if.cc (revision 0)
+++ tests/image_if.cc (revision 0)
@@ -0,0 +1,46 @@
+// 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.
+
+/*! \file tests/image_if.cc
+ *
+ * \brief Tests on mln::image_if.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/image_if.hh>
+#include <mln/fun/p2b/chess.hh>
+#include <mln/debug/println.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ image2d_b<int> ima(8, 8);
+ // debug::println(ima | fun::p2b::chess);
+ mln_assertion((ima | fun::p2b::chess).npoints() = 32);
+}
Index: tests/queue_p.cc
--- tests/queue_p.cc (revision 0)
+++ tests/queue_p.cc (revision 0)
@@ -0,0 +1,57 @@
+// 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.
+
+/*! \file tests/queue_p.cc
+ *
+ * \brief Tests on mln::queue_p.
+ */
+
+#include <mln/core/point2d.hh>
+#include <mln/core/queue_p.hh>
+
+
+
+int main()
+{
+ using namespace mln;
+
+ queue_p<point2d> q;
+ q
+ .push(make::point2d(6, 9))
+ .push(make::point2d(5, 1))
+ .push(make::point2d(4, 2));
+ mln_assertion(q.npoints() = 3);
+
+ std::cout << q.bbox() << std::endl;
+ std::cout << q << std::endl;
+
+ q.pop();
+ mln_assertion(q.npoints() = 2);
+ point2d p = q.front();
+ mln_assertion(q.npoints() = 2);
+ mln_assertion(p = make::point2d(5, 1));
+}
Index: tests/pset_if.cc
--- tests/pset_if.cc (revision 0)
+++ tests/pset_if.cc (revision 0)
@@ -0,0 +1,45 @@
+// 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.
+
+/*! \file tests/pset_if.cc
+ *
+ * \brief Tests on mln::pset_if.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/core/pset_if.hh>
+#include <mln/fun/p2b/chess.hh>
+#include <mln/convert/to_image.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ box2d box_8x8 = make::box2d(8, 8);
+ mln_assertion((box_8x8 | fun::p2b::chess).npoints() = 32);
+}
Index: mln/estim/mean.hh
--- mln/estim/mean.hh (revision 1047)
+++ mln/estim/mean.hh (working copy)
@@ -33,8 +33,8 @@
* \brief Compute the mean pixel value.
*/
-# include <mln/core/concept/image.hh>
# include <mln/accu/mean.hh>
+# include <mln/level/run.hh>
namespace mln
@@ -43,32 +43,22 @@
namespace estim
{
-
/*! \brief Compute the mean value of the pixels of image \p input.
*
- * Parameter \c S is the type of the mean value.
+ * \param[in] input The image.
*/
- template <typename S, typename I>
- S mean(const Image<I>& input);
-
+ template <typename I>
+ mln_sum(mln_value(I)) mean(const Image<I>& input);
# ifndef MLN_INCLUDE_ONLY
- template <typename S, typename I>
- S
- mean(const Image<I>& input_)
+ template <typename I>
+ mln_sum(mln_value(I)) mean(const Image<I>& input)
{
- const I& input = exact(input_);
- mln_precondition(input.has_data());
-
- accu::mean<mln_value(I), S> m;
-
- mln_piter(I) p(input.domain());
- for_all(p)
- m.take(input(p));
-
- return m;
+ typedef mln_value(I) V;
+ typedef mln_sum(V) S;
+ return level::run(input, accu::mean<V, S>());
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 0)
+++ mln/pw/image.hh (revision 0)
@@ -0,0 +1,192 @@
+// 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 MLN_PW_IMAGE_HH
+# define MLN_PW_IMAGE_HH
+
+/*! \file mln/pw/image.hh
+ *
+ * \brief Definition of an image class FIXME
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/core/concept/function.hh>
+# include <mln/value/set.hh>
+
+
+namespace mln
+{
+
+ // Fwd decl.
+ namespace pw { template <typename F, typename S> struct image; }
+
+
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename F, typename S>
+ pw::image<F,S>
+ operator | (const Function_p2v<F>& f, const Point_Set<S>& ps);
+
+
+
+ namespace pw
+ {
+
+ /*! \brief FIXME
+ *
+ */
+ template <typename F, typename S>
+ struct image : public internal::image_base_< S, image<F,S> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point_Set associated type.
+ typedef S pset;
+
+ /// Value associated type.
+ typedef mln_result(F) value;
+
+ /// Return type of read-only access.
+ typedef mln_result(F) rvalue;
+
+ /// Return type of read-write access.
+ typedef void lvalue; // FIXME
+
+ /// Value set associated type.
+ typedef mln::value::set<mln_result(F)> vset;
+
+
+ /// Constructor.
+ image(const Function_p2v<F>& f, const Point_Set<S>& ps);
+
+
+ /// Test if this image has been initialized.
+ bool has_data() const;
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const psite& p) const;
+
+ /// Give the definition domain.
+ const S& domain() const;
+
+ /// Read-only access of pixel value at point site \p p.
+ mln_result(F) operator()(const psite& p) const;
+
+ /// Read-write access is present but disabled.
+ void operator()(const psite&);
+
+ /// Give the set of values of the image.
+ const vset& values() const;
+
+ /// Change value type. FIXME!
+ template <typename U>
+ struct change_value
+ {
+ typedef void ret;
+ };
+
+ protected:
+ F f_;
+ S pset_;
+ };
+
+ } // end of namespace mln::pw
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename F, typename S>
+ pw::image<F,S>
+ operator | (const Function_p2v<F>& f, const Point_Set<S>& ps)
+ {
+ pw::image<F,S> tmp(f, ps);
+ return tmp;
+ }
+
+ namespace pw
+ {
+
+ template <typename F, typename S>
+ image<F,S>::image(const Function_p2v<F>& f, const Point_Set<S>& ps)
+ : f_(exact(f)),
+ pset_(exact(ps))
+ {
+ }
+
+ template <typename F, typename S>
+ bool image<F,S>::has_data() const
+ {
+ return true;
+ }
+
+ template <typename F, typename S>
+ bool image<F,S>::owns_(const psite& p) const
+ {
+ return pset_.has(p);
+ }
+
+ template <typename F, typename S>
+ const S&
+ image<F,S>::domain() const
+ {
+ return pset_;
+ }
+
+ template <typename F, typename S>
+ mln_result(F)
+ image<F,S>::operator()(const psite& p) const
+ {
+ mln_precondition(pset_.has(p));
+ return f_(p);
+ }
+
+ template <typename F, typename S>
+ void
+ image<F,S>::operator()(const psite&)
+ {
+ mln_invariant(0); // FIXME: Turn into a compile-time error...
+ }
+
+ template <typename F, typename S>
+ const mln::value::set<mln_result(F)>&
+ image<F,S>::values() const
+ {
+ return vset::the();
+ }
+
+ } // end of namespace mln::pw
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_PW_IMAGE_HH
Index: mln/pw/all.hh
--- mln/pw/all.hh (revision 1047)
+++ mln/pw/all.hh (working copy)
@@ -47,6 +47,7 @@
# include <mln/pw/value.hh>
# include <mln/pw/cst.hh>
# include <mln/pw/var.hh>
+# include <mln/pw/image.hh>
# include <mln/fun/ops.hh>
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 0)
+++ mln/core/image_if.hh (revision 0)
@@ -0,0 +1,118 @@
+// 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 MLN_CORE_IMAGE_IF_HH
+# define MLN_CORE_IMAGE_IF_HH
+
+/*! \file mln/core/image_if.hh
+ *
+ * \brief Definition of a base class for image adaptors.
+ */
+
+# include <mln/core/internal/image_adaptor.hh>
+# include <mln/core/pset_if.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A base class for image adaptors.
+ *
+ */
+ template <typename I, typename F>
+ struct image_if : public internal::image_adaptor_< I,
+ image_if<I,F>,
+ pset_if<mln_pset(I),F> >
+ {
+ /// Point_Set associated type.
+ typedef pset_if<mln_pset(I), F> pset;
+
+ /// Constructor from an \p adaptee image.
+ image_if(I& adaptee, const F& f);
+
+ /// Test if a pixel value is accessible at \p p.
+ bool owns_(const mln_psite(I)& p) const;
+
+ /// Give the definition domain.
+ const pset& domain() const;
+
+ template <typename T>
+ struct change_value
+ {
+ typedef image_if<mln_ch_value(I,T), F> ret;
+ };
+
+ protected:
+
+ pset pset_;
+ F f_;
+
+ typedef image_if<I,F> self_;
+ typedef internal::image_adaptor_< I, self_, pset > super_;
+ };
+
+
+
+ template <typename I, typename F>
+ image_if<I, F>
+ operator | (Image<I>& ima, const Function_p2b<F>& f)
+ {
+ image_if<I, F> tmp(exact(ima), exact(f));
+ return tmp;
+ }
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename F>
+ image_if<I,F>::image_if(I& adaptee, const F& f)
+ : super_(adaptee),
+ pset_(adaptee.domain() | f),
+ f_(f)
+ {
+ }
+
+ template <typename I, typename F>
+ bool
+ image_if<I,F>::owns_(const mln_psite(I)& p) const
+ {
+ return pset_.has(p);
+ }
+
+ template <typename I, typename F>
+ const pset_if<mln_pset(I), F>&
+ image_if<I,F>::domain() const
+ {
+ return pset_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_IMAGE_IF_HH
Index: mln/core/queue_p.hh
--- mln/core/queue_p.hh (revision 0)
+++ mln/core/queue_p.hh (revision 0)
@@ -0,0 +1,253 @@
+// 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 MLN_CORE_QUEUE_P_HH
+# define MLN_CORE_QUEUE_P_HH
+
+/*! \file mln/core/queue_p.hh
+ *
+ * \brief Definition of a point set class based on std::deque.
+ */
+
+# include <vector>
+# include <deque>
+# include <algorithm>
+# include <iterator>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/vec_p_piter.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point queue class (based on std::deque).
+ *
+ * This is a mathematical set of points (unique insertion).
+ *
+ * \todo Make it work with P being a Point_Site.
+ * \todo Add a parameter flag to choose another policy for "push"
+ * (i.e., no-op if multiple or allow multiple insertions).
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints() when this container is multiple.
+ */
+ template <typename P>
+ class queue_p : public Point_Set< queue_p<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ queue_p();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Push a point \p p in the queue.
+ queue_p<P>& push(const P& p);
+
+ /// Pop (remove) the front point \p p from the queue; \p p is the
+ /// least recently inserted point.
+ void pop();
+
+ /// Give the front point \p p of the queue; \p p is the least
+ /// recently inserted point.
+ const P& front() const;
+
+ /// Clear the queue.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::deque<P> q_;
+
+ mutable std::vector<P> vect_;
+ mutable bool vect_needs_update_;
+ void vect_update_() const;
+
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+ void bb_update_() const;
+
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ queue_p<P>::queue_p()
+ {
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::vect_update_() const
+ {
+ vect_.clear();
+ vect_.reserve(q_.size());
+ std::copy(q_.begin(), q_.end(),
+ std::back_inserter(vect_));
+ vect_needs_update_ = false;
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::bb_update_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < q_.size(); ++i)
+ bb_.take(q_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ queue_p<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < q_.size(); ++i)
+ if (q_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ queue_p<P>::npoints() const
+ {
+ return q_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ queue_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ bb_update_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ queue_p<P>&
+ queue_p<P>::push(const P& p)
+ {
+ mln_precondition(! has(p));
+ // FIXME: Our choice is "error if multiple insertions"
+ q_.push_back(p);
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::pop()
+ {
+ q_.pop_front();
+ if (! vect_needs_update_)
+ {
+ vect_needs_update_ = true;
+ bb_needs_update_ = true;
+ }
+ }
+
+ template <typename P>
+ const P&
+ queue_p<P>::front() const
+ {
+ mln_precondition(! q_.empty());
+ return q_.front();
+ }
+
+ template <typename P>
+ void
+ queue_p<P>::clear()
+ {
+ q_.clear();
+ vect_.clear();
+ vect_needs_update_ = false;
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ queue_p<P>::vect() const
+ {
+ if (vect_needs_update_)
+ vect_update_();
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ queue_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return q_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_QUEUE_P_HH
Index: mln/core/internal/set_of.hh
--- mln/core/internal/set_of.hh (revision 1047)
+++ mln/core/internal/set_of.hh (working copy)
@@ -173,16 +173,6 @@
std::ostream& operator<<(std::ostream& ostr, const set_of_<E>& s);
- /*! \brief Test if both sets \p lhs and \p rhs are equal.
- *
- * \param[in] lhs A set.
- * \param[in] rhs Another set.
- *
- * \relates mln::internal::set_of_
- */
- template <typename E>
- bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs);
-
# ifndef MLN_INCLUDE_ONLY
@@ -279,18 +269,6 @@
return ostr;
}
- template <typename E>
- bool operator=(const set_of_<E>& lhs, const set_of_<E>& rhs)
- {
- if (lhs.nelements() != rhs.nelements())
- return false;
- const unsigned n = lhs.nelements();
- for (unsigned i = 0; i < n; ++i)
- if (rhs.element(i) != lhs.element(i))
- return false;
- return true;
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::internal
Index: mln/core/pset_if.hh
--- mln/core/pset_if.hh (revision 0)
+++ mln/core/pset_if.hh (revision 0)
@@ -0,0 +1,191 @@
+// 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 MLN_CORE_PSET_IF_HH
+# define MLN_CORE_PSET_IF_HH
+
+/*! \file mln/core/pset_if.hh
+ *
+ * \brief Definition of the restriction of a point set w.r.t. a predicate.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/concept/function.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename S, typename F> struct pset_if;
+ template <typename S, typename F> struct pset_if_fwd_piter_;
+ template <typename S, typename F> struct pset_if_bkd_piter_;
+
+
+
+ /*! \brief Restrict a point set \p pset to points that verify \p f.
+ *
+ * \param[in] pset A point set.
+ * \param[in] f A function from point to Boolean.
+ * \return A subset of points.
+ */
+ template <typename S, typename F>
+ pset_if<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f);
+
+
+
+ /*! \brief Generic subset class.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ */
+ template <typename S, typename F>
+ struct pset_if : public Point_Set< pset_if<S,F> >
+ {
+ /// Point_Site associated type.
+ typedef mln_psite(S) psite;
+
+ /// Point associated type.
+ typedef mln_point(S) point;
+
+
+ /// Forward Point_Iterator associated type.
+ typedef pset_if_fwd_piter_<S,F> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef internal::fixme bkd_piter;
+
+
+ /// Constructor without argument.
+ pset_if(const S& pset, const F& f);
+
+
+ /// Test if \p p belongs to the subset.
+ bool has(const psite& p) const;
+
+ /// Give a bounding box of the subset.
+ const box_<point>& bbox() const;
+
+ /// Give the number of points of the subset.
+ std::size_t npoints() const;
+
+ /// Give the primary overset.
+ const S& overset() const;
+
+ /// Test predicate on point site \p p.
+ bool pred(const psite& p) const;
+
+ protected:
+
+ const S& pset_;
+ F f_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ template <typename S, typename F>
+ pset_if<S, F>
+ operator | (const Point_Set<S>& pset, const Function_p2b<F>& f)
+ {
+ pset_if<S, F> tmp(exact(pset), exact(f));
+ return tmp;
+ }
+
+
+ // pset_if<S,F>
+
+ template <typename S, typename F>
+ bool
+ pset_if<S,F>::has(const psite& p) const
+ {
+ return pset_.has(p) && f_(p);
+ }
+
+ template <typename S, typename F>
+ const box_<mln_point(S)>&
+ pset_if<S,F>::bbox() const
+ {
+ return pset_.bbox();
+ }
+
+ template <typename S, typename F>
+ const S&
+ pset_if<S,F>::overset() const
+ {
+ return pset_;
+ }
+
+ template <typename S, typename F>
+ bool
+ pset_if<S,F>::pred(const psite& p) const
+ {
+ return f_(p);
+ }
+
+ template <typename S, typename F>
+ pset_if<S,F>::pset_if(const S& pset, const F& f)
+ : pset_(pset),
+ f_(f)
+ {
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+
+# include <mln/core/pset_if_piter.hh>
+
+
+
+namespace mln
+{
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename S, typename F>
+ std::size_t
+ pset_if<S,F>::npoints() const
+ {
+ std::size_t n = 0;
+ fwd_piter p(*this);
+ for_all(p)
+ ++n;
+ return n;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_IF_HH
Index: mln/core/pset_if_piter.hh
--- mln/core/pset_if_piter.hh (revision 0)
+++ mln/core/pset_if_piter.hh (revision 0)
@@ -0,0 +1,125 @@
+// 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 MLN_CORE_PSET_IF_PITER_HH
+# define MLN_CORE_PSET_IF_PITER_HH
+
+/*! \file mln/core/pset_if_piter.hh
+ *
+ * \brief Definition of iterators on points of pset_ifes.
+ */
+
+# include <mln/core/concept/point_iterator.hh>
+# include <mln/core/internal/piter_adaptor.hh>
+# include <mln/core/internal/fixme.hh>
+# include <mln/core/pset_if.hh>
+
+
+namespace mln
+{
+
+ /*! \brief A generic forward iterator on points of subsets.
+ *
+ * Parameter \c S is a point set type; parameter F is a function
+ * from point to Boolean.
+ *
+ * \see mln::pset_if
+ */
+ template <typename S, typename F>
+ class pset_if_fwd_piter_
+ : public internal::piter_adaptor_< mln_fwd_piter(S),
+ pset_if_fwd_piter_<S,F> >
+ {
+ typedef mln_fwd_piter(S) adaptee_;
+ typedef pset_if_fwd_piter_<S,F> self_;
+ typedef internal::piter_adaptor_<adaptee_, self_> super_;
+
+ public:
+
+ /// Constructor from a subset of points.
+ pset_if_fwd_piter_(const pset_if<S,F>& subset);
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ private:
+
+ const pset_if<S,F>& subset_;
+ };
+
+
+ // FIXME:
+ template <typename S, typename F>
+ class pset_if_bkd_piter_
+ : public internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+
+ // pset_if_fwd_piter_<S,F>
+
+ template <typename S, typename F>
+ pset_if_fwd_piter_<S,F>::pset_if_fwd_piter_(const pset_if<S,F>& subset)
+ : super_(adaptee_(subset.overset())),
+ subset_(subset)
+ {
+ }
+
+ template <typename S, typename F>
+ void
+ pset_if_fwd_piter_<S,F>::start()
+ {
+ this->piter_.start();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_))
+ this->piter_.next();
+ }
+
+ template <typename S, typename F>
+ void
+ pset_if_fwd_piter_<S,F>::next_()
+ {
+ do
+ this->piter_.next();
+ while (this->piter_.is_valid() && ! subset_.pred(this->piter_));
+ }
+
+
+ // FIXME: pset_if_bkd_piter_<S,F>
+
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_PSET_IF_PITER_HH
Index: mln/core/vec_p.hh
--- mln/core/vec_p.hh (revision 0)
+++ mln/core/vec_p.hh (revision 0)
@@ -0,0 +1,208 @@
+// 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 MLN_CORE_VEC_P_HH
+# define MLN_CORE_VEC_P_HH
+
+/*! \file mln/core/vec_p.hh
+ *
+ * \brief Definition of a point set class based on std::vector.
+ */
+
+# include <vector>
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/accu/bbox.hh>
+
+
+namespace mln
+{
+
+ // Fwd decls.
+ template <typename P> struct vec_p_fwd_piter_;
+ template <typename P> struct vec_p_bkd_piter_;
+
+
+ /*! \brief Point set class based on std::vector.
+ *
+ * This is a multi-set of points.
+ *
+ * \warning We have some troubles with point set comparison based on
+ * a call to npoints(). FIXME: Explain!
+ *
+ * \todo Make it work with P being a Point_Site.
+ */
+ template <typename P>
+ class vec_p : public Point_Set< vec_p<P> >
+ {
+ public:
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ vec_p();
+
+ /// Constructor from a vector \p vect.
+ vec_p(const std::vector<P>& vect);
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Give the exact bounding box.
+ const box_<P>& bbox() const;
+
+ /// Append a point \p p.
+ vec_p<P>& append(const P& p);
+
+ /// Clear this set.
+ void clear();
+
+ /// Return the corresponding std::vector of points.
+ const std::vector<P>& vect() const;
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ protected:
+
+ std::vector<P> vect_;
+ mutable accu::bbox<P> bb_;
+ mutable bool bb_needs_update_;
+
+ void update_bb_() const;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ vec_p<P>::vec_p()
+ {
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ vec_p<P>::vec_p(const std::vector<P>& vect)
+ : vect_(vect)
+ {
+ bb_needs_update_ = true;
+ }
+
+ template <typename P>
+ void
+ vec_p<P>::update_bb_() const
+ {
+ bb_.init();
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ bb_.take(vect_[i]);
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ bool
+ vec_p<P>::has(const P& p) const
+ {
+ for (unsigned i = 0; i < vect_.size(); ++i)
+ if (vect_[i] = p)
+ return true;
+ return false;
+ }
+
+ template <typename P>
+ std::size_t
+ vec_p<P>::npoints() const
+ {
+ return vect_.size();
+ }
+
+ template <typename P>
+ const box_<P>&
+ vec_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ if (bb_needs_update_)
+ update_bb_();
+ return bb_.to_value();
+ }
+
+ template <typename P>
+ vec_p<P>&
+ vec_p<P>::append(const P& p)
+ {
+ vect_.push_back(p);
+ if (! bb_needs_update_)
+ bb_needs_update_ = true;
+ return *this;
+ }
+
+ template <typename P>
+ void
+ vec_p<P>::clear()
+ {
+ vect_.clear();
+ bb_needs_update_ = false;
+ }
+
+ template <typename P>
+ const std::vector<P>&
+ vec_p<P>::vect() const
+ {
+ return vect_;
+ }
+
+ template <typename P>
+ const P&
+ vec_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return vect_[i];
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+# include <mln/core/vec_p_piter.hh>
+
+
+#endif // ! MLN_CORE_VEC_P_HH
Index: mln/core/concept/window.hh
--- mln/core/concept/window.hh (revision 1047)
+++ mln/core/concept/window.hh (working copy)
@@ -77,6 +77,14 @@
W operator-(const Window<W>& rhs);
+ /*! \brief Equality comparison between windows \p lhs and \p rhs.
+ *
+ * \relates mln::Window
+ */
+ template <typename Wl, typename Wr>
+ bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename E>
@@ -107,6 +115,26 @@
return exact(rhs).sym_();
}
+ template <typename Wl, typename Wr>
+ bool operator=(const Window<Wl>& lhs, const Window<Wr>& rhs)
+ {
+ // FIXME: Same grid!
+ typedef mln_point(Wl) P;
+
+ mln_fwd_qiter(Wl) ql(exact(lhs), P::zero);
+ mln_fwd_qiter(Wr) qr(exact(rhs), P::zero);
+
+ for (ql.start(), qr.start();
+ ql.is_valid() && qr.is_valid();
+ ql.next(), qr.next())
+ if (ql != qr)
+ return false; // difference found
+
+ // both windows are equal only if both browsings are completed at
+ // the same time:
+ return ! ql.is_valid() && ! qr.is_valid();
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: mln/core/vec_p_piter.hh
--- mln/core/vec_p_piter.hh (revision 0)
+++ mln/core/vec_p_piter.hh (revision 0)
@@ -0,0 +1,172 @@
+// 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 MLN_CORE_VEC_P_PITER_HH
+# define MLN_CORE_VEC_P_PITER_HH
+
+/*! \file mln/core/vec_p_piter.hh
+ *
+ * \brief Definition of point iterators on mln::vec_p.
+ */
+
+# include <mln/core/vec_p.hh>
+# include <mln/core/internal/fixme.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Forward iterator on points of a vec_p<P>.
+ *
+ */
+ template <typename P>
+ struct vec_p_fwd_piter_ : public Point_Iterator< vec_p_fwd_piter_<P> >
+ {
+ enum { dim = P::dim };
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Point associated type.
+ typedef P point;
+
+ /// Dpoint associated type.
+ typedef mln_dpoint(P) dpoint;
+
+ /// Coordinate associated type.
+ typedef mln_coord(P) coord;
+
+ /// Coordinate associated type.
+ template <typename S>
+ vec_p_fwd_piter_(const Point_Set<S>& s);
+
+ /// Give a hook to the point address.
+ const P* pointer_() const;
+
+ /// Read-only access to the \p i-th coordinate.
+ coord operator[](unsigned i) const;
+
+ /// Test if the iterator is valid.
+ bool is_valid() const;
+
+ /// Invalidate the iterator.
+ void invalidate();
+
+ /// Start an iteration.
+ void start();
+
+ /// Go to the next point.
+ void next_();
+
+ /// Convert the iterator into a point.
+ operator P() const;
+
+ protected:
+ const std::vector<P>& vect_;
+ unsigned i_;
+ P p_;
+ };
+
+
+
+ // FIXME:
+ template <typename P>
+ struct vec_p_bkd_piter_ : internal::fixme
+ {};
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ template <typename S>
+ vec_p_fwd_piter_<P>::vec_p_fwd_piter_(const Point_Set<S>& s)
+ : vect_(exact(s).vect())
+ {
+ invalidate();
+ }
+
+ template <typename P>
+ const P*
+ vec_p_fwd_piter_<P>::pointer_() const
+ {
+ return & p_;
+ }
+
+ template <typename P>
+ mln_coord(P)
+ vec_p_fwd_piter_<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < dim);
+ mln_precondition(is_valid());
+ return p_[i];
+ }
+
+ template <typename P>
+ bool
+ vec_p_fwd_piter_<P>::is_valid() const
+ {
+ return i_ < vect_.size();
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::invalidate()
+ {
+ i_ = vect_.size();
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::start()
+ {
+ i_ = 0;
+ if (is_valid())
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ void
+ vec_p_fwd_piter_<P>::next_()
+ {
+ ++i_;
+ p_ = vect_[i_];
+ }
+
+ template <typename P>
+ vec_p_fwd_piter_<P>::operator P() const
+ {
+ mln_precondition(is_valid());
+ return p_;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_VEC_P_PITER_HH
Index: mln/core/set_p.hh
--- mln/core/set_p.hh (revision 0)
+++ mln/core/set_p.hh (revision 0)
@@ -0,0 +1,162 @@
+// 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 MLN_CORE_SET_P_HH
+# define MLN_CORE_SET_P_HH
+
+/*! \file mln/core/set_p.hh
+ *
+ * \brief Definition of a point set class based on std::set.
+ */
+
+# include <mln/core/concept/point_set.hh>
+# include <mln/core/internal/set_of.hh>
+# include <mln/accu/bbox.hh>
+# include <mln/core/vec_p.hh>
+
+
+namespace mln
+{
+
+ /*! \brief Point set class based on std::set.
+ *
+ * This is a mathematical set of points (not a multi-set). The
+ * parameter \p P shall be a Point type.
+ *
+ * \todo Test if \p P being a Point_Site is ok.
+ */
+ template <typename P>
+ class set_p : public Point_Set< set_p<P> >,
+ private internal::set_of_<P>
+ {
+ typedef internal::set_of_<P> super_;
+
+ public:
+
+ /// Point associated type.
+ typedef mln_point(P) point;
+
+ /// Point_Site associated type.
+ typedef P psite;
+
+ /// Forward Point_Iterator associated type.
+ typedef vec_p_fwd_piter_<P> fwd_piter;
+
+ /// Backward Point_Iterator associated type.
+ typedef vec_p_bkd_piter_<P> bkd_piter;
+
+ /// Constructor.
+ set_p();
+
+ /// Test is \p p belongs to this point set.
+ bool has(const P& p) const;
+
+ /// Return the corresponding std::vector of points.
+ using super_::vect;
+
+ /// Give the number of points.
+ std::size_t npoints() const;
+
+ /// Insert a point \p p.
+ set_p<P>& insert(const P& p);
+
+ /// Return the \p i-th point.
+ const P& operator[](unsigned i) const;
+
+ /// Clear this set.
+ void clear();
+
+ /// Give the exact bounding box.
+ const box_<point>& bbox() const;
+
+ protected:
+
+ accu::bbox<P> bb_;
+ // FIXME: Add invariant bb_.is_valid() <=> npoints() != 0
+ };
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename P>
+ set_p<P>::set_p()
+ {
+ }
+
+ template <typename P>
+ bool
+ set_p<P>::has(const P& p) const
+ {
+ return this->super_::has(p);
+ }
+
+ template <typename P>
+ std::size_t
+ set_p<P>::npoints() const
+ {
+ return this->super_::nelements();
+ }
+
+ template <typename P>
+ set_p<P>&
+ set_p<P>::insert(const P& p)
+ {
+ this->super_::insert(p);
+ bb_.take(p);
+ return *this;
+ }
+
+ template <typename P>
+ const P&
+ set_p<P>::operator[](unsigned i) const
+ {
+ mln_precondition(i < npoints());
+ return this->super_::element(i);
+ }
+
+ template <typename P>
+ void
+ set_p<P>::clear()
+ {
+ this->super_::clear();
+ bb_.init();
+ }
+
+ template <typename P>
+ const box_<mln_point(P)>&
+ set_p<P>::bbox() const
+ {
+ mln_precondition(npoints() != 0);
+ return bb_.to_value();
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_SET_P_HH
Index: mln/core/line2d.hh
--- mln/core/line2d.hh (revision 1047)
+++ mln/core/line2d.hh (working copy)
@@ -36,7 +36,7 @@
# include <vector>
# include <mln/core/concept/point_set.hh>
-# include <mln/core/pvec_piter.hh>
+# include <mln/core/vec_p_piter.hh>
# include <mln/core/box2d.hh>
# include <mln/math/all.hh>
@@ -58,10 +58,10 @@
typedef point2d psite;
/// Forward Point_Iterator associated type.
- typedef pvec_fwd_piter_<point2d> fwd_piter;
+ typedef vec_p_fwd_piter_<point2d> fwd_piter;
/// Backward Point_Iterator associated type.
- typedef pvec_bkd_piter_<point2d> bkd_piter;
+ typedef vec_p_bkd_piter_<point2d> bkd_piter;
/// Constructor from point \p beg to point \p end.
Index: mln/draw/line.hh
--- mln/draw/line.hh (revision 1047)
+++ mln/draw/line.hh (working copy)
@@ -35,6 +35,9 @@
# include <mln/core/concept/image.hh>
# include <mln/core/line2d.hh>
+# include <mln/level/paste.hh>
+# include <mln/pw/image.hh>
+# include <mln/pw/cst.hh>
namespace mln
@@ -43,7 +46,8 @@
namespace draw
{
- /// Draw a line at level \p v in image \p ima between the points \p beg and \p end.
+ /// Draw a line at level \p v in image \p ima between the points
+ /// \p beg and \p end.
template <typename I>
void line(Image<I>& ima,
const mln_point(I)& beg, const mln_point(I)& end,
@@ -52,27 +56,6 @@
# ifndef MLN_INCLUDE_ONLY
- namespace impl
- {
-
- template <typename I>
- void line(I& ima,
- const point2d& beg, const point2d& end,
- const mln_value(I)& v)
- {
- line2d l(beg, end);
- mln_piter(line2d) p(l);
- for_all(p)
- ima(p) = v;
- }
-
- // FIXME: Overload.
-
- } // end of namespace mln::draw::impl
-
-
- // Facade.
-
template <typename I>
void line(Image<I>& ima,
const mln_point(I)& beg, const mln_point(I)& end,
@@ -80,7 +63,8 @@
{
mln_precondition(exact(ima).has_data());
mln_precondition(exact(ima).has(beg) && exact(ima).has(end));
- impl::line(exact(ima), beg, end, v);
+ level::paste(pw::cst(v) | line2d(beg, end),
+ ima);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/take.hh
--- mln/level/take.hh (revision 0)
+++ mln/level/take.hh (revision 0)
@@ -0,0 +1,102 @@
+// 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 MLN_LEVEL_TAKE_HH
+# define MLN_LEVEL_TAKE_HH
+
+/*! \file mln/level/take.hh
+ *
+ * \brief Make an accumulator take image pixel values.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+# include <mln/core/concept/image.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Make an accumulator take the values of the image \p input.
+ *
+ * \param[in,out] a The accumulator.
+ * \param[in] input The input image.
+ *
+ * This routine runs: \n
+ * for all p of \p input, \p a.take( \p input(p) ) \n
+ *
+ * \warning This routine does not perform a.init().
+ */
+ template <typename A, typename I>
+ void take(Accumulator<A>& a, const Image<I>& input);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ namespace impl
+ {
+
+ template <typename A, typename I>
+ void take(A& a, const Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_piter(I) p(input.domain());
+ for_all(p)
+ a.take(input(p));
+ }
+
+ template <typename A, typename I>
+ void take(A& a, const Fast_Image<I>& input_)
+ {
+ const I& input = exact(input_);
+ mln_pixter(const I) pxl(input);
+ for_all(pxl)
+ a.take(*pxl);
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facade.
+
+ template <typename A, typename I>
+ void take(Accumulator<A>& a, const Image<I>& input)
+ {
+ mln_precondition(exact(input).has_data());
+ impl::take(exact(a), exact(input));
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_TAKE_HH
Index: mln/level/apply.hh
--- mln/level/apply.hh (revision 1047)
+++ mln/level/apply.hh (working copy)
@@ -30,7 +30,7 @@
/*! \file mln/level/apply.hh
*
- * \brief Apply some function-objects on an image.
+ * \brief Apply a function-object onto image pixel values.
*/
# include <mln/core/concept/image.hh>
@@ -52,34 +52,25 @@
* This routine runs: \n
* for all p of \p input, \p f( \p input(p) ) \n
* return \p f
+ *
+ * \todo Find a meaning for this routine! (Clue: f is mutable
+ * and/or same for input?)
*/
template <typename I, typename F>
F apply(const Image<I>& input, const Function<F>& f);
- /*! Apply an accumulator to the image \p input.
- *
- * \param[in] input The input image.
- * \param[in] a The accumulator.
- * \result A copy of the accumulator.
- *
- * This routine runs: \n
- * a.init() \n
- * for all p of \p input, \p a.take( \p input(p) ) \n
- * return \p a
- */
- template <typename I, typename A>
- A apply(const Image<I>& input, const Accumulator<A>& a);
-
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
+
template <typename I, typename F>
F apply(const Image<I>& input_, const Function<F>& f_)
{
const I& input = exact(input_);
F f = exact(f_);
- mln_precondition(input.has_data());
mln_piter(I) p(input.domain());
for_all(p)
@@ -87,18 +78,28 @@
return f;
}
- template <typename I, typename A>
- A apply(const Image<I>& input_, const Accumulator<A>& a_)
+ template <typename I, typename F>
+ F apply(const Fast_Image<I>& input_, const Function<F>& f_)
{
const I& input = exact(input_);
- A a = exact(a_);
- mln_precondition(input.has_data());
+ F f = exact(f_);
- a.init();
- mln_piter(I) p(input.domain());
- for_all(p)
- a.take(input(p));
- return a;
+ mln_pixter(const I) pxl(input);
+ for_all(pxl)
+ f(input(*pxl));
+ return f;
+ }
+
+ } // end of namespace mln::level::impl
+
+
+ // Facades.
+
+ template <typename I, typename F>
+ F apply(const Image<I>& input, const Function<F>& f)
+ {
+ mln_precondition(exact(input).has_data());
+ return impl::apply(exact(input), f);
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/level/run.hh
--- mln/level/run.hh (revision 0)
+++ mln/level/run.hh (revision 0)
@@ -0,0 +1,79 @@
+// 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 MLN_LEVEL_RUN_HH
+# define MLN_LEVEL_RUN_HH
+
+/*! \file mln/level/run.hh
+ *
+ * \brief Run an accumulator onto image pixel values.
+ */
+
+# include <mln/level/take.hh>
+
+
+namespace mln
+{
+
+ namespace level
+ {
+
+ /*! Run an accumulator onto the pixel values of the image \p input.
+ *
+ * \param[in] input The input image.
+ * \param[in] a The accumulator.
+ * \return A resulting accumulator.
+ *
+ * This routine runs: \n
+ * res = \p a \n
+ * res.init() \n
+ * level::take(res, \p input) \n
+ * return res \n
+ */
+ template <typename I, typename A>
+ A run(const Image<I>& input, const Accumulator<A>& a);
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename I, typename A>
+ A run(const Image<I>& input, const Accumulator<A>& a)
+ {
+ A res = exact(a);
+ res.init();
+ level::take(res, input);
+ return res;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::level
+
+} // end of namespace mln
+
+
+#endif // ! MLN_LEVEL_RUN_HH
Index: mln/accu/sum.hh
--- mln/accu/sum.hh (revision 1047)
+++ mln/accu/sum.hh (working copy)
@@ -34,6 +34,7 @@
*/
# include <mln/core/concept/accumulator.hh>
+# include <mln/value/props.hh>
namespace mln
@@ -46,10 +47,10 @@
/*! Generic sum accumulator class.
*
* Parameter \c V is the type of values that we sum. Parameter \c
- * S is the type to store the sum value; the default type of
- * \c S is \c V.
+ * S is the type to store the value sum; the default type of
+ * \c S is the summation type (property) of \c V.
*/
- template <typename V, typename S = V>
+ template <typename V, typename S = mln_sum(V)>
struct sum : public Accumulator< sum<V,S> >
{
typedef V value;
@@ -61,6 +62,8 @@
operator S() const;
S to_value() const;
+ sum<V,S>& operator+=(const sum<V,S>& rhs);
+
protected:
S sum_;
@@ -99,7 +102,15 @@
S
sum<V,S>::to_value() const
{
- return sum_ / count_;
+ return sum_;
+ }
+
+ template <typename V, typename S>
+ sum<V,S>&
+ sum<V,S>::operator+=(const sum<V,S>& rhs)
+ {
+ sum_ += rhs.sum_;
+ return *this;
}
# endif // ! MLN_INCLUDE_ONLY
Index: mln/accu/count.hh
--- mln/accu/count.hh (revision 0)
+++ mln/accu/count.hh (revision 0)
@@ -0,0 +1,119 @@
+// 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 MLN_ACCU_COUNT_HH
+# define MLN_ACCU_COUNT_HH
+
+/*! \file mln/accu/count.hh
+ *
+ * \brief Define an accumulator that counts.
+ */
+
+# include <mln/core/concept/accumulator.hh>
+
+
+namespace mln
+{
+
+ namespace accu
+ {
+
+
+ /*! Generic counter accumulator class.
+ */
+ template <typename V>
+ struct count : public Accumulator< count<V> >
+ {
+ typedef V value;
+
+ count();
+ void take(const value&);
+ void init();
+
+ operator std::size_t() const;
+ std::size_t to_value() const;
+
+ count<V>& operator+=(const count<V>& rhs);
+
+ protected:
+
+ std::size_t count_;
+ };
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename V>
+ count<V>::count()
+ {
+ init();
+ }
+
+ template <typename V>
+ void
+ count<V>::take(const value&)
+ {
+ ++count_;
+ }
+
+ template <typename V>
+ void
+ count<V>::init()
+ {
+ count_ = 0;
+ }
+
+ template <typename V>
+ count<V>::operator std::size_t() const
+ {
+ return to_value();
+ }
+
+ template <typename V>
+ std::size_t
+ count<V>::to_value() const
+ {
+ return count_;
+ }
+
+ template <typename V>
+ count<V>&
+ count<V>::operator+=(const count<V>& rhs)
+ {
+ count_ += rhs.count_;
+ return *this;
+ }
+
+# endif // ! MLN_INCLUDE_ONLY
+
+ } // end of namespace mln::accu
+
+} // end of namespace mln
+
+
+#endif // ! MLN_ACCU_COUNT_HH
Index: mln/accu/mean.hh
--- mln/accu/mean.hh (revision 1047)
+++ mln/accu/mean.hh (working copy)
@@ -33,7 +33,7 @@
* \brief Define an accumulator that computes a mean.
*/
-# include <mln/accu/counter.hh>
+# include <mln/accu/count.hh>
# include <mln/accu/sum.hh>
@@ -48,10 +48,13 @@
*
* Parameter \c V is the type of values that we sum. Parameter \c
* S is the type to store the sum of values; the default type of
- * \c S is \c V. Parameter \c M is the type of the mean value;
- * the default type of \c M is \c S.
+ * \c S is the summation type (property) of \c V. Parameter \c M
+ * is the type of the mean value; the default type of \c M is \c
+ * S.
*/
- template <typename V, typename S = V, typename M = S>
+ template <typename V,
+ typename S = mln_sum(V),
+ typename M = S>
struct mean : public Accumulator< mean<V,S,M> >
{
typedef V value;
@@ -63,9 +66,11 @@
operator M() const;
M to_value() const;
+ mean<V,S,M>& operator+=(const mean<V,S,M>& rhs);
+
protected:
- accu::counter<V> count_;
+ accu::count<V> count_;
accu::sum<V,S> sum_;
};
@@ -97,7 +102,7 @@
template <typename V, typename S, typename M>
mean<V,S,M>::operator M() const
{
- return to_value;
+ return to_value();
}
template <typename V, typename S, typename M>
@@ -107,6 +112,15 @@
return sum_.to_value() / count_.to_value();
}
+ template <typename V, typename S, typename M>
+ mean<V,S,M>&
+ mean<V,S,M>::operator+=(const mean<V,S,M>& rhs)
+ {
+ count_ += rhs.count_;
+ sum_ += rhs.sum_;
+ return *this;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::accu
Index: mln/value/props.hh
--- mln/value/props.hh (revision 1047)
+++ mln/value/props.hh (working copy)
@@ -61,6 +61,9 @@
# define mln_is_lowq(T) typename metal::bool_<( mln_card_(T) != 0 )>::type
+/// Give the summation type for values of type \c T.
+# define mln_sum(T) typename mln::value::props< T >::sum
+
namespace mln
@@ -121,6 +124,7 @@
static const unsigned char max = 255;
static const std::size_t card_ = 256;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -130,6 +134,7 @@
static const signed char max = 127;
static const std::size_t card_ = 256;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -139,6 +144,7 @@
static const unsigned short max = 65535;
static const std::size_t card_ = 65536;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -148,6 +154,7 @@
static const signed short max = 32767;
static const std::size_t card_ = 655356;
typedef data_kind kind;
+ typedef float sum;
};
template <>
@@ -157,6 +164,7 @@
static const unsigned int max = UINT_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -166,6 +174,7 @@
static const signed int max = INT_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -175,6 +184,7 @@
static const unsigned long int max = ULONG_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -184,6 +194,7 @@
static const signed long int max = LONG_MAX;
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
@@ -196,6 +207,7 @@
static const float max() { return FLT_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef float sum;
};
template <>
@@ -205,6 +217,7 @@
static const double max() { return DBL_MAX; }
typedef data_kind kind;
static const std::size_t card_ = 0;
+ typedef double sum;
};
} // end of namespace mln::value
Index: mln/value/int_s.hh
--- mln/value/int_s.hh (revision 1047)
+++ mln/value/int_s.hh (working copy)
@@ -97,6 +97,7 @@
static const std::size_t card_ = metal::pow<2, n>::value;
static const unsigned nbits = n;
typedef data_kind kind;
+ typedef float sum;
};
Index: mln/value/int_u.hh
--- mln/value/int_u.hh (revision 1047)
+++ mln/value/int_u.hh (working copy)
@@ -99,6 +99,7 @@
static const int_u<n> max; // = card_ - 1
static const unsigned nbits = n;
typedef data_kind kind;
+ typedef float sum;
};
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/static
Index: ChangeLog
from Roland Levillain <roland(a)lrde.epita.fr>
Disable check_delegatee_inherited.
* stc/scoop.hxx (helper_check): Disable
`check_delegatee_inherited<curr>' since it triggers errors in
valid cases.
scoop.hxx | 7 +++++++
1 file changed, 7 insertions(+)
Index: stc/scoop.hxx
--- stc/scoop.hxx (revision 1046)
+++ stc/scoop.hxx (working copy)
@@ -370,6 +370,8 @@
* check_delegatee_inherited
*/
+ // FIXME: Improve location in error message (as in other check_*
+ // routines).
template <typename curr>
struct check_delegatee_inherited
: mlc::assert_< stc::is_found< typename first_stm<curr,
@@ -502,7 +504,12 @@
: check_no_final_inherited< mlc::pair_<curr, stc::not_delegated>,
stc_super(curr),
target >
+// FIXME: Disabled. Seems to break the lookup, even in valid cases
+// (use the examples image.cc and morpher.cc in the repository of the
+// LCSD '07 draft to observe this behavior).
+#if 0
, check_delegatee_inherited< curr >
+#endif
{
typedef typename check<stc_super(curr), target>::ret ret;
};
1
0