Commit aa29f391 authored by Roland Levillain's avatar Roland Levillain
Browse files

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.
parent cfc65f32
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.
# 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.
......
// 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
// 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;
}
// 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;
}
// 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;