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;
}