Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fast aoi queries #2

Merged
merged 7 commits into from
Feb 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Package: rlas
Type: Package
Title: Read and Write 'las' and 'laz' Binary File Formats Used For Remote Sensing Data
Version: 1.1.0.900
Version: 1.1.0.9000
Date: 2016-12-23
Authors@R: c(
person("Jean-Romain", "Roussel", email = "jean-romain.roussel.1@ulaval.ca", role = c("aut", "cre", "cph")),
Expand Down
26 changes: 13 additions & 13 deletions R/readLAS.r
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@

#' Read data from a .las or .laz file
#'
#' Read data from .las or .laz files in format 1 to 4 according to LAS specifications and returns
#' Reads data from .las or .laz files in format 1 to 4 according to LAS specifications and returns
#' a \code{data.table} labeled according to LAS specifications. See the ASPRS documentation for the
#' \href{http://www.asprs.org/a/society/committees/standards/LAS_1_4_r13.pdf}{LAS file format}.
#' The optional logical parameters enable the user to save memory by choosing to load only the
#' The optional logical parameters enables the user to save memory by choosing to load only the
#' fields they need. Indeed, data is loaded into the computer's memory (RAM) suboptimally because
#' R does not accommodate many different data types. Moreover the function provides a streaming filter
#' to load only the points of interest into the memory never allocating any usless memory.
#' R does not accommodate many different data types. Moreover, the function provides a streaming filter
#' to load only the points of interest into the memory without allocating any superfluous memory.
#'
#' Because \code{rlas} rely on the well know \code{LASlib} library written by Martin Isenburg
#' to read the binary files, the package inherit also of filter commands avaible in
#' Because \code{rlas} relies on the well-known \code{LASlib} library written by Martin Isenburg
#' to read the binary files, the package also inherits the filter commands available in
#' \href{https://rapidlasso.com/lastools/}{LAStools}. To use these filters the user can pass the
#' common commands from \code{LAStools} into the parameter \code{'filter'}. Type \code{rlas:::lasfilterusage()} to
#' display the documentation of \code{LASlib} and the avaible filters.\cr\cr
#' The filter works in two passes. First it streams the file without loading anything and count
#' the number of points of interest. Then it allocates the necessary amount of memory and read the file
#' a second time and stores the point of interests into the computer's memory (RAM).
#' display the \code{LASlib} documentation and the available filters.\cr\cr
#' The filter works in two passes. First it streams the file without loading anything and counts
#' the number of points of interest. Then it allocates the necessary amount of memory and reads the file
#' a second time, and stores the points of interest in the computer's memory (RAM).
#'
#' @param file characters path to the .las or .laz file
#' @param file filepath character string to the .las or .laz file
#' @param Intensity logical. do you want to load the Intensity field? default: TRUE
#' @param ReturnNumber logical. do you want to load the ReturnNumber field? default: TRUE
#' @param NumberOfReturns logical. do you want to load the NumberOfReturns field? default: TRUE
Expand Down Expand Up @@ -105,11 +105,11 @@ readlasdata = function(file,

#' Read header from a .las or .laz file
#'
#' Read header from .las or .laz files in format 1 to 4 according to LAS specifications and returns
#' Reads header from .las or .laz files in format 1 to 4 according to LAS specifications and returns
#' a \code{list} labeled according to LAS specifications. See the ASPRS documentation for the
#' \href{http://www.asprs.org/a/society/committees/standards/LAS_1_4_r13.pdf}{LAS file format}.
#'
#' @param file characters path to the .las or .laz file
#' @param file filepath character string to the .las or .laz file
#' @family rlas
#' @return A \code{list}
#' @importFrom Rcpp sourceCpp
Expand Down
25 changes: 24 additions & 1 deletion src/LASlib/lasreader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

CHANGE HISTORY:

3 February 2017 -- by Florian de Boissieu -- L1798,1813 added parse_str because of strange problem with overloaded functions
Copy link
Collaborator

@Jean-Romain Jean-Romain Feb 3, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that there is a strange problem with overloaded functions. I'm ok with that. But why you needed a new function. There is no function to parse CHAR?

23 December 2016 -- by Jean-Romain Roussel -- L430,434 %lf -> %f (ISO C++98)
20 December 2016 -- by Jean-Romain Roussel -- Change fprint(stderr, ...), raise an exeption
20 December 2016 -- by Jean-Romain Roussel -- Comment L38-43, L698-941, L1167-1269, L1827-1850
Expand Down Expand Up @@ -1795,6 +1795,29 @@ BOOL LASreadOpener::parse(int argc, char* argv[])
return TRUE;
}

BOOL LASreadOpener::parse_str(CHAR* string)
{
int p = 0;
int argc = 1;
char* argv[64];
int len = strlen(string);

while (p < len)
{
while ((p < len) && (string[p] == ' ')) p++;
if (p < len)
{
argv[argc] = string + p;
argc++;
while ((p < len) && (string[p] != ' ')) p++;
string[p] = '\0';
p++;
}
}

return parse(argc, argv);
}

U32 LASreadOpener::get_file_name_number() const
{
return file_name_number;
Expand Down
2 changes: 2 additions & 0 deletions src/include/LASlib/lasreader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

CHANGE HISTORY:

3 February 2017 -- by Florian de Boissieu -- L198 added parse_str because of strange problem with overloaded functions
7 February 2014 -- added option '-apply_file_source_ID' when reading LAS/LAZ
22 August 2012 -- added the '-pipe_on' option for a multi-stage LAStools pipeline
11 August 2012 -- added on-the-fly buffered reading of LiDAR files (efficient with LAX)
Expand Down Expand Up @@ -194,6 +195,7 @@ class LASLIB_DLL LASreadOpener
void set_inside_circle(const F64 center_x, const F64 center_y, const F64 radius);
void set_inside_rectangle(const F64 min_x, const F64 min_y, const F64 max_x, const F64 max_y);
BOOL parse(int argc, char* argv[]);
BOOL parse_str(CHAR* string);
BOOL is_piped() const;
BOOL is_buffered() const;
BOOL is_header_populated() const;
Expand Down
8 changes: 2 additions & 6 deletions src/readLAS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ List lasdatareader(CharacterVector file, bool Intensity, bool ReturnNumber, bool
// Initialize las objects
LASreadOpener lasreadopener;
lasreadopener.set_file_name(filechar);
lasreadopener.parse_str(filterchar);
LASreader* lasreader = lasreadopener.open();
LASfilter lasfilter;

if(0 == lasreader || NULL == lasreader)
throw std::runtime_error("LASlib internal error. See message above.");
Expand All @@ -104,16 +104,14 @@ List lasdatareader(CharacterVector file, bool Intensity, bool ReturnNumber, bool
// First pass to read the whole file. Aims to know how much memory we must allocate
if(stream)
{
lasfilter.parse_string(filterchar);

npoints = 0;
while (lasreader->read_point())
{
if(!lasfilter.filter(&lasreader->point))
npoints++;
}

lasreader->seek(0);
lasreadopener.reopen(lasreader);
}

// Allocate the required amount of data only if necessary
Expand Down Expand Up @@ -142,8 +140,6 @@ List lasdatareader(CharacterVector file, bool Intensity, bool ReturnNumber, bool
unsigned long int i = 0;
while (lasreader->read_point())
{
if(stream && lasfilter.filter(&lasreader->point))
continue;

X[i] = lasreader->point.get_x();
Y[i] = lasreader->point.get_y();
Expand Down