1 // Copyright (c) 2003-2004  INRIA Sophia-Antipolis (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/Mesh_2/include/CGAL/Delaunay_mesh_area_criteria_2.h $
7 // $Id: Delaunay_mesh_area_criteria_2.h 0779373 2020-03-26T13:31:46+01:00 Sébastien Loriot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Laurent RINEAU
12 
13 #ifndef CGAL_DELAUNAY_MESH_AREA_CRITERIA_2_H
14 #define CGAL_DELAUNAY_MESH_AREA_CRITERIA_2_H
15 
16 #include <CGAL/license/Mesh_2.h>
17 
18 
19 #include <CGAL/Delaunay_mesh_size_criteria_2.h>
20 
21 namespace CGAL {
22 
23 template <class Tr>
24 class Delaunay_mesh_area_criteria_2
25   : public virtual Delaunay_mesh_criteria_2<Tr>,
26     private Delaunay_mesh_size_criteria_2<Tr>
27 /* This class "is a" Delaunay_mesh_criteria_2<Tr> and is implemented by
28    Delaunay_mesh_size_criteria_2<Tr>. Delaunay_mesh_criteria_2<Tr> is a
29    virtual base class of Delaunay_mesh_size_criteria_2<Tr>. */
30 {
31   typedef typename Tr::Geom_traits Geom_traits;
32 
33 protected:
34   Geom_traits traits;
35 public:
36   typedef Delaunay_mesh_criteria_2<Tr> Base;
37   typedef Delaunay_mesh_size_criteria_2<Tr> Private_base;
38 
39   typedef typename Delaunay_mesh_size_criteria_2<Tr>::Quality Quality;
40 
41   Delaunay_mesh_area_criteria_2(const double aspect_bound = 0.125,
42                                 const double area_bound = 0,
43                                 const Geom_traits& traits = Geom_traits())
Private_base(aspect_bound,area_bound,traits)44     : Private_base(aspect_bound, area_bound, traits), traits(traits) {}
45 
46   inline
area_bound()47   double area_bound() const { return this->sizebound; }
48 
49   inline
set_area_bound(const double ab)50   void set_area_bound(const double ab) { this->sizebound = ab; }
51 
52   class Is_bad: public Private_base::Is_bad
53   {
54   public:
55     typedef typename Private_base::Is_bad Is_bad_base;
56 
57     typedef typename Tr::Point Point_2;
58     typedef typename Tr::Triangle Triangle_2;
59     typedef typename Tr::Face_handle Face_handle;
60 
Is_bad(const double aspect_bound,const double area_bound,const Geom_traits & traits)61     Is_bad(const double aspect_bound,
62            const double area_bound,
63            const Geom_traits& traits)
64       : Is_bad_base(aspect_bound, area_bound, traits) {}
65 
operator()66     Mesh_2::Face_badness operator()(Quality q)
67     {
68       return Is_bad_base::operator()(q);
69     }
70 
operator()71     Mesh_2::Face_badness operator()(const Face_handle& fh,
72                                     Quality& q) const
73     {
74       typedef typename Tr::Geom_traits Geom_traits;
75 
76       typedef typename Geom_traits::Point_2 Point_2;
77       typedef typename Geom_traits::Triangle_2 Triangle_2;
78       typedef typename Geom_traits::Compute_area_2 Compute_area_2;
79       typedef typename Geom_traits::Compute_squared_distance_2
80         Compute_squared_distance_2;
81 
82       Geom_traits geom_traits;
83 
84       Compute_area_2 area_2 = geom_traits.compute_area_2_object();
85       Compute_squared_distance_2 squared_distance =
86         geom_traits.compute_squared_distance_2_object();
87 
88       const Point_2& pa = fh->vertex(0)->point();
89       const Point_2& pb = fh->vertex(1)->point();
90       const Point_2& pc = fh->vertex(2)->point();
91 
92       Triangle_2 t = geom_traits.construct_triangle_2_object()(pa,pb,pc);
93       double area = CGAL::to_double(area_2(t));
94       area=area*area; // squared area
95 
96       double
97         a = CGAL::to_double(squared_distance(pb, pc)),
98         b = CGAL::to_double(squared_distance(pc, pa)),
99         c = CGAL::to_double(squared_distance(pa, pb));
100 
101       double min_sine; // squared minimum sine
102 
103       if(a<b)
104         if(a<c)
105           min_sine = area/(b*c);
106         else
107           min_sine = area/(a*b);
108       else
109         if(b<c)
110           min_sine = area/(a*c);
111         else
112           min_sine = area/(a*b);
113 
114       q.first = min_sine;
115       q.second = area;
116 
117       if( this->squared_size_bound != 0 &&
118           area > this->squared_size_bound )
119         return Mesh_2::IMPERATIVELY_BAD;
120       else
121         if( min_sine < this->B )
122           return Mesh_2::BAD;
123         else
124           return Mesh_2::NOT_BAD;
125     };
126   }; // end class Is_bad
127 
is_bad_object()128   Is_bad is_bad_object() const
129   { return Is_bad(this->bound(), area_bound(), traits); }
130 };
131 
132 } //end namespace
133 
134 #endif
135