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
#include <iostream>
#include <fstream>
#include <algorithm>
#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>
#include "../convert/convertor.h"
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/path.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/tokenizer.hpp>
#include <boost/format.hpp>
#include <boost/algorithm/string.hpp>
//void TestPcdreader();
//
//void TestPdalReadLas();
//
//void TestPdalWriteLas();
//
//void TestPcd2Las();
#include <cxxopts.hpp>
cxxopts::ParseResult parse(int argc, char* argv[]);
int pcd2las(const cxxopts::ParseResult& argsresult);
int pcd2lasauto(const cxxopts::ParseResult& argsresult);
int main(int argc, char* argv[])
{
auto res = parse(argc, argv);
std::unordered_set<std::string> modes;
if (res.count("mode"))
{
std::string temp = res["mode"].as<std::string>();
std::vector<std::string> vectemp;
boost::split(vectemp, temp, boost::is_any_of(","));
for (auto item : vectemp)
{
boost::trim(item);
modes.insert(item);
}
}
if (modes.count("pcd2las.auto"))
{
std::cout << ">>>begin pcd2las.auto --------------------------------------------------" << std::endl;
pcd2lasauto(res);
std::cout << ">>>end pcd2las.auto --------------------------------------------------" << std::endl;
}
if (modes.count("pcs2las"))
{
std::cout << ">>>begin pcd2las--------------------------------------------------" << std::endl;
pcd2las(res);
std::cout << ">>>end pcd2las--------------------------------------------------" << std::endl;
}
return true;
//if (res.count("mode"))
//{
// std::string mode = res["mode"].as<std::string>();
// if (0 == mode.compare("pcd2las"))
// {
// pcd2las(res);
// }
//}
//cxxopts::Options options(argv[0], "觉非高精地图数据转换工具,[pcd2las]");
//options.positional_help("[optional args]").show_positional_help();
//options.add_options()
// ("m,mode", "转换模式,[pcd2las]", cxxopts::value<std::string>()) // a bool parameter
// ("l,lasfile", "las 文件路径", cxxopts::value<std::string>())
// ("p,pcdfile", "pcd 文件路径", cxxopts::value<std::string>())
// ("o,offsetxyz", "x,y,z", cxxopts::value<std::string>())
// ("v,verbose", "Verbose output", cxxopts::value<bool>()->default_value("false"))
// ;
//auto result = options.parse(argc, argv);
//std::string pcdfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add.pcd" };
//std::string lasfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add_libmyself.las" };
//jfhd::convert::Pcd2LasInfo info;
//std::string errormsg;
//jfhd::convert::Convertor::Pcd2Las(pcdfilepath, lasfilepath, info, &errormsg);
return 0;
}
cxxopts::ParseResult parse(int argc, char* argv[])
{
try
{
cxxopts::Options options(argv[0], " - example command line options");
options
.positional_help("[optional args]")
.show_positional_help();
bool apple = false;
options
.allow_unrecognised_options()
.add_options()
("m,mode", "pcd2las,pcd2las.auto", cxxopts::value<std::string>()->default_value("pcd2las.auto"))
("h,help", "Print help")
#ifdef CXXOPTS_USE_UNICODE
("unicode", u8"A help option with non-ascii: à. Here the size of the"
" string should be correct")
#endif
;
options.add_options("pcd2las.auto")
("workdir", "自动化的任务根目录", cxxopts::value<std::string>());
options.add_options("pcd2las")
("pcdfile", "输入pcd文件路径", cxxopts::value<std::string>())
("lasfile", "输出las文件路径", cxxopts::value<std::string>())
("offsetxyz", "A list of doubles", cxxopts::value<std::vector<double>>()->default_value("0.0,0.0,0.0"));
auto result = options.parse(argc, argv);
if (result.count("help"))
{
std::cout << options.help({ "" , "pcd2las.auto", "pcd2las" }) << std::endl;
exit(0);
}
return result;
}
catch (const cxxopts::OptionException& e)
{
std::cout << "error parsing options: " << e.what() << std::endl;
exit(1);
}
}
int pcd2las(const cxxopts::ParseResult& argsresult)
{
using namespace boost::filesystem;
std::string pcdfilepath;
if (argsresult.count("input"))
{
pcdfilepath = argsresult["input"].as<std::string>();
}
path full_path(initial_path());
full_path = system_complete(path(pcdfilepath, portable_name));
if (!exists(full_path))
{
std::cout << "ERROR:file not exist," << full_path << std::endl;
return -1;
}
std::string lasfilepath;
full_path = system_complete(path(lasfilepath, portable_name));
if (exists(full_path))
std::cout << "INFO:cover file," << lasfilepath << std::endl;
if (argsresult.count("output"))
{
lasfilepath = argsresult["output"].as<std::string>();
}
jfhd::convert::Pcd2LasInfo info;
if (argsresult.count("offsetxyz"))
{
const auto values = argsresult["offsetxyz"].as<std::vector<double>>();
if (values.size() < 3)
{
std::cout << "offsetxyz 需要三个偏移值" << std::endl;
return -1;
}
info.offsetx = values[0];
info.offsety = values[1];
info.offsetz = values[2];
}
std::string errormsg;
jfhd::convert::Convertor::Pcd2Las(pcdfilepath, lasfilepath, info, &errormsg);
return 0;
}
using str_dict = std::unordered_map<std::string, std::string>;
bool ReadJfStationFile(const std::string& filepath, str_dict* dict);
bool ReadJdStationFile(const std::string& filepath, str_dict* dict);
bool CalcConvertInfo(const str_dict& jfdict, const str_dict& jddict, jfhd::convert::Pcd2LasInfo* convert_info)
{
try
{
double jf_e0 = std::stod(jfdict.at("E0_PROJECT"));
double jf_n0 = std::stod(jfdict.at("N0_PROJECT"));
double jf_h0 = std::stod(jfdict.at("H0_PROJECT"));
double jd_e0 = std::stod(jddict.at("E0_UTM_JD"));
double jd_n0 = std::stod(jddict.at("N0_UTM_JD"));
double jd_h0 = std::stod(jddict.at("H0_UTM_JD"));
double jf_adjust2jd_x = std::stod(jddict.at("E_OFFSET"));
double jf_adjust2jd_y = std::stod(jddict.at("N_OFFSET"));
double jf_adjuet2jd_z = std::stod(jddict.at("H_OFFSET"));
// 求偏移值
// jd_e = jfe + jfe0 + adjueste - jde0
convert_info->offsetx = jf_e0 + jf_adjust2jd_x - jd_e0;
convert_info->offsety = jf_n0 + jf_adjust2jd_y - jd_n0;
convert_info->offsetz = jf_h0 + jf_adjuet2jd_z - jd_h0;
return true;
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
return false;
}
}
int pcd2lasauto(const cxxopts::ParseResult& argsresult)
{
std::string workdirpath{ "" };
if (argsresult.count("workdir"))
{
workdirpath = argsresult["workdir"].as<std::string>();
}
using namespace boost::filesystem;
// 查找station_jf.txt文件
path workdir(initial_path());
workdir = system_complete(path(workdirpath, portable_name));
std::stringstream ss;
ss << workdir.filename().string() << "_station_jf.txt";
std::string temp = ss.str();
auto station_jf_file(workdir);
station_jf_file.append(temp.begin(), temp.end());
if (!exists(station_jf_file) || !is_regular_file(station_jf_file))
{
std::cout << "ERROR:pcd2las.auto 找不到觉非站心文件:" << station_jf_file.string() << std::endl;
return -1;
}
ss.str("");
ss << workdir.filename().string() << "_station_jd.txt";
temp = ss.str();
auto station_jd_file(workdir);
station_jd_file.append(temp.begin(), temp.end());
if (!exists(station_jd_file) || !is_regular_file(station_jd_file))
{
std::cout << "ERROR:pcd2las.auto 找不到京东站心和偏移文件:" << station_jd_file.string() << std::endl;
return -1;
}
temp = "pcd_utm_merge";
auto src_pcd_dir(workdir);
src_pcd_dir.append(temp.begin(), temp.end());
if (!exists(src_pcd_dir) || !is_directory(src_pcd_dir))
{
std::cout << "ERROR:pcd2las.auto 找不到输入utm pcd文件目录:" << src_pcd_dir.string() << std::endl;
return -1;
}
// 读取taskid_station_jf.txt,taskid_station_jd.txt
str_dict jf_station_dict, jd_station_dict;
if (!ReadJfStationFile(station_jf_file.string(), &jf_station_dict))
return false;
if (!ReadJdStationFile(station_jd_file.string(), &jd_station_dict))
return false;
jfhd::convert::Pcd2LasInfo convert_info;
if (!CalcConvertInfo(jf_station_dict, jd_station_dict, &convert_info))
return false;
auto dst_las_dir(workdir);
temp = "submit";
dst_las_dir.append(temp.begin(), temp.end());
temp = "jd";
dst_las_dir.append(temp.begin(), temp.end());
temp = "las";
dst_las_dir.append(temp.begin(), temp.end());
boost::filesystem::create_directories(dst_las_dir);
// 在特定目录生成
boost::filesystem::directory_iterator item_begin(src_pcd_dir);
boost::filesystem::directory_iterator item_end;
//std::unordered_map<boost::filesystem::path, boost::filesystem::path> pcdfile_rel_lasfile;
str_dict pcdfile_rel_lasfile;
for (; item_begin != item_end; ++item_begin)
{
if (is_directory(*item_begin))
continue;
auto pp = item_begin->path().string();
auto suffix = pp.substr(pp.size() - 11);
if (0 != suffix.compare("_ground.pcd") && 0 != suffix.compare("_object.pcd"))
{
std::cout << "INFO:not _ground.pcd or _object.pcd skip file=" << item_begin->path().string() << std::endl;
continue;
}
boost::filesystem::path temp_path(dst_las_dir);
temp = item_begin->path().filename().string();
auto filename = temp.substr(0, temp.size() - 4);
filename.append(".las");
temp_path.append(filename.begin(), filename.end());
pcdfile_rel_lasfile.emplace(item_begin->path().string(), temp_path.string());
}
ss.str("");
ss << "offsetx = " << convert_info.offsetx << std::endl;
ss << "offsety = " << convert_info.offsety << std::endl;
ss << "offsetz = " << convert_info.offsetz << std::endl;
std::string errormsg;
for (auto item : pcdfile_rel_lasfile)
{
if (!jfhd::convert::Convertor::Pcd2Las(item.first, item.second, convert_info, &errormsg))
{
std::cout << "ERROR: failed" << item.first << ">>" << item.second << std::endl;
}
else
{
std::cout << "INFO: successed " << item.first << ">>" << item.second << std::endl;
}
}
return 0;
}
auto ReadStationFileFunc = [](const std::string& filepath, str_dict* dict)
{
assert(dict);
try
{
std::ifstream ifile;
ifile.open(filepath, std::ifstream::in);
std::string line;
while (std::getline(ifile, line))
{
std::vector<std::string> params;
boost::split(params, line, boost::is_any_of((":")));
if (params.size() < 2)
{
continue;
}
boost::trim(params[0]);
boost::trim(params[1]);
std::transform(params[0].begin(), params[0].end(), params[0].begin(), ::toupper);
std::transform(params[1].begin(), params[1].end(), params[1].begin(), ::toupper);
//jf_dict.emplace(std::make_pair(boost::trim(params[0]), boost::trim(params[1])));
dict->emplace(params[0], params[1]);
}
ifile.close();
return true;
}
catch (std::exception& e)
{
std::cout << e.what() << std::endl;
return false;
}
};
bool ReadJfStationFile(const std::string& filepath, str_dict* jfdict)
{
assert(jfdict != nullptr);
if (!ReadStationFileFunc(filepath, jfdict))
return false;
auto checkfunc = [&filepath, &jfdict](const std::string& key) {
if (jfdict->end() == jfdict->find(key))
{
std::cout << "ERROR: can not fine key:" << key << " in file[" << filepath << "]" << std::endl;
return false;
}
return true;
};
if (!checkfunc("E0_PROJECT"))
return false;
if (!checkfunc("N0_PROJECT"))
return false;
if (!checkfunc("H0_PROJECT"))
return false;
return true;
}
bool ReadJdStationFile(const std::string& filepath, str_dict* jddict)
{
assert(jddict != nullptr);
if (!ReadStationFileFunc(filepath, jddict))
return false;
auto checkfunc = [&filepath, &jddict](const std::string& key) {
if (jddict->end() == jddict->find(key))
{
std::cout << "ERROR: can not fine key:" << key << " in file[" << filepath << "]" << std::endl;
return false;
}
return true;
};
if (!checkfunc("E_OFFSET"))
return false;
if (!checkfunc("N_OFFSET"))
return false;
if (!checkfunc("H_OFFSET"))
return false;
if (!checkfunc("E0_UTM_JD"))
return false;
if (!checkfunc("N0_UTM_JD"))
return false;
if (!checkfunc("H0_UTM_JD"))
return false;
return true;
}
//#include <corecrt_io.h>
//#include <pcl/io/pcd_io.h>
//#include <pcl/point_types.h>
//#include <pcl/PCLPointCloud2.h>
//
////typedef struct PointXYZIT {
//// PCL_ADD_POINT4D
////
//// float label;
//// float intensity;
//// EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
////} EIGEN_ALIGN16 PPoint;
//
//
////typedef struct PointXYZIT {
//// PCL_ADD_POINT4D
////
//// float label;
//// float intensity;
//// EIGEN_MAKE_ALIGNED_OPERATOR_NEW // make sure our new allocators are aligned
////} EIGEN_ALIGN16 PPoint;
////
////POINT_CLOUD_REGISTER_POINT_STRUCT(
//// PointXYZIT, (float, x, x) (float, y, y)(float, z, z)(float, intensity, intensity)(float, label, label))
//
//
// //pdal::Dimension::Type GetLasDimDataType(const pcl::PCLPointField& field);
//#include <unordered_map>
//
//
//void TestPcd2Las()
//{
// 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;
// pcl::io::loadPCDFile(pcdfilepath, pcloud, origin, orientation);
//
// //pcl::PointCloud<PointXYZIT>::Ptr cloud(new pcl::PointCloud<PointXYZIT>);
// //pcl::io::loadPCDFile(pcdfilepath, *cloud);
//
// // pcd field 变换到 las的dim
// std::unordered_map<std::string, pdal::Dimension::Id> dict_pclfieldname_lasid;
// pdal::PointTable table;
// auto layerout = table.layout();
// for (auto field : pcloud.fields)
// {
// 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_pclfieldname_lasid.emplace(std::make_pair(field.name, dim));
// }
//
// 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 ipoint = 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 << ipoint << ":";
// const std::uint8_t* msg_data = row_data + col * point_step;
//
// for (const auto& item : pcloud.fields)
// {
// if (dict_pclfieldname_lasid.end() == dict_pclfieldname_lasid.find(item.name))
// continue;
//
// //constexpr pcl::PCLPointField::PointFieldTypes field_type = (pcl::PCLPointField::PointFieldTypes)item.datatype;
//
// switch (item.datatype) {
// case pcl::PCLPointField::INT8: {
// pcl::traits::asType<pcl::PCLPointField::INT8>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::INT8>::type));
// //GetValueFunctor<pcl::PCLPointField::INT8> funcotr;
// //funcotr(msg_data, item);
// }break;
// case pcl::PCLPointField::UINT8:
// {
// pcl::traits::asType<pcl::PCLPointField::UINT8>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::UINT8>::type));
// }break;
// case pcl::PCLPointField::INT16:
// {
// pcl::traits::asType<pcl::PCLPointField::INT16>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::INT16>::type));
// }break;
// case pcl::PCLPointField::UINT16:
// {
// pcl::traits::asType<pcl::PCLPointField::UINT16>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::UINT16>::type));
// }break;
// case pcl::PCLPointField::INT32:
// {
// pcl::traits::asType<pcl::PCLPointField::INT32>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::INT32>::type));
// }break;
// case pcl::PCLPointField::UINT32:
// {
// pcl::traits::asType<pcl::PCLPointField::UINT32>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::UINT32>::type));
// auto it = dict_pclfieldname_lasid.find(item.name);
// if (it != dict_pclfieldname_lasid.end())
// {
// view->setField(it->second, ipoint, val);
// }
// }break;
// case pcl::PCLPointField::FLOAT32:
// {
// pcl::traits::asType<pcl::PCLPointField::FLOAT32>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::FLOAT32>::type));
//
// auto it = dict_pclfieldname_lasid.find(item.name);
// if (it != dict_pclfieldname_lasid.end())
// {
// view->setField(it->second, ipoint, (double)val);
// }
// // TODO: 判断x,y,z 进行加减
// }break;
// case pcl::PCLPointField::FLOAT64:
// {
// pcl::traits::asType<pcl::PCLPointField::FLOAT64>::type val;
// memcpy(&val, msg_data + item.offset, sizeof(pcl::traits::asType<pcl::PCLPointField::FLOAT64>::type));
//
// auto it = dict_pclfieldname_lasid.find(item.name);
// if (it != dict_pclfieldname_lasid.end())
// {
// view->setField(it->second, ipoint, val);
// }
// }break;
// default:
// break;
// }
// }
// ++ipoint;
//
// 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);
// writer->execute(table);
//
// //las_options.add()
//
// //pdal::PointTable table;
// //auto layerout = table.layout();
// //pdal::PointLayout layerout;
// //layerout->registerDim(pdal::Dimension::Id::X);
// //layerout->registerDim(pdal::Dimension::Id::Y);
// //layerout->registerDim(pdal::Dimension::Id::Z);
//
// // ȱ�ٱ��� dim field ��Ӧ��ϵ
// //for (auto field : pcloud.fields)
// //{
// // if (0 == field.name.compare("_"))
// // continue;
//
// // auto dim = pdal::Dimension::id(field.name);
// // if (pdal::Dimension::Id::Unknown != dim)
// // {
// // layerout->registerDim(dim);
// // continue;
// // }
//
// // auto dimdatatype = GetLasDimDataType(field);
// // if (pdal::Dimension::Type::None == dimdatatype)
// // {
// // // TODO::
// // continue;
// // }
//
// // auto customdim = layerout->assignDim(field.name, dimdatatype);
// //}
//
//
//}
//
//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;
// }
//}
//
//void TestPcdreader()
//{
// std::string pcdfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add.pcd" };
//
// pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZRGBA>);
// //pcl::PointCloud<PPoint>::Ptr cloud(new pcl::PointCloud<PPoint>);
//// pcl::io::loadPCDFile(pcdfilepath, *cloud);
//
//
//
//
// //pcl::PCDReader p;
//
//
// pcl::PCLPointCloud2 pcd2;
// Eigen::Vector4f origin;
// Eigen::Quaternionf orientation;
// int res = pcl::io::loadPCDFile(pcdfilepath, pcd2, origin, orientation);
//
// //for (auto i : pcd2->points)
// //{
// // std::cout << "x=" << i.x;
// // std::cout << " y=" << i.y;
// // std::cout << " z=" << i.z << std::endl;
// // break;
// //}
//
// std::cout << "end" << std::endl;
//}
//
//#include <pdal/io/LasReader.hpp>
//#include <pdal/io/LasHeader.hpp>
//#include <pdal/io/LasVLR.hpp>
//#include <pdal/io/LasUtils.hpp>
//#include <pdal/Dimension.hpp>
//#include <vector>
//
//using DT = pdal::Dimension::Type;
//const pdal::Dimension::Type lastypes[] = {
// DT::None, DT::Unsigned8, DT::Signed8, DT::Unsigned16, DT::Signed16,
// DT::Unsigned32, DT::Signed32, DT::Unsigned64, DT::Signed64,
// DT::Float, DT::Double
//};
//
//void pdal::ExtraBytesIf::setType(uint8_t lastype)
//{
// m_fieldCnt = 1;
// while (lastype > 10)
// {
// m_fieldCnt++;
// lastype -= 10;
// }
//
// m_type = lastypes[lastype];
// if (m_type == Dimension::Type::None)
// m_fieldCnt = 0;
//}
//
//
//void pdal::ExtraBytesIf::readFrom(const char *buf)
//{
// LeExtractor extractor(buf, sizeof(ExtraBytesSpec));
// uint16_t dummy16;
// uint32_t dummy32;
// uint64_t dummy64;
// double dummyd;
// uint8_t options;
// uint8_t type;
//
// uint8_t SCALE_MASK = 1 << 3;
// uint8_t OFFSET_MASK = 1 << 4;
//
// extractor >> dummy16 >> type >> options;
// extractor.get(m_name, 32);
// extractor >> dummy32;
// for (size_t i = 0; i < 3; ++i)
// extractor >> dummy64; // No data field.
// for (size_t i = 0; i < 3; ++i)
// extractor >> dummyd; // Min.
// for (size_t i = 0; i < 3; ++i)
// extractor >> dummyd; // Max.
// for (size_t i = 0; i < 3; ++i)
// extractor >> m_scale[i];
// for (size_t i = 0; i < 3; ++i)
// extractor >> m_offset[i];
// extractor.get(m_description, 32);
//
// setType(type);
// if (m_type == Dimension::Type::None)
// m_size = options;
// if (!(options & SCALE_MASK))
// for (size_t i = 0; i < 3; ++i)
// m_scale[i] = 1.0;
// if (!(options & OFFSET_MASK))
// for (size_t i = 0; i < 3; ++i)
// m_offset[i] = 0.0;
//}
//
//std::vector<pdal::ExtraDim> pdal::ExtraBytesIf::toExtraDims()
//{
// std::vector<ExtraDim> eds;
//
// if (m_type == Dimension::Type::None)
// {
// ExtraDim ed(m_name, Dimension::Type::None);
// ed.m_size = m_size;
// eds.push_back(ed);
// }
// else if (m_fieldCnt == 1)
// {
// ExtraDim ed(m_name, m_type, m_scale[0], m_offset[0]);
// eds.push_back(ed);
// }
// else
// {
// for (size_t i = 0; i < m_fieldCnt; ++i)
// {
// ExtraDim ed(m_name + std::to_string(i), m_type,
// m_scale[i], m_offset[i]);
// eds.push_back(ed);
// }
// }
// return eds;
//}
//
//static bool ReadExtraBytesVlr(pdal::LasHeader& header, std::vector<pdal::ExtraDim>& extraDims)
//{
// using namespace pdal;
//
// const LasVLR *vlr = header.findVlr(SPEC_USER_ID, EXTRA_BYTES_RECORD_ID);
// if (!vlr)
// {
// return false;
// }
//
// size_t size = vlr->dataLen();
// if (size % sizeof(ExtraBytesSpec) != 0)
// {
// //ccLog::Warning("[LAS] Bad size for extra bytes VLR. Ignoring.");
// return false;
// }
// size_t count = size / sizeof(ExtraBytesSpec);
// //ccLog::PrintDebug("[LAS] VLR count: " + QString::number(count));
//
// try
// {
// const char* pos = vlr->data();
// for (size_t i = 0; i < count; ++i)
// {
// ExtraBytesIf eb;
// eb.readFrom(pos);
// pos += sizeof(ExtraBytesSpec);
//
// std::vector<ExtraDim> eds = eb.toExtraDims();
// for (const ExtraDim& ed : eds)
// {
// // ccLog::PrintDebug(QString("[LAS] VLR #%1: %2").arg(i + 1).arg(QString::fromStdString(ed.m_name)));
// extraDims.push_back(ed);
// }
// }
// }
// catch (const std::bad_alloc&)
// {
// //ccLog::Warning("[LAS] Not enough memory to retrieve the extra bytes fields.");
// return false;
// }
//
// return true;
//}
//
//void TestPdalReadLas()
//{
// using namespace pdal;
//
// std::string lasfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add_cc.las" };
// pdal::PointTable table;
// pdal::LasReader las_reader;
//
// pdal::Options las_opts;
// las_opts.add(pdal::Option("filename", lasfilepath));
// las_reader.setOptions(las_opts);
// las_reader.prepare(table);
// auto las_header = las_reader.header();
//
// std::vector<pdal::ExtraDim> extradims;
// ReadExtraBytesVlr(las_header, extradims);
//
// //las_opts.add(pdal::Option("extra_dims", "label=float"));
//
// StringList extraNamesToLoad;
// std::string extraDimsArg;
// for (unsigned i = 0; i < extradims.size(); ++i)
// {
// //if (s_lasOpenDlg->doLoadEVLR(i))
// //{
// extraDimsArg += extradims[i].m_name + "=" + pdal::Dimension::interpretationName(extradims[i].m_dimType.m_type) + ",";
// extraNamesToLoad.push_back(extradims[i].m_name);
// //}
// }
// pdal::Options las_opts2;
// las_opts2.add(pdal::Option("extra_dims", extraDimsArg));
// las_reader.addOptions(las_opts2);
// las_reader.prepare(table);
//
// pdal::PointViewSet point_view_set = las_reader.execute(table);
//
// pdal::PointViewPtr point_view = *point_view_set.begin();
// pdal::Dimension::IdList dims = point_view->dims();
// auto layout = point_view->layout();
//
// //ͷ�ļ���Ϣ
// unsigned int PointCount = las_header.pointCount();
// //char* projstr = table.spatialRef().getWKT(pdal::SpatialReference::e
//}
//
//void TestPdalWriteLas()
//{
// std::string lasfilepath{ "E:/data/jd/task1-2/1106/JF_PCD/12_ground_utm_add1.las" };
//
// pdal::Options las_options;
// las_options.add("filename", lasfilepath);
// las_options.add("extra_dims", "all");
// las_options.add("scale_x", 0.01);
// las_options.add("scale_y", 0.01);
// las_options.add("scale_z", 0.01);
// las_options.add("offset_x", 0.0);
// las_options.add("offset_y", 0.0);
// las_options.add("offset_z", 0.0);
// pdal::Uuid uuid;
// uuid.parse("C8DED732-F71F-44D7-A62E-24F7F8A43E69");
// las_options.add("project_id", uuid);
//
// //las_options.add()
//
// pdal::PointTable table;
// auto layerout = table.layout();
// //pdal::PointLayout layerout;
// layerout->registerDim(pdal::Dimension::Id::X);
// layerout->registerDim(pdal::Dimension::Id::Y);
// layerout->registerDim(pdal::Dimension::Id::Z);
// //layerout.registerDim(pdal::Dimension::Id::lay)
// auto labelid = layerout->assignDim("label", pdal::Dimension::Type::Double);
//
// pdal::PointViewPtr view(new pdal::PointView(table));
// for (int i = 0; i < 100; ++i)
// {
// view->setField(pdal::Dimension::Id::X, i, i * 10.0);
// view->setField(pdal::Dimension::Id::Y, i, i * 10.0);
// view->setField(pdal::Dimension::Id::Z, i, i * 10.0);
// view->setField(labelid, i, i);
// }
//
// 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);
// writer->execute(table);
//}
//
//#include <pcl/io/pcd_io.h>
//
////POINT_CLOUD_REGISTER_POINT_STRUCT(
//// PointXYZIT, (float, x, x)(float, y, y)(float, z, z)(float, intensity, intensity))
// typedef pcl::PointCloud<PPoint> PPointCloud;
//void TestPCLRead()
//{
// PPointCloud* pcld = new PPointCloud();
// std::string filepath = "E:/gdata/gjd/task1-2/1106/JF_PCD/12_ground_utm_add.pcd";
// pcl::io::loadPCDFile(filepath, *pcld);
//}
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