Skip to content

Commit

Permalink
测试完成,但是点云测试用例无法通过
Browse files Browse the repository at this point in the history
  • Loading branch information
171930433 committed Mar 20, 2024
1 parent 5ab4a5a commit 16209df
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 38 deletions.
27 changes: 18 additions & 9 deletions src/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -36,21 +34,18 @@ 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}
${PROTO_STRUCT_HDRS}
${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}
Expand All @@ -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)
2 changes: 2 additions & 0 deletions src/example/message/zpointcloud.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<T>, 可以使用多态,即直接使用子类对象或者子类智能指针
s_compress.decodePointCloud(compressed_pcl_pointcloud, (pcl::PointCloud<pcl::PointXYZIT>::Ptr&)result);
// std::cout <<" compressed_pcl_pointcloud size = " << compressed_pcl_pointcloud.str().size() << " done \n";

return result;
}
Expand Down
59 changes: 31 additions & 28 deletions src/example/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<inner_struct::ZPointCloudXYZIT>();
// *(std::shared_ptr<inner_struct::ZFrame>)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<inner_struct::ZPointCloudXYZIT>();
*(std::shared_ptr<inner_struct::ZFrame>)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;
Expand All @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/protoc-plugin/cmake/struct_pb.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 16209df

Please sign in to comment.