Skip to content

Commit

Permalink
temp
Browse files Browse the repository at this point in the history
  • Loading branch information
171930433 committed Mar 15, 2024
1 parent e6ae53f commit e189c82
Show file tree
Hide file tree
Showing 14 changed files with 80 additions and 71 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ endif()

# 指定struct_pb库目录
set(struct_pb_plugin_DIRS ${CMAKE_CURRENT_LIST_DIR}/src/protoc-plugin) # struct_pb_plugin_DIRS 将指定 proto_to_struct.proto,struct_pb.cmake等目录
set(Protobuf_IMPORT_DIRS ${struct_pb_plugin_DIRS} ) # 设置protoc --proto_path参数
set(Protobuf_IMPORT_DIRS ${CMAKE_SOURCE_DIR}) # 设置protoc --proto_path参数


# add_subdirectory(src/protoc-plugin)
Expand Down
30 changes: 24 additions & 6 deletions src/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,29 @@ include(${struct_pb_plugin_DIRS}/cmake/struct_pb.cmake)
find_package(PCL REQUIRED COMPONENTS common io)
find_package(OpenCV REQUIRED COMPONENTS core)

file(GLOB PROTO_FILES "*.proto")
# file(GLOB PROTO_FILES "*.proto")

# set(PROTO_FILES "base.proto" "zframe.proto" "imu.proto")
set(PROTO_FILES "/home/gsk/pro/yalantinglibs/src/example/base.proto" "/home/gsk/pro/yalantinglibs/src/example/zframe.proto")


# 输出到指定目录
message(!!!!!!"${CMAKE_BINARY_DIR}"!!!!!!!)
protobuf_generate_cpp(COMMON_PROTO_SRCS COMMON_PROTO_HDRS
${struct_pb_plugin_DIRS}/proto_to_struct.proto
PROTOC_OUT_DIR ${CMAKE_BINARY_DIR}/src/protoc-plugin
)
protobuf_generate_python(COMMON_PROTO_PYTHON_SRCS
${struct_pb_plugin_DIRS}/proto_to_struct.proto
PROTOC_OUT_DIR ${CMAKE_BINARY_DIR}/src/protoc-plugin
)

# generate .pb.cc .pb.h
protobuf_generate_cpp(PROTO_SRCS PROTO_HDRS
${struct_pb_plugin_DIRS}/proto_to_struct.proto
${PROTO_FILES}
)

protobuf_generate_python(PROTO_PYTHON_SRCS
${struct_pb_plugin_DIRS}/proto_to_struct.proto
${PROTO_FILES}
)

Expand All @@ -30,15 +43,19 @@ list(FILTER PROTO_FILES EXCLUDE REGEX "pointcloud\\.proto$|image\\.proto$")

protobuf_generate_struct_pb(PROTO_STRUCT_SRCS PROTO_STRUCT_HDRS
${PROTO_FILES}
OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter")
OPTION "namespace=zhito.inner_struct,converter_namespace=zhito.converter"
# PROTOC_OUT_DIR ${CMAKE_CURRENT_BINARY_DIR}
)

add_executable(struct_pb_tutorial tutorial.cpp
zpointcloud.cpp zimage.cpp
#
${COMMON_PROTO_SRCS} ${COMMON_PROTO_HDRS} ${COMMON_PROTO_PYTHON_SRCS}
# zpointcloud.cpp zimage.cpp
${PROTO_SRCS}
${PROTO_HDRS}
${PROTO_STRUCT_SRCS}
${PROTO_STRUCT_HDRS}
${PROTO_PYTHON_SRCS}
# ${PROTO_PYTHON_SRCS}
)

target_link_libraries(struct_pb_tutorial protobuf::libprotobuf
Expand All @@ -52,6 +69,7 @@ target_include_directories(struct_pb_tutorial PUBLIC
${CMAKE_CURRENT_LIST_DIR}
${PCL_INCLUDE_DIRS}
${OpenCV_INCLUDE_DIRS}
${CMAKE_BINARY_DIR}/src/protoc-plugin
)


3 changes: 1 addition & 2 deletions src/example/base.proto
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
syntax = "proto3";
package zhito.inner_class;

import "proto_to_struct.proto";

import "src/protoc-plugin/proto_to_struct.proto";
option(write_eigen_helper) = true;

message Vector4f
Expand Down
5 changes: 2 additions & 3 deletions src/example/chasis.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "base.proto";
import "src/example/zframe.proto";
import "src/example/base.proto";
import "proto_to_struct.proto";

message ZChassis
{
ZFrame header = 1 [(inherits_from) = true];
Expand Down
5 changes: 2 additions & 3 deletions src/example/gnss.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "base.proto";
import "src/example/zframe.proto";
import "src/example/base.proto";
import "proto_to_struct.proto";

message ZGnss
{
ZFrame header = 1 [(inherits_from) = true];;
Expand Down
2 changes: 1 addition & 1 deletion src/example/image.proto
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "src/example/zframe.proto";

message ZImage
{
Expand Down
5 changes: 2 additions & 3 deletions src/example/imu.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "base.proto";
import "src/example/zframe.proto";
import "src/example/base.proto";
import "proto_to_struct.proto";

message ZImu
{
ZFrame header = 1 [(inherits_from) = true];
Expand Down
5 changes: 2 additions & 3 deletions src/example/perception.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "base.proto";
import "src/example/zframe.proto";
import "src/example/base.proto";
import "proto_to_struct.proto";

message ZPercBase
{
int32 track_id = 1;
Expand Down
5 changes: 2 additions & 3 deletions src/example/pointcloud.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "base.proto";
import "src/example/zframe.proto";
import "src/example/base.proto";
import "proto_to_struct.proto";

message ZPointCloudXYZIT
{
ZFrame header = 1 ;
Expand Down
5 changes: 2 additions & 3 deletions src/example/state.proto
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
syntax = "proto3";
package zhito.inner_class;

import "zframe.proto";
import "base.proto";
import "src/example/zframe.proto";
import "src/example/base.proto";
import "proto_to_struct.proto";

message ZState{
ZFrame header = 1 [(inherits_from) = true];
Vector3d pos = 2;//位置: X Y Z
Expand Down
76 changes: 38 additions & 38 deletions src/example/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,60 @@
#include <string>

// #include "addressbook.struct_pb.h"
#include "imu.struct_pb.h"
#include "zimage.hpp"
#include "zpointcloud.hpp"
// #include "imu.struct_pb.h"
// #include "zimage.hpp"
// #include "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);
// }

inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc);
inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2);
// inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc);
// inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2);

// 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;
// void ImuDemo() {
// using namespace zhito;

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);
// 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;
}
// std::cout << imu1 << std::endl;
// std::cout << imu2.ShortDebugString() << std::endl;
// 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
5 changes: 2 additions & 3 deletions src/example/zframe.proto
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
syntax = "proto3";
package zhito.inner_class;

import "base.proto";
import "proto_to_struct.proto";

import "src/example/base.proto";
import "src/protoc-plugin/proto_to_struct.proto";
enum ZFrameType{
None = 0;
VEHICLE_MODEL = 1; // 车辆运动约束虚拟帧
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
1 change: 0 additions & 1 deletion src/struct_pb/examples/addressbook.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ syntax = "proto3";

import "proto_to_struct.proto";


package tutorial;

enum MyType {
Expand Down

0 comments on commit e189c82

Please sign in to comment.