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
00029
00030 #include <cstdlib>
00031 #include <cmath>
00032
00033 #include <algorithm>
00034 #include <vector>
00035 #include <iostream>
00036 #include <utility>
00037
00038 #include <TriMesh.h>
00039
00040 #include "io.hh"
00041
00042
00043
00044 static const float pi = 4 * atanf(1);
00045
00046
00047 int main(int argc, char* argv[])
00048 {
00049 if (argc != 3)
00050 {
00051 std::cerr << "usage: " << argv[0] << " input.off output.off"
00052 << std::endl;
00053 std::exit(1);
00054 }
00055
00056 std::string input_filename = argv[1];
00057 std::string output_filename = argv[2];
00058
00059
00060
00061
00062
00063 TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str());
00064 if (!mesh_ptr)
00065 std::exit(2);
00066 TriMesh& mesh = *mesh_ptr;
00067
00068
00069 mesh.need_faces();
00070
00071 mesh.need_curvatures();
00072 std::vector<float> vertex_h_inv(mesh.vertices.size(), 0.f);
00073 for (unsigned v = 0; v < mesh.vertices.size(); ++v)
00074 {
00075 float h = (mesh.curv1[v] + mesh.curv2[v]) / 2;
00076
00077 float h_inv = 1 / pi * (atan(-h) + pi / 2);
00078 vertex_h_inv[v] = h_inv;
00079 }
00080
00081
00082 std::vector<float> face_h_inv(mesh.faces.size(), 42.f);
00083 for (unsigned f = 0; f < mesh.faces.size(); ++f)
00084 {
00085 float h_inv = (vertex_h_inv[mesh.faces[f][0]] +
00086 vertex_h_inv[mesh.faces[f][1]] +
00087 vertex_h_inv[mesh.faces[f][2]]) / 3;
00088 mln_invariant(0.f <= h_inv);
00089 mln_invariant(h_inv <= 1.f);
00090 face_h_inv[f] = h_inv;
00091 }
00092
00093
00094 FILE* f_out = fopen(output_filename.c_str(), "wb");
00095 if (!f_out)
00096 {
00097 std::cerr << "Error opening " << output_filename.c_str()
00098 << " for writing." << std::endl;
00099 std::exit(2);
00100 }
00101 write_off_float(mesh_ptr, face_h_inv, f_out);
00102 fclose(f_out);
00103
00104 delete mesh_ptr;
00105 }