1 // Copyright (c) 2016 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/Mesh_3/include/CGAL/Mesh_3/experimental/Sizing_field_minimum.h $
7 // $Id: Sizing_field_minimum.h 254d60f 2019-10-19T15:23:19+02:00 Sébastien Loriot
8 // SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
9 //
10 //
11 // Author(s)     : Jane Tournois
12 //
13 //******************************************************************************
14 // File Description :
15 //
16 //
17 //******************************************************************************
18 
19 
20 #ifndef CGAL_MESH_3_SIZING_FIELD_MINIMUM
21 #define CGAL_MESH_3_SIZING_FIELD_MINIMUM
22 
23 #include <CGAL/license/Mesh_3.h>
24 
25 #include <boost/static_assert.hpp>
26 #include <boost/type_traits/is_same.hpp>
27 
28 namespace CGAL
29 {
30   template <typename SizingField1, typename SizingField2>
31   class Sizing_field_minimum
32   {
33   public:
34     typedef typename SizingField1::FT       FT;
35     typedef typename SizingField1::Point_3  Point_3;
36     typedef typename SizingField1::Index    Index;
37 
38     BOOST_STATIC_ASSERT_MSG((
39       boost::is_same<typename SizingField1::FT,
40                      typename SizingField2::FT>::value),
41       "FT type should be the same for both sizing fields");
42     BOOST_STATIC_ASSERT_MSG((
43       boost::is_same<typename SizingField1::Point_3,
44                      typename SizingField2::Point_3>::value),
45       "Point_3 type should be the same for both sizing fields");
46     BOOST_STATIC_ASSERT_MSG((
47       boost::is_same<typename SizingField1::Index,
48                      typename SizingField2::Index>::value),
49       "Index type should be the same for both sizing fields");
50 
51   private:
52     const SizingField1* mp_size1;
53     const SizingField2* mp_size2;
54 
55   public:
Sizing_field_minimum(const SizingField1 * sf1,const SizingField2 * sf2)56     Sizing_field_minimum(const SizingField1* sf1,
57                          const SizingField2* sf2)
58       : mp_size1(sf1)
59       , mp_size2(sf2)
60     {}
61 
operator()62     FT operator()(const Point_3& p, const int dim, const Index& index) const
63     {
64       if(mp_size2 == 0) return (*mp_size1)(p, dim, index);
65       if(mp_size1 == 0) return (*mp_size2)(p, dim, index);
66       FT s1 = (*mp_size1)(p, dim, index);
67       FT s2 = (*mp_size2)(p, dim, index);
68       if (s1 == 0)       return s2;
69       else if (s2 == 0)  return s1;
70       else               return (std::min)(s1, s2);
71     }
72 
73   };//Sizing_field_minimum
74 
75 }//namespace CGAL
76 
77 #endif // CGAL_MESH_3_SIZING_FIELD_MINIMUM
78