00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00031
00032 #include <cstdlib>
00033
00034 #include <algorithm>
00035 #include <vector>
00036 #include <iostream>
00037 #include <utility>
00038
00039 #include <TriMesh.h>
00040
00041 #include <mln/math/max.hh>
00042 #include <mln/math/sqr.hh>
00043 #include <mln/accu/stat/min_max.hh>
00044 #include <mln/fun/v2v/linear.hh>
00045
00046 #include "io.hh"
00047
00048
00049 int main(int argc, char* argv[])
00050 {
00051 if (argc != 3)
00052 {
00053 std::cerr << "usage: " << argv[0] << " input.off output.off"
00054 << std::endl;
00055 std::exit(1);
00056 }
00057
00058 std::string input_filename = argv[1];
00059 std::string output_filename = argv[2];
00060
00061
00062
00063
00064
00065 TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str());
00066 if (!mesh_ptr)
00067 std::exit(2);
00068 TriMesh& mesh = *mesh_ptr;
00069
00070
00071 mesh.need_faces();
00072
00073 mesh.need_curvatures();
00074
00075 std::vector<float> vertex_m(mesh.vertices.size(), 0.f);
00076 for (unsigned v = 0; v < mesh.vertices.size(); ++v)
00077
00078 vertex_m[v] = mln::math::max(mln::math::sqr(mesh.curv1[v]),
00079 mln::math::sqr(mesh.curv2[v]));
00080
00081
00082
00083 std::vector<float> face_m(mesh.faces.size(), 0.f);
00084 mln::accu::stat::min_max<float> acc;
00085 for (unsigned f = 0; f < mesh.faces.size(); ++f)
00086 {
00087 float m = (vertex_m[mesh.faces[f][0]] +
00088 vertex_m[mesh.faces[f][1]] +
00089 vertex_m[mesh.faces[f][2]]) / 3;
00090 face_m[f] = m;
00091 acc.take(m);
00092 }
00093
00094
00095
00096
00097 std::vector<float> normalized_face_m(face_m.size(), 0.0f);
00098 std::pair<float, float> min_max(acc);
00099
00100 float min = min_max.first;
00101 float max = min_max.second;
00102
00103
00104 if (min != max)
00105 {
00106 float m = 0.0f;
00107 float M = 1.0f;
00108 float a = (M - m) / (max - min);
00109 float b = (m * max - M * min) / (max - min);
00110 mln::fun::v2v::linear<float, float, float> f(a, b);
00111 std::transform(face_m.begin(), face_m.end(),
00112 normalized_face_m.begin(), f);
00113 }
00114
00115
00116 FILE* f_out = fopen(output_filename.c_str(), "wb");
00117 if (!f_out)
00118 {
00119 std::cerr << "Error opening " << output_filename.c_str()
00120 << " for writing." << std::endl;
00121 std::exit(2);
00122 }
00123 write_off_float(mesh_ptr, normalized_face_m, f_out);
00124 fclose(f_out);
00125
00126 delete mesh_ptr;
00127 }