* apps/statues/mesh-complex-segm.cc: New.
* apps/statues/Makefile.am (bin_PROGRAMS): Add mesh-complex-segm.
(mesh_complex_segm_SOURCES): New.
* apps/statues/test.in: Exercise mesh-complex-segm.
* mln/core/alias/complex_image.hh
(mln::unsigned_2complex_image3df): New typedef.
---
milena/ChangeLog | 11 ++
milena/apps/statues/Makefile.am | 8 ++
milena/apps/statues/mesh-complex-segm.cc | 163 ++++++++++++++++++++++++++++++
milena/apps/statues/test.in | 4 +
milena/mln/core/alias/complex_image.hh | 11 ++-
5 files changed, 195 insertions(+), 2 deletions(-)
create mode 100644 milena/apps/statues/mesh-complex-segm.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 9224c7f..e35b296 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,16 @@
2008-11-19 Roland Levillain <roland(a)lrde.epita.fr>
+ New application: surface segmentation using complex-based images.
+
+ * apps/statues/mesh-complex-segm.cc: New.
+ * apps/statues/Makefile.am (bin_PROGRAMS): Add mesh-complex-segm.
+ (mesh_complex_segm_SOURCES): New.
+ * apps/statues/test.in: Exercise mesh-complex-segm.
+ * mln/core/alias/complex_image.hh
+ (mln::unsigned_2complex_image3df): New typedef.
+
+2008-11-19 Roland Levillain <roland(a)lrde.epita.fr>
+
* mln/core/site_set/p_array.hh (nsites): Fix return type.
2008-11-18 Roland Levillain <roland(a)lrde.epita.fr>
diff --git a/milena/apps/statues/Makefile.am b/milena/apps/statues/Makefile.am
index 971a4ec..d1e65f7 100644
--- a/milena/apps/statues/Makefile.am
+++ b/milena/apps/statues/Makefile.am
@@ -53,4 +53,12 @@ mesh_max_curv_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh)
mesh_max_curv_LDFLAGS = $(LDFLAGS_trimesh)
mesh_max_curv_LDADD = $(LDADD_trimesh)
+## ---------------------------------------------------- ##
+## Complex-based applications, independent of Trimesh. ##
+## ---------------------------------------------------- ##
+
+bin_PROGRAMS += mesh-complex-segm
+mesh_complex_segm_SOURCES = mesh-complex-segm.cc
+
+
TESTS = test
diff --git a/milena/apps/statues/mesh-complex-segm.cc
b/milena/apps/statues/mesh-complex-segm.cc
new file mode 100644
index 0000000..05fffe0
--- /dev/null
+++ b/milena/apps/statues/mesh-complex-segm.cc
@@ -0,0 +1,163 @@
+// Copyright (C) 2008 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
+// of the GNU General Public License version 2 as published by the
+// Free Software Foundation.
+//
+// This library is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+// General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this library; see the file COPYING. If not, write to
+// the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+// Boston, MA 02111-1307, USA.
+//
+// As a special exception, you may use this file as part of a free
+// software library without restriction. Specifically, if other files
+// instantiate templates or use macros or inline functions from this
+// file, or you compile this file and link it with other files to
+// produce an executable, this file does not by itself cause the
+// resulting executable to be covered by the GNU General Public
+// License. This exception does not however invalidate any other
+// reasons why the executable file might be covered by the GNU General
+// Public License.
+
+/// \file apps/statues/mesh-complex-segm.cc
+/// \brief A program performing a WST-based segmentation of the
+/// surface of the (triangle) mesh of a statue, using a complex-based
+/// image.
+
+#include <cstdlib>
+#include <cmath>
+
+#include <utility>
+#include <iostream>
+
+#include <mln/core/image/complex_image.hh>
+#include <mln/core/image/complex_neighborhoods.hh>
+
+#include <mln/morpho/closing_area.hh>
+#include <mln/morpho/meyer_wst.hh>
+
+#include <mln/literal/white.hh>
+
+#include <mln/io/off/load.hh>
+#include <mln/io/off/save.hh>
+
+
+
+int main(int argc, char* argv[])
+{
+ if (argc != 4)
+ {
+ std::cerr << "usage: " << argv[0] << " input.off
lambda output.off"
+ << std::endl;
+ exit(1);
+ }
+
+ std::string input_filename = argv[1];
+ unsigned lambda = atoi(argv[2]);
+ std::string output_filename = argv[3];
+
+ /*----------------.
+ | Complex image. |
+ `----------------*/
+
+ // Image type.
+ typedef mln::float_2complex_image3df ima_t;
+ // Dimension of the image (and therefore of the complex).
+ static const unsigned D = ima_t::dim;
+ // Geometry of the image.
+ typedef mln_geom_(ima_t) G;
+
+ ima_t input;
+ mln::io::off::load(input, input_filename);
+
+ // Values on edges.
+
+ /* FIXME: To be improved: instead of computing the curvature on
+ edges from a mean of the curvature on adjacent polygons, compute
+ it directly from the curvature on vertices. We should probably
+ integrate Trimesh's curvature computation into Milena. */
+ mln::p_n_faces_fwd_piter<D, G> e(input.domain(), 1);
+ typedef mln::complex_higher_neighborhood<D, G> adj_polygons_nbh_t;
+ adj_polygons_nbh_t adj_polygons_nbh;
+ mln_niter_(adj_polygons_nbh_t) p(adj_polygons_nbh, e);
+ // Iterate on edges (1-faces).
+ for_all(e)
+ {
+ float s = 0.0f;
+ unsigned n = 0;
+ for_all(p)
+ {
+ s += input(p);
+ ++n;
+ }
+ input(e) = s / n;
+ // An edge should be adjacent to two polygons at most.
+ mln_invariant(n <= 2);
+ }
+
+ /*-----------------.
+ | Simplification. |
+ `-----------------*/
+
+ /// Adjancent edges are connected by shared polygons.
+ typedef
+ mln::complex_higher_dim_connected_n_face_neighborhood<D, G>
+ adj_edges_nbh_t;
+ adj_edges_nbh_t adj_edges_nbh;
+
+ ima_t closed_input(input.domain());
+ mln::morpho::closing_area(input, adj_edges_nbh, lambda, closed_input);
+
+ /*------.
+ | WST. |
+ `------*/
+
+ /* FIXME: Note that the WST is either doing too much work, since we
+ have not constrained the domain of the image to 1-faces only.
+
+ It would be great if we could use something like this:
+
+ closed_input | mln::p_faces<1, D, G>(closed_input.domain())
+
+ as input of the WST. */
+
+ // Compute the WST on edges.
+ typedef unsigned wst_val_t;
+ wst_val_t nbasins;
+ typedef mln::unsigned_2complex_image3df wst_ima_t;
+ wst_ima_t wshed =
+ mln::morpho::meyer_wst(closed_input, adj_edges_nbh, nbasins);
+ std::cout << "nbasins = " << nbasins << std::endl;
+
+ // Label polygons (i.e., propagate labels from edges to polygons).
+ for_all(e)
+ if (wshed(e) != 0)
+ for_all(p)
+ wshed(p) = wshed(e);
+
+ /*---------.
+ | Output. |
+ `---------*/
+
+ mln::rgb8_2complex_image3df output(wshed.domain());
+ mln::level::fill(output, mln::literal::white);
+
+ // FIXME: Use a colorize functor instead.
+ // Choose random colors for each basin number.
+ std::vector<mln::value::rgb8> basin_color (nbasins + 1);
+ for (unsigned i = 0; i <= nbasins; ++i)
+ basin_color[i] = mln::value::rgb8(random() % 256,
+ random() % 256,
+ random() % 256);
+ mln_piter_(ima_t) f(wshed.domain());
+ for_all(f)
+ output(f) = basin_color[wshed(f)];
+
+ mln::io::off::save(output, output_filename);
+}
diff --git a/milena/apps/statues/test.in b/milena/apps/statues/test.in
index 181a1fd..92c9d31 100755
--- a/milena/apps/statues/test.in
+++ b/milena/apps/statues/test.in
@@ -7,3 +7,7 @@ mesh_dir=@top_srcdir@/milena/mesh
time ./mesh-segm $mesh_dir/socket.off 25 socket-segm.off
time ./mesh-segm $mesh_dir/teapot.off 50 teapot-segm.off
time ./mesh-segm $mesh_dir/bunny-holefilled.off 500 bunny-holefilled-segm.off
+
+time ./mesh-complex-segm $mesh_dir/socket-max-curv.off 25 socket-max-curv-segm.off
+time ./mesh-complex-segm $mesh_dir/teapot-max-curv.off 50 teapot-max-curv-segm.off
+time ./mesh-complex-segm $mesh_dir/bunny-holefilled-pinv-curv.off 500
bunny-holefilled-pinv-curv-segm.off
diff --git a/milena/mln/core/alias/complex_image.hh
b/milena/mln/core/alias/complex_image.hh
index 9dc5956..6336d6b 100644
--- a/milena/mln/core/alias/complex_image.hh
+++ b/milena/mln/core/alias/complex_image.hh
@@ -47,12 +47,19 @@ namespace mln
mln::complex_image<2, mln::space_2complex_geometry, bool>
bin_2complex_image3df;
+ /// \brief Type alias for an 8-bit grey-level image based on a
+ /// 2-complex, where 0-faces are located at floating-point
+ /// 3-dimensional points.
+ typedef
+ mln::complex_image<2, mln::space_2complex_geometry, mln::value::int_u8>
+ int_u8_2complex_image3df;
+
/// \brief Type alias for a grey-level image based on a 2-complex,
/// where 0-faces are located at floating-point 3-dimensional
/// points.
typedef
- mln::complex_image<2, mln::space_2complex_geometry, mln::value::int_u8>
- int_u8_2complex_image3df;
+ mln::complex_image<2, mln::space_2complex_geometry, unsigned>
+ unsigned_2complex_image3df;
/// \brief Type alias for a floating-point image based on a
/// 2-complex, where 0-faces are located at floating-point
--
1.6.0.1