Skip to content

Commit

Permalink
Pull untwine 1.4.0 from upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
uclaros committed Oct 21, 2024
1 parent 756083c commit 74a09f8
Show file tree
Hide file tree
Showing 33 changed files with 558 additions and 361 deletions.
2 changes: 1 addition & 1 deletion external/untwine/api/QgisUntwine_win.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ bool QgisUntwine::start(Options& options)
cmdline += "--" + op.first + " \"" + op.second + "\" ";

PROCESS_INFORMATION processInfo;
STARTUPINFOA startupInfo;
STARTUPINFO startupInfo;

ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
ZeroMemory(&startupInfo, sizeof(STARTUPINFO));
Expand Down
4 changes: 3 additions & 1 deletion external/untwine/bu/BuPyramid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
#include "../untwine/Common.hpp"
#include "../untwine/ProgressWriter.hpp"

#include <dirlist.hpp> //untwine/os

namespace untwine
{
namespace bu
Expand Down Expand Up @@ -53,7 +55,7 @@ void BuPyramid::getInputFiles()
return std::make_pair(true, VoxelKey(x, y, z, level));
};

std::vector<std::string> files = directoryList(m_b.opts.tempDir);
std::vector<std::string> files = os::directoryList(m_b.opts.tempDir);

VoxelKey root;
for (std::string file : files)
Expand Down
4 changes: 3 additions & 1 deletion external/untwine/bu/CopcSupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "../untwine/Common.hpp"
#include "../untwine/FileDimInfo.hpp"

#include <stringconv.hpp> // untwine/os

