diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index dd04f98c4..d7e38cefa 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -21,13 +21,11 @@ file(GLOB PROTO_FILES "*.proto") protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS ${struct_pb_plugin_DIRS}/proto_to_struct.proto ${PROTO_FILES} - # IMPORT_DIRS ${CMAKE_SOURCE_DIR} ) protobuf_generate_python(PROTO_PYTHON_SRCS ${struct_pb_plugin_DIRS}/proto_to_struct.proto ${PROTO_FILES} - # IMPORT_DIRS ${CMAKE_SOURCE_DIR} ) protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS @@ -36,7 +34,8 @@ OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter" # PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR} ) -add_executable(struct_pb_tutorial tutorial.cpp + +add_library(proto_common OBJECT ${PROTO_SRCS} ${PROTO_HDRS} ${PROTO_STRUCT_SRCS} @@ -44,13 +43,9 @@ add_executable(struct_pb_tutorial tutorial.cpp ${PROTO_PYTHON_SRCS} ) -target_link_libraries(struct_pb_tutorial protobuf::libprotobuf - pcl_common pcl_io # pcl - opencv_imgcodecs opencv_core # opencv - $ENV{proto_message} -) +target_link_libraries(proto_common protobuf::libprotobuf ) -target_include_directories(struct_pb_tutorial PUBLIC +target_include_directories(proto_common PUBLIC ${CMAKE_BINARY_DIR} ${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_LIST_DIR} @@ -59,4 +54,18 @@ target_include_directories(struct_pb_tutorial PUBLIC ${CMAKE_BINARY_DIR}/src/protoc-plugin ) + +add_executable(struct_pb_tutorial tutorial.cpp ) + +target_link_libraries(struct_pb_tutorial + proto_common + $ENV{proto_message} +) + +target_include_directories(struct_pb_tutorial PUBLIC + ${CMAKE_BINARY_DIR} + ${CMAKE_SOURCE_DIR} +) + + add_subdirectory(message) diff --git a/src/example/message/zpointcloud.cpp b/src/example/message/zpointcloud.cpp index 9c20b26cf..2d3388343 100644 --- a/src/example/message/zpointcloud.cpp +++ b/src/example/message/zpointcloud.cpp @@ -33,8 +33,10 @@ zhito::inner_struct::spZPointCloudXYZIT ClassToStruct(::zhito::inner_class::ZPoi *(std::shared_ptr<::zhito::inner_struct::ZFrame>)result = ClassToStruct(in.header()); // 解压点云 std::stringstream compressed_pcl_pointcloud(in.pcl_compressed_pc()); + // std::cout <<" compressed_pcl_pointcloud size = " << compressed_pcl_pointcloud.str().size() << "\n"; // decodePointCloud 的参数定义成了智能指针的引用, 所以不能存在转换. 只有是 const T& 和 std::shared_ptr, 可以使用多态,即直接使用子类对象或者子类智能指针 s_compress.decodePointCloud(compressed_pcl_pointcloud, (pcl::PointCloud::Ptr&)result); + // std::cout <<" compressed_pcl_pointcloud size = " << compressed_pcl_pointcloud.str().size() << " done \n"; return result; } diff --git a/src/example/tutorial.cpp b/src/example/tutorial.cpp index c79cad233..e998b9bf1 100644 --- a/src/example/tutorial.cpp +++ b/src/example/tutorial.cpp @@ -5,28 +5,31 @@ // #include "addressbook.struct_pb.h" #include "src/example/message/imu.struct_pb.h" -// #include "src/message/zimage.hpp" -// #include "src/message/zpointcloud.hpp" +#include "src/example/message/zimage.hpp" +#include "src/example/message/zpointcloud.hpp" -// void PointcloudDemo() { -// using namespace zhito; -// pcl::PointXYZIT p2{1, 2}; +void PointcloudDemo() { + using namespace zhito; + pcl::PointXYZIT p2{1, 2}; -// 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); -// } + 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); + } +// std::cout<< "11111111111\n"; + inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc); +// std::cout<< "2222222222222\n"; -// inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc); -// inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2); + inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2); +// std::cout<< "33333\n"; -// // pcl::io::savePCDFileBinaryCompressed("1.pcd", *pc3); + // pcl::io::savePCDFileBinaryCompressed("1.pcd", *pc3); -// std::cout << *pc3 << std::endl; -// } + std::cout << *pc3 << std::endl; +} void ImuDemo() { using namespace zhito; @@ -40,24 +43,24 @@ void ImuDemo() { std::cout << imu3 << std::endl; } -// void ImageDemo() { -// using namespace zhito; +void ImageDemo() { + using namespace zhito; -// inner_struct::ZImage image1{1, 2, 3, inner_struct::ZFrameType::CvImage, "/zhito/image"}; -// (cv::Mat&)image1 = cv::Mat::eye(4, 4, CV_64F); + inner_struct::ZImage image1{1, 2, 3, inner_struct::ZFrameType::CvImage, "/zhito/image"}; + (cv::Mat&)image1 = cv::Mat::eye(4, 4, CV_64F); -// inner_class::ZImage image2 = converter::StructToClass(image1); -// inner_struct::ZImage image3 = converter::ClassToStruct(image2); + inner_class::ZImage image2 = converter::StructToClass(image1); + inner_struct::ZImage image3 = converter::ClassToStruct(image2); -// std::cout << image1 << std::endl; -// std::cout << image2.ShortDebugString() << std::endl; -// std::cout << image3 << std::endl; -// } + std::cout << image1 << std::endl; + std::cout << image2.ShortDebugString() << std::endl; + std::cout << image3 << std::endl; +} int main() { ImuDemo(); // PointcloudDemo(); - // ImageDemo(); + ImageDemo(); std::cout << "Done!!!" << std::endl; diff --git a/src/protoc-plugin/cmake/struct_pb.cmake b/src/protoc-plugin/cmake/struct_pb.cmake index 52c7c14be..3c24182ef 100644 --- a/src/protoc-plugin/cmake/struct_pb.cmake +++ b/src/protoc-plugin/cmake/struct_pb.cmake @@ -119,7 +119,7 @@ function(protobuf_generate_modified) # message(status _out!!!!!!!!${protobuf_generate_LANGUAGE}_out}) - message(status _opt!!!!!!!!${_opt}${protobuf_generate_PROTOC_OUT_DIR}) + # message(status _opt!!!!!!!!${_opt}${protobuf_generate_PROTOC_OUT_DIR}) add_custom_command(