Skip to content

Commit c9da9b7

Browse files
alexbruynyalldawson
authored andcommitted
update pdal_wrench to 1.1
1 parent 35e7f15 commit c9da9b7

File tree

4 files changed

+82
-5
lines changed

4 files changed

+82
-5
lines changed

external/pdal_wrench/alg.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ struct Merge : public Alg
206206
// parameters from the user
207207
std::string outputFile;
208208
std::vector<std::string> inputFiles;
209+
std::string inputFileList;
209210

210211
// args - initialized in addArgs()
211212
pdal::Arg* argOutput = nullptr;

external/pdal_wrench/merge.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
****************************************************************************/
1212

1313
#include <iostream>
14+
#include <fstream>
1415
#include <filesystem>
1516
#include <thread>
1617

@@ -36,6 +37,8 @@ void Merge::addArgs()
3637
argOutput = &programArgs.add("output,o", "Output virtual point cloud file", outputFile);
3738
// we set hasSingleInput=false so the default "input,i" argument is not added
3839
programArgs.add("files", "input files", inputFiles).setPositional();
40+
programArgs.add("input-file-list", "Read input files from a text file", inputFileList);
41+
3942
}
4043

4144
bool Merge::checkArgs()
@@ -108,6 +111,22 @@ static std::unique_ptr<PipelineManager> pipeline(ParallelJobInfo *tile)
108111
void Merge::preparePipelines(std::vector<std::unique_ptr<PipelineManager>>& pipelines)
109112
{
110113
ParallelJobInfo tile(ParallelJobInfo::Single, BOX2D(), filterExpression, filterBounds);
114+
if (!inputFileList.empty())
115+
{
116+
std::ifstream inputFile(inputFileList);
117+
std::string line;
118+
if(!inputFile)
119+
{
120+
std::cerr << "failed to open input file list: " << inputFileList << std::endl;
121+
return;
122+
}
123+
124+
while (std::getline(inputFile, line))
125+
{
126+
inputFiles.push_back(line);
127+
}
128+
}
129+
111130
tile.inputFilenames = inputFiles;
112131
tile.outputFilename = outputFile;
113132

@@ -120,5 +139,4 @@ void Merge::preparePipelines(std::vector<std::unique_ptr<PipelineManager>>& pipe
120139
QuickInfo qi = getQuickInfo(f);
121140
totalPoints += qi.m_pointCount;
122141
}
123-
124142
}

external/pdal_wrench/tile/tile.cpp

+19-1
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ struct BaseInfo
124124
int max_threads;
125125
std::string outputFormat; // las or laz (for now)
126126
bool buildVpc = false;
127+
std::string inputFileList; // file list with input files
127128
} opts;
128129

