* apps/mesh-segm-skel/mesh-segm.cc: Catch up with the new
interface of graphs.
Use mln::edge_image instead of mln::line_graph_image.
Turn a test into an invariant.
Use mln::morpho::watershed::flooding instead of
mln::morpho::meyer_wst.
* apps/mesh-segm-skel/Makefile.am (bin_PROGRAMS):
Re-enable mesg-segm.
(mesh_segm_SOURCES, mesh_segm_CPPFLAGS)
(mesh_segm_LDFLAGS, mesh_segm_LDADD):
Re-enable.
(TESTS): Reenable test-mesh-segm.
(MOSTLYCLEANFILES): Reenable socket-segm.off and teapot-segm.off.
---
milena/ChangeLog | 18 +++++
milena/apps/mesh-segm-skel/Makefile.am | 28 +++++----
milena/apps/mesh-segm-skel/mesh-segm.cc | 110 +++++++++++++++++++------------
3 files changed, 103 insertions(+), 53 deletions(-)
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 2d28537..b2f2330 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,3 +1,21 @@
+2010-05-11 Roland Levillain <roland(a)lrde.epita.fr>
+
+ Revive, fix and update application mesh-segm.
+
+ * apps/mesh-segm-skel/mesh-segm.cc: Catch up with the new
+ interface of graphs.
+ Use mln::edge_image instead of mln::line_graph_image.
+ Turn a test into an invariant.
+ Use mln::morpho::watershed::flooding instead of
+ mln::morpho::meyer_wst.
+ * apps/mesh-segm-skel/Makefile.am (bin_PROGRAMS):
+ Re-enable mesg-segm.
+ (mesh_segm_SOURCES, mesh_segm_CPPFLAGS)
+ (mesh_segm_LDFLAGS, mesh_segm_LDADD):
+ Re-enable.
+ (TESTS): Reenable test-mesh-segm.
+ (MOSTLYCLEANFILES): Reenable socket-segm.off and teapot-segm.off.
+
2010-05-10 Roland Levillain <roland(a)lrde.epita.fr>
Fix a bug in the reimplementation of Trimesh algorithms.
diff --git a/milena/apps/mesh-segm-skel/Makefile.am
b/milena/apps/mesh-segm-skel/Makefile.am
index 9768f25..501dec0 100644
--- a/milena/apps/mesh-segm-skel/Makefile.am
+++ b/milena/apps/mesh-segm-skel/Makefile.am
@@ -1,4 +1,5 @@
-# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE).
+# Copyright (C) 2008, 2009, 2010 EPITA Research and Development
+# Laboratory (LRDE).
#
# This file is part of Olena.
#
@@ -49,19 +50,22 @@ MOSTLYCLEANFILES =
## ------------------------------------------------ ##
if ENABLE_TRIMESH
-# bin_PROGRAMS += mesh-segm mesh-skel
-#
-# mesh_segm_SOURCES = mesh-segm.cc io.hh
-# mesh_segm_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh)
-# mesh_segm_LDFLAGS = $(LDFLAGS_trimesh)
-# mesh_segm_LDADD = $(LDADD_trimesh)
-#
-# TESTS += test-mesh-segm
-# MOSTLYCLEANFILES += socket-segm.off teapot-segm.off
-
-# FIXME: mesh_skel is unfinished. Anyway, it should be superseded by
-# another program, using no Trimesh code.
-
+## FIXME: Rename as mesh-trimesh-graph-{max,pinv}-curv-segm?
+bin_PROGRAMS += mesh-segm
+mesh_segm_SOURCES = mesh-segm.cc io.hh
+mesh_segm_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh)
+mesh_segm_LDFLAGS = $(LDFLAGS_trimesh)
+mesh_segm_LDADD = $(LDADD_trimesh)
+
+TESTS += test-mesh-segm
+# FIXME: Likewise.
+MOSTLYCLEANFILES += socket-segm.off teapot-segm.off
+
+# FIXME: mesh_skel is unfinished. Anyway, it has been be superseded
+# by `mesh-complex-skel' (see below), using no Trimesh code.
+
+## FIXME: Rename as mesh-trimesh-graph-{max,pinv}-curv-skel?
+# bin_PROGRAMS += mesh-skel
# mesh_skel_SOURCES = mesh-skel.cc io.hh
# mesh_skel_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh)
# mesh_skel_LDFLAGS = $(LDFLAGS_trimesh)
diff --git a/milena/apps/mesh-segm-skel/mesh-segm.cc
b/milena/apps/mesh-segm-skel/mesh-segm.cc
index bf87249..06ddc93 100644
--- a/milena/apps/mesh-segm-skel/mesh-segm.cc
+++ b/milena/apps/mesh-segm-skel/mesh-segm.cc
@@ -1,4 +1,5 @@
-// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE)
+// Copyright (C) 2008, 2009, 2010 EPITA Research and Development
+// Laboratory (LRDE)
//
// This file is part of the Milena Library. This library is free
// software; you can redistribute it and/or modify it under the terms
@@ -40,14 +41,18 @@
#include <TriMesh.h>
#include <mln/core/alias/point3d.hh>
-#include <mln/core/alias/point3d.hh>
+
+#include <mln/fun/i2v/array.hh>
+#include <mln/convert/from_to.hh>
#include <mln/util/graph.hh>
-#include <mln/core/image/line_graph_image.hh>
-#include <mln/core/image/line_graph_elt_neighborhood.hh>
+#include <mln/util/line_graph.hh>
+#include <mln/util/site_pair.hh>
+#include <mln/core/image/edge_image.hh>
+#include <mln/make/edge_image.hh>
#include <mln/morpho/closing/area.hh>
-#include <mln/morpho/meyer_wst.hh>
+#include <mln/morpho/watershed/flooding.hh>
#include "io.hh"
@@ -116,12 +121,9 @@ int main(int argc, char* argv[])
std::vector<curv_t> vertex_values (mesh.faces.size(), 0.f);
std::vector<curv_t> edge_values;
- /* FIXME: We don't have the required site type yet. Simulate with a
- dummy type (point3d). */
- mln::util::graph<mln::point3d> g;
+ mln::util::graph g;
// Populate the graph with vertices.
- for (unsigned i = 0; i < mesh.faces.size(); ++i)
- g.add_vertex (mln::point3d(i, i, i));
+ g.add_vertices(mesh.faces.size());
// Populate the graph with edges.
mesh.need_across_edge();
@@ -132,25 +134,26 @@ int main(int argc, char* argv[])
if (f_adj != -1)
{
// Add an edge into the graph.
- if (g.add_edge(f, f_adj) != mln_max(mln::util::edge_id::equiv))
- {
- // Find the edge (i.e., the two vertices) common to faces
- // F and F_ADJ.
- /* FIXME: We lack a proper interface from the TriMesh
- structure to do this elegantly. */
- std::vector<int> adj_vertices;
- adj_vertices.reserve(2);
- for (unsigned i = 0; i < 3; ++i)
- for (unsigned j = 0; j < 3; ++j)
- if (mesh.faces[f][i] == mesh.faces[f_adj][j])
- adj_vertices.push_back(mesh.faces[f][i]);
- mln_assertion(adj_vertices.size() == 2);
-
- // Compute the mean curvature on the edge.
- edge_values.push_back((vertex_h_inv[adj_vertices[0]] +
- vertex_h_inv[adj_vertices[1]])
- / 2);
- }
+ mln::util::edge_id_t new_edge = g.add_edge(f, f_adj);
+ mln_invariant(new_edge.is_valid());
+
+ /* Among the edges adjacent to F and F_ADJ, find the one
+ they share. In practice, find the two vertices shared
+ by F and F_ADJ. */
+ /* FIXME: We lack a proper interface from the TriMesh
+ structure to do this elegantly. */
+ std::vector<int> adj_vertices;
+ adj_vertices.reserve(2);
+ for (unsigned i = 0; i < 3; ++i)
+ for (unsigned j = 0; j < 3; ++j)
+ if (mesh.faces[f][i] == mesh.faces[f_adj][j])
+ adj_vertices.push_back(mesh.faces[f][i]);
+ mln_assertion(adj_vertices.size() == 2);
+
+ // Compute the mean curvature on the edge.
+ edge_values.push_back((vertex_h_inv[adj_vertices[0]] +
+ vertex_h_inv[adj_vertices[1]])
+ / 2);
// Check the consistency of the two arrays.
mln_assertion(g.edges().size() == edge_values.size());
@@ -161,19 +164,38 @@ int main(int argc, char* argv[])
| Line graph image. |
`-------------------*/
- mln::p_line_graph<mln::point3d> plg(g);
+ // Points associated to the line graph vertices (edges in the graph).
+ typedef mln::util::site_pair<mln::point3df> P;
+ typedef mln::fun::i2v::array<P> fsite_t;
+ fsite_t sites(g.e_nmax());
+ for (unsigned i = 0; i < g.e_nmax(); ++i)
+ /* FIXME: Add a dummy location information for the moment. This
+ doesn't really matter as we won't use it to produce the output.
+ However, we may need it later: do not forget to add relevant
+ locations (obtained from the mesh) in a future version of this
+ program. */
+ sites(i) = P(mln::point3df(0, 0, 0), mln::point3df(1, 1, 1));
+
+ // FIXME: This intermediate structure costs us a copy.
+ typedef mln::fun::i2v::array<curv_t> values_t;
+ values_t values;
+ mln::convert::from_to(edge_values, values);
+
+ typedef mln::edge_image<P, curv_t, mln::util::graph> ima_t;
+ ima_t graph_ima(g, sites, values);
- typedef mln::line_graph_image<mln::point3d, curv_t> ima_t;
- ima_t lg_ima(plg, vertex_values, edge_values);
/*-----------------.
| Simplification. |
`-----------------*/
- typedef mln::line_graph_elt_neighborhood<mln::point3d> nbh_t;
+ typedef ima_t::nbh_t nbh_t;
nbh_t nbh;
- ima_t closed_lg_ima = mln::morpho::closing::area(lg_ima, nbh, lambda);
+ // ``Area'' is not a proper term here, since it is defined to the
+ // number of edges in the graph. Taking into account the actual
+ // area of triangles would be a more clever choice.
+ ima_t closed_graph_ima = mln::morpho::closing::area(graph_ima, nbh, lambda);
/*------.
| WST. |
@@ -181,24 +203,30 @@ int main(int argc, char* argv[])
typedef unsigned wst_val_t;
wst_val_t nbasins;
- typedef mln::line_graph_image<mln::point3d, wst_val_t> wst_ima_t;
- wst_ima_t wshed = mln::morpho::meyer_wst(closed_lg_ima, nbh, nbasins);
+ typedef mln_ch_value_(ima_t, wst_val_t) wst_ima_t;
+ wst_ima_t wshed =
+ mln::morpho::watershed::flooding(closed_graph_ima, nbh, nbasins);
std::cout << "nbasins = " << nbasins << std::endl;
/*------------------------------------------.
| Label graph vertices (i.e., mesh faces). |
`------------------------------------------*/
- /* FIXME: We should be using wshed.vertex_values_ if
- mln::line_graph_image were fully functional... */
- std::vector<unsigned> vertex_label(wshed.domain().nvertices(), 0);
+ // FIXME: Use a vertex_image and a e2v neighborhood instead?
+
+ /* FIXME: p_edges does not provide nvertices(), so we cannot write
+
+ std::vector<unsigned> vertex_label(wshed.domain().nvertices(), 0);
+
+ Likewise, p_vertices does not provide n_edges(). */
+ std::vector<unsigned> vertex_label(wshed.domain().graph().v_nmax(), 0);
mln_piter_(wst_ima_t) pw(wshed.domain());
for_all(pw)
if (wshed(pw) != 0)
{
mln_psite_(wst_ima_t) pp(pw);
- vertex_label[pp.first_id().to_equiv()] = wshed(pw);
- vertex_label[pp.second_id().to_equiv()] = wshed(pw);
+ vertex_label[pp.v1().id()] = wshed(pw);
+ vertex_label[pp.v2().id()] = wshed(pw);
}
/*---------.
--
1.5.6.5