-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
191 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/* | ||
* (C) Copyright 1996- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* In applying this licence, ECMWF does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an intergovernmental organisation nor | ||
* does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#include <array> | ||
#include <vector> | ||
|
||
#include "eckit/memory/Builder.h" | ||
#include "eckit/memory/Factory.h" | ||
|
||
|
||
namespace eckit { | ||
class Configuration; | ||
} // namespace eckit | ||
|
||
|
||
namespace eckit::geo { | ||
|
||
|
||
using Triangle = std::array<size_t, 3>; | ||
|
||
|
||
class Triangulation : protected std::vector<Triangle> { | ||
public: | ||
// -- Types | ||
|
||
using builder_t = BuilderT1<Triangulation>; | ||
using ARG1 = const Configuration&; | ||
|
||
// -- Destructor | ||
|
||
virtual ~Triangulation() = default; | ||
|
||
// -- Operators | ||
|
||
using vector::operator[]; | ||
|
||
// -- Methods | ||
|
||
static std::string className() { return "Triangulation"; } | ||
|
||
using vector::at; | ||
using vector::size; | ||
|
||
using vector::begin; | ||
using vector::cbegin; | ||
using vector::cend; | ||
using vector::end; | ||
|
||
protected: | ||
// -- Constructors | ||
|
||
Triangulation() /*noexcept */ = default; | ||
}; | ||
|
||
|
||
using TriangulationFactory = Factory<Triangulation>; | ||
|
||
template <typename T> | ||
using TriangulationBuilder = ConcreteBuilderT1<Triangulation, T>; | ||
|
||
|
||
} // namespace eckit::geo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* (C) Copyright 1996- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* In applying this licence, ECMWF does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an intergovernmental organisation nor | ||
* does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#include "eckit/geo/triangulation/Triangulation3.h" | ||
|
||
#include <memory> | ||
|
||
#include "eckit/exception/Exceptions.h" | ||
#include "eckit/geo/Grid.h" | ||
#include "eckit/geo/projection/LonLatToXYZ.h" | ||
|
||
#include "libqhullcpp/Qhull.h" | ||
#include "libqhullcpp/QhullFacetList.h" | ||
#include "libqhullcpp/QhullVertexSet.h" | ||
|
||
|
||
namespace eckit::geo::triangulation { | ||
|
||
|
||
Triangulation3::Triangulation3(const Grid& grid) { | ||
auto [lat, lon] = grid.to_latlon(); | ||
ASSERT(lat.size() == lon.size()); | ||
|
||
auto N = static_cast<int>(lon.size()); | ||
std::vector<double> coord(N * 3); | ||
|
||
geo::projection::LonLatToXYZ lonlat2xyz(1.); | ||
for (size_t i = 0; i < N; ++i) { | ||
auto p = lonlat2xyz.fwd({lon[i], lat[i]}); | ||
|
||
coord[i * 3 + 0] = p.X; | ||
coord[i * 3 + 1] = p.Y; | ||
coord[i * 3 + 2] = p.Z; | ||
} | ||
|
||
auto qh = std::make_unique<orgQhull::Qhull>("", 3, N, coord.data(), "Qt"); | ||
|
||
reserve(qh->facetCount()); | ||
for (const auto& facet : qh->facetList()) { | ||
auto vertices = facet.vertices(); | ||
ASSERT(vertices.size() == 3); | ||
emplace_back(Triangle{static_cast<size_t>(vertices[0].id()), | ||
static_cast<size_t>(vertices[1].id()), | ||
static_cast<size_t>(vertices[2].id())}); | ||
} | ||
} | ||
|
||
|
||
} // namespace eckit::geo::triangulation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* (C) Copyright 1996- ECMWF. | ||
* | ||
* This software is licensed under the terms of the Apache Licence Version 2.0 | ||
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. | ||
* In applying this licence, ECMWF does not waive the privileges and immunities | ||
* granted to it by virtue of its status as an intergovernmental organisation nor | ||
* does it submit to any jurisdiction. | ||
*/ | ||
|
||
|
||
#pragma once | ||
|
||
#include "eckit/geo/Triangulation.h" | ||
|
||
|
||
namespace eckit::geo { | ||
class Grid; | ||
} // namespace eckit::geo | ||
|
||
|
||
namespace eckit::geo::triangulation { | ||
|
||
|
||
class Triangulation3 : public Triangulation { | ||
public: | ||
explicit Triangulation3(const Grid&); | ||
}; | ||
|
||
|
||
} // namespace eckit::geo::triangulation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters