1 // Copyright (c) 2018 GeometryFactory (France).
2 // All rights reserved.
3 //
4 // This file is part of CGAL (www.cgal.org).
5 //
6 // $URL: https://github.com/CGAL/cgal/blob/v5.3/Polygon_mesh_processing/include/CGAL/Polygon_mesh_processing/internal/Smoothing/smoothing_evaluation.h $
7 // $Id: smoothing_evaluation.h f33618e 2020-02-06T09:54:35+01:00 Mael Rouxel-Labbé
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Konstantinos Katrioplas (konst.katrioplas@gmail.com)
12 
13 #ifndef CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SMOOTHING_EVALUATION_H
14 #define CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SMOOTHING_EVALUATION_H
15 
16 #include <CGAL/license/Polygon_mesh_processing/meshing_hole_filling.h>
17 
18 #include <CGAL/Polygon_mesh_processing/measure.h>
19 
20 #include <boost/graph/graph_traits.hpp>
21 #include <boost/property_map/property_map.hpp>
22 
23 #include <set>
24 #include <vector>
25 
26 namespace CGAL {
27 namespace Polygon_mesh_processing {
28 namespace internal {
29 
30 template<typename PolygonMesh, typename GeomTraits>
31 class Quality_evaluator
32 {
33   typedef typename GeomTraits::Point_3                                          Point;
34   typedef typename GeomTraits::Vector_3                                         Vector;
35   typedef typename GeomTraits::Line_3                                           Line;
36   typedef typename boost::graph_traits<PolygonMesh>::halfedge_descriptor        halfedge_descriptor;
37   typedef typename boost::graph_traits<PolygonMesh>::face_descriptor            face_descriptor;
38   typedef typename boost::property_map<PolygonMesh, CGAL::vertex_point_t>::type VertexPointMap;
39   typedef typename boost::property_traits<VertexPointMap>::reference            Point_ref;
40 
41 public:
Quality_evaluator(PolygonMesh & pmesh,const GeomTraits & traits)42   Quality_evaluator(PolygonMesh& pmesh,
43                     const GeomTraits& traits)
44     : mesh_(pmesh), traits_(traits)
45   {
46     std::size_t number_of_triangles = faces(mesh_).size();
47     angles_.reserve(number_of_triangles * 3);
48     areas_.reserve(number_of_triangles);
49     aspect_ratios_.reserve(number_of_triangles);
50     vpmap_ = get(CGAL::vertex_point, mesh_);
51   }
52 
gather_angles()53   void gather_angles()
54   {
55     for(halfedge_descriptor hi : halfedges(mesh_))
56     {
57       const Point_ref a = get(vpmap_, source(hi, mesh_));
58       const Point_ref b = get(vpmap_, target(hi, mesh_));
59       const Point_ref c = get(vpmap_, target(next(hi, mesh_), mesh_));
60 
61       angles_.push_back(traits_.compute_approximate_angle_3_object()(a, b, c));
62     }
63 
64 #ifdef CGAL_PMP_SMOOTHING_DEBUG
65     std::cout << "angles_ size = " << angles_.size() << std::endl;
66 #endif
67   }
68 
69   template <typename Stream>
extract_angles(Stream & output)70   void extract_angles(Stream& output)
71   {
72     for(unsigned int i=0; i!=angles_.size(); ++i)
73       output << angles_[i] << std::endl;
74     output.close();
75   }
76 
measure_areas()77   void measure_areas()
78   {
79     for(face_descriptor f : faces(mesh_))
80       areas_.push_back(face_area(f, mesh_));
81 
82 #ifdef CGAL_PMP_SMOOTHING_DEBUG
83     std::cout << "areas_ size = " << areas_.size() << std::endl;
84 #endif
85   }
86 
87   template <typename Stream>
extract_areas(Stream & output)88   void extract_areas(Stream& output)
89   {
90     for(unsigned int i=0; i!=areas_.size(); ++i)
91       output << areas_[i] << std::endl;
92     output.close();
93   }
94 
calc_aspect_ratios()95   void calc_aspect_ratios()
96   {
97     for(face_descriptor f : faces(mesh_))
98       aspect_ratios_.push_back(CGAL::Polygon_mesh_processing::face_aspect_ratio(f, mesh_));
99 
100 #ifdef CGAL_PMP_SMOOTHING_DEBUG
101     std::cout << "aspect_ratios_ size = " << aspect_ratios_.size() << std::endl;
102 #endif
103   }
104 
105   template <typename Stream>
extract_aspect_ratios(Stream & output)106   void extract_aspect_ratios(Stream& output)
107   {
108     for(unsigned int i=0; i!=aspect_ratios_.size(); ++i)
109       output << aspect_ratios_[i] << std::endl;
110     output.close();
111   }
112 
113 private:
114   PolygonMesh& mesh_;
115   const GeomTraits& traits_;
116   VertexPointMap vpmap_;
117 
118   std::vector<double> angles_;
119   std::vector<double> areas_;
120   std::vector<double> aspect_ratios_;
121 };
122 
123 } // namespace internal
124 } // namespace Polygon_mesh_processing
125 } // namespace CGAL
126 
127 #endif // CGAL_POLYGON_MESH_PROCESSING_INTERNAL_SMOOTHING_EVALUATION_H
128