Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Update Untwine to the latest main branch
This lowers the required minimum version of PDAL to >= 1.7 which makes it much easier to use in many linux distributions which are not yet shipping PDAL 2.2.
- Loading branch information
Showing
with
501 additions
and 20 deletions.
- +1 −0 external/untwine/bu/BuPyramid.cpp
- +4 −4 external/untwine/bu/FileInfo.hpp
- +2 −3 external/untwine/bu/PointAccessor.hpp
- +2 −3 external/untwine/bu/PyramidManager.hpp
- +2 −2 external/untwine/epf/Epf.cpp
- +2 −3 external/untwine/epf/Epf.hpp
- +3 −2 external/untwine/epf/Reprocessor.cpp
- +2 −3 external/untwine/epf/Writer.hpp
- +109 −0 external/untwine/untwine/MapFile.cpp
- +84 −0 external/untwine/untwine/MapFile.hpp
- +117 −0 external/untwine/untwine/ThreadPool.cpp
- +172 −0 external/untwine/untwine/ThreadPool.hpp
- +1 −0 external/untwine/untwine/Untwine.cpp
@@ -0,0 +1,109 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2020, Hobu Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided | ||
* with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
* OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#include "MapFile.hpp" | ||
|
||
namespace untwine | ||
{ | ||
|
||
MapContext mapFile(const std::string& filename, bool readOnly, | ||
size_t pos, size_t size) | ||
{ | ||
MapContext ctx; | ||
|
||
if (!readOnly) | ||
{ | ||
ctx.m_error = "readOnly must be true."; | ||
return ctx; | ||
} | ||
|
||
#ifndef WIN32 | ||
ctx.m_fd = ::open(filename.c_str(), readOnly ? O_RDONLY : O_RDWR); | ||
#else | ||
ctx.m_fd = ::_open(filename.c_str(), readOnly ? O_RDONLY : O_RDWR); | ||
#endif | ||
|
||
if (ctx.m_fd == -1) | ||
{ | ||
ctx.m_error = "Mapped file couldn't be opened."; | ||
return ctx; | ||
} | ||
ctx.m_size = size; | ||
|
||
#ifndef _WIN32 | ||
ctx.m_addr = ::mmap(0, size, PROT_READ, MAP_SHARED, ctx.m_fd, (off_t)pos); | ||
if (ctx.m_addr == MAP_FAILED) | ||
{ | ||
ctx.m_addr = nullptr; | ||
ctx.m_error = "Couldn't map file"; | ||
} | ||
#else | ||
ctx.m_handle = CreateFileMapping((HANDLE)_get_osfhandle(ctx.m_fd), | ||
NULL, PAGE_READONLY, 0, 0, NULL); | ||
uint32_t low = pos & 0xFFFFFFFF; | ||
uint32_t high = (pos >> 8); | ||
ctx.m_addr = MapViewOfFile(ctx.m_handle, FILE_MAP_READ, high, low, | ||
ctx.m_size); | ||
if (ctx.m_addr == nullptr) | ||
ctx.m_error = "Couldn't map file"; | ||
#endif | ||
|
||
return ctx; | ||
} | ||
|
||
MapContext unmapFile(MapContext ctx) | ||
{ | ||
#ifndef _WIN32 | ||
if (::munmap(ctx.m_addr, ctx.m_size) == -1) | ||
ctx.m_error = "Couldn't unmap file."; | ||
else | ||
{ | ||
ctx.m_addr = nullptr; | ||
ctx.m_size = 0; | ||
ctx.m_error = ""; | ||
} | ||
::close(ctx.m_fd); | ||
#else | ||
if (UnmapViewOfFile(ctx.m_addr) == 0) | ||
ctx.m_error = "Couldn't unmap file."; | ||
else | ||
{ | ||
ctx.m_addr = nullptr; | ||
ctx.m_size = 0; | ||
ctx.m_error = ""; | ||
} | ||
CloseHandle(ctx.m_handle); | ||
::_close(ctx.m_fd); | ||
#endif | ||
return ctx; | ||
} | ||
|
||
} // namespace untwine | ||
|
@@ -0,0 +1,84 @@ | ||
/****************************************************************************** | ||
* Copyright (c) 2020, Hobu Inc. | ||
* | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following | ||
* conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided | ||
* with the distribution. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | ||
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE | ||
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, | ||
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | ||
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS | ||
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | ||
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | ||
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY | ||
* OF SUCH DAMAGE. | ||
****************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#ifdef _WIN32 | ||
#include <Windows.h> | ||
#else | ||
#include <fcntl.h> | ||
#include <unistd.h> | ||
#include <sys/mman.h> | ||
#endif | ||
|
||
#include <string> | ||
|
||
namespace untwine | ||
{ | ||
struct MapContext | ||
{ | ||
public: | ||
MapContext() : m_fd(-1), m_addr(nullptr) | ||
{} | ||
|
||
void *addr() const | ||
{ return m_addr; } | ||
std::string what() const | ||
{ return m_error; } | ||
|
||
int m_fd; | ||
size_t m_size; | ||
void *m_addr; | ||
std::string m_error; | ||
#ifdef _WIN32 | ||
HANDLE m_handle; | ||
#endif | ||
}; | ||
/** | ||
Map a file to memory. | ||
\param filename Filename to map. | ||
\param readOnly Must be true at this time. | ||
\param pos Starting position of file to map. | ||
\param size Number of bytes in file to map. | ||
\return MapContext. addr() gets the mapped address. what() gets | ||
any error message. addr() returns nullptr on error. | ||
*/ | ||
MapContext mapFile(const std::string& filename, bool readOnly, | ||
size_t pos, size_t size); | ||
|
||
/** | ||
Unmap a previously mapped file. | ||
\param ctx Previously returned MapContext | ||
\return MapContext indicating current state of the file mapping. | ||
*/ | ||
MapContext unmapFile(MapContext ctx); | ||
|
||
} // namespace untwine | ||
|
Oops, something went wrong.