|
1 | 1 | #include "DEMInterpolator.h"
|
2 | 2 |
|
3 |
| -#include <isce3/core/Constants.h> |
4 |
| -#include <isce3/io/Raster.h> |
5 |
| -#include <Eigen/Dense> |
| 3 | +#include <memory> |
| 4 | +#include <pybind11/eigen.h> |
6 | 5 | #include <stdexcept>
|
7 | 6 | #include <string>
|
8 | 7 |
|
| 8 | +#include <Eigen/Dense> |
| 9 | + |
| 10 | +#include <isce3/core/Constants.h> |
| 11 | +#include <isce3/io/Raster.h> |
| 12 | + |
9 | 13 | namespace py = pybind11;
|
10 | 14 |
|
11 |
| -using DI = isce3::geometry::DEMInterpolator; |
| 15 | +using DEMInterp = isce3::geometry::DEMInterpolator; |
12 | 16 |
|
13 |
| -void addbinding(pybind11::class_<DI> & pyDEMInterpolator) |
| 17 | +void addbinding(pybind11::class_<DEMInterp>& pyDEMInterpolator) |
14 | 18 | {
|
15 | 19 | pyDEMInterpolator
|
16 |
| - .def(py::init<double, isce3::core::dataInterpMethod, int>(), |
17 |
| - py::arg("height") = 0.0, |
18 |
| - py::arg("method") = isce3::core::BILINEAR_METHOD, |
19 |
| - py::arg("epsg") = 4326) |
20 |
| - // For convenience allow a string, too. |
21 |
| - .def(py::init([](double h, const std::string & method, int epsg) { |
| 20 | + .def(py::init<double, isce3::core::dataInterpMethod, int>(), |
| 21 | + py::arg("height") = 0.0, |
| 22 | + py::arg("method") = isce3::core::BILINEAR_METHOD, |
| 23 | + py::arg("epsg") = 4326) |
| 24 | + // For convenience allow a string, too. |
| 25 | + .def(py::init([](double h, const std::string& method, int epsg) { |
22 | 26 | auto m = parseDataInterpMethod(method);
|
23 |
| - return new DI(h, m, epsg); |
| 27 | + return DEMInterp(h, m, epsg); |
| 28 | + }), |
| 29 | + py::arg("height") = 0.0, py::arg("method") = "bilinear", |
| 30 | + py::arg("epsg") = 4326) |
| 31 | + |
| 32 | + // This constructor is similar to method "loadDEM" but is more |
| 33 | + // convenient! |
| 34 | + .def(py::init([](isce3::io::Raster& raster_obj) { |
| 35 | + DEMInterp dem {}; |
| 36 | + dem.loadDEM(raster_obj); |
| 37 | + return dem; |
24 | 38 | }),
|
25 |
| - py::arg("height") = 0.0, |
26 |
| - py::arg("method") = "bilinear", |
27 |
| - py::arg("epsg") = 4326) |
| 39 | + "Construct DEM from ISCE3 Raster object", |
| 40 | + py::arg("raster_obj")) |
28 | 41 |
|
29 |
| - .def("load_dem", |
30 |
| - py::overload_cast<isce3::io::Raster&>(&DI::loadDEM)) |
31 |
| - .def("load_dem", |
32 |
| - py::overload_cast<isce3::io::Raster&, double, double, double, double> |
33 |
| - (&DI::loadDEM), |
34 |
| - py::arg("raster"), py::arg("min_x"), py::arg("max_x"), |
35 |
| - py::arg("min_y"), py::arg("max_y")) |
| 42 | + .def("load_dem", |
| 43 | + py::overload_cast<isce3::io::Raster&>(&DEMInterp::loadDEM)) |
| 44 | + .def("load_dem", |
| 45 | + py::overload_cast<isce3::io::Raster&, double, double, |
| 46 | + double, double>(&DEMInterp::loadDEM), |
| 47 | + py::arg("raster"), py::arg("min_x"), py::arg("max_x"), |
| 48 | + py::arg("min_y"), py::arg("max_y")) |
36 | 49 |
|
37 |
| - .def("interpolate_lonlat", &DI::interpolateLonLat) |
38 |
| - .def("interpolate_xy", &DI::interpolateXY) |
| 50 | + .def("interpolate_lonlat", &DEMInterp::interpolateLonLat) |
| 51 | + .def("interpolate_xy", &DEMInterp::interpolateXY) |
39 | 52 |
|
40 |
| - .def_property("ref_height", |
41 |
| - py::overload_cast<>(&DI::refHeight, py::const_), |
42 |
| - py::overload_cast<double>(&DI::refHeight)) |
43 |
| - .def_property_readonly("have_raster", &DI::haveRaster) |
44 |
| - .def_property("interp_method", |
45 |
| - py::overload_cast<>(&DI::interpMethod, py::const_), |
46 |
| - py::overload_cast<isce3::core::dataInterpMethod>(&DI::interpMethod)) |
| 53 | + .def_property("ref_height", |
| 54 | + py::overload_cast<>(&DEMInterp::refHeight, py::const_), |
| 55 | + py::overload_cast<double>(&DEMInterp::refHeight)) |
| 56 | + .def_property_readonly("have_raster", &DEMInterp::haveRaster) |
| 57 | + .def_property("interp_method", |
| 58 | + py::overload_cast<>(&DEMInterp::interpMethod, py::const_), |
| 59 | + py::overload_cast<isce3::core::dataInterpMethod>( |
| 60 | + &DEMInterp::interpMethod)) |
47 | 61 |
|
48 |
| - // Define all these as readonly even though writable in C++ API. |
49 |
| - // Probably better to just convert your data to a GDAL format than try |
50 |
| - // to build a DEM on the fly. |
51 |
| - .def_property_readonly("data", [](DI & self) { // .data() isn't const |
52 |
| - if (!self.haveRaster()) { |
53 |
| - throw std::out_of_range("Tried to access DEM data but size=0"); |
54 |
| - } |
55 |
| - using namespace Eigen; |
56 |
| - using MatF = Eigen::Matrix<float, Dynamic, Dynamic, RowMajor>; |
57 |
| - Map<const MatF> mat(self.data(), self.length(), self.width()); |
58 |
| - return mat; |
59 |
| - }, py::return_value_policy::reference_internal) |
60 |
| - .def_property_readonly("x_start", py::overload_cast<>(&DI::xStart, py::const_)) |
61 |
| - .def_property_readonly("y_start", py::overload_cast<>(&DI::yStart, py::const_)) |
62 |
| - .def_property_readonly("delta_x", py::overload_cast<>(&DI::deltaX, py::const_)) |
63 |
| - .def_property_readonly("delta_y", py::overload_cast<>(&DI::deltaY, py::const_)) |
64 |
| - .def_property_readonly("width", py::overload_cast<>(&DI::width, py::const_)) |
65 |
| - .def_property_readonly("length", py::overload_cast<>(&DI::length, py::const_)) |
66 |
| - .def_property_readonly("epsg_code", py::overload_cast<>(&DI::epsgCode, py::const_)) |
67 |
| - ; |
| 62 | + // Define all these as readonly even though writable in C++ API. |
| 63 | + // Probably better to just convert your data to a GDAL format than |
| 64 | + // try to build a DEM on the fly. |
| 65 | + .def_property_readonly( |
| 66 | + "data", |
| 67 | + [](DEMInterp& self) { // .data() isn't const |
| 68 | + if (!self.haveRaster()) { |
| 69 | + throw std::out_of_range( |
| 70 | + "Tried to access DEM data but size=0"); |
| 71 | + } |
| 72 | + using namespace Eigen; |
| 73 | + using MatF = Eigen::Matrix<float, Dynamic, Dynamic, |
| 74 | + RowMajor>; |
| 75 | + Map<const MatF> mat( |
| 76 | + self.data(), self.length(), self.width()); |
| 77 | + return mat; |
| 78 | + }, |
| 79 | + py::return_value_policy::reference_internal) |
| 80 | + .def_property_readonly("x_start", |
| 81 | + py::overload_cast<>(&DEMInterp::xStart, py::const_)) |
| 82 | + .def_property_readonly("y_start", |
| 83 | + py::overload_cast<>(&DEMInterp::yStart, py::const_)) |
| 84 | + .def_property_readonly("delta_x", |
| 85 | + py::overload_cast<>(&DEMInterp::deltaX, py::const_)) |
| 86 | + .def_property_readonly("delta_y", |
| 87 | + py::overload_cast<>(&DEMInterp::deltaY, py::const_)) |
| 88 | + .def_property_readonly( |
| 89 | + "width", py::overload_cast<>(&DEMInterp::width, py::const_)) |
| 90 | + .def_property_readonly("length", |
| 91 | + py::overload_cast<>(&DEMInterp::length, py::const_)) |
| 92 | + .def_property_readonly("epsg_code", |
| 93 | + py::overload_cast<>(&DEMInterp::epsgCode, py::const_)); |
68 | 94 | }
|
0 commit comments