From 0d784d3ee1cf786493a20055b4d32fea628ee6da Mon Sep 17 00:00:00 2001 From: Alexander Bruy Date: Wed, 23 Aug 2023 19:57:07 +0300 Subject: [PATCH] add an option to merge command to read input point cloud files from a text file. --- README.md | 8 +++++++- src/alg.hpp | 1 + src/merge.cpp | 20 +++++++++++++++++++- 3 files changed, 27 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9e27ad3..37a5f3d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ PDAL wrench has parallel processing built in and tries to run pipelines in paral so PDAL wrench can split the input into multiple tiles that can be processed independently in parallel - input dataset is a [virtual point cloud (VPC)](vpc-spec.md) - such datasets are composed of a number of files, so the whole work can be split into jobs where each parallel job processes one or more input files - + If the input is a single LAS/LAZ file, no parallelization is attempted. This may change in the future with introduction of more complex algorithms (where the cost of reading the input is much lower than the cost of the actual algorithm). # Commands @@ -113,6 +113,12 @@ Merges multiple point cloud files to a single one. pdal_wrench merge --output=merged.las data1.las data2.las data3.las ``` +Alternatively, it is possible to merge files whose paths are specified in a text file (one file per line) + +``` +pdal_wrench merge --output=merged.las --input-file-list=my_list.txt +``` + ## tile Creates tiles from input data. For example to get tiles sized 100x100: diff --git a/src/alg.hpp b/src/alg.hpp index e3e8a8b..20afd0f 100644 --- a/src/alg.hpp +++ b/src/alg.hpp @@ -206,6 +206,7 @@ struct Merge : public Alg // parameters from the user std::string outputFile; std::vector inputFiles; + std::string inputFileList; // args - initialized in addArgs() pdal::Arg* argOutput = nullptr; diff --git a/src/merge.cpp b/src/merge.cpp index 9502dbb..f715794 100644 --- a/src/merge.cpp +++ b/src/merge.cpp @@ -11,6 +11,7 @@ ****************************************************************************/ #include +#include #include #include @@ -36,6 +37,8 @@ void Merge::addArgs() argOutput = &programArgs.add("output,o", "Output virtual point cloud file", outputFile); // we set hasSingleInput=false so the default "input,i" argument is not added programArgs.add("files", "input files", inputFiles).setPositional(); + programArgs.add("input-file-list", "Read input files from a text file", inputFileList); + } bool Merge::checkArgs() @@ -108,6 +111,22 @@ static std::unique_ptr pipeline(ParallelJobInfo *tile) void Merge::preparePipelines(std::vector>& pipelines) { ParallelJobInfo tile(ParallelJobInfo::Single, BOX2D(), filterExpression, filterBounds); + if (!inputFileList.empty()) + { + std::ifstream inputFile(inputFileList); + std::string line; + if(!inputFile) + { + std::cerr << "failed to open input file list: " << inputFileList << std::endl; + return; + } + + while (std::getline(inputFile, line)) + { + inputFiles.push_back(line); + } + } + tile.inputFilenames = inputFiles; tile.outputFilename = outputFile; @@ -120,5 +139,4 @@ void Merge::preparePipelines(std::vector>& pipe QuickInfo qi = getQuickInfo(f); totalPoints += qi.m_pointCount; } - }