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
February 2009
- 12 participants
- 266 discussions
23 Feb '09
* mln/io/pbm/load.hh,
* mln/io/pgm/load.hh,
* mln/io/ppm/load.hh: load a list of 2D image files and build a 3D
image from that.
* tests/io/pbm/pbm.cc,
* tests/io/pgm/pgm.cc,
* tests/io/ppm/ppm.cc: update tests.
---
milena/ChangeLog | 13 +++++++
milena/mln/io/pbm/load.hh | 38 ++++++++++++++++++++-
milena/mln/io/pgm/load.hh | 67 +++++++++++++++++++++++++++++---------
milena/mln/io/ppm/load.hh | 77 ++++++++++++++++++++++++++++++-------------
milena/tests/io/pbm/pbm.cc | 30 +++++++++++++----
milena/tests/io/pgm/pgm.cc | 35 +++++++++++++++++---
milena/tests/io/ppm/ppm.cc | 33 ++++++++++++++++---
7 files changed, 235 insertions(+), 58 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4868689..556e3ec 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2009-02-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add new routines to make a 3D image from a list of files.
+
+ * mln/io/pbm/load.hh,
+ * mln/io/pgm/load.hh,
+ * mln/io/ppm/load.hh: load a list of 2D image files and build a 3D
+ image from that.
+
+ * tests/io/pbm/pbm.cc,
+ * tests/io/pgm/pgm.cc,
+ * tests/io/ppm/ppm.cc: update tests.
+
+2009-02-23 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add more trace::warning in labeling canvas.
* mln/canvas/labeling.hh: add new trace::warnings.
diff --git a/milena/mln/io/pbm/load.hh b/milena/mln/io/pbm/load.hh
index ea9e78c..81ad23d 100644
--- a/milena/mln/io/pbm/load.hh
+++ b/milena/mln/io/pbm/load.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA
-// Research and Development Laboratory (LRDE)
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -40,8 +40,11 @@
# include <string>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/io/pnm/load_header.hh>
+# include <mln/make/image3d.hh>
+
namespace mln
{
@@ -69,6 +72,14 @@ namespace mln
///
image2d<bool> load(const std::string& filename);
+ /// Load ppm images as slices of a 3D Milena image.
+ ///
+ /// \param[out] ima A reference to the 3D image which will receive
+ /// data.
+ /// \param[in] filenames The list of 2D images to load..
+ void load(image3d<bool>& ima,
+ const util::array<std::string>& filenames);
+
# ifndef MLN_INCLUDE_ONLY
namespace internal
@@ -160,6 +171,29 @@ namespace mln
ima = load(filename);
}
+
+ inline
+ void load(image3d<bool>& ima,
+ const util::array<std::string>& filenames)
+ {
+ trace::entering("mln::io::pbm::load");
+ mln_precondition(!filenames.is_empty());
+
+ util::array<image2d<bool> > slices;
+
+ for (unsigned i = 0; i < filenames.nelements(); ++i)
+ {
+ image2d<bool> tmp;
+ io::pbm::load(tmp, filenames[i]);
+ slices.append(tmp);
+ }
+
+ ima = make::image3d(slices);
+
+ trace::exiting("mln::io::pbm::load");
+ }
+
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::pbm
diff --git a/milena/mln/io/pgm/load.hh b/milena/mln/io/pgm/load.hh
index a82f5b5..c69349c 100644
--- a/milena/mln/io/pgm/load.hh
+++ b/milena/mln/io/pgm/load.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -42,11 +42,13 @@
# include <string>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/value/int_u8.hh>
# include <mln/io/pnm/load.hh>
+# include <mln/make/image3d.hh>
namespace mln
{
@@ -57,28 +59,38 @@ namespace mln
namespace pgm
{
- /*! Load a pgm image in a Milena image.
- *
- * \param[out] ima A reference to the image which will receive
- * data.
- * \param[in] filename The source.
- */
+ /// Load a pgm image in a Milena image.
+ ///
+ /// \param[out] ima A reference to the image which will receive
+ /// data.
+ /// \param[in] filename The source.
template <typename I>
void load(Image<I>& ima,
const std::string& filename);
- /*! Load a pgm image in a Milena image. To use this routine, you
- * should specialize the template whith the value type of the
- * image loaded. (ex : load<value::int_u8>("...") )
- *
- * \param[in] filename The image source.
- *
- * \return An image2d which contains loaded data.
- */
+ /// Load a pgm image in a Milena image. To use this routine, you
+ /// should specialize the template whith the value type of the
+ /// image loaded. (ex : load<value::int_u8>("...") )
+ ///
+ /// \param[in] filename The image source.
+ ///
+ /// \return An image2d which contains loaded data.
template <typename V>
image2d<V> load(const std::string& filename);
+
+ /// Load ppm images as slices of a 3D Milena image.
+ ///
+ /// \param[out] ima A reference to the 3D image which will receive
+ /// data.
+ /// \param[in] filenames The list of 2D images to load..
+ ///
+ template <typename V>
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames);
+
+
# ifndef MLN_INCLUDE_ONLY
template <typename V>
@@ -101,6 +113,29 @@ namespace mln
trace::exiting("mln::io::pgm::load");
}
+
+ template <typename V>
+ inline
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames)
+ {
+ trace::entering("mln::io::pgm::load");
+ mln_precondition(!filenames.is_empty());
+
+ util::array<image2d<V> > slices;
+
+ for (unsigned i = 0; i < filenames.nelements(); ++i)
+ {
+ image2d<V> tmp;
+ io::pnm::load<image2d<V> >(PGM, tmp, filenames[i]);
+ slices.append(tmp);
+ }
+
+ ima = make::image3d(slices);
+
+ trace::exiting("mln::io::pgm::load");
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::pgm
diff --git a/milena/mln/io/ppm/load.hh b/milena/mln/io/ppm/load.hh
index bf9d27b..291eaf8 100644
--- a/milena/mln/io/ppm/load.hh
+++ b/milena/mln/io/ppm/load.hh
@@ -1,5 +1,5 @@
-// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008 EPITA
-// Research and Development Laboratory
+// Copyright (C) 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
+// EPITA Research and Development Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -29,23 +29,23 @@
#ifndef MLN_IO_PPM_LOAD_HH
# define MLN_IO_PPM_LOAD_HH
-/*!
- * \file mln/io/ppm/load.hh
- *
- * \brief Define a function which loads an image of kind ppm with
- * given path.
- *
- */
+/// \file mln/io/ppm/load.hh
+///
+/// Define a function which loads an image of kind ppm with
+/// given path.
# include <iostream>
# include <fstream>
# include <string>
# include <mln/core/image/image2d.hh>
+# include <mln/core/image/image3d.hh>
# include <mln/value/rgb8.hh>
# include <mln/io/pnm/load.hh>
+# include <mln/make/image3d.hh>
+
namespace mln
{
@@ -55,27 +55,36 @@ namespace mln
namespace ppm
{
- /*! Load a ppm image in a Milena image.
- *
- * \param[out] ima A reference to the image which will receive
- * data.
- * \param[in] filename The source.
- */
+ /// Load a ppm image in a Milena image.
+ ///
+ /// \param[out] ima A reference to the image which will receive
+ /// data.
+ /// \param[in] filename The source.
template <typename I>
void load(Image<I>& ima,
const std::string& filename);
- /*! Load a ppm image in a Milena image. To use this routine, you
- * should specialize the template whith the value type of the
- * image loaded. (ex : load<value::int_u8>("...") )
- *
- * \param[in] filename The image source.
- *
- * \return An image2d which contains loaded data.
- */
+ /// Load a ppm image in a Milena image. To use this routine, you
+ /// should specialize the template whith the value type of the
+ /// image loaded. (ex : load<value::int_u8>("..."))
+ ///
+ /// \param[in] filename The image source.
+ ///
+ /// \return An image2d which contains loaded data.
+ ///
template <typename V>
image2d<V> load(const std::string& filename);
+
+ /// Load ppm images as slices of a 3D Milena image.
+ ///
+ /// \param[out] ima A reference to the 3D image which will receive
+ /// data.
+ /// \param[in] filenames The list of 2D images to load..
+ template <typename V>
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames);
+
# ifndef MLN_INCLUDE_ONLY
template <typename V>
@@ -98,6 +107,28 @@ namespace mln
trace::exiting("mln::io::ppm::load");
}
+ template <typename V>
+ inline
+ void load(image3d<V>& ima,
+ const util::array<std::string>& filenames)
+ {
+ trace::entering("mln::io::ppm::load");
+ mln_precondition(!filenames.is_empty());
+
+ util::array<image2d<V> > slices;
+
+ for (unsigned i = 0; i < filenames.nelements(); ++i)
+ {
+ image2d<V> tmp;
+ io::pnm::load<image2d<V> >(PPM, tmp, filenames[i]);
+ slices.append(tmp);
+ }
+
+ ima = make::image3d(slices);
+
+ trace::exiting("mln::io::ppm::load");
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln::io::ppm
diff --git a/milena/tests/io/pbm/pbm.cc b/milena/tests/io/pbm/pbm.cc
index fc02dda..e54d820 100644
--- a/milena/tests/io/pbm/pbm.cc
+++ b/milena/tests/io/pbm/pbm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/io/pbm/pbm.cc
- *
- * \brief Test on mln::io::pbm::.
- */
+/// \file tests/io/pbm/pbm.cc
+///
+/// Test on mln::io::pbm::.
#include <mln/core/image/image2d.hh>
#include <mln/io/pbm/load.hh>
@@ -44,10 +44,26 @@ int main()
using namespace mln;
image2d<bool> pic = io::pbm::load(MLN_IMG_DIR "/picasso.pbm");
- io::pbm::save(pic, "pic.pbm");
- image2d<bool> pic2 = io::pbm::load("pic.pbm");
+ io::pbm::save(pic, "out.pbm");
+ image2d<bool> pic2 = io::pbm::load("out.pbm");
mln_assertion(pic == pic2);
+
+
+ pic2(point2d(0,0)) = true;
+ io::pbm::save(pic2, "out.pbm");
+
+ util::array<std::string> files(2);
+ files[0] = MLN_IMG_DIR "/picasso.pbm";
+ files[1] = "out.pbm";
+
+ image3d<bool> ima3d;
+ io::pbm::load(ima3d, files);
+
+ mln_assertion(ima3d.nslices() == 2);
+ mln_assertion(slice(ima3d, 0) == pic);
+ mln_assertion(slice(ima3d, 1) == pic2);
+
}
diff --git a/milena/tests/io/pgm/pgm.cc b/milena/tests/io/pgm/pgm.cc
index 6a6da68..fd22c42 100644
--- a/milena/tests/io/pgm/pgm.cc
+++ b/milena/tests/io/pgm/pgm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,13 +26,15 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/io/pgm/pgm.cc
- *
- * \brief Test on mln::io::pgm::load and mln::io::pgm::save.
- */
+/// \file tests/io/pgm/pgm.cc
+///
+/// Test on mln::io::pgm::load and mln::io::pgm::save.
+
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/core/routine/duplicate.hh>
#include <mln/value/int_u8.hh>
@@ -40,6 +43,8 @@
#include <mln/level/compare.hh>
+#include <mln/literal/colors.hh>
+
#include "tests/data.hh"
@@ -65,4 +70,24 @@ int main()
io::pgm::load(lena2, "out.pgm");
mln_assertion(lena2 == lena);
}
+
+ {
+ image2d<int_u8> lena = io::pgm::load<int_u8>(MLN_IMG_DIR "/lena.pgm");
+
+ image2d<int_u8> lena2 = duplicate(lena);
+ lena2(point2d(0,0)) = 200;
+
+ io::pgm::save(lena2, "out.pgm");
+
+ util::array<std::string> files(2);
+ files[0] = MLN_IMG_DIR "/lena.pgm";
+ files[1] = "out.pgm";
+
+ image3d<int_u8> ima3d;
+ io::pgm::load(ima3d, files);
+
+ mln_assertion(ima3d.nslices() == 2);
+ mln_assertion(slice(ima3d, 0) == lena);
+ mln_assertion(slice(ima3d, 1) == lena2);
+ }
}
diff --git a/milena/tests/io/ppm/ppm.cc b/milena/tests/io/ppm/ppm.cc
index 7dca079..ecc80b4 100644
--- a/milena/tests/io/ppm/ppm.cc
+++ b/milena/tests/io/ppm/ppm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,12 +26,13 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/io/ppm/ppm.cc
- *
- * \brief Test on mln::io::ppm::load and mln::io::ppm::save.
- */
+/// \file tests/io/ppm/ppm.cc
+///
+/// Test on mln::io::ppm::load and mln::io::ppm::save.
+
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
#include <mln/value/rgb8.hh>
#include <mln/io/ppm/load.hh>
@@ -38,6 +40,10 @@
#include <mln/level/compare.hh>
+#include <mln/util/array.hh>
+
+#include <mln/literal/colors.hh>
+
#include "tests/data.hh"
@@ -52,4 +58,21 @@ int main()
image2d<rgb8> lena2;
io::ppm::load(lena2, "out.ppm");
mln_assertion(lena2 == lena);
+
+
+
+ lena2(point2d(0,0)) = literal::green;
+ io::ppm::save(lena2, "out.ppm");
+
+ util::array<std::string> files(2);
+ files[0] = MLN_IMG_DIR "/lena.ppm";
+ files[1] = "out.ppm";
+
+ image3d<rgb8> ima3d;
+ io::ppm::load(ima3d, files);
+
+ mln_assertion(ima3d.nslices() == 2);
+ mln_assertion(slice(ima3d, 0) == lena);
+ mln_assertion(slice(ima3d, 1) == lena2);
}
+
--
1.5.6.5
1
0
https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
Index: ChangeLog
from Thierry Geraud <thierry.geraud(a)lrde.epita.fr>
Update different files.
* theo/exec/superpose.cc: New.
* theo/esiee/laurent/presentation/wst2d.cc: Update.
* theo/esiee/laurent/presentation/classif.cc: Update.
* theo/csi/edwin.cc: Update.
csi/edwin.cc | 36 +++++++++++++++++++++++++------
esiee/laurent/presentation/classif.cc | 4 +--
esiee/laurent/presentation/wst2d.cc | 8 ++++++
exec/superpose.cc | 39 ++++++++++++++++++++++++++++++++++
4 files changed, 78 insertions(+), 9 deletions(-)
Index: theo/exec/superpose.cc
--- theo/exec/superpose.cc (revision 0)
+++ theo/exec/superpose.cc (revision 0)
@@ -0,0 +1,39 @@
+#include "filetype.hh"
+
+#include <mln/core/image/image_if.hh>
+#include <mln/data/fill.hh>
+#include <mln/pw/all.hh>
+
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input_int_u8.dump input_bool.dump output.dump" << std::endl
+ << " Superpose." << std::endl;
+ std::abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u8;
+
+ if (argc != 4)
+ usage(argv);
+
+ trace::entering("main");
+
+ image3d<int_u8> ima;
+ io::dump::load(ima, argv[1]);
+
+ image3d<bool> msk;
+ io::dump::load(msk, argv[2]);
+
+ data::fill( (ima | pw::value(msk)).rw(), 255 );
+
+ io::dump::save(ima, argv[3]);
+
+ trace::exiting("main");
+}
Index: theo/esiee/laurent/presentation/wst2d.cc
--- theo/esiee/laurent/presentation/wst2d.cc (revision 3409)
+++ theo/esiee/laurent/presentation/wst2d.cc (working copy)
@@ -5,6 +5,7 @@
# include <mln/io/pgm/load.hh>
# include <mln/io/ppm/save.hh>
+# include <mln/io/pgm/save.hh>
# include <mln/core/var.hh>
# include <mln/core/image/image2d.hh>
@@ -15,12 +16,15 @@
# include <mln/literal/black.hh>
# include <mln/debug/println.hh>
+# include <mln/extension/adjust_duplicate.hh>
+
# include <mln/morpho/closing_area.hh>
# include <mln/morpho/gradient.hh>
# include <mln/accu/min_max.hh>
# include <mln/morpho/meyer_wst.hh>
+
using namespace mln;
using value::int_u8;
@@ -32,6 +36,8 @@
const I& input = exact(input_);
const N& nbh = exact(nbh_);
+ extension::adjust_duplicate(input, nbh);
+
mln_concrete(I) output;
initialize(output, input);
accu::min_max<mln_value(I)> mm;
@@ -92,6 +98,8 @@
{
I grad = morpho_gradient(ima, nbh);
+ io::pgm::save(grad, "temp_grad.pgm");
+
I clo;
if (lambda > 1)
clo = morpho::closing_area(grad, nbh, lambda);
Index: theo/esiee/laurent/presentation/classif.cc
--- theo/esiee/laurent/presentation/classif.cc (revision 3409)
+++ theo/esiee/laurent/presentation/classif.cc (working copy)
@@ -358,8 +358,8 @@
`-----------------*/
// Currently, does nothing (lambda = 1).
- dist_ima_t closed_dist_ima (dist_ima.domain());
- morpho::closing_height(dist_ima, nbh, atoi(argv[1]), closed_dist_ima);
+ dist_ima_t closed_dist_ima; // (dist_ima.domain());
+ closed_dist_ima = morpho::closing_height(dist_ima, nbh, atoi(argv[1]));
/*------.
| WST. |
Index: theo/csi/edwin.cc
--- theo/csi/edwin.cc (revision 3409)
+++ theo/csi/edwin.cc (working copy)
@@ -28,7 +28,7 @@
void
back_propagate(const T& t, A& a)
// a value propagates from the representative point to every point
- // of the component...
+ // of the component at the same level (NOT to the branch points!)
{
mln_fwd_piter(T) p(t.domain());
for_all(p)
@@ -41,6 +41,19 @@
template <typename T, typename A>
+ void
+ back_propagate_II(const T& t, A& a)
+ // a value propagates from a representative point to every point
+ // of the component and the children components (branch).
+ {
+ mln_bkd_piter(T) p(t.domain());
+ for_all(p)
+ if (t.is_a_node(p) && a(t.parent(p)) == true)
+ a(p) = a(t.parent(p));
+ }
+
+
+ template <typename T, typename A>
inline
A
sample(const T& t, const A& a, bool echo = false)
@@ -57,6 +70,7 @@
if (echo) debug::println("aa (before)", aa);
+ back_propagate_II(t, aa);
back_propagate(t, aa);
if (echo) debug::println("aa (after)", aa);
@@ -71,7 +85,8 @@
void usage(char* argv[])
{
- std::cerr << "usage: " << argv[0] << " input.pgm output.pbm" << std::endl;
+ std::cerr << "usage: " << argv[0] << " input.pgm echo output.pbm" << std::endl;
+ std::cerr << " echo: 0 (none) or 1 (verbose)" << std::endl;
abort();
}
@@ -84,11 +99,15 @@
mln_VAR(nbh, c4());
- if (argc != 3)
+ if (argc != 4)
usage(argv);
- bool echo = false;
-
+ int echo = std::atoi(argv[2]);
+ if (echo != 0 && echo != 1)
+ {
+ std::cerr << "bad 'echo' value!" << std::endl;
+ usage(argv);
+ }
typedef image2d<int_u8> I;
@@ -96,6 +115,7 @@
io::pgm::load(input, argv[1]);
if (echo) debug::println("input", input);
+// I f = input;
I f = morpho::elementary::gradient(input, nbh);
if (echo) debug::println("f", f);
@@ -115,8 +135,10 @@
debug::println("a | nodes", a | t.nodes());
}
- image2d<bool> b = duplicate((pw::value(a) < pw::cst(10)) | a.domain());
+ image2d<bool> b = duplicate((pw::value(a) < pw::cst(21)) | a.domain());
if (echo) debug::println("b", b | t.nodes());
- io::pbm::save(sample(t, b), argv[2]);
+ io::pbm::save(sample(t, b,
+ echo),
+ argv[3]);
}
1
0
* lazzara/csv2vtk/csv2vtk.cc: convert a cloud of points in CSV format
to a VTK file.
---
milena/sandbox/ChangeLog | 7 +++
milena/sandbox/lazzara/csv2vtk/csv2vtk.cc | 83 +++++++++++++++++++++++++++++
2 files changed, 90 insertions(+), 0 deletions(-)
create mode 100644 milena/sandbox/lazzara/csv2vtk/csv2vtk.cc
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index 4065f8d..e569149 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,5 +1,12 @@
2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add csv2vtk converter.
+
+ * lazzara/csv2vtk/csv2vtk.cc: convert a cloud of points in CSV format
+ to a VTK file.
+
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Cleanup sandbox.
* lazzara/igr/igr-biggest-comp.cc: new. Variant of igr.cc which
diff --git a/milena/sandbox/lazzara/csv2vtk/csv2vtk.cc b/milena/sandbox/lazzara/csv2vtk/csv2vtk.cc
new file mode 100644
index 0000000..dc1f686
--- /dev/null
+++ b/milena/sandbox/lazzara/csv2vtk/csv2vtk.cc
@@ -0,0 +1,83 @@
+// Author: Andrew J. P. Maclean
+// Purpose read in a dataset where each line consists of point
+// with its position (x,y,z) and (possibly) a scalar.
+// Then create and save a vtk polydata array suitable for further rendering.
+
+#include <iostream>
+#include <stdexcept>
+#include <string>
+#include <fstream>
+#include <iomanip>
+#include <algorithm>
+#include <sstream>
+#include <vtkRenderer.h>
+#include <vtkRenderWindow.h>
+#include <vtkRenderWindowInteractor.h>
+#include <vtkPolyDataMapper.h>
+#include <vtkActor.h>
+#include <vtkXMLPolyDataWriter.h>
+#include <vtkXMLPolyDataReader.h>
+#include <vtkParticleReader.h>
+#include <vtkSmartPointer.h>
+
+
+
+int main ( int argc, char* argv[] )
+{
+ if ( argc != 3 )
+ {
+ std::cout << "Need input file and output file." << std::endl;
+ return 1;
+ }
+
+ std::string ifn = argv[1];
+ std::string ofn = argv[2];
+ std::cerr << "Input file: " << ifn << std::endl;
+ std::cerr << "Output file: " << ofn << std::endl;
+
+ if ( ifn == ofn )
+ {
+ std::cerr << "File names cannot be the same." << std::endl;
+ return 1;
+ }
+
+ vtkSmartPointer<vtkParticleReader> reader =
+ vtkSmartPointer<vtkParticleReader>::New();
+
+ reader->SetFileName(ifn.c_str());
+ reader->Update();
+
+ vtkSmartPointer<vtkXMLPolyDataWriter> writer =
+ vtkSmartPointer<vtkXMLPolyDataWriter>::New();
+ writer->SetInput(reader->GetOutput());
+ writer->SetFileName(ofn.c_str());
+ writer->Write();
+
+ // Set up the pipeline.
+
+ vtkSmartPointer<vtkPolyDataMapper> mapper =
+ vtkSmartPointer<vtkPolyDataMapper>::New();
+
+ mapper->SetInput(reader->GetOutput());
+
+ vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
+ actor->SetMapper(mapper);
+
+ vtkSmartPointer<vtkRenderer> ren = vtkSmartPointer<vtkRenderer>::New();
+ ren->SetBackground(0.2,0.2 ,0.3);
+
+ vtkSmartPointer<vtkRenderWindow> renWin =
+ vtkSmartPointer<vtkRenderWindow>::New();
+ renWin->AddRenderer(ren);
+ renWin->SetSize(800 ,600);
+
+ vtkSmartPointer<vtkRenderWindowInteractor> iRen =
+ vtkSmartPointer<vtkRenderWindowInteractor>::New();
+ iRen->SetRenderWindow(renWin);
+ ren->AddViewProp(actor);
+ ren->Render();
+ iRen->Initialize();
+ iRen->Start();
+}
+
+
--
1.5.6.5
1
0
* lazzara/igr/igr-biggest-comp.cc: new. Variant of igr.cc which
extract the biggest component before registrating.
* lazzara/irm/wst_rag.cc,
* lazzara/irm_seg_with_mm_and_rag.mine.cc,
* lazzara/igr-cloud.cc,
* lazzara/igr.cc,
* lazzara/irm/hsl_grad_and_wst.cc,
* lazzara/irm/irm_seg_with_mm_and_rag.cc,
* lazzara/irm/wst_rag_hsl.cc: Move to...
* lazzara/igr/irm/wst_rag.cc,
* lazzara/igr/irm_seg_with_mm_and_rag.mine.cc,
* lazzara/igr/igr-cloud.cc,
* lazzara/igr/igr.cc,
* lazzara/igr/irm/hsl_grad_and_wst.cc,
* lazzara/igr/irm/irm_seg_with,
* lazzara/igr/irm/wst_rag_hsl.cc: ... here.
* lazzara/igr/registration_3d.cc: 3D registration.
* lazzara/igr/tr_image.cc: quick test on transformed image.
---
milena/sandbox/ChangeLog | 27 ++
milena/sandbox/lazzara/igr/igr-biggest-comp.cc | 294 ++++++++++++++++++++
milena/sandbox/lazzara/{ => igr}/igr-cloud.cc | 0
milena/sandbox/lazzara/{ => igr}/igr.cc | 17 +-
.../lazzara/{ => igr}/irm/hsl_grad_and_wst.cc | 0
.../{ => igr}/irm/irm_seg_with_mm_and_rag.cc | 0
milena/sandbox/lazzara/{ => igr}/irm/wst_rag.cc | 0
.../sandbox/lazzara/{ => igr}/irm/wst_rag_hsl.cc | 0
.../{ => igr}/irm_seg_with_mm_and_rag.mine.cc | 0
milena/sandbox/lazzara/igr/registration_3d.cc | 48 ++++
milena/sandbox/lazzara/igr/tr_image.cc | 185 ++++++++++++
11 files changed, 557 insertions(+), 14 deletions(-)
create mode 100644 milena/sandbox/lazzara/igr/igr-biggest-comp.cc
rename milena/sandbox/lazzara/{ => igr}/igr-cloud.cc (100%)
rename milena/sandbox/lazzara/{ => igr}/igr.cc (93%)
rename milena/sandbox/lazzara/{ => igr}/irm/hsl_grad_and_wst.cc (100%)
rename milena/sandbox/lazzara/{ => igr}/irm/irm_seg_with_mm_and_rag.cc (100%)
rename milena/sandbox/lazzara/{ => igr}/irm/wst_rag.cc (100%)
rename milena/sandbox/lazzara/{ => igr}/irm/wst_rag_hsl.cc (100%)
rename milena/sandbox/lazzara/{ => igr}/irm_seg_with_mm_and_rag.mine.cc (100%)
create mode 100644 milena/sandbox/lazzara/igr/registration_3d.cc
create mode 100644 milena/sandbox/lazzara/igr/tr_image.cc
diff --git a/milena/sandbox/ChangeLog b/milena/sandbox/ChangeLog
index e4e1643..4065f8d 100644
--- a/milena/sandbox/ChangeLog
+++ b/milena/sandbox/ChangeLog
@@ -1,3 +1,30 @@
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
+ Cleanup sandbox.
+
+ * lazzara/igr/igr-biggest-comp.cc: new. Variant of igr.cc which
+ extract the biggest component before registrating.
+
+ * lazzara/irm/wst_rag.cc,
+ * lazzara/irm_seg_with_mm_and_rag.mine.cc,
+ * lazzara/igr-cloud.cc,
+ * lazzara/igr.cc,
+ * lazzara/irm/hsl_grad_and_wst.cc,
+ * lazzara/irm/irm_seg_with_mm_and_rag.cc,
+ * lazzara/irm/wst_rag_hsl.cc: Move to...
+
+ * lazzara/igr/irm/wst_rag.cc,
+ * lazzara/igr/irm_seg_with_mm_and_rag.mine.cc,
+ * lazzara/igr/igr-cloud.cc,
+ * lazzara/igr/igr.cc,
+ * lazzara/igr/irm/hsl_grad_and_wst.cc,
+ * lazzara/igr/irm/irm_seg_with,
+ * lazzara/igr/irm/wst_rag_hsl.cc: ... here.
+
+ * lazzara/igr/registration_3d.cc: 3D registration.
+
+ * lazzara/igr/tr_image.cc: quick test on transformed image.
+
2009-02-20 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update DICOM support to n dimensions.
diff --git a/milena/sandbox/lazzara/igr/igr-biggest-comp.cc b/milena/sandbox/lazzara/igr/igr-biggest-comp.cc
new file mode 100644
index 0000000..ecfc7a1
--- /dev/null
+++ b/milena/sandbox/lazzara/igr/igr-biggest-comp.cc
@@ -0,0 +1,294 @@
+#include <mln/registration/registration.hh>
+#include <mln/essential/2d.hh>
+#include <mln/core/image/image3d.hh>
+#include <mln/binarization/binarization.hh>
+#include <mln/labeling/flat_zones.hh>
+#include <mln/labeling/background.hh>
+
+#include <mln/debug/colorize.hh>
+
+
+#include <mln/essential/3d.hh>
+#include <mln/core/image/slice_image.hh>
+#include <mln/core/image/tr_image.hh>
+#include <mln/core/image/interpolated.hh>
+
+#include <mln/io/cloud/load.hh>
+#include <mln/util/timer.hh>
+#include <mln/core/concept/function.hh>
+#include <mln/trait/ch_value.hh>
+
+#include <mln/fun/p2b/big_chess.hh>
+
+#include <mln/fun/x2v/trilinear.hh>
+
+namespace mln
+{
+
+ struct threshold : mln::Function_p2b<threshold>
+ {
+ bool operator()(const mln::value::rgb8& val) const
+ {
+ unsigned inty = (val.red() + val.blue() + val.green());
+ return inty > 100 && inty < 600;
+ }
+ };
+
+
+ namespace registration
+ {
+ extern std::string method;
+ }
+
+ template <typename I>
+ mln_concrete(I)
+ fill_holes(const mln::Image<I>& ima)
+ {
+ using namespace mln;
+
+ mln_concrete(I) output;
+ initialize(output, ima);
+ data::fill(output, true);
+
+ value::label_16 nlabels;
+ mln_ch_value(I, value::label_16) lbl = labeling::background(ima, c4(), nlabels);
+
+ mln_VAR(lbl_count, labeling::compute(accu::meta::count(), ima, lbl, nlabels));
+
+ unsigned max_id = 1;
+ for (unsigned i = 2; i <= nlabels; ++i)
+ if (lbl_count[max_id] < lbl_count[i])
+ max_id = i;
+
+ data::fill((output | pw::value(lbl) == max_id).rw(), false);
+
+ return output;
+ }
+
+ template <typename I>
+ mln_concrete(I)
+ keep_largest_component(const mln::Image<I>& ima)
+ {
+ using namespace mln;
+
+ image2d<bool> in_bw_cleaned = fill_holes(ima);
+ io::pbm::save(in_bw_cleaned, "in_bw_cleaned.pbm");
+
+ logical::not_inplace(in_bw_cleaned);
+ image2d<bool> in_bw_cleaned_full = fill_holes(in_bw_cleaned);
+ io::pbm::save(in_bw_cleaned_full, "in_bw_cleaned_full.pbm");
+
+ logical::not_inplace(in_bw_cleaned_full);
+ return in_bw_cleaned_full;
+ }
+
+ template <typename I>
+ mln_ch_value(I,bool)
+ get_main_object_shape(const mln::Image<I>& in)
+ {
+ using namespace mln;
+
+ typedef image2d<bool> J;
+
+ value::label_16 nlabels;
+ mln_ch_value(I, value::label_16) labels = labeling::flat_zones(in, c8(), nlabels);
+ util::array<unsigned> arr = labeling::compute(accu::meta::count(),
+ in, labels, nlabels);
+
+ unsigned big_second_count = 0;
+ unsigned big_second_lbl = 0;
+ unsigned big_first_count = 0;
+ unsigned big_first_lbl = 0;
+ for (unsigned i = 0; i < arr.nelements(); ++i)
+ {
+ if (arr[i] > big_second_count)
+ {
+ big_second_count = arr[i];
+ big_second_lbl = i;
+ }
+ if (big_second_count > big_first_count)
+ {
+ int swap = big_first_count;
+ int swap_lbl = big_first_lbl;
+ big_first_count = big_second_count;
+ big_first_lbl = big_second_lbl;
+ big_second_count = swap;
+ big_second_lbl = swap_lbl;
+ }
+ }
+
+ J result;
+ initialize(result, in);
+ data::fill(result, false);
+ data::fill((result | (pw::value(labels) == big_second_lbl)).rw(), true);
+
+ return morpho::elementary::gradient_internal(keep_largest_component(result), c8());
+ }
+
+
+ namespace debug
+ {
+
+ template <typename I, typename T>
+ image3d<value::rgb8>
+ make_registered_image(Image<I>& P_, Image<I>& X_, const T& transf)
+ {
+ I& P = exact(P_);
+ I& X = exact(X_);
+
+ mln_pset(I) box = geom::bbox(X);
+ box.enlarge(1, 60);
+ box.enlarge(2, 60);
+
+ typedef mln_ch_value(I,value::rgb8) result_t;
+ result_t result(box);
+
+ typedef extension_fun<result_t,pw::cst_<mln_value(result_t)> > result_ext_t;
+ result_ext_t ext_result(result, pw::cst(value::rgb8(0,0,0)));
+
+ extension_fun<I,pw::cst_<mln_value(I)> > ext_X(X, pw::cst(false));
+ data::fill(ext_result, literal::black);
+
+ mln_VAR(ig, (P | pw::value(P) == true));
+ mln_piter(ig_t) p(ig.domain());
+ for_all(p)
+ ext_result(transf(p)) = literal::green;
+
+ return ext_result;
+ }
+
+ template <typename I, typename J>
+ void
+ compare_registration(Image<I>& registered_, Image<J>& X_)
+ {
+ I& registered = exact(registered_);
+ J& X = exact(X_);
+
+ typedef mln_ch_value(I,value::rgb8) result_t;
+ result_t result;
+ initialize(result, registered);
+ extension_fun<J,pw::cst_<mln_value(J)> > ext_X(X, pw::cst(false));
+
+ data::fill(result, literal::black);
+ data::fill((result | (pw::value(ext_X) == true)).rw(), literal::white);
+ data::fill((result | (pw::value(registered) != pw::cst(literal::black))).rw(),
+ literal::cyan);
+
+ io::ppm::save(slice(result,0), "final_registered.ppm");
+ }
+
+
+
+ template <typename I, typename T>
+ void
+ compare_registration2(Image<I>& P_, Image<I>& X_,
+ const T& transf)
+ {
+ I& P = exact(P_);
+ const I& X = exact(X_);
+
+ typedef extension_fun<I,pw::cst_<mln_value(I)> > ext_P_t;
+ ext_P_t ext_P(P, pw::cst(value::rgb8(literal::black)));
+ typedef interpolated<ext_P_t, fun::x2v::trilinear> inter_t;
+ inter_t inter(ext_P);
+ tr_image<box3d, inter_t, T> trima(X.domain(), inter, transf);
+ io::ppm::save(slice(trima, 0), "trima.ppm");
+
+ I tmp = duplicate(X);
+ fun::p2b::big_chess<box3d> fun(tmp.domain(), 20);
+ data::paste((trima | fun), tmp);
+
+ io::ppm::save(slice(tmp,0), "registration_filter.ppm");
+ }
+
+ }
+}
+
+
+int main(int, char* argv[])
+{
+ using namespace mln;
+ using namespace fun::x2x;
+ using value::rgb8;
+ using value::int_u8;
+ using value::label_16;
+
+ //Load image
+ typedef image2d<rgb8> I;
+ typedef image2d<bool> J;
+ typedef image3d<bool> K;
+ typedef image3d<value::rgb8> L;
+
+// Load ppm images and apply a threshold.
+// I in;
+// io::ppm::load(in, argv[1]);
+// image2d<bool> in_bw = level::transform(in, threshold());
+// J in_obj = get_main_object_shape(in_bw);
+//
+// I ref;
+// io::ppm::load(ref, argv[2]);
+// image2d<bool> ref_bw = level::transform(ref, threshold());
+// J ref_obj = get_main_object_shape(ref_bw);
+
+
+
+ I in;
+ io::ppm::load(in, argv[1]);
+ J in_obj = get_main_object_shape(in);
+ io::pbm::save(in_obj, "in_obj.pbm");
+
+ I ref;
+ io::ppm::load(ref, argv[2]);
+ J ref_obj = get_main_object_shape(ref);
+ io::pbm::save(ref_obj, "ref_obj.pbm");
+
+ I in_orig;
+ io::ppm::load(in_orig, argv[3]);
+
+ I ref_orig;
+ io::ppm::load(ref_orig, argv[4]);
+
+ K in_3d = make::image3d(in_obj);
+ K ref_3d = make::image3d(ref_obj);
+ std::cout << " igr.cc - in_3d.nsites = " << in_3d.nsites() << std::endl;
+ std::cout << " igr.cc - ref_3d.nsites = " << ref_3d.nsites() << std::endl;
+
+ typedef p_array<point3d> p_arr_t;
+ p_arr_t in_3d_ = convert::to<p_arr_t>(in_3d);
+ p_arr_t ref_3d_ = convert::to<p_arr_t>(ref_3d);
+
+
+ /// Add objects shapes in original images.
+ L in_wborders = make::image3d(in_orig);
+ data::fill((in_wborders | in_3d_).rw(), literal::green);
+ io::ppm::save(slice(in_wborders,0), "in_with_borders.ppm");
+
+ L ref_wborders = make::image3d(ref_orig);
+ data::fill((ref_wborders | ref_3d_).rw(), literal::green);
+ io::ppm::save(slice(ref_wborders,0), "ref_with_borders.ppm");
+
+ // Starting registration.
+ util::timer t;
+ t.start();
+ typedef rotation<3u,float> rot_t;
+ typedef translation<3u,float> trans_t;
+ box3d bbox = geom::bbox(in_3d);
+ bbox.enlarge(0, in_3d.nslices() / 2);
+ bbox.enlarge(1, in_3d.nrows() / 2);
+ bbox.enlarge(2, in_3d.ncols() / 2);
+
+ composed<trans_t,rot_t> qk = registration::registration3(bbox, in_3d_, ref_3d_);
+ std::cout << "igr.cc - Registration - " << t << "s" << std::endl;
+
+ std::cout << qk.first().mat() << std::endl << std::endl;;
+ std::cout << qk.first().inv().mat() << std::endl << std::endl;;
+ std::cout << qk.second().mat() << std::endl;
+ std::cout << qk.second().inv().mat() << std::endl;
+
+ std::cout << "* Build result image" << std::endl;
+ image3d<value::rgb8> registered = debug::make_registered_image(in_3d, ref_3d, qk);
+ debug::compare_registration(registered, ref_3d);
+
+ debug::compare_registration2(in_wborders, ref_wborders, qk);
+
+}
diff --git a/milena/sandbox/lazzara/igr-cloud.cc b/milena/sandbox/lazzara/igr/igr-cloud.cc
similarity index 100%
rename from milena/sandbox/lazzara/igr-cloud.cc
rename to milena/sandbox/lazzara/igr/igr-cloud.cc
diff --git a/milena/sandbox/lazzara/igr.cc b/milena/sandbox/lazzara/igr/igr.cc
similarity index 93%
rename from milena/sandbox/lazzara/igr.cc
rename to milena/sandbox/lazzara/igr/igr.cc
index 0df1d92..98e1ce4 100644
--- a/milena/sandbox/lazzara/igr.cc
+++ b/milena/sandbox/lazzara/igr/igr.cc
@@ -202,22 +202,11 @@ namespace mln
typedef extension_fun<I,pw::cst_<mln_value(I)> > ext_P_t;
ext_P_t ext_P(P, pw::cst(value::rgb8(literal::black)));
- tr_image<box3d, ext_P_t, T> trima(P.domain(), ext_P, transf);
+ typedef interpolated<ext_P_t, fun::x2v::bilinear> inter_t;
+ inter_t inter(ext_P);
+ tr_image<box3d, inter_t, T> trima(X.domain(), inter, transf);
io::ppm::save(slice(trima, 0), "trima.ppm");
- I reg(X.domain());
- data::fill(reg, literal::black);
- mln_piter(I) p(P.domain());
- for_all(p)
- if (reg.domain().has(transf(p.to_vec())))
- reg(transf(p.to_vec())) = P(p);
- io::ppm::save(slice(reg,0), "registered-2.ppm");
-
- I tmp2 = duplicate(X);
- fun::p2b::big_chess<box3d> fun2(tmp2.domain(), 20);
- data::paste((reg | fun2), tmp2);
- io::ppm::save(slice(tmp2,0), "registration_filter-a.ppm");
-
I tmp = duplicate(X);
fun::p2b::big_chess<box3d> fun(tmp.domain(), 20);
data::paste((trima | fun), tmp);
diff --git a/milena/sandbox/lazzara/irm/hsl_grad_and_wst.cc b/milena/sandbox/lazzara/igr/irm/hsl_grad_and_wst.cc
similarity index 100%
rename from milena/sandbox/lazzara/irm/hsl_grad_and_wst.cc
rename to milena/sandbox/lazzara/igr/irm/hsl_grad_and_wst.cc
diff --git a/milena/sandbox/lazzara/irm/irm_seg_with_mm_and_rag.cc b/milena/sandbox/lazzara/igr/irm/irm_seg_with_mm_and_rag.cc
similarity index 100%
rename from milena/sandbox/lazzara/irm/irm_seg_with_mm_and_rag.cc
rename to milena/sandbox/lazzara/igr/irm/irm_seg_with_mm_and_rag.cc
diff --git a/milena/sandbox/lazzara/irm/wst_rag.cc b/milena/sandbox/lazzara/igr/irm/wst_rag.cc
similarity index 100%
rename from milena/sandbox/lazzara/irm/wst_rag.cc
rename to milena/sandbox/lazzara/igr/irm/wst_rag.cc
diff --git a/milena/sandbox/lazzara/irm/wst_rag_hsl.cc b/milena/sandbox/lazzara/igr/irm/wst_rag_hsl.cc
similarity index 100%
rename from milena/sandbox/lazzara/irm/wst_rag_hsl.cc
rename to milena/sandbox/lazzara/igr/irm/wst_rag_hsl.cc
diff --git a/milena/sandbox/lazzara/irm_seg_with_mm_and_rag.mine.cc b/milena/sandbox/lazzara/igr/irm_seg_with_mm_and_rag.mine.cc
similarity index 100%
rename from milena/sandbox/lazzara/irm_seg_with_mm_and_rag.mine.cc
rename to milena/sandbox/lazzara/igr/irm_seg_with_mm_and_rag.mine.cc
diff --git a/milena/sandbox/lazzara/igr/registration_3d.cc b/milena/sandbox/lazzara/igr/registration_3d.cc
new file mode 100644
index 0000000..f049d88
--- /dev/null
+++ b/milena/sandbox/lazzara/igr/registration_3d.cc
@@ -0,0 +1,48 @@
+#include <mln/essential/2d.hh>
+#include <mln/essential/3d.hh>
+#include <mln/registration/registration.hh>
+#include <mln/io/cloud/all.hh>
+#include <mln/debug/slices_2d.hh>
+
+int main(int, char *argv[])
+{
+ using namespace mln;
+
+ typedef p_array<point3d> arr_t;
+
+ arr_t in;
+ io::cloud::load(in, argv[1]);
+
+ arr_t ref;
+ io::cloud::load(ref, argv[2]);
+
+ // Starting registration.
+ util::timer t;
+ t.start();
+
+ typedef fun::x2x::rotation<3u,float> rot_t;
+ typedef fun::x2x::translation<3u,float> trans_t;
+ fun::x2x::composed<trans_t,rot_t> qk = registration::registration3(in, ref);
+
+ std::cout << "igr.cc - Registration - " << t << "s" << std::endl;
+
+ box3d bbox = geom::bbox(ref);
+ bbox.enlarge(1, 50);
+ bbox.enlarge(2, 50);
+ image3d<value::rgb8> ima_in(bbox);
+ data::fill(ima_in, literal::black);
+ data::fill((ima_in | in).rw(), literal::green);
+
+ mln_VAR(ext_ima, extended_with(ima_in, pw::cst(value::rgb8(literal::black))));
+ mln_VAR(trima, transposed_image(bbox, ext_ima, qk));
+
+ image3d<value::rgb8> ima_ref(geom::bbox(ref));
+ mln_VAR(ext_ima_ref, extended_with(ima_ref, pw::cst(value::rgb8(literal::black))));
+ data::fill(ext_ima_ref, literal::black);
+ data::fill((ext_ima_ref | ref).rw(), literal::white);
+ data::fill((ext_ima_ref | pw::value(trima) == pw::cst(literal::green)).rw(), literal::green);
+
+// io::cloud::save(res, "registered.txt");
+
+ io::ppm::save(debug::slices_2d(ima_ref, 5, 3, literal::black), "registration_3d.ppm");
+}
diff --git a/milena/sandbox/lazzara/igr/tr_image.cc b/milena/sandbox/lazzara/igr/tr_image.cc
new file mode 100644
index 0000000..d1a8056
--- /dev/null
+++ b/milena/sandbox/lazzara/igr/tr_image.cc
@@ -0,0 +1,185 @@
+#include <mln/essential/2d.hh>
+#include <mln/essential/3d.hh>
+#include <mln/fun/x2x/composed.hh>
+#include <mln/fun/x2x/rotation.hh>
+#include <mln/fun/x2x/translation.hh>
+#include <mln/core/image/interpolated.hh>
+#include <mln/fun/x2v/trilinear.hh>
+#include <mln/fun/x2v/bilinear.hh>
+#include <mln/core/image/tr_image.hh>
+
+#include <mln/io/cloud/save.hh>
+#include <mln/debug/slices_2d.hh>
+
+int main(int, char *argv[])
+{
+ using namespace mln;
+ using namespace fun::x2x;
+ using value::rgb8;
+ using value::int_u8;
+ using value::label_16;
+
+ //Load image
+ typedef image2d<bool> J;
+ typedef image3d<rgb8> K;
+ typedef image2d<rgb8> I;
+
+ I P;
+ io::ppm::load(P, argv[1]);
+ K P_3d = make::image3d(P);
+
+
+ {
+ typedef rotation<3u,float> rot_t;
+ rot_t rot(1.57f, make::vec(0,0, 1));
+ typedef translation<3u,float> trans_t;
+ trans_t trans(make::vec(150, 50, 0));
+ typedef composed<trans_t, rot_t> transf_t;
+ transf_t qk(trans, rot);
+
+// std::cout << rot.mat() << std::endl;
+//
+ point3d p10_3d(0,1,0);
+ std::cout << "point " << p10_3d << " == vec " << p10_3d.to_vec() << std::endl;
+// point3d p11_3d(0,1,1);
+// algebra::vec<4u,float> p10 = make::vec(0,1,0,1);
+// algebra::vec<4u,float> p11 = make::vec(0.f,1.f,1.f,1.f);
+// algebra::vec<4u,float> p01 = make::vec(0.f,0.f,1.f,1.f);
+// algebra::vec<4u,float> p_01 = make::vec(0,0,-1,1);
+//
+// std::cout << "qk(p10_3d.to_vec) = " << qk(p10_3d.to_vec()) << std::endl;
+// std::cout << "rot(p10) = " << (rot.mat() * p10) << std::endl;
+// std::cout << "rot(p10) + trans = " << (qk.mat() * p10) << std::endl << std::endl << std::endl;
+//
+//
+// std::cout << "rot.inv()(p10) = " << (rot.inv().mat() * p10) << std::endl;
+// std::cout << "rot.inv()(p_01) = " << (rot.inv().mat() * p_01) << std::endl;
+// std::cout << "rot.inv()(p01) = " << (rot.inv().mat() * p01) << std::endl;
+// std::cout << "qk.inv()(p11_3d) = " << qk.inv()(p11_3d.to_vec()) << std::endl;
+// std::cout << "qk.inv().mat() * p11 = " << (qk.inv().mat() * p11) << std::endl;
+// std::cout << "rot(p).inv() (p11 + trans.inv) = " << rot.inv().mat() * (trans.inv().mat() * p11) << std::endl;
+// std::cout << "trans.inv()(p01) = " << trans.inv().mat() * p01 << std::endl;
+//
+// std::cout << std::endl << "trans.mat" << std::endl;
+// std::cout << trans.mat() << std::endl;
+// std::cout << "trans.mat.inv" << std::endl;
+// std::cout << trans.inv().mat() << std::endl;
+//
+//
+// std::cout << std::endl << "rot.mat" << std::endl;
+// std::cout << rot.mat() << std::endl;
+// std::cout << "rot.mat.inv" << std::endl;
+// std::cout << rot.inv().mat() << std::endl;
+//
+// std::cout << "qk.mat" << std::endl;
+// std::cout << qk.mat() << std::endl;
+// std::cout << "qk.inv().mat()" << std::endl;
+// std::cout << qk.inv().mat() << std::endl;
+
+ typedef extension_fun<K,pw::cst_<mln_value_(I)> > ext_P_t;
+ ext_P_t ext_P(P_3d, pw::cst(value::rgb8(literal::black)));
+
+ typedef interpolated<ext_P_t, fun::x2v::trilinear> inter_t;
+ inter_t inter(ext_P);
+
+ std::cout << std::endl << "DEBUG TR_IMAGE" << std::endl;
+ tr_image<box3d, inter_t, transf_t> trima(P_3d.domain(), inter, qk);
+
+ io::ppm::save(slice(trima, 0), "trima_3d2.ppm");
+
+ }
+
+// {
+// typedef rotation<3u,float> rot_t;
+//
+// algebra::quat q;
+// q[0] = 0
+// q[3] = cos(1.57f / 2);
+// rot_t rot(1.57f, make::vec(0, 0, 1));
+// typedef translation<3u,float> trans_t;
+// trans_t trans(make::vec(150, 50, 0));
+// typedef composed<trans_t, rot_t> transf_t;
+// transf_t qk(trans, rot);
+//
+// typedef extension_fun<K,pw::cst_<mln_value_(I)> > ext_P_t;
+// ext_P_t ext_P(P_3d, pw::cst(value::rgb8(literal::black)));
+//
+// typedef interpolated<ext_P_t, fun::x2v::trilinear> inter_t;
+// inter_t inter(ext_P);
+//
+// std::cout << std::endl << "DEBUG TR_IMAGE" << std::endl;
+// tr_image<box3d, inter_t, transf_t> trima(P_3d.domain(), inter, qk);
+//
+// io::ppm::save(slice(trima, 0), "trima_3d3.ppm");
+//
+// }
+
+
+ {
+
+ typedef rotation<2u,float> rot_t;
+ rot_t rot(1.57f, make::vec(1, 0));
+
+ typedef translation<2u,float> trans_t;
+ trans_t trans(make::vec(150, 50));
+ typedef composed<trans_t, rot_t> transf_t;
+ transf_t qk(trans, rot);
+
+ std::cout << rot.mat() << std::endl;
+
+ typedef extension_fun<I,pw::cst_<mln_value_(I)> > ext_P_t;
+ ext_P_t ext_P(P, pw::cst(value::rgb8(literal::black)));
+ typedef interpolated<ext_P_t, fun::x2v::bilinear> inter_t;
+ inter_t inter(ext_P);
+ tr_image<box2d, inter_t, transf_t> trima(P.domain(), inter, qk);
+ io::ppm::save(trima, "trima_2d.ppm");
+
+ }
+/*
+ {
+ typedef rotation<3u,float> rot_t;
+ rot_t rot(1.57f, make::vec(0, 0, 1));
+ typedef translation<3u,float> trans_t;
+ trans_t trans(make::vec(160, 60, 0));
+ typedef composed<trans_t, rot_t> transf_t;
+ transf_t qk(trans, rot);
+
+ std::cout << rot.mat() << std::endl;
+
+ typedef extension_fun<K,pw::cst_<mln_value_(I)> > ext_P_t;
+ ext_P_t ext_P(P_3d, pw::cst(value::rgb8(literal::black)));
+ typedef interpolated<ext_P_t, fun::x2v::bilinear> inter_t;
+ inter_t inter(ext_P);
+ tr_image<box3d, inter_t, transf_t> trima(P_3d.domain(), inter, qk);
+ io::ppm::save(slice(trima, 0), "trima_3d.ppm");
+
+ std::cout << std::endl << " points: " << std::endl;
+ unsigned i = 0;
+ mln_piter_(box3d) p (P_3d.domain());
+ for_all(p)
+ {
+ algebra::vec<4,float> tmp;
+ for (unsigned j = 0; j < 3; ++j)
+ tmp[j] = p.to_vec()[j];
+ tmp[3] = 1;
+ tmp = (qk.mat() * tmp);
+ algebra::vec<3,float> res;
+ for (unsigned j = 0; j < 3; ++j)
+ res[j] = tmp[j];
+ point3d ptmp = res;
+ std::cout << p << " - " << res << " - " << point3d(res) << " - " << ptmp << std::endl;
+ if (i >10)
+ break;
+ ++i;
+ }
+ }
+*/
+// K reg(b);
+// data::fill(reg, literal::black);
+// mln_piter_(K) p(P_3d.domain());
+// for_all(p)
+// if (reg.domain().has(qk(p.to_site().to_vec())))
+// reg(qk(p.to_site().to_vec())) = P_3d(p);
+// io::ppm::save(slice(reg,0), "trima_mine.ppm");
+
+}
--
1.5.6.5
1
0
* mln/core/image/extension_fun.hh,
* mln/core/image/extension_ima.hh,
* mln/core/image/extension_val.hh: add extended_with routine.
---
milena/ChangeLog | 8 ++++++++
milena/mln/core/image/extension_fun.hh | 14 +++++++++++++-
milena/mln/core/image/extension_ima.hh | 13 +++++++++++++
milena/mln/core/image/extension_val.hh | 12 ++++++++++++
4 files changed, 46 insertions(+), 1 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 5c7fdf4..999d18b 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add extended_with routine.
+
+ * mln/core/image/extension_fun.hh,
+ * mln/core/image/extension_ima.hh,
+ * mln/core/image/extension_val.hh: add extended_with routine.
+
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Add implicit conversion from algebra::quat to algebra::vec.
* mln/algebra/quat.hh: add implicit conversion operator to
diff --git a/milena/mln/core/image/extension_fun.hh b/milena/mln/core/image/extension_fun.hh
index c140283..0cd09b6 100644
--- a/milena/mln/core/image/extension_fun.hh
+++ b/milena/mln/core/image/extension_fun.hh
@@ -1,4 +1,5 @@
-// Copyright (C) 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory
+// (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -266,6 +267,17 @@ namespace mln
target = model.extension();
}
+ template <typename I, typename F>
+ extension_fun<I,F>
+ extended_with(Image<I>& ima, const Function_v2v<F>& f)
+ {
+ mlc_not_equal(mln_trait_image_ext_domain(I),
+ trait::image::ext_domain::none)::check();
+ mln_precondition(exact(ima).is_valid());
+ extension_fun<I,F> tmp(exact(ima), exact(f));
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
diff --git a/milena/mln/core/image/extension_ima.hh b/milena/mln/core/image/extension_ima.hh
index 91055dd..98360b4 100644
--- a/milena/mln/core/image/extension_ima.hh
+++ b/milena/mln/core/image/extension_ima.hh
@@ -268,6 +268,19 @@ namespace mln
target_ = ext_;
}
+
+ template <typename I, typename J>
+ extension_ima<I,J>
+ extended_with(Image<I>& ima, const Image<J> ext)
+ {
+ mlc_not_equal(mln_trait_image_ext_domain(I),
+ trait::image::ext_domain::none)::check();
+ mln_precondition(exact(ima).is_valid());
+ mln_precondition(exact(ext).is_valid());
+ extension_ima<I,J> tmp(exact(ima), exact(ext));
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
diff --git a/milena/mln/core/image/extension_val.hh b/milena/mln/core/image/extension_val.hh
index 63dbeb7..45f1926 100644
--- a/milena/mln/core/image/extension_val.hh
+++ b/milena/mln/core/image/extension_val.hh
@@ -268,6 +268,18 @@ namespace mln
target = static_cast<V>(model.extension());
}
+ template <typename I, typename J>
+ extension_ima<I,J>
+ extended_with(Image<I>& ima, const Image<J> ext)
+ {
+ mlc_not_equal(mln_trait_image_ext_domain(I),
+ trait::image::ext_domain::none)::check();
+ mln_precondition(exact(ima).is_valid());
+ mln_precondition(exact(ext).is_valid());
+ extension_ima<I,J> tmp(exact(ima), exact(ext));
+ return tmp;
+ }
+
# endif // ! MLN_INCLUDE_ONLY
} // end of namespace mln
--
1.5.6.5
1
0
20 Feb '09
* mln/algebra/quat.hh: add implicit conversion operator to
algebra::vec.
---
milena/ChangeLog | 7 +++++++
milena/mln/algebra/quat.hh | 8 ++++++++
2 files changed, 15 insertions(+), 0 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 4efb183..5c7fdf4 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,12 @@
2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Add implicit conversion from algebra::quat to algebra::vec.
+
+ * mln/algebra/quat.hh: add implicit conversion operator to
+ algebra::vec.
+
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Update ICP.
* mln/registration/icp.hh: store point indexes instead of points in
diff --git a/milena/mln/algebra/quat.hh b/milena/mln/algebra/quat.hh
index 33e7d07..85ebcbd 100644
--- a/milena/mln/algebra/quat.hh
+++ b/milena/mln/algebra/quat.hh
@@ -162,6 +162,8 @@ namespace mln
/// Explicit conversion to a 4D algebra::vec.
const algebra::vec<4,float>& to_vec() const;
+ /// Implicit conversion to a 4D algebra::vec.
+ operator const algebra::vec<4,float>&() const;
/// Give the scalar part.
float s() const;
@@ -340,6 +342,12 @@ namespace mln
}
inline
+ quat::operator const algebra::vec<4,float>&() const
+ {
+ return this->v_;
+ }
+
+ inline
float
quat::s() const
{
--
1.5.6.5
1
0
* mln/registration/icp.hh: store point indexes instead of points in
closest point image. Remove useless to_vec().
* mln/registration/registration.hh: remove useless to_vec(). Pass a
domain to the function to be used to compute the closest point image.
* mln/transform/internal/closest_point_functor.hh: Store point indexes
instead of points.
---
milena/ChangeLog | 13 +++
milena/mln/registration/icp.hh | 81 +++++++++++---------
milena/mln/registration/registration.hh | 63 ++++++++--------
.../transform/internal/closest_point_functor.hh | 29 ++++++-
4 files changed, 114 insertions(+), 72 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index ce02eb9..4efb183 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,18 @@
2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Update ICP.
+
+ * mln/registration/icp.hh: store point indexes instead of points in
+ closest point image. Remove useless to_vec().
+
+ * mln/registration/registration.hh: remove useless to_vec(). Pass a
+ domain to the function to be used to compute the closest point image.
+
+ * mln/transform/internal/closest_point_functor.hh: Store point indexes
+ instead of points.
+
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Reorder data in the vector returned by to_vec().
* mln/core/concept/gdpoint.hh,
diff --git a/milena/mln/registration/icp.hh b/milena/mln/registration/icp.hh
index de763ea..d484f5c 100644
--- a/milena/mln/registration/icp.hh
+++ b/milena/mln/registration/icp.hh
@@ -49,28 +49,31 @@
# include <mln/set/compute.hh>
//Should be removed when closest_point functors are moved.
+# include <mln/core/image/slice_image.hh>
+# include <mln/core/image/tr_image.hh>
+# include <mln/core/image/extension_fun.hh>
+
# include <mln/core/alias/neighb3d.hh>
+
# include <mln/transform/internal/closest_point_functor.hh>
# include <mln/canvas/distance_geodesic.hh>
# include <mln/pw/all.hh>
# include <mln/io/ppm/save.hh>
# include <mln/io/pbm/save.hh>
+
# include <mln/debug/colorize.hh>
+# include <mln/debug/histo.hh>
+
+# include <mln/accu/histo.hh>
+# include <mln/accu/sum.hh>
+
+# include <mln/value/int_u16.hh>
# include <mln/literal/black.hh>
# include <mln/literal/white.hh>
# include <mln/literal/colors.hh>
-# include <mln/core/image/slice_image.hh>
-
-#include <mln/core/image/tr_image.hh>
-#include <mln/core/image/extension_fun.hh>
-
-#include <mln/accu/histo.hh>
-#include <mln/accu/sum.hh>
-#include <mln/debug/histo.hh>
-
# include <mln/util/timer.hh>
namespace mln
@@ -129,7 +132,7 @@ namespace mln
class closest_point_with_map
{
typedef mln_image_from_grid(mln_grid(P), P) I;
- typedef mln_ch_value(I, P) cp_ima_t;
+ typedef mln_ch_value(I, unsigned) cp_ima_t;
typedef mln_ch_value(I,value::int_u16) dmap_t;
public:
@@ -137,6 +140,7 @@ namespace mln
closest_point_with_map(const p_array<P>& X)
{
box3d box = geom::bbox(X);
+ box.enlarge(0, box.nslis());
box.enlarge(1, box.nrows());
box.enlarge(2, box.ncols());
@@ -144,11 +148,13 @@ namespace mln
std::cout << "Map image defined on " << box << std::endl;
+ X_ = X;
init(X, box);
}
closest_point_with_map(const p_array<P>& X, const box<P>& box)
{
+ X_ = X;
init(X, box);
}
@@ -159,13 +165,14 @@ namespace mln
data::fill(model, false);
data::fill((model | X).rw(), true);
- transform::internal::closest_point_functor<model_t> f;
+ transform::internal::closest_point_functor<model_t> f(X);
+
util::timer t;
t.start();
dmap_X_ = canvas::distance_geodesic(model, c6(),
mln_max(value::int_u16),
f);
- std::cout << "canvas::distance_geodesic - " << t << "s" << std::endl;
+ std::cout << "distance_geodesic = " << t << "s" << std::endl;
initialize(this->cp_ima_, f.cp_ima);
this->cp_ima_ = f.cp_ima;
@@ -202,14 +209,18 @@ namespace mln
mln_site(I) operator()(const mln_site(I)& p) const
{
- return cp_ima_(p);
+ return X_[cp_ima_(p)];
}
+
// Distance map
dmap_t dmap_X_;
+
+ private:
+ p_array<P> X_;
// Closest point image.
cp_ima_t cp_ima_;
- private:
+
};
@@ -229,17 +240,18 @@ namespace mln
mln_site(I) operator()(const vec3d_f& v) const
{
- vec3d_f best_x = convert::to<vec3d_f>(X_[0].to_vec());
+ vec3d_f best_x = X_[0];
float best_d = norm::l2_distance(v, best_x);
mln_piter(X_t) X_i(X_);
for_all(X_i)
{
- float d = norm::l2_distance(v, convert::to<vec3d_f>(X_i));
+ vec3d_f X_i_vec = X_i;
+ float d = norm::l2_distance(v, X_i_vec);
if (d < best_d)
{
best_d = d;
- best_x = X_i.to_vec();
+ best_x = X_i_vec;
}
}
return best_x;
@@ -266,11 +278,11 @@ namespace mln
mln_piter(p_array<P>) p(kept);
for_all(p)
- ext_result(qR.rotate(p.to_vec()) + qT) = literal::green;
+ ext_result(qR.rotate(p) + qT) = literal::green;
mln_piter(p_array<P>) p2(removed);
for_all(p2)
- ext_result(qR.rotate(p2.to_vec()) + qT) = literal::red;
+ ext_result(qR.rotate(p2) + qT) = literal::red;
io::ppm::save(slice(ext_result,0), "registered-2.ppm");
}
@@ -289,7 +301,7 @@ namespace mln
mln_piter(p_array<P>) p(P_);
for_all(p)
{
- vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second;
+ vec3d_f Pk_i = pair.first.rotate(p) + pair.second;
vec3d_f Yk_i = closest_point(Pk_i).to_vec();
// yk_i - pk_i
e_k_accu.take(Yk_i - Pk_i);
@@ -317,8 +329,8 @@ namespace mln
for_all(p)
{
- vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second;
- vec3d_f Yk_i = closest_point(Pk_i).to_vec();
+ vec3d_f Pk_i = pair.first.rotate(p) + pair.second;
+ vec3d_f Yk_i = closest_point(Pk_i);
int d_i = closest_point.dmap_X_(Pk_i);
if (d_i >= d_min && d_i <= d_max)
@@ -399,7 +411,7 @@ namespace mln
for_all(p)
{
vec3d_f Pk_i = pair.first.rotate(p.to_vec()) + pair.second;
- vec3d_f Yk_i = closest_point(Pk_i).to_vec();
+ vec3d_f Yk_i = closest_point(Pk_i);
int d_i = closest_point.dmap_X_(Pk_i);
if (d_i >= d_min && d_i <= d_max)
@@ -440,31 +452,27 @@ namespace mln
const std::pair<algebra::quat,mln_vec(P)>& pair,
const std::string& period, const value::rgb8& c)
{
-# ifndef NDEBUG
data::fill(out, literal::black);
data::fill((out | X).rw(), literal::white);
-# endif // !NDEBUG
mln_piter(p_array<P>) p1(P_);
for_all(p1)
{
- vec3d_f Pk_i = pair.first.rotate(p1.to_vec()) + pair.second;
+ vec3d_f Pk_i = pair.first.rotate(p1) + pair.second;
out(Pk_i) = literal::red;
}
mln_piter(p_array<P>) p2(P_sub);
for_all(p2)
{
- vec3d_f Pk_i = pair.first.rotate(p2.to_vec()) + pair.second;
+ vec3d_f Pk_i = pair.first.rotate(p2) + pair.second;
out(Pk_i) = c;
}
-# ifndef NDEBUG
std::ostringstream ss;
ss << prefix << "_" << r << "_" << period << ".ppm";
io::ppm::save(slice(out,0), ss.str());
-# endif // ! NDEBUG
}
@@ -483,8 +491,9 @@ namespace mln
for_all(p)
{
// yk_i - pk+1_i
- vec3d_f Pk_i = qR_old.rotate(p.to_vec()) + qT_old;
- vec3d_f Pk_1_i = qR.rotate(p.to_vec()) + qT;
+ vec3d_f P_i = p;
+ vec3d_f Pk_i = qR_old.rotate(P_i) + qT_old;
+ vec3d_f Pk_1_i = qR.rotate(P_i) + qT;
accu.take(closest_point(Pk_i).to_vec() - Pk_1_i);
}
return accu.to_result();
@@ -508,9 +517,9 @@ namespace mln
// FIXME: could we use an accu?
for_all(p)
{
- vec3d_f P_i = p.to_vec();
- vec3d_f Pk_i = qR.rotate(p.to_vec()) + qT;
- vec3d_f Yk_i = closest_point(Pk_i).to_vec();
+ vec3d_f P_i = p;
+ vec3d_f Pk_i = qR.rotate(P_i) + qT;
+ vec3d_f Yk_i = closest_point(Pk_i);
Spx += make::mat(P_i - mu_P) * trans(make::mat(Yk_i - mu_Yk));
}
Spx /= P_.nsites();
@@ -564,7 +573,7 @@ namespace mln
{
// yk_i - pk_i
vec3d_f Pk_i = qR.rotate(p.to_vec()) + qT;
- vec3d_f Yk_i = closest_point(Pk_i).to_vec();
+ vec3d_f Yk_i = closest_point(Pk_i);
mu_yk.take(Yk_i);
e_k_accu.take(Yk_i - Pk_i);
}
@@ -641,7 +650,7 @@ namespace mln
image3d<value::rgb8> tmp_ = duplicate(debug);
mln_piter(p_array<P>) p_dbg(P_);
for_all(p_dbg)
- tmp_(qR_old.rotate(p_dbg.to_vec()) + qT_old) = literal::green;
+ tmp_(qR_old.rotate(p_dbg) + qT_old) = literal::green;
std::ostringstream ss;
ss << "tmp_0";
if (k < 10)
diff --git a/milena/mln/registration/registration.hh b/milena/mln/registration/registration.hh
index 21d6ea5..98c5ae9 100644
--- a/milena/mln/registration/registration.hh
+++ b/milena/mln/registration/registration.hh
@@ -34,6 +34,7 @@
/// \sa registration::icp
# include <mln/core/image/image3d.hh>
+# include <mln/core/site_set/box.hh>
# include <mln/registration/icp.hh>
# include <mln/fun/x2x/all.hh>
# include <mln/fun/x2p/closest_point.hh>
@@ -56,7 +57,8 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration1(const p_array<P>& P_,
+ registration1(const box<P>& domain,
+ const p_array<P>& P_,
const p_array<P>& X);
//FIXME: move to registration.hh
@@ -70,7 +72,8 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration2(const p_array<P>& P_,
+ registration2(const box<P>& domain,
+ const p_array<P>& P_,
const p_array<P>& X);
//FIXME: move to registration.hh
@@ -83,7 +86,8 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration3(const p_array<P>& P_,
+ registration3(const box<P>& domain,
+ const p_array<P>& P_,
const p_array<P>& X);
@@ -119,8 +123,9 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration1(const p_array<P>& P_,
- const p_array<P>& X)
+ registration1(const box<P>& domain,
+ const p_array<P>& P_,
+ const p_array<P>& X)
{
trace::entering("mln::registration::registration1");
@@ -129,7 +134,7 @@ namespace mln
t.start();
# endif // ! NDEBUG
- registration::closest_point_with_map<P> closest_point(X);
+ registration::closest_point_with_map<P> closest_point(X, domain);
std::pair<algebra::quat,mln_vec(P)> pair = icp(P_, X, closest_point,
algebra::quat(1,0,0,0),
@@ -153,15 +158,16 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration2(const p_array<P>& P_,
- const p_array<P>& X)
+ registration2(const box<P>& domain,
+ const p_array<P>& P_,
+ const p_array<P>& X)
{
trace::entering("mln::registration::registration2");
// Used for debug.
std::string method = "registration2";
- registration::closest_point_with_map<P> closest_point(X);
+ registration::closest_point_with_map<P> closest_point(X, domain);
# ifndef NDEBUG
util::timer t;
@@ -175,12 +181,9 @@ namespace mln
std::pair<algebra::quat,mln_vec(P)> pair;
pair.first = algebra::quat(1,0,0,0);
pair.second = literal::zero;
- box3d box = geom::bbox(X);
- box.enlarge(1, 60);
- box.enlarge(2, 60);
// Used for debug.
- image3d<value::rgb8> out(box);
+ image3d<value::rgb8> out(domain);
p_array<P> removed_set;
@@ -219,7 +222,7 @@ namespace mln
# ifndef NDEBUG
std::cout << "icp = " << t << std::endl;
- draw_last_run(box, P_bak, removed_set, X, pair.first, pair.second);
+ draw_last_run(domain, P_bak, removed_set, X, pair.first, pair.second);
# endif
typedef rotation<3u,float> rot_t;
@@ -237,15 +240,13 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration3(const p_array<P>& P_,
- const p_array<P>& X)
+ registration3(const box<P>& domain,
+ const p_array<P>& P_,
+ const p_array<P>& X)
{
trace::entering("mln::registration::registration3");
- registration::closest_point_with_map<P> closest_point(X);
- std::cout << " pmin and pmax: " << std::endl;
- std::cout << closest_point.cp_ima_.domain().pmin() << std::endl;
- std::cout << closest_point.cp_ima_.domain().pmax() << std::endl;
+ registration::closest_point_with_map<P> closest_point(X, domain);
// Used for debug.
std::string method = "registration3";
@@ -262,12 +263,9 @@ namespace mln
std::pair<algebra::quat,mln_vec(P)> pair;
pair.first = algebra::quat(1,0,0,0);
pair.second = literal::zero;
- box3d box = geom::bbox(X);
- box.enlarge(1, 60);
- box.enlarge(2, 60);
// Used for debug.
- image3d<value::rgb8> out(box);
+ image3d<value::rgb8> out(domain);
p_array<P> removed_set;
@@ -306,7 +304,7 @@ namespace mln
# ifndef NDEBUG
std::cout << "icp = " << t << std::endl;
- draw_last_run(box, P_bak, removed_set, X, pair.first, pair.second);
+ draw_last_run(domain, P_bak, removed_set, X, pair.first, pair.second);
# endif // ! NDEBUG
typedef rotation<3u,float> rot_t;
@@ -329,7 +327,8 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration1(const p_array<P>& cloud,
+ registration1(const box<P>& domain,
+ const p_array<P>& cloud,
const p_array<P>& surface)
{
trace::entering("registration::registration1");
@@ -337,7 +336,7 @@ namespace mln
internal::registration_tests(cloud, surface);
composed< translation<P::dim,float>, rotation<P::dim,float> >
- qk = impl::registration1(cloud, surface);
+ qk = impl::registration1(domain, cloud, surface);
trace::exiting("registration::registration1");
@@ -348,7 +347,8 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration2(const p_array<P>& cloud,
+ registration2(const box<P>& domain,
+ const p_array<P>& cloud,
const p_array<P>& surface)
{
trace::entering("registration::registration2");
@@ -356,7 +356,7 @@ namespace mln
internal::registration_tests(cloud, surface);
composed< translation<P::dim,float>, rotation<P::dim,float> >
- qk = impl::registration2(cloud, surface);
+ qk = impl::registration2(domain, cloud, surface);
trace::exiting("registration::registration2");
@@ -367,7 +367,8 @@ namespace mln
template <typename P>
inline
composed< translation<P::dim,float>,rotation<P::dim,float> >
- registration3(const p_array<P>& cloud,
+ registration3(const box<P>& domain,
+ const p_array<P>& cloud,
const p_array<P>& surface)
{
trace::entering("registration::registration3");
@@ -375,7 +376,7 @@ namespace mln
internal::registration_tests(cloud, surface);
composed< translation<P::dim,float>, rotation<P::dim,float> >
- qk = impl::registration3(cloud, surface);
+ qk = impl::registration3(domain, cloud, surface);
trace::exiting("registration::registration3");
diff --git a/milena/mln/transform/internal/closest_point_functor.hh b/milena/mln/transform/internal/closest_point_functor.hh
index 99f8391..098c994 100644
--- a/milena/mln/transform/internal/closest_point_functor.hh
+++ b/milena/mln/transform/internal/closest_point_functor.hh
@@ -50,7 +50,10 @@ namespace mln
typedef mln_value(I) V;
typedef mln_psite(I) P;
- mln_ch_value(I,P) cp_ima;
+ closest_point_functor(const p_array<P>& pset);
+
+ mln_ch_value(I,unsigned) cp_ima;
+ const p_array<P>& pset_;
void init(const I&);
bool inqueue_p_wrt_input_p(const V& input_p);
@@ -58,9 +61,13 @@ namespace mln
bool inqueue_p_wrt_input_n(const V& input_n);
void process(const P&, const P&);
- void init_(const I& input) { initialize(cp_ima, input); }
+ void init_(const I& input)
+ {
+ init(input);
+ }
+
bool inqueue_p_wrt_input_p_(const V& input_p) { return input_p == true; }
- void init_p_(unsigned p) { cp_ima.element(p) = cp_ima.point_at_index(p); }
+ void init_p_(unsigned) { }//cp_ima.element(p) = pset_(cp_ima.point_at_index(p)); }
bool inqueue_p_wrt_input_n_(const V& input_n) { return input_n == false; }
void process_(unsigned p, unsigned n) { cp_ima.element(n) = cp_ima.element(p); }
};
@@ -70,10 +77,22 @@ namespace mln
template <typename I>
inline
+ closest_point_functor<I>::closest_point_functor(const p_array<mln_psite(I)>& pset)
+ : pset_(pset)
+ {
+ }
+
+ template <typename I>
+ inline
void
closest_point_functor<I>::init(const I& input)
{
initialize(cp_ima, input);
+ data::fill(cp_ima, 0u);
+
+ mln_piter(p_array<mln_psite(I)>) p(pset_);
+ for_all(p)
+ cp_ima(p) = p.index();
}
template <typename I>
@@ -87,9 +106,9 @@ namespace mln
template <typename I>
inline
void
- closest_point_functor<I>::init_p(const P& p)
+ closest_point_functor<I>::init_p(const P&)
{
- cp_ima(p) = p;
+// cp_ima(p) = p;
}
template <typename I>
--
1.5.6.5
1
0
* mln/core/concept/gdpoint.hh,
* mln/core/concept/gpoint.hh: make to_vec return a new object.
* mln/core/dpoint.hh,
* mln/core/point.hh: make to_vec return a vector of float with
coordinates ordered as a user would expect, (x,y,z...).
* mln/fun/x2v/bilinear.hh,
* mln/fun/x2v/trilinear.hh: get the coordinates in the proper vector
index.
* mln/fun/x2x/rotation.hh: normalize the axis.
* tests/algebra/h_vec.cc,
* tests/core/alias/dpoint3d.cc,
* tests/core/alias/point1d.cc: fix tests according these changes.
---
milena/ChangeLog | 21 +++++++
milena/mln/core/concept/gdpoint.hh | 2 +-
milena/mln/core/concept/gpoint.hh | 2 +-
milena/mln/core/dpoint.hh | 34 +++++++++--
milena/mln/core/point.hh | 113 +++++++++++++++++++----------------
milena/mln/fun/x2v/bilinear.hh | 8 +-
milena/mln/fun/x2v/trilinear.hh | 6 +-
milena/mln/fun/x2x/rotation.hh | 6 +-
milena/tests/algebra/h_vec.cc | 14 ++--
milena/tests/core/alias/dpoint3d.cc | 2 +-
milena/tests/core/alias/point1d.cc | 12 ++--
11 files changed, 137 insertions(+), 83 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 401a2a6..ce02eb9 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,26 @@
2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+ Reorder data in the vector returned by to_vec().
+
+ * mln/core/concept/gdpoint.hh,
+ * mln/core/concept/gpoint.hh: make to_vec return a new object.
+
+ * mln/core/dpoint.hh,
+ * mln/core/point.hh: make to_vec return a vector of float with
+ coordinates ordered as a user would expect, (x,y,z...).
+
+ * mln/fun/x2v/bilinear.hh,
+ * mln/fun/x2v/trilinear.hh: get the coordinates in the proper vector
+ index.
+
+ * mln/fun/x2x/rotation.hh: normalize the axis.
+
+ * tests/algebra/h_vec.cc,
+ * tests/core/alias/dpoint3d.cc,
+ * tests/core/alias/point1d.cc: fix tests according these changes.
+
+2009-02-20 Guillaume Lazzara <z(a)lrde.epita.fr>
+
Revert patch #3397.
* mln/algebra/quat.hh,
diff --git a/milena/mln/core/concept/gdpoint.hh b/milena/mln/core/concept/gdpoint.hh
index 5a5695e..62408e1 100644
--- a/milena/mln/core/concept/gdpoint.hh
+++ b/milena/mln/core/concept/gdpoint.hh
@@ -166,7 +166,7 @@ namespace mln
{
typedef mln_grid(E) grid;
typedef mln_vec(E) vec;
- const vec& (E::*m)() const = & E::to_vec;
+ vec (E::*m)() const = & E::to_vec;
m = 0;
}
diff --git a/milena/mln/core/concept/gpoint.hh b/milena/mln/core/concept/gpoint.hh
index 12f1b38..40a2420 100644
--- a/milena/mln/core/concept/gpoint.hh
+++ b/milena/mln/core/concept/gpoint.hh
@@ -281,7 +281,7 @@ namespace mln
typedef mln_grid(E) grid;
typedef mln_delta(E) delta;
typedef mln_vec(E) vec;
- const vec& (E::*m)() const = & E::to_vec;
+ vec (E::*m)() const = & E::to_vec;
m = 0;
}
diff --git a/milena/mln/core/dpoint.hh b/milena/mln/core/dpoint.hh
index 17245c5..358013c 100644
--- a/milena/mln/core/dpoint.hh
+++ b/milena/mln/core/dpoint.hh
@@ -125,7 +125,7 @@ namespace mln
operator mln::algebra::vec<dpoint<G,C>::dim, Q>() const;
/// Explicit conversion.
- const vec& to_vec() const;
+ vec to_vec() const;
protected:
mln::algebra::vec<G::dim, C> coord_;
@@ -161,7 +161,17 @@ namespace mln
inline
dpoint<G,C>::dpoint(const algebra::vec<dim,C2>& v)
{
- coord_ = v;
+ // FIXME: to be improved.
+ if (dim < 3)
+ coord_ = v;
+ else
+ {
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ coord_[i] = v[j++];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ coord_[i-j] = v[j];
+ }
}
template <typename G, typename C>
@@ -249,15 +259,29 @@ namespace mln
inline
dpoint<G,C>::operator mln::algebra::vec<dpoint<G,C>::dim, Q> () const
{
- return coord_;
+ return to_vec();
}
template <typename G, typename C>
inline
- const typename dpoint<G,C>::vec&
+ typename dpoint<G,C>::vec
dpoint<G,C>::to_vec() const
{
- return coord_;
+ algebra::vec<G::dim, float> tmp;
+
+ // FIXME: to be improved.
+ if (dim == 1)
+ tmp[0] = coord_[0];
+ else
+ {
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ tmp[j++] = coord_[i];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ tmp[j] = coord_[i-j];
+ }
+
+ return tmp;
}
# endif // ! MLN_INCLUDE_ONLY
diff --git a/milena/mln/core/point.hh b/milena/mln/core/point.hh
index a661fe5..755f50c 100644
--- a/milena/mln/core/point.hh
+++ b/milena/mln/core/point.hh
@@ -61,22 +61,6 @@ namespace mln
/// \}
- namespace internal
- {
-
- // Helper point_to_.
-
- template <typename G, typename C>
- struct point_to_
- {
- typedef algebra::vec<G::dim, C> metal_vec;
- typedef mln::algebra::h_vec<G::dim, C> h_vec;
- };
-
- } // end of namespace mln::internal
-
-
-
/// Generic point class.
///
/// Parameters are \c n the dimension of the space and \c C the
@@ -108,10 +92,10 @@ namespace mln
typedef C coord;
/// Algebra vector (vec) associated type.
- typedef algebra::vec<G::dim, C> vec;
+ typedef algebra::vec<G::dim, float> vec;
/// Algebra hexagonal vector (hvec) associated type.
- typedef algebra::h_vec<G::dim, C> h_vec;
+ typedef algebra::h_vec<G::dim, float> h_vec;
/// Read-only access to the \p i-th coordinate value.
/// \param[in] i The coordinate index.
@@ -171,23 +155,16 @@ namespace mln
/// Shifting by \p the inverse of dp.
point<G,C>& operator-=(const delta& dp);
- /// Hook to coordinates.
- operator typename internal::point_to_<G, C>::metal_vec () const;
- /* FIXME: Seems highly non-generic! Moreover, causes
- overloading/duplicate errors with the previous operator when
- C == float. Disable it for the moment.
-
+ /* FIXME: Seems highly non-generic!
This (non documented change, even in ChangeLog) change was
introduce by revision 1224, see
https://trac.lrde.org/olena/changeset/1224#file2
https://www.lrde.epita.fr/pipermail/olena-patches/2007-October/001592.html
*/
-#if 0
operator algebra::vec<G::dim, float> () const;
-#endif
/// Explicit conversion towards mln::algebra::vec.
- const vec& to_vec() const;
+ vec to_vec() const;
/// Transform to point in homogene coordinate system.
h_vec to_h_vec() const;
@@ -214,7 +191,8 @@ namespace mln
template <typename G, typename C, typename E>
struct subject_point_impl< point<G,C>, E >
{
- const typename point<G,C>::vec& to_vec() const;
+ typename point<G,C>::vec to_vec() const;
+ operator algebra::vec<G::dim, float>() const;
private:
const E& exact_() const;
@@ -281,7 +259,17 @@ namespace mln
inline
point<G,C>::point(const algebra::vec<dim,C2>& v)
{
- coord_ = v;
+ unsigned j = 0;
+ //FIXME: to be improved.
+ if (dim < 3)
+ coord_ = v;
+ else
+ {
+ for (unsigned i = dim - 2; i < dim; ++i)
+ coord_[i] = v[j++];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ coord_[i-j] = v[j];
+ }
}
template <typename G, typename C>
@@ -406,29 +394,29 @@ namespace mln
template <typename G, typename C>
inline
- point<G,C>::operator typename internal::point_to_<G, C>::metal_vec () const
- {
- return coord_; // FIXME: Is it OK?
- }
-
- // FIXME: See declaration of this member above.
-#if 0
- template <typename G, typename C>
- inline
point<G,C>::operator algebra::vec<G::dim, float> () const
{
- algebra::vec<dim, float> tmp;
- for (unsigned int i = 0; i < dim; ++i)
- tmp[i] = coord_[i];
- return tmp;
+ return to_vec();
}
-#endif
template <typename G, typename C>
inline
- const typename point<G,C>::vec&
+ typename point<G,C>::vec
point<G,C>::to_vec() const
{
+ //FIXME: to be improved.
+ if (dim > 2)
+ {
+ algebra::vec<G::dim, float> tmp;
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ tmp[j++] = coord_[i];
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ tmp[j] = coord_[i-j];
+
+ return tmp;
+ }
+
return coord_;
}
@@ -437,10 +425,23 @@ namespace mln
typename point<G,C>::h_vec
point<G,C>::to_h_vec() const
{
- algebra::h_vec<G::dim, C> tmp;
- for (unsigned i = 0; i < dim; ++i)
- tmp[i] = coord_[i];
- tmp[G::dim] = 1;
+ algebra::h_vec<G::dim, float> tmp;
+
+ //FIXME: to be improved.
+ if (dim == 1)
+ tmp[0] = coord_[0];
+ else
+ {
+ unsigned j = 0;
+ for (unsigned i = dim - 2; i < dim; ++i)
+ tmp[j++] = coord_[i];
+
+ for (unsigned i = 2; i < dim; ++i, ++j)
+ tmp[j] = coord_[i-j];
+
+ tmp[G::dim] = 1;
+ }
+
return tmp;
}
@@ -476,20 +477,27 @@ namespace mln
template <typename G, typename C, typename E>
inline
- const typename point<G,C>::vec&
+ typename point<G,C>::vec
subject_point_impl< point<G,C>, E >::to_vec() const
{
return exact_().get_subject().to_vec();
}
+ template <typename G, typename C, typename E>
+ inline
+ subject_point_impl< point<G,C>, E >::operator algebra::vec<G::dim, float>() const
+ {
+ return exact_().get_subject();
+ }
+
} // end of namespace mln::internal
template <typename G, typename C>
inline
- const algebra::vec<point<G,C>::dim - 1, C>&
+ algebra::vec<point<G,C>::dim - 1, C>
cut_(const point<G,C>& p)
{
- return *(const algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec());
+ return *(algebra::vec<point<G,C>::dim - 1, C>*)(& p.to_vec());
}
template <typename C>
@@ -502,7 +510,8 @@ namespace mln
}
# endif // ! MLN_INCLUDE_ONLY
-
+
+
} // end of namespace mln
diff --git a/milena/mln/fun/x2v/bilinear.hh b/milena/mln/fun/x2v/bilinear.hh
index e264462..1daefa8 100644
--- a/milena/mln/fun/x2v/bilinear.hh
+++ b/milena/mln/fun/x2v/bilinear.hh
@@ -79,7 +79,7 @@ namespace mln
template <typename I>
bilinear<I>::bilinear(const I& ima) : ima(ima)
{
- //mlc_bool(I::psite::dim == 2)::check();
+ mlc_or(mlc_bool(I::psite::dim == 2), mlc_bool(I::psite::dim == 3))::check();
}
template <typename I>
@@ -141,14 +141,14 @@ namespace mln
// | | |
// q11----r1----q21
- double x = v[1];
- double y = v[2];
+ double x = v[0];
+ double y = v[1];
double x1 = std::floor(x);
double x2 = std::floor(x) + 1;
double y1 = std::floor(y);
double y2 = std::floor(y) + 1;
- def::coord z = math::round<float>()(v[0]);
+ def::coord z = math::round<float>()(v[3]);
//Following access are supposed valid.
vsum q11 = ima(point3d(z, static_cast<unsigned>(x1), static_cast<unsigned>(y1)));
diff --git a/milena/mln/fun/x2v/trilinear.hh b/milena/mln/fun/x2v/trilinear.hh
index 3015502..2a1d594 100644
--- a/milena/mln/fun/x2v/trilinear.hh
+++ b/milena/mln/fun/x2v/trilinear.hh
@@ -86,9 +86,9 @@ namespace mln
{
typedef mln_sum(mln_value(I)) vsum;
- double x = v[1]; // row
- double y = v[2]; // col
- double z = v[0]; // sli
+ double x = v[0]; // row
+ double y = v[1]; // col
+ double z = v[2]; // sli
math::round<double> f;
unsigned x1 = f(std::floor(x));
diff --git a/milena/mln/fun/x2x/rotation.hh b/milena/mln/fun/x2x/rotation.hh
index 9addb50..cbe1dd2 100644
--- a/milena/mln/fun/x2x/rotation.hh
+++ b/milena/mln/fun/x2x/rotation.hh
@@ -197,10 +197,9 @@ namespace mln
inline
rotation<n,C>::rotation(const algebra::quat& q)
{
- mln_precondition(q.is_unit());
-
// FIXME: Should also work for 2d.
- mln_precondition(n == 3);
+ mlc_bool(n == 3)::check();
+ mln_precondition(q.is_unit());
float
w = q.to_vec()[0],
@@ -221,6 +220,7 @@ namespace mln
axis_[0] = x;
axis_[1] = y;
axis_[2] = z;
+ axis_.normalize();
}
diff --git a/milena/tests/algebra/h_vec.cc b/milena/tests/algebra/h_vec.cc
index e4bffa6..27448e3 100644
--- a/milena/tests/algebra/h_vec.cc
+++ b/milena/tests/algebra/h_vec.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/algebra/h_vec.cc
- *
- * \brief Tests on mln::algebra::h_vec.
- */
+/// \file tests/algebra/h_vec.cc
+///
+/// Tests on mln::algebra::h_vec.
#include <mln/algebra/h_vec.hh>
#include <mln/core/alias/point3d.hh>
@@ -36,11 +36,11 @@
using namespace mln;
-void run_in_3d(const algebra::vec<3, def::coord>&)
+void run_in_3d(const algebra::vec<3, float>&)
{
}
-void run_in_3d_h(const algebra::h_vec<3, def::coord>&)
+void run_in_3d_h(const algebra::h_vec<3, float>&)
{
}
diff --git a/milena/tests/core/alias/dpoint3d.cc b/milena/tests/core/alias/dpoint3d.cc
index 20bcbaf..d538f1b 100644
--- a/milena/tests/core/alias/dpoint3d.cc
+++ b/milena/tests/core/alias/dpoint3d.cc
@@ -49,5 +49,5 @@ int main()
mln_assertion(q == p + dp);
algebra::vec<3, float> v = dp;
- mln_assertion(v[1] == 6);
+ mln_assertion(v[0] == 6);
}
diff --git a/milena/tests/core/alias/point1d.cc b/milena/tests/core/alias/point1d.cc
index fbe8e72..cbcda23 100644
--- a/milena/tests/core/alias/point1d.cc
+++ b/milena/tests/core/alias/point1d.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2007, 2008 EPITA Research and Development Laboratory
+// Copyright (C) 2007, 2008, 2009 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Olena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -25,10 +26,9 @@
// reasons why the executable file might be covered by the GNU General
// Public License.
-/*! \file tests/core/alias/point1d.cc
- *
- * \brief Tests on mln::point1d.
- */
+/// \file tests/core/alias/point1d.cc
+///
+/// Tests on mln::point1d.
#include <mln/core/alias/point1d.hh>
@@ -43,7 +43,7 @@ int main()
// assignment
p[0] = 4;
- algebra::vec<1,def::coord> v = p;
+ algebra::vec<1,float> v = p;
p.ind() += 1;
mln_assertion(p.ind() == 5 && p[0] == 5);
--
1.5.6.5
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-02-20 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update DICOM support to n dimensions.
* fabien/gdcm/gdcm.cc: Update.
* fabien/gdcm/load.hh: Update load support for
multidimensional DICOM.
---
gdcm.cc | 11 ++++++--
load.hh | 80 ++++++++++++++++++----------------------------------------------
2 files changed, 31 insertions(+), 60 deletions(-)
Index: trunk/milena/sandbox/fabien/gdcm/load.hh
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3402)
+++ trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3403)
@@ -39,7 +39,7 @@
# include <mln/core/image/image2d.hh>
# include <mln/core/image/image3d.hh>
-# include <mln/value/int_u16.hh>
+# include <mln/algebra/vec.hh>
# include <gdcmReader.h>
# include <gdcmImageReader.h>
@@ -57,7 +57,7 @@
namespace dicom
{
- /*! Load a gdcm image in a Milena image.
+ /*! Load a dicom image in a Milena image.
*
* \param[out] ima A reference to the image which will receive
* data.
@@ -67,28 +67,6 @@
void load(Image<I>& ima,
const std::string& filename);
- /*! Load a gdcm image in a Milena image. To use this routine, you
- * should specialize the template whith the value type of the
- * image loaded. (ex : load<value::int_u8>("...") )
- *
- * \param[in] filename The image source.
- *
- * \return An image2d which contains loaded data.
- */
- template <typename V>
- image2d<V> load(const std::string& filename);
-
- /*! Load a gdcm image in a Milena image. To use this routine, you
- * should specialize the template whith the value type of the
- * image loaded. (ex : load<value::int_u8>("...") )
- *
- * \param[in] filename The image source.
- *
- * \return An image2d which contains loaded data.
- */
- template <typename V>
- image3d<V> load(const std::string& filename);
-
# ifndef MLN_INCLUDE_ONLY
template <typename V>
@@ -135,52 +113,40 @@
gdcm::Image& image = r.GetImage();
- std::cout << std::endl << "Image information" << std::endl
- << "=================" << std::endl;
- image.Print(std::cout);
-
- std::cout << std::endl << "Buffer information" << std::endl
- << "=================" << std::endl;
- std::cout << "Buffer length: " << image.GetBufferLength() << std::endl;
char* dataBuffer = new char[image.GetBufferLength()];
image.GetBuffer(dataBuffer);
int ndims = image.GetNumberOfDimensions();
const unsigned int* dims = image.GetDimensions();
- // FIXME: Check ScalarType
- if (ndims == 1)
- {
-
- }
- if (ndims == 2)
- {
- //image2d<int_u16> mln_ima(dims[1], dims[0]);
- //mln_piter(image2d<int_u16>) p(ima.domain());
- //for_all(p)
- //{
- // ima(p) = dataBuffer[(p.col() + p.row() * dims[0]) * 2] * 256 +
- // dataBuffer[(p.col() + p.row() * dims[0]) * 2 + 1];
- //}
+ algebra::vec<mln_site_(I)::dim, unsigned int> vmin;
+ algebra::vec<mln_site_(I)::dim, unsigned int> vmax;
+ algebra::vec<mln_site_(I)::dim, unsigned int> vdims;
+ for (int i = ndims - 1; i >= 0; --i)
+ {
+ vmin[i] = 0;
+ vmax[i] = dims[ndims - i - 1] - 1;
+ if (i == ndims - 1)
+ vdims[i] = 1;
+ else
+ vdims[i] = dims[ndims - i - 2] * vdims[i + 1];
}
- if (ndims == 3)
- {
- //image3d<int_u16> ima(dims[2], dims[1], dims[0]);
- mln_site(I) pmin(0, 0, 0);
- mln_site(I) pmax(dims[2] - 1, dims[1] - 1, dims[0] - 1);
+
+ mln_site(I) pmin(vmin);
+ mln_site(I) pmax(vmax);
mln_concrete(I) result(box<mln_site(I)>(pmin, pmax));
initialize(ima, result);
mln_piter(I) p(ima.domain());
+ // FIXME: Check ScalarType and HighBit
+ unsigned int index = 0;
for_all(p)
{
- ima(p) = dataBuffer[(p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2] * 256 +
- dataBuffer[(p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2 + 1];
- std::cout << (p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2 << " ["
- << "p.col = " << p.col() << "] ["
- << "p.row = " << p.row() << "] ["
- << "p.sli = " << p.sli() << "]"
- << std::endl;
+ index = 0;
+ for (int i = 0; i < ndims; ++i)
+ {
+ index += p.to_site().to_vec()[i] * vdims[i];
}
+ ima(p) = dataBuffer[index * 2] * 256 + dataBuffer[index * 2 + 1];
}
delete(dataBuffer);
Index: trunk/milena/sandbox/fabien/gdcm/gdcm.cc
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3402)
+++ trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3403)
@@ -1,18 +1,23 @@
#include <mln/core/image/image2d.hh>
+#include <mln/core/image/image3d.hh>
#include <mln/value/int_u8.hh>
#include <mln/value/int_u16.hh>
#include "load.hh"
#include <mln/io/dump/save.hh>
+#include <mln/io/pgm/save.hh>
int main()
{
using namespace mln;
using value::int_u16;
- image3d<int_u16> lena;
+ image2d<int_u16> lena2;
+ image3d<int_u16> lena3;
- io::dicom::load(lena, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0061.dcm");
- io::dump::save(lena, "IM_0061.dump");
+ //io::dicom::load(lena3, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0058.dcm");
+ io::dicom::load(lena2, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0058.dcm");
+ //io::dump::save(lena3, "IM_0058.dump");
+ io::pgm::save(lena2, "IM_0058.pgm");
}
1
0
URL: https://svn.lrde.epita.fr/svn/oln/trunk/milena/sandbox
ChangeLog:
2009-02-20 Fabien Freling <fabien.freling(a)lrde.epita.fr>
Update DICOM loader.
* fabien/gdcm/Makefile: Update.
* fabien/gdcm/dump2pgm.cc: New tool to convert dump volume
to a pgm flat image.
* fabien/gdcm/gdcm.cc: Update.
* fabien/gdcm/load.hh: Update.
---
Makefile | 2 +-
dump2pgm.cc | 35 +++++++++++++++++++++++++++++++++++
gdcm.cc | 4 ++--
load.hh | 16 ++++++++++------
4 files changed, 48 insertions(+), 9 deletions(-)
Index: trunk/milena/sandbox/fabien/gdcm/dump2pgm.cc
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/dump2pgm.cc (revision 0)
+++ trunk/milena/sandbox/fabien/gdcm/dump2pgm.cc (revision 3402)
@@ -0,0 +1,35 @@
+
+#include <mln/core/image/image2d.hh>
+#include <mln/make/image3d.hh>
+#include <mln/debug/slices_2d.hh>
+
+#include <mln/value/int_u16.hh>
+#include <mln/io/dump/load.hh>
+#include <mln/io/pgm/save.hh>
+
+#include <mln/literal/colors.hh>
+
+
+void usage(char* argv[])
+{
+ std::cerr << "usage: " << argv[0] << " input.dump output.pgm" << std::endl;
+ abort();
+}
+
+
+
+int main(int argc, char* argv[])
+{
+ using namespace mln;
+ using value::int_u16;
+
+ if (argc != 3)
+ usage(argv);
+
+ image3d<int_u16> vol;
+ io::dump::load(vol, argv[1]);
+
+ int_u16 bg = 0;
+ image2d<int_u16> ima = debug::slices_2d(vol, 1.f, bg);
+ io::pgm::save(ima, argv[2]);
+}
Index: trunk/milena/sandbox/fabien/gdcm/Makefile
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/Makefile (revision 3401)
+++ trunk/milena/sandbox/fabien/gdcm/Makefile (revision 3402)
@@ -8,5 +8,5 @@
-L/Users/HiSoKa/Downloads/gdcmbin/bin \
-lgdcmCommon -lgdcmDICT -lgdcmDSED -lgdcmIOD -lgdcmMSFF -lgdcmexpat -lgdcmjpeg12 -lgdcmjpeg16 -lgdcmjpeg8 -lgdcmopenjpeg -lgdcmuuid -lgdcmzlib \
-framework CoreFoundation \
- -DNDEBUG \
+ -DNDEBUG -O1 \
gdcm.cc -o mln_gdcm
Index: trunk/milena/sandbox/fabien/gdcm/load.hh
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3401)
+++ trunk/milena/sandbox/fabien/gdcm/load.hh (revision 3402)
@@ -143,10 +143,7 @@
<< "=================" << std::endl;
std::cout << "Buffer length: " << image.GetBufferLength() << std::endl;
char* dataBuffer = new char[image.GetBufferLength()];
- if (image.GetBuffer(dataBuffer))
- std::cout << "GetBuffer success" << std::endl;
- else
- std::cout << "GetBuffer failure" << std::endl;
+ image.GetBuffer(dataBuffer);
int ndims = image.GetNumberOfDimensions();
const unsigned int* dims = image.GetDimensions();
@@ -170,17 +167,24 @@
{
//image3d<int_u16> ima(dims[2], dims[1], dims[0]);
mln_site(I) pmin(0, 0, 0);
- mln_site(I) pmax(dims[2], dims[1], dims[0]);
+ mln_site(I) pmax(dims[2] - 1, dims[1] - 1, dims[0] - 1);
mln_concrete(I) result(box<mln_site(I)>(pmin, pmax));
initialize(ima, result);
- mln_piter(image3d<int_u16>) p(ima.domain());
+ mln_piter(I) p(ima.domain());
for_all(p)
{
ima(p) = dataBuffer[(p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2] * 256+
dataBuffer[(p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2 + 1];
+ std::cout << (p.col() + p.row() * dims[0] + p.sli() * dims[0] * dims[1]) * 2 << " ["
+ << "p.col = " << p.col() << "] ["
+ << "p.row = " << p.row() << "] ["
+ << "p.sli = " << p.sli() << "]"
+ << std::endl;
}
}
+ delete(dataBuffer);
+
trace::exiting("mln::io::dicom::load");
}
Index: trunk/milena/sandbox/fabien/gdcm/gdcm.cc
===================================================================
--- trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3401)
+++ trunk/milena/sandbox/fabien/gdcm/gdcm.cc (revision 3402)
@@ -13,6 +13,6 @@
image3d<int_u16> lena;
- io::dicom::load(lena, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0052.dcm");
- io::dump::save(lena, "IM_0052.dump");
+ io::dicom::load(lena, "/Users/HiSoKa/Work/IGR/souris18/irm/IM_0061.dcm");
+ io::dump::save(lena, "IM_0061.dump");
}
1
0