From ef8dc7f373894a8560c04e01e0113f917b46b0d0 Mon Sep 17 00:00:00 2001 From: kylemann16 Date: Thu, 6 Sep 2018 16:55:07 -0500 Subject: [PATCH] got decompression working and put into view. need to add gzip decomp and search children nodes --- kyle-config.sy | 1 + plugins/i3s/CMakeLists.txt | 11 +- plugins/i3s/io/i3sPointLayout.hpp | 4 + plugins/i3s/io/i3sReader.cpp | 239 ++++++++++++++++++++---------- plugins/i3s/io/i3sReader.hpp | 15 +- plugins/i3s/io/i3sReceiver.cpp | 58 ++++++++ plugins/i3s/io/i3sReceiver.hpp | 48 ++++++ plugins/i3s/lepcc/CMakeLists.txt | 35 +++++ 8 files changed, 322 insertions(+), 89 deletions(-) create mode 100644 plugins/i3s/io/i3sPointLayout.hpp create mode 100644 plugins/i3s/io/i3sReceiver.cpp create mode 100644 plugins/i3s/io/i3sReceiver.hpp create mode 100644 plugins/i3s/lepcc/CMakeLists.txt diff --git a/kyle-config.sy b/kyle-config.sy index ae01bdeb86..73d94e563e 100755 --- a/kyle-config.sy +++ b/kyle-config.sy @@ -15,6 +15,7 @@ cmake .. \ -DWITH_LAZPERF=ON \ -DCMAKE_INSTALL_PREFIX=/usr \ -DCMAKE_INSTALL_LIBDIR=lib \ + -DCMAKE_BUILD_TYPE=Debug \ ; \ echo Make... diff --git a/plugins/i3s/CMakeLists.txt b/plugins/i3s/CMakeLists.txt index eb901e02ee..18bb4ef553 100644 --- a/plugins/i3s/CMakeLists.txt +++ b/plugins/i3s/CMakeLists.txt @@ -4,6 +4,10 @@ if (WIN32) add_definitions("-DARBITER_DLL_IMPORT") endif() +add_subdirectory(lepcc) +set_property(TARGET lepcc PROPERTY POSITION_INDEPENDENT_CODE TRUE) + + PDAL_ADD_PLUGIN(reader_libname reader i3s FILES io/i3sReader.cpp @@ -12,7 +16,12 @@ PDAL_ADD_PLUGIN(reader_libname reader i3s ${PDAL_JSONCPP_LIB_NAME} ${WINSOCK_LIBRARY} ) +target_link_libraries(${reader_libname} PRIVATE + lepcc +) target_include_directories(${reader_libname} PRIVATE ${PDAL_JSONCPP_INCLUDE_DIR} - ${PDAL_VENDOR_DIR}) + ${PDAL_VENDOR_DIR} + ${LEPCC_INCLUDE_DIR} +) diff --git a/plugins/i3s/io/i3sPointLayout.hpp b/plugins/i3s/io/i3sPointLayout.hpp new file mode 100644 index 0000000000..3d79e12ace --- /dev/null +++ b/plugins/i3s/io/i3sPointLayout.hpp @@ -0,0 +1,4 @@ +#pragma once + +#include +#include diff --git a/plugins/i3s/io/i3sReader.cpp b/plugins/i3s/io/i3sReader.cpp index b23aeaa354..184adbc6fc 100644 --- a/plugins/i3s/io/i3sReader.cpp +++ b/plugins/i3s/io/i3sReader.cpp @@ -1,7 +1,18 @@ // I3SReader.cpp #include "i3sReader.hpp" - +#include "../lepcc/src/include/lepcc_c_api.h" +#include "../lepcc/src/include/lepcc_types.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include #include #include #include @@ -62,110 +73,174 @@ namespace pdal void I3SReader::addArgs(ProgramArgs& args) { - args.add("url", "URL", m_args.url); - args.add("body", "JSON formatted body", m_args.body); - args.add("itemId", "ID of the current item", m_args.itemId); - args.add("name", "Name of the point cloud data", m_args.name); - + args.add("url", "URL", m_args.url); + args.add("body", "JSON formatted body", m_args.body); + args.add("itemId", "ID of the current item", m_args.itemId); + args.add("name", "Name of the point cloud data", m_args.name); } void I3SReader::addDimensions(PointLayoutPtr layout) { - Json::StreamWriterBuilder writer; - writer.settings_["indentation"] = ""; - - //register default values X, Y and Z - layout->registerDim(Dimension::Id::X); - layout->registerDim(Dimension::Id::Y); - layout->registerDim(Dimension::Id::Z); - - for (int j = 0; j < m_args.body["layers"].size(); j++) { - - Json::Value attributes = m_args.body["layers"][j]["attributeStorageInfo"]; + Json::StreamWriterBuilder writer; + writer.settings_["indentation"] = ""; - for(int i = 0; i < attributes.size(); i ++) + for (int j = 0; j < m_args.body["layers"].size(); j++) { - std::string name = Json::writeString(writer, attributes[i]["name"]); - - name.erase( - remove( name.begin(), name.end(), '\"' ), - name.end() - ); - - std::string type; - /*Check the entry has an attributevalues object - TODO check if name is a part of pdal's wanted parameters - TODO manage struct from header file - */ - if (attributes[i].isMember("attributeValues")) { - type = Json::writeString(writer, - attributes[i]["attributeValues"]["valueType"]); - layout->registerOrAssignDim(name, pdal::Dimension::type(type)); - m_layout.registerOrAssignDim(name, pdal::Dimension::type(type)); - } - else{ - layout->registerOrAssignDim(name, Dimension::Type::Double); - m_layout.registerOrAssignDim(name, Dimension::Type::Double); - } - + Json::Value attributes = + m_args.body["layers"][j]["attributeStorageInfo"]; + + for(int i = 0; i < attributes.size(); i ++) + { + + std::string readName = + Json::writeString(writer, attributes[i]["name"]); + //remove quotes from json object + readName.erase( + remove( readName.begin(), readName.end(), '\"' ), + readName.end() + ); + //remove random underscores + readName.erase( + remove( readName.begin(), readName.end(), '_' ), + readName.end() + ); + + if(Dimension::id(readName) != Dimension::Id::Unknown) + { + Dimension::Id name = Dimension::id(readName); + layout->registerDim(name); + m_layout.registerDim(name); + }else if(readName.compare("RGB") == 0) + { + m_layout.registerDim(Dimension::Id::Red); + m_layout.registerDim(Dimension::Id::Green); + m_layout.registerDim(Dimension::Id::Blue); + + layout->registerDim(Dimension::Id::Red); + layout->registerDim(Dimension::Id::Green); + layout->registerDim(Dimension::Id::Blue); + } + else if(readName.compare("FLAGS") == 0) + { + m_layout.registerDim(Dimension::Id::Flag); + layout->registerDim(Dimension::Id::Flag); + } + else if(readName.compare("RETURNS") == 0) + { + m_layout.registerDim(Dimension::Id::NumberOfReturns); + layout->registerDim(Dimension::Id::NumberOfReturns); + } + else if(readName.compare("ELEVATION") == 0) + { + layout->registerDim(Dimension::Id::X); + layout->registerDim(Dimension::Id::Y); + layout->registerDim(Dimension::Id::Z); + + m_layout.registerDim(Dimension::Id::X); + m_layout.registerDim(Dimension::Id::Y); + m_layout.registerDim(Dimension::Id::Z); + } + else if(readName.compare("CLASSCODE") == 0) + { + m_layout.registerDim(Dimension::Id::ClassFlags); + layout->registerDim(Dimension::Id::ClassFlags); + } + else if(readName.compare("POINTSRCID") == 0) + { + m_layout.registerDim(Dimension::Id::PointSourceId); + layout->registerDim(Dimension::Id::PointSourceId); + } + else//if it isn't in pdal dimensions and isn't a special case + { + std::string type; + if (attributes[i].isMember("attributeValues")) + { + std::string type; + type = Json::writeString(writer, + attributes[i]["attributeValues"]["valueType"]); + layout->registerOrAssignDim(readName, + pdal::Dimension::type(type)); + m_layout.registerOrAssignDim(readName, + pdal::Dimension::type(type)); + } + else + { + layout->registerOrAssignDim(readName, + Dimension::Type::Double); + m_layout.registerOrAssignDim(readName, + Dimension::Type::Double); + } + } + } } - } } void I3SReader::ready(PointTableRef) { - - SpatialReference ref("EPSG:4385"); - setSpatialReference(ref); + Json::StreamWriterBuilder writer; + writer.settings_["indentation"] = ""; + Json::Value spatialJson = + m_args.body["layers"][0]["spatialReference"]; + std::string spatialStr = + "EPSG:" + + Json::writeString(writer, + spatialJson["wkid"]); + //if(spatialJson.isMember("vcsWkid")) + // spatialStr += ("+" + + // Json::writeString(writer, + // spatialJson["vcsWkid"]) + // ); + SpatialReference ref(spatialStr); + setSpatialReference(ref); } - point_count_t I3SReader::read(PointViewPtr view, point_count_t count) { - /* - -3scenelayerinfo: URL Pattern - -node index document: /nodes/ - -shared resources: /shared/ - -feature data: /features/ - -geometry data: /geometries/ - -texture data: /textures/ - */ - - log()->get(LogLevel::Debug) << "fetching info from " << - m_args.url + "/layers/0/nodes/0/geometries/0" << "\n"; - - std::string urlGeo = m_args.url + "/layers/0/nodes/0/geometries/0"; - - auto response(m_arbiter->getBinary(urlGeo)); + /* + -3scenelayerinfo: URL Pattern + -node index document: /nodes/ + -shared resources: /shared/ + -feature data: /features/ + -geometry data: /geometries/ + -texture data: /textures/ + */ - const std::size_t pointSize(view->layout()->pointSize()); - uint32_t numPoints(0); - std::copy( - response.data() + response.size() - sizeof(uint32_t), - response.data() + response.size(), - reinterpret_cast(&numPoints)); - log()->get(LogLevel::Debug) << - "Fetched " << numPoints << " points" << std::endl; - log()->get(LogLevel::Debug) << - "Fetched " << response.size() << " bytes" << std::endl; - - - view->setField(pdal::Dimension::Id::X, 0, 12); - view->setField(pdal::Dimension::Id::Y, 0, 13); - view->setField(pdal::Dimension::Id::Z, 0, 14); - view->setField(pdal::Dimension::Id::Intensity, 0, 55); - - - - return 0; + /*Determine number of nodes*/ + Json::Value config; + + std::string nodeUrl = m_args.url + "/layers/0/nodepages/0"; + //Json::Value nodeIndex = parse(m_arbiter->get(nodeUrl)); + //int nodeSize = nodeIndex.size(); + std::cout << nodeUrl << std::endl ; + //std::cout <<"Hello worldi" << nodeIndex << std::endl; + int pointCloudCount = 0; + for(int i = 0; i < 64; i++) + { + /*Retrieve binary*/ + std::string urlGeo = m_args.url + + "/layers/0/nodes/" + std::to_string(i) + "/geometries/0"; + std::vector response = m_arbiter->getBinary(urlGeo); + std::vector pointcloud = + decompress(true, true, &response, i); + for(std::size_t j = 0; j < pointcloud.size(); j ++) + { + view->setField(pdal::Dimension::Id::X, pointCloudCount, pointcloud[j].x); + view->setField(pdal::Dimension::Id::Y, pointCloudCount, pointcloud[j].y); + view->setField(pdal::Dimension::Id::Z, pointCloudCount, pointcloud[j].z); + pointCloudCount++; + } + } + const std::size_t pointSize(view->layout()->pointSize()); + + + return 0; } void I3SReader::done(PointTableRef) { m_stream.reset(); } - } //namespace pdal diff --git a/plugins/i3s/io/i3sReader.hpp b/plugins/i3s/io/i3sReader.hpp index e289244da5..b180c6e0c6 100644 --- a/plugins/i3s/io/i3sReader.hpp +++ b/plugins/i3s/io/i3sReader.hpp @@ -2,20 +2,23 @@ #pragma once +#include "../lepcc/src/include/lepcc_c_api.h" +#include "../lepcc/src/include/lepcc_types.h" +#include "i3sReceiver.hpp" + #include #include #include -#include "i3sReceiver.hpp" #include #include #include #include +#include +#include #include - #include - #include @@ -65,12 +68,13 @@ namespace pdal } Added m_added; - }; + }; class I3SReader : public Reader { public: I3SReader() : Reader() {}; std::string getName() const; + private: std::unique_ptr m_stream; @@ -81,7 +85,7 @@ namespace pdal I3SArgs m_args; Json::Value m_info; FixedPointLayout m_layout; - + virtual void addArgs(ProgramArgs& args); virtual void initialize(PointTableRef table) override; virtual void addDimensions(PointLayoutPtr layout); @@ -89,6 +93,5 @@ namespace pdal virtual point_count_t read(PointViewPtr view, point_count_t count); virtual void done(PointTableRef table); - }; } diff --git a/plugins/i3s/io/i3sReceiver.cpp b/plugins/i3s/io/i3sReceiver.cpp new file mode 100644 index 0000000000..73b51d4c69 --- /dev/null +++ b/plugins/i3s/io/i3sReceiver.cpp @@ -0,0 +1,58 @@ +//i3sRecevier.cpp +#include "i3sReceiver.hpp" + +namespace pdal +{ + std::vector decompress( + bool elevation, bool rgb, std::vector* compData, int nodeNum) + { + unsigned char* c = new unsigned char [compData->size()]; + + /*Make buffer*/ + + std::copy(compData->begin(), compData->end(), c); + + const unsigned char* compressed = c; + int numPoint = 0; + int nInfo = lepcc_getBlobInfoSize(); + lepcc_ContextHdl ctx(nullptr); + ctx = lepcc_createContext(); + lepcc_blobType bt; + lepcc::uint32 blobSize = 0; + + lepcc::ErrCode errCode = (lepcc::ErrCode)lepcc_getBlobInfo(ctx, compressed, nInfo, &bt, &blobSize); + + int nBytes = (errCode == lepcc::ErrCode::Ok) ? (int)blobSize : -1; + + lepcc::Byte vec; + lepcc_status stat; + std::vector decVec; + lepcc::uint32 nPts = 0; + const lepcc::Byte* pByte = &compressed[0]; + + if(elevation) + { + if (nBytes > 0) + { + stat = lepcc_getPointCount(ctx, pByte, nBytes, &nPts); + if(stat != (lepcc_status) lepcc::ErrCode::Ok) + { + std::cout << "lepcc_getPointCount() failed. \n"; + return decVec; + } + std::cout << "Node Number: " << nodeNum << std::endl; + std::cout << "Point Count: " << nPts << std::endl; + decVec.resize(nPts); + stat = lepcc_decodeXYZ( + ctx, &pByte, nBytes, &nPts, (double*)(&decVec[0])); + if(stat != (lepcc_status) lepcc::ErrCode::Ok) + { + std::cout << "lepcc_decodeXYZ() failed. \n"; + return decVec; + } + return decVec; + } + } + return decVec; + } +} diff --git a/plugins/i3s/io/i3sReceiver.hpp b/plugins/i3s/io/i3sReceiver.hpp new file mode 100644 index 0000000000..10290bdda2 --- /dev/null +++ b/plugins/i3s/io/i3sReceiver.hpp @@ -0,0 +1,48 @@ +//i3sReceiver.hpp +#pragma once + +#include "../lepcc/src/include/lepcc_c_api.h" +#include "../lepcc/src/include/lepcc_types.h" +#include +#include +#include +#include +#include +#include +#include + + +namespace pdal +{ + /*Return value of data in json format*/ + static inline Json::Value parse(const std::string& data) + { + Json::Value json; + Json::Reader reader; + if (data.size()) + { + if (!reader.parse(data, json, false)) + { + const std::string jsonError(reader.getFormattedErrorMessages()); + if (!jsonError.empty()) + { + throw pdal_error("Error during parsing: " + jsonError); + } + } + } + return json; + } + + struct I3SArgs + { + std::string url; + Json::Value body; + std::string name; + std::string itemId; + std::string intensity; + }; + + + std::vector decompress( + bool elevation, bool rgb, std::vector* compData, int nodeNum); +} diff --git a/plugins/i3s/lepcc/CMakeLists.txt b/plugins/i3s/lepcc/CMakeLists.txt new file mode 100644 index 0000000000..724dbe9f60 --- /dev/null +++ b/plugins/i3s/lepcc/CMakeLists.txt @@ -0,0 +1,35 @@ +cmake_minimum_required(VERSION 3.6) + +project(LEPCC CXX C) +string(TOLOWER ${PROJECT_NAME} PROJECT_NAME_LOWER) + +set(ROOT_DIR "${PROJECT_SOURCE_DIR}") + +file(GLOB BASE_SRCS + ${PROJECT_SOURCE_DIR}/src/*.cpp + ) +set (CMAKE_CXX_STANDARD 11) +message(INFO "files ${BASE_SRCS}") + +set(LEPCC_INCLUDE_DIR "${PROJECT_SOURCE_DIR}/src/include") +message(INFO "LEPCC_INCLUDE_DIR ${LEPCC_INCLUDE_DIR}") + +file(GLOB TEST_SRCS + ${PROJECT_SOURCE_DIR}/src/Test_C_Api.cpp) +message(INFO "TEST_SRCS ${TEST_SRCS}") + +list(REMOVE_ITEM BASE_SRCS ${TEST_SRCS}) + +message(INFO "files ${BASE_SRCS}") +add_library(lepcc STATIC "${BASE_SRCS}") + +target_include_directories(lepcc PRIVATE + ${LEPCC_INCLUDE_DIR}) + + +add_executable(lepcctest ${TEST_SRCS}) +target_include_directories(lepcctest PRIVATE + ${LEPCC_INCLUDE_DIR}) +target_link_libraries(lepcctest lepcc) + +add_compile_options(-fPIC)