44 static const float pi = 4 * atanf(1);
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();
72 std::vector<float> vertex_h_inv(mesh.vertices.size(), 0.f);
73 for (
unsigned v = 0; v < mesh.vertices.size(); ++v)
75 float h = (mesh.curv1[v] + mesh.curv2[v]) / 2;
77 float h_inv = 1 / pi * (atan(-h) + pi / 2);
78 vertex_h_inv[v] = h_inv;
82 std::vector<float> face_h_inv(mesh.faces.size(), 42.f);
83 for (
unsigned f = 0; f < mesh.faces.size(); ++f)
85 float h_inv = (vertex_h_inv[mesh.faces[f][0]] +
86 vertex_h_inv[mesh.faces[f][1]] +
87 vertex_h_inv[mesh.faces[f][2]]) / 3;
88 mln_invariant(0.f <= h_inv);
89 mln_invariant(h_inv <= 1.f);
90 face_h_inv[f] = h_inv;
94 FILE* f_out = fopen(output_filename.c_str(),
"wb");
97 std::cerr <<
"Error opening " << output_filename.c_str()
98 <<
" for writing." << std::endl;
101 write_off_float(mesh_ptr, face_h_inv, f_out);