Skip to content

Commit

Permalink
Fix #732
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-Romain committed Nov 22, 2023
1 parent 6d9e64e commit 3bf2bf0
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 24 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ If you are viewing this file on CRAN, please check [the latest news on GitHub](h
## lidR v4.0.5 (Release date: )

- Fix: [#726](https://github.com/r-lidar/lidR/issues/726) character palette causes error in plot.
- Fix: [#732](https://github.com/r-lidar/lidR/issues/732) octree spatial indexes is not working properly. lidR now use voxel partition and no longer support octree until the problem is fixed.

## lidR v4.0.4 (Release date: 2023-09-07)

Expand Down
4 changes: 2 additions & 2 deletions inst/include/SpatialIndex.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ inline SpatialIndex::SpatialIndex(const Rcpp::S4 las)
case GRIDPARTITION:
case VOXELPARTITION: grid = GridPartition(las); break;
case QUADTREE: quadtree = QuadTree(las); break;
case OCTREE: octree = Octree(las); break;
case OCTREE: Rcpp::stop("Error: octree no longer supported."); break; // # nocov
default: Rcpp::stop("Internal error: spatial index code inccorect."); break; // # nocov
}
}
Expand Down Expand Up @@ -186,7 +186,7 @@ inline int SpatialIndex::index_selector(const Rcpp::S4 las) const
if (sensor == UKN || sensor == ALS)
code = GRIDPARTITION;
else if (sensor == TLS || sensor == UAV || sensor == DAP)
code = OCTREE;
code = VOXELPARTITION;
else
code = QUADTREE;
}
Expand Down
11 changes: 9 additions & 2 deletions inst/include/lidR/GridPartition.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,15 @@ template<typename T> void GridPartition::lookup(T& shape, std::vector<PointXYZ>&
int colmax = std::ceil((xmax - this->xmin) / xres);
int rowmin = std::floor((this->ymax - ymax) / yres);
int rowmax = std::ceil((this->ymax - ymin) / yres);
int laymin = std::floor((zmin - this->zmin) / zres);
int laymax = std::ceil((zmax - this->zmin) / zres);

int laymin = 0;
int laymax = nlayers;
if (zmin > this->zmin && zmax < this->zmax)
{
laymin = std::floor((zmin - this->zmin) / zres);
laymax = std::ceil((zmax - this->zmin) / zres);
}

int cell;

res.clear();
Expand Down
10 changes: 8 additions & 2 deletions inst/include/lidR/Octree.h
Original file line number Diff line number Diff line change
Expand Up @@ -390,8 +390,14 @@ template<typename T> Node::Ocnode* Octree::locate_region(T shape)
double bbxmax = (shape.xmax - xmin)/(xmax-xmin);
double bbymin = (shape.ymin - ymin)/(ymax-ymin);
double bbymax = (shape.ymax - ymin)/(ymax-ymin);
double bbzmin = (shape.zmin - zmin)/(zmax-zmin);
double bbzmax = (shape.zmax - zmin)/(zmax-zmin);

double bbzmin = 0;
double bbzmax = 1;
if (shape.zmin > this->zmin && shape.zmax < this->zmax)
{
bbzmin = (shape.zmin - zmin)/(zmax-zmin);
bbzmax = (shape.zmax - zmin)/(zmax-zmin);
}

if (bbxmax < 0 || bbxmin > 1 || bbymax < 0 || bbymin > 1 || bbzmax < 0 || bbzmin > 1)
return 0;
Expand Down
36 changes: 18 additions & 18 deletions tests/testthat/test-spatialindex.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ las = LAS(D)

test_that("circle lookup works for each spatial index", {

for(index in 0:4)
for(index in 0:3)
{
index(las) <- index

Expand All @@ -183,7 +183,7 @@ test_that("circle lookup works for each spatial index", {

test_that("oriented rectangle lookup works for each spatial index", {

for(index in 0:4)
for(index in 0:3)
{
index(las) <- index

Expand All @@ -202,7 +202,7 @@ test_that("oriented rectangle lookup works for each spatial index", {

test_that("knn in 2d works for each spatial indexes", {

for(index in 0:4)
for(index in 0:3)
{
index(las) <- index

Expand All @@ -219,7 +219,7 @@ test_that("knn in 2d works for each spatial indexes", {

test_that("knn in 3d works for each spatial indexes", {

for(index in 0:4)
for(index in 0:3)
{
index(las) <- index

Expand Down Expand Up @@ -248,8 +248,8 @@ test_that("Spatial indexes work with more points (coverage)", {
y = runif(1, 10, 900)
z = runif(1, 1, 19)

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_knn3d_lookup(las, x,y,z,10)
Expand All @@ -258,8 +258,8 @@ test_that("Spatial indexes work with more points (coverage)", {

expect_true(all(sapply(u, identical, u[[1]])))

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_circle_lookup(las, x, y, 5)
Expand All @@ -278,8 +278,8 @@ test_that("Spatial indexes work with 0 point", {
y = runif(1, 10, 900)
z = runif(1, 1, 19)

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_knn3d_lookup(las, x, y, z,10)
Expand All @@ -288,8 +288,8 @@ test_that("Spatial indexes work with 0 point", {

expect_true(all(sapply(u, identical, integer(0))))

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_circle_lookup(las, x, y, 5)
Expand All @@ -308,8 +308,8 @@ test_that("Spatial indexes work with 1 point", {
y = runif(1, 10, 11)
z = runif(1, 1, 19)

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_knn3d_lookup(las, x, y, z, 10)
Expand All @@ -318,8 +318,8 @@ test_that("Spatial indexes work with 1 point", {

expect_true(all(sapply(u, identical, 1L)))

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_circle_lookup(las, x, y, 5)
Expand All @@ -338,8 +338,8 @@ test_that("Spatial indexes work no point to find", {
y = -100
z = 0

u = vector("list", 4)
for(index in 0:4)
u = vector("list", 3)
for(index in 0:3)
{
index(las) <- index
id = lidR:::C_circle_lookup(las, x, y, 5)
Expand Down

0 comments on commit 3bf2bf0

Please sign in to comment.