olena-2.0-33-gaa29f39 Remove anything depending on the Trimesh library.

* apps/mesh-segm-skel/io.hh, * apps/mesh-segm-skel/mesh-max-curv.cc, * apps/mesh-segm-skel/mesh-pinv-curv.cc, * apps/mesh-segm-skel/mesh-segm.cc, * apps/mesh-segm-skel/mesh-skel.cc, * apps/mesh-segm-skel/test-mesh-max-curv.in, * apps/mesh-segm-skel/test-mesh-segm.in: Remove. * apps/mesh-segm-skel/Makefile.am: Remove anything related to the Trimesh library. --- milena/ChangeLog | 15 ++ milena/apps/mesh-segm-skel/Makefile.am | 72 +------ milena/apps/mesh-segm-skel/io.hh | 205 ------------------- milena/apps/mesh-segm-skel/mesh-max-curv.cc | 125 ------------ milena/apps/mesh-segm-skel/mesh-pinv-curv.cc | 105 ---------- milena/apps/mesh-segm-skel/mesh-segm.cc | 230 ---------------------- milena/apps/mesh-segm-skel/mesh-skel.cc | 207 ------------------- milena/apps/mesh-segm-skel/test-mesh-max-curv.in | 23 --- milena/apps/mesh-segm-skel/test-mesh-segm.in | 26 --- 9 files changed, 21 insertions(+), 987 deletions(-) delete mode 100644 milena/apps/mesh-segm-skel/io.hh delete mode 100644 milena/apps/mesh-segm-skel/mesh-max-curv.cc delete mode 100644 milena/apps/mesh-segm-skel/mesh-pinv-curv.cc delete mode 100644 milena/apps/mesh-segm-skel/mesh-segm.cc delete mode 100644 milena/apps/mesh-segm-skel/mesh-skel.cc delete mode 100644 milena/apps/mesh-segm-skel/test-mesh-max-curv.in delete mode 100755 milena/apps/mesh-segm-skel/test-mesh-segm.in diff --git a/milena/ChangeLog b/milena/ChangeLog index 83f5520..bb0f61c 100644 --- a/milena/ChangeLog +++ b/milena/ChangeLog @@ -1,3 +1,18 @@ +2012-10-05 Roland Levillain <roland@lrde.epita.fr> + + Remove anything depending on the Trimesh library. + + * apps/mesh-segm-skel/io.hh, + * apps/mesh-segm-skel/mesh-max-curv.cc, + * apps/mesh-segm-skel/mesh-pinv-curv.cc, + * apps/mesh-segm-skel/mesh-segm.cc, + * apps/mesh-segm-skel/mesh-skel.cc, + * apps/mesh-segm-skel/test-mesh-max-curv.in, + * apps/mesh-segm-skel/test-mesh-segm.in: + Remove. + * apps/mesh-segm-skel/Makefile.am: Remove anything related to the + Trimesh library. + 2012-06-15 Roland Levillain <roland@lrde.epita.fr> Remove dependencies on suppressed files. diff --git a/milena/apps/mesh-segm-skel/Makefile.am b/milena/apps/mesh-segm-skel/Makefile.am index 9768f25..55ef805 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, 2012 EPITA Research and Development +# Laboratory (LRDE). # # This file is part of Olena. # @@ -14,25 +15,11 @@ # You should have received a copy of the GNU General Public License # along with Olena. If not, see <http://www.gnu.org/licenses/>. -# Linking with gluit and GLUT/OpenGL. -gluit_builddir = $(top_builddir)/external/trimesh/gluit -include $(top_srcdir)/external/trimesh/gluit/gluit.mk - -# Find Milena and trimesh headers. +# Find Milena headers. AM_CPPFLAGS = -I$(top_srcdir)/milena -CPPFLAGS_trimesh = -I$(top_srcdir)/external/trimesh/include # Produce fast code. APPS_CXXFLAGS = @APPS_CXXFLAGS@ AM_CXXFLAGS = $(APPS_CXXFLAGS) -# Find the trimesh library and its dependencies. -# -# Don't use TRIMESH_LDFLAGS, since it looks like the LDFLAGS of the -# program `TRIMESH' and triggers Automake warnings; use -# LDFLAGS_trimesh instead. Likewise for CPPFLAGS_trimesh and -# LDADD_trimesh, for symmetry reasons. -LDFLAGS_trimesh = $(GLFLAGS) -LDADD_trimesh = -L$(top_builddir)/external/trimesh/libsrc -ltrimesh $(GLLIBS) - bin_PROGRAMS = TESTS = @@ -41,56 +28,9 @@ MOSTLYCLEANFILES = # FIXME: Have program names embed the type of structure used (either # graph or complex). -## FIXME: Likewise, programs' names should reflect a dependency on -## Trimesh, if any. - -## ------------------------------------------------ ## -## Graph-based applications, depending on Trimesh. ## -## ------------------------------------------------ ## - -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. - -# mesh_skel_SOURCES = mesh-skel.cc io.hh -# mesh_skel_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh) -# mesh_skel_LDFLAGS = $(LDFLAGS_trimesh) -# mesh_skel_LDADD = $(LDADD_trimesh) -endif ENABLE_TRIMESH - -## -------------------------------------------------- ## -## Complex-based applications, depending on Trimesh. ## -## -------------------------------------------------- ## - -if ENABLE_TRIMESH - bin_PROGRAMS += mesh-pinv-curv mesh-max-curv - - mesh_pinv_curv_SOURCES = mesh-pinv-curv.cc io.hh - mesh_pinv_curv_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh) - mesh_pinv_curv_LDFLAGS = $(LDFLAGS_trimesh) - mesh_pinv_curv_LDADD = $(LDADD_trimesh) - - mesh_max_curv_SOURCES = mesh-max-curv.cc io.hh - mesh_max_curv_CPPFLAGS = $(AM_CPPFLAGS) $(CPPFLAGS_trimesh) - mesh_max_curv_LDFLAGS = $(LDFLAGS_trimesh) - mesh_max_curv_LDADD = $(LDADD_trimesh) - TESTS += test-mesh-max-curv - MOSTLYCLEANFILES += teapot-max-curv-skel.off -endif ENABLE_TRIMESH - -## ---------------------------------------------------- ## -## Complex-based applications, independent of Trimesh. ## -## ---------------------------------------------------- ## +## ---------------------------- ## +## Complex-based applications. ## +## ---------------------------- ## # A Milena re-implementation of some features from Trimesh. This code # is completely independent from the Trimesh library. diff --git a/milena/apps/mesh-segm-skel/io.hh b/milena/apps/mesh-segm-skel/io.hh deleted file mode 100644 index 4d7516c..0000000 --- a/milena/apps/mesh-segm-skel/io.hh +++ /dev/null @@ -1,205 +0,0 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. -// -// As a special exception, you may use this file as part of a free -// software project without restriction. Specifically, if other files -// instantiate templates or use macros or inline functions from this -// file, or you compile this file and link it with other files to produce -// an executable, this file does not by itself cause the resulting -// executable to be covered by the GNU General Public License. This -// exception does not however invalidate any other reasons why the -// executable file might be covered by the GNU General Public License. - -#ifndef APPS_MESH_SEGM_SKEL_IO_HH -# define APPS_MESH_SEGM_SKEL_IO_HH - -/// \file apps/mesh-segm-skel/io.hh -/// \brief I/O routines adapted from TriMesh's ones. - -#include <cstdio> - -#include <algorithm> - -#include <TriMesh.h> - -#include <mln/value/rgb8.hh> - - -/// Taken from TriMesh_io.cc -/// \{ -// Convert colors float -> uchar -inline unsigned char color2uchar(float p) -{ - return min(max(int(255.0f * p + 0.5f), 0), 255); -} - -// Write a bunch of vertices to an ASCII file -inline void write_verts_asc(TriMesh *mesh, FILE *f, - const char *before_vert, - const char *before_norm, - const char *before_color, - bool float_color, - const char *before_conf, - const char *after_line) -{ - for (unsigned i = 0; i < mesh->vertices.size(); i++) { - fprintf(f, "%s%.7g %.7g %.7g", before_vert, - mesh->vertices[i][0], - mesh->vertices[i][1], - mesh->vertices[i][2]); - if (!mesh->normals.empty() && before_norm) - fprintf(f, "%s%.7g %.7g %.7g", before_norm, - mesh->normals[i][0], - mesh->normals[i][1], - mesh->normals[i][2]); - if (!mesh->colors.empty() && before_color && float_color) - fprintf(f, "%s%.7g %.7g %.7g", before_color, - mesh->colors[i][0], - mesh->colors[i][1], - mesh->colors[i][2]); - if (!mesh->colors.empty() && before_color && !float_color) - fprintf(f, "%s%d %d %d", before_color, - color2uchar(mesh->colors[i][0]), - color2uchar(mesh->colors[i][1]), - color2uchar(mesh->colors[i][2])); - if (!mesh->confidences.empty() && before_conf) - fprintf(f, "%s%.7g", before_conf, mesh->confidences[i]); - fprintf(f, "%s\n", after_line); - } -} -/// \} - - -/// Taken and adapted from TriMesh_io.cc -/// \{ - -/*----------------------. -| OFF with color data. | -`----------------------*/ - -/// Write a bunch of faces to an ASCII file with colors. -inline void write_faces_asc_colored(TriMesh *mesh, - const std::vector<mln::value::rgb8>& colors, - FILE *f, - const char *before_face, - const char *after_line) -{ - mesh->need_faces(); - for (unsigned i = 0; i < mesh->faces.size(); i++) - { - fprintf(f, "%s%d %d %d %d %d %d%s\n", - before_face, - mesh->faces[i][0], mesh->faces[i][1], mesh->faces[i][2], - int(colors[i].red()), - int(colors[i].green()), - int(colors[i].blue()), - after_line); - } -} - -/// Write an off file with colors. -inline void write_off_colored(TriMesh *mesh, - const std::vector<mln::value::rgb8>& colors, - FILE *f) -{ - fprintf(f, "OFF\n"); - mesh->need_faces(); - fprintf(f, "%lu %lu 0\n", (unsigned long) mesh->vertices.size(), - (unsigned long) mesh->faces.size()); - write_verts_asc(mesh, f, "", 0, 0, false, 0, ""); - write_faces_asc_colored(mesh, colors, f, "3 ", ""); -} - -/*----------------------. -| OFF with float data. | -`----------------------*/ - -/// Write a bunch of faces to an ASCII file with colors. -inline void write_faces_asc_float(TriMesh *mesh, - const std::vector<float>& values, - FILE *f, - const char *before_face, - const char *after_line) -{ - mesh->need_faces(); - for (unsigned i = 0; i < mesh->faces.size(); i++) - { - // Vertices Color - // -------- ------------ - // V0 V1 V2 R G B A - fprintf(f, "%s%d %d %d %f %f %f 1.0%s\n", - before_face, - mesh->faces[i][0], mesh->faces[i][1], mesh->faces[i][2], - values[i], values[i], values[i], - after_line); - } -} - -/// Write an off file with floating-point values. -inline void write_off_float(TriMesh *mesh, const std::vector<float>& values, - FILE *f) -{ - fprintf(f, "OFF\n"); - mesh->need_faces(); - fprintf(f, "%lu %lu 0\n", (unsigned long) mesh->vertices.size(), - (unsigned long) mesh->faces.size()); - write_verts_asc(mesh, f, "", 0, 0, false, 0, ""); - write_faces_asc_float(mesh, values, f, "3 ", ""); -} -/// \} - - -/*---------------------------------------. -| OFF without data (``binary values''). | -`---------------------------------------*/ - -/// Taken and adapted from TriMesh_io.cc -/// \{ -/// Write a bunch of faces to an ASCII file, removing the ones tagged -/// as ``false'' in \a face_value. -inline void write_faces_asc_binary(TriMesh *mesh, - const std::vector<bool>& face_value, - FILE *f, - const char *before_face, - const char *after_line) -{ - mesh->need_faces(); - for (unsigned i = 0; i < mesh->faces.size(); i++) - if (face_value[i]) - { - fprintf(f, "%s%d %d %d%s\n", - before_face, - mesh->faces[i][0], mesh->faces[i][1], mesh->faces[i][2], - after_line); - } -} - -/// Write an off file, removing faces tagged as ``false'' in \a face_value. -inline void write_off_binary(TriMesh *mesh, - const std::vector<bool>& face_value, - FILE *f) -{ - fprintf(f, "OFF\n"); - mesh->need_faces(); - unsigned long nfaces = - std::count(face_value.begin(), face_value.end(), true); - fprintf(f, "%lu %lu 0\n", (unsigned long) mesh->vertices.size(), nfaces); - write_verts_asc(mesh, f, "", 0, 0, false, 0, ""); - write_faces_asc_binary(mesh, face_value, f, "3 ", ""); -} -/// \} - -#endif // ! APPS_MESH_SEGM_SKEL_IO_HH diff --git a/milena/apps/mesh-segm-skel/mesh-max-curv.cc b/milena/apps/mesh-segm-skel/mesh-max-curv.cc deleted file mode 100644 index 8376fc0..0000000 --- a/milena/apps/mesh-segm-skel/mesh-max-curv.cc +++ /dev/null @@ -1,125 +0,0 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. -// -// As a special exception, you may use this file as part of a free -// software project 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/mesh-segm-skel/mesh-max-curv.cc -/// \brief A program computing the max curvature at each (2-)face of -/// a mesh. - -#include <cstdlib> - -#include <algorithm> -#include <vector> -#include <iostream> -#include <utility> - -#include <TriMesh.h> - -#include <mln/math/max.hh> -#include <mln/math/sqr.hh> -#include <mln/accu/stat/min_max.hh> -#include <mln/fun/v2v/linear.hh> - -#include "io.hh" - - -int main(int argc, char* argv[]) -{ - if (argc != 3) - { - std::cerr << "usage: " << argv[0] << " input.off output.off" - << std::endl; - std::exit(1); - } - - std::string input_filename = argv[1]; - std::string output_filename = argv[2]; - - - // TriMesh is a pain: it systematically allocates on the heap. - // Introduce another name to manipulate the mesh as a (non-pointer) - // object. - TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str()); - if (!mesh_ptr) - std::exit(2); - TriMesh& mesh = *mesh_ptr; - - // Computes faces (triangles). - mesh.need_faces(); - // Computation of the curvature on each vertex of the mesh. - mesh.need_curvatures(); - - std::vector<float> vertex_m(mesh.vertices.size(), 0.f); - for (unsigned v = 0; v < mesh.vertices.size(); ++v) - // Max curvature. - vertex_m[v] = mln::math::max(mln::math::sqr(mesh.curv1[v]), - mln::math::sqr(mesh.curv2[v])); - - // For each face of the mesh, computean an average curvature value - // from the mean curvature at its vertices. - std::vector<float> face_m(mesh.faces.size(), 0.f); - mln::accu::stat::min_max<float> acc; - for (unsigned f = 0; f < mesh.faces.size(); ++f) - { - float m = (vertex_m[mesh.faces[f][0]] + - vertex_m[mesh.faces[f][1]] + - vertex_m[mesh.faces[f][2]]) / 3; - face_m[f] = m; - acc.take(m); - } - - /* Shrink the values of FACE_M into the range 0..1, as these are - the only values accepted a an RGB floating-point component in the - OFF file format. */ - std::vector<float> normalized_face_m(face_m.size(), 0.0f); - std::pair<float, float> min_max(acc); - // FIXME: Taken from mln/data/stretch.hh (this should be factored). - float min = min_max.first; - float max = min_max.second; - // Don't normalize actually if the curvature is constant (i.e., - // if min == max). - if (min != max) - { - float m = 0.0f; - float M = 1.0f; - float a = (M - m) / (max - min); - float b = (m * max - M * min) / (max - min); - mln::fun::v2v::linear<float, float, float> f(a, b); - std::transform(face_m.begin(), face_m.end(), - normalized_face_m.begin(), f); - } - - // Taken and adapted from TriMesh_io.cc - FILE* f_out = fopen(output_filename.c_str(), "wb"); - if (!f_out) - { - std::cerr << "Error opening " << output_filename.c_str() - << " for writing." << std::endl; - std::exit(2); - } - write_off_float(mesh_ptr, normalized_face_m, f_out); - fclose(f_out); - - delete mesh_ptr; -} diff --git a/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc b/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc deleted file mode 100644 index af51c97..0000000 --- a/milena/apps/mesh-segm-skel/mesh-pinv-curv.cc +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (C) 2008 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. -// -// As a special exception, you may use this file as part of a free -// software project 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/mesh-segm-skel/mesh-pinv-curv.cc -/// \brief A program computing the pseudo-inverse curvature at each -/// (2-)face of a mesh. - -#include <cstdlib> -#include <cmath> - -#include <algorithm> -#include <vector> -#include <iostream> -#include <utility> - -#include <TriMesh.h> - -#include "io.hh" - - -// Doesn't C++ have a better way to express Pi? -static const float pi = 4 * atanf(1); - - -int main(int argc, char* argv[]) -{ - if (argc != 3) - { - std::cerr << "usage: " << argv[0] << " input.off output.off" - << std::endl; - std::exit(1); - } - - std::string input_filename = argv[1]; - std::string output_filename = argv[2]; - - - // TriMesh is a pain: it systematically allocates on the heap. - // Introduce another name to manipulate the mesh as a (non-pointer) - // object. - TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str()); - if (!mesh_ptr) - std::exit(2); - TriMesh& mesh = *mesh_ptr; - - // Computes faces (triangles). - mesh.need_faces(); - // Computation of the curvature on each vertex of the mesh. - mesh.need_curvatures(); - std::vector<float> vertex_h_inv(mesh.vertices.size(), 0.f); - for (unsigned v = 0; v < mesh.vertices.size(); ++v) - { - float h = (mesh.curv1[v] + mesh.curv2[v]) / 2; - // Pseudo-inverse curvature. - float h_inv = 1 / pi * (atan(-h) + pi / 2); - vertex_h_inv[v] = h_inv; - } - // For each face of the mesh, computean an average curvature value - // from the mean curvature at its vertices. - std::vector<float> face_h_inv(mesh.faces.size(), 42.f); - for (unsigned f = 0; f < mesh.faces.size(); ++f) - { - float h_inv = (vertex_h_inv[mesh.faces[f][0]] + - vertex_h_inv[mesh.faces[f][1]] + - vertex_h_inv[mesh.faces[f][2]]) / 3; - mln_invariant(0.f <= h_inv); - mln_invariant(h_inv <= 1.f); - face_h_inv[f] = h_inv; - } - - // Taken and adapted from TriMesh_io.cc - FILE* f_out = fopen(output_filename.c_str(), "wb"); - if (!f_out) - { - std::cerr << "Error opening " << output_filename.c_str() - << " for writing." << std::endl; - std::exit(2); - } - write_off_float(mesh_ptr, face_h_inv, f_out); - fclose(f_out); - - delete mesh_ptr; -} diff --git a/milena/apps/mesh-segm-skel/mesh-segm.cc b/milena/apps/mesh-segm-skel/mesh-segm.cc deleted file mode 100644 index 63e707d..0000000 --- a/milena/apps/mesh-segm-skel/mesh-segm.cc +++ /dev/null @@ -1,230 +0,0 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. -// -// As a special exception, you may use this file as part of a free -// software project 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/mesh-segm-skel/mesh-segm.cc -/// \brief A program performing a WST-based segmentation of the -/// surface of the (triangle) mesh of a statue. - -// FIXME: Factor commons parts between mesh-segm and mesh-skel. - -#include <cstdlib> -#include <cmath> - -#include <utility> -#include <iostream> - -#include <TriMesh.h> - -#include <mln/core/alias/point3d.hh> -#include <mln/core/alias/point3d.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/morpho/closing/area.hh> -#include <mln/morpho/meyer_wst.hh> - -#include "io.hh" - - -// Doesn't C++ have a better way to express Pi ? -const float pi = 4 * atanf(1); - - -int main(int argc, char* argv[]) -{ - if (argc != 4) - { - std::cerr << "usage: " << argv[0] << " input.off lambda output.off" - << std::endl; - std::exit(1); - } - - std::string input_filename = argv[1]; - unsigned lambda = atoi(argv[2]); - std::string output_filename = argv[3]; - - - /*-------. - | Mesh. | - `-------*/ - - // TriMesh is a pain: it systematically allocates on the heap. - // Introduce another name to manipulate the mesh as a (non-pointer) - // object. - TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str()); - if (!mesh_ptr) - std::exit(2); - TriMesh& mesh = *mesh_ptr; - - // Computes faces (triangles). - mesh.need_faces(); - // Computation of the mean curvature on each vertex of the mesh. - mesh.need_curvatures(); - /* FIXME: Our implementation of the WST doesn't work well with - floats (yet). Convert floating point values to a proportional - integer value for the moment. */ - typedef int curv_t; - std::vector<curv_t> vertex_h_inv(mesh.vertices.size(), 0.f); - for (unsigned v = 0; v < mesh.vertices.size(); ++v) - { - float h = (mesh.curv1[v] + mesh.curv2[v]) / 2; - float h_inv = 1 / pi * atan(-h) + pi / 2; - /* FIXME: This coefficient is used to distinguish small - curvature values. We should get rid of it as soon as - morpho::meyer_wst works correctly on images of float - values. */ - vertex_h_inv[v] = 1000 * h_inv; - } - - /*--------. - | Graph. | - `--------*/ - - /* Build a graph whose vertices correspond to the faces of the mesh, - whose edges (between two vertices) correspond to edges (between - two faces) of the mesh. */ - - // Values associated to the graph sites. - // (Reminder: currently, values associated to vertices in a - // line_graph_image are dummy.) - 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; - // Populate the graph with vertices. - for (unsigned i = 0; i < mesh.faces.size(); ++i) - g.add_vertex (mln::point3d(i, i, i)); - - // Populate the graph with edges. - mesh.need_across_edge(); - for (unsigned f = 0; f < mesh.faces.size(); ++f) - for (unsigned e = 0; e < 3; ++e) - { - int f_adj = mesh.across_edge[f][e]; - 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); - } - - // Check the consistency of the two arrays. - mln_assertion(g.edges().size() == edge_values.size()); - } - } - - /*-------------------. - | Line graph image. | - `-------------------*/ - - mln::p_line_graph<mln::point3d> plg(g); - - 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; - nbh_t nbh; - - ima_t closed_lg_ima = mln::morpho::closing::area(lg_ima, nbh, lambda); - - /*------. - | WST. | - `------*/ - - 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); - 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); - 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); - } - - /*---------. - | Output. | - `---------*/ - - // 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); - - // Assign colors to graph vertices (mesh faces). - std::vector<mln::value::rgb8> face_color (vertex_label.size()); - for (unsigned i = 0; i < vertex_label.size() ; ++i) - face_color[i] = basin_color[vertex_label[i]]; - - // Taken and adapted from TriMesh_io.cc - FILE* f_out = fopen(output_filename.c_str(), "wb"); - if (!f_out) - { - std::cerr << "Error opening " << output_filename.c_str() - << " for writing." << std::endl; - std::exit(2); - } - write_off_colored(mesh_ptr, face_color, f_out); - fclose(f_out); - - delete mesh_ptr; -} diff --git a/milena/apps/mesh-segm-skel/mesh-skel.cc b/milena/apps/mesh-segm-skel/mesh-skel.cc deleted file mode 100644 index e68620d..0000000 --- a/milena/apps/mesh-segm-skel/mesh-skel.cc +++ /dev/null @@ -1,207 +0,0 @@ -// Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE) -// -// This file is part of Olena. -// -// Olena is free software: you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation, version 2 of the License. -// -// Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. -// -// As a special exception, you may use this file as part of a free -// software project 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/mesh-segm-skel/mesh-skel.cc -/// \brief A program computing a skeleton of the surface of the -/// (triangle) mesh of a statue. - -// FIXME: Factor commons parts between mesh-segm and mesh-skel. - -#include <cstdlib> -#include <cmath> - -#include <utility> -#include <iostream> - -#include <TriMesh.h> - -#include <mln/core/alias/point3d.hh> -#include <mln/core/alias/point3d.hh> - -#include <mln/util/graph.hh> -#include <mln/core/image/graph_image.hh> -#include <mln/core/image/graph_elt_neighborhood.hh> - -#include <mln/morpho/closing/area.hh> -#include <mln/labeling/regional_minima.hh> - -#include "io.hh" - - -// Doesn't C++ have a better way to express Pi ? -const float pi = 4 * atanf(1); - - -int main(int argc, char* argv[]) -{ - if (argc != 4) - { - std::cerr << "usage: " << argv[0] << " input.off lambda output.off" - << std::endl; - std::exit(1); - } - - std::string input_filename = argv[1]; - unsigned lambda = atoi(argv[2]); - std::string output_filename = argv[3]; - - - /*-------. - | Mesh. | - `-------*/ - - // TriMesh is a pain: it systematically allocates on the heap. - // Introduce another name to manipulate the mesh as a (non-pointer) - // object. - TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str()); - if (!mesh_ptr) - std::exit(2); - TriMesh& mesh = *mesh_ptr; - - // Computes faces (triangles). - mesh.need_faces(); - // Computation of the mean curvature on each vertex of the mesh. - mesh.need_curvatures(); - std::vector<float> vertex_h_inv(mesh.faces.size(), 0.f); - for (unsigned v = 0; v < mesh.vertices.size(); ++v) - { - float h = (mesh.curv1[v] + mesh.curv2[v]) / 2; - float h_inv = 1 / pi * atan(-h) + pi / 2; - vertex_h_inv[v] = h_inv; - } - // Computation of the mean curvature on each face of the mesh. - /* FIXME: Our implementation of the computation of the regional - minima doesn't work well with floats (yet). Convert floating - point values to a proportional integer value for the moment. */ - typedef int curv_t; - std::vector<curv_t> face_h_inv(mesh.faces.size(), 0.f); - for (unsigned f = 0; f < mesh.faces.size(); ++f) - { - float h_inv = - (vertex_h_inv[mesh.faces[f][0]] + - vertex_h_inv[mesh.faces[f][1]] + - vertex_h_inv[mesh.faces[f][2]]) - / 3; - /* FIXME: This coefficient is used to distinguish small - curvature values. We should get rid of it as soon as - labeling::regional_minima works correctly on images of float - values. */ - face_h_inv[f] = 1000 * h_inv; - } - - /*--------. - | Graph. | - `--------*/ - - /* Build a graph whose vertices correspond to the faces of the mesh, - whose edges (between two vertices) correspond to edges (between - two faces) of the mesh. */ - - /* FIXME: We don't have the required site type yet. Simulate with a - dummy type (point3d). */ - mln::util::graph<mln::point3d> g; - // Populate the graph with vertices. - for (unsigned i = 0; i < mesh.faces.size(); ++i) - g.add_vertex (mln::point3d(i, i, i)); - - // Populate the graph with edges. - mesh.need_across_edge(); - for (unsigned f = 0; f < mesh.faces.size(); ++f) - for (unsigned e = 0; e < 3; ++e) - { - int f_adj = mesh.across_edge[f][e]; - if (f_adj != -1) - // Add an edge into the graph. - g.add_edge(f, f_adj); - } - - /*--------------. - | Graph image. | - `--------------*/ - - mln::p_graph<mln::point3d> pg(g); - - typedef mln::graph_image<mln::point3d, curv_t> ima_t; - ima_t g_ima(pg, face_h_inv); - - /*-----------------. - | Simplification. | - `-----------------*/ - - typedef mln::graph_elt_neighborhood<mln::point3d> nbh_t; - nbh_t nbh; - - ima_t closed_g_ima = mln::morpho::closing::area(g_ima, nbh, lambda); - - /*------------------. - | Regional minima. | - `------------------*/ - - typedef unsigned label_t; - label_t nlabels; - typedef mln::graph_image<mln::point3d, label_t> label_ima_t; - label_ima_t minima = - mln::labeling::regional_minima(closed_g_ima, nbh, nlabels); - std::cout << "nlabels = " << nlabels << std::endl; - - /*-----------. - | Skeleton. | - `-----------*/ - - // FIXME: To do. - - /*---------. - | Output. | - `---------*/ - - /* FIXME We should created a boolean graph_image instead. But as - we cannot directly save a graph_image as an OFF file now, just - store the values of this would-be image into an array. */ - // Assign a boolean value to graph vertices (mesh faces). - std::vector<bool> face_value (minima.domain().nvertices(), true); - mln_piter_(label_ima_t) pm(minima.domain()); - for_all(pm) - // FIXME: Use literal::zero. - if (minima(pm) != 0) - { - // The face belongs to a regional minima: ``remove'' it from - // the mesh by tagging it as false. - mln_psite_(label_ima_t) pp(pm); - face_value[pp.id().to_equiv()] = false; - } - - // Taken and adapted from TriMesh_io.cc - FILE* f_out = fopen(output_filename.c_str(), "wb"); - if (!f_out) - { - std::cerr << "Error opening " << output_filename.c_str() - << " for writing." << std::endl; - std::exit(2); - } - write_off_binary(mesh_ptr, face_value, f_out); - fclose(f_out); - - delete mesh_ptr; -} diff --git a/milena/apps/mesh-segm-skel/test-mesh-max-curv.in b/milena/apps/mesh-segm-skel/test-mesh-max-curv.in deleted file mode 100644 index e5eaf96..0000000 --- a/milena/apps/mesh-segm-skel/test-mesh-max-curv.in +++ /dev/null @@ -1,23 +0,0 @@ -#! /bin/sh - -# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE). -# -# This file is part of Olena. -# -# Olena is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, version 2 of the License. -# -# Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. - -set -ex - -mesh_dir=@top_srcdir@/milena/mesh - -time ./mesh-max-curv $mesh_dir/teapot.off teapot-max-curv.off diff --git a/milena/apps/mesh-segm-skel/test-mesh-segm.in b/milena/apps/mesh-segm-skel/test-mesh-segm.in deleted file mode 100755 index e70e63a..0000000 --- a/milena/apps/mesh-segm-skel/test-mesh-segm.in +++ /dev/null @@ -1,26 +0,0 @@ -#! /bin/sh - -# Copyright (C) 2008, 2009 EPITA Research and Development Laboratory (LRDE). -# -# This file is part of Olena. -# -# Olena is free software: you can redistribute it and/or modify it under -# the terms of the GNU General Public License as published by the Free -# Software Foundation, version 2 of the License. -# -# Olena 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 Olena. If not, see <http://www.gnu.org/licenses/>. - -set -ex - -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 -# FIXME: Too long. Should be run with (future) target `check-full'. -#time ./mesh-segm $mesh_dir/bunny-holefilled.off 500 bunny-holefilled-segm.off -- 1.7.2.5
participants (1)
-
Roland Levillain