Commit 4ed9d944 authored by xuebingbing's avatar xuebingbing

create

parents
Pipeline #594 failed with stages
############################################################
# Visual Studio - Start
############################################################
## Ignore Visual Studio temporary files, build results, and
## files generated by popular Visual Studio add-ons.
# User-specific files
.vscode
\ No newline at end of file
cmake_minimum_required(VERSION 3.18.0)
string(TIMESTAMP TIME %Y%m%d%H)
project(formatconverter VERSION 0.0.1.${TIME})
IF(MSVC)
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /utf-8")
# disable macros that offend std::numeric_limits<T>::min()/max()
# ADD_DEFINITIONS(-DNOMINMAX)
ENDIF(MSVC)
add_subdirectory(src)
\ No newline at end of file
add_subdirectory(convertor)
add_subdirectory(convert)
\ No newline at end of file
string(TIMESTAMP TIME %Y%m%d%H)
project(jfhdconvert VERSION 0.0.1.${TIME})
add_definitions(-DCONVERT_EXPORT)
find_package(PDAL REQUIRED)
find_package(PCL REQUIRED COMPONENTS common io)
file(GLOB_RECURSE INC_FILES *.h *.hpp)
file(GLOB_RECURSE SRC_FILES *.cpp)
add_library(${PROJECT_NAME} SHARED ${INC_FILES} ${SRC_FILES})
target_include_directories(${PROJECT_NAME}
PUBLIC $<BUILD_INTERFACE:${PCL_INCLUDE_DIRS}>
PRIVATE $<INSTALL_INTERFACE:${PCL_INCLUDE_DIRS}>
)
target_link_libraries(${PROJECT_NAME}
PRIVATE ${PCL_LIBRARIES}
PRIVATE pdalcpp pdal_util pdal_arbiter pdal_kazhdan
)
#安装相关的命令
#include "convertor.h"
#include <corecrt_io.h>
// pcl
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/PCLPointCloud2.h>
// pdal
#include <pdal/PointTable.hpp>
#include <pdal/PointView.hpp>
#include <pdal/Options.hpp>
#include <pdal/io/BufferReader.hpp>
#include <pdal/StageFactory.hpp>
#include <pdal/Dimension.hpp>
// stl
#include <unordered_map>
pdal::Dimension::Type GetLasDimDataType(const pcl::PCLPointField& field)
{
switch (field.datatype) {
case pcl::PCLPointField::INT8:
{
return pdal::Dimension::Type::Signed8;
}break;
case pcl::PCLPointField::UINT8:
{
return pdal::Dimension::Type::Unsigned8;
}break;
case pcl::PCLPointField::INT16:
{
return pdal::Dimension::Type::Signed16;
}break;
case pcl::PCLPointField::UINT16:
{
return pdal::Dimension::Type::Unsigned16;
}break;
case pcl::PCLPointField::INT32:
{
return pdal::Dimension::Type::Signed32;
}break;
case pcl::PCLPointField::UINT32:
{
return pdal::Dimension::Type::Unsigned32;
}break;
case pcl::PCLPointField::FLOAT32:
{
return pdal::Dimension::Type::Float;
}break;
case pcl::PCLPointField::FLOAT64:
{
return pdal::Dimension::Type::Double;
}break;
default:
return pdal::Dimension::Type::None;
}
}
std::unordered_map<std::string, pdal::Dimension::Id> GetLasdimidFromPcdFields(const std::vector<::pcl::PCLPointField>& pcdfields, pdal::PointLayoutPtr layerout)
{
std::unordered_map<std::string, pdal::Dimension::Id> dict;
for (auto field : pcdfields)
{
if (0 == field.name.compare("_"))
continue;
auto dimdatatype = GetLasDimDataType(field);
if (pdal::Dimension::Type::None == dimdatatype)
{
// TODO::
continue;
}
pdal::Dimension::Id dim = pdal::Dimension::id(field.name);
if (pdal::Dimension::Id::Unknown != dim)
{
layerout->registerDim(dim);
}
else
{
dim = layerout->assignDim(field.name, dimdatatype);
}
dict.emplace(std::make_pair(field.name, dim));
}
return dict;
}
void PcdPoint2LasPoint(const std::uint8_t* msg_data, const std::vector<::pcl::PCLPointField>& pcdfields,
const std::unordered_map<std::string, pdal::Dimension::Id>& pcdfieldname2lasdimid,
const jfhd::convert::Pcd2LasInfo& info, std::uint64_t las_pointid, pdal::PointViewPtr view)
{
for (const auto& item : pcdfields)
{
auto it = pcdfieldname2lasdimid.find(item.name);
if (pcdfieldname2lasdimid.end() == it)
continue;
switch (item.datatype) {
case pcl::PCLPointField::INT8: {
pcl::traits::asType<pcl::PCLPointField::INT8>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
case pcl::PCLPointField::UINT8: {
pcl::traits::asType<pcl::PCLPointField::UINT8>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
case pcl::PCLPointField::INT16: {
pcl::traits::asType<pcl::PCLPointField::INT16>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
case pcl::PCLPointField::UINT16: {
pcl::traits::asType<pcl::PCLPointField::UINT16>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
case pcl::PCLPointField::INT32: {
pcl::traits::asType<pcl::PCLPointField::INT32>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
case pcl::PCLPointField::UINT32: {
pcl::traits::asType<pcl::PCLPointField::UINT32>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
case pcl::PCLPointField::FLOAT32: {
pcl::traits::asType<pcl::PCLPointField::FLOAT32>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
// TODO: 判断x,y,z 进行加减
if (it->second == pdal::Dimension::Id::X)
{
double x = val;
x += info.offsetx;
view->setField(it->second, las_pointid, x);
}
else if(it->second == pdal::Dimension::Id::Y)
{
double y = val;
y += info.offsety;
view->setField(it->second, las_pointid, y);
}
else if(it->second == pdal::Dimension::Id::Z)
{
double z = val;
z += info.offsetz;
view->setField(it->second, las_pointid, z);
}
else
{
view->setField(it->second, las_pointid, val);
}
}break;
case pcl::PCLPointField::FLOAT64: {
pcl::traits::asType<pcl::PCLPointField::FLOAT64>::type val;
memcpy(&val, msg_data + item.offset, sizeof(val));
view->setField(it->second, las_pointid, val);
}break;
default:
break;
}
}
}
namespace jfhd {
namespace convert {
Convertor::Convertor()
{
}
Convertor::~Convertor()
{
}
bool Convertor::Pcd2Las(const std::string& pcdfilepath, std::string& lasfilepath, const Pcd2LasInfo& info, std::string* errormsg)
{
//std::string pcdfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add.pcd" };
Eigen::Vector4f origin;
Eigen::Quaternionf orientation;
pcl::PCLPointCloud2 pcloud;
if (0 != pcl::io::loadPCDFile(pcdfilepath, pcloud, origin, orientation))
{
std::stringstream ss;
ss << "open pcd[<< " << pcdfilepath << "]failed";
*errormsg = ss.str();
return false;
}
// pcd field 变换到 las的dim
pdal::PointTable table;
auto layerout = table.layout();
std::unordered_map<std::string, pdal::Dimension::Id>
dict_pclfieldname_lasid = GetLasdimidFromPcdFields(pcloud.fields, table.layout());
pdal::PointViewPtr view(new pdal::PointView(table));
std::uint64_t width = pcloud.width;
std::uint64_t height = pcloud.height;
std::uint64_t point_count = width * height;
std::uint64_t point_step = pcloud.point_step;
std::uint64_t point_index = 0;
for (std::uint64_t row = 0; row < height; ++row)
{
const std::uint8_t* row_data = &pcloud.data[row * pcloud.row_step];
for (std::uint32_t col = 0; col < pcloud.width; ++col)
{
//std::cout << point_index << ":";
const std::uint8_t* msg_data = row_data + col * point_step;
PcdPoint2LasPoint(msg_data, pcloud.fields, dict_pclfieldname_lasid, info, point_index, view);
++point_index;
//std::cout << std::endl;
}
}
//std::string lasfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add_myself.las" };
pdal::Options las_options;
las_options.add("filename", lasfilepath);
las_options.add("extra_dims", "all");
las_options.add("scale_x", 1.0e-5);
las_options.add("scale_y", 1.0e-5);
las_options.add("scale_z", 1.0e-5);
pdal::Uuid uuid;
uuid.parse("C8DED732-F71F-44D7-A62E-24F7F8A43E69");
las_options.add("project_id", uuid);
pdal::BufferReader bufferreader;
bufferreader.addView(view);
pdal::StageFactory factory;
pdal::Stage* writer = factory.createStage("writers.las");
writer->setOptions(las_options);
writer->setInput(bufferreader);
writer->prepare(table);
pdal::PointViewSet pointviewset = writer->execute(table);
if (pointviewset.size() > 0)
{
return true;
}
else
{
return false;
}
}
}
}
#ifndef JF_HD_CONVERT_SWITH_H_
#define JF_HD_CONVERT_SWITH_H_
#include <string>
#include "export.h"
namespace jfhd {
namespace convert {
struct CONVERT_API Pcd2LasInfo
{
double offsetx = 0.0;
double offsety = 0.0;
double offsetz = 0.0;
};
class CONVERT_API Convertor
{
public:
Convertor();
~Convertor();
static bool Pcd2Las(const std::string& pcdfilepath, std::string& lasfilepath, const Pcd2LasInfo& info, std::string* errormsg);
};
}
}
#endif // !JF_HD_CONVERT_SWITH_H_
#ifndef JF_HD_CONVERT_EXPORT_H_
#define JF_HD_CONVERT_EXPORT_H_
#ifdef CONVERT_EXPORT
#if defined(_MSC_VER)
#define CONVERT_API __declspec(dllexport)
#endif
#if (__GNUC__ >= 4) && !defined(_MSC_VER)
#define CONVERT_API __attribute__((visibility("default")))
//#define DLL_LOCAL __attribute__ ((visibility("hidden")))
#endif
#if(__GNUC__ < 4) && !defined(_MSC_VER)
#define CONVERT_API
#endif // #if (__GNUC__ >= 4)
#else
#if defined(_MSC_VER)
#define CONVERT_API __declspec(dllimport)
#endif
#if (__GNUC__ >= 4) && !defined(_MSC_VER)
#define CONVERT_API __attribute__((visibility("default")))
//#define DLL_LOCAL __attribute__ ((visibility("hidden")))
#endif
#if(__GNUC__ < 4) && !defined(_MSC_VER)
#define CONVERT_API
#endif // #if (__GNUC__ >= 4)
#endif// #ifdef CONVERT_EXPORT
#endif // #ifndef JF_HD_CONVERT_EXPORT_H_
string(TIMESTAMP TIME %Y%m%d%H)
project(jfhdconvertor VERSION 0.0.1.${TIME})
find_package(cxxopts REQUIRED)
find_package(PDAL REQUIRED)
find_package(PCL REQUIRED COMPONENTS common io)
file(GLOB_RECURSE INC_FILES *.h *.hpp)
file(GLOB_RECURSE SRC_FILES *.cpp)
add_executable(${PROJECT_NAME} ${INC_FILES} ${SRC_FILES})
target_link_libraries(${PROJECT_NAME}
PRIVATE jfhdconvert
PRIVATE ${PCL_LIBRARIES}
PRIVATE pdalcpp pdal_util pdal_arbiter pdal_kazhdan
)
# install cmd
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment