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 #include <cmath>
00034
00035 #include <algorithm>
00036 #include <vector>
00037 #include <iostream>
00038 #include <utility>
00039
00040 #include <TriMesh.h>
00041
00042 #include "io.hh"
00043
00044
00045
00046 static const float pi = 4 * atanf(1);
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 std::vector<float> vertex_h_inv(mesh.vertices.size(), 0.f);
00075 for (unsigned v = 0; v < mesh.vertices.size(); ++v)
00076 {
00077 float h = (mesh.curv1[v] + mesh.curv2[v]) / 2;
00078
00079 float h_inv = 1 / pi * (atan(-h) + pi / 2);
00080 vertex_h_inv[v] = h_inv;
00081 }
00082
00083
00084 std::vector<float> face_h_inv(mesh.faces.size(), 42.f);
00085 for (unsigned f = 0; f < mesh.faces.size(); ++f)
00086 {
00087 float h_inv = (vertex_h_inv[mesh.faces[f][0]] +
00088 vertex_h_inv[mesh.faces[f][1]] +
00089 vertex_h_inv[mesh.faces[f][2]]) / 3;
00090 mln_invariant(0.f <= h_inv);
00091 mln_invariant(h_inv <= 1.f);
00092 face_h_inv[f] = h_inv;
00093 }
00094
00095
00096 FILE* f_out = fopen(output_filename.c_str(), "wb");
00097 if (!f_out)
00098 {
00099 std::cerr << "Error opening " << output_filename.c_str()
00100 << " for writing." << std::endl;
00101 std::exit(2);
00102 }
00103 write_off_float(mesh_ptr, face_h_inv, f_out);
00104 fclose(f_out);
00105
00106 delete mesh_ptr;
00107 }