* apps/statues/mesh-max-curv.cc: New.
* apps/statues/Makefile.am (bin_PROGRAMS): Add mesh-max-curv.
(mesh_max_curv_SOURCES): New.
---
milena/ChangeLog | 8 ++
milena/apps/statues/Makefile.am | 3 +-
milena/apps/statues/mesh-max-curv.cc | 131 ++++++++++++++++++++++++++++++++++
3 files changed, 141 insertions(+), 1 deletions(-)
create mode 100644 milena/apps/statues/mesh-max-curv.cc
diff --git a/milena/ChangeLog b/milena/ChangeLog
index 7de2bd7..fa83a63 100644
--- a/milena/ChangeLog
+++ b/milena/ChangeLog
@@ -1,5 +1,13 @@
2008-11-18 Roland Levillain <roland(a)lrde.epita.fr>
+ Add a program computing the maximum curvature on a mesh.
+
+ * apps/statues/mesh-max-curv.cc: New.
+ * apps/statues/Makefile.am (bin_PROGRAMS): Add mesh-max-curv.
+ (mesh_max_curv_SOURCES): New.
+
+2008-11-18 Roland Levillain <roland(a)lrde.epita.fr>
+
Rename apps/statues/mesh-curv as apps/statues/mesh-pinv-curv.
* apps/statues/mesh-curv.cc: Rename as...
diff --git a/milena/apps/statues/Makefile.am b/milena/apps/statues/Makefile.am
index 9a5c9a1..d41ead6 100644
--- a/milena/apps/statues/Makefile.am
+++ b/milena/apps/statues/Makefile.am
@@ -14,9 +14,10 @@ AM_LDFLAGS = $(GLFLAGS)
LDADD = -L$(top_builddir)/external/trimesh/libsrc -ltrimesh $(GLLIBS)
-bin_PROGRAMS = mesh-pinv-curv mesh-segm mesh-skel
+bin_PROGRAMS = mesh-pinv-curv mesh-max-curv mesh-segm mesh-skel
mesh_pinv_curv_SOURCES = mesh-pinv-curv.cc io.hh
+mesh_max_curv_SOURCES = mesh-max-curv.cc io.hh
mesh_segm_SOURCES = mesh-segm.cc io.hh
mesh_skel_SOURCES = mesh-skel.cc io.hh
diff --git a/milena/apps/statues/mesh-max-curv.cc b/milena/apps/statues/mesh-max-curv.cc
new file mode 100644
index 0000000..8fc9a06
--- /dev/null
+++ b/milena/apps/statues/mesh-max-curv.cc
@@ -0,0 +1,131 @@
+// 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-max-curv.cc
+/// \brief A program computing the max curvature at each (2-)face of
+/// a mesh.
+
+#include <cstdlib>
+#include <cmath>
+
+#include <algorithm>
+#include <vector>
+#include <iostream>
+#include <utility>
+
+#include <TriMesh.h>
+
+#include <mln/math/max.hh>
+#include <mln/math/sqr.hh>
+#include <mln/accu/min_max.hh>
+#include <mln/fun/v2v/linear.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 != 3)
+ {
+ std::cerr << "usage: " << argv[0] << " input.off
output.off"
+ << std::endl;
+ 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)
+ 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(), 42.f);
+ mln::accu::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/level/stretch.hh (this should be factored).
+ float min = min_max.first;
+ float max = min_max.second;
+ // Don't normalize actually if the curvature is constants (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;
+ exit(2);
+ }
+ write_off_float(mesh_ptr, normalized_face_m, f_out);
+ fclose(f_out);
+
+ delete mesh_ptr;
+}
--
1.6.0.1