Skip to content

Commit

Permalink
Improve handling of dimensions for LAS input (#158)
Browse files Browse the repository at this point in the history
* Rework preflight file-scanning.

* Add test for issue 155.

* Fix size calc.

* Use filesystem::path.

* More filesystem::path nonsense.

* Close files before we try to delete them cause Windows.
  • Loading branch information
abellgithub authored Feb 23, 2024
1 parent c19046b commit 255d30b
Show file tree
Hide file tree
Showing 9 changed files with 442 additions and 264 deletions.
453 changes: 249 additions & 204 deletions epf/Epf.cpp

Large diffs are not rendered by default.

18 changes: 15 additions & 3 deletions epf/Epf.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@
#include "../untwine/ProgressWriter.hpp"
#include "../untwine/ThreadPool.hpp"

namespace pdal
{
class LasReader;
class Stage;
}

namespace untwine
{

Expand All @@ -45,9 +51,15 @@ class Epf
void run(ProgressWriter& progress);

private:
PointCount createFileInfo(const StringList& input, StringList dimNames,
std::vector<FileInfo>& fileInfos);
void fillMetadata(const pdal::PointLayoutPtr layout);
void createFileInfos(const StringList& input, std::vector<FileInfo>& fileInfos);
void filterDims(std::vector<FileInfo>& infos, StringList allowedDims);
void determineDims(std::vector<FileInfo>& infos, pdal::PointLayout& layout);
void determineOffset(const std::vector<FileInfo>& infos);
pdal::SpatialReference determineSrs(const std::vector<FileInfo>& infos);
std::vector<FileInfo> processLas(pdal::LasReader& reader, FileInfo fi);
FileInfo processGeneric(pdal::Stage& reader, FileInfo fi);
void calcCreationDay();
void fillMetadata(const pdal::PointLayout& layout);

BaseInfo& m_b;
Grid m_grid;
Expand Down
2 changes: 2 additions & 0 deletions epf/EpfTypes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <pdal/SpatialReference.hpp>
#include <pdal/util/Bounds.hpp>

#include <array>
#include <cstdint>
#include <memory>
#include <unordered_map>
Expand Down Expand Up @@ -55,6 +56,7 @@ struct FileInfo
int untwineBitsOffset;
// Currently only set for LAS files.
int fileVersion;
std::array<double, 3> offsets {}; // X, Y, Z offsets

bool valid() const
{ return filename.size(); }
Expand Down
12 changes: 12 additions & 0 deletions lazperf/readers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ struct named_file::Private
Private(const std::string& filename) : f(filename, std::ios::binary)
{}

~Private()
{ close(); }

void close()
{ f.close(); }


std::ifstream f;
};

Expand Down Expand Up @@ -444,6 +451,11 @@ named_file::named_file(const std::string& filename) : p_(new Private(filename))
named_file::~named_file()
{}

void named_file::close()
{
p_->close();
}

// Chunk decompressor

struct chunk_decompressor::Private
Expand Down
3 changes: 3 additions & 0 deletions lazperf/readers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class basic_file
~basic_file();

bool open(std::istream& in);
void close();

public:
LAZPERF_EXPORT uint64_t pointCount() const;
Expand Down Expand Up @@ -85,6 +86,8 @@ class named_file : public basic_file
LAZPERF_EXPORT named_file(const std::string& filename);
LAZPERF_EXPORT ~named_file();

LAZPERF_EXPORT void close();

private:
std::unique_ptr<Private> p_;
};
Expand Down
24 changes: 19 additions & 5 deletions lazperf/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@
===============================================================================
FILE: util.hpp
CONTENTS:
Utility classes
PROGRAMMERS:
martin.isenburg@rapidlasso.com - http://rapidlasso.com
uday.karan@gmail.com - Hobu, Inc.
COPYRIGHT:
(c) 2007-2014, martin isenburg, rapidlasso - tools to catch reality
(c) 2014, Uday Verma, Hobu, Inc.
Expand All @@ -22,9 +22,9 @@
This software is distributed WITHOUT ANY WARRANTY and without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
CHANGE HISTORY:
===============================================================================
*/

Expand All @@ -38,6 +38,8 @@
#include <cstdlib>
#include <limits>

#include <lazperf/portable_endian.hpp>

#ifdef PRINT_DEBUG
#define LAZDEBUG(e) (void)(e)
#else
Expand Down Expand Up @@ -146,6 +148,18 @@ inline uint32_t unpack(const char *in)
(b1 & 0xFF));
}

template<>
inline float unpack(const char *in)
{
uint32_t u;
float f;

memcpy(&u, in, sizeof(u));
u = le32toh(u);
memcpy(&f, &u, sizeof(u));
return f;
}

inline void pack(const uint32_t v, char *out)
{
out[3] = (v >> 24) & 0xFF;
Expand Down
Loading

0 comments on commit 255d30b

Please sign in to comment.