diff --git a/CMakeLists.txt b/CMakeLists.txt index 65c2a40a22..ffa6be1a35 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -128,7 +128,7 @@ include(${PDAL_CMAKE_DIR}/python.cmake) include(${PDAL_CMAKE_DIR}/arbiter.cmake) #------------------------------------------------------------------------------ -# generate the pdal_defines.h header +# generate the pdal_features.hpp header #------------------------------------------------------------------------------ # from http://stackoverflow.com/questions/1435953/how-can-i-pass-git-sha1-to-compiler-as-definition-using-cmake @@ -139,7 +139,7 @@ configure_file( "${PROJECT_SOURCE_DIR}/gitsha.cpp.in" "${PROJECT_SOURCE_DIR}/pdal/gitsha.cpp") -# needs to come before configuration of pdal_defines +# needs to come before configuration of pdal_features if(APPLE) option(PDAL_BUNDLE "Create PDAL as Application Bundle on OSX" FALSE) if (PDAL_BUNDLE) @@ -147,11 +147,10 @@ if(APPLE) endif() endif() -set(pdal_defines_h_in "${CMAKE_CURRENT_SOURCE_DIR}/pdal_defines.h.in") -set(pdal_defines_h "${CMAKE_CURRENT_BINARY_DIR}/include/pdal/pdal_defines.h") -include(CheckIncludeFiles) -check_include_files(execinfo.h PDAL_HAVE_EXECINFO_H) -configure_file(${pdal_defines_h_in} ${pdal_defines_h}) +set(pdal_features_hpp_in "${CMAKE_CURRENT_SOURCE_DIR}/pdal_features.hpp.in") +set(pdal_features_hpp + "${CMAKE_CURRENT_BINARY_DIR}/include/pdal/pdal_features.hpp") +configure_file(${pdal_features_hpp_in} ${pdal_features_hpp}) #------------------------------------------------------------------------------ # subdirectory controls @@ -198,22 +197,48 @@ file(GLOB BASE_SRCS ${PDAL_FILTERS_DIR}/*.cpp ${PDAL_IO_DIR}/*.cpp ${PDAL_KERNELS_DIR}/*.cpp - ${PDAL_SRC_DIR}/*.cpp) + ${PDAL_SRC_DIR}/*.cpp + ${PDAL_SRC_DIR}/compression/*.cpp) file(GLOB_RECURSE PRIVATE_SRCS ${PDAL_FILTERS_DIR}/private/*.cpp ${PDAL_IO_DIR}/private/*.cpp ${PDAL_KERNELS_DIR}/private/*.cpp ${PDAL_SRC_DIR}/private/*.cpp) list(APPEND SRCS ${BASE_SRCS} ${PRIVATE_SRCS}) + +# +# Remove stuff we don't want to build. +# if (NOT PDAL_HAVE_LIBXML2) file(GLOB XML_SRCS io/Ilvis2MetadataReader.cpp io/Ilvis2Metadata.cpp - pdal/DbWriter.cpp - pdal/DbReader.cpp - pdal/XMLSchema.cpp) + ${PDAL_SRC_DIR}/DbWriter.cpp + ${PDAL_SRC_DIR}/DbReader.cpp + ${PDAL_SRC_DIR}/XMLSchema.cpp) list(REMOVE_ITEM SRCS ${XML_SRCS}) endif() +if (NOT PDAL_HAVE_ZSTD) + file(GLOB ZSTD_SRCS + ${PDAL_SRC_DIR}/compression/ZstdCompression.cpp) + list(REMOVE_ITEM SRCS ${ZSTD_SRCS}) +endif() +if (NOT PDAL_HAVE_ZLIB) + file(GLOB ZLIB_SRCS + ${PDAL_SRC_DIR}/compression/DeflateCompression.cpp) + list(REMOVE_ITEM SRCS ${ZLIB_SRCS}) +endif() +if (NOT PDAL_HAVE_LZMA) + file(GLOB LZMA_SRCS + ${PDAL_SRC_DIR}/compression/LzmaCompression.cpp) + list(REMOVE_ITEM SRCS ${LZMA_SRCS}) +endif() +if (NOT PDAL_HAVE_LAZPERF) + file(GLOB LAZPERF_SRCS + ${PDAL_SRC_DIR}/compression/LazPerfCompression.cpp + ${PDAL_SRC_DIR}/compression/LazPerfVlrCompression.cpp) + list(REMOVE_ITEM SRCS ${LAZPERF_SRCS}) +endif() PDAL_ADD_LIBRARY(${PDAL_BASE_LIB_NAME} ${SRCS} ${RPLY_SRCS}) # @@ -307,7 +332,7 @@ install(DIRECTORY ${PDAL_FILTERS_DIR} PATTERN "private" EXCLUDE ) -install(FILES ${DIMENSION_OUTFILE} ${pdal_defines_h} +install(FILES ${DIMENSION_OUTFILE} ${pdal_features_h} DESTINATION include/pdal ) diff --git a/apps/pdal.cpp b/apps/pdal.cpp index 7df599fe4d..d031800ad1 100644 --- a/apps/pdal.cpp +++ b/apps/pdal.cpp @@ -93,7 +93,7 @@ class App void App::outputVersion() { m_out << headline << std::endl; - m_out << "pdal " << GetFullVersionString() << std::endl; + m_out << "pdal " << Config::fullVersionString() << std::endl; m_out << headline << std::endl; m_out << std::endl; } @@ -354,7 +354,8 @@ int App::execute(StringList& cmdArgs, LogPtr& log) else if (m_debug) log->setLevel(LogLevel::Debug); PluginManager::setLog(log); -#ifdef PDAL_HAVE_EXECINFO_H +#ifndef _WIN32 +#if __has_include() if (m_debug) { signal(SIGSEGV, [](int sig) @@ -367,6 +368,7 @@ int App::execute(StringList& cmdArgs, LogPtr& log) exit(1); }); } +#endif #endif m_command = Utils::tolower(m_command); diff --git a/cmake/win32_compiler_options.cmake b/cmake/win32_compiler_options.cmake index c702dd254c..dff3c71c09 100644 --- a/cmake/win32_compiler_options.cmake +++ b/cmake/win32_compiler_options.cmake @@ -1,18 +1,3 @@ -if (MSVC) - set(PDAL_COMPILER_MSVC 1) - if (MSVC12) - set(PDAL_COMPILER_VC12 1) - elseif (MSVC11) - set(PDAL_COMPILER_VC11 1) - elseif (MSVC10) - set(PDAL_COMPILER_VC10 1) - elseif (MSVC9) - set(PDAL_COMPILER_VC9 1) - elseif (MSVC8) - set(PDAL_COMPILER_VC8 1) - endif() -endif() - function(PDAL_TARGET_COMPILE_SETTINGS target) target_compile_definitions(${target} PUBLIC -DWIN32_LEAN_AND_MEAN) if (MSVC) diff --git a/filters/private/pnp/GridPnp.hpp b/filters/private/pnp/GridPnp.hpp index 697ad8e965..b818ff74cd 100644 --- a/filters/private/pnp/GridPnp.hpp +++ b/filters/private/pnp/GridPnp.hpp @@ -278,8 +278,8 @@ class GridPnp double scalex = ((m_xMax - m_xMin) * yAvgLen) / ((m_yMax - m_yMin) * xAvgLen); double scaley = 1 / scalex; - double mx = std::sqrt(m * scalex); - double my = std::sqrt(m * scaley); + size_t mx = (size_t)std::sqrt(m * scalex); + size_t my = (size_t)std::sqrt(m * scaley); // We always round up, because why not. return XYIndex(mx + 1, my + 1); diff --git a/io/GDALGrid.cpp b/io/GDALGrid.cpp index 5809a3b897..429fa45417 100644 --- a/io/GDALGrid.cpp +++ b/io/GDALGrid.cpp @@ -421,7 +421,7 @@ void GDALGrid::windowFill(size_t dstI, size_t dstJ) continue; // The ternaries just avoid underflow UB. We're just trying to // find the distance from j to dstJ or i to dstI. - double distance = std::max(j > dstJ ? j - dstJ : dstJ - j, + double distance = (double)std::max(j > dstJ ? j - dstJ : dstJ - j, i > dstI ? i - dstI : dstI - i); windowFillCell(srcIdx, dstIdx, distance); distSum += (1 / distance); diff --git a/io/GDALGrid.hpp b/io/GDALGrid.hpp index 524a9aee56..99a4bc6bc6 100644 --- a/io/GDALGrid.hpp +++ b/io/GDALGrid.hpp @@ -113,11 +113,11 @@ class GDALGrid // Convert an absolute X position to a horizontal cell index. int horizontalIndex(double x) - { return x / m_edgeLength; } + { return (int)(x / m_edgeLength); } // Convert an absolute Y position to a vertical cell index. int verticalIndex(double y) - { return m_height - (y / m_edgeLength) - 1; } + { return (int)(m_height - (y / m_edgeLength) - 1); } // Return the absolute horizontal position of the center of a cell given // the cell i index. diff --git a/io/Ilvis2Reader.cpp b/io/Ilvis2Reader.cpp index 19dd164c7a..111c480d01 100644 --- a/io/Ilvis2Reader.cpp +++ b/io/Ilvis2Reader.cpp @@ -33,6 +33,7 @@ ****************************************************************************/ #include "Ilvis2Reader.hpp" +#include "Ilvis2MetadataReader.hpp" #include #include #include diff --git a/io/Ilvis2Reader.hpp b/io/Ilvis2Reader.hpp index ee0f64e5f0..2fd99f88a1 100644 --- a/io/Ilvis2Reader.hpp +++ b/io/Ilvis2Reader.hpp @@ -32,6 +32,7 @@ * OF SUCH DAMAGE. ****************************************************************************/ +#include // For PDAL_HAVE_LIBXML2 #include #include #include diff --git a/io/LasHeader.cpp b/io/LasHeader.cpp index c06baf3e09..d3db9727b5 100644 --- a/io/LasHeader.cpp +++ b/io/LasHeader.cpp @@ -55,12 +55,10 @@ const size_t LasHeader::RETURN_COUNT; std::string GetDefaultSoftwareId() { - std::string ver(PDAL_VERSION_STRING); + std::string ver(Config::versionString()); std::stringstream oss; std::ostringstream revs; - revs << GetSHA1(); - - + revs << Config::sha1(); oss << "PDAL " << ver << " (" << revs.str().substr(0, 6) <<")"; return oss.str(); } diff --git a/io/LasReader.cpp b/io/LasReader.cpp index 816a8fe006..9ba27cf8a3 100644 --- a/io/LasReader.cpp +++ b/io/LasReader.cpp @@ -32,6 +32,8 @@ * OF SUCH DAMAGE. ****************************************************************************/ +#include + #include "LasReader.hpp" #include @@ -63,6 +65,18 @@ struct invalid_stream : public std::runtime_error } // unnamed namespace +LasReader::LasReader() : m_decompressor(nullptr), m_index(0) +{} + + +LasReader::~LasReader() +{ +#ifdef PDAL_HAVE_LAZPERF + delete m_decompressor; +#endif +} + + void LasReader::addArgs(ProgramArgs& args) { addSpatialReferenceArg(args); @@ -245,8 +259,9 @@ void LasReader::ready(PointTableRef table) { const LasVLR *vlr = m_header.findVlr(LASZIP_USER_ID, LASZIP_RECORD_ID); - m_decompressor.reset(new LazPerfVlrDecompressor(*stream, - vlr->data(), m_header.pointOffset())); + delete m_decompressor; + m_decompressor = new LazPerfVlrDecompressor(*stream, + vlr->data(), m_header.pointOffset()); m_decompressorBuf.resize(m_decompressor->pointSize()); } #endif diff --git a/io/LasReader.hpp b/io/LasReader.hpp index 85e4303ae6..f20979c141 100644 --- a/io/LasReader.hpp +++ b/io/LasReader.hpp @@ -38,7 +38,6 @@ #include #include #include -#include #ifdef PDAL_HAVE_LASZIP #include @@ -62,6 +61,7 @@ class NitfReader; class LasHeader; class LeExtractor; class PointDimensions; +class LazPerfVlrDecompressor; class PDAL_DLL LasReader : public pdal::Reader { @@ -87,8 +87,8 @@ class PDAL_DLL LasReader : public pdal::Reader friend class NitfReader; public: - LasReader() : pdal::Reader(), m_index(0) - {} + LasReader(); + ~LasReader(); static void * create(); static int32_t destroy(void *); @@ -122,7 +122,8 @@ class PDAL_DLL LasReader : public pdal::Reader LasHeader m_header; laszip_POINTER m_laszip; laszip_point_struct *m_laszipPoint; - std::unique_ptr m_decompressor; + + LazPerfVlrDecompressor *m_decompressor; std::vector m_decompressorBuf; point_count_t m_index; StringList m_extraDimSpec; diff --git a/io/LasWriter.cpp b/io/LasWriter.cpp index 3bf7c00bc4..97e5c4a268 100644 --- a/io/LasWriter.cpp +++ b/io/LasWriter.cpp @@ -32,6 +32,8 @@ * OF SUCH DAMAGE. ****************************************************************************/ +#include + #include "LasWriter.hpp" #include @@ -65,11 +67,19 @@ CREATE_STATIC_PLUGIN(1, 0, LasWriter, Writer, s_info) std::string LasWriter::getName() const { return s_info.name; } -LasWriter::LasWriter() : m_ostream(NULL), m_compression(LasCompression::None), - m_srsCnt(0) +LasWriter::LasWriter() : m_compressor(nullptr), m_ostream(NULL), + m_compression(LasCompression::None), m_srsCnt(0) {} +LasWriter::~LasWriter() +{ +#ifdef PDAL_HAVE_LAZPERF + delete m_compressor; +#endif +} + + void LasWriter::addArgs(ProgramArgs& args) { std::time_t now; @@ -704,8 +714,9 @@ void LasWriter::readyLazPerfCompression() zipvlr.extract((char *)data.data()); addVlr(LASZIP_USER_ID, LASZIP_RECORD_ID, "http://laszip.org", data); - m_compressor.reset(new LazPerfVlrCompressor(*m_ostream, schema, - zipvlr.chunk_size)); + delete m_compressor; + m_compressor = new LazPerfVlrCompressor(*m_ostream, schema, + zipvlr.chunk_size); #endif } diff --git a/io/LasWriter.hpp b/io/LasWriter.hpp index 648c85192a..d3aa44ca35 100644 --- a/io/LasWriter.hpp +++ b/io/LasWriter.hpp @@ -37,7 +37,6 @@ #include #include -#include #include "HeaderVal.hpp" #include "LasError.hpp" @@ -62,6 +61,7 @@ class LeInserter; class LasTester; class NitfWriter; class GeotiffSupport; +class LazPerfVlrCompressor; struct VlrOptionInfo { @@ -82,6 +82,7 @@ class PDAL_DLL LasWriter : public FlexWriter std::string getName() const; LasWriter(); + ~LasWriter(); protected: void prepOutput(std::ostream *out, const SpatialReference& srs); @@ -91,7 +92,7 @@ class PDAL_DLL LasWriter : public FlexWriter LasHeader m_lasHeader; std::unique_ptr m_summaryData; laszip_POINTER m_laszip; - std::unique_ptr m_compressor; + LazPerfVlrCompressor *m_compressor; bool m_discardHighReturnNumbers; std::map m_headerVals; std::vector m_optionInfos; diff --git a/io/PlyReader.cpp b/io/PlyReader.cpp index 6aa3a955e6..4fc57f3381 100644 --- a/io/PlyReader.cpp +++ b/io/PlyReader.cpp @@ -301,8 +301,6 @@ void PlyReader::initialize() void PlyReader::addDimensions(PointLayoutPtr layout) { - SimpleProperty *prop; - // Override XYZ to doubles. layout->registerDim(Dimension::Id::X); layout->registerDim(Dimension::Id::Y); diff --git a/io/QfitReader.cpp b/io/QfitReader.cpp index d93e3301a0..6f1366232e 100644 --- a/io/QfitReader.cpp +++ b/io/QfitReader.cpp @@ -175,10 +175,7 @@ Word # Content #include #include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif - +#pragma warning(disable: 4127) // conditional expression is constant namespace pdal { diff --git a/kernels/HausdorffKernel.cpp b/kernels/HausdorffKernel.cpp index bf0a23b8bc..83a5cad060 100644 --- a/kernels/HausdorffKernel.cpp +++ b/kernels/HausdorffKernel.cpp @@ -90,7 +90,7 @@ int HausdorffKernel::execute() root.add("filenames", m_sourceFile); root.add("filenames", m_candidateFile); root.add("hausdorff", hausdorff); - root.add("pdal_version", pdal::GetFullVersionString()); + root.add("pdal_version", Config::fullVersionString()); Utils::toJSON(root, std::cout); return 0; diff --git a/kernels/InfoKernel.cpp b/kernels/InfoKernel.cpp index c90dfa01de..e962ceb4f9 100644 --- a/kernels/InfoKernel.cpp +++ b/kernels/InfoKernel.cpp @@ -347,7 +347,7 @@ MetadataNode InfoKernel::run(const std::string& filename) m_manager.prepare(); dump(root); } - root.add("pdal_version", pdal::GetFullVersionString()); + root.add("pdal_version", Config::fullVersionString()); return root; } diff --git a/pdal/DbWriter.cpp b/pdal/DbWriter.cpp index 5a57a94258..790ec1b791 100644 --- a/pdal/DbWriter.cpp +++ b/pdal/DbWriter.cpp @@ -126,19 +126,22 @@ void DbWriter::ready(PointTableRef /*table*/) { xmlDim.m_dimType.m_xform = m_scaling.m_xXform; xmlDim.m_dimType.m_type = Type::Signed32; - m_xOffsets = std::make_pair(m_packedPointSize, m_dbPointSize); + m_xOffsets = + std::make_pair((int)m_packedPointSize, (int)m_dbPointSize); } if (xmlDim.m_dimType.m_id == Id::Y) { xmlDim.m_dimType.m_xform = m_scaling.m_yXform; xmlDim.m_dimType.m_type = Type::Signed32; - m_yOffsets = std::make_pair(m_packedPointSize, m_dbPointSize); + m_yOffsets = + std::make_pair((int)m_packedPointSize, (int)m_dbPointSize); } if (xmlDim.m_dimType.m_id == Id::Z) { xmlDim.m_dimType.m_xform = m_scaling.m_zXform; xmlDim.m_dimType.m_type = Type::Signed32; - m_zOffsets = std::make_pair(m_packedPointSize, m_dbPointSize); + m_zOffsets = + std::make_pair((int)m_packedPointSize, (int)m_dbPointSize); } } m_packedPointSize += Dimension::size(dt.m_type); diff --git a/pdal/GDALUtils.cpp b/pdal/GDALUtils.cpp index 7daee5409a..36fe4b8353 100644 --- a/pdal/GDALUtils.cpp +++ b/pdal/GDALUtils.cpp @@ -42,9 +42,7 @@ #include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif +#pragma warning(disable: 4127) // conditional expression is constant namespace pdal { diff --git a/pdal/GEOSUtils.cpp b/pdal/GEOSUtils.cpp index 3fb34588b7..facda658b0 100644 --- a/pdal/GEOSUtils.cpp +++ b/pdal/GEOSUtils.cpp @@ -40,9 +40,7 @@ #include #include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif +#pragma warning(disable: 4127) // conditional expression is constant namespace pdal { diff --git a/pdal/Mesh.hpp b/pdal/Mesh.hpp index 389599751e..f7c6fa948d 100644 --- a/pdal/Mesh.hpp +++ b/pdal/Mesh.hpp @@ -35,12 +35,11 @@ #pragma once #include -#include namespace pdal { -class Triangle +class PDAL_DLL Triangle { public: Triangle(PointId a, PointId b, PointId c) : m_a(a), m_b(b), m_c(c) @@ -55,7 +54,7 @@ class Triangle A mesh is a way to represent a set of points connected by edges. Point indices are into a point view. */ -class PDAL_DLL Mesh +class Mesh {}; @@ -64,22 +63,19 @@ class PDAL_DLL Mesh /** A mesh where the faces are triangles. */ -class PDAL_DLL TriangularMesh : public Mesh +class TriangularMesh : public Mesh { public: - TriangularMesh() + PDAL_DLL TriangularMesh() {} - size_t size() const + size_t PDAL_DLL size() const { return m_index.size(); } - void add(PointId a, PointId b, PointId c) + void PDAL_DLL add(PointId a, PointId b, PointId c) { m_index.emplace_back(a, b, c); } - const Triangle& operator[](PointId id) const + const PDAL_DLL Triangle& operator[](PointId id) const { return m_index[id]; } protected: -#ifdef PDAL_COMPILER_MSVC -#pragma warning(disable:4251)// [templated class] needs to have dll-interface... -#endif std::deque m_index; }; diff --git a/pdal/PDALUtils.cpp b/pdal/PDALUtils.cpp index 35fc13265f..6bc0cbd4c3 100644 --- a/pdal/PDALUtils.cpp +++ b/pdal/PDALUtils.cpp @@ -33,6 +33,7 @@ ****************************************************************************/ #include +#include #ifdef PDAL_ARBITER_ENABLED #include @@ -219,8 +220,6 @@ class ArbiterOutStream : public std::ofstream close(); arbiter::Arbiter a; a.put(m_remotePath, a.getBinary(m_localFile.filename())); -#else - throw pdal_error("Arbiter is not enabled for this configuration!"); #endif } diff --git a/pdal/PDALUtils.hpp b/pdal/PDALUtils.hpp index 443a934365..ffb685eed0 100644 --- a/pdal/PDALUtils.hpp +++ b/pdal/PDALUtils.hpp @@ -36,20 +36,15 @@ #include #include -#include #include #include #include -#ifndef WIN32 +#ifndef _WIN32 #include #include #endif -#ifdef PDAL_COMPILER_MSVC -//# pragma warning(disable: 4127) // conditional expression is constant -#endif - namespace pdal { diff --git a/pdal/PipelineManager.cpp b/pdal/PipelineManager.cpp index 390220bf4c..c5aa25fb0b 100644 --- a/pdal/PipelineManager.cpp +++ b/pdal/PipelineManager.cpp @@ -38,9 +38,7 @@ #include #include -#if defined(PDAL_COMPILER_CLANG) || defined(PDAL_COMPILER_GCC) -# pragma GCC diagnostic ignored "-Wmissing-field-initializers" -#endif +#pragma GCC diagnostic ignored "-Wmissing-field-initializers" namespace pdal { diff --git a/pdal/PluginManager.cpp b/pdal/PluginManager.cpp index 8758a1f09e..4246e4eb09 100644 --- a/pdal/PluginManager.cpp +++ b/pdal/PluginManager.cpp @@ -39,7 +39,7 @@ #include -#include +#include #include #include #include @@ -94,10 +94,10 @@ StringList pluginSearchPaths() for (std::string& s : standardPaths) { if (FileUtils::toAbsolutePath(s) != - FileUtils::toAbsolutePath(PDAL_PLUGIN_INSTALL_PATH)) + FileUtils::toAbsolutePath(Config::pluginInstallPath())) searchPaths.push_back(s); } - searchPaths.push_back(PDAL_PLUGIN_INSTALL_PATH); + searchPaths.push_back(Config::pluginInstallPath()); } return searchPaths; } diff --git a/pdal/PointView.hpp b/pdal/PointView.hpp index 2645f8820a..0f4348a8e7 100644 --- a/pdal/PointView.hpp +++ b/pdal/PointView.hpp @@ -49,9 +49,7 @@ #include #include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4244) // conversion from 'type1' to 'type2', possible loss of data -#endif +#pragma warning(disable: 4244) // conversion from 'type1' to 'type2', possible loss of data namespace pdal { diff --git a/pdal/PyArray.hpp b/pdal/PyArray.hpp index f34e43f2a1..67b0fa3b75 100644 --- a/pdal/PyArray.hpp +++ b/pdal/PyArray.hpp @@ -38,13 +38,9 @@ #include -//#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -//#endif +#pragma warning(disable: 4127) // conditional expression is constant -#ifdef PDAL_HAVE_PYTHON - #include #undef toupper #undef tolower @@ -57,8 +53,6 @@ #define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION #include -#endif //PDAL_HAVE_PYTHON - // forward declare PyObject so we don't need the python headers everywhere // see: http://mail.python.org/pipermail/python-dev/2003-August/037601.html #ifndef PyObject_HEAD @@ -79,7 +73,6 @@ class PDAL_DLL Array Array() : m_py_array(0) { -#ifdef PDAL_HAVE_PYTHON auto initNumpy = []() { #undef NUMPY_IMPORT_ARRAY_RETVAL @@ -87,7 +80,6 @@ class PDAL_DLL Array import_array(); }; initNumpy(); -#endif } ~Array() @@ -98,7 +90,6 @@ class PDAL_DLL Array inline void update(PointViewPtr view) { -#ifdef PDAL_HAVE_PYTHON typedef std::unique_ptr> DataPtr; cleanup(); int nd = 1; @@ -145,7 +136,6 @@ class PDAL_DLL Array m_py_array = pyArray; m_data_array = std::move(pdata); -#endif } @@ -156,11 +146,9 @@ class PDAL_DLL Array inline void cleanup() { -#ifdef PDAL_HAVE_PYTHON PyObject* p = (PyObject*)(m_py_array); Py_XDECREF(p); m_data_array.reset(); -#endif } inline PyObject* buildNumpyDescription(PointViewPtr view) const @@ -175,7 +163,6 @@ class PDAL_DLL Array // 'Blue']} // -#ifdef PDAL_HAVE_PYTHON std::stringstream oss; Dimension::IdList dims = view->dims(); @@ -225,7 +212,6 @@ class PDAL_DLL Array // std::string output(s); // std::cout << "array: " << output << std::endl; return dict; -#endif } PyObject* m_py_array; diff --git a/pdal/SpatialReference.cpp b/pdal/SpatialReference.cpp index f5b97ecbba..738a533a36 100644 --- a/pdal/SpatialReference.cpp +++ b/pdal/SpatialReference.cpp @@ -40,21 +40,11 @@ #include // gdal -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wfloat-equal" -#endif -#ifdef PDAL_COMPILER_GCC # pragma GCC diagnostic push # pragma GCC diagnostic ignored "-Wfloat-equal" -#endif #include -#ifdef PDAL_COMPILER_GCC # pragma GCC diagnostic pop -#endif -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif + #include #include diff --git a/pdal/Writer.cpp b/pdal/Writer.cpp index bc540d81f8..5ec4dd98fe 100644 --- a/pdal/Writer.cpp +++ b/pdal/Writer.cpp @@ -37,9 +37,7 @@ #include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif +#pragma warning(disable: 4127) // conditional expression is constant namespace pdal { diff --git a/pdal/XMLSchema.hpp b/pdal/XMLSchema.hpp index 4eeb8cd539..9127988be9 100644 --- a/pdal/XMLSchema.hpp +++ b/pdal/XMLSchema.hpp @@ -38,10 +38,6 @@ #define PDAL_XML_SCHEMA_VERSION "1.3" -#ifndef PDAL_HAVE_LIBXML2 -#error "Including XMLSchema.hpp without libxml2 - build problem." -#endif - #include #include #include diff --git a/pdal/compression/Compression.hpp b/pdal/compression/Compression.hpp index d5d88f8c4d..b075c9d4f9 100644 --- a/pdal/compression/Compression.hpp +++ b/pdal/compression/Compression.hpp @@ -63,7 +63,7 @@ class compression_error : public std::runtime_error }; -class Compressor +class PDAL_DLL Compressor { public: virtual ~Compressor() @@ -75,7 +75,7 @@ class Compressor }; -class Decompressor +class PDAL_DLL Decompressor { public: virtual ~Decompressor() diff --git a/pdal/compression/DeflateCompression.cpp b/pdal/compression/DeflateCompression.cpp new file mode 100644 index 0000000000..268560b5d1 --- /dev/null +++ b/pdal/compression/DeflateCompression.cpp @@ -0,0 +1,253 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 "DeflateCompression.hpp" + +#include + +namespace pdal +{ + +class DeflateCompressorImpl +{ +public: + DeflateCompressorImpl(BlockCb cb) : m_cb(cb) + { + m_strm.zalloc = Z_NULL; + m_strm.zfree = Z_NULL; + m_strm.opaque = Z_NULL; + switch (deflateInit(&m_strm, Z_DEFAULT_COMPRESSION)) + { + case Z_OK: + return; + case Z_MEM_ERROR: + throw compression_error("Memory allocation failure."); + case Z_STREAM_ERROR: + throw compression_error("Internal error."); + case Z_VERSION_ERROR: + throw compression_error("Incompatible version."); + default: + throw compression_error(); + } + } + + ~DeflateCompressorImpl() + { + deflateEnd(&m_strm); + } + + void compress(const char *buf, size_t bufsize) + { + run(buf, bufsize, Z_NO_FLUSH); + } + + void done() + { + run(nullptr, 0, Z_FINISH); + } + +private: + void run(const char *buf, size_t bufsize, int mode) + { + auto handleError = [](int ret) -> void + { + switch (ret) + { + case Z_OK: + case Z_STREAM_END: + return; + case Z_STREAM_ERROR: + throw compression_error("Internal error."); + case Z_DATA_ERROR: + throw compression_error("Corrupted data."); + case Z_MEM_ERROR: + throw compression_error("Memory allocation failure."); + default: + std::cerr << "Compression error !\n"; + throw compression_error(); + } + }; + + if (buf) + { + m_strm.avail_in = bufsize; + m_strm.next_in = reinterpret_cast( + const_cast(buf)); + } + int ret = Z_OK; + do + { + m_strm.avail_out = CHUNKSIZE; + m_strm.next_out = m_tmpbuf; + ret = ::deflate(&m_strm, mode); + handleError(ret); + size_t written = CHUNKSIZE - m_strm.avail_out; + if (written) + m_cb(reinterpret_cast(m_tmpbuf), written); + } while (m_strm.avail_out == 0); + } + +private: + BlockCb m_cb; + z_stream m_strm; + unsigned char m_tmpbuf[CHUNKSIZE]; +}; + + +DeflateCompressor::DeflateCompressor(BlockCb cb) : + m_impl(new DeflateCompressorImpl(cb)) +{} + + +DeflateCompressor::~DeflateCompressor() +{} + + +void DeflateCompressor::compress(const char *buf, size_t bufsize) +{ + m_impl->compress(buf, bufsize); +} + + +void DeflateCompressor::done() +{ + m_impl->done(); +} + + +class DeflateDecompressorImpl +{ +public: + DeflateDecompressorImpl(BlockCb cb) : m_cb(cb) + { + m_strm.zalloc = Z_NULL; + m_strm.zfree = Z_NULL; + m_strm.opaque = Z_NULL; + m_strm.avail_in = 0; + m_strm.next_in = Z_NULL; + switch (inflateInit(&m_strm)) + { + case Z_OK: + return; + case Z_MEM_ERROR: + throw compression_error("Memory allocation failure."); + case Z_STREAM_ERROR: + throw compression_error("Internal error."); + case Z_VERSION_ERROR: + throw compression_error("Incompatible version."); + default: + throw compression_error(); + } + } + + ~DeflateDecompressorImpl() + { + inflateEnd(&m_strm); + } + + void decompress(const char *buf, size_t bufsize) + { + run(buf, bufsize, Z_NO_FLUSH); + } + + void done() + { + run(nullptr, 0, Z_FINISH); + } + +private: + void run(const char *buf, size_t bufsize, int mode) + { + auto handleError = [](int ret) -> void + { + switch (ret) + { + case Z_OK: + case Z_STREAM_END: + return; + case Z_STREAM_ERROR: + throw compression_error("Internal error."); + case Z_DATA_ERROR: + throw compression_error("Corrupted data."); + case Z_MEM_ERROR: + throw compression_error("Memory allocation failure."); + default: + throw compression_error(); + } + }; + + m_strm.next_in = reinterpret_cast( + const_cast(buf)); + m_strm.avail_in = bufsize; + int ret = Z_OK; + do + { + m_strm.avail_out = CHUNKSIZE; + m_strm.next_out = m_tmpbuf; + ret = inflate(&m_strm, mode); + handleError(ret); + size_t written = CHUNKSIZE - m_strm.avail_out; + if (written) + m_cb(reinterpret_cast(m_tmpbuf), written); + } while (m_strm.avail_out == 0); + } + +private: + BlockCb m_cb; + z_stream m_strm; + unsigned char m_tmpbuf[CHUNKSIZE]; +}; + + +DeflateDecompressor::DeflateDecompressor(BlockCb cb) : + m_impl(new DeflateDecompressorImpl(cb)) +{} + + +DeflateDecompressor::~DeflateDecompressor() +{} + + +void DeflateDecompressor::decompress(const char *buf, size_t bufsize) +{ + m_impl->decompress(buf, bufsize); +} + + +void DeflateDecompressor::done() +{ + m_impl->done(); +} + +} // namespace pdal diff --git a/pdal/compression/DeflateCompression.hpp b/pdal/compression/DeflateCompression.hpp index a41528b53b..6c21628107 100644 --- a/pdal/compression/DeflateCompression.hpp +++ b/pdal/compression/DeflateCompression.hpp @@ -33,184 +33,40 @@ ****************************************************************************/ #pragma once -#ifdef PDAL_HAVE_ZLIB - #include "Compression.hpp" -#include - namespace pdal { +class DeflateCompressorImpl; + class DeflateCompressor : public Compressor { public: - DeflateCompressor(BlockCb cb) : m_cb(cb) - { - m_strm.zalloc = Z_NULL; - m_strm.zfree = Z_NULL; - m_strm.opaque = Z_NULL; - switch (deflateInit(&m_strm, Z_DEFAULT_COMPRESSION)) - { - case Z_OK: - return; - case Z_MEM_ERROR: - throw compression_error("Memory allocation failure."); - case Z_STREAM_ERROR: - throw compression_error("Internal error."); - case Z_VERSION_ERROR: - throw compression_error("Incompatible version."); - default: - throw compression_error(); - } - } - - ~DeflateCompressor() - { - deflateEnd(&m_strm); - } + PDAL_DLL DeflateCompressor(BlockCb cb); + PDAL_DLL ~DeflateCompressor(); - void compress(const char *buf, size_t bufsize) - { - run(buf, bufsize, Z_NO_FLUSH); - } - - void done() - { - run(nullptr, 0, Z_FINISH); - } + PDAL_DLL void compress(const char *buf, size_t bufsize); + PDAL_DLL void done(); private: - void run(const char *buf, size_t bufsize, int mode) - { - auto handleError = [](int ret) -> void - { - switch (ret) - { - case Z_OK: - case Z_STREAM_END: - return; - case Z_STREAM_ERROR: - throw compression_error("Internal error."); - case Z_DATA_ERROR: - throw compression_error("Corrupted data."); - case Z_MEM_ERROR: - throw compression_error("Memory allocation failure."); - default: - std::cerr << "Compression error !\n"; - throw compression_error(); - } - }; + std::unique_ptr m_impl; +}; - if (buf) - { - m_strm.avail_in = bufsize; - m_strm.next_in = reinterpret_cast( - const_cast(buf)); - } - int ret = Z_OK; - do - { - m_strm.avail_out = CHUNKSIZE; - m_strm.next_out = m_tmpbuf; - ret = ::deflate(&m_strm, mode); - handleError(ret); - size_t written = CHUNKSIZE - m_strm.avail_out; - if (written) - m_cb(reinterpret_cast(m_tmpbuf), written); - } while (m_strm.avail_out == 0); - } -private: - BlockCb m_cb; - z_stream m_strm; - unsigned char m_tmpbuf[CHUNKSIZE]; -}; +class DeflateDecompressorImpl; class DeflateDecompressor : public Decompressor { public: - DeflateDecompressor(BlockCb cb) : m_cb(cb) - { - m_strm.zalloc = Z_NULL; - m_strm.zfree = Z_NULL; - m_strm.opaque = Z_NULL; - m_strm.avail_in = 0; - m_strm.next_in = Z_NULL; - switch (inflateInit(&m_strm)) - { - case Z_OK: - return; - case Z_MEM_ERROR: - throw compression_error("Memory allocation failure."); - case Z_STREAM_ERROR: - throw compression_error("Internal error."); - case Z_VERSION_ERROR: - throw compression_error("Incompatible version."); - default: - throw compression_error(); - } - } + PDAL_DLL DeflateDecompressor(BlockCb cb); + PDAL_DLL ~DeflateDecompressor(); - ~DeflateDecompressor() - { - inflateEnd(&m_strm); - } - - void decompress(const char *buf, size_t bufsize) - { - run(buf, bufsize, Z_NO_FLUSH); - } - - void done() - { - run(nullptr, 0, Z_FINISH); - } + PDAL_DLL void decompress(const char *buf, size_t bufsize); + PDAL_DLL void done(); private: - void run(const char *buf, size_t bufsize, int mode) - { - auto handleError = [](int ret) -> void - { - switch (ret) - { - case Z_OK: - case Z_STREAM_END: - return; - case Z_STREAM_ERROR: - throw compression_error("Internal error."); - case Z_DATA_ERROR: - throw compression_error("Corrupted data."); - case Z_MEM_ERROR: - throw compression_error("Memory allocation failure."); - default: - throw compression_error(); - } - }; - - m_strm.next_in = reinterpret_cast( - const_cast(buf)); - m_strm.avail_in = bufsize; - int ret = Z_OK; - do - { - m_strm.avail_out = CHUNKSIZE; - m_strm.next_out = m_tmpbuf; - ret = inflate(&m_strm, mode); - handleError(ret); - size_t written = CHUNKSIZE - m_strm.avail_out; - if (written) - m_cb(reinterpret_cast(m_tmpbuf), written); - } while (m_strm.avail_out == 0); - } - -private: - BlockCb m_cb; - z_stream m_strm; - unsigned char m_tmpbuf[CHUNKSIZE]; + std::unique_ptr m_impl; }; - } // namespace pdal - -#endif // PDAL_HAVE_ZLIB diff --git a/pdal/compression/LazPerfCompression.cpp b/pdal/compression/LazPerfCompression.cpp new file mode 100644 index 0000000000..ed0fa16c92 --- /dev/null +++ b/pdal/compression/LazPerfCompression.cpp @@ -0,0 +1,267 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 + +#include +#include +#include + +#include +#include +#include +#include +#include + +#include "LazPerfCompression.hpp" + +namespace pdal +{ + +namespace +{ + +template +size_t addFields(LasZipEngine& engine, const DimTypeList& dims) +{ + using namespace Dimension; + + size_t pointSize = 0; + for (auto di = dims.begin(); di != dims.end(); ++di) + { + switch (di->m_type) + { + case Type::Signed64: + engine->template add_field(); + engine->template add_field(); + break; + case Type::Signed32: + case Type::Float: + engine->template add_field(); + break; + case Type::Signed16: + engine->template add_field(); + break; + case Type::Signed8: + engine->template add_field(); + break; + case Type::Unsigned64: + case Type::Double: + engine->template add_field(); + engine->template add_field(); + break; + case Type::Unsigned32: + engine->template add_field(); + break; + case Type::Unsigned16: + engine->template add_field(); + break; + case Type::Unsigned8: + engine->template add_field(); + break; + default: + return 0; + } + pointSize += Dimension::size(di->m_type); + } + return pointSize; +} + +} // anonymous namespace + + +class LazPerfCompressorImpl +{ +public: + LazPerfCompressorImpl(BlockCb cb, const DimTypeList& dims) : + m_cb(cb), + m_encoder(*this), + m_compressor(laszip::formats::make_dynamic_compressor(m_encoder)), + m_pointSize(0), + m_avail(CHUNKSIZE) + { m_pointSize = addFields(m_compressor, dims); } + + void putBytes(const uint8_t* buf, size_t bufsize) + { + while (bufsize) + { + size_t copyCnt = std::min(m_avail, bufsize); + std::copy(buf, buf + copyCnt, m_tmpbuf + (CHUNKSIZE - m_avail)); + m_avail -= copyCnt; + if (m_avail == 0) + { + m_cb(reinterpret_cast(m_tmpbuf), CHUNKSIZE); + m_avail = CHUNKSIZE; + } + buf += copyCnt; + bufsize -= copyCnt; + } + } + + void putByte(unsigned char b) + { + m_tmpbuf[CHUNKSIZE - m_avail] = b; + if (--m_avail == 0) + { + m_cb(reinterpret_cast(m_tmpbuf), CHUNKSIZE); + m_avail = CHUNKSIZE; + } + } + + void compress(const char *buf, size_t bufsize) + { + while (bufsize >= m_pointSize) + { + m_compressor->compress(buf); + buf += m_pointSize; + bufsize -= m_pointSize; + } + } + + void done() + { + m_encoder.done(); + if (m_avail != CHUNKSIZE) + m_cb(reinterpret_cast(m_tmpbuf), CHUNKSIZE - m_avail); + m_avail = CHUNKSIZE; + } + +private: + BlockCb m_cb; + typedef laszip::encoders::arithmetic Encoder; + Encoder m_encoder; + typedef typename laszip::formats::dynamic_field_compressor::ptr + Compressor; + Compressor m_compressor; + size_t m_pointSize; + unsigned char m_tmpbuf[CHUNKSIZE]; + size_t m_avail; +}; + + +LazPerfCompressor::LazPerfCompressor(BlockCb cb, const DimTypeList& dims) : + m_impl(new LazPerfCompressorImpl(cb, dims)) +{} + + +LazPerfCompressor::~LazPerfCompressor() +{} + + +void LazPerfCompressor::compress(const char *buf, size_t bufsize) +{ + m_impl->compress(buf, bufsize); +} + + +void LazPerfCompressor::done() +{ + m_impl->done(); +} + + +class LazPerfDecompressorImpl +{ +public: + LazPerfDecompressorImpl(BlockCb cb, const DimTypeList& dims, + size_t numPoints) : + m_decoder(*this), + m_decompressor(laszip::formats::make_dynamic_decompressor(m_decoder)), + m_cb(cb), + m_numPoints(numPoints) + { m_pointSize = addFields(m_decompressor, dims); } + + unsigned char getByte() + { + if (m_srcsize) + { + m_srcsize--; + return *m_srcbuf++; + } + return 0; + } + + void getBytes(uint8_t *dst, size_t dstsize) + { + size_t count = std::min(dstsize, m_srcsize); + uint8_t *src = const_cast( + reinterpret_cast(m_srcbuf)); + std::copy(src, src + count, dst); + m_srcbuf += count; + m_srcsize -= count; + } + + void decompress(const char *buf, size_t bufsize) + { + m_srcbuf = buf; + m_srcsize = bufsize; + + std::vector outbuf(m_pointSize); + while (m_numPoints--) + { + m_decompressor->decompress(outbuf.data()); + m_cb(outbuf.data(), m_pointSize); + } + } + +private: + typedef laszip::decoders::arithmetic Decoder; + Decoder m_decoder; + typedef typename laszip::formats::dynamic_field_decompressor::ptr + Decompressor; + Decompressor m_decompressor; + BlockCb m_cb; + size_t m_numPoints; + const char *m_srcbuf; + size_t m_srcsize; + size_t m_pointSize; +}; + +LazPerfDecompressor::LazPerfDecompressor(BlockCb cb, const DimTypeList& dims, + size_t numPoints) : + m_impl(new LazPerfDecompressorImpl(cb, dims, numPoints)) +{} + + +LazPerfDecompressor::~LazPerfDecompressor() +{} + + +void LazPerfDecompressor::decompress(const char *buf, size_t bufsize) +{ + m_impl->decompress(buf, bufsize); +} + +} // namespace pdal + diff --git a/pdal/compression/LazPerfCompression.hpp b/pdal/compression/LazPerfCompression.hpp index 05aa41fe44..98f81610c8 100644 --- a/pdal/compression/LazPerfCompression.hpp +++ b/pdal/compression/LazPerfCompression.hpp @@ -33,394 +33,46 @@ ****************************************************************************/ #pragma once -#ifdef PDAL_HAVE_LAZPERF -#include -#include - -#include -#include -#include - -#include -#include -#include -#include -#include - #include "Compression.hpp" -#endif // PDAL_HAVE_LAZPERF - -namespace pdal -{ - -#ifdef PDAL_HAVE_LAZPERF -namespace -{ - -template -size_t addFields(LasZipEngine& engine, const DimTypeList& dims) -{ - using namespace Dimension; - - size_t pointSize = 0; - for (auto di = dims.begin(); di != dims.end(); ++di) - { - switch (di->m_type) - { - case Type::Signed64: - engine->template add_field(); - engine->template add_field(); - break; - case Type::Signed32: - case Type::Float: - engine->template add_field(); - break; - case Type::Signed16: - engine->template add_field(); - break; - case Type::Signed8: - engine->template add_field(); - break; - case Type::Unsigned64: - case Type::Double: - engine->template add_field(); - engine->template add_field(); - break; - case Type::Unsigned32: - engine->template add_field(); - break; - case Type::Unsigned16: - engine->template add_field(); - break; - case Type::Unsigned8: - engine->template add_field(); - break; - default: - return 0; - } - pointSize += Dimension::size(di->m_type); - } - return pointSize; -} - -} // anonymous namespace - - -// This compressor write data in chunks to a stream. At the beginning of the -// data is an offset to the end of the data, where the chunk table is -// stored. The chunk table keeps a list of the offsets to the beginning of -// each chunk. Chunks consist of a fixed number of points (last chunk may -// have fewer points). Each time a chunk starts, the compressor is reset. -// This allows decompression of some set of points that's less than the -// entire set when desired. -// The compressor uses the schema of the point data in order to compress -// the point stream. The schema is also stored in a VLR that isn't -// handled as part of the compression process itself. -class LazPerfVlrCompressor -{ - typedef laszip::io::__ofstream_wrapper OutputStream; - typedef laszip::encoders::arithmetic Encoder; - typedef laszip::formats::dynamic_compressor Compressor; - typedef laszip::factory::record_schema Schema; - -public: - LazPerfVlrCompressor(std::ostream& stream, const Schema& schema, - uint32_t chunksize) : - m_stream(stream), m_outputStream(stream), m_schema(schema), - m_chunksize(chunksize), m_chunkPointsWritten(0), m_chunkInfoPos(0), - m_chunkOffset(0) - {} - - ~LazPerfVlrCompressor() - { - if (m_encoder) - std::cerr << "LazPerfVlrCompressor destroyed without a call " - "to done()"; - } - - - void compress(const char *inbuf) - { - // First time through. - if (!m_encoder || !m_compressor) - { - // Get the position - m_chunkInfoPos = m_stream.tellp(); - // Seek over the chunk info offset value - m_stream.seekp(sizeof(uint64_t), std::ios::cur); - m_chunkOffset = m_stream.tellp(); - resetCompressor(); - } - else if (m_chunkPointsWritten == m_chunksize) - { - resetCompressor(); - newChunk(); - } - m_compressor->compress(inbuf); - m_chunkPointsWritten++; - } - - void done() - { - // Close and clear the point encoder. - m_encoder->done(); - m_encoder.reset(); - - newChunk(); - - // Save our current position. Go to the location where we need - // to write the chunk table offset at the beginning of the point data. - std::streampos chunkTablePos = m_stream.tellp(); - m_stream.seekp(m_chunkInfoPos); - OLeStream out(&m_stream); - out << (uint64_t)chunkTablePos; - - // Move to the start of the chunk table. - m_stream.seekp(chunkTablePos); - - // Write the chunk table header. - out << (uint32_t)0; // Version (?) - out << (uint32_t)m_chunkTable.size(); - - // Encode and write the chunk table. - OutputStream outputStream(m_stream); - Encoder encoder(outputStream); - laszip::compressors::integer compressor(32, 2); - compressor.init(); - - uint32_t predictor = 0; - for (uint32_t offset : m_chunkTable) - { - offset = htole32(offset); - compressor.compress(encoder, predictor, offset, 1); - predictor = offset; - } - encoder.done(); - } - -private: - void resetCompressor() - { - if (m_encoder) - m_encoder->done(); - m_encoder.reset(new Encoder(m_outputStream)); - m_compressor = laszip::factory::build_compressor(*m_encoder, m_schema); - } - - void newChunk() - { - std::streampos offset = m_stream.tellp(); - m_chunkTable.push_back((uint32_t)(offset - m_chunkOffset)); - m_chunkOffset = offset; - m_chunkPointsWritten = 0; - } - - std::ostream& m_stream; - OutputStream m_outputStream; - std::unique_ptr m_encoder; - Compressor::ptr m_compressor; - Schema m_schema; - uint32_t m_chunksize; - uint32_t m_chunkPointsWritten; - std::streampos m_chunkInfoPos; - std::streampos m_chunkOffset; - std::vector m_chunkTable; -}; +#include -class LazPerfVlrDecompressor +namespace pdal { -public: - LazPerfVlrDecompressor(std::istream& stream, const char *vlrData, - std::streamoff pointOffset) : - m_stream(stream), m_inputStream(stream), m_chunksize(0), - m_chunkPointsRead(0) - { - laszip::io::laz_vlr zipvlr(vlrData); - m_chunksize = zipvlr.chunk_size; - m_schema = laszip::io::laz_vlr::to_schema(zipvlr); - m_stream.seekg(pointOffset + sizeof(int64_t)); - } - - size_t pointSize() const - { return (size_t)m_schema.size_in_bytes(); } - - void decompress(char *outbuf) - { - if (m_chunkPointsRead == m_chunksize || !m_decoder || !m_decompressor) - { - resetDecompressor(); - m_chunkPointsRead = 0; - } - m_decompressor->decompress(outbuf); - m_chunkPointsRead++; - } - -private: - void resetDecompressor() - { - m_decoder.reset(new Decoder(m_inputStream)); - m_decompressor = - laszip::factory::build_decompressor(*m_decoder, m_schema); - } - - typedef laszip::io::__ifstream_wrapper InputStream; - typedef laszip::decoders::arithmetic Decoder; - typedef laszip::formats::dynamic_decompressor Decompressor; - typedef laszip::factory::record_schema Schema; - - std::istream& m_stream; - InputStream m_inputStream; - std::unique_ptr m_decoder; - Decompressor::ptr m_decompressor; - Schema m_schema; - uint32_t m_chunksize; - uint32_t m_chunkPointsRead; -}; +class LazPerfCompressorImpl; class LazPerfCompressor : public Compressor { public: - LazPerfCompressor(BlockCb cb, const DimTypeList& dims) : - m_cb(cb), - m_encoder(*this), - m_compressor(laszip::formats::make_dynamic_compressor(m_encoder)), - m_pointSize(0), - m_avail(CHUNKSIZE) - { m_pointSize = addFields(m_compressor, dims); } - - ~LazPerfCompressor() - { - } - - void putBytes(const uint8_t* buf, size_t bufsize) - { - while (bufsize) - { - size_t copyCnt = std::min(m_avail, bufsize); - std::copy(buf, buf + copyCnt, m_tmpbuf + (CHUNKSIZE - m_avail)); - m_avail -= copyCnt; - if (m_avail == 0) - { - m_cb(reinterpret_cast(m_tmpbuf), CHUNKSIZE); - m_avail = CHUNKSIZE; - } - buf += copyCnt; - bufsize -= copyCnt; - } - } - - void putByte(unsigned char b) - { - m_tmpbuf[CHUNKSIZE - m_avail] = b; - if (--m_avail == 0) - { - m_cb(reinterpret_cast(m_tmpbuf), CHUNKSIZE); - m_avail = CHUNKSIZE; - } - } + PDAL_DLL LazPerfCompressor(BlockCb cb, const DimTypeList& dims); + PDAL_DLL ~LazPerfCompressor(); - void compress(const char *buf, size_t bufsize) - { - while (bufsize >= m_pointSize) - { - m_compressor->compress(buf); - buf += m_pointSize; - bufsize -= m_pointSize; - } - } - - void done() - { - m_encoder.done(); - if (m_avail != CHUNKSIZE) - m_cb(reinterpret_cast(m_tmpbuf), CHUNKSIZE - m_avail); - m_avail = CHUNKSIZE; - } + PDAL_DLL void compress(const char *buf, size_t bufsize); + PDAL_DLL void done(); private: - BlockCb m_cb; - typedef laszip::encoders::arithmetic Encoder; - Encoder m_encoder; - typedef typename laszip::formats::dynamic_field_compressor::ptr - Compressor; - Compressor m_compressor; - size_t m_pointSize; - unsigned char m_tmpbuf[CHUNKSIZE]; - size_t m_avail; + std::unique_ptr m_impl; }; +class LazPerfDecompressorImpl; + // NOTE - The LazPerfDecompressor is different from others, even though the // interface is the same, in that it always executes the callback after // a point's worth of data is read. class LazPerfDecompressor : public Decompressor { public: - LazPerfDecompressor(BlockCb cb, const DimTypeList& dims, - size_t numPoints) : - m_decoder(*this), - m_decompressor(laszip::formats::make_dynamic_decompressor(m_decoder)), - m_cb(cb), - m_numPoints(numPoints) - { m_pointSize = addFields(m_decompressor, dims); } - - unsigned char getByte() - { - if (m_srcsize) - { - m_srcsize--; - return *m_srcbuf++; - } - return 0; - } + PDAL_DLL LazPerfDecompressor(BlockCb cb, const DimTypeList& dims, + size_t numPoints); + PDAL_DLL ~LazPerfDecompressor(); - void getBytes(uint8_t *dst, size_t dstsize) - { - size_t count = std::min(dstsize, m_srcsize); - uint8_t *src = const_cast( - reinterpret_cast(m_srcbuf)); - std::copy(src, src + count, dst); - m_srcbuf += count; - m_srcsize -= count; - } - - void decompress(const char *buf, size_t bufsize) - { - m_srcbuf = buf; - m_srcsize = bufsize; - - std::vector outbuf(m_pointSize); - while (m_numPoints--) - { - m_decompressor->decompress(outbuf.data()); - m_cb(outbuf.data(), m_pointSize); - } - } - - void done() - {} + PDAL_DLL void decompress(const char *buf, size_t bufsize); private: - typedef laszip::decoders::arithmetic Decoder; - Decoder m_decoder; - typedef typename laszip::formats::dynamic_field_decompressor::ptr - Decompressor; - Decompressor m_decompressor; - BlockCb m_cb; - size_t m_numPoints; - const char *m_srcbuf; - size_t m_srcsize; - size_t m_pointSize; + std::unique_ptr m_impl; }; -#else - -typedef char LazPerfVlrCompressor; -typedef char LazPerfVlrDecompressor; - -#endif // PDAL_HAVE_LAZPERF - } // namespace pdal diff --git a/pdal/compression/LazPerfVlrCompression.cpp b/pdal/compression/LazPerfVlrCompression.cpp new file mode 100644 index 0000000000..428277302b --- /dev/null +++ b/pdal/compression/LazPerfVlrCompression.cpp @@ -0,0 +1,266 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 +#include +#include + +#include +#include +#include +#include +#include + +#include "LazPerfVlrCompression.hpp" + +namespace pdal +{ + +// This compressor write data in chunks to a stream. At the beginning of the +// data is an offset to the end of the data, where the chunk table is +// stored. The chunk table keeps a list of the offsets to the beginning of +// each chunk. Chunks consist of a fixed number of points (last chunk may +// have fewer points). Each time a chunk starts, the compressor is reset. +// This allows decompression of some set of points that's less than the +// entire set when desired. +// The compressor uses the schema of the point data in order to compress +// the point stream. The schema is also stored in a VLR that isn't +// handled as part of the compression process itself. +class LazPerfVlrCompressorImpl +{ + typedef laszip::io::__ofstream_wrapper OutputStream; + typedef laszip::encoders::arithmetic Encoder; + typedef laszip::formats::dynamic_compressor Compressor; + typedef laszip::factory::record_schema Schema; + +public: + LazPerfVlrCompressorImpl(std::ostream& stream, const Schema& schema, + uint32_t chunksize) : + m_stream(stream), m_outputStream(stream), m_schema(schema), + m_chunksize(chunksize), m_chunkPointsWritten(0), m_chunkInfoPos(0), + m_chunkOffset(0) + {} + + ~LazPerfVlrCompressorImpl() + { + if (m_encoder) + std::cerr << "LazPerfVlrCompressor destroyed without a call " + "to done()"; + } + + + void compress(const char *inbuf) + { + // First time through. + if (!m_encoder || !m_compressor) + { + // Get the position + m_chunkInfoPos = m_stream.tellp(); + // Seek over the chunk info offset value + m_stream.seekp(sizeof(uint64_t), std::ios::cur); + m_chunkOffset = m_stream.tellp(); + resetCompressor(); + } + else if (m_chunkPointsWritten == m_chunksize) + { + resetCompressor(); + newChunk(); + } + m_compressor->compress(inbuf); + m_chunkPointsWritten++; + } + + void done() + { + // Close and clear the point encoder. + m_encoder->done(); + m_encoder.reset(); + + newChunk(); + + // Save our current position. Go to the location where we need + // to write the chunk table offset at the beginning of the point data. + std::streampos chunkTablePos = m_stream.tellp(); + m_stream.seekp(m_chunkInfoPos); + OLeStream out(&m_stream); + out << (uint64_t)chunkTablePos; + + // Move to the start of the chunk table. + m_stream.seekp(chunkTablePos); + + // Write the chunk table header. + out << (uint32_t)0; // Version (?) + out << (uint32_t)m_chunkTable.size(); + + // Encode and write the chunk table. + OutputStream outputStream(m_stream); + Encoder encoder(outputStream); + laszip::compressors::integer compressor(32, 2); + compressor.init(); + + uint32_t predictor = 0; + for (uint32_t offset : m_chunkTable) + { + offset = htole32(offset); + compressor.compress(encoder, predictor, offset, 1); + predictor = offset; + } + encoder.done(); + } + +private: + void resetCompressor() + { + if (m_encoder) + m_encoder->done(); + m_encoder.reset(new Encoder(m_outputStream)); + m_compressor = laszip::factory::build_compressor(*m_encoder, m_schema); + } + + void newChunk() + { + std::streampos offset = m_stream.tellp(); + m_chunkTable.push_back((uint32_t)(offset - m_chunkOffset)); + m_chunkOffset = offset; + m_chunkPointsWritten = 0; + } + + std::ostream& m_stream; + OutputStream m_outputStream; + std::unique_ptr m_encoder; + Compressor::ptr m_compressor; + Schema m_schema; + uint32_t m_chunksize; + uint32_t m_chunkPointsWritten; + std::streampos m_chunkInfoPos; + std::streampos m_chunkOffset; + std::vector m_chunkTable; +}; + + +LazPerfVlrCompressor::LazPerfVlrCompressor(std::ostream& stream, + const Schema& schema, uint32_t chunksize) : + m_impl(new LazPerfVlrCompressorImpl(stream, schema, chunksize)) +{} + + +LazPerfVlrCompressor::~LazPerfVlrCompressor() +{} + + +void LazPerfVlrCompressor::compress(const char *inbuf) +{ + m_impl->compress(inbuf); +} + + +void LazPerfVlrCompressor::done() +{ + m_impl->done(); +} + + +class LazPerfVlrDecompressorImpl +{ +public: + LazPerfVlrDecompressorImpl(std::istream& stream, const char *vlrData, + std::streamoff pointOffset) : + m_stream(stream), m_inputStream(stream), m_chunksize(0), + m_chunkPointsRead(0) + { + laszip::io::laz_vlr zipvlr(vlrData); + m_chunksize = zipvlr.chunk_size; + m_schema = laszip::io::laz_vlr::to_schema(zipvlr); + m_stream.seekg(pointOffset + sizeof(int64_t)); + } + + size_t pointSize() const + { return (size_t)m_schema.size_in_bytes(); } + + void decompress(char *outbuf) + { + if (m_chunkPointsRead == m_chunksize || !m_decoder || !m_decompressor) + { + resetDecompressor(); + m_chunkPointsRead = 0; + } + m_decompressor->decompress(outbuf); + m_chunkPointsRead++; + } + +private: + void resetDecompressor() + { + m_decoder.reset(new Decoder(m_inputStream)); + m_decompressor = + laszip::factory::build_decompressor(*m_decoder, m_schema); + } + + typedef laszip::io::__ifstream_wrapper InputStream; + typedef laszip::decoders::arithmetic Decoder; + typedef laszip::formats::dynamic_decompressor Decompressor; + typedef laszip::factory::record_schema Schema; + + std::istream& m_stream; + InputStream m_inputStream; + std::unique_ptr m_decoder; + Decompressor::ptr m_decompressor; + Schema m_schema; + uint32_t m_chunksize; + uint32_t m_chunkPointsRead; +}; + +LazPerfVlrDecompressor::LazPerfVlrDecompressor(std::istream& stream, + const char *vlrData, std::streamoff pointOffset) : + m_impl(new LazPerfVlrDecompressorImpl(stream, vlrData, pointOffset)) +{} + + +LazPerfVlrDecompressor::~LazPerfVlrDecompressor() +{} + + +size_t LazPerfVlrDecompressor::pointSize() const +{ + return m_impl->pointSize(); +} + + +void LazPerfVlrDecompressor::decompress(char *outbuf) +{ + m_impl->decompress(outbuf); +} + +} // namespace pdal + diff --git a/pdal/compression/LazPerfVlrCompression.hpp b/pdal/compression/LazPerfVlrCompression.hpp new file mode 100644 index 0000000000..75c81b9594 --- /dev/null +++ b/pdal/compression/LazPerfVlrCompression.hpp @@ -0,0 +1,95 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 + +#include +#include + +namespace laszip +{ +namespace factory +{ + struct record_schema; +} +} + +namespace pdal +{ + class LazPerfVlrCompressorImpl; + +// This compressor write data in chunks to a stream. At the beginning of the +// data is an offset to the end of the data, where the chunk table is +// stored. The chunk table keeps a list of the offsets to the beginning of +// each chunk. Chunks consist of a fixed number of points (last chunk may +// have fewer points). Each time a chunk starts, the compressor is reset. +// This allows decompression of some set of points that's less than the +// entire set when desired. +// The compressor uses the schema of the point data in order to compress +// the point stream. The schema is also stored in a VLR that isn't +// handled as part of the compression process itself. +class LazPerfVlrCompressor +{ + typedef laszip::factory::record_schema Schema; + +public: + PDAL_DLL LazPerfVlrCompressor(std::ostream& stream, const Schema& schema, + uint32_t chunksize); + PDAL_DLL ~LazPerfVlrCompressor(); + + PDAL_DLL void compress(const char *inbuf); + PDAL_DLL void done(); + +private: + std::unique_ptr m_impl; +}; + + +class LazPerfVlrDecompressorImpl; + +class LazPerfVlrDecompressor +{ +public: + PDAL_DLL LazPerfVlrDecompressor(std::istream& stream, const char *vlrData, + std::streamoff pointOffset); + PDAL_DLL ~LazPerfVlrDecompressor(); + + PDAL_DLL size_t pointSize() const; + PDAL_DLL void decompress(char *outbuf); + +private: + std::unique_ptr m_impl; +}; + +} // namespace pdal + diff --git a/pdal/compression/LzmaCompression.cpp b/pdal/compression/LzmaCompression.cpp new file mode 100644 index 0000000000..1377ac7877 --- /dev/null +++ b/pdal/compression/LzmaCompression.cpp @@ -0,0 +1,178 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 "LzmaCompression.hpp" + +#include + +namespace pdal +{ + +class Lzma +{ +protected: + Lzma(BlockCb cb) : m_cb(cb) + { + m_strm = LZMA_STREAM_INIT; + } + + ~Lzma() + { + lzma_end(&m_strm); + } + + void run(const char *buf, size_t bufsize, lzma_action mode) + { + m_strm.avail_in = bufsize; + m_strm.next_in = reinterpret_cast( + const_cast(buf)); + int ret = LZMA_OK; + do + { + m_strm.avail_out = CHUNKSIZE; + m_strm.next_out = m_tmpbuf; + ret = lzma_code(&m_strm, mode); + size_t written = CHUNKSIZE - m_strm.avail_out; + if (written) + m_cb(reinterpret_cast(m_tmpbuf), written); + } while (ret == LZMA_OK); + if (ret == LZMA_STREAM_END) + return; + + switch (ret) + { + case LZMA_MEM_ERROR: + throw compression_error("Memory allocation failure."); + case LZMA_DATA_ERROR: + throw compression_error("LZMA data error."); + case LZMA_OPTIONS_ERROR: + throw compression_error("Unsupported option."); + case LZMA_UNSUPPORTED_CHECK: + throw compression_error("Unsupported integrity check."); + } + } + +protected: + lzma_stream m_strm; + +private: + unsigned char m_tmpbuf[CHUNKSIZE]; + BlockCb m_cb; +}; + + +class LzmaCompressorImpl : public Lzma +{ +public: + LzmaCompressorImpl(BlockCb cb) : Lzma(cb) + { + if (lzma_easy_encoder(&m_strm, 2, LZMA_CHECK_CRC64) != LZMA_OK) + throw compression_error("Can't create compressor"); + } + + void compress(const char *buf, size_t bufsize) + { + run(buf, bufsize, LZMA_RUN); + } + + void done() + { + run(nullptr, 0, LZMA_FINISH); + } +}; + + +LzmaCompressor::LzmaCompressor(BlockCb cb) : + m_impl(new LzmaCompressorImpl(cb)) +{} + + +LzmaCompressor::~LzmaCompressor() +{} + + +void LzmaCompressor::compress(const char *buf, size_t bufsize) +{ + m_impl->compress(buf, bufsize); +} + + +void LzmaCompressor::done() +{ + m_impl->done(); +} + + +class LzmaDecompressorImpl : public Lzma +{ +public: + LzmaDecompressorImpl(BlockCb cb) : Lzma(cb) + { + if (lzma_auto_decoder(&m_strm, std::numeric_limits::max(), + LZMA_TELL_UNSUPPORTED_CHECK)) + throw compression_error("Can't create decompressor"); + } + + void decompress(const char *buf, size_t bufsize) + { + run(buf, bufsize, LZMA_RUN); + } + + void done() + { + run(nullptr, 0, LZMA_FINISH); + } +}; + +LzmaDecompressor::LzmaDecompressor(BlockCb cb) : + m_impl(new LzmaDecompressorImpl(cb)) +{} + + +LzmaDecompressor::~LzmaDecompressor() +{} + + +void LzmaDecompressor::decompress(const char *buf, size_t bufsize) +{ + m_impl->decompress(buf, bufsize); +} + + +void LzmaDecompressor::done() +{ + m_impl->done(); +} + +} // namespace pdal diff --git a/pdal/compression/LzmaCompression.hpp b/pdal/compression/LzmaCompression.hpp index ca9e05592c..944b5a9d9d 100644 --- a/pdal/compression/LzmaCompression.hpp +++ b/pdal/compression/LzmaCompression.hpp @@ -33,110 +33,39 @@ ****************************************************************************/ #pragma once -#ifdef PDAL_HAVE_LZMA - #include "Compression.hpp" -#include - namespace pdal { -class Lzma +class LzmaCompressorImpl; +class LzmaCompressor : public Compressor { -protected: - Lzma(BlockCb cb) : m_cb(cb) - { - m_strm = LZMA_STREAM_INIT; - } - - ~Lzma() - { - lzma_end(&m_strm); - } - - void run(const char *buf, size_t bufsize, lzma_action mode) - { - m_strm.avail_in = bufsize; - m_strm.next_in = reinterpret_cast( - const_cast(buf)); - int ret = LZMA_OK; - do - { - m_strm.avail_out = CHUNKSIZE; - m_strm.next_out = m_tmpbuf; - ret = lzma_code(&m_strm, mode); - size_t written = CHUNKSIZE - m_strm.avail_out; - if (written) - m_cb(reinterpret_cast(m_tmpbuf), written); - } while (ret == LZMA_OK); - if (ret == LZMA_STREAM_END) - return; - - switch (ret) - { - case LZMA_MEM_ERROR: - throw compression_error("Memory allocation failure."); - case LZMA_DATA_ERROR: - throw compression_error("LZMA data error."); - case LZMA_OPTIONS_ERROR: - throw compression_error("Unsupported option."); - case LZMA_UNSUPPORTED_CHECK: - throw compression_error("Unsupported integrity check."); - } - } +public: + PDAL_DLL LzmaCompressor(BlockCb cb); + PDAL_DLL ~LzmaCompressor(); -protected: - lzma_stream m_strm; + PDAL_DLL void compress(const char *buf, size_t bufsize); + PDAL_DLL void done(); private: - unsigned char m_tmpbuf[CHUNKSIZE]; - BlockCb m_cb; + std::unique_ptr m_impl; }; -class LzmaCompressor : public Compressor, public Lzma -{ -public: - LzmaCompressor(BlockCb cb) : Lzma(cb) - { - if (lzma_easy_encoder(&m_strm, 2, LZMA_CHECK_CRC64) != LZMA_OK) - throw compression_error("Can't create compressor"); - } - - void compress(const char *buf, size_t bufsize) - { - run(buf, bufsize, LZMA_RUN); - } - - void done() - { - run(nullptr, 0, LZMA_FINISH); - } -}; +class LzmaDecompressorImpl; - -class LzmaDecompressor : public Decompressor, public Lzma +class LzmaDecompressor : public Decompressor { public: - LzmaDecompressor(BlockCb cb) : Lzma(cb) - { - if (lzma_auto_decoder(&m_strm, std::numeric_limits::max(), - LZMA_TELL_UNSUPPORTED_CHECK)) - throw compression_error("Can't create decompressor"); - } + PDAL_DLL LzmaDecompressor(BlockCb cb); + PDAL_DLL ~LzmaDecompressor(); - void decompress(const char *buf, size_t bufsize) - { - run(buf, bufsize, LZMA_RUN); - } + PDAL_DLL void decompress(const char *buf, size_t bufsize); + PDAL_DLL void done(); - void done() - { - run(nullptr, 0, LZMA_FINISH); - } +private: + std::unique_ptr m_impl; }; } // namespace pdal - -#endif // PDAL_HAVE_LZMA diff --git a/pdal/compression/ZstdCompression.cpp b/pdal/compression/ZstdCompression.cpp new file mode 100644 index 0000000000..1b8aec0cd7 --- /dev/null +++ b/pdal/compression/ZstdCompression.cpp @@ -0,0 +1,170 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 "ZstdCompression.hpp" + +#include + +namespace pdal +{ + +class ZstdCompressorImpl +{ +public: + ZSTD_CStream *m_strm; + ZSTD_inBuffer m_inBuf; + char m_tmpbuf[CHUNKSIZE]; + BlockCb m_cb; + + ZstdCompressorImpl(BlockCb cb) : m_cb(cb) + { + m_strm = ZSTD_createCStream(); + ZSTD_initCStream(m_strm, 15); + } + + ~ZstdCompressorImpl() + { ZSTD_freeCStream(m_strm); } + + void compress(const char *buf, size_t bufsize) + { + m_inBuf.src = reinterpret_cast(buf); + m_inBuf.size = bufsize; + m_inBuf.pos = 0; + + size_t ret; + do + { + ZSTD_outBuffer outBuf + { reinterpret_cast(m_tmpbuf), CHUNKSIZE, 0 }; + ret = ZSTD_compressStream(m_strm, &outBuf, &m_inBuf); + if (ZSTD_isError(ret)) + break; + if (outBuf.pos) + m_cb(m_tmpbuf, outBuf.pos); + } while (m_inBuf.pos != m_inBuf.size); + } + + void done() + { + size_t ret; + do + { + ZSTD_outBuffer outBuf + { reinterpret_cast(m_tmpbuf), CHUNKSIZE, 0 }; + ret = ZSTD_endStream(m_strm, &outBuf); + if (ZSTD_isError(ret)) + break; + if (outBuf.pos) + m_cb(m_tmpbuf, outBuf.pos); + } while (ret); + } +}; + +ZstdCompressor::ZstdCompressor(BlockCb cb) : + m_impl(new ZstdCompressorImpl(cb)) +{} + + +ZstdCompressor::~ZstdCompressor() +{} + + +void ZstdCompressor::compress(const char *buf, size_t bufsize) +{ + m_impl->compress(buf, bufsize); +} + + +void ZstdCompressor::done() +{ + m_impl->done(); +} + + +class ZstdDecompressorImpl +{ +public: + ZstdDecompressorImpl(BlockCb cb) : m_cb(cb) + { + m_strm = ZSTD_createDStream(); + ZSTD_initDStream(m_strm); + } + + ~ZstdDecompressorImpl() + { + ZSTD_freeDStream(m_strm); + } + + void decompress(const char *buf, size_t bufsize) + { + m_inBuf.src = reinterpret_cast(buf); + m_inBuf.size = bufsize; + m_inBuf.pos = 0; + + size_t ret; + do + { + ZSTD_outBuffer outBuf + { reinterpret_cast(m_tmpbuf), CHUNKSIZE, 0 }; + ret = ZSTD_decompressStream(m_strm, &outBuf, &m_inBuf); + if (ZSTD_isError(ret)) + break; + if (outBuf.pos) + m_cb(m_tmpbuf, outBuf.pos); + } while (m_inBuf.pos != m_inBuf.size); + } + +private: + BlockCb m_cb; + + ZSTD_DStream *m_strm; + ZSTD_inBuffer m_inBuf; + char m_tmpbuf[CHUNKSIZE]; +}; + +ZstdDecompressor::ZstdDecompressor(BlockCb cb) : + m_impl(new ZstdDecompressorImpl(cb)) +{} + + +ZstdDecompressor::~ZstdDecompressor() +{} + + +void ZstdDecompressor::decompress(const char *buf, size_t bufsize) +{ + m_impl->decompress(buf, bufsize); +} + +} // namespace pdal diff --git a/pdal/compression/ZstdCompression.hpp b/pdal/compression/ZstdCompression.hpp index 237eeeaf7f..624423e4ce 100644 --- a/pdal/compression/ZstdCompression.hpp +++ b/pdal/compression/ZstdCompression.hpp @@ -33,114 +33,41 @@ ****************************************************************************/ #pragma once -#ifdef PDAL_HAVE_ZSTD - #include "Compression.hpp" -#include - namespace pdal { +class ZstdCompressorImpl; + class ZstdCompressor : public Compressor { public: - ZstdCompressor(BlockCb cb) : m_cb(cb) - { - m_strm = ZSTD_createCStream(); - ZSTD_initCStream(m_strm, 15); - } - - ~ZstdCompressor() - { ZSTD_freeCStream(m_strm); } - - - void compress(const char *buf, size_t bufsize) - { - m_inBuf.src = reinterpret_cast(buf); - m_inBuf.size = bufsize; - m_inBuf.pos = 0; - - size_t ret; - do - { - ZSTD_outBuffer outBuf - { reinterpret_cast(m_tmpbuf), CHUNKSIZE, 0 }; - ret = ZSTD_compressStream(m_strm, &outBuf, &m_inBuf); - if (ZSTD_isError(ret)) - break; - if (outBuf.pos) - m_cb(m_tmpbuf, outBuf.pos); - } while (m_inBuf.pos != m_inBuf.size); - } + PDAL_DLL ZstdCompressor(BlockCb cb); + PDAL_DLL ~ZstdCompressor(); - void done() - { - size_t ret; - do - { - ZSTD_outBuffer outBuf - { reinterpret_cast(m_tmpbuf), CHUNKSIZE, 0 }; - ret = ZSTD_endStream(m_strm, &outBuf); - if (ZSTD_isError(ret)) - break; - if (outBuf.pos) - m_cb(m_tmpbuf, outBuf.pos); - } while (ret); - } + PDAL_DLL void compress(const char *buf, size_t bufsize); + PDAL_DLL void done(); private: - BlockCb m_cb; - - ZSTD_CStream *m_strm; - ZSTD_inBuffer m_inBuf; - char m_tmpbuf[CHUNKSIZE]; + std::unique_ptr m_impl; }; +class ZstdDecompressorImpl; + class ZstdDecompressor : public Decompressor { public: - ZstdDecompressor(BlockCb cb) : m_cb(cb) - { - m_strm = ZSTD_createDStream(); - ZSTD_initDStream(m_strm); - } - - ~ZstdDecompressor() - { - ZSTD_freeDStream(m_strm); - } + PDAL_DLL ZstdDecompressor(BlockCb cb); + PDAL_DLL ~ZstdDecompressor(); - void decompress(const char *buf, size_t bufsize) - { - m_inBuf.src = reinterpret_cast(buf); - m_inBuf.size = bufsize; - m_inBuf.pos = 0; - - size_t ret; - do - { - ZSTD_outBuffer outBuf - { reinterpret_cast(m_tmpbuf), CHUNKSIZE, 0 }; - ret = ZSTD_decompressStream(m_strm, &outBuf, &m_inBuf); - if (ZSTD_isError(ret)) - break; - if (outBuf.pos) - m_cb(m_tmpbuf, outBuf.pos); - } while (m_inBuf.pos != m_inBuf.size); - } - - void done() + PDAL_DLL void decompress(const char *buf, size_t bufsize); + PDAL_DLL void done() {} private: - BlockCb m_cb; - - ZSTD_DStream *m_strm; - ZSTD_inBuffer m_inBuf; - char m_tmpbuf[CHUNKSIZE]; + std::unique_ptr m_impl; }; } // namespace pdal -#endif // PDAL_HAVE_ZSTD diff --git a/pdal/pdal_config.cpp b/pdal/pdal_config.cpp index 7aa6dc52d4..6f1f6a45a9 100644 --- a/pdal/pdal_config.cpp +++ b/pdal/pdal_config.cpp @@ -1,14 +1,7 @@ /****************************************************************************** - * $Id$ - * - * Project: libLAS - http://liblas.org - A BSD library for LAS format data. - * Purpose: LAS version related functions. - * Author: Mateusz Loskot, mateusz@loskot.net - * Frank Warmerdam, warmerdam@pobox.com - * - ****************************************************************************** * Copyright (c) 2008, Mateusz Loskot * Copyright (c) 2010, Frank Warmerdam + * Copyright (c) 2018, Hobu Inc. * * All rights reserved. * @@ -42,23 +35,19 @@ ****************************************************************************/ #include +#include #include #include -#include #include #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wfloat-equal" -#endif +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wfloat-equal" #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif +#pragma clang diagnostic pop #include @@ -70,60 +59,101 @@ namespace pdal { - -/// Check if GeoTIFF support has been built in to PDAL -bool IsLibGeoTIFFEnabled() +namespace Config { - return true; -} -/// Check if LasZip compression support has been built in to PDAL -bool IsLasZipEnabled() +bool hasFeature(Feature f) { + bool enabled = false; + switch (f) + { + case Feature::LASZIP: #ifdef PDAL_HAVE_LASZIP - return true; -#else - return false; + enabled = true; #endif + break; + case Feature::LAZPERF: +#ifdef PDAL_HAVE_LAZPERF + enabled = true; +#endif + break; + case Feature::ZSTD: +#ifdef PDAL_HAVE_ZSTD + enabled = true; +#endif + break; + case Feature::ZLIB: +#ifdef PDAL_HAVE_ZLIB + enabled = true; +#endif + break; + case Feature::LZMA: +#ifdef PDAL_HAVE_LZMA + enabled = true; +#endif + break; + case Feature::LIBXML2: +#ifdef PDAL_HAVE_LIBXML2 + enabled = true; +#endif + break; + case Feature::PYTHON: +#ifdef PDAL_HAVE_PYTHON + enabled = true; +#endif + break; + case Feature::ARBITER: +#ifdef PDAL_HAVE_ARBITER + enabled = true; +#endif + break; + default: + break; + } + return enabled; } -int GetVersionMajor() + +int versionMajor() { return PDAL_VERSION_MAJOR; } -int GetVersionMinor() + +int versionMinor() { return PDAL_VERSION_MINOR; } -int GetVersionPatch() + +int versionPatch() { return PDAL_VERSION_PATCH; } -std::string GetVersionString() + +std::string versionString() { return std::string(PDAL_VERSION_STRING); } -int GetVersionInteger() +int versionInteger() { return PDAL_VERSION_INTEGER; } -std::string GetSHA1() +std::string sha1() { return g_GIT_SHA1; } /// Tell the user a bit about PDAL's compilation -std::string GetFullVersionString() +std::string fullVersionString() { std::ostringstream os; - std::string sha = GetSHA1(); + std::string sha = sha1(); if (!Utils::iequals(sha, "Release")) sha = sha.substr(0,6); @@ -133,7 +163,7 @@ std::string GetFullVersionString() } -std::string getPDALDebugInformation() +std::string debugInformation() { Utils::screenWidth(); std::string headline(Utils::screenWidth(), '-'); @@ -146,7 +176,7 @@ std::string getPDALDebugInformation() os << "Version information" << std::endl; os << headline << std::endl; - os << "(" << pdal::GetFullVersionString() << ")" << std::endl; + os << "(" << fullVersionString() << ")" << std::endl; os << std::endl; os << "Debug build status" << std::endl; @@ -173,4 +203,10 @@ std::string getPDALDebugInformation() return os.str(); } +std::string pluginInstallPath() +{ + return PDAL_PLUGIN_INSTALL_PATH; +} + +} // namespace Config } // namespace pdal diff --git a/pdal/pdal_config.hpp b/pdal/pdal_config.hpp index f539af838a..8bf9346c18 100644 --- a/pdal/pdal_config.hpp +++ b/pdal/pdal_config.hpp @@ -1,14 +1,7 @@ /****************************************************************************** - * $Id$ - * - * Project: libLAS - http://liblas.org - A BSD library for LAS format data. - * Purpose: LAS version related functions. - * Author: Mateusz Loskot, mateusz@loskot.net - * Frank Warmerdam, warmerdam@pobox.com - * - ****************************************************************************** * Copyright (c) 2008, Mateusz Loskot * Copyright (c) 2010, Frank Warmerdam + * Copyright (c) 2018, Hobu Inc. * * All rights reserved. * @@ -49,20 +42,33 @@ namespace pdal { +namespace Config +{ -PDAL_DLL bool IsLibLASEnabled(); -PDAL_DLL bool IsGDALEnabled(); -PDAL_DLL bool IsLibGeoTIFFEnabled(); -PDAL_DLL bool IsLasZipEnabled(); +enum class Feature +{ + LASZIP, + LAZPERF, + ZSTD, + ZLIB, + LZMA, + LIBXML2, + PYTHON, + ARBITER +}; -PDAL_DLL std::string GetFullVersionString(); -PDAL_DLL std::string GetVersionString(); -PDAL_DLL int GetVersionInteger(); -PDAL_DLL std::string GetSHA1(); -PDAL_DLL int GetVersionMajor(); -PDAL_DLL int GetVersionMinor(); -PDAL_DLL int GetVersionPatch(); -PDAL_DLL std::string getPDALDebugInformation(); +PDAL_DLL bool hasFeature(Feature f); +PDAL_DLL bool lazPerfEnabled(); +PDAL_DLL std::string fullVersionString(); +PDAL_DLL std::string versionString(); +PDAL_DLL int versionInteger(); +PDAL_DLL std::string sha1(); +PDAL_DLL int versionMajor(); +PDAL_DLL int versionMinor(); +PDAL_DLL int versionPatch(); +PDAL_DLL std::string debugInformation(); +PDAL_DLL std::string pluginInstallPath(); +} // namespace Config } // namespace pdal diff --git a/pdal/pdal_export.hpp b/pdal/pdal_export.hpp index 0c09705793..e6fdbce3b8 100644 --- a/pdal/pdal_export.hpp +++ b/pdal/pdal_export.hpp @@ -34,10 +34,8 @@ #pragma once -#include - #ifndef PDAL_DLL -#if defined(PDAL_COMPILER_MSVC) +#ifdef _WIN32 #if defined(PDAL_DLL_EXPORT) # define PDAL_DLL __declspec(dllexport) #elif defined(PDAL_DLL_IMPORT) @@ -54,7 +52,7 @@ #endif #endif -#ifdef PDAL_COMPILER_MSVC +#ifdef _WIN32 #pragma warning(disable:4251)// [templated class] needs to have dll-interface... #endif diff --git a/pdal/pdal_internal.hpp b/pdal/pdal_internal.hpp index 0138e4a376..c46d222bb5 100644 --- a/pdal/pdal_internal.hpp +++ b/pdal/pdal_internal.hpp @@ -39,7 +39,6 @@ #include #include -#include #include // This is an extraction from the gtest header. It allows us to make test @@ -65,7 +64,7 @@ friend class test_case_name##_##test_name##_Test #endif -#ifdef PDAL_COMPILER_MSVC +#ifdef _WIN32 # pragma warning(disable: 4068) // ignore unknown pragmas (due to boost's use of GCC pragmas) #endif diff --git a/pdal/util/Utils.cpp b/pdal/util/Utils.cpp index 46b94ca597..fd9ae016f7 100644 --- a/pdal/util/Utils.cpp +++ b/pdal/util/Utils.cpp @@ -44,15 +44,13 @@ #include #include #include // WIFEXITED, WEXITSTATUS -#ifdef PDAL_HAVE_EXECINFO_H +#if __has_include() #include // backtrace #endif #include // dladdr #endif -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif +#pragma warning(disable: 4127) // conditional expression is constant #include #include @@ -606,7 +604,8 @@ double Utils::normalizeLongitude(double longitude) std::vector Utils::backtrace() { std::vector lines; -#ifdef PDAL_HAVE_EXECINFO_H +#ifndef _WIN32 +#if __has_include() const int MAX_STACK_SIZE(100); void* buffer[MAX_STACK_SIZE]; std::vector prefixes; @@ -658,6 +657,7 @@ std::vector Utils::backtrace() symbol = prefix + symbol; } } +#endif #endif return lines; } diff --git a/pdal/util/Uuid.hpp b/pdal/util/Uuid.hpp index 8b7b4a33d8..9494e97a16 100644 --- a/pdal/util/Uuid.hpp +++ b/pdal/util/Uuid.hpp @@ -62,10 +62,8 @@ #include "Inserter.hpp" #include "Extractor.hpp" -#ifdef PDAL_COMPILER_MSVC -# pragma warning(push) -# pragma warning(disable: 4267 4244) // ignore conversion warnings -#endif +#pragma warning(push) +#pragma warning(disable: 4267 4244) // ignore conversion warnings namespace pdal @@ -234,7 +232,5 @@ inline std::istream& operator >> (std::istream& in, Uuid& u) } // namespace pdal -#ifdef PDAL_COMPILER_MSVC -# pragma warning(pop) -#endif +#pragma warning(pop) diff --git a/pdal_defines.h.in b/pdal_features.hpp.in similarity index 53% rename from pdal_defines.h.in rename to pdal_features.hpp.in index eb41ef13ad..bf324c2d91 100644 --- a/pdal_defines.h.in +++ b/pdal_features.hpp.in @@ -1,12 +1,10 @@ /* - * pdal_defines.h.in is used by cmake to generate pdal_defines.h + * pdal_features.hpp.in is used by cmake to generate pdal_features.hpp * - * Do not edit pdal_defines.h! + * Do not edit pdal_features.hpp * - * Note this is a C-style header. Do not use C++ syntax. */ -#ifndef PDAL_DEFINES_H -#define PDAL_DEFINES_H +#pragma once /* * version settings @@ -17,8 +15,6 @@ #define PDAL_VERSION_STRING "@PDAL_VERSION_STRING@" -#define PDAL_PLUGIN_VERSION 1 - /* (note this will look yucky until we get to major>=1) */ #define PDAL_VERSION_INTEGER ((PDAL_VERSION_MAJOR*100*100)+(PDAL_VERSION_MINOR*100)+PDAL_VERSION_PATCH) @@ -27,48 +23,20 @@ * availability of 3rd-party libraries */ #cmakedefine PDAL_HAVE_HDF5 -#cmakedefine PDAL_HAVE_LASZIP -#cmakedefine PDAL_HAVE_LAZPERF #cmakedefine PDAL_HAVE_ZSTD #cmakedefine PDAL_HAVE_ZLIB #cmakedefine PDAL_HAVE_LZMA #cmakedefine PDAL_HAVE_LIBXML2 #cmakedefine PDAL_HAVE_PYTHON - #cmakedefine PDAL_ARBITER_ENABLED -/* - * availability of execinfo.h - */ -#cmakedefine PDAL_HAVE_EXECINFO_H - /* * Debug or Release build? */ #define PDAL_BUILD_TYPE "@PDAL_BUILD_TYPE@" -/* - * platform OS - */ -#cmakedefine PDAL_PLATFORM_WIN32 -#cmakedefine PDAL_PLATFORM_OSX -#cmakedefine PDAL_PLATFORM_LINUX - -/* - * platform compiler - */ -#cmakedefine PDAL_COMPILER_MSVC -#cmakedefine PDAL_COMPILER_VC12 -#cmakedefine PDAL_COMPILER_VC11 -#cmakedefine PDAL_COMPILER_VC10 -#cmakedefine PDAL_COMPILER_VC9 -#cmakedefine PDAL_COMPILER_VC8 -#cmakedefine PDAL_COMPILER_GCC -#cmakedefine PDAL_COMPILER_CLANG - /* * built pdal app as application bundle on OSX? */ #cmakedefine PDAL_APP_BUNDLE -#endif diff --git a/plugins/greyhound/io/GreyhoundReader.cpp b/plugins/greyhound/io/GreyhoundReader.cpp index 2596bf8bac..b39fa6bf55 100644 --- a/plugins/greyhound/io/GreyhoundReader.cpp +++ b/plugins/greyhound/io/GreyhoundReader.cpp @@ -34,7 +34,7 @@ #include "GreyhoundReader.hpp" -#include +#include #include #include #include @@ -239,7 +239,7 @@ point_count_t GreyhoundReader::read(PointViewPtr view, point_count_t count) p.z = view->getFieldAs(Dimension::Id::Z, i); if (!obounds.contains(p)) - view->setField(Dimension::Id::Omit, i, true); + view->setField(Dimension::Id::Omit, i, 1); } } diff --git a/plugins/greyhound/io/GreyhoundWriter.cpp b/plugins/greyhound/io/GreyhoundWriter.cpp index 6356f0cb6e..5dd49b264d 100644 --- a/plugins/greyhound/io/GreyhoundWriter.cpp +++ b/plugins/greyhound/io/GreyhoundWriter.cpp @@ -34,6 +34,7 @@ #include "GreyhoundWriter.hpp" +#include #include #include diff --git a/plugins/greyhound/io/point.hpp b/plugins/greyhound/io/point.hpp index 32874cdc89..855dbedd49 100644 --- a/plugins/greyhound/io/point.hpp +++ b/plugins/greyhound/io/point.hpp @@ -269,7 +269,7 @@ class PDAL_DLL Point static Point round(const Point& p) { - return Point(std::llround(p.x), std::llround(p.y), std::llround(p.z)); + return Point(std::round(p.x), std::round(p.y), std::round(p.z)); } double x; diff --git a/plugins/mrsid/test/MrsidTest.cpp b/plugins/mrsid/test/MrsidTest.cpp index abd7de418f..4adfdd562a 100644 --- a/plugins/mrsid/test/MrsidTest.cpp +++ b/plugins/mrsid/test/MrsidTest.cpp @@ -44,10 +44,7 @@ #include -#ifdef PDAL_COMPILER_GCC #pragma GCC diagnostic ignored "-Wsign-compare" -#endif - using namespace pdal; diff --git a/plugins/nitf/io/MetadataReader.cpp b/plugins/nitf/io/MetadataReader.cpp index ee0da9897d..38ae4a7fb0 100644 --- a/plugins/nitf/io/MetadataReader.cpp +++ b/plugins/nitf/io/MetadataReader.cpp @@ -37,15 +37,11 @@ #include #include -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic ignored "-Wenum-compare" -#endif - +#pragma GCC diagnostic ignored "-Wenum-compare" namespace pdal { - MetadataReader::MetadataReader(::nitf::Record& record, MetadataNode& node, bool showEmptyFields) : diff --git a/plugins/nitf/io/MetadataReader.hpp b/plugins/nitf/io/MetadataReader.hpp index c6d2491b0e..6c003c89c9 100644 --- a/plugins/nitf/io/MetadataReader.hpp +++ b/plugins/nitf/io/MetadataReader.hpp @@ -38,35 +38,20 @@ #include -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wredundant-decls" -# pragma GCC diagnostic ignored "-Wextra" -# pragma GCC diagnostic ignored "-Wcast-qual" - // The following pragma doesn't actually work: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653 - //# pragma GCC diagnostic ignored "-Wliteral-suffix" -#endif -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" +#pragma GCC diagnostic ignored "-Wextra" +#pragma GCC diagnostic ignored "-Wcast-qual" #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic pop -#endif +#pragma GCC diagnostic pop namespace pdal { class MetadataNode; } - namespace pdal { diff --git a/plugins/nitf/io/NitfFileReader.hpp b/plugins/nitf/io/NitfFileReader.hpp index 3ee01f983b..64d3b44ff0 100644 --- a/plugins/nitf/io/NitfFileReader.hpp +++ b/plugins/nitf/io/NitfFileReader.hpp @@ -39,28 +39,14 @@ #include -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wredundant-decls" -# pragma GCC diagnostic ignored "-Wextra" -# pragma GCC diagnostic ignored "-Wcast-qual" - // The following pragma doesn't actually work: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653 - //# pragma GCC diagnostic ignored "-Wliteral-suffix" -#endif -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" +#pragma GCC diagnostic ignored "-Wextra" +#pragma GCC diagnostic ignored "-Wcast-qual" #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic pop -#endif +#pragma GCC diagnostic pop namespace pdal { diff --git a/plugins/nitf/io/NitfFileWriter.hpp b/plugins/nitf/io/NitfFileWriter.hpp index 04c1fea3d2..24881d347d 100644 --- a/plugins/nitf/io/NitfFileWriter.hpp +++ b/plugins/nitf/io/NitfFileWriter.hpp @@ -39,28 +39,14 @@ #include -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wredundant-decls" -# pragma GCC diagnostic ignored "-Wextra" -# pragma GCC diagnostic ignored "-Wcast-qual" - // The following pragma doesn't actually work: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653 - //# pragma GCC diagnostic ignored "-Wliteral-suffix" -#endif -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" +#pragma GCC diagnostic ignored "-Wextra" +#pragma GCC diagnostic ignored "-Wcast-qual" #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic pop -#endif +#pragma GCC diagnostic pop namespace pdal { diff --git a/plugins/nitf/io/NitfWriter.cpp b/plugins/nitf/io/NitfWriter.cpp index 565929b132..6bd6196f46 100644 --- a/plugins/nitf/io/NitfWriter.cpp +++ b/plugins/nitf/io/NitfWriter.cpp @@ -41,24 +41,12 @@ #include #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif - #ifndef IMPORT_NITRO_API #define IMPORT_NITRO_API #endif #include #include "tre_plugins.hpp" -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic pop -#endif - // NOTES // // is it legal to write a LAZ file? diff --git a/plugins/nitf/io/tre_plugins.cpp b/plugins/nitf/io/tre_plugins.cpp index 535e16cd25..50987a16eb 100644 --- a/plugins/nitf/io/tre_plugins.cpp +++ b/plugins/nitf/io/tre_plugins.cpp @@ -34,19 +34,10 @@ #include "tre_plugins.hpp" -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic push -# pragma GCC diagnostic ignored "-Wredundant-decls" -# pragma GCC diagnostic ignored "-Wextra" -# pragma GCC diagnostic ignored "-Wcast-qual" - // The following pragma doesn't actually work: - // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61653 - //# pragma GCC diagnostic ignored "-Wliteral-suffix" -#endif -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic push -# pragma clang diagnostic ignored "-Wunused-private-field" -#endif +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wredundant-decls" +#pragma GCC diagnostic ignored "-Wextra" +#pragma GCC diagnostic ignored "-Wcast-qual" #ifndef IMPORT_NITRO_API #define IMPORT_NITRO_API @@ -54,12 +45,7 @@ #include #include -#ifdef PDAL_COMPILER_CLANG -# pragma clang diagnostic pop -#endif -#ifdef PDAL_COMPILER_GCC -# pragma GCC diagnostic pop -#endif +#pragma GCC diagnostic pop namespace pdal { diff --git a/plugins/nitf/test/NitfReaderTest.cpp b/plugins/nitf/test/NitfReaderTest.cpp index 8d2976c0b9..d6673253d4 100644 --- a/plugins/nitf/test/NitfReaderTest.cpp +++ b/plugins/nitf/test/NitfReaderTest.cpp @@ -43,10 +43,7 @@ #include -#ifdef PDAL_COMPILER_GCC #pragma GCC diagnostic ignored "-Wsign-compare" -#endif - using namespace pdal; diff --git a/plugins/oci/io/OciWrapper.cpp b/plugins/oci/io/OciWrapper.cpp index d5a4179019..8fc10e01b2 100644 --- a/plugins/oci/io/OciWrapper.cpp +++ b/plugins/oci/io/OciWrapper.cpp @@ -32,7 +32,7 @@ #include -namespace pdal +namespace pdal { @@ -1764,7 +1764,9 @@ unsigned long OWStatement::GetBlobLength(OCILobLocator* phLocator) return 0; } - return nLength; + // For absurdly long blobs where sizeof(long) < sizeof(long long) this + // is broken. + return (unsigned long)nLength; } bool OWStatement::OpenBlob(OCILobLocator* phLocator, @@ -1853,7 +1855,7 @@ sb4 callback(void *ctxp, void *bufp, oraub8 *lenp, ub1 *piece, void **changed_bufpp, oraub8 *changed_lenp) { - ub4 nbytes(0); + oraub8 nbytes(0); cbctx * ctx = (cbctx *) ctxp; oraub8 amt = (*lenp > ctx->buffer_len) ? ctx->buffer_len : *lenp; oraub8 rem = ctx->length - (ctx->position - 1); @@ -2331,7 +2333,7 @@ const char* OWParseSDO_GEOR_INIT(const char* pszInsert, int nField) pszEnd++; - int nLength = pszEnd - pszStart + 1; + size_t nLength = pszEnd - pszStart + 1; char szBuffer[OWTEXT]; diff --git a/plugins/python/plang/Environment.cpp b/plugins/python/plang/Environment.cpp index 341b21c701..a724d2a6c9 100644 --- a/plugins/python/plang/Environment.cpp +++ b/plugins/python/plang/Environment.cpp @@ -45,9 +45,7 @@ #include #include -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif +#pragma warning(disable: 4127) // conditional expression is constant #include #include diff --git a/plugins/python/plang/Invocation.cpp b/plugins/python/plang/Invocation.cpp index d096110c8a..8aabef60d0 100644 --- a/plugins/python/plang/Invocation.cpp +++ b/plugins/python/plang/Invocation.cpp @@ -35,8 +35,8 @@ #include "Invocation.hpp" #include "Environment.hpp" -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant +#pragma warning(disable: 4127) // conditional expression is constant +#ifdef _WIN32 #define HAVE_ROUND // inconsistent dll linkage otherwise #endif diff --git a/plugins/python/plang/Redirector.cpp b/plugins/python/plang/Redirector.cpp index 778103c87e..ae7ff9b291 100644 --- a/plugins/python/plang/Redirector.cpp +++ b/plugins/python/plang/Redirector.cpp @@ -8,10 +8,8 @@ #include "Redirector.hpp" -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -# pragma warning(disable: 4068) // gcc pragma warnings -#endif +#pragma warning(disable: 4127) // conditional expression is constant +#pragma warning(disable: 4068) // gcc pragma warnings #include #include diff --git a/plugins/python/plang/Redirector.hpp b/plugins/python/plang/Redirector.hpp index 2a34dbada0..10a6576397 100644 --- a/plugins/python/plang/Redirector.hpp +++ b/plugins/python/plang/Redirector.hpp @@ -11,9 +11,8 @@ #pragma once #include -#include -#ifdef PDAL_COMPILER_MSVC +#ifdef _WIN32 # pragma warning(disable: 4127) // conditional expression is constant #ifndef HAVE_ROUND #define HAVE_ROUND // inconsistent dll linkage otherwise diff --git a/plugins/python/plang/Script.cpp b/plugins/python/plang/Script.cpp index a4f4714742..cd7685af41 100644 --- a/plugins/python/plang/Script.cpp +++ b/plugins/python/plang/Script.cpp @@ -34,9 +34,7 @@ #include "../plang/Script.hpp" -#ifdef PDAL_COMPILER_MSVC -# pragma warning(disable: 4127) // conditional expression is constant -#endif +#pragma warning(disable: 4127) // conditional expression is constant namespace pdal { diff --git a/plugins/sqlite/io/SQLiteReader.cpp b/plugins/sqlite/io/SQLiteReader.cpp index 06e9af75ec..9a2f4d79bf 100644 --- a/plugins/sqlite/io/SQLiteReader.cpp +++ b/plugins/sqlite/io/SQLiteReader.cpp @@ -35,6 +35,7 @@ #include "SQLiteReader.hpp" #include +#include #include #include #include diff --git a/plugins/sqlite/io/SQLiteWriter.cpp b/plugins/sqlite/io/SQLiteWriter.cpp index 927aa28cd6..eb82938bc6 100644 --- a/plugins/sqlite/io/SQLiteWriter.cpp +++ b/plugins/sqlite/io/SQLiteWriter.cpp @@ -34,7 +34,7 @@ #include "SQLiteWriter.hpp" -#include +#include #include #include diff --git a/plugins/sqlite/test/SQLiteTest.cpp b/plugins/sqlite/test/SQLiteTest.cpp index cfd0bbe377..328ed8ef84 100644 --- a/plugins/sqlite/test/SQLiteTest.cpp +++ b/plugins/sqlite/test/SQLiteTest.cpp @@ -36,9 +36,8 @@ #include #include - #include -#include +#include #include #include "../io/SQLiteCommon.hpp" @@ -143,24 +142,22 @@ TEST(SQLiteTest, readWrite) testReadWrite(false, false); } -#ifdef PDAL_HAVE_LAZPERF TEST(SQLiteTest, readWriteCompress) { - testReadWrite(true, false); + if (Config::hasFeature(Config::Feature::LAZPERF)) + testReadWrite(true, false); } -#endif TEST(SQLiteTest, readWriteScale) { testReadWrite(false, true); } -#ifdef PDAL_HAVE_LAZPERF TEST(SQLiteTest, readWriteCompressScale) { - testReadWrite(true, true); + if (Config::hasFeature(Config::Feature::LAZPERF)) + testReadWrite(true, true); } -#endif TEST(SQLiteTest, Issue895) { diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index dc690aadaf..3610677794 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -58,7 +58,18 @@ PDAL_ADD_TEST(pdal_streaming_test FILES StreamingTest.cpp) PDAL_ADD_TEST(pdal_support_test FILES SupportTest.cpp) PDAL_ADD_TEST(pdal_utils_test FILES UtilsTest.cpp) PDAL_ADD_TEST(pdal_uuid_test FILES UuidTest.cpp) -PDAL_ADD_TEST(pdal_compression_test FILES CompressionTest.cpp) +if (PDAL_HAVE_LAZ_PERF) +PDAL_ADD_TEST(pdal_lazperf_test FILES LazPerfTest.cpp) +endif() +if (PDAL_HAVE_ZLIB) +PDAL_ADD_TEST(pdal_deflate_test FILES DeflateTest.cpp) +endif() +if (PDAL_HAVE_LZMA) +PDAL_ADD_TEST(pdal_lzma_test FILES LzmaTest.cpp) +endif() +if (PDAL_HAVE_ZSTD) +PDAL_ADD_TEST(pdal_zstd_test FILES ZstdTest.cpp) +endif() # # sources for the native io diff --git a/test/unit/ConfigTest.cpp b/test/unit/ConfigTest.cpp index 45394f3c9b..a23d71215a 100644 --- a/test/unit/ConfigTest.cpp +++ b/test/unit/ConfigTest.cpp @@ -37,13 +37,11 @@ #include using namespace pdal; +using namespace pdal::Config; TEST(ConfigTest, test_3rdparty_libs) { - bool geotiff = IsLibGeoTIFFEnabled(); - bool laszip = IsLasZipEnabled(); - - EXPECT_TRUE(geotiff); + bool laszip = hasFeature(Feature::LASZIP); #ifdef PDAL_HAVE_LASZIP EXPECT_TRUE(laszip); @@ -56,18 +54,18 @@ TEST(ConfigTest, test_version) { // just verify these functions can be called, don't worry about the values - std::string version = GetVersionString(); + std::string version = versionString(); EXPECT_TRUE(!version.empty()); - std::string fullVersion = GetFullVersionString(); + std::string fullVersion = fullVersionString(); EXPECT_TRUE(!fullVersion.empty()); - int major = GetVersionMajor(); + int major = versionMajor(); EXPECT_TRUE(major >= 0); - int minor = GetVersionMinor(); + int minor = versionMinor(); EXPECT_TRUE(minor >= 0); - int patch = GetVersionPatch(); + int patch = versionPatch(); EXPECT_TRUE(patch >= 0); - int bignum = GetVersionInteger(); + int bignum = versionInteger(); EXPECT_TRUE(bignum > 0); } diff --git a/test/unit/DeflateTest.cpp b/test/unit/DeflateTest.cpp new file mode 100644 index 0000000000..123c93eb81 --- /dev/null +++ b/test/unit/DeflateTest.cpp @@ -0,0 +1,84 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 + +#include + +#include + +using namespace pdal; + +TEST(Compression, deflate) +{ + std::default_random_engine generator; + std::uniform_int_distribution dist(std::numeric_limits::min()); + + // Choosing a size that isn't a multiple of the internal buffer. + std::vector orig(1000357); + // Trying to make something that compresses reasonably well. + int val = dist(generator); + for (size_t i = 0; i < orig.size(); ++i) + { + orig[i] = val++; + if (i % 100 == 0) + val = dist(generator); + } + + std::vector compressed; + auto cb = [&compressed](char *buf, size_t bufsize) + { + static size_t total = 0; + compressed.insert(compressed.end(), buf, buf + bufsize); + total += bufsize; + }; + + DeflateCompressor compressor(cb); + + size_t s = orig.size() * sizeof(int); + char *sp = reinterpret_cast(orig.data()); + compressor.compress(sp, s); + compressor.done(); + + auto verifier = [&sp](char *buf, size_t bufsize) + { + EXPECT_EQ(memcmp(buf, sp, bufsize), 0); + sp += bufsize; + }; + + DeflateDecompressor decompressor(verifier); + decompressor.decompress(compressed.data(), compressed.size()); + decompressor.done(); +} + diff --git a/test/unit/CompressionTest.cpp b/test/unit/LazPerfTest.cpp similarity index 61% rename from test/unit/CompressionTest.cpp rename to test/unit/LazPerfTest.cpp index d81f601c6e..ac129ed24d 100644 --- a/test/unit/CompressionTest.cpp +++ b/test/unit/LazPerfTest.cpp @@ -34,8 +34,6 @@ #include -#include -#include #include #include #include @@ -43,10 +41,7 @@ #include "Support.hpp" #include #include -#include #include -#include -#include #include using namespace pdal; @@ -66,7 +61,6 @@ std::vector getBytes(PointViewPtr view) } -#ifdef PDAL_HAVE_LAZPERF TEST(Compression, simple) { const std::string file(Support::datapath("las/1.2-with-color.las")); @@ -197,137 +191,4 @@ TEST(Compression, types) decompress(reinterpret_cast(rawBuf.data()), rawBuf.size()); } -#endif // PDAL_HAVE_LAZPERF - - -#ifdef PDAL_HAVE_ZILB -TEST(Compression, deflate) -{ - std::default_random_engine generator; - std::uniform_int_distribution dist(std::numeric_limits::min()); - - // Choosing a size that isn't a multiple of the internal buffer. - std::vector orig(1000357); - // Trying to make something that compresses reasonably well. - int val = dist(generator); - for (size_t i = 0; i < orig.size(); ++i) - { - orig[i] = val++; - if (i % 100 == 0) - val = dist(generator); - } - - std::vector compressed; - auto cb = [&compressed](char *buf, size_t bufsize) - { - static size_t total = 0; - compressed.insert(compressed.end(), buf, buf + bufsize); - total += bufsize; - }; - - DeflateCompressor compressor(cb); - - size_t s = orig.size() * sizeof(int); - char *sp = reinterpret_cast(orig.data()); - compressor.compress(sp, s); - compressor.done(); - - auto verifier = [&sp](char *buf, size_t bufsize) - { - EXPECT_EQ(memcmp(buf, sp, bufsize), 0); - sp += bufsize; - }; - - DeflateDecompressor decompressor(verifier); - decompressor.decompress(compressed.data(), compressed.size()); - decompressor.done(); -} -#endif // PDAL_HAVE_ZLIB - - -#ifdef PDAL_HAVE_LZMA -TEST(Compression, lzma) -{ - std::default_random_engine generator; - std::uniform_int_distribution dist(std::numeric_limits::min()); - - // Choosing a size that isn't a multiple of the internal buffer. - // Trying to make something that compresses reasonably well. - std::vector orig(1000357); - int val = dist(generator); - for (size_t i = 0; i < orig.size(); ++i) - { - orig[i] = val++; - if (i % 100 == 0) - val = dist(generator); - } - - std::vector compressed; - auto cb = [&compressed](char *buf, size_t bufsize) - { - static size_t total = 0; - compressed.insert(compressed.end(), buf, buf + bufsize); - total += bufsize; - }; - - size_t s = orig.size() * sizeof(int); - char *sp = reinterpret_cast(orig.data()); - LzmaCompressor compressor(cb); - compressor.compress(sp, s); - compressor.done(); - - auto verifier = [&sp](char *buf, size_t bufsize) - { - EXPECT_EQ(memcmp(buf, sp, bufsize), 0); - sp += bufsize; - }; - - LzmaDecompressor decompressor(verifier); - decompressor.decompress(compressed.data(), compressed.size()); - decompressor.done(); -} -#endif // PDAL_HAVE_LZMA - -#ifdef PDAL_HAVE_ZSTD -TEST(Compression, zstd) -{ - std::default_random_engine generator; - std::uniform_int_distribution dist(std::numeric_limits::min()); - - // Choosing a size that isn't a multiple of the internal buffer. - // Trying to make something that compresses reasonably well. - std::vector orig(1000357); - int val = dist(generator); - for (size_t i = 0; i < orig.size(); ++i) - { - orig[i] = val++; - if (i % 100 == 0) - val = dist(generator); - } - - std::vector compressed; - auto cb = [&compressed](char *buf, size_t bufsize) - { - static size_t total = 0; - compressed.insert(compressed.end(), buf, buf + bufsize); - total += bufsize; - }; - - size_t s = orig.size() * sizeof(int); - char *sp = reinterpret_cast(orig.data()); - ZstdCompressor compressor(cb); - compressor.compress(sp, s); - compressor.done(); - - auto verifier = [&sp](char *buf, size_t bufsize) - { - EXPECT_EQ(memcmp(buf, sp, bufsize), 0); - sp += bufsize; - }; - - ZstdDecompressor decompressor(verifier); - decompressor.decompress(compressed.data(), compressed.size()); - decompressor.done(); -} -#endif // PDAL_HAVE_ZSTD diff --git a/test/unit/LzmaTest.cpp b/test/unit/LzmaTest.cpp new file mode 100644 index 0000000000..22f5d0ed53 --- /dev/null +++ b/test/unit/LzmaTest.cpp @@ -0,0 +1,83 @@ +/****************************************************************************** +* Copyright (c) 2014, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 + +#include + +#include + +using namespace pdal; + +TEST(Compression, lzma) +{ + std::default_random_engine generator; + std::uniform_int_distribution dist(std::numeric_limits::min()); + + // Choosing a size that isn't a multiple of the internal buffer. + // Trying to make something that compresses reasonably well. + std::vector orig(1000357); + int val = dist(generator); + for (size_t i = 0; i < orig.size(); ++i) + { + orig[i] = val++; + if (i % 100 == 0) + val = dist(generator); + } + + std::vector compressed; + auto cb = [&compressed](char *buf, size_t bufsize) + { + static size_t total = 0; + compressed.insert(compressed.end(), buf, buf + bufsize); + total += bufsize; + }; + + size_t s = orig.size() * sizeof(int); + char *sp = reinterpret_cast(orig.data()); + LzmaCompressor compressor(cb); + compressor.compress(sp, s); + compressor.done(); + + auto verifier = [&sp](char *buf, size_t bufsize) + { + EXPECT_EQ(memcmp(buf, sp, bufsize), 0); + sp += bufsize; + }; + + LzmaDecompressor decompressor(verifier); + decompressor.decompress(compressed.data(), compressed.size()); + decompressor.done(); +} + diff --git a/test/unit/PluginManagerTest.cpp b/test/unit/PluginManagerTest.cpp index 8be62125ed..1681b0ae48 100644 --- a/test/unit/PluginManagerTest.cpp +++ b/test/unit/PluginManagerTest.cpp @@ -35,6 +35,7 @@ #include #include +#include #include #include @@ -127,7 +128,7 @@ TEST(PluginManagerTest, SearchPaths) EXPECT_TRUE(Utils::contains(paths, "./lib")); EXPECT_TRUE(Utils::contains(paths, "../lib")); EXPECT_TRUE(Utils::contains(paths, "../bin")); - EXPECT_TRUE(Utils::contains(paths, PDAL_PLUGIN_INSTALL_PATH)); + EXPECT_TRUE(Utils::contains(paths, Config::pluginInstallPath())); Utils::setenv("PDAL_DRIVER_PATH", "/foo/bar://baz"); paths = PluginManager::test_pluginSearchPaths(); diff --git a/test/unit/SegmentationTest.cpp b/test/unit/SegmentationTest.cpp index 8974c04dc9..5094892998 100644 --- a/test/unit/SegmentationTest.cpp +++ b/test/unit/SegmentationTest.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include diff --git a/test/unit/UtilsTest.cpp b/test/unit/UtilsTest.cpp index 10c7b70ad5..f71859735c 100644 --- a/test/unit/UtilsTest.cpp +++ b/test/unit/UtilsTest.cpp @@ -33,7 +33,6 @@ ****************************************************************************/ #include -#include #include diff --git a/test/unit/ZstdTest.cpp b/test/unit/ZstdTest.cpp new file mode 100644 index 0000000000..c4c5f13ad7 --- /dev/null +++ b/test/unit/ZstdTest.cpp @@ -0,0 +1,83 @@ +/****************************************************************************** +* Copyright (c) 2018, Howard Butler (howard@hobu.co) +* +* 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. +* * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the +* names of its contributors may be used to endorse or promote +* products derived from this software without specific prior +* written permission. +* +* 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 + +#include + +#include + +using namespace pdal; + +TEST(Compression, zstd) +{ + std::default_random_engine generator; + std::uniform_int_distribution dist(std::numeric_limits::min()); + + // Choosing a size that isn't a multiple of the internal buffer. + // Trying to make something that compresses reasonably well. + std::vector orig(1000357); + int val = dist(generator); + for (size_t i = 0; i < orig.size(); ++i) + { + orig[i] = val++; + if (i % 100 == 0) + val = dist(generator); + } + + std::vector compressed; + auto cb = [&compressed](char *buf, size_t bufsize) + { + static size_t total = 0; + compressed.insert(compressed.end(), buf, buf + bufsize); + total += bufsize; + }; + + size_t s = orig.size() * sizeof(int); + char *sp = reinterpret_cast(orig.data()); + ZstdCompressor compressor(cb); + compressor.compress(sp, s); + compressor.done(); + + auto verifier = [&sp](char *buf, size_t bufsize) + { + EXPECT_EQ(memcmp(buf, sp, bufsize), 0); + sp += bufsize; + }; + + ZstdDecompressor decompressor(verifier); + decompressor.decompress(compressed.data(), compressed.size()); + decompressor.done(); +} + diff --git a/test/unit/apps/pc2pcTest.cpp b/test/unit/apps/pc2pcTest.cpp index fd6ac16004..d68856079b 100644 --- a/test/unit/apps/pc2pcTest.cpp +++ b/test/unit/apps/pc2pcTest.cpp @@ -50,7 +50,7 @@ static std::string appName() } -#ifdef PDAL_COMPILER_MSVC +#ifdef _WIN32 TEST(pc2pcTest, pc2pcTest_test_no_input) { std::string cmd = appName();