namespace untwine
{
namespace bu
Expand All @@ -39,7 +41,7 @@ CopcSupport::CopcSupport(const BaseInfo& b) : m_b(b),
else
m_wktVlr = b.srs.getWKT();

m_f.open(toNative(b.opts.outputName), std::ios::out | std::ios::binary);
m_f.open(os::toNative(b.opts.outputName), std::ios::out | std::ios::binary);

m_header.global_encoding = m_b.globalEncoding;
m_header.global_encoding |= (1 << 4); // Set for WKT
Expand Down
8 changes: 4 additions & 4 deletions external/untwine/bu/FileInfo.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

#include <list>

#include "../untwine/Common.hpp"
#include <mapfile.hpp> // untwine/os

namespace untwine
{
Expand Down Expand Up @@ -44,16 +44,16 @@ class FileInfo
char *address() const
{ return reinterpret_cast<char *>(m_ctx.addr()); }

MapContext context() const
untwine::os::MapContext context() const
{ return m_ctx; }
void setContext(const MapContext& ctx)
void setContext(const untwine::os::MapContext& ctx)
{ m_ctx = ctx; }

private:
std::string m_filename;
int m_numPoints;
int m_start;
MapContext m_ctx;
untwine::os::MapContext m_ctx;
};
using FileInfoList = std::list<FileInfo>;

Expand Down
6 changes: 4 additions & 2 deletions external/untwine/bu/PointAccessor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
#include "../untwine/Common.hpp"
#include "../untwine/Point.hpp"

#include <mapfile.hpp> // untwine/os

#include "FileInfo.hpp"

namespace untwine
Expand All @@ -31,13 +33,13 @@ class PointAccessor
~PointAccessor()
{
for (FileInfo *fi : m_fileInfos)
unmapFile(fi->context());
os::unmapFile(fi->context());
}

void read(FileInfo& fi)
{
std::string filename = m_b.opts.tempDir + "/" + fi.filename();
auto ctx = mapFile(filename, true, 0, fi.numPoints() * m_b.pointSize);
auto ctx = os::mapFile(filename, true, 0, fi.numPoints() * m_b.pointSize);
if (ctx.m_addr == nullptr)
throw FatalError(filename + ": " + ctx.m_error);
fi.setContext(ctx);
Expand Down
10 changes: 5 additions & 5 deletions external/untwine/bu/Processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include "Processor.hpp"
#include "PyramidManager.hpp"

#include <stringconv.hpp> // untwine/os

namespace untwine
{
namespace bu
Expand All @@ -50,14 +52,12 @@ void Processor::run()
}
catch (const std::exception& ex)
{
std::cerr << "Exception: " << ex.what() << "\n";
m_manager.queueWithError(m_vi.octant(), ex.what());
return;
}
catch (...)
{
std::string msg = std::string("Unexpected error processing ") + m_vi.key().toString() + ".";
std::cerr << "Exception: " << msg << "\n";
m_manager.queueWithError(m_vi.octant(), msg);
return;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ void Processor::writeBinOutput(Index& index)
// pass.
std::string filename = m_vi.key().toString() + ".bin";
std::string fullFilename = m_b.opts.tempDir + "/" + filename;
std::ofstream out(toNative(fullFilename), std::ios::binary | std::ios::trunc);
std::ofstream out(os::toNative(fullFilename), std::ios::binary | std::ios::trunc);
if (!out)
throw FatalError("Couldn't open '" + fullFilename + "' for output.");
for (size_t i = 0; i < index.size(); ++i)
Expand Down Expand Up @@ -482,13 +482,13 @@ void Processor::createChunk(const VoxelKey& key, pdal::PointViewPtr view)

uint64_t location = m_manager.newChunk(key, chunk.size(), (uint32_t)view->size());

std::ofstream out(toNative(m_b.opts.outputName),
std::ofstream out(os::toNative(m_b.opts.outputName),
std::ios::out | std::ios::in | std::ios::binary);
out.seekp(std::ofstream::pos_type(location));
out.write(reinterpret_cast<const char *>(chunk.data()), chunk.size());
out.close();
if (!out)
throw FatalError("Failure writing to '" + m_b.opts.outputName + "'.");
throw FatalError("Failure writing to file '" + m_b.opts.outputName + "'.");
}

void Processor::fillPointBuf(pdal::PointRef& point, std::vector<char>& buf,
Expand Down
3 changes: 2 additions & 1 deletion external/untwine/bu/PyramidManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,8 @@ void PyramidManager::run()

if (m_error.size())
{
std::cerr << "Exception: " << m_error << "\n";
lock.unlock();
m_pool.join();
throw FatalError(m_error);
}
}
Expand Down
13 changes: 10 additions & 3 deletions external/untwine/epf/Epf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#include <pdal/util/FileUtils.hpp>
#include <pdal/util/ProgramArgs.hpp>

#include <dirlist.hpp> // untwine/os

namespace untwine
{
Expand Down Expand Up @@ -265,7 +266,7 @@ void Epf::createFileInfos(const StringList& input, std::vector<FileInfo>& fileIn
{
if (FileUtils::isDirectory(filename))
{
StringList dirfiles = directoryList(filename);
StringList dirfiles = os::directoryList(filename);
filenames.insert(filenames.end(), dirfiles.begin(), dirfiles.end());
}
else
Expand All @@ -281,12 +282,18 @@ void Epf::createFileInfos(const StringList& input, std::vector<FileInfo>& fileIn
std::string driver = factory.inferReaderDriver(filename);
if (driver.empty())
throw FatalError("Can't infer reader for '" + filename + "'.");
// Use LAS reader for COPC files.
if (driver == "readers.copc")
driver = "readers.las";
Stage *s = factory.createStage(driver);

pdal::Options opts;
opts.add("filename", filename);
if (driver == "readers.las")
{
opts.add("nosrs", m_b.opts.no_srs);
opts.add("use_eb_vlr", "true");
}
s->setOptions(opts);

FileInfo fi;
Expand Down Expand Up @@ -437,8 +444,8 @@ std::vector<FileInfo> Epf::processLas(pdal::LasReader& r, FileInfo fi)
fi.numPoints = h.pointCount();

m_b.scale[0] = (std::max)(m_b.scale[0], h.scaleX());
m_b.scale[1] = (std::max)(m_b.scale[0], h.scaleY());
m_b.scale[2] = (std::max)(m_b.scale[0], h.scaleZ());
m_b.scale[1] = (std::max)(m_b.scale[1], h.scaleY());
m_b.scale[2] = (std::max)(m_b.scale[2], h.scaleZ());

fi.offsets[0] = h.offsetX();
fi.offsets[1] = h.offsetY();
Expand Down
4 changes: 3 additions & 1 deletion external/untwine/epf/FileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,13 @@ void FileProcessor::run()
opts.add("filename", m_fi.filename);
opts.add("count", m_fi.numPoints);
if (m_fi.driver == "readers.las")
{
opts.add("nosrs", m_fi.no_srs);
opts.add("use_eb_vlr", "true");
#ifdef PDAL_LAS_START
if (m_fi.driver == "readers.las")
opts.add("start", m_fi.start);
#endif
}

pdal::StageFactory factory;
pdal::Stage *s = factory.createStage(m_fi.driver);
Expand Down
6 changes: 4 additions & 2 deletions external/untwine/epf/Reprocessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#include "Reprocessor.hpp"
#include "../untwine/Common.hpp"

#include <mapfile.hpp> // untwine/os

namespace untwine
{
namespace epf
Expand Down Expand Up @@ -51,7 +53,7 @@ Reprocessor::Reprocessor(const VoxelKey& k, int numPoints, int pointSize,

void Reprocessor::run()
{
auto ctx = mapFile(m_filename, true, 0, m_fileSize);
auto ctx = os::mapFile(m_filename, true, 0, m_fileSize);
if (ctx.addr() == nullptr)
{
std::cerr << "FATAL: " + m_filename + ": " + ctx.what();
Expand All @@ -69,7 +71,7 @@ void Reprocessor::run()
cell->advance();
pos += m_pointSize;
}
unmapFile(ctx);
os::unmapFile(ctx);
pdal::FileUtils::deleteFile(m_filename);
}

Expand Down
6 changes: 4 additions & 2 deletions external/untwine/epf/Writer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
#include "../untwine/Common.hpp"
#include "../untwine/VoxelKey.hpp"

#include <stringconv.hpp> // untwine/os

using namespace pdal;

namespace untwine
Expand Down Expand Up @@ -144,14 +146,14 @@ void Writer::run()

// Open the file. Write the data. Stick the buffer back on the cache.
// Remove the key from the active key list.
std::ofstream out(toNative(path(wd.key)), std::ios::app | std::ios::binary);
std::ofstream out(os::toNative(path(wd.key)), std::ios::app | std::ios::binary);
out.write(reinterpret_cast<const char *>(wd.data->data()), wd.dataSize);
out.close();

std::lock_guard<std::mutex> lock(m_mutex);
if (!out)
{
m_pool.setError("Failure writing to '" + path(wd.key) + "'.");
m_pool.setError("Failure writing to file '" + path(wd.key) + "'.");
m_stop = true;
}
else
Expand Down
Loading

0 comments on commit 74a09f8

Please sign in to comment.