Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move OS-specific functions #169

Merged
merged 12 commits into from
Jul 4, 2024
15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,20 @@ file(GLOB SRCS
bu/*.cpp
)

# MINGW must come before WIN32 test
# APPLE must come before LINUX test
if (MINGW)
set(UNTWINE_OS_DIR untwine/mingw)
elseif (WIN32)
set(UNTWINE_OS_DIR untwine/windows)
elseif (APPLE)
set(UNTWINE_OS_DIR untwine/osx)
elseif (LINUX)
set(UNTWINE_OS_DIR untwine/generic)
else()
message(FATAL_ERROR "OS not supported")
endif()

set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}/bin)

add_executable(untwine ${SRCS} ${LAZPERF_SRCS})
Expand All @@ -38,6 +52,7 @@ untwine_target_compile_settings(untwine)

target_include_directories(untwine
PRIVATE
${UNTWINE_OS_DIR}
${CMAKE_CURRENT_BINARY_DIR}/include
${PDAL_INCLUDE_DIRS}
${PROJECT_SOURCE_DIR}
Expand Down
4 changes: 3 additions & 1 deletion 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 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 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 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
6 changes: 4 additions & 2 deletions 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 Down Expand Up @@ -245,7 +247,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,7 +484,7 @@ 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());
Expand Down
7 changes: 4 additions & 3 deletions 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 Down Expand Up @@ -437,8 +438,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
3 changes: 2 additions & 1 deletion epf/FileProcessor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ 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);
#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 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
4 changes: 3 additions & 1 deletion 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,7 +146,7 @@ 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();

Expand Down
Loading
Loading