17#include <geos/operation/grid/Grid.h>
18#include <geos/operation/grid/Matrix.h>
27 class PointOnGeometryLocator;
30namespace geos::operation::grid {
39struct fill_values<float>
41 static constexpr float EXTERIOR{ 0.0f };
42 static constexpr float INTERIOR{ 1.0f };
43 static constexpr float FILLABLE{ -1.0f };
45 static constexpr float UNKNOWN{ -2.0f };
54 FloodFill(
const geom::Geometry& g,
const Grid<bounded_extent>& extent);
59 void flood(Matrix<T>& arr)
const;
61 bool cellIsInside(
size_t i,
size_t j)
const;
64 Grid<bounded_extent> m_extent;
65 const geom::Geometry& m_g;
66 std::unique_ptr<algorithm::locate::PointOnGeometryLocator> m_loc;
71floodFromPixel(Matrix<T>& arr,
size_t i,
size_t j, T fill_value)
73 std::queue<std::pair<size_t, size_t>> locations;
75 locations.emplace(i, j);
77 while (!locations.empty()) {
78 i = locations.front().first;
79 j = locations.front().second;
82 if (arr(i, j) == fill_value) {
87 if (j > 0 && arr(i, j - 1) == fill_values<T>::FILLABLE) {
88 locations.emplace(i, j - 1);
94 for (; j < arr.getNumCols() && arr(i, j) == fill_values<T>::FILLABLE; j++) {
95 arr(i, j) = fill_value;
102 for (j = j0; j < j1; j++) {
104 if (arr(i - 1, j) == fill_values<T>::FILLABLE) {
105 locations.emplace(i - 1, j);
111 if (i < arr.getNumRows() - 1) {
112 for (j = j0; j < j1; j++) {
114 if (arr(i + 1, j) == fill_values<T>::FILLABLE) {
115 locations.emplace(i + 1, j);
124FloodFill::flood(Matrix<T>& arr)
const
127 for (
size_t i = 0; i < arr.getNumRows(); i++) {
128 for (
size_t j = 0; j < arr.getNumCols(); j++) {
129 if (arr(i, j) == fill_values<T>::UNKNOWN) {
130 throw std::runtime_error(
"Cell with unknown position encountered.");
131 }
else if (arr(i, j) == fill_values<T>::FILLABLE) {
134 if (cellIsInside(i, j)) {
135 floodFromPixel(arr, i, j, fill_values<T>::INTERIOR);
137 floodFromPixel(arr, i, j, fill_values<T>::EXTERIOR);
Classes which determine the Location of points in geometries.
Definition IndexedPointInAreaLocator.h:40