Olena-patches
Threads by month
- ----- 2025 -----
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- 9625 discussions
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Fix to_upper_window in convert.
* labeling_level.hh: Update to_upper_window.
---
labeling_level.hh | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
Index: trunk/milena/sandbox/duhamel/labeling_level.hh
===================================================================
--- trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1138)
+++ trunk/milena/sandbox/duhamel/labeling_level.hh (revision 1139)
@@ -61,8 +61,7 @@
window<D> win;
mln_niter(N) n(nbh, P::zero);
for_all(n)
- // FIXME: pour Guillaume
- if (n < P::zero)
+ if (n > P::zero)
win.insert(n - P::zero);
return win;
}
@@ -101,8 +100,8 @@
{
typedef mln_point (I) P;
mln_bkd_pixter(const I) p(f.input);
- mln_nixter(const I, N) n(p, f.nbh);
- // mln_qixter(const I, window<P>) n(p, convert::to_upper_window(f.nbh));
+ // mln_nixter(const I, N) n(p, f.nbh);
+ mln_qixter(const I, window<P>) n(p, convert::to_upper_window(f.nbh));
for_all(p) if (f.handles(p))
{
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Guillaume Duhamel <guillaume.duhamel(a)lrde.epita.fr>
Fix fill border in sandbox.
* border_fill.cc,
* border_fill.hh: Update.
---
border_fill.cc | 76 +++++++++++++++++
border_fill.hh | 242 ++++++++++++++++++++++++++++++++++++++++++++++++---------
2 files changed, 279 insertions(+), 39 deletions(-)
Index: trunk/milena/sandbox/duhamel/border_fill.hh
===================================================================
--- trunk/milena/sandbox/duhamel/border_fill.hh (revision 1137)
+++ trunk/milena/sandbox/duhamel/border_fill.hh (revision 1138)
@@ -25,8 +25,8 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-#ifndef MLN_BORDER_FILL_HH
-# define MLN_BORDER_FILL_HH
+#ifndef SANDBOX_MLN_BORDER_FILL_HH
+# define SANDBOX_MLN_BORDER_FILL_HH
/*! \file mln/border/fill.hh
*
@@ -35,15 +35,8 @@
# include <mln/core/concept/image.hh>
# include <mln/core/internal/fixme.hh>
-# include <mln/level/memset_.hh>
-//# include <mln/core/line_piter.hh>
-# include <mln/geom/nrows.hh>
-# include <mln/geom/ncols.hh>
-# include <mln/core/pixel.hh>
# include <mln/core/line_piter.hh>
-# include <mln/core/inplace.hh>
-# include <mln/level/memcpy_.hh>
-# include <mln/core/point2d.hh>
+# include <mln/level/memset_.hh>
namespace mln
{
@@ -67,53 +60,226 @@
# ifndef MLN_INCLUDE_ONLY
+ namespace impl
+ {
template <typename I>
- void fill(const Fast_Image<I>& ima_, const mln_value(I)& v)
+ void fill_1d_size_1_(const Fast_Image<I>& ima_, const mln_value(I)& v)
{
const I& ima = exact(ima_);
mln_precondition(ima.has_data());
- // FIX
+
typedef mln_point(I) P;
- typedef mln_dpoint(I) delta_point;
+ std::size_t border = ima.border ();
+ std::size_t len = exact(ima).bbox().len(P::dim - 1);
+
+ std::memset((void*)&ima[0],
+ *(const int*)(&v), // violent cast
+ border);
+
+ std::memset((void*)&ima[border + len],
+ *(const int*)(&v), // violent cast
+ border);
+ }
+
+ template <typename I>
+ void fill_1d_size_n_(const Fast_Image<I>& ima_, const mln_value(I)& v)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
- Fast_Image<I> im (ima);
- // internal::fixme();
+ typedef mln_point(I) P;
std::size_t border = ima.border ();
- std::size_t nbrows = geom::max_row(ima) - geom::min_row(ima);
- std::size_t nbcols = geom::max_col(ima) - geom::min_col(ima);
- // std::size_t n = ima.bbox().len(P::dim - 1);
+ std::size_t len = exact(ima).bbox().len(P::dim - 1);
+ std::size_t i = 0;
- point2d p = ima.bbox ().pmin ();
+ for (; i < border; ++i)
+ const_cast<I&>(ima)[i] = v;
+
+ std::size_t e = 2 * border + len;
+ for (i += len; i < e; ++i)
+ const_cast<I&>(ima)[i] = v;
+ }
+
+ template <typename I>
+ void fill_2d_size_1_(const Fast_Image<I>& ima_, const mln_value(I)& v)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+
+ typedef mln_point(I) P;
+
+ std::size_t border = ima.border ();
+ std::size_t border_2x = 2 * border;
+ std::size_t len = exact(ima).bbox().len(P::dim - 1);
+ std::size_t n = len + 2 * border;
+ std::size_t s = border * (n + 1);
+ std::size_t e = n;
+
+ for (int i = P::dim - 2; i >= 0; --i)
+ e *= exact(ima).bbox().len(i) + 2 * border;
+
+ std::memset((void*)&ima[0],
+ *(const int*)(&v), // violent cast
+ s);
+
+ std::size_t end = e - ((border + 1) * n);
+ for (s += len; s < end; s += n)
+ std::memset((void*)&ima[s],
+ *(const int*)(&v), // violent cast
+ border_2x);
+
+ std::memset((void*)&ima[s],
+ *(const int*)(&v), // violent cast
+ e - s);
+ }
+
+ template <typename I>
+ void fill_2d_size_n_(const Fast_Image<I>& ima_, const mln_value(I)& v)
+ {
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
+
+ typedef mln_point(I) P;
+
+ std::size_t border = ima.border ();
+ std::size_t border_2x = 2 * border;
+ std::size_t len = exact(ima).bbox().len(P::dim - 1);
+ std::size_t n = len + 2 * border;
+ std::size_t s = border * (n + 1);
+ std::size_t e = n;
+
+ for (int i = P::dim - 2; i >= 0; --i)
+ e *= exact(ima).bbox().len(i) + 2 * border;
- // FIXME : REMOVE THIS LOOP BY MEMSET
- std::size_t s = border * (2 * (border + 1) + nbcols);
for (std::size_t i = 0; i < s; ++i)
const_cast<I&>(ima)[i] = v;
- // typename I::line_piter p(ima.domain());
+ std::size_t end = e - ((border + 1) * n);
+ for (s += len; s < end; s += len)
+ for (std::size_t j = 0; j < border_2x; ++j, ++s)
+ (const_cast<I&>(ima))[s] = v;
-// for (std::size_t i = 0; i < border; ++i, p = p.next ())
+ for (std::size_t i = s; i < e; ++i)
+ const_cast<I&>(ima)[i] = v;
+ }
+
+// template <typename I>
+// void fill_3d_size_n_(const Fast_Image<I>& ima_, const mln_value(I)& v)
// {
-// // memset_(inplace(make::pixel(ima, p)),
-// // v,
-// // n);
+// const I& ima = exact(ima_);
+// mln_precondition(ima.has_data());
+
+// typedef mln_point(I) P;
+
+// std::size_t border = ima.border ();
+// std::size_t border_2x = 2 * border;
+// std::size_t len_s = exact(ima).bbox().len(0);
+// std::size_t len_r = exact(ima).bbox().len(1);
+// std::size_t len_c = exact(ima).bbox().len(2);
+
+// // std::size_t real_len_s = len_s + border_2x;
+// std::size_t real_len_r = len_r + border_2x;
+// std::size_t real_len_c = len_c + border_2x;
+
+// std::size_t face = real_len_r * real_len_c;
+
+// std::size_t cpt = 0;
+
+// for (std::size_t k = 0; k < border; ++k)
+// for (std::size_t i = 0; i < face; ++i, ++cpt)
+// const_cast<I&>(ima)[cpt] = v;
+
+// for (std::size_t k = 0; k < len_s; ++k)
+// {
+// std::size_t s = real_len_c * border + border;
+// for (std::size_t i = 0; i < s; ++i, ++cpt)
+// const_cast<I&>(ima)[cpt] = v;
+
+
+// cpt += len_r;
+// std::size_t end = cpt + len_r + len_c * len_r;
+
+// for (; cpt < end; cpt += len_r)
+// {
+// std::cout << "cpt = "
+// << cpt
+// << "end = "
+// << end
+// << std::endl;
+// for (std::size_t j = 0; j < border_2x; ++j, ++cpt)
+// (const_cast<I&>(ima))[cpt] = v;
// }
- // ACCESS TO RIGHT UP CORNER
- s = nbcols + 1;
- for (std::size_t i = 0; i < s; ++i)
- p = p + right;
+// for (std::size_t i = 0; i < s; ++i, ++cpt)
+// const_cast<I&>(ima)[cpt] = v;
+// }
+
+// for (std::size_t k = 0; k < border; ++k)
+// for (std::size_t i = 0; i < face; ++i, ++cpt)
+// const_cast<I&>(ima)[cpt] = v;
+// }
+
+ template <typename I>
+ void fill_size_1_(const Fast_Image<I>& ima_, const mln_value(I)& v)
+ {
+ typedef mln_point(I) P;
+ const I& ima = exact(ima_);
+ typedef mln_point(I) P;
+ typename I::line_piter pl(ima.domain());
+ std::size_t len_r = exact(ima).bbox().len(P::dim - 1);
+ std::size_t st = 0;
+
+ for_all (pl)
+ {
+ std::size_t end = ima.offset_at (pl);
+ std::memset((void*)&ima[st],
+ *(const int*)(&v),
+ end - st);
+ st = end + len_r;
+ }
+ std::memset((void*)&ima[st],
+ *(const int*)(&v),
+ ima.ncells () - st);
+ }
- // FILL BORDER
- for (std::size_t i = 0; i < nbrows; ++i)
+ template <typename I>
+ void fill_size_n_(const Fast_Image<I>& ima_, const mln_value(I)& v)
{
- level::memset_(const_cast<I&>(ima), p, v, 2 * border);
- p = p + down;
+ typedef mln_point(I) P;
+ const I& ima = exact(ima_);
+ typedef mln_point(I) P;
+ typename I::line_piter pl(ima.domain());
+ std::size_t len_r = exact(ima).bbox().len(P::dim - 1);
+ std::size_t st = 0;
+
+ for_all (pl)
+ {
+ std::size_t end = ima.offset_at (pl);
+ for (std::size_t i = st; i < end; ++i)
+ const_cast<I&>(ima)[i] = v;
+ st = end + len_r;
}
+ for (std::size_t i = st; i < ima.ncells (); ++i)
+ const_cast<I&>(ima)[i] = v;
+ }
+ } // end of namespace mln::border::impl
+
+
+ // Facade.
+
+ template <typename I>
+ void fill(const Fast_Image<I>& ima_, const mln_value(I)& v)
+ {
+ typedef mln_point(I) P;
+ const I& ima = exact(ima_);
+ mln_precondition(ima.has_data());
- // FILL THE BOTTOM OF BORDER
- level::memset_(const_cast<I&>(ima), p, v, border * (2 * (border + 1) + nbcols));
- // END FIX
+ if (!ima.border ())
+ return;
+ if (sizeof(mln_value(I)) == 1)
+ impl::fill_size_1_(ima_, v);
+ else
+ impl::fill_size_n_(ima_, v);
}
# endif // ! MLN_INCLUDE_ONLY
@@ -123,4 +289,4 @@
} // end of namespace mln
-#endif // ! MLN_BORDER_FILL_HH
+#endif // ! SANDBOX_MLN_BORDER_FILL_HH
Index: trunk/milena/sandbox/duhamel/border_fill.cc
===================================================================
--- trunk/milena/sandbox/duhamel/border_fill.cc (revision 1137)
+++ trunk/milena/sandbox/duhamel/border_fill.cc (revision 1138)
@@ -31,18 +31,92 @@
*/
#include "border_fill.hh"
+#include <mln/core/image1d_b.hh>
#include <mln/core/image2d_b.hh>
+#include <mln/core/image3d_b.hh>
#include <mln/value/int_u8.hh>
#include <mln/pw/all.hh>
#include <mln/debug/println_with_border.hh>
using namespace mln;
+template <typename I>
+void print_3d_with_border (const Fast_Image<I>& input_)
+{
+ const I& ima = exact(input_);
+ mln_precondition(ima.has_data());
+
+ typedef mln_point(I) P;
+
+ std::size_t len_s = exact(ima).bbox().len(P::dim - 3);
+ std::size_t len_r = exact(ima).bbox().len(P::dim - 1);
+ std::size_t len_c = exact(ima).bbox().len(P::dim - 2);
+ std::size_t border = ima.border ();
+ std::size_t real_len_s = len_s + 2 * border;
+ std::size_t real_len_r = len_r + 2 * border;
+ std::size_t real_len_c = len_c + 2 * border;
+
+ for (std::size_t k = 0; k < real_len_s; ++k)
+ {
+ for (std::size_t j = 0; j < real_len_c; ++j)
+ {
+ for (std::size_t i = 0; i < real_len_r; ++i)
+ std::cout << ima[k * (real_len_r * real_len_c) + j * real_len_r + i]
+ << " ";
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+ }
+ std::cout << std::endl;
+}
+
int
main (void)
{
- image2d_b<value::int_u8> i1(9, 6);
+
+
+ std::cout << "Test 2d size=2x3 in value::int_u8"
+ << std::endl;
+ image2d_b<value::int_u8> i1(2, 3);
border::fill (i1, 8);
debug::println_with_border(i1);
+
+ std::cout << "Test 2d size=2x3 in int"
+ << std::endl;
+ image2d_b<int> i2(2, 3);
+ border::fill (i2, 5);
+ debug::println_with_border(i2);
+
+ std::cout << "Test 3d size=2x3x1 in value::int_u8"
+ << std::endl;
+ image3d_b<value::int_u8> i4(2, 3, 1, 2);
+ border::fill (i4, 7);
+ print_3d_with_border(i4);
+
+
+ std::cout << "Test 3d size=2x3x1 with border=1 in int"
+ << std::endl;
+ image3d_b<int> i3(2, 3, 1, 1);
+ border::fill (i3, 6);
+ print_3d_with_border(i3);
+
+
+
+ std::cout << "Test 1d size=5 with border=3 in value::int_u8"
+ << std::endl;
+ image1d_b<value::int_u8> i6(5);
+ border::fill (i6, 9);
+ debug::println_with_border(i6);
+
+
+ std::cout << std::endl;
+
+ std::cout << "Test 1d size=8 with border=3 in int"
+ << std::endl;
+ image1d_b<int> i5(8);
+ border::fill (i5, 1);
+ debug::println_with_border(i5);
+
+
}
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Add the notion of concrete image associated type.
New material for the notion of concrete images.
* mln/trait: New.
* mln/trait/image_from_mesh.hh: New.
* mln/trait/concrete.hh: New.
* mln/core/macros.hh (mln_ch_value): Remove; now in...
* mln/trait/ch_value.hh: New.
* tests/trait_ch_value.cc: New.
* mln/tag: New directory.
* mln/tag/skeleton.hh: New.
Replace change_value by skeleton in images.
* mln/core/concept/image.hh,
* mln/core/concept/doc/image.hh (change_value): Remove.
(skeleton): New.
* mln/pw/image.hh,
* mln/core/decorated_image.hh,
* mln/core/image_if.hh,
* mln/core/rle_image.hh,
* mln/core/image2d_b.hh,
* mln/core/cast_image.hh,
* mln/core/safe.hh,
* mln/core/sub_image.hh,
* mln/core/sparse_image.hh,
* mln/core/t_image.hh,
* mln/core/image1d_b.hh,
* mln/core/image3d_b.hh,
* mln/value/stack.hh: Update.
Misc.
* tests/interpolated.cc: Typo.
* mln/level/paste.hh (paste_pw_): Rename as...
(paste_generic_): ...this.
* tests/level_paste.cc: Update.
mln/core/cast_image.hh | 11 +--
mln/core/concept/doc/image.hh | 19 ++----
mln/core/concept/image.hh | 13 ++--
mln/core/decorated_image.hh | 11 +--
mln/core/image1d_b.hh | 10 +--
mln/core/image2d_b.hh | 10 +--
mln/core/image3d_b.hh | 10 +--
mln/core/image_if.hh | 12 ++--
mln/core/macros.hh | 17 +----
mln/core/rle_image.hh | 11 +--
mln/core/safe.hh | 9 +--
mln/core/sparse_image.hh | 11 +--
mln/core/sub_image.hh | 9 +--
mln/core/t_image.hh | 11 ---
mln/level/paste.hh | 4 -
mln/pw/image.hh | 12 +---
mln/tag/skeleton.hh | 60 ++++++++++++++++++++
mln/trait/ch_value.hh | 126 ++++++++++++++++++++++++++++++++++++++++++
mln/trait/concrete.hh | 60 ++++++++++++++++++++
mln/trait/image_from_mesh.hh | 82 +++++++++++++++++++++++++++
mln/value/stack.hh | 12 +---
tests/level_paste.cc | 4 +
tests/trait_ch_value.cc | 43 ++++++++++++++
23 files changed, 449 insertions(+), 118 deletions(-)
Index: tests/level_paste.cc
--- tests/level_paste.cc (revision 1136)
+++ tests/level_paste.cc (working copy)
@@ -53,6 +53,8 @@
debug::iota(ima2);
debug::println(ima2);
- level::paste(ima, ima2);
+ level::paste(ima, ima2); // Fast version.
debug::println(ima2);
+
+ level::impl::paste_generic_(ima, ima2); // Not so fast version...
}
Index: tests/trait_ch_value.cc
--- tests/trait_ch_value.cc (revision 0)
+++ tests/trait_ch_value.cc (revision 0)
@@ -0,0 +1,43 @@
+// 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/trait_ch_value.cc
+ *
+ * \brief Tests on mln::trait::ch_value.
+ */
+
+#include <mln/core/image2d_b.hh>
+#include <mln/trait/ch_value.hh>
+
+
+int main()
+{
+ using namespace mln;
+
+ typedef image2d_b<int> I;
+ trait::ch_value<I, bool>::ret ima;
+}
Index: tests/interpolated.cc
Index: mln/trait/image_from_mesh.hh
--- mln/trait/image_from_mesh.hh (revision 0)
+++ mln/trait/image_from_mesh.hh (revision 0)
@@ -0,0 +1,82 @@
+// 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_TRAIT_IMAGE_FROM_MESH_HH
+# define MLN_TRAIT_IMAGE_FROM_MESH_HH
+
+/*! \file mln/core/trait/image_from_mesh.hh
+ *
+ * \brief Definition of the "image from mesh" trait.
+ */
+
+# include <mln/core/grids.hh>
+
+
+# define mln_image_from_mesh(I, V) typename mln::trait::image_from_mesh< I, V >::ret
+
+
+
+namespace mln
+{
+
+
+ // Fwd decls.
+ template <typename T> struct image1d_b;
+ template <typename T> struct image2d_b;
+ template <typename T> struct image3d_b;
+
+
+ namespace trait
+ {
+
+ template <typename M, typename V> struct image_from_mesh;
+
+ template <typename V>
+ struct image_from_mesh< grid::tick, V >
+ {
+ typedef image1d_b<V> ret;
+ };
+
+ template <typename V>
+ struct image_from_mesh< grid::square, V >
+ {
+ typedef image2d_b<V> ret;
+ };
+
+ template <typename V>
+ struct image_from_mesh< grid::cube, V >
+ {
+ typedef image3d_b<V> ret;
+ };
+
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_IMAGE_FROM_MESH_HH
Index: mln/trait/concrete.hh
--- mln/trait/concrete.hh (revision 0)
+++ mln/trait/concrete.hh (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_CONCRETE_HH
+# define MLN_TRAIT_CONCRETE_HH
+
+/*! \file mln/core/trait/concrete.hh
+ *
+ * \brief Definition of the concrete image trait.
+ */
+
+# include <mln/trait/ch_value.hh>
+
+
+# define mln_concrete(I) typename mln::trait::concrete< I >::ret
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+ template <typename I>
+ struct concrete
+ {
+ typedef typename I::value value;
+ typedef typename ch_value<I, value>::ret ret;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_CONCRETE_HH
Index: mln/trait/ch_value.hh
--- mln/trait/ch_value.hh (revision 0)
+++ mln/trait/ch_value.hh (revision 0)
@@ -0,0 +1,126 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_TRAIT_CH_VALUE_HH
+# define MLN_TRAIT_CH_VALUE_HH
+
+/*! \file mln/core/trait/ch_value.hh
+ *
+ * \brief Definition of the "change value" image trait.
+ */
+
+# include <mln/tag/skeleton.hh>
+# include <mln/trait/image_from_mesh.hh>
+# include <mln/metal/vec.hh>
+
+
+# define mln_ch_value(I, V) typename mln::trait::ch_value< I, V >::ret
+
+
+
+namespace mln
+{
+
+ namespace trait
+ {
+
+
+ template <typename I, typename V> struct ch_value; // Fwd decl.
+
+
+ namespace impl
+ {
+
+ template <typename I, typename V> struct ch_value_; // Decl.
+
+ template < template <class> class M, typename I,
+ typename V >
+ struct ch_value_< M< tag::image<I> >, V >
+ {
+ typedef M< mln_ch_value(I, V) > ret;
+ };
+
+ template < template <class> class M, typename T,
+ typename V >
+ struct ch_value_< M< tag::value<T> >, V >
+ {
+ typedef M< V > ret;
+ };
+
+ template < template <class, class> class M, typename T, typename I,
+ typename V >
+ struct ch_value_< M< tag::value<T>, tag::image<I> >, V >
+ {
+ typedef mln_ch_value(I, V) ret;
+ };
+
+ template < template <class, class> class M, typename P, typename T,
+ typename V >
+ struct ch_value_< M< tag::psite<P>, tag::value<T> >, V >
+ {
+ typedef M< P, V > ret;
+ };
+
+ template < template <class, class> class M, unsigned n, typename I,
+ typename V >
+ struct ch_value_< M< tag::unsigned_<n>, tag::image<I> >, V > // value::stack !
+ {
+ typedef metal::vec<n, V> value;
+ typedef mln_ch_value(I, value) ret;
+ };
+
+ template < template <class, class> class M, typename I, typename S,
+ typename V >
+ struct ch_value_< M< tag::image<I>, tag::pset<S> >, V >
+ {
+ typedef M< mln_ch_value(I, V), S > ret;
+ };
+
+ template < template <class, class> class M, typename F, typename S,
+ typename V >
+ struct ch_value_< M< tag::function<F>, tag::pset<S> >, V >
+ {
+ typedef typename S::mesh mesh;
+ typedef typename image_from_mesh< mesh, V >::ret ret; // FIXME: from_psite instead? coord=int!?
+ };
+
+ } // end of namespace mln::trait::impl
+
+
+ template <typename I, typename V>
+ struct ch_value
+ {
+ typedef typename I::skeleton skeleton;
+ typedef typename impl::ch_value_<skeleton, V>::ret ret;
+ };
+
+ } // end of namespace mln::trait
+
+} // end of namespace mln
+
+
+#endif // ! MLN_TRAIT_CH_VALUE_HH
Index: mln/pw/image.hh
--- mln/pw/image.hh (revision 1136)
+++ mln/pw/image.hh (working copy)
@@ -67,6 +67,11 @@
typedef internal::image_base_< S, image<F,S> > super_;
public:
+
+ /// Skeleton.
+ typedef image< tag::function<F>, tag::pset<S> > skeleton;
+
+
// From super class.
typedef mln_psite(super_) psite;
@@ -106,13 +111,6 @@
/// Give the set of values of the image.
const vset& values() const;
- /// Change value type. FIXME!
- template <typename U>
- struct change_value
- {
- typedef internal::fixme ret;
- };
-
protected:
F f_;
S pset_;
Index: mln/core/macros.hh
--- mln/core/macros.hh (revision 1136)
+++ mln/core/macros.hh (working copy)
@@ -184,18 +184,7 @@
-
-
-/*! \brief Shortcut to change the value type of an image type.
- *
- * \c I is an image type
- * \c T is the new value type
- */
-# define mln_ch_value(I, T) typename I ::template change_value< T >::ret
-
-
-
-// FIXME: Doc!
+// FIXME: Just include trait/all.hh !!!
# define mln_fwd_pixter(I) typename mln::trait::fwd_pixter< I >::ret
# define mln_fwd_pixter_(I) mln::trait::fwd_pixter< I >::ret
@@ -216,4 +205,8 @@
+# include <mln/trait/ch_value.hh>
+
+
+
#endif // ! MLN_CORE_MACROS_HH
Index: mln/core/decorated_image.hh
--- mln/core/decorated_image.hh (revision 1136)
+++ mln/core/decorated_image.hh (working copy)
@@ -77,17 +77,16 @@
typedef mln::value::proxy<const self_> rvalue;
typedef typename impl_::lvalue lvalue;
+
+ /// Skeleton.
+ typedef decorated_image< tag::image<I>, tag::data<D> > skeleton;
+
+
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;
- 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;
Index: mln/core/image_if.hh
--- mln/core/image_if.hh (revision 1136)
+++ mln/core/image_if.hh (working copy)
@@ -48,6 +48,11 @@
image_if<I,F>,
pset_if<mln_pset(I),F> >
{
+
+ /// Skeleton.
+ typedef image_if< tag::image<I>, tag::function<F> > skeleton;
+
+
/// Point_Set associated type.
typedef pset_if<mln_pset(I), F> pset;
@@ -60,12 +65,6 @@
/// Give the definition domain.
const pset& domain() const;
- template <typename T>
- struct change_value
- {
- typedef image_if<mln_ch_value(I,T), F> ret;
- };
-
/// Const promotion via convertion.
operator image_if<const I, F>() const;
@@ -89,6 +88,7 @@
}
+
# ifndef MLN_INCLUDE_ONLY
template <typename I, typename F>
Index: mln/core/rle_image.hh
--- mln/core/rle_image.hh (revision 1136)
+++ mln/core/rle_image.hh (working copy)
@@ -58,6 +58,11 @@
typedef internal::run_psite<P> psite;
typedef mln::value::set<T> vset;
+
+ /// Skeleton.
+ typedef rle_image< tag::psite<P>, tag::value<T> > skeleton;
+
+
rle_image();
/// Add a new range to the image.
@@ -75,12 +80,6 @@
/// Give the set of values of the image.
const vset& values() const;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef rle_image<P, U> ret;
- };
protected:
/// Image values.
std::vector<T> values_;
Index: mln/core/image2d_b.hh
--- mln/core/image2d_b.hh (revision 1136)
+++ mln/core/image2d_b.hh (working copy)
@@ -100,12 +100,10 @@
/// Return type of read-write access.
typedef T& lvalue;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef image2d_b<U> ret;
- };
+
+ /// Skeleton.
+ typedef image2d_b< tag::value<T> > skeleton;
+
/// Value_Set associated type.
typedef mln::value::set<T> vset;
Index: mln/core/cast_image.hh
--- mln/core/cast_image.hh (revision 1136)
+++ mln/core/cast_image.hh (working copy)
@@ -67,6 +67,10 @@
typedef mln::value::set<T> vset;
+ /// Skeleton.
+ typedef cast_image< tag::value<T>, tag::image<I> > skeleton;
+
+
/// Constructor.
cast_image_(const Image<I>& ima);
@@ -89,13 +93,6 @@
/// Give the set of values of the image.
const vset& values() const;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef mln_ch_value(I, U) ret;
- };
-
protected:
const I& ima_;
};
Index: mln/core/safe.hh
--- mln/core/safe.hh (revision 1136)
+++ mln/core/safe.hh (working copy)
@@ -42,6 +42,9 @@
typedef internal::image_adaptor_< I, safe_image<I> > super_;
public:
+ /// Skeleton.
+ typedef safe_image< tag::image<I> > skeleton;
+
safe_image(I& ima, const mln_value(I)& default_value);
mln_rvalue(I) operator()(const mln_psite(I)& p) const;
@@ -49,12 +52,6 @@
typedef typename super_::lvalue lvalue;
lvalue operator()(const mln_psite(I)& p);
- template <typename U>
- struct change_value
- {
- typedef safe_image<mln_ch_value(I, U)> ret;
- };
-
/// Const promotion via convertion.
operator safe_image<const I>() const;
Index: mln/core/sub_image.hh
--- mln/core/sub_image.hh (revision 1136)
+++ mln/core/sub_image.hh (working copy)
@@ -44,16 +44,13 @@
typedef internal::image_adaptor_<I, sub_image<I,S>, S> super_;
public:
+ /// Skeleton.
+ typedef sub_image< tag::image<I>, tag::pset<S> > skeleton;
+
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.
Index: mln/core/concept/image.hh
--- mln/core/concept/image.hh (revision 1136)
+++ mln/core/concept/image.hh (working copy)
@@ -34,7 +34,10 @@
# include <mln/core/concept/point_set.hh>
# include <mln/core/concept/mesh.hh>
-# include <mln/core/trait/all.hh>
+
+# include <mln/core/trait/all.hh> // FIXME: Move out of core!
+# include <mln/trait/ch_value.hh> // FIXME: Should be in all.hh!
+
# include <mln/metal/is_a.hh>
@@ -68,11 +71,7 @@
rvalue operator()(const psite& p) const;
lvalue operator()(const psite& p);
- template <typename T>
- struct change_value
- {
- typedef ret;
- };
+ typedef skeleton;
// provided by internal::image_base_:
@@ -128,7 +127,7 @@
typedef mln_rvalue(E) rvalue;
typedef mln_lvalue(E) lvalue;
- typedef mln_ch_value(E, value) change;
+ typedef typename E::skeleton skeleton;
bool (E::*m3)() const = & E::has_data;
m3 = 0;
Index: mln/core/concept/doc/image.hh
--- mln/core/concept/doc/image.hh (revision 1136)
+++ mln/core/concept/doc/image.hh (working copy)
@@ -63,6 +63,14 @@
typedef void vset;
+
+ /*! \brief Associate type that describes how this type of image
+ * is constructed.
+ */
+ typedef void skeleton;
+
+
+
/*! \brief Test if the image have been initialized.
*/
bool has_data() const;
@@ -108,17 +116,6 @@
- /*! \brief Trait that gives the corresponding image type with
- the value type changes to T.
- */
- template <typename T>
- struct change_value
- {
- typedef ret;
- };
-
-
-
/*! \brief Point set associated type.
* \invariant This type has to derive from mln::Point_Set.
*/
Index: mln/core/sparse_image.hh
--- mln/core/sparse_image.hh (revision 1136)
+++ mln/core/sparse_image.hh (working copy)
@@ -58,6 +58,11 @@
typedef internal::run_psite<P> psite;
typedef mln::value::set<T> vset;
+
+ /// Skeleton.
+ typedef sparse_image< tag::psite<P>, tag::value<T> > skeleton;
+
+
sparse_image();
/// Add a new range to the image.
@@ -75,12 +80,6 @@
/// Give the set of values of the image.
const vset& values() const;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef sparse_image<P, U> ret;
- };
protected:
/// Image values.
std::vector< std::vector<value> > values_;
Index: mln/core/t_image.hh
--- mln/core/t_image.hh (revision 1136)
+++ mln/core/t_image.hh (working copy)
@@ -49,6 +49,8 @@
template <typename I>
struct t_image : public internal::image_adaptor_< I, t_image<I> >
{
+ /// Skeleton.
+ typedef t_image< tag::image<I> > skeleton;
/// Test if a pixel value is accessible at \p p.
bool owns_(const mln_point(I)& p) const;
@@ -65,15 +67,6 @@
/// Read-write access of pixel value at point site \p p.
lvalue operator()(const mln_point(I)& p);
-
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef mln_ch_value(I, U) ret;
- };
-
-
/// Constructor.
t_image(I& ima, unsigned c1, unsigned c2);
Index: mln/core/image1d_b.hh
--- mln/core/image1d_b.hh (revision 1136)
+++ mln/core/image1d_b.hh (working copy)
@@ -100,12 +100,10 @@
/// Return type of read-write access.
typedef T& lvalue;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef image1d_b<U> ret;
- };
+
+ /// Skeleton.
+ typedef image1d_b< tag::value<T> > skeleton;
+
/// Value_Set associated type.
typedef mln::value::set<T> vset;
Index: mln/core/image3d_b.hh
--- mln/core/image3d_b.hh (revision 1136)
+++ mln/core/image3d_b.hh (working copy)
@@ -100,12 +100,10 @@
/// Return type of read-write access.
typedef T& lvalue;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef image3d_b<U> ret;
- };
+
+ /// Skeleton.
+ typedef image3d_b< tag::value<T> > skeleton;
+
/// Value_Set associated type.
typedef mln::value::set<T> vset;
Index: mln/level/paste.hh
--- mln/level/paste.hh (revision 1136)
+++ mln/level/paste.hh (working copy)
@@ -70,7 +70,7 @@
{
template <typename I, typename J>
- void paste_pw_(const Image<I>& data_, Image<J>& destination_)
+ void paste_generic_(const Image<I>& data_, Image<J>& destination_)
{
const I& data = exact(data_);
J& destination = exact(destination_);
@@ -110,7 +110,7 @@
if (sizeof(mln_value(I)) = sizeof(mln_value(J)))
paste_fast_(data, destination);
else
- paste_pw_(data, destination);
+ paste_generic_(data, destination);
}
} // end of namespace mln::level::impl
Index: mln/tag/skeleton.hh
--- mln/tag/skeleton.hh (revision 0)
+++ mln/tag/skeleton.hh (revision 0)
@@ -0,0 +1,60 @@
+// Copyright (C) 2007 EPITA Research and Development Laboratory
+//
+// This file is part of the Olena Library. This library is free
+// software; you can redistribute it and/or modify it under the terms
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+#ifndef MLN_CORE_TAG_SKELETON_HH
+# define MLN_CORE_TAG_SKELETON_HH
+
+/*! \file mln/core/tag/skeleton.hh
+ *
+ * \brief Definition of tags used in the skeleton types associated to
+ * image types.
+ */
+
+
+namespace mln
+{
+
+ namespace tag
+ {
+
+ // With param.
+ template <typename I> struct image { typedef I param; };
+ template <typename V> struct value { typedef V param; };
+ template <typename P> struct psite { typedef P param; };
+ template <typename S> struct pset { typedef S param; };
+ template <typename D> struct data { typedef D param; };
+ template <typename F> struct function { typedef F param; };
+
+ // With value.
+ template <unsigned u> struct unsigned_ { enum { value = u }; };
+
+ } // end of namespace mln::tag
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_TAG_SKELETON_HH
Index: mln/value/stack.hh
--- mln/value/stack.hh (revision 1136)
+++ mln/value/stack.hh (working copy)
@@ -101,6 +101,10 @@
typedef mln::value::set<value> vset;
+ /// Skeleton.
+ typedef stack_image< tag::unsigned_<n>, tag::image<I> > skeleton;
+
+
/// Constructor.
stack_image(const metal::vec<n,I*>& imas);
@@ -125,14 +129,6 @@
/// Give the set of values of the image.
const vset& values() const;
- /// Change value type.
- template <typename U>
- struct change_value
- {
- typedef metal::vec<n,U> vec_n_U;
- typedef mln_ch_value(I, vec_n_U) ret;
- };
-
protected:
metal::vec<n,I*> imas_;
};
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Replace next prev by before after.
* dpoint1d.hh: Replace.
---
dpoint1d.hh | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
Index: trunk/milena/mln/core/dpoint1d.hh
===================================================================
--- trunk/milena/mln/core/dpoint1d.hh (revision 1135)
+++ trunk/milena/mln/core/dpoint1d.hh (revision 1136)
@@ -57,8 +57,11 @@
{
// FIXME: Doc!
- const dpoint1d prev = make::dpoint1d( -1 );
- const dpoint1d next = make::dpoint1d( +1 );
+ const dpoint1d before = make::dpoint1d( -1 );
+ const dpoint1d after = make::dpoint1d( +1 );
+
+ const dpoint1d ind_dec = before;
+ const dpoint1d ind_inc = after;
} // end of namespace mln
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
Replace and & or for g++-2.95.
* internal/tracked_ptr.hh: Replace.
---
tracked_ptr.hh | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Index: trunk/milena/mln/core/internal/tracked_ptr.hh
===================================================================
--- trunk/milena/mln/core/internal/tracked_ptr.hh (revision 1134)
+++ trunk/milena/mln/core/internal/tracked_ptr.hh (revision 1135)
@@ -29,7 +29,7 @@
# define MLN_CORE_INTERNAL_TRACKED_PTR_HH
# include <set>
-# include <ostream>
+# include <iostream>
# include <mln/core/contract.hh>
@@ -176,7 +176,7 @@
{
mln_invariant(run_());
mln_invariant(rhs.run_());
- if (&rhs == this or rhs.ptr_ == ptr_)
+ if (&rhs == this || rhs.ptr_ == ptr_)
// no-op
return *this;
clean_();
@@ -220,7 +220,7 @@
{
typedef std::set<tracked_ptr<T>*> holders_t;
- mln_invariant((ptr_ and holders_) or (not ptr_ and not holders_));
+ mln_invariant((ptr_ && holders_) || (! ptr_ && ! holders_));
if (ptr_ == 0)
return true;
mln_invariant(holders_->size() > 0);
1
0
19 Sep '07
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
add tracked pointer in image1d_b and image3d_b
* image1d_b.hh:
* image1d_b_data.hh:
* image3d_b.hh:
* image3d_b_data.hh: update image1d_b and image3d_b
---
image1d_b.hh | 116 ++++++++++--------------------------------
image1d_b_data.hh | 116 ++++++++++++++++++++++++++++++++++++++++++
image3d_b.hh | 147 +++++++++++-------------------------------------------
image3d_b_data.hh | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 317 insertions(+), 205 deletions(-)
Index: trunk/milena/mln/core/image1d_b_data.hh
===================================================================
--- trunk/milena/mln/core/image1d_b_data.hh (revision 0)
+++ trunk/milena/mln/core/image1d_b_data.hh (revision 1134)
@@ -0,0 +1,116 @@
+// 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_IMAGE1D_B_DATA_HH
+# define MLN_IMAGE1D_B_DATA_HH
+
+/*! \file mln/core/image1d_b_data.hh
+ *
+ * \brief Definition of the basic mln::image1d_b_data class.
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/core/box1d.hh>
+
+# include <mln/fun/i2v/all.hh>
+
+namespace mln
+{
+ template <typename T>
+ struct image1d_b_data
+ {
+ public:
+ image1d_b_data(const box1d& b, unsigned bdr);
+ ~image1d_b_data();
+
+ T* buffer_;
+ T* array_;
+
+ box1d b_; // theoretical box
+ unsigned bdr_;
+ box1d vb_; // virtual box, i.e., box including the virtual border
+
+ void update_vb_();
+ void allocate_();
+ void deallocate_();
+
+ };
+
+
+ template <typename T>
+ image1d_b_data<T>::image1d_b_data(const box1d& b, unsigned bdr)
+ : buffer_(0),
+ array_ (0),
+ b_ (b),
+ bdr_ (bdr)
+ {
+ allocate_();
+ }
+
+ template <typename T>
+ image1d_b_data<T>::~image1d_b_data()
+ {
+ deallocate_();
+ }
+
+
+ // private
+
+ template <typename T>
+ void
+ image1d_b_data<T>::update_vb_()
+ {
+ vb_.pmin() = b_.pmin() - dpoint1d(all(bdr_));
+ vb_.pmax() = b_.pmax() + dpoint1d(all(bdr_));
+ }
+
+ template <typename T>
+ void
+ image1d_b_data<T>::allocate_()
+ {
+ update_vb_();
+ unsigned
+ ni = vb_.len(0);
+ buffer_ = new T[ni];
+ array_ = buffer_ - vb_.pmin().ind();
+ mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
+ }
+
+ template <typename T>
+ void
+ image1d_b_data<T>::deallocate_()
+ {
+ if (buffer_)
+ {
+ delete[] buffer_;
+ buffer_ = 0;
+ }
+ }
+
+}
+
+#endif // ! MLN_IMAGE1D_B_DATA_HH
Index: trunk/milena/mln/core/image3d_b_data.hh
===================================================================
--- trunk/milena/mln/core/image3d_b_data.hh (revision 0)
+++ trunk/milena/mln/core/image3d_b_data.hh (revision 1134)
@@ -0,0 +1,143 @@
+// 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_IMAGE3D_B_DATA_HH
+# define MLN_IMAGE3D_B_DATA_HH
+
+/*! \file mln/core/image3d_b_data.hh
+ *
+ * \brief Definition of the basic mln::image3d_b_data class.
+ */
+
+# include <mln/core/box3d.hh>
+# include <mln/core/point.hh>
+
+# include <mln/fun/i2v/all.hh>
+
+namespace mln
+{
+ template <typename T>
+ struct image3d_b_data
+ {
+ public:
+ image3d_b_data(const box3d& b, unsigned bdr);
+ ~image3d_b_data();
+
+ T* buffer_;
+ T*** array_;
+
+ box3d b_; // theoretical box
+ unsigned bdr_;
+ box3d vb_; // virtual box, i.e., box including the virtual border
+
+ void update_vb_();
+ void allocate_();
+ void deallocate_();
+
+ };
+
+
+ template <typename T>
+ image3d_b_data<T>::image3d_b_data(const box3d& b, unsigned bdr)
+ : buffer_(0),
+ array_ (0),
+ b_ (b),
+ bdr_ (bdr)
+ {
+ allocate_();
+ }
+
+ template <typename T>
+ image3d_b_data<T>::~image3d_b_data()
+ {
+ deallocate_();
+ }
+
+ template <typename T>
+ void
+ image3d_b_data<T>::update_vb_()
+ {
+ vb_.pmin() = b_.pmin() - dpoint3d(all(bdr_));
+ vb_.pmax() = b_.pmax() + dpoint3d(all(bdr_));
+ }
+
+ template <typename T>
+ void
+ image3d_b_data<T>::allocate_()
+ {
+ update_vb_();
+ unsigned
+ ns = vb_.len(0),
+ nr = vb_.len(1),
+ nc = vb_.len(2);
+ buffer_ = new T[nr * nc * ns];
+ array_ = new T**[ns];
+ T* buf = buffer_ - vb_.pmin().col();
+ for (unsigned i = 0; i < ns; ++i)
+ {
+ T** tmp = new T*[nr];
+ array_[i] = tmp;
+ for (unsigned j = 0; j < nr; ++j)
+ {
+ array_[i][j] = buf;
+ buf += nc;
+ }
+ array_[i] -= vb_.pmin().row();
+ }
+ array_ -= vb_.pmin().sli();
+ mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
+ }
+
+ template <typename T>
+ void
+ image3d_b_data<T>::deallocate_()
+ {
+ if (buffer_)
+ {
+ delete[] buffer_;
+ buffer_ = 0;
+ }
+ for (typename point3d::coord i = vb_.pmin().sli(); i <= vb_.pmax().sli(); ++i)
+ {
+ if (array_[i])
+ {
+ array_[i] += vb_.pmin().row();
+ delete[] array_[i];
+ array_[i] = 0;
+ }
+ }
+ if (array_)
+ {
+ array_ += vb_.pmin().sli();
+ delete[] array_;
+ array_ = 0;
+ }
+ }
+
+}
+
+#endif // ! MLN_IMAGE3D_B_DATA_HH
Index: trunk/milena/mln/core/image1d_b.hh
===================================================================
--- trunk/milena/mln/core/image1d_b.hh (revision 1133)
+++ trunk/milena/mln/core/image1d_b.hh (revision 1134)
@@ -42,6 +42,9 @@
# include <mln/core/line_piter.hh>
+# include <mln/core/internal/tracked_ptr.hh>
+# include <mln/core/image1d_b_data.hh>
+
// FIXME:
// # include <mln/core/pixter1d_b.hh>
@@ -190,16 +193,7 @@
private:
- T* buffer_;
- T* array_;
-
- box1d b_; // theoretical box
- unsigned bdr_;
- box1d vb_; // virtual box, i.e., box including the virtual border
-
- void update_vb_();
- void allocate_();
- void deallocate_();
+ tracked_ptr< image1d_b_data<T> > data_;
typedef internal::image_base_< box1d, image1d_b<T> > super;
};
@@ -212,16 +206,13 @@
template <typename T>
image1d_b<T>::image1d_b()
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
- bdr_ = border::thickness; // default value in ctors.
}
template <typename T>
image1d_b<T>::image1d_b(int ninds, unsigned bdr)
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
init_with(ninds, bdr);
}
@@ -231,15 +222,12 @@
image1d_b<T>::init_with(int ninds, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = make::box1d(ninds);
- bdr_ = bdr;
- allocate_();
+ data_ = new image1d_b_data<T>(make::box1d(ninds), bdr);
}
template <typename T>
image1d_b<T>::image1d_b(const box1d& b, unsigned bdr)
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
init_with(b, bdr);
}
@@ -249,21 +237,14 @@
image1d_b<T>::init_with(const box1d& b, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = b;
- bdr_ = bdr;
- allocate_();
+ data_ = new image1d_b_data<T>(b, bdr);
}
template <typename T>
image1d_b<T>::image1d_b(const image1d_b<T>& rhs)
: super(rhs),
- b_(rhs.domain()),
- bdr_(rhs.border())
+ data_(rhs.data_)
{
- allocate_();
- std::memcpy(this->buffer_,
- rhs.buffer_,
- ncells() * sizeof(T));
}
// assignment
@@ -275,14 +256,8 @@
mln_precondition(rhs.has_data());
if (& rhs == this)
return *this;
- if (this->has_data())
- this->deallocate_();
- this->b_ = rhs.domain();
- this->bdr_ = rhs.border();
- allocate_();
- std::memcpy(this->buffer_,
- rhs.buffer_,
- ncells() * sizeof(T));
+
+ this->data_ = rhs.data_;
return *this;
}
@@ -292,7 +267,7 @@
bool
image1d_b<T>::has_data() const
{
- return buffer_ != 0 && array_ != 0;;
+ return data_ != 0;
}
template <typename T>
@@ -307,7 +282,7 @@
image1d_b<T>::domain() const
{
mln_precondition(this->has_data());
- return b_;
+ return data_->b_;
}
template <typename T>
@@ -315,7 +290,7 @@
image1d_b<T>::border() const
{
mln_precondition(this->has_data());
- return bdr_;
+ return data_->bdr_;
}
template <typename T>
@@ -323,19 +298,19 @@
image1d_b<T>::ncells() const
{
mln_precondition(this->has_data());
- return vb_.npoints();
+ return data_->vb_.npoints();
}
template <typename T>
bool
image1d_b<T>::owns_(const point1d& p) const
{
- if (! vb_.has(p))
+ if (! data_->vb_.has(p))
{
std::cout << " p = " << p << std::endl;
}
mln_precondition(this->has_data());
- return vb_.has(p);
+ return data_->vb_.has(p);
}
template <typename T>
@@ -343,7 +318,7 @@
image1d_b<T>::operator()(const point1d& p) const
{
mln_precondition(this->owns_(p));
- return array_[p.ind()];
+ return data_->array_[p.ind()];
}
template <typename T>
@@ -351,7 +326,7 @@
image1d_b<T>::operator()(const point1d& p)
{
mln_precondition(this->owns_(p));
- return array_[p.ind()];
+ return data_->array_[p.ind()];
}
template <typename T>
@@ -359,7 +334,7 @@
image1d_b<T>::operator[](unsigned o) const
{
mln_precondition(o < ncells());
- return *(buffer_ + o);
+ return *(data_->buffer_ + o);
}
template <typename T>
@@ -367,7 +342,7 @@
image1d_b<T>::operator[](unsigned o)
{
mln_precondition(o < ncells());
- return *(buffer_ + o);
+ return *(data_->buffer_ + o);
}
template <typename T>
@@ -375,7 +350,7 @@
image1d_b<T>::at(int ind) const
{
mln_precondition(this->owns_(make::point1d(ind)));
- return array_[ind];
+ return data_->array_[ind];
}
template <typename T>
@@ -383,13 +358,12 @@
image1d_b<T>::at(int ind)
{
mln_precondition(this->owns_(make::point1d(ind)));
- return array_[ind];
+ return data_->array_[ind];
}
template <typename T>
image1d_b<T>::~image1d_b()
{
- deallocate_();
}
template <typename T>
@@ -397,7 +371,7 @@
image1d_b<T>::buffer() const
{
mln_precondition(this->has_data());
- return buffer_;
+ return data_->buffer_;
}
template <typename T>
@@ -405,7 +379,7 @@
image1d_b<T>::buffer()
{
mln_precondition(this->has_data());
- return buffer_;
+ return data_->buffer_;
}
template <typename T>
@@ -422,45 +396,11 @@
image1d_b<T>::point_at_offset(unsigned o) const
{
mln_precondition(o < ncells());
- point1d p = make::point1d(o + vb_.min_ind());
- mln_postcondition(& this->operator()(p) == this->buffer_ + o);
+ point1d p = make::point1d(o + data_->vb_.min_ind());
+ mln_postcondition(& this->operator()(p) == this->data_->buffer_ + o);
return p;
}
-
- // private
-
- template <typename T>
- void
- image1d_b<T>::update_vb_()
- {
- vb_.pmin() = b_.pmin() - dpoint1d(all(bdr_));
- vb_.pmax() = b_.pmax() + dpoint1d(all(bdr_));
- }
-
- template <typename T>
- void
- image1d_b<T>::allocate_()
- {
- update_vb_();
- unsigned
- ni = vb_.len(0);
- buffer_ = new T[ni];
- array_ = buffer_ - vb_.pmin().ind();
- mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
- }
-
- template <typename T>
- void
- image1d_b<T>::deallocate_()
- {
- if (buffer_)
- {
- delete[] buffer_;
- buffer_ = 0;
- }
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
Index: trunk/milena/mln/core/image3d_b.hh
===================================================================
--- trunk/milena/mln/core/image3d_b.hh (revision 1133)
+++ trunk/milena/mln/core/image3d_b.hh (revision 1134)
@@ -42,6 +42,9 @@
# include <mln/core/line_piter.hh>
+# include <mln/core/internal/tracked_ptr.hh>
+# include <mln/core/image3d_b_data.hh>
+
// FIXME:
// # include <mln/core/pixter3d_b.hh>
@@ -190,16 +193,7 @@
private:
- T* buffer_;
- T*** array_;
-
- box3d b_; // theoretical box
- unsigned bdr_;
- box3d vb_; // virtual box, i.e., box including the virtual border
-
- void update_vb_();
- void allocate_();
- void deallocate_();
+ tracked_ptr< image3d_b_data<T> > data_;
typedef internal::image_base_< box3d, image3d_b<T> > super;
};
@@ -212,16 +206,14 @@
template <typename T>
image3d_b<T>::image3d_b()
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
- bdr_ = border::thickness; // default value in ctors.
+ data_->bdr_ = border::thickness; // default value in ctors.
}
template <typename T>
image3d_b<T>::image3d_b(int nslis, int nrows, int ncols, unsigned bdr)
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
init_with(nslis, nrows, ncols, bdr);
}
@@ -231,15 +223,12 @@
image3d_b<T>::init_with(int nslis, int nrows, int ncols, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = make::box3d(nslis, nrows, ncols);
- bdr_ = bdr;
- allocate_();
+ data_ = new image3d_b_data<T>(make::box3d(nslis, nrows, ncols), bdr);
}
template <typename T>
image3d_b<T>::image3d_b(const box3d& b, unsigned bdr)
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
init_with(b, bdr);
}
@@ -249,21 +238,14 @@
image3d_b<T>::init_with(const box3d& b, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = b;
- bdr_ = bdr;
- allocate_();
+ data_ = new image3d_b_data<T>(b, bdr);
}
template <typename T>
image3d_b<T>::image3d_b(const image3d_b<T>& rhs)
: super(rhs),
- b_(rhs.domain()),
- bdr_(rhs.border())
+ data_(rhs.data_)
{
- allocate_();
- std::memcpy(this->buffer_,
- rhs.buffer_,
- ncells() * sizeof(T));
}
// assignment
@@ -275,14 +257,8 @@
mln_precondition(rhs.has_data());
if (& rhs == this)
return *this;
- if (this->has_data())
- this->deallocate_();
- this->b_ = rhs.domain();
- this->bdr_ = rhs.border();
- allocate_();
- std::memcpy(this->buffer_,
- rhs.buffer_,
- ncells() * sizeof(T));
+
+ this->data_ = rhs.data_;
return *this;
}
@@ -292,7 +268,7 @@
bool
image3d_b<T>::has_data() const
{
- return buffer_ != 0 && array_ != 0;;
+ return data_ != 0;
}
template <typename T>
@@ -307,7 +283,7 @@
image3d_b<T>::domain() const
{
mln_precondition(this->has_data());
- return b_;
+ return data_->b_;
}
template <typename T>
@@ -315,7 +291,7 @@
image3d_b<T>::border() const
{
mln_precondition(this->has_data());
- return bdr_;
+ return data_->bdr_;
}
template <typename T>
@@ -323,7 +299,7 @@
image3d_b<T>::ncells() const
{
mln_precondition(this->has_data());
- return vb_.npoints();
+ return data_->vb_.npoints();
}
template <typename T>
@@ -331,7 +307,7 @@
image3d_b<T>::owns_(const point3d& p) const
{
mln_precondition(this->has_data());
- return vb_.has(p);
+ return data_->vb_.has(p);
}
template <typename T>
@@ -339,7 +315,7 @@
image3d_b<T>::operator()(const point3d& p) const
{
mln_precondition(this->owns_(p));
- return array_[p.sli()][p.row()][p.col()];
+ return data_->array_[p.sli()][p.row()][p.col()];
}
template <typename T>
@@ -347,7 +323,7 @@
image3d_b<T>::operator()(const point3d& p)
{
mln_precondition(this->owns_(p));
- return array_[p.sli()][p.row()][p.col()];
+ return data_->array_[p.sli()][p.row()][p.col()];
}
template <typename T>
@@ -355,7 +331,7 @@
image3d_b<T>::operator[](unsigned o) const
{
mln_precondition(o < ncells());
- return *(buffer_ + o);
+ return *(data_->buffer_ + o);
}
template <typename T>
@@ -363,7 +339,7 @@
image3d_b<T>::operator[](unsigned o)
{
mln_precondition(o < ncells());
- return *(buffer_ + o);
+ return *(data_->buffer_ + o);
}
template <typename T>
@@ -371,7 +347,7 @@
image3d_b<T>::at(int sli, int row, int col) const
{
mln_precondition(this->owns_(make::point3d(sli, row, col)));
- return array_[sli][row][col];
+ return data_->array_[sli][row][col];
}
template <typename T>
@@ -379,13 +355,12 @@
image3d_b<T>::at(int sli, int row, int col)
{
mln_precondition(this->owns_(make::point3d(sli, row, col)));
- return array_[sli][row][col];
+ return data_->array_[sli][row][col];
}
template <typename T>
image3d_b<T>::~image3d_b()
{
- deallocate_();
}
template <typename T>
@@ -393,7 +368,7 @@
image3d_b<T>::buffer() const
{
mln_precondition(this->has_data());
- return buffer_;
+ return data_->buffer_;
}
template <typename T>
@@ -401,7 +376,7 @@
image3d_b<T>::buffer()
{
mln_precondition(this->has_data());
- return buffer_;
+ return data_->buffer_;
}
template <typename T>
@@ -418,76 +393,14 @@
image3d_b<T>::point_at_offset(unsigned o) const
{
mln_precondition(o < ncells());
- point3d p = make::point3d(o / (vb_.len(1) * vb_.len(2)) + vb_.min_sli(),
- (o % (vb_.len(1) * vb_.len(2))) / vb_.len(2) + vb_.min_row(),
- o % vb_.len(2) + vb_.min_col());
- mln_postcondition(& this->operator()(p) == this->buffer_ + o);
+ point3d p = make::point3d(o / (data_->vb_.len(1) * data_->vb_.len(2)) + data_->vb_.min_sli(),
+ (o % (data_->vb_.len(1) * data_->vb_.len(2))) / data_->vb_.len(2) + data_->vb_.min_row(),
+ o % data_->vb_.len(2) + data_->vb_.min_col());
+ mln_postcondition(& this->operator()(p) == this->data_->buffer_ + o);
return p;
}
- // private
-
- template <typename T>
- void
- image3d_b<T>::update_vb_()
- {
- vb_.pmin() = b_.pmin() - dpoint3d(all(bdr_));
- vb_.pmax() = b_.pmax() + dpoint3d(all(bdr_));
- }
-
- template <typename T>
- void
- image3d_b<T>::allocate_()
- {
- update_vb_();
- unsigned
- ns = vb_.len(0),
- nr = vb_.len(1),
- nc = vb_.len(2);
- buffer_ = new T[nr * nc * ns];
- array_ = new T**[ns];
- T* buf = buffer_ - vb_.pmin().col();
- for (unsigned i = 0; i < ns; ++i)
- {
- T** tmp = new T*[nr];
- array_[i] = tmp;
- for (unsigned j = 0; j < nr; ++j)
- {
- array_[i][j] = buf;
- buf += nc;
- }
- array_[i] -= vb_.pmin().row();
- }
- array_ -= vb_.pmin().sli();
- mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
- }
-
- template <typename T>
- void
- image3d_b<T>::deallocate_()
- {
- if (buffer_)
- {
- delete[] buffer_;
- buffer_ = 0;
- }
- for (typename point::coord i = vb_.pmin().sli(); i <= vb_.pmax().sli(); ++i)
- {
- if (array_[i])
- {
- array_[i] += vb_.pmin().row();
- delete[] array_[i];
- array_[i] = 0;
- }
- }
- if (array_)
- {
- array_ += vb_.pmin().sli();
- delete[] array_;
- array_ = 0;
- }
- }
# endif // ! MLN_INCLUDE_ONLY
1
0
19 Sep '07
Matthieu Garrigues wrote:
> URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
>
> ChangeLog:
> 2007-09-19 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
>
> add tracked pointer for images
s/add tracked pointer for images/Add tracked pointer for images./
^ ^
> * image2d_b.hh:
no empty comment please
> * image2d_b_data.hh: move image data into an imaage2d_b_data class,
> then hold it with a tracked pointer to avoid useless data copy like
> in olena
s/move/Move/
^
s/olena/olena./
^
> * internal/tracked_ptr.hh: tracked pointer class from olena. fix a bug
> related to invariant_ call to optimize data access.
> ...
meta-q is your friend and avoid blank lines when inappropriate
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Matthieu Garrigues <garrigues(a)lrde.epita.fr>
add tracked pointer for images
* image2d_b.hh:
* image2d_b_data.hh: move image data into an imaage2d_b_data class,
then hold it with a tracked pointer to avoid useless data copy like
in olena
* internal/tracked_ptr.hh: tracked pointer class from olena. fix a bug
related to invariant_ call to optimize data access.
---
image2d_b.hh | 135 +++++------------------
image2d_b_data.hh | 131 ++++++++++++++++++++++
internal/tracked_ptr.hh | 281 ++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 443 insertions(+), 104 deletions(-)
Index: trunk/milena/mln/core/image2d_b_data.hh
===================================================================
--- trunk/milena/mln/core/image2d_b_data.hh (revision 0)
+++ trunk/milena/mln/core/image2d_b_data.hh (revision 1133)
@@ -0,0 +1,131 @@
+// 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_IMAGE2D_B_DATA_HH
+# define MLN_IMAGE2D_B_DATA_HH
+
+/*! \file mln/core/image2d_b_data.hh
+ *
+ * \brief Definition of the basic mln::image2d_b_data class.
+ */
+
+# include <mln/core/internal/image_base.hh>
+# include <mln/core/box2d.hh>
+
+# include <mln/fun/i2v/all.hh>
+
+namespace mln
+{
+ template <typename T>
+ struct image2d_b_data
+ {
+ public:
+ image2d_b_data(const box2d& b, unsigned bdr);
+ ~image2d_b_data();
+
+ T* buffer_;
+ T** array_;
+
+ box2d b_; // theoretical box
+ unsigned bdr_;
+ box2d vb_; // virtual box, i.e., box including the virtual border
+
+ void update_vb_();
+ void allocate_();
+ void deallocate_();
+
+ };
+
+
+ template <typename T>
+ image2d_b_data<T>::image2d_b_data(const box2d& b, unsigned bdr)
+ : buffer_(0),
+ array_ (0),
+ b_ (b),
+ bdr_ (bdr)
+ {
+ allocate_();
+ }
+
+ template <typename T>
+ image2d_b_data<T>::~image2d_b_data()
+ {
+ deallocate_();
+ }
+
+
+ // private
+
+ template <typename T>
+ void
+ image2d_b_data<T>::update_vb_()
+ {
+ vb_.pmin() = b_.pmin() - dpoint2d(all(bdr_));
+ vb_.pmax() = b_.pmax() + dpoint2d(all(bdr_));
+ }
+
+ template <typename T>
+ void
+ image2d_b_data<T>::allocate_()
+ {
+ update_vb_();
+ unsigned
+ nr = vb_.len(0),
+ nc = vb_.len(1);
+ buffer_ = new T[nr * nc];
+ array_ = new T*[nr];
+ T* buf = buffer_ - vb_.pmin().col();
+ for (unsigned i = 0; i < nr; ++i)
+ {
+ array_[i] = buf;
+ buf += nc;
+ }
+ array_ -= vb_.pmin().row();
+ mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
+ mln_postcondition(vb_.len(1) == b_.len(1) + 2 * bdr_);
+ }
+
+ template <typename T>
+ void
+ image2d_b_data<T>::deallocate_()
+ {
+ if (buffer_)
+ {
+ delete[] buffer_;
+ buffer_ = 0;
+ }
+ if (array_)
+ {
+ array_ += vb_.pmin().row();
+ delete[] array_;
+ array_ = 0;
+ }
+ }
+
+}
+
+#endif // ! MLN_IMAGE2D_B_DATA_HH
Index: trunk/milena/mln/core/internal/tracked_ptr.hh
===================================================================
--- trunk/milena/mln/core/internal/tracked_ptr.hh (revision 0)
+++ trunk/milena/mln/core/internal/tracked_ptr.hh (revision 1133)
@@ -0,0 +1,281 @@
+// Copyright (C) 2006 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_INTERNAL_TRACKED_PTR_HH
+# define MLN_CORE_INTERNAL_TRACKED_PTR_HH
+
+# include <set>
+# include <ostream>
+
+# include <mln/core/contract.hh>
+
+
+namespace mln
+{
+
+ template <typename T>
+ struct tracked_ptr
+ {
+ typedef tracked_ptr<T> self_t;
+ typedef std::set<self_t*> holders_t;
+
+ T* ptr_;
+ holders_t* holders_;
+
+ /// Coercion towards Boolean (for arithmetical tests).
+ operator bool() const;
+
+ /// Negation (for arithmetical tests).
+ bool operator not() const;
+
+ /*! \brief Mimics the behavior of op-> for a pointer in the const case.
+ **
+ ** \invariant Pointer proxy exists.
+ */
+ const T*const operator->() const;
+
+ /*! \brief Mimics the behavior of op-> for a pointer in the mutable case.
+ **
+ ** \invariant Pointer proxy exists.
+ */
+ T*const operator->();
+
+ /// Ctor.
+ tracked_ptr();
+
+ /// Ctor.
+ tracked_ptr(T* ptr);
+
+ /// Cpy ctor.
+ tracked_ptr(const tracked_ptr<T>& rhs);
+
+ /// Assignment.
+ tracked_ptr<T>& operator=(const tracked_ptr<T>& rhs);
+
+ /// Assignment.
+ tracked_ptr<T>& operator=(T* ptr);
+
+ /// Dtor.
+ ~tracked_ptr();
+
+ bool run_() const;
+
+ void clean_();
+
+ };
+
+
+
+
+# ifndef MLN_INCLUDE_ONLY
+
+ template <typename T>
+ tracked_ptr<T>::operator bool() const
+ {
+ mln_invariant(run_());
+ return ptr_ != 0;
+ }
+
+ template <typename T>
+ /// Negation (for arithmetical tests).
+ bool tracked_ptr<T>::operator not() const
+ {
+ mln_invariant(run_());
+ return not bool(*this);
+ }
+
+ template <typename T>
+ /*! \brief Mimics the behavior of op-> for a pointer in the const case.
+ **
+ ** \invariant Pointer proxy exists.
+ */
+ const T*const tracked_ptr<T>::operator->() const
+ {
+ mln_invariant(run_());
+ mln_precondition(ptr_ != 0);
+ return ptr_;
+ }
+
+ template <typename T>
+ /*! \brief Mimics the behavior of op-> for a pointer in the mutable case.
+ **
+ ** \invariant Pointer proxy exists.
+ */
+ T*const tracked_ptr<T>::operator->()
+ {
+ mln_invariant(run_());
+ mln_precondition(ptr_ != 0);
+ return ptr_;
+ }
+
+ template <typename T>
+ /// Ctor.
+ tracked_ptr<T>::tracked_ptr() :
+ ptr_(0),
+ holders_(0)
+ {
+ mln_invariant(run_());
+ }
+
+ template <typename T>
+ /// Ctor.
+ tracked_ptr<T>::tracked_ptr(T* ptr) :
+ ptr_(ptr)
+ {
+ typedef std::set<tracked_ptr<T>*> holders_t;
+
+ if (ptr == 0)
+ holders_ = 0;
+ else
+ {
+ holders_ = new holders_t;
+ holders_->insert(this);
+ }
+ mln_invariant(run_());
+ }
+
+ template <typename T>
+ /// Cpy ctor.
+ tracked_ptr<T>::tracked_ptr(const tracked_ptr<T>& rhs) :
+ ptr_(rhs.ptr_),
+ holders_(rhs.holders_)
+ {
+ mln_invariant(rhs.run_());
+ if (ptr_ != 0)
+ holders_->insert(this);
+ mln_invariant(run_());
+ }
+
+ template <typename T>
+ /// Assignment.
+ tracked_ptr<T>& tracked_ptr<T>::operator=(const tracked_ptr<T>& rhs)
+ {
+ mln_invariant(run_());
+ mln_invariant(rhs.run_());
+ if (&rhs == this or rhs.ptr_ == ptr_)
+ // no-op
+ return *this;
+ clean_();
+ ptr_ = rhs.ptr_;
+ holders_ = rhs.holders_;
+ holders_->insert(this);
+ return *this;
+ }
+
+ template <typename T>
+ /// Assignment.
+ tracked_ptr<T>& tracked_ptr<T>::operator=(T* ptr)
+ {
+ typedef std::set<tracked_ptr<T>*> holders_t;
+
+ mln_invariant(run_());
+ if (ptr == ptr_)
+ // no-op
+ return *this;
+ clean_();
+ ptr_ = ptr;
+ if (ptr == 0)
+ holders_ = 0;
+ else
+ {
+ holders_ = new holders_t;
+ holders_->insert(this);
+ }
+ return *this;
+ }
+
+ /// Dtor.
+ template <typename T>
+ tracked_ptr<T>::~tracked_ptr()
+ {
+ clean_();
+ }
+
+ template <typename T>
+ bool tracked_ptr<T>::run_() const
+ {
+ typedef std::set<tracked_ptr<T>*> holders_t;
+
+ mln_invariant((ptr_ and holders_) or (not ptr_ and not holders_));
+ if (ptr_ == 0)
+ return true;
+ mln_invariant(holders_->size() > 0);
+ tracked_ptr<T>* this_ = const_cast<tracked_ptr<T>*>(this);
+ mln_invariant(holders_->find(this_) != holders_->end());
+ this_ = 0;
+ typename holders_t::const_iterator i;
+ for (i = holders_->begin(); i != holders_->end(); ++i)
+ mln_invariant((*i)->ptr_ == ptr_);
+ return true;
+ }
+
+ template <typename T>
+ void tracked_ptr<T>::clean_()
+ {
+ mln_invariant(run_());
+ if (ptr_ == 0)
+ // no-op
+ return;
+ if (holders_->size() == 1)
+ {
+ delete ptr_;
+ delete holders_;
+ }
+ else
+ holders_->erase(this);
+ ptr_ = 0;
+ holders_ = 0;
+ mln_invariant(run_());
+ }
+
+ template <typename T>
+ std::ostream& operator<<(std::ostream& ostr, const tracked_ptr<T>& tp)
+ {
+ typedef std::set<tracked_ptr<T>*> holders_t;
+
+ ostr << "tracked_ptr @ " << (&tp)
+ << " { ptr = " << tp.ptr_
+ << " / holders = ";
+ if (tp.holders_ == 0)
+ ostr << "0";
+ else
+ {
+ typename holders_t::const_iterator i;
+ for (i = tp.holders_->begin(); i != tp.holders_->end(); ++i)
+ ostr << (*i) << ' ';
+ }
+ ostr << " }";
+ return ostr;
+ }
+
+
+# endif
+
+} // end of namespace mln
+
+
+#endif // ! MLN_CORE_INTERNAL_TRACKED_PTR_HH
Index: trunk/milena/mln/core/image2d_b.hh
===================================================================
--- trunk/milena/mln/core/image2d_b.hh (revision 1132)
+++ trunk/milena/mln/core/image2d_b.hh (revision 1133)
@@ -42,6 +42,9 @@
# include <mln/core/line_piter.hh>
+# include <mln/core/internal/tracked_ptr.hh>
+# include <mln/core/image2d_b_data.hh>
+
// FIXME:
// # include <mln/core/pixter2d_b.hh>
@@ -128,6 +131,9 @@
/// Destructor.
~image2d_b();
+ /// detach data from an image (free it if nobody else hold it)
+ void destroy();
+
/// Initialize an empty image.
void init_with(int nrows, int ncols, unsigned bdr = border::thickness);
@@ -190,16 +196,7 @@
private:
- T* buffer_;
- T** array_;
-
- box2d b_; // theoretical box
- unsigned bdr_;
- box2d vb_; // virtual box, i.e., box including the virtual border
-
- void update_vb_();
- void allocate_();
- void deallocate_();
+ tracked_ptr< image2d_b_data<T> > data_;
typedef internal::image_base_< box2d, image2d_b<T> > super;
};
@@ -212,16 +209,13 @@
template <typename T>
image2d_b<T>::image2d_b()
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
- bdr_ = border::thickness; // default value in ctors.
}
template <typename T>
image2d_b<T>::image2d_b(int nrows, int ncols, unsigned bdr)
- : buffer_(0),
- array_ (0)
+ : data_(0)
{
init_with(nrows, ncols, bdr);
}
@@ -231,15 +225,11 @@
image2d_b<T>::init_with(int nrows, int ncols, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = make::box2d(nrows, ncols);
- bdr_ = bdr;
- allocate_();
+ data_ = new image2d_b_data<T>(make::box2d(nrows, ncols), bdr);
}
template <typename T>
image2d_b<T>::image2d_b(const box2d& b, unsigned bdr)
- : buffer_(0),
- array_ (0)
{
init_with(b, bdr);
}
@@ -249,21 +239,14 @@
image2d_b<T>::init_with(const box2d& b, unsigned bdr)
{
mln_precondition(! this->has_data());
- b_ = b;
- bdr_ = bdr;
- allocate_();
+ data_ = new image2d_b_data<T>(b, bdr);
}
template <typename T>
image2d_b<T>::image2d_b(const image2d_b<T>& rhs)
: super(rhs),
- b_(rhs.domain()),
- bdr_(rhs.border())
+ data_(rhs.data_)
{
- allocate_();
- std::memcpy(this->buffer_,
- rhs.buffer_,
- ncells() * sizeof(T));
}
// assignment
@@ -275,14 +258,8 @@
mln_precondition(rhs.has_data());
if (& rhs == this)
return *this;
- if (this->has_data())
- this->deallocate_();
- this->b_ = rhs.domain();
- this->bdr_ = rhs.border();
- allocate_();
- std::memcpy(this->buffer_,
- rhs.buffer_,
- ncells() * sizeof(T));
+
+ this->data_ = rhs.data_;
return *this;
}
@@ -292,7 +269,7 @@
bool
image2d_b<T>::has_data() const
{
- return buffer_ != 0 && array_ != 0;
+ return data_ != 0;
}
template <typename T>
@@ -307,7 +284,7 @@
image2d_b<T>::domain() const
{
mln_precondition(this->has_data());
- return b_;
+ return data_->b_;
}
template <typename T>
@@ -315,7 +292,7 @@
image2d_b<T>::border() const
{
mln_precondition(this->has_data());
- return bdr_;
+ return data_->bdr_;
}
template <typename T>
@@ -323,7 +300,7 @@
image2d_b<T>::ncells() const
{
mln_precondition(this->has_data());
- return vb_.npoints();
+ return data_->vb_.npoints();
}
template <typename T>
@@ -331,7 +308,7 @@
image2d_b<T>::owns_(const point2d& p) const
{
mln_precondition(this->has_data());
- return vb_.has(p);
+ return data_->vb_.has(p);
}
template <typename T>
@@ -339,7 +316,7 @@
image2d_b<T>::operator()(const point2d& p) const
{
mln_precondition(this->owns_(p));
- return array_[p.row()][p.col()];
+ return data_->array_[p.row()][p.col()];
}
template <typename T>
@@ -347,7 +324,7 @@
image2d_b<T>::operator()(const point2d& p)
{
mln_precondition(this->owns_(p));
- return array_[p.row()][p.col()];
+ return data_->array_[p.row()][p.col()];
}
template <typename T>
@@ -355,7 +332,7 @@
image2d_b<T>::operator[](unsigned o) const
{
mln_precondition(o < ncells());
- return *(buffer_ + o);
+ return *(data_->buffer_ + o);
}
template <typename T>
@@ -363,7 +340,7 @@
image2d_b<T>::operator[](unsigned o)
{
mln_precondition(o < ncells());
- return *(buffer_ + o);
+ return *(data_->buffer_ + o);
}
template <typename T>
@@ -371,7 +348,7 @@
image2d_b<T>::at(int row, int col) const
{
mln_precondition(this->owns_(make::point2d(row, col)));
- return array_[row][col];
+ return data_->array_[row][col];
}
template <typename T>
@@ -379,13 +356,12 @@
image2d_b<T>::at(int row, int col)
{
mln_precondition(this->owns_(make::point2d(row, col)));
- return array_[row][col];
+ return data_->array_[row][col];
}
template <typename T>
image2d_b<T>::~image2d_b()
{
- deallocate_();
}
template <typename T>
@@ -393,7 +369,7 @@
image2d_b<T>::buffer() const
{
mln_precondition(this->has_data());
- return buffer_;
+ return data_->buffer_;
}
template <typename T>
@@ -401,7 +377,7 @@
image2d_b<T>::buffer()
{
mln_precondition(this->has_data());
- return buffer_;
+ return data_->buffer_;
}
template <typename T>
@@ -409,7 +385,7 @@
image2d_b<T>::offset(const dpoint2d& dp) const
{
mln_precondition(this->has_data());
- int o = dp[0] * vb_.len(1) + dp[1];
+ int o = dp[0] * data_->vb_.len(1) + dp[1];
return o;
}
@@ -418,61 +394,12 @@
image2d_b<T>::point_at_offset(unsigned o) const
{
mln_precondition(o < ncells());
- point2d p = make::point2d(o / vb_.len(1) + vb_.min_row(),
- o % vb_.len(1) + vb_.min_col());
- mln_postcondition(& this->operator()(p) == this->buffer_ + o);
+ point2d p = make::point2d(o / data_->vb_.len(1) + data_->vb_.min_row(),
+ o % data_->vb_.len(1) + data_->vb_.min_col());
+ mln_postcondition(& this->operator()(p) == this->data_->buffer_ + o);
return p;
}
-
- // private
-
- template <typename T>
- void
- image2d_b<T>::update_vb_()
- {
- vb_.pmin() = b_.pmin() - dpoint2d(all(bdr_));
- vb_.pmax() = b_.pmax() + dpoint2d(all(bdr_));
- }
-
- template <typename T>
- void
- image2d_b<T>::allocate_()
- {
- update_vb_();
- unsigned
- nr = vb_.len(0),
- nc = vb_.len(1);
- buffer_ = new T[nr * nc];
- array_ = new T*[nr];
- T* buf = buffer_ - vb_.pmin().col();
- for (unsigned i = 0; i < nr; ++i)
- {
- array_[i] = buf;
- buf += nc;
- }
- array_ -= vb_.pmin().row();
- mln_postcondition(vb_.len(0) == b_.len(0) + 2 * bdr_);
- mln_postcondition(vb_.len(1) == b_.len(1) + 2 * bdr_);
- }
-
- template <typename T>
- void
- image2d_b<T>::deallocate_()
- {
- if (buffer_)
- {
- delete[] buffer_;
- buffer_ = 0;
- }
- if (array_)
- {
- array_ += vb_.pmin().row();
- delete[] array_;
- array_ = 0;
- }
- }
-
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Bug fixed on 3d building by array
* mln/make/w_window3d.hh: Fix.
* mln/make/w_window3d_int.hh: Fix.
* mln/make/window3d.hh: Fix.
* tests/w_window3d_int.cc: Update.
---
mln/make/w_window3d.hh | 19 ++++++++++---------
mln/make/w_window3d_int.hh | 12 ++++++------
mln/make/window3d.hh | 17 ++++++++---------
tests/w_window3d_int.cc | 14 ++++++++------
4 files changed, 32 insertions(+), 30 deletions(-)
Index: trunk/milena/tests/w_window3d_int.cc
===================================================================
--- trunk/milena/tests/w_window3d_int.cc (revision 1131)
+++ trunk/milena/tests/w_window3d_int.cc (revision 1132)
@@ -53,18 +53,20 @@
using namespace mln;
{
- int ws[3][9] = {{-3, -2, -3,
+ int ws[27] = {-3, -2, -3,
-2, 1, -2,
- -3, -2, -3},
- { 2, 0, -2,
+ -3, -2, -3,
+ 2, 0, -2,
0, 0, 0,
- 2, 0, -2},
- { 3, 2, 3,
+ 2, 0, -2,
+ 3, 2, 3,
2, -1, 2,
- 3, 2, 3}};
+ 3, 2, 3};
w_window3d_int w_win = make::w_window3d(ws);
image3d_b<int> ima = convert::to_image(w_win);
+ debug::println(ima);
+ std::cout << std::endl;
w_window3d_int w_win_2 = convert::to_w_window(ima);
mln_assertion(w_win_2 == w_win);
}
Index: trunk/milena/mln/make/w_window3d.hh
===================================================================
--- trunk/milena/mln/make/w_window3d.hh (revision 1131)
+++ trunk/milena/mln/make/w_window3d.hh (revision 1132)
@@ -38,6 +38,7 @@
# include <mln/core/w_window.hh>
# include <mln/core/dpoint3d.hh>
+#include <iostream>
namespace mln
{
@@ -49,30 +50,30 @@
*
* \param[in] weights Array.
*
- * \pre The array size, \c M, has to be an odd integer.
- * \pre The array size, \c N, has to be the square of \c M.
+ * \pre The array size, \c M, has to be a cube of an odd integer.
*
* \return A 3D weighted window.
*/
- template <typename W, unsigned M, unsigned N>
- mln::w_window<mln::dpoint3d, W> w_window3d(W (&weights)[M][N]);
+ template <typename W, unsigned M>
+ mln::w_window<mln::dpoint3d, W> w_window3d(W (&weights)[M]);
# ifndef MLN_INCLUDE_ONLY
- template <typename W, unsigned M, unsigned N>
+ template <typename W, unsigned M>
mln::w_window<mln::dpoint3d, W>
- w_window3d(W (&weights)[M][N])
+ w_window3d(W (&weights)[M])
{
- int h = M / 2;
- mln_precondition(1 == (M % 2) && M * M == N);
+ int h = unsigned(std::pow(float(M), float(1. / 3))) / 2;
+ mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M);
mln::w_window<mln::dpoint3d, W> tmp;
unsigned i = 0;
for (int sli = - h; sli <= h; ++sli)
for (int row = - h; row <= h; ++row)
for (int col = - h; col <= h; ++col)
{
- const W& cur = weights[i / N][i % N];
+ const W& cur = weights[i];
+
if (cur != 0)
tmp.insert(cur, make::dpoint3d(sli, row, col));
i++;
Index: trunk/milena/mln/make/w_window3d_int.hh
===================================================================
--- trunk/milena/mln/make/w_window3d_int.hh (revision 1131)
+++ trunk/milena/mln/make/w_window3d_int.hh (revision 1132)
@@ -47,22 +47,22 @@
*
* \param[in] weights Array of integers.
*
- * \pre The array size, \c M, has to be an odd integer.
- * \pre The array size, \c N, has to be the square of \c M.
+ * \pre The array size, \c M, has to be a cube of an odd integer.
*
* \return A 3D int-weighted window.
*/
- template <unsigned M, unsigned N>
+ template <unsigned M>
mln::w_window3d_int w_window3d_int(int (&weights)[M][N]);
# ifndef MLN_INCLUDE_ONLY
- template <unsigned M, unsigned N>
+ template <unsigned M>
mln::w_window3d_int
- w_window3d_int(int (&weights)[M][N])
+ w_window3d_int(int (&weights)[M])
{
- mln_precondition(1 == (M % 2) && M * M == N);
+ int h = unsigned(std::pow(float(M), 1 / 3)) / 2;
+ mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M);
return make::w_window3d(weights);
}
Index: trunk/milena/mln/make/window3d.hh
===================================================================
--- trunk/milena/mln/make/window3d.hh (revision 1131)
+++ trunk/milena/mln/make/window3d.hh (revision 1132)
@@ -48,28 +48,27 @@
*
* \param[in] values Array of Booleans.
*
- * \pre The array size, \c M, has to be an odd integer.
- * \pre The array size, \c N, has to be the square of \c N.
+ * \pre The array size, \c M, has to be a cube of an odd integer.
*
* \return A 3D window.
*/
- template <unsigned M, unsigned N>
- mln::window3d window3d(bool (&values)[M][N]);
+ template <unsigned M>
+ mln::window3d window3d(bool (&values)[M]);
# ifndef MLN_INCLUDE_ONLY
- template <unsigned M, unsigned N>
- mln::window3d window3d(bool (&values)[M][N])
+ template <unsigned M>
+ mln::window3d window3d(bool (&values)[M])
{
- int h = M / 2;
- mln_precondition((M % 2) == 1 && M * M == N);
+ int h = unsigned(std::pow(float(M), 1 / 3)) / 2;
+ mln_precondition((2 * h + 1) * (2 * h + 1) * (2 * h + 1) == M);
mln::window3d tmp;
unsigned i = 0;
for (int sli = - h; sli <= h; ++sli)
for (int row = - h; row <= h; ++row)
for (int col = - h; col <= h; ++col)
- if (values[i / N][i++ % N])
+ if (values[i++])
tmp.insert(make::dpoint3d(sli, row, col));
return tmp;
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena
ChangeLog:
2007-09-19 Simon Nivault <simon.nivault(a)lrde.epita.fr>
Buf fixed on interpolated image.
* mln/core/interpolated.hh: Fix.
---
interpolated.hh | 36 ++++++++++++------------------------
1 file changed, 12 insertions(+), 24 deletions(-)
Index: trunk/milena/mln/core/interpolated.hh
===================================================================
--- trunk/milena/mln/core/interpolated.hh (revision 1130)
+++ trunk/milena/mln/core/interpolated.hh (revision 1131)
@@ -55,7 +55,7 @@
typedef mln_value(I) value;
/// Return type of read-write access.
- typedef mln_lvalue(I) lvalue;
+ typedef mln_lvalue(I) lvalue; // FIXME: Depends on lvalue presence in I.
/// Return type of read-only access.
typedef mln_rvalue(I) rvalue;
@@ -66,7 +66,7 @@
/// Constructor.
- interpolated(const Image<I>& ima);
+ interpolated(I& ima);
/// Test if this image has been initialized.
@@ -79,14 +79,13 @@
const mln_pset(I)& domain() const;
/// Read-only access of pixel value at point site \p p.
- mln_value(I) operator()(const psite& p) const;
+ mln_rvalue(I) operator()(const psite& p) const;
/// Mutable access is only OK for reading (not writing).
- mln_value(I) operator()(const psite& p);
+ mln_lvalue(I) operator()(const psite& p);
- mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v) const;
- mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v);
+ mln_value(I) operator()(const mln::metal::vec<I::point::dim, float>& v) const;
/// Give the set of values of the image.
@@ -100,7 +99,7 @@
};
protected:
- const I& ima_;
+ I& ima_;
};
@@ -108,10 +107,10 @@
# ifndef MLN_INCLUDE_ONLY
template <typename I>
- interpolated<I>::interpolated(const Image<I>& ima)
- : ima_(exact(ima))
+ interpolated<I>::interpolated(I& ima)
+ : ima_(ima)
{
- mln_precondition(exact(ima).has_data());
+ mln_precondition(ima.has_data());
}
template <typename I>
@@ -135,7 +134,7 @@
}
template <typename I>
- mln_value(I)
+ mln_rvalue(I)
interpolated<I>::operator()(const psite& p) const
{
mln_precondition(ima_.owns_(p));
@@ -143,7 +142,7 @@
}
template <typename I>
- mln_value(I)
+ mln_lvalue(I)
interpolated<I>::operator()(const psite& p)
{
return ima_(p);
@@ -157,18 +156,7 @@
for (unsigned i = 0; i < I::point::dim; ++i)
p[i] = static_cast<int>(round(v[i]));
mln_assertion(ima_.owns_(p));
- return (ima_(p));
- }
-
- template <typename I>
- mln_value(I)
- interpolated<I>::operator()(const mln::metal::vec<I::point::dim, float>& v)
- {
- mln_point(I) p;
- for (unsigned i = 0; i < I::point::dim; ++i)
- p[i] = static_cast<int>(round(v[i]));
- mln_assertion(ima_.owns_(p));
- return (ima_(p));
+ return ima_(p);
}
template <typename I>
1
0