40 #include <mln/core/alias/point3d.hh>
41 #include <mln/core/alias/point3d.hh>
43 #include <mln/util/graph.hh>
44 #include <mln/core/image/graph_image.hh>
45 #include <mln/core/image/graph_elt_neighborhood.hh>
47 #include <mln/morpho/closing/area.hh>
48 #include <mln/labeling/regional_minima.hh>
54 const float pi = 4 * atanf(1);
57 int main(
int argc,
char* argv[])
61 std::cerr <<
"usage: " << argv[0] <<
" input.off lambda output.off"
66 std::string input_filename = argv[1];
67 unsigned lambda = atoi(argv[2]);
68 std::string output_filename = argv[3];
78 TriMesh* mesh_ptr = TriMesh::read(input_filename.c_str());
81 TriMesh& mesh = *mesh_ptr;
86 mesh.need_curvatures();
87 std::vector<float> vertex_h_inv(mesh.faces.size(), 0.f);
88 for (
unsigned v = 0; v < mesh.vertices.size(); ++v)
90 float h = (mesh.curv1[v] + mesh.curv2[v]) / 2;
91 float h_inv = 1 / pi * atan(-h) + pi / 2;
92 vertex_h_inv[v] = h_inv;
99 std::vector<curv_t> face_h_inv(mesh.faces.size(), 0.f);
100 for (
unsigned f = 0; f < mesh.faces.size(); ++f)
103 (vertex_h_inv[mesh.faces[f][0]] +
104 vertex_h_inv[mesh.faces[f][1]] +
105 vertex_h_inv[mesh.faces[f][2]])
111 face_h_inv[f] = 1000 * h_inv;
126 for (
unsigned i = 0; i < mesh.faces.size(); ++i)
130 mesh.need_across_edge();
131 for (
unsigned f = 0; f < mesh.faces.size(); ++f)
132 for (
unsigned e = 0; e < 3; ++e)
134 int f_adj = mesh.across_edge[f][e];
144 mln::p_graph<mln::point3d> pg(g);
146 typedef mln::graph_image<mln::point3d, curv_t> ima_t;
147 ima_t g_ima(pg, face_h_inv);
156 ima_t closed_g_ima = mln::morpho::closing::area(g_ima, nbh, lambda);
162 typedef unsigned label_t;
164 typedef mln::graph_image<mln::point3d, label_t> label_ima_t;
167 std::cout <<
"nlabels = " << nlabels << std::endl;
183 std::vector<bool> face_value (minima.domain().nvertices(),
true);
184 mln_piter_(label_ima_t) pm(minima.domain());
191 mln_psite_(label_ima_t) pp(pm);
192 face_value[pp.
id().to_equiv()] = false;
196 FILE* f_out = fopen(output_filename.c_str(), "wb");
199 std::cerr <<
"Error opening " << output_filename.c_str()
200 <<
" for writing." << std::endl;
203 write_off_binary(mesh_ptr, face_value, f_out);