129130
pdal::BOX3D trueBounds;
@@ -434,6 +435,7 @@ void addArgs(pdal::ProgramArgs& programArgs, BaseInfo::Options& options, pdal::A
434435
{
435436
programArgs.add("output,o", "Output directory/filename", options.outputDir);
436437
programArgs.add("files,i", "Input files/directory", options.inputFiles).setPositional();
438+
programArgs.add("input-file-list", "Read input files from a text file", options.inputFileList);
437439
programArgs.add("length,l", "Tile length", options.tileLength, 1000.);
438440
tempArg = &(programArgs.add("temp_dir", "Temp directory", options.tempDir));
439441
programArgs.add("output-format", "Output format (las/laz)", options.outputFormat);
@@ -461,7 +463,7 @@ bool handleOptions(pdal::StringList& arglist, BaseInfo::Options& options)
461463
addArgs(programArgs, options, tempArg, threadsArg);
462464
try
463465
{
464-
programArgs.parse(arglist);
466+
programArgs.parseSimple(arglist);
465467
}
466468
catch (const pdal::arg_error& err)
467469
{
@@ -498,6 +500,22 @@ bool handleOptions(pdal::StringList& arglist, BaseInfo::Options& options)
498500
throw FatalError("Unknown output format: " + options.outputFormat);
499501
}
500502

503+
if (!options.inputFileList.empty())
504+
{
505+
std::ifstream inputFile(options.inputFileList);
506+
std::string line;
507+
if(!inputFile)
508+
{
509+
throw FatalError("Failed to open input file list: " + options.inputFileList);
510+
}
511+
512+
while (std::getline(inputFile, line))
513+
{
514+
options.inputFiles.push_back(line);
515+
}
516+
}
517+
518+
501519
return true;
502520
}
503521

external/pdal_wrench/vpc.cpp

+43-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
****************************************************************************/
1212

1313
#include <iostream>
14+
#include <fstream>
1415
#include <filesystem>
1516
#include <thread>
1617
namespace fs = std::filesystem;
@@ -25,7 +26,6 @@ namespace fs = std::filesystem;
2526
#include "nlohmann/json.hpp"
2627

2728

28-
2929
using json = nlohmann::json;
3030

3131
using namespace pdal;
@@ -368,8 +368,18 @@ std::string dateTimeStringFromYearAndDay(int year, int dayOfYear)
368368
{
369369
bool leapYear = isLeapYear(year);
370370

371-
if (year < 0) return ""; // Year is negative
372-
if ((dayOfYear < 1) || (dayOfYear > (leapYear ? 366 : 365))) return ""; // Day of year is out of range
371+
if (year < 0) // Year is negative
372+
{
373+
std::cerr << "Warning: year(" << year <<
374+
") is not valid. Defualting to 1970." << std::endl;
375+
year = 1970;
376+
}
377+
if ((dayOfYear < 1) || (dayOfYear > (leapYear ? 366 : 365)))
378+
{
379+
std::cerr << "Warning: DayOfYear(" << year <<
380+
") is out of range. Defualting to 1." << std::endl;
381+
dayOfYear = 1;
382+
}
373383

374384
// Figure out month and day of month, from day of year.
375385
int daysInMonth[] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
@@ -395,16 +405,20 @@ std::string dateTimeStringFromYearAndDay(int year, int dayOfYear)
395405
void buildVpc(std::vector<std::string> args)
396406
{
397407
std::string outputFile;
408+
std::string inputFileList;
398409
std::vector<std::string> inputFiles;
399410
bool boundaries = false;
400411
bool stats = false;
401412
bool overview = false;
402413
int max_threads = -1;
403414
bool verbose = false;
415+
bool help = false;
404416

405417
ProgramArgs programArgs;
418+
programArgs.add("help,h", "Output command help.", help);
406419
programArgs.add("output,o", "Output virtual point cloud file", outputFile);
407420
programArgs.add("files,f", "input files", inputFiles).setPositional();
421+
programArgs.add("input-file-list", "Read input files from a txt file, one file per line.", inputFileList);
408422
programArgs.add("boundary", "Calculate boundary polygons from data", boundaries);
409423
programArgs.add("stats", "Calculate statistics from data", stats);
410424
programArgs.add("overview", "Create overview point cloud from source data", overview);
@@ -422,6 +436,32 @@ void buildVpc(std::vector<std::string> args)
422436
return;
423437
}
424438

439+
if (help)
440+
{
441+
442+
std::cout << "usage: pdal_wrench build_vpc [<args>]" << std::endl;
443+
programArgs.dump(std::cerr, 2, Utils::screenWidth());
444+
return;
445+
}
446+
447+
if (!inputFileList.empty())
448+
{
449+
std::ifstream inputFile(inputFileList);
450+
std::string line;
451+
452+
if(!inputFile)
453+
{
454+
std::cerr << "failed to open input file list: " << inputFileList << std::endl;
455+
return;
456+
}
457+
458+
while (std::getline(inputFile, line))
459+
{
460+
inputFiles.push_back(line);
461+
}
462+
463+
}
464+
425465
// std::cout << "input " << inputFiles.size() << std::endl;
426466
// std::cout << "output " << outputFile << std::endl;
427467

0 commit comments

Comments
 (0)