tiagodc / TreeLS

R functions for processing individual tree TLS point clouds
GNU General Public License v3.0
82 stars 27 forks source link

stemSegmentation fatal error #32

Open bbrede opened 3 years ago

bbrede commented 3 years ago

I have pre-segmented point clouds from an external algorithm and want to estimate DBH for each. Some of the single point clouds do not contain trees, but only bushes or branches, but I do not know which. So I want to use stemSegmentation in a loop (not interactively) iterating over the single point clouds. However, stemSegmentation is producing errors in a way that I cannot catch them with tryCatch, plus my R session is crashing.

Here a MWE to reproduce the fatal error:

library(TreeLS)

n_point <- 100 dat <- data.table(X = runif(n_point, 0, 10), Y = runif(n_point, 0, 10), Z = runif(n_point, 0, 10))

scale_factor <- 0.00025 header <- list('File Signature' = 'LASF', 'File Source ID' = 0, 'Global Encoding' = list('GPS Time Type' = FALSE, 'Waveform Data Packets Internal' = FALSE, 'Waveform Data Packets External' = FALSE, 'Synthetic Return Numbers' = FALSE, 'WKT' = TRUE, 'Aggregate Model' = FALSE), 'Project ID - GUID' = '00000000-0000-0000-0000-000000000000', 'Version Major' = 1, 'Version Minor' = 4, 'System Identifier' = 'GRS', 'Generating Software' = 'R', 'File Creation Year' = 2020, 'File Creation Day of Year' = 1, 'Point Data Format ID' = 0, 'Header Size' = 375,

'Offset to point data' = 1642,

           'X scale factor' = scale_factor,
           'Y scale factor' = scale_factor,
           'Z scale factor' = scale_factor,
           'X offset' = floor(min(dat$X)),
           'Y offset' = floor(min(dat$Y)),
           'Z offset' = floor(min(dat$Z)))

las <- LAS(dat, header = header, check = TRUE) %>% las_rescale(xscale = scale_factor, yscale = scale_factor, zscale = scale_factor) %>% las_reoffset(xoffset = header$X offset, yoffset = header$Y offset, zoffset = header$Z offset)

las = las %>% tlsNormalize()

las = stemPoints(las, stm.hough()) tryCatch({ sgt = stemSegmentation(las, sgt.ransac.circle(n=20)) })