diff --git a/.clang-format b/.clang-format index ea9836807..b7f73aa44 100644 --- a/.clang-format +++ b/.clang-format @@ -7,6 +7,7 @@ BraceWrapping: BeforeElse: true AllowShortLambdasOnASingleLine: None AllowShortIfStatementsOnASingleLine: Never +ColumnLimit: 120 --- Language: JavaScript DisableFormat: true diff --git a/src/struct_pb/protoc-plugin/example/CMakeLists.txt b/src/struct_pb/protoc-plugin/example/CMakeLists.txt index d5a21b255..b95de0726 100644 --- a/src/struct_pb/protoc-plugin/example/CMakeLists.txt +++ b/src/struct_pb/protoc-plugin/example/CMakeLists.txt @@ -24,9 +24,9 @@ if (Protobuf_FOUND) state.proto chasis.proto perception.proto - # pointcloud.proto + pointcloud.proto ) - add_executable(struct_pb_tutorial tutorial.cpp + add_executable(struct_pb_tutorial tutorial.cpp zpointcloud.cpp ${PROTO_SRCS} ${PROTO_HDRS}) target_link_libraries(struct_pb_tutorial protobuf::libprotobuf pcl_common pcl_io pcl_octree) diff --git a/src/struct_pb/protoc-plugin/example/pointcloud.proto b/src/struct_pb/protoc-plugin/example/pointcloud.proto index 2ff26fe7f..ba68b156c 100644 --- a/src/struct_pb/protoc-plugin/example/pointcloud.proto +++ b/src/struct_pb/protoc-plugin/example/pointcloud.proto @@ -4,31 +4,11 @@ package inner_class; import "base.proto"; import "proto_to_struct.proto"; -option(write_pcl_helper) = true; -message PointXYZI -{ - option(pcl_typename) = "pcl::PointXYZI"; - repeated float data = 3 [(fix_size) = 4]; // data[0-2] x y z - repeated float data_c = 4 [(fix_size) = 4]; // data_c[0] intensity -} - -message PclCloudXYZI -{ - option(pcl_typename) = "pcl::PointCloud"; - - repeated PointXYZI points = 1; - uint32 width = 2; - uint32 height = 3; - bool is_dense = 4; - Vector4f sensor_origin_ = 5; - Quaternionf sensor_orientation_ = 6; -} -message ZPointCloudXYZI +message ZPointCloudXYZIT { - ZFrame header = 1 [(inherits_from) = true]; - // PclCloudXYZI point_cloud = 2 [(inherits_from) = true]; - bytes points = 2; + ZFrame header = 1 ; + bytes pcl_compressed_pc = 2; // pcl的压缩点云 } diff --git a/src/struct_pb/protoc-plugin/example/tutorial.cpp b/src/struct_pb/protoc-plugin/example/tutorial.cpp index 1c2a08ed1..baf8330ab 100644 --- a/src/struct_pb/protoc-plugin/example/tutorial.cpp +++ b/src/struct_pb/protoc-plugin/example/tutorial.cpp @@ -5,71 +5,46 @@ // #include "addressbook.struct_pb.h" #include "imu.struct_pb.h" +#include "zpointcloud.hpp" -#include "xyzit_points.hpp" -#include -#include +void PointcloudDemo() +{ + pcl::PointXYZIT p2 {1,2}; -// #include -// #include + inner_struct::spZPointCloudXYZIT pc = std::make_shared(); + *(std::shared_ptr)pc = inner_struct::ZFrame{1,2,3,inner_struct::ZFrameType::PointCloud, "/zhito/pointcloud"}; + for (int i = 0; i < 1e5; ++i) { + p2.x += (rand() % 10000 * 0.0001); + pc->push_back(p2); + } -#include -#include + inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc); + inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2); -#include -#include + // pcl::io::savePCDFileBinaryCompressed("1.pcd", *pc3); + std::cout << *pc3 << std::endl; +} - - -int main() { - +void ImuDemo() +{ inner_struct::ZImu imu1{1,2,3,inner_struct::ZFrameType::IMU,"channel_name", {4,5,6}, {7,8,9}, 10}; inner_class::ZImu imu2 = converter::StructToClass(imu1); inner_struct::ZImu imu3 = converter::ClassToStruct(imu2); - // std::cout << imu1 << std::endl; - // std::cout << imu2.ShortDebugString() << std::endl; - // std::cout << imu3 << std::endl; - - - // inner_struct::ZPointCloudXYZI pc1; - // pc1.points.push_back(pcl::PointXYZI()); - // pc1.points.push_back(pcl::PointXYZI()); - // pcl::PointXYZI p1; - // pcl::PointXYZI p1 {1}; - // std::cout << p1 << std::endl; - - pcl::PointXYZIT p2 {1,2}; - // std::cout << p2 << std::endl; - - - pcl::PointCloud::Ptr pc = std::make_shared>(); - pc->push_back(p2); - pc->push_back(p2); - pc->push_back(p2); - pc->push_back(p2); - - std::cout<< pc->width <<" " << pc->height << std::endl; - - - pcl::io::OctreePointCloudCompression compress; - - std::stringstream ss; - - compress.encodePointCloud(pc,ss); - - std::cout<<" str = " << ss.str() << std::endl; + std::cout << imu1 << std::endl; + std::cout << imu2.ShortDebugString() << std::endl; + std::cout << imu3 << std::endl; +} +int main() { - // pc2 - pcl::PointCloud::Ptr pc2 = std::make_shared>(); - compress.decodePointCloud(ss,pc2); - std::cout << *pc2 << std::endl; + ImuDemo(); + PointcloudDemo(); std::cout << "Done!!!" << std::endl; diff --git a/src/struct_pb/protoc-plugin/example/zpointcloud.cpp b/src/struct_pb/protoc-plugin/example/zpointcloud.cpp new file mode 100644 index 000000000..6ba4308e3 --- /dev/null +++ b/src/struct_pb/protoc-plugin/example/zpointcloud.cpp @@ -0,0 +1,39 @@ +#include "zpointcloud.hpp" + +#include +#include + +#include +#include + +namespace converter { +// StructToClass declaration + +// static pcl::io::OctreePointCloudCompression s_compress( +// {pcl::io::compression_Profiles_e::MED_RES_ONLINE_COMPRESSION_WITH_COLOR}, true); +static pcl::io::OctreePointCloudCompression s_compress; + +::inner_class::ZPointCloudXYZIT StructToClass(inner_struct::sp_cZPointCloudXYZIT const& in) { + ::inner_class::ZPointCloudXYZIT result; + *result.mutable_header() = StructToClass(*(std::shared_ptr)in); + // 压缩点云 + std::stringstream compressed_pcl_pointcloud; + s_compress.encodePointCloud(in, compressed_pcl_pointcloud); + result.set_pcl_compressed_pc(compressed_pcl_pointcloud.str()); + // std::cout <<" compress size = " << compressed_pcl_pointcloud.str().size() <<"\n"; + return result; +} + +// ClassToStruct declaration +inner_struct::spZPointCloudXYZIT ClassToStruct(::inner_class::ZPointCloudXYZIT const& in) { + ::inner_struct::spZPointCloudXYZIT result = std::make_shared(); + pcl::PointCloud::Ptr pc_result = result; // stupid code , need solve + *(std::shared_ptr<::inner_struct::ZFrame>)result = ClassToStruct(in.header()); + // 解压点云 + std::stringstream compressed_pcl_pointcloud(in.pcl_compressed_pc()); + s_compress.decodePointCloud(compressed_pcl_pointcloud, pc_result); + + return result; +} + +} // namespace converter diff --git a/src/struct_pb/protoc-plugin/example/zpointcloud.hpp b/src/struct_pb/protoc-plugin/example/zpointcloud.hpp new file mode 100644 index 000000000..ef54aa1a7 --- /dev/null +++ b/src/struct_pb/protoc-plugin/example/zpointcloud.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include + +#include "base.struct_pb.h" +#include "pointcloud.pb.h" +#include "xyzit_points.hpp" + +// save to file +#include +#include + +namespace inner_struct { + +template +struct ZPointCloud : public ZFrame, public pcl::PointCloud<_PointType> { + +}; + +using ZPointCloudXYZIT = ::inner_struct::ZPointCloud; +using spZPointCloudXYZIT = std::shared_ptr<::inner_struct::ZPointCloudXYZIT>; +using sp_cZPointCloudXYZIT = std::shared_ptr<::inner_struct::ZPointCloudXYZIT const>; + + +template +inline std::ostream& operator<<(std::ostream& os,::inner_struct::ZPointCloud<_PointType> const& in) +{ + os << (ZFrame&)in << std::endl; + os << (pcl::PointCloud<_PointType>&)in << std::endl; + return os; +} + +} // namespace inner_struct + + +namespace converter { +// StructToClass declaration + +::inner_class::ZPointCloudXYZIT StructToClass(inner_struct::sp_cZPointCloudXYZIT const& in); +// enum + +// ClassToStruct declaration +::inner_struct::spZPointCloudXYZIT ClassToStruct(::inner_class::ZPointCloudXYZIT const& in); + +} // namespace converter \ No newline at end of file