Debian Codegraph @

src/atlas/util/CGALSphericalTriangulation.h

raw
1 /*
2 * (C) Copyright 2023 ECMWF.
3 *
4 * This software is licensed under the terms of the Apache Licence Version 2.0
5 * which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
6 * In applying this licence, ECMWF does not waive the privileges and immunities
7 * granted to it by virtue of its status as an intergovernmental organisation
8 * nor does it submit to any jurisdiction.
9 */
10
11 #pragma once
12
13 #include <array>
14 #include <vector>
15 #include <memory>
16
17 #include "atlas/library/config.h"
18 namespace atlas {
19 namespace util {
20
21
22 class CGALSphericalTriangulation {
23 public:
24 template <typename LonLatVector>
25 CGALSphericalTriangulation(const LonLatVector& lonlat);
26 CGALSphericalTriangulation(size_t N, const double lonlat[]);
27 CGALSphericalTriangulation(size_t N, const double lon[], const double lat[]);
28 CGALSphericalTriangulation(size_t N, const double lon[], const double lat[], int lon_stride, int lat_stride);
29
30 ~CGALSphericalTriangulation();
31
32 /// @return number of triangles
33 size_t size() const;
34
35 void triangles(std::array<int,3>[]) const;
36 void triangles(std::array<long,3>[]) const;
37 void triangles(std::array<long long,3>[]) const;
38 void triangles(std::array<size_t,3>[]) const;
39
40 template<typename Value>
41 std::vector<std::array<Value,3>> triangles() const;
42 std::vector<std::array<idx_t,3>> triangles() const;
43
44 private:
45 struct CGAL;
46 std::unique_ptr<CGAL> cgal_;
47 std::vector<std::array<double,3>> points_xyz_;
48 };
49
50 template <typename LonLatVector>
51 inline CGALSphericalTriangulation::CGALSphericalTriangulation(const LonLatVector& lonlat) :
52 CGALSphericalTriangulation(lonlat.size(), reinterpret_cast<const double*>(lonlat.data())) {}
53
54 template<typename Value>
55 inline std::vector<std::array<Value,3>> CGALSphericalTriangulation::triangles() const {
56 std::vector<std::array<Value,3>> vector(size());
57 triangles(vector.data());
58 return vector;
59 }
60
61
62 }
63 }
64