Skip to content
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
27 changes: 21 additions & 6 deletions entwine/util/info.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,12 +268,22 @@ bool areStemsUnique(const SourceList& sources)
return true;
}

SourceInfo analyzeOne(const std::string path, const bool deep, json pipeline)
SourceInfo analyzeOne(
const std::string path,
const bool deep,
json pipeline,
const uint64_t pointCount)
{
try
{
pipeline.at(0)["filename"] = path;
return deep ? getDeepInfo(pipeline) : getShallowInfo(pipeline);
SourceInfo info = deep
? getDeepInfo(pipeline)
: getShallowInfo(pipeline);

if (!info.points && pointCount) info.points = pointCount;

return info;
}
catch (const std::exception& e)
{
Expand Down Expand Up @@ -324,15 +334,17 @@ std::string toLower(std::string s)
return s;
}

arbiter::LocalHandle localize(
MaybePointlessFile localize(
const std::string path,
const bool deep,
const std::string tmp,
const arbiter::Arbiter& a)
{
const std::string extension = toLower(arbiter::getExtension(path));
const bool isLas = extension == "las" || extension == "laz";
if (deep || a.isLocal(path) || !isLas) return a.getLocalHandle(path, tmp);
if (deep || a.isLocal(path) || !isLas) {
return MaybePointlessFile { a.getLocalHandle(path, tmp) };
}
return getPointlessLasFile(path, tmp, a);
}

Expand Down Expand Up @@ -372,11 +384,14 @@ SourceList analyze(
{
pool.add([&]()
{
const auto handle(localize(source.path, deep, tmp, a));
const auto file(localize(source.path, deep, tmp, a));
const auto handle = file.handle;
const auto pointCount = file.pointCount;
source.info = analyzeOne(
handle.localPath(),
deep,
pipelineTemplate);
pipelineTemplate,
pointCount);
});
}
}
Expand Down
10 changes: 8 additions & 2 deletions entwine/util/info.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@
#include <entwine/third/arbiter/arbiter.hpp>
#include <entwine/types/reprojection.hpp>
#include <entwine/types/source.hpp>
#include <entwine/util/io.hpp>
#include <entwine/util/json.hpp>
#include <entwine/util/optional.hpp>

namespace entwine
{

arbiter::LocalHandle localize(
MaybePointlessFile localize(
std::string path,
bool deep,
std::string tmp,
const arbiter::Arbiter& a);

SourceInfo analyzeOne(std::string path, bool deep, json pipelineTemplate);
SourceInfo analyzeOne(
std::string path,
bool deep,
json pipelineTemplate,
uint64_t pointCount = 0);

Source parseOne(std::string path, const arbiter::Arbiter& a = { });

SourceList analyze(
Expand Down
23 changes: 21 additions & 2 deletions entwine/util/io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ arbiter::LocalHandle ensureGetLocalHandle(
throw std::runtime_error("Failed to get " + path);
}

arbiter::LocalHandle getPointlessLasFile(
MaybePointlessFile getPointlessLasFile(
const std::string& path,
const std::string& tmp,
const arbiter::Arbiter& a)
Expand All @@ -201,13 +201,17 @@ arbiter::LocalHandle getPointlessLasFile(
const uint64_t minorVersionPos(25);
const uint64_t headerSizePos(94);
const uint64_t pointOffsetPos(96);
const uint64_t legacyPointCountPos(107);
const uint64_t pointCountPos(247);
const uint64_t evlrOffsetPos(235);
const uint64_t evlrNumberPos(evlrOffsetPos + 8);

std::string fileSignature;
uint8_t minorVersion(0);
uint16_t headerSize(0);
uint32_t pointOffset(0);
uint32_t legacyPointCount(0);
uint64_t pointCount(0);
uint64_t evlrOffset(0);
uint32_t evlrNumber(0);

Expand Down Expand Up @@ -238,6 +242,14 @@ arbiter::LocalHandle getPointlessLasFile(
is.seek(pointOffsetPos);
is >> pointOffset;

// Grab the legacy point count, then set its value in the header to zero.
is.seek(legacyPointCountPos);
is >> legacyPointCount;
pointCount = legacyPointCount;

os.seek(legacyPointCountPos);
os << static_cast<uint32_t>(0);

if (minorVersion >= 4)
{
is.seek(evlrOffsetPos);
Expand All @@ -250,6 +262,10 @@ arbiter::LocalHandle getPointlessLasFile(
// removing the point data itself.
os.seek(evlrOffsetPos);
os << pointOffset;

// And zero out the non-legacy point count.
os.seek(pointCountPos);
os << static_cast<uint64_t>(0);
}

// Extract the modified header, VLRs, and append the EVLRs.
Expand Down Expand Up @@ -279,6 +295,9 @@ arbiter::LocalHandle getPointlessLasFile(

const std::string outputPath = arbiter::join(tmp, basename);
a.put(outputPath, data);
return arbiter::LocalHandle(outputPath, true);
return MaybePointlessFile {
arbiter::LocalHandle(outputPath, true),
pointCount
};
}
} // namespace entwine
8 changes: 7 additions & 1 deletion entwine/util/io.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#pragma once

#include <cstdint>
#include <stdexcept>
#include <string>
#include <vector>
Expand Down Expand Up @@ -76,7 +77,12 @@ arbiter::LocalHandle ensureGetLocalHandle(
const std::string& path,
int tries = defaultTries);

arbiter::LocalHandle getPointlessLasFile(
struct MaybePointlessFile
{
arbiter::LocalHandle handle;
uint64_t pointCount = 0;
};
MaybePointlessFile getPointlessLasFile(
const std::string& path,
const std::string& tmp,
const arbiter::Arbiter& a);
Expand Down
Loading