ACloudViewer  3.9.4
A Modern Library for 3D Data Processing
ccRasterGrid.cpp
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // - CloudViewer: www.cloudViewer.org -
3 // ----------------------------------------------------------------------------
4 // Copyright (c) 2018-2024 www.cloudViewer.org
5 // SPDX-License-Identifier: MIT
6 // ----------------------------------------------------------------------------
7 
8 #include <pybind11/pybind11.h>
9 #include <pybind11/stl.h>
10 #include <pybind11/stl_bind.h>
11 
12 #include <ecvPointCloud.h>
13 #include <ecvProgressDialog.h>
14 #include <ecvRasterGrid.h>
15 
16 #include "../casters.h"
17 
18 namespace py = pybind11;
19 using namespace pybind11::literals;
20 
21 void define_ccRasterGrid(py::module &m)
22 {
23  py::class_<ccRasterCell>(m, "ccRasterCell")
24  .def(py::init<>())
25  .def_readwrite("h", &ccRasterCell::h)
26  .def_readwrite("minHeight", &ccRasterCell::minHeight)
27  .def_readwrite("maxHeight", &ccRasterCell::maxHeight)
28  .def_readwrite("nbPoints", &ccRasterCell::nbPoints)
29  .def_readwrite("nearestPointIndex", &ccRasterCell::pointIndex)
30  .def_readwrite("color", &ccRasterCell::color);
31 
32  py::class_<ccRasterGrid> PyRasterGrid(m, "ccRasterGrid");
33 
34  py::enum_<ccRasterGrid::ExportableFields>(PyRasterGrid, "ExportableFields")
35  .value("PER_CELL_VALUE", ccRasterGrid::ExportableFields::PER_CELL_VALUE)
36  .value("PER_CELL_COUNT", ccRasterGrid::ExportableFields::PER_CELL_COUNT)
37  .value("PER_CELL_MIN_VALUE", ccRasterGrid::ExportableFields::PER_CELL_MIN_VALUE)
38  .value("PER_CELL_MAX_VALUE", ccRasterGrid::ExportableFields::PER_CELL_MAX_VALUE)
39  .value("PER_CELL_AVG_VALUE", ccRasterGrid::ExportableFields::PER_CELL_AVG_VALUE)
40  .value("PER_CELL_VALUE_STD_DEV", ccRasterGrid::ExportableFields::PER_CELL_VALUE_STD_DEV)
41  .value("PER_CELL_VALUE_RANGE", ccRasterGrid::ExportableFields::PER_CELL_VALUE_RANGE)
42  .value("PER_CELL_MEDIAN_VALUE", ccRasterGrid::ExportableFields::PER_CELL_MEDIAN_VALUE)
43  .value("PER_CELL_PERCENTILE_VALUE",
44  ccRasterGrid::ExportableFields::PER_CELL_PERCENTILE_VALUE)
45  .value("PER_CELL_UNIQUE_COUNT_VALUE",
46  ccRasterGrid::ExportableFields::PER_CELL_UNIQUE_COUNT_VALUE)
47  .value("PER_CELL_INVALID", ccRasterGrid::ExportableFields::PER_CELL_INVALID)
48  .export_values();
49 
50  py::enum_<ccRasterGrid::ProjectionType>(PyRasterGrid, "ProjectionType")
51  .value("PROJ_MINIMUM_VALUE", ccRasterGrid::ProjectionType::PROJ_MINIMUM_VALUE)
52  .value("PROJ_AVERAGE_VALUE", ccRasterGrid::ProjectionType::PROJ_AVERAGE_VALUE)
53  .value("PROJ_MAXIMUM_VALUE", ccRasterGrid::ProjectionType::PROJ_MAXIMUM_VALUE)
54  .value("PROJ_MEDIAN_VALUE", ccRasterGrid::ProjectionType::PROJ_MEDIAN_VALUE)
55  .value("PROJ_INVERSE_VAR_VALUE", ccRasterGrid::ProjectionType::PROJ_INVERSE_VAR_VALUE)
56  .value("INVALID_PROJECTION_TYPE", ccRasterGrid::ProjectionType::INVALID_PROJECTION_TYPE)
57  .export_values();
58 
59  py::enum_<ccRasterGrid::EmptyCellFillOption>(PyRasterGrid, "EmptyCellFillOption")
60  .value("LEAVE_EMPTY", ccRasterGrid::EmptyCellFillOption::LEAVE_EMPTY)
61  .value("FILL_MINIMUM_HEIGHT", ccRasterGrid::EmptyCellFillOption::FILL_MINIMUM_HEIGHT)
62  .value("FILL_MAXIMUM_HEIGHT", ccRasterGrid::EmptyCellFillOption::FILL_MAXIMUM_HEIGHT)
63  .value("FILL_CUSTOM_HEIGHT", ccRasterGrid::EmptyCellFillOption::FILL_CUSTOM_HEIGHT)
64  .value("FILL_AVERAGE_HEIGHT", ccRasterGrid::EmptyCellFillOption::FILL_AVERAGE_HEIGHT)
65  .value("INTERPOLATE_DELAUNAY", ccRasterGrid::EmptyCellFillOption::INTERPOLATE_DELAUNAY)
66  .export_values();
67 
68  PyRasterGrid.def(py::init<>())
69  .def_static("ComputeGridSize",
71  "Z"_a,
72  "box"_a,
73  "gridStep"_a,
74  "width"_a,
75  "height"_a)
76  .def("init", &ccRasterGrid::ComputeGridSize, "w"_a, "h"_a, "gridStep"_a, "minCorner"_a)
77  .def("reset", &ccRasterGrid::reset)
78  .def_static("GetDefaultFieldName", &ccRasterGrid::GetDefaultFieldName, "field"_a)
79  .def("convertToCloud",
81  "exportedFields"_a,
82  "interpolateSF"_a,
83  "interpolateColors"_a,
84  "resampleInputCloudXY"_a,
85  "resampleInputCloudZ"_a,
86  "inputCloud"_a,
87  "Z"_a,
88  "box"_a,
89  "fillEmptyCells"_a,
90  "emptyCellsHeight"_a,
91  "exportToOriginalCS"_a)
92  .def("fillWith",
94  "cloud"_a,
95  "projectionDimension"_a,
96  "projectionType"_a,
97  "interpolateEmptyCells"_a,
98  "sfInterpolation"_a = ccRasterGrid::ProjectionType::INVALID_PROJECTION_TYPE,
99  "progressDialog"_a = nullptr)
100  .def("fillEmptyCells",
102  "projectionDimension"_a,
103  "customCellHeight"_a = 0)
104  .def("updateNonEmptyCellCount", &ccRasterGrid::updateNonEmptyCellCount)
105  .def("updateCellStats", &ccRasterGrid::updateCellStats)
106  .def("setValid", &ccRasterGrid::setValid, "state"_a)
107  .def("isValid", &ccRasterGrid::isValid)
108  .def("computeCellPos", &ccRasterGrid::computeCellPos, "P"_a, "X"_a, "Y"_a)
109  .def("computeCellCenter", &ccRasterGrid::computeCellCenter, "i"_a, "j"_a, "X"_a, "Y"_a)
110  // TODO rows
111  // todo scalarfields
112  .def_readwrite("width", &ccRasterGrid::width)
113  .def_readwrite("height", &ccRasterGrid::height)
114  .def_readwrite("gridStep", &ccRasterGrid::gridStep)
115  .def_readwrite("minCorner", &ccRasterGrid::minCorner)
116  .def_readwrite("minHeight", &ccRasterGrid::minHeight)
117  .def_readwrite("maxHeight", &ccRasterGrid::maxHeight)
118  .def_readwrite("meanHeight", &ccRasterGrid::meanHeight)
119  .def_readwrite("nonEmptyCellCount", &ccRasterGrid::nonEmptyCellCount)
120  .def_readwrite("validCellCount", &ccRasterGrid::validCellCount)
121  .def_readwrite("hasColors", &ccRasterGrid::hasColors)
122  .def_readwrite("valid", &ccRasterGrid::valid);
123 }
void define_ccRasterGrid(py::module &m)
CCVector3d color
Color.
Definition: ecvRasterGrid.h:49
double h
Height value.
Definition: ecvRasterGrid.h:35
unsigned nbPoints
Number of points projected in this cell.
Definition: ecvRasterGrid.h:45
unsigned pointIndex
Nearest point index (if any)
Definition: ecvRasterGrid.h:47
PointCoordinateType maxHeight
Max height value.
Definition: ecvRasterGrid.h:43
PointCoordinateType minHeight
Min height value.
Definition: ecvRasterGrid.h:41
void updateCellStats()
Updates the statistics about the cells.
CCVector2d computeCellCenter(int i, int j, unsigned char X, unsigned char Y) const
Computes the position of the center of a given cell.
unsigned validCellCount
Number of VALID cells.
unsigned nonEmptyCellCount
Number of NON-EMPTY cells.
void setValid(bool state)
Sets valid.
double gridStep
Grid step ('pixel' size)
unsigned height
Number of rows.
bool hasColors
Whether the (average) colors are available or not.
double meanHeight
Average height (computed on the NON-EMPTY or INTERPOLATED cells)
bool fillWith(ccGenericPointCloud *cloud, unsigned char projectionDimension, ProjectionType projectionType, bool interpolateEmptyCells, ProjectionType sfInterpolation=INVALID_PROJECTION_TYPE, ecvProgressDialog *progressDialog=nullptr)
Fills the grid with a point cloud.
CCVector3d minCorner
Min corner (3D)
static QString GetDefaultFieldName(ExportableFields field)
Returns the default name of a given field.
void reset()
Resets the grid.
std::pair< int, int > computeCellPos(const CCVector3 &P, unsigned char X, unsigned char Y) const
Computes the position of the cell that includes a given point.
static bool ComputeGridSize(unsigned char Z, const ccBBox &box, double gridStep, unsigned &width, unsigned &height)
Computes the raster size for a given bounding-box.
double maxHeight
Max height (computed on the NON-EMPTY or INTERPOLATED cells)
unsigned updateNonEmptyCellCount()
Updates the number of non-empty cells.
ccPointCloud * convertToCloud(const std::vector< ExportableFields > &exportedFields, bool interpolateSF, bool interpolateColors, bool resampleInputCloudXY, bool resampleInputCloudZ, ccGenericPointCloud *inputCloud, unsigned char Z, const ccBBox &box, bool fillEmptyCells, double emptyCellsHeight, bool exportToOriginalCS) const
Converts the grid to a cloud with scalar field(s)
bool isValid() const
Returns whether the grid is 'valid' or not.
unsigned width
Number of columns.
bool valid
Whether the grid is valid/up-to-date.
double minHeight
Min height (computed on the NON-EMPTY or INTERPOLATED cells)
void fillEmptyCells(EmptyCellFillOption fillEmptyCellsStrategy, double customCellHeight=0)
Fills the empty cell (for all strategies but 'INTERPOLATE_DELAUNAY')