diff --git a/src/struct_pb/protoc-plugin/example/CMakeLists.txt b/src/struct_pb/protoc-plugin/example/CMakeLists.txt index e4b9072cc..d5a21b255 100644 --- a/src/struct_pb/protoc-plugin/example/CMakeLists.txt +++ b/src/struct_pb/protoc-plugin/example/CMakeLists.txt @@ -7,7 +7,8 @@ set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/output/examples) include(../cmake/struct_pb.cmake) cmake_policy(SET CMP0075 NEW) -find_package(PCL REQUIRED package common) +find_package(PCL REQUIRED package common io octree) +# find_package(PCL REQUIRED ) if (Protobuf_FOUND) @@ -28,7 +29,10 @@ if (Protobuf_FOUND) add_executable(struct_pb_tutorial tutorial.cpp ${PROTO_SRCS} ${PROTO_HDRS}) - target_link_libraries(struct_pb_tutorial protobuf::libprotobuf pcl_common) + target_link_libraries(struct_pb_tutorial protobuf::libprotobuf pcl_common pcl_io pcl_octree) + # target_link_libraries(struct_pb_tutorial protobuf::libprotobuf ${PCL_LIBRARIES}) + + target_include_directories(struct_pb_tutorial PUBLIC ${CMAKE_CURRENT_BINARY_DIR} diff --git a/src/struct_pb/protoc-plugin/example/tutorial.cpp b/src/struct_pb/protoc-plugin/example/tutorial.cpp index a03ca83f0..1c2a08ed1 100644 --- a/src/struct_pb/protoc-plugin/example/tutorial.cpp +++ b/src/struct_pb/protoc-plugin/example/tutorial.cpp @@ -5,51 +5,22 @@ // #include "addressbook.struct_pb.h" #include "imu.struct_pb.h" -#include - -#include -namespace pcl -{ -struct EIGEN_ALIGN16 _PointXYZIT { - PCL_ADD_POINT4D // This adds the members x,y,z which can also be accessed - // using the point (which is float[4]) - union { - struct { - float intensity; - float dt; // 添加 intensity 属性 - }; - float data_c[4]; - }; - PCL_MAKE_ALIGNED_OPERATOR_NEW -}; - -struct PointXYZIT : public _PointXYZIT -{ - inline constexpr PointXYZIT (const _PointXYZIT &p) : PointXYZIT{p.x, p.y, p.z, p.intensity, p.dt} {} - - inline constexpr PointXYZIT (float _intensity = 0.f, float _dt = 0.f) : PointXYZIT(0.f, 0.f, 0.f, _intensity,_dt) {} - - inline constexpr PointXYZIT (float _x, float _y, float _z, float _intensity = 0.f, float _dt = 0.f) : _PointXYZIT{{{_x, _y, _z, 1.0f}}, {{_intensity,_dt}}} {} - - friend std::ostream& operator << (std::ostream& os, const PointXYZIT& p); -}; - -inline std::ostream& operator << (std::ostream& os, const PointXYZIT& p) -{ - os << "(" << p.x << "," << p.y << "," << p.z << " - " << p.intensity <<" " << p.dt << ")"; - return (os); -} -} +#include "xyzit_points.hpp" +#include + +#include + +// #include +// #include + +#include +#include + +#include +#include + -// 声明 PCL 的宏定义以实现点类型 -POINT_CLOUD_REGISTER_POINT_STRUCT(pcl::PointXYZIT, // 自定义点类型的名称 - (float, x, x) // 属性 x - (float, y, y) // 属性 y - (float, z, z) // 属性 z - (float, intensity, intensity) // 属性 intensity - (float, dt, dt) // 属性 dt -) int main() { @@ -68,11 +39,36 @@ int main() { // 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::PointXYZI p1 {1}; + // std::cout << p1 << std::endl; pcl::PointXYZIT p2 {1,2}; - std::cout << p2 << std::endl; + // 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; + + + // pc2 + pcl::PointCloud::Ptr pc2 = std::make_shared>(); + compress.decodePointCloud(ss,pc2); + + std::cout << *pc2 << std::endl; std::cout << "Done!!!" << std::endl; diff --git a/src/struct_pb/protoc-plugin/example/xyzit_points.hpp b/src/struct_pb/protoc-plugin/example/xyzit_points.hpp new file mode 100644 index 000000000..44b6348b5 --- /dev/null +++ b/src/struct_pb/protoc-plugin/example/xyzit_points.hpp @@ -0,0 +1,43 @@ +#include +namespace pcl +{ +struct EIGEN_ALIGN16 _PointXYZIT { + PCL_ADD_POINT4D // This adds the members x,y,z which can also be accessed + // using the point (which is float[4]) + union { + struct { + float intensity; + float dt; // 添加 intensity 属性 + }; + float data_c[4]; + }; + PCL_MAKE_ALIGNED_OPERATOR_NEW +}; + +struct PointXYZIT : public _PointXYZIT +{ + inline constexpr PointXYZIT (const _PointXYZIT &p) : PointXYZIT{p.x, p.y, p.z, p.intensity, p.dt} {} + + inline constexpr PointXYZIT (float _intensity = 0.f, float _dt = 0.f) : PointXYZIT(0.f, 0.f, 0.f, _intensity,_dt) {} + + inline constexpr PointXYZIT (float _x, float _y, float _z, float _intensity = 0.f, float _dt = 0.f) : _PointXYZIT{{{_x, _y, _z, 1.0f}}, {{_intensity,_dt}}} {} + + friend std::ostream& operator << (std::ostream& os, const PointXYZIT& p); +}; + +inline std::ostream& operator << (std::ostream& os, const PointXYZIT& p) +{ + os << "(" << p.x << "," << p.y << "," << p.z << " - " << p.intensity <<" " << p.dt << ")"; + return (os); +} + +} + +// 声明 PCL 的宏定义以实现点类型 +POINT_CLOUD_REGISTER_POINT_STRUCT(pcl::PointXYZIT, // 自定义点类型的名称 + (float, x, x) // 属性 x + (float, y, y) // 属性 y + (float, z, z) // 属性 z + (float, intensity, intensity) // 属性 intensity + (float, dt, dt) // 属性 dt +) \ No newline at end of file