Debian Codegraph @

src/atlas/util/QhullSphericalTriangulation.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 class QhullSphericalTriangulation {
22 public:
23 template <typename LonLatVector>
24 QhullSphericalTriangulation(const LonLatVector& lonlat);
25 QhullSphericalTriangulation(size_t N, const double lonlat[]);
26 QhullSphericalTriangulation(size_t N, const double lon[], const double lat[]);
27 QhullSphericalTriangulation(size_t N, const double lon[], const double lat[], int lon_stride, int lat_stride);
28
29 ~QhullSphericalTriangulation();
30
31 /// @return number of triangles
32 size_t size() const;
33
34 void triangles(std::array<int,3>[]) const;
35 void triangles(std::array<long,3>[]) const;
36 void triangles(std::array<long long,3>[]) const;
37 void triangles(std::array<size_t,3>[]) const;
38
39 template<typename Value>
40 std::vector<std::array<Value,3>> triangles() const;
41 std::vector<std::array<idx_t,3>> triangles() const;
42
43 private:
44 struct Qhull;
45 std::unique_ptr<Qhull> qhull_;
46 std::vector<std::array<double,3>> points_xyz_;
47 };
48
49 template <typename LonLatVector>
50 inline QhullSphericalTriangulation::QhullSphericalTriangulation(const LonLatVector& lonlat) :
51 QhullSphericalTriangulation(lonlat.size(), reinterpret_cast<const double*>(lonlat.data())) {}
52
53 template<typename Value>
54 inline std::vector<std::array<Value,3>> QhullSphericalTriangulation::triangles() const {
55 std::vector<std::array<Value,3>> vector(size());
56 triangles(vector.data());
57 return vector;
58 }
59
60
61 }
62 }
63