39 #include <mln/math/max.hh>
40 #include <mln/math/sqr.hh>
41 #include <mln/accu/stat/min_max.hh>
42 #include <mln/fun/v2v/linear.hh>
47 int main(
int argc,
char* argv[])
51 std::cerr <<
"usage: " << argv[0] <<
" input.off output.off"
56 std::string input_filename = argv[1];
57 std::string output_filename = argv[2];
63 TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str());
66 TriMesh& mesh = *mesh_ptr;
71 mesh.need_curvatures();
73 std::vector<float> vertex_m(mesh.vertices.size(), 0.f);
74 for (
unsigned v = 0; v < mesh.vertices.size(); ++v)
76 vertex_m[v] = mln::math::max(mln::math::sqr(mesh.curv1[v]),
77 mln::math::sqr(mesh.curv2[v]));
81 std::vector<float> face_m(mesh.faces.size(), 0.f);
83 for (
unsigned f = 0; f < mesh.faces.size(); ++f)
85 float m = (vertex_m[mesh.faces[f][0]] +
86 vertex_m[mesh.faces[f][1]] +
87 vertex_m[mesh.faces[f][2]]) / 3;
95 std::vector<float> normalized_face_m(face_m.size(), 0.0f);
96 std::pair<float, float> min_max(acc);
98 float min = min_max.first;
99 float max = min_max.second;
106 float a = (M - m) / (max - min);
107 float b = (m * max - M * min) / (max - min);
109 std::transform(face_m.begin(), face_m.end(),
110 normalized_face_m.begin(), f);
114 FILE* f_out = fopen(output_filename.c_str(),
"wb");
117 std::cerr <<
"Error opening " << output_filename.c_str()
118 <<
" for writing." << std::endl;
121 write_off_float(mesh_ptr, normalized_face_m, f_out);