18 #include <CGAL/AABB_tree.h>
19 #include <CGAL/AABB_traits.h>
20 #include <CGAL/AABB_face_graph_triangle_primitive.h>
34 #include <boost/foreach.hpp>
38 using Triangle = CGALKernel::Triangle_3;
39 using Segment = CGALKernel::Segment_3;
40 using Ray = CGALKernel::Ray_3;
45 template<
typename Po
int3d,
typename Vector >
52 double b = 2.0 * v * w;
53 double c = (w * w) - r * r;
54 double delta = b * b - 4 * a * c;
65 double t = (-b + std::sqrt(delta)) / (2.0 * a);
106 template<
typename VertexIterator,
107 typename HalfedgeGraph,
109 typename MSDM2NearestMap,
113 const PointMap &pm_degr,
114 const MSDM2NearestMap &nearest_pmap,
116 const VertexIterator p_vertex,
118 std::vector< double > &tab_distance1,
119 std::vector< double > &tab_distance2,
120 std::vector< CGALPoint > &tab_point1,
121 std::vector< CGALPoint > &tab_point2,
126 double variance1 = 0;
129 double variance2 = 0;
131 double covariance = 0;
136 double *tab_wi1 =
new double[tab_point1.size()];
137 double *tab_wi2 =
new double[tab_point1.size()];
138 double somme_distance1 = 0;
139 double somme_distance2 = 0;
140 double somme_wi1 = 0;
141 double somme_wi2 = 0;
142 for(
unsigned int i = 0; i < tab_point1.size(); i++)
144 auto distance_pt1 = tab_point1[i] -
get(pm_degr, p_vertex);
145 double dist_pt1 = sqrt(distance_pt1 * distance_pt1);
146 double wi1 = 1 /
variance / sqrt(2 * 3.141592) *
151 somme_distance1 += tab_distance1[i] * wi1;
153 auto distance_pt2 = tab_point2[i] -
get(nearest_pmap, p_vertex);
154 double dist_pt2 = sqrt(distance_pt2 * distance_pt2);
156 double wi2 = 1 /
variance / sqrt(2 * 3.141592) *
160 somme_distance2 += tab_distance2[i] * wi2;
162 moyenne1 = somme_distance1 / (double)somme_wi1;
163 moyenne2 = somme_distance2 / (double)somme_wi2;
166 for(
unsigned int i = 0; i < tab_point1.size(); i++)
168 variance1 += tab_wi1[i] * pow(tab_distance1[i] - moyenne1, 2);
169 variance2 += tab_wi2[i] * pow(tab_distance2[i] - moyenne2, 2);
170 covariance += tab_wi2[i] * (tab_distance1[i] - moyenne1) *
171 (tab_distance2[i] - moyenne2);
174 variance1 = variance1 / somme_wi1;
175 variance2 = variance2 / somme_wi2;
176 variance1 = sqrt(variance1);
177 variance2 = sqrt(variance2);
179 covariance = covariance / somme_wi1;
186 (
std::fabs(moyenne1 - moyenne2)) / (std::max(moyenne1, moyenne2) + 1);
188 (
std::fabs(variance1 - variance2)) / (std::max(variance1, variance2) + 1);
189 double fact3 = (
std::fabs(variance1 * variance2 - covariance)) /
190 (variance1 * variance2 + 1);
193 auto tmp_msdm2 =
get(msdm2_map, p_vertex);
194 tmp_msdm2 += std::pow(
195 (std::pow(fact1, 1) + std::pow(fact2, 1) + param * std::pow(fact3, 1)) /
198 put(msdm2_map, p_vertex, tmp_msdm2);
216 template<
typename MSDM2Map,
217 typename HalfedgeGraph,
218 typename MSDM2NearestMap,
221 typename FaceIterator =
222 typename boost::graph_traits< HalfedgeGraph >::face_iterator >
225 MSDM2Map &msdm2m_degrad,
226 MSDM2NearestMap &msdm2nm_degrad,
228 const PointMap &pm_degrad,
229 const HalfedgeGraph &m_poly_original,
230 CGAL::SM_Face_index *tab_matched_facet)
233 typename CGAL::AABB_face_graph_triangle_primitive< HalfedgeGraph >;
234 using AABB_Traits =
typename CGAL::AABB_traits< CGALKernel, AABB_Primitive >;
235 using AABB_Tree =
typename CGAL::AABB_tree< AABB_Traits >;
237 using Point_and_primitive_id =
typename AABB_Tree::Point_and_primitive_id;
240 auto original_faces =
faces(m_poly_original);
242 FaceIterator orig_begin = original_faces.first;
243 FaceIterator orig_end = original_faces.second;
245 AABB_Tree tree(orig_begin, orig_end, m_poly_original);
246 tree.accelerate_distance_queries();
253 put(msdm2m_degrad, vi, 0.);
254 put(tag_map, vi, ind);
256 Point_and_primitive_id pp =
257 tree.closest_point_and_primitive(
get(pm_degrad, vi));
258 auto f_nearest = pp.second;
260 put(msdm2nm_degrad, vi, pp.first);
261 tab_matched_facet[ind] = f_nearest;
268 template<
typename PointMap,
269 typename HalfedgeGraph,
270 typename FaceNormalMap,
271 typename VertexMSDM2Map,
272 typename GeometryTraits >
275 const PointMap &pm_degrad,
276 const FaceNormalMap &fnm_degrad,
278 const GeometryTraits >_degrad,
279 const HalfedgeGraph &m_poly_original,
280 const PointMap &pm_original,
281 const FaceNormalMap &fnm_original,
283 const GeometryTraits &,
285 VertexMSDM2Map &msdm2_pmap,
289 std::vector< CGALPoint > tab_point1;
290 std::vector< CGALPoint > tab_point2;
292 double somme_msdm2 = 0;
295 auto curvature_map_degr =
299 auto curvature_map_orig =
304 CGAL::SM_Face_index *tab_matched_facet =
308 VertexMSDM2Map msdm2_match_pmap;
309 if(
has_map(pmaps_degrad, std::string(
"v:msdm2_match")))
312 boost::any_cast< VertexMSDM2Map >(pmaps_degrad.at(
"v:msdm2_match"));
317 FEVV::make_vertex_property_map< HalfedgeGraph, double >(m_poly_degrad);
318 pmaps_degrad[
"v:msdm2_match"] = msdm2_match_pmap;
322 vertex_msdm2_nearest_map;
323 vertex_msdm2_nearest_map msdm2_nearest_pmap;
325 if(
has_map(pmaps_degrad, std::string(
"v:msdm2_nearest")))
327 msdm2_nearest_pmap = boost::any_cast< vertex_msdm2_nearest_map >(
328 pmaps_degrad.at(
"v:msdm2_nearest"));
333 FEVV::make_vertex_property_map< HalfedgeGraph, CGALPoint >(
335 pmaps_degrad[
"v:msdm2_nearest"] = msdm2_nearest_pmap;
339 vertex_tag_map tag_map;
341 if(
has_map(pmaps_degrad, std::string(
"v:tag")))
343 tag_map = boost::any_cast< vertex_tag_map >(pmaps_degrad.at(
"v:tag"));
348 FEVV::make_vertex_property_map< HalfedgeGraph, int >(m_poly_degrad);
349 pmaps_degrad[
"v:tag"] = tag_map;
360 double radius_curvature = 0.002;
361 for(
int i = 0; i < nb_level; i++)
363 double min_nrm_min_curvature_deg, max_nrm_min_curvature_deg,
364 min_nrm_max_curvature_deg, max_nrm_max_curvature_deg;
365 double min_nrm_min_curvature_org, max_nrm_min_curvature_org,
366 min_nrm_max_curvature_org, max_nrm_max_curvature_org;
373 maxdim * radius_curvature,
374 min_nrm_min_curvature_deg,
375 max_nrm_min_curvature_deg,
376 min_nrm_max_curvature_deg,
377 max_nrm_max_curvature_deg);
383 maxdim * radius_curvature,
384 min_nrm_min_curvature_org,
385 max_nrm_min_curvature_org,
386 min_nrm_max_curvature_org,
387 max_nrm_max_curvature_org);
389 kmax_kmean(m_poly_original, curvature_map_orig, maxdim);
390 kmax_kmean(m_poly_degrad, curvature_map_degr, maxdim);
402 std::vector< double > tab_distance1;
403 std::vector< double > tab_distance2;
418 radius_curvature * 5 * maxdim,
433 radius_curvature * 5 * maxdim,
438 radius_curvature += 0.001;
443 double l_msdm2 =
get(msdm2_pmap, vi) / nb_level;
444 put(msdm2_pmap, vi, l_msdm2);
445 somme_msdm2 += std::pow(l_msdm2, 3);
450 msdm2_value = std::pow(somme_msdm2 / (
double)nb_vertex, 1. / 3.);
452 delete[] tab_matched_facet;
466 template<
typename PointMap,
467 typename HalfedgeGraph,
468 typename CurvatureVertexMap,
469 typename MSMD2CurvatureMatchMap >
472 const PointMap &pm_degr,
473 const HalfedgeGraph &m_poly_orig,
474 const PointMap &pm_orig,
475 const CurvatureVertexMap curv_orig,
476 MSMD2CurvatureMatchMap curvmatch_pmap,
477 CGAL::SM_Face_index *tab_matched_facet)
484 auto *f_nearest = &tab_matched_facet[ind];
492 auto x2 =
get(pm_orig,
501 double l1 = sqrt((x3 - x2) * (x3 - x2));
502 double l2 = sqrt((x1 - x3) * (x1 - x3));
503 double l3 = sqrt((x1 - x2) * (x1 - x2));
505 auto v1 = x1 -
get(pm_degr, vi);
506 auto v2 = x2 -
get(pm_degr, vi);
507 auto v3 = x3 -
get(pm_degr, vi);
509 double t1 = sqrt(v1 * v1);
510 double t2 = sqrt(v2 * v2);
511 double t3 = sqrt(v3 * v3);
513 double p1 = (l1 + t2 + t3) / 2;
514 double p2 = (t1 + l2 + t3) / 2;
515 double p3 = (t1 + t2 + l3) / 2;
517 double a1 = (p1 * (p1 - l1) * (p1 - t3) * (p1 - t2));
518 double a2 = (p2 * (p2 - l2) * (p2 - t3) * (p2 - t1));
519 double a3 = (p3 * (p3 - l3) * (p3 - t1) * (p3 - t2));
537 double c2 =
get(curv_orig,
548 double curvmatch = 0.0;
549 if((a1 + a2 + a3) > 0)
550 curvmatch = (a1 * c1 + a2 * c2 + a3 * c3) / (a1 + a2 + a3);
552 curvmatch = (c1 + c2 + c3) / 3;
553 put(curvmatch_pmap, vi, curvmatch);
572 template<
typename VertexIterator,
573 typename HalfedgeGraph,
576 typename CurvatureVertexMap,
577 typename MSDM2NearestMap,
578 typename MSMD2CurvatureMatchMap,
579 typename GeometryTraits >
582 const PointMap &pm_degr,
583 const TagMap &tags_pmap,
584 const CurvatureVertexMap &curv_pmap,
585 const MSDM2NearestMap &nearest_pmap,
586 const MSMD2CurvatureMatchMap &curvmatch_pmap,
587 const GeometryTraits &,
588 const HalfedgeGraph &,
590 const VertexIterator &p_vertex,
592 std::vector< double > &tab_distance1,
593 std::vector< double > &tab_distance2,
594 std::vector< CGALPoint > &tab_point1,
595 std::vector< CGALPoint > &tab_point2)
600 std::stack< VertexIterator > s;
602 auto o =
get(pm_degr, p_vertex);
608 tab_distance1.push_back(
get(curv_pmap, p_vertex).KmaxCurv);
609 tab_point1.push_back(
get(pm_degr, p_vertex));
611 tab_distance2.push_back(
get(curvmatch_pmap, p_vertex));
612 tab_point2.push_back(
get(nearest_pmap, p_vertex));
614 int nb_sommet_in_sphere = 0;
619 VertexIterator v_it = s.top();
626 auto p1 =
get(pm_degr,
target(h, m_degr));
629 auto p1m =
get(nearest_pmap,
target(h, m_degr));
633 auto vm = (p2m - p1m);
635 if(v_it == p_vertex || v * (p - o) > 0.0)
638 double len_old = std::sqrt(v * v);
640 double len_edge = std::sqrt(v * v);
642 nb_sommet_in_sphere++;
645 double weighted_curv1, weighted_curv2;
648 bool is_already_integrated =
false;
659 is_already_integrated =
true;
662 if(is_already_integrated ==
false)
664 if(len_old != 0 && isect)
667 (1 - len_edge / len_old) *
668 get(curv_pmap,
target(h, m_degr)).KmaxCurv +
672 weighted_p1 = p1 + v;
675 (1 - len_edge / len_old) *
679 weighted_p2 = p1m + (len_edge / len_old) * vm;
691 tab_distance1.push_back(weighted_curv1);
692 tab_point1.push_back(weighted_p1);
694 tab_distance2.push_back(weighted_curv2);
695 tab_point2.push_back(weighted_p2);
710 template<
typename HalfedgeGraph,
typename CurvatureVertexMap >
713 CurvatureVertexMap &curv_vmap,
719 auto curv =
get(curv_vmap, vi);
720 double kmax = curv.KmaxCurv * coef;
721 double kmin = std::abs(curv.KminCurv * coef);
722 curv.KmaxCurv = (kmax + kmin) / 2.;
723 put(curv_vmap, vi, curv);
736 template<
typename HalfedgeGraph,
739 typename FaceNormalMap,
740 typename VertexMSDM2Map >
743 const PointMap &pm_degrad,
744 const FaceNormalMap &fnm_degrad,
746 const HalfedgeGraph &m_poly_original,
747 const PointMap &pm_original,
748 const FaceNormalMap &fnm_original,
751 VertexMSDM2Map &msdm2_pmap,
755 GeometryTraits gt_deg(m_poly_degrad);
756 GeometryTraits gt_org(m_poly_original);