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/line_graph_image.hh>
45 #include <mln/core/image/line_graph_elt_neighborhood.hh>
47 #include <mln/morpho/closing/area.hh>
48 #include <mln/morpho/meyer_wst.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();
91 std::vector<curv_t> vertex_h_inv(mesh.vertices.size(), 0.f);
92 for (
unsigned v = 0; v < mesh.vertices.size(); ++v)
94 float h = (mesh.curv1[v] + mesh.curv2[v]) / 2;
95 float h_inv = 1 / pi * atan(-h) + pi / 2;
100 vertex_h_inv[v] = 1000 * h_inv;
114 std::vector<curv_t> vertex_values (mesh.faces.size(), 0.f);
115 std::vector<curv_t> edge_values;
121 for (
unsigned i = 0; i < mesh.faces.size(); ++i)
125 mesh.need_across_edge();
126 for (
unsigned f = 0; f < mesh.faces.size(); ++f)
127 for (
unsigned e = 0; e < 3; ++e)
129 int f_adj = mesh.across_edge[f][e];
133 if (g.
add_edge(f, f_adj) != mln_max(mln::util::edge_id::equiv))
139 std::vector<int> adj_vertices;
140 adj_vertices.reserve(2);
141 for (
unsigned i = 0; i < 3; ++i)
142 for (
unsigned j = 0; j < 3; ++j)
143 if (mesh.faces[f][i] == mesh.faces[f_adj][j])
144 adj_vertices.push_back(mesh.faces[f][i]);
145 mln_assertion(adj_vertices.size() == 2);
148 edge_values.push_back((vertex_h_inv[adj_vertices[0]] +
149 vertex_h_inv[adj_vertices[1]])
154 mln_assertion(g.
edges().size() == edge_values.size());
162 mln::p_line_graph<mln::point3d> plg(g);
164 typedef mln::line_graph_image<mln::point3d, curv_t> ima_t;
165 ima_t lg_ima(plg, vertex_values, edge_values);
171 typedef mln::line_graph_elt_neighborhood<mln::point3d> nbh_t;
174 ima_t closed_lg_ima = mln::morpho::closing::area(lg_ima, nbh, lambda);
180 typedef unsigned wst_val_t;
182 typedef mln::line_graph_image<mln::point3d, wst_val_t> wst_ima_t;
184 std::cout <<
"nbasins = " << nbasins << std::endl;
192 std::vector<unsigned> vertex_label(wshed.domain().nvertices(), 0);
193 mln_piter_(wst_ima_t) pw(wshed.domain());
197 mln_psite_(wst_ima_t) pp(pw);
198 vertex_label[pp.first_id().to_equiv()] = wshed(pw);
199 vertex_label[pp.second_id().to_equiv()] = wshed(pw);
207 std::vector<mln::value::rgb8> basin_color (nbasins + 1);
208 for (
unsigned i = 0; i <= nbasins; ++i)
209 basin_color[i] = mln::value::rgb8(random() % 256,
214 std::vector<mln::value::rgb8> face_color (vertex_label.size());
215 for (
unsigned i = 0; i < vertex_label.size() ; ++i)
216 face_color[i] = basin_color[vertex_label[i]];
219 FILE* f_out = fopen(output_filename.c_str(), "wb");
222 std::cerr <<
"Error opening " << output_filename.c_str()
223 <<
" for writing." << std::endl;
226 write_off_colored(mesh_ptr, face_color, f_out);