File: Implicit_surface_3.h

package info (click to toggle)
cgal 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 144,952 kB
  • sloc: cpp: 811,597; ansic: 208,576; sh: 493; python: 411; makefile: 286; javascript: 174
file content (150 lines) | stat: -rw-r--r-- 4,348 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// Copyright (c) 2006-2007  INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
//
// $URL: https://github.com/CGAL/cgal/blob/v6.1.1/Surface_mesher/include/CGAL/Implicit_surface_3.h $
// $Id: include/CGAL/Implicit_surface_3.h 08b27d3db14 $
// SPDX-License-Identifier: GPL-3.0-or-later OR LicenseRef-Commercial
//
// Author(s)     : Laurent RINEAU

#ifndef CGAL_IMPLICIT_SURFACE_3_H
#define CGAL_IMPLICIT_SURFACE_3_H

#include <CGAL/license/Surface_mesher.h>

#define CGAL_DEPRECATED_HEADER "<CGAL/Implicit_surface_3.h>"
#define CGAL_DEPRECATED_MESSAGE_DETAILS \
  "The 3D Mesh Generation package (see https://doc.cgal.org/latest/Mesh_3/) should be used instead."
#include <CGAL/Installation/internal/deprecation_warning.h>

#include <CGAL/disable_warnings.h>

#include <CGAL/make_surface_mesh.h>
#include <CGAL/Surface_mesher/Implicit_surface_oracle_3.h>

#include <functional>
#include <functional>

namespace CGAL {

  template<
    typename GT,
    typename Function_ = std::function<typename GT::FT(typename GT::Point_3)>
    // The type of the argument `Function` will be ignored anyway.
    // The parameter is here only for backward-compatibility.
    >
  class Implicit_surface_3
  {
  public:
    typedef GT Geom_traits;
    typedef typename Geom_traits::Sphere_3 Sphere_3;
    typedef typename Geom_traits::FT FT;
    typedef typename Geom_traits::Point_3 Point;
    typedef std::function<FT(Point)> Function;
    typedef Implicit_surface_3<Geom_traits, Function_> Self;

    Function& function() { return func; }

    typedef Surface_mesher::Implicit_surface_oracle_3<
      Geom_traits,
      Self> Surface_mesher_traits_3;

    Implicit_surface_3(Function f,
                       const Sphere_3 bounding_sphere,
                       const FT error_bound = FT(1e-3),
                       Geom_traits gt = Geom_traits())
      : func(f),
        sphere(bounding_sphere),
        gt(gt)
    {
      squared_error = error_bound * error_bound;
      squared_error = squared_error *
        gt.compute_squared_radius_3_object()(bounding_sphere);
    }

    FT operator()(Point p) const
    {
      return func(p);
    }

    const FT& squared_error_bound() const
    {
      return squared_error;
    }

    const Sphere_3& bounding_sphere() const
    {
      return sphere;
    }

    const Sphere_3& bounding_sphere_squared_radius() const
    {
      return gt.compute_squared_radius_3_object()(sphere);
    }

    template <typename Vertex_handle>
    bool vertices_not_on_same_surface_patch(const Vertex_handle& v1,
                                            const Vertex_handle& v2,
                                            const Vertex_handle& v3) const
    {
      return
        v1->point().element_index() != v2->point().element_index() ||
        v1->point().element_index() != v3->point().element_index();
    }

    const Function& function() const
    {
      return func;
    }

  private:
    Function func;
    Sphere_3 sphere;
    FT squared_error;
    Geom_traits gt;
  }; // end Implicit_surface_3


  template <typename GT, typename Function>
  Implicit_surface_3<GT, Function>
  make_implicit_surface_3(GT, Function f,
                          typename GT::Sphere_3 sphere,
                          typename GT::FT error_bound)
  {
    typedef Implicit_surface_3<GT> surface;
    return surface(f, sphere, error_bound);
  }

//   template <typename GT, typename Function>
//   struct Surface_mesh_traits_generator_3<Implicit_surface_3<GT, Function> >
//   {
//     typedef Implicit_surface_3<GT, Function> Surface_type;
//     typedef typename Surface_mesher::Implicit_surface_oracle_3<GT,
//                                                              Surface_type> Type;
//     typedef Type type; // Boost meta-programming compatibility
//   };

  // non documented class
  template <typename FT, typename Point>
  class Implicit_function_wrapper : public CGAL::cpp98::unary_function<Point, FT>
  {
    typedef FT (*Implicit_function)(FT, FT, FT);

    Implicit_function function;

  public:
    Implicit_function_wrapper(Implicit_function f) : function(f) {}

    FT operator()(Point p) const
    {
      return function(p.x(), p.y(), p.z());
    }
  };

} // end namespace CGAL

#include <CGAL/enable_warnings.h>

#endif // CGAL_IMPLICIT_SURFACE_3_H