17 #include <CGAL/boost/graph/iterator.h>
18 #include <CGAL/boost/graph/helpers.h>
30 template<
typename Graph>
35 typedef boost::graph_traits<Graph> GraphTraits;
39 auto vertices_range = CGAL::vertices_around_target(v, g);
40 for (
auto v : vertices_range) {
47 template<
typename Graph>
52 typename boost::graph_traits<Graph>::edge_descriptor min_e)
54 typedef boost::graph_traits<Graph> GraphTraits;
56 typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
59 if (min_e !=
edge(GraphTraits::null_halfedge(), g))
62 halfedge_descriptor h =
halfedge(min_e, g);
66 halfedge_descriptor h_end = h;
70 auto it_res = processed_vertices.find(v_adj);
71 if ((it_res == processed_vertices.end()) || !it_res->second)
73 if (it_res != processed_vertices.end())
74 it_res->second =
true;
76 processed_vertices[v_adj] =
true;
81 }
while (!(h == h_end));
85 auto vertices_range = CGAL::vertices_around_target(v, g);
86 for (
auto v_adj : vertices_range) {
87 auto it_res = processed_vertices.find(v_adj);
88 if ((it_res != processed_vertices.end()) && it_res->second)
91 if (it_res != processed_vertices.end())
92 it_res->second =
true;
94 processed_vertices[v_adj] =
true;
113 template<
typename GeometryTraits >
117 const GeometryTraits& gt)
120 double perim = FEVV::Operators::Geometry::triangle_perimeter<GeometryTraits>(v_s_t_kept_neighbor_pos, v_s_pos, v_t_pos, gt);
122 if (gt.length(v_s_pos, v_t_pos) < prec)
127 area = FEVV::Operators::Geometry::triangle_area<GeometryTraits>(v_s_t_kept_neighbor_pos, v_s_pos, v_t_pos, gt);
128 double res = ((perim < prec)? area:area/perim);
129 static double min_res = 0., max_res = 1024. * 2.;
130 size_t nb_bit_quantization =
static_cast<size_t>(log2(max_res) + 2);
134 std::cout <<
"max_res = " << max_res << std::endl;
136 if (nb_bit_quantization > 32)
137 nb_bit_quantization = 32;
138 size_t two_power_nb_bit = std::pow(2, nb_bit_quantization);
139 double delta = (max_res - min_res) / two_power_nb_bit;
141 res = std::floor(res / delta) * delta + 0.5 * delta;
147 template<
typename Graph,
typename Po
intMap,
typename GeometryTraits = FEVV::Geometry_traits<Graph> >
155 const GeometryTraits& gt)
157 typedef boost::graph_traits<Graph> GraphTraits;
159 if (gt.length(v_s_pos, v_t_pos) > 1e-8)
161 std::map< vertex_descriptor, double > vertex_priority;
163 auto it = adjacent2v.begin(), it_e = adjacent2v.end();
164 for (; it != it_e; ++it)
166 const auto& pos_n =
get(pm, *it);
170 return (vertex_priority[v1] > vertex_priority[v2]);
176 template<
typename Graph,
typename Po
intMap,
typename GeometryTraits = FEVV::Geometry_traits<Graph> >
182 const GeometryTraits& gt)
184 typedef boost::graph_traits<Graph> GraphTraits;
186 typedef typename GraphTraits::halfedge_descriptor halfedge_descriptor;
188 std::map< vertex_descriptor, double > vertex_priority;
191 vertex_descriptor first = GraphTraits::null_vertex(), second = GraphTraits::null_vertex();
192 bool find_a_border =
false;
194 const auto& pos_v =
get(pm, v);
195 auto it = adjacent2v.begin(), it_e = adjacent2v.end();
196 for (; it != it_e; ++it)
198 halfedge_descriptor h =
halfedge(*it, v, g).first;
199 if (CGAL::is_border(h, g))
200 find_a_border =
true;
201 const auto& pos_n =
get(pm, *it);
202 double d_tmp = gt.length(pos_v, pos_n);
214 it = adjacent2v.begin();
215 for (; it != it_e; ++it)
217 const auto& pos_n1 =
get(pm, *it);
220 for (; it2 != it_e; ++it2)
222 const auto& pos_n2 =
get(pm, *it2);
223 double d_tmp = gt.length(pos_n1, pos_n2);
233 const auto& pos_first =
get(pm, first);
236 const auto& pos_second = ((find_a_border)? pos_v :
get(pm, second));
237 auto normal = gt.sub_p(pos_second, pos_first);
238 auto plane_point = ((find_a_border) ? pos_v:gt.add_pv(pos_first, gt.scalar_mult(normal, 0.5f)));
239 normal = gt.normalize(normal);
243 it = adjacent2v.begin();
244 for (; it != it_e; ++it)
246 const auto& pos_n =
get(pm, *it);
247 double d_tmp = std::abs( gt.dot_product(normal, gt.sub_p(pos_n, plane_point)) );
248 vertex_priority[*it] = -d_tmp;
251 return (vertex_priority[v1] > vertex_priority[v2]);
256 template <
typename Graph,
typename Po
intMap,
typename GeometryTraits = FEVV::Geometry_traits<Graph> >
269 typedef typename GeometryTraits::Scalar
Scalar;
299 std::set<vertex_descriptor> remaining_mesh_vertices(vertices_range_pair.first, vertices_range_pair.second);
302 std::list< std::list<vertex_descriptor> > connected_components;
303 if (!remaining_mesh_vertices.empty())
307 std::map< vertex_descriptor, bool > already_stacked;
308 std::list<vertex_descriptor> component;
315 if (list_v_around.empty())
317 already_stacked[v_current] =
true;
318 component.push_back(v_current);
319 remaining_mesh_vertices.erase(v_current);
323 std::stack<vertex_descriptor> component_stack;
324 component_stack.push(v_current);
326 while (!component_stack.empty())
329 component_stack.pop();
331 already_stacked[v] =
true;
332 component.push_back(v);
336 for (
auto v_around : list_v_around)
338 typename std::set<vertex_descriptor>::iterator it = remaining_mesh_vertices.find(v_around);
339 if (it != remaining_mesh_vertices.end())
341 already_stacked[v_around] =
true;
342 component_stack.push(v_around);
348 remaining_mesh_vertices.erase(v);
353 connected_components.push_back(component);
355 }
while (!remaining_mesh_vertices.empty());
359 typename std::list< std::list<vertex_descriptor> >::iterator it_list = connected_components.begin();
360 for (; it_list != connected_components.end(); ++it_list)
362 assert(!it_list->empty());
363 auto iter_v = it_list->begin(),
364 iter_v_e = it_list->end();
368 for (; iter_v != iter_v_e; ++iter_v)
370 if (
_cmp_v(*iter_v, best_root))
375 if (tie_break_detection) {
376 iter_v = it_list->begin();
377 while (iter_v != iter_v_e)
379 if ((*iter_v != best_root) && !
_cmp_v(*iter_v, best_root) && !
_cmp_v(best_root, *iter_v))
384 std::list<vertex_descriptor> root_candidates;
385 while (iter_v != iter_v_e)
387 if (*iter_v != best_root)
389 if (!
_cmp_v(*iter_v, best_root) && !
_cmp_v(best_root, *iter_v))
393 auto iter_v2 = iter_v;
396 while (iter_v2 != iter_v_e)
400 if ((iter_v2 != iter_v_e) && (!
_cmp_v(*iter_v, *iter_v2) && !
_cmp_v(*iter_v2, *iter_v)))
403 while (iter_v2 != iter_v_e)
405 if (!
_cmp_v(*iter_v, *iter_v2) && !
_cmp_v(*iter_v2, *iter_v))
413 if (iter_v2 == iter_v_e)
414 root_candidates.push_back(*iter_v);
419 root_candidates.sort(
_cmp_v);
420 if (!root_candidates.empty())
421 best_root = *(root_candidates.begin());
424 std::cerr <<
"Spanning_tree_vertex_edge_comparator: compute_first_vertex_connected_component (find the root(s)): tie-break detected!" << std::endl;
446 auto vi = vertices_range_pair.first;
447 auto vi_end = vertices_range_pair.second;
449 std::map<vertex_descriptor, bool> processed_vertices;
450 for (; vi != vi_end; ++vi)
451 processed_vertices.insert(std::make_pair(*vi,
false));
453 auto edges_range_pair =
edges(
_g);
454 auto iter_e = edges_range_pair.first;
455 auto dist = std::distance(edges_range_pair.first, edges_range_pair.second);
456 for( ;iter_e != edges_range_pair.second; ++iter_e)
463 processed_vertices.find(*it_root_vertices)->second =
true;
467 for (; it_root_vertices != it_root_vertices_e; ++it_root_vertices)
470 assert(current_v != GraphTraits::null_vertex());
474 processed_vertices.find(current_v)->second =
true;
496 if (tie_break_detection) {
498 for (; it_v_debug != it_v_debug_e; ++it_v_debug)
500 auto it_v2_debug = it_v_debug;
501 if (it_v2_debug != it_v_debug_e)
505 if ((it_v2_debug != it_v_debug_e) && !
_cmp_v(*it_v_debug, *it_v2_debug) && !
_cmp_v(*it_v2_debug, *it_v_debug))
509 for (; it_v2_debug != it_v_debug_e; ++it_v2_debug)
511 if (!
_cmp_v(*it_v_debug, *it_v2_debug) && !
_cmp_v(*it_v2_debug, *it_v_debug))
514 std::cerr <<
"Spanning_tree_vertex_edge_comparator: compute_st: new region growing start: tie-break detected!" << std::endl;
530 for (; it_v != it_v_e; ++it_v)
533 auto res =
edge(current_v, *it_v,
_g);
552 current_v = *current_st_it;
559 _gt(GeometryTraits(g)),
614 return edge(GraphTraits::null_halfedge(),
_g);
618 auto pair_e_bool =
edge(min_v, v,
_g);
619 return pair_e_bool.first;
627 return edge(GraphTraits::null_halfedge(),
_g);
631 auto it_v = list_v_around.begin(),
632 it_v_e = list_v_around.end();
633 for (; it_v != it_v_e; ++it_v)
635 auto pair_e_bool =
edge(v, *it_v,
_g);
638 if (selected_min_edge ==
edge(GraphTraits::null_halfedge(),
_g))
639 selected_min_edge = pair_e_bool.first;
641 selected_min_edge = pair_e_bool.first;
644 if (selected_min_edge ==
edge(GraphTraits::null_halfedge(),
_g))
647 return selected_min_edge;
660 template <
typename Graph,
typename Po
intMap,
typename GeometryTraits = FEVV::Geometry_traits<Graph> >
662 Spanning_tree_vertex_edge_comparator<Graph, PointMap, GeometryTraits>