Skip to content

Commit

Permalink
添加点云demo
Browse files Browse the repository at this point in the history
  • Loading branch information
171930433 committed Mar 9, 2024
1 parent e8cab8b commit 685f5e3
Show file tree
Hide file tree
Showing 6 changed files with 114 additions and 74 deletions.
1 change: 1 addition & 0 deletions .clang-format
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ BraceWrapping:
BeforeElse: true
AllowShortLambdasOnASingleLine: None
AllowShortIfStatementsOnASingleLine: Never
ColumnLimit: 120
---
Language: JavaScript
DisableFormat: true
Expand Down
4 changes: 2 additions & 2 deletions src/struct_pb/protoc-plugin/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 3 additions & 23 deletions src/struct_pb/protoc-plugin/example/pointcloud.proto
Original file line number Diff line number Diff line change
Expand Up @@ -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<pcl::PointXYZI>";

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的压缩点云
}

73 changes: 24 additions & 49 deletions src/struct_pb/protoc-plugin/example/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,71 +5,46 @@

// #include "addressbook.struct_pb.h"
#include "imu.struct_pb.h"
#include "zpointcloud.hpp"

#include "xyzit_points.hpp"
#include <pcl/point_cloud.h>

#include <pcl/io/pcd_io.h>
void PointcloudDemo()
{
pcl::PointXYZIT p2 {1,2};

// #include <pcl/compression/organized_pointcloud_compression.h>
// #include <pcl/io/impl/organized_pointcloud_compression.hpp>
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);
}

#include <pcl/compression/octree_pointcloud_compression.h>
#include <pcl/io/impl/octree_pointcloud_compression.hpp>
inner_class::ZPointCloudXYZIT pc2 = converter::StructToClass(pc);
inner_struct::spZPointCloudXYZIT pc3 = converter::ClassToStruct(pc2);

#include <pcl/octree/octree_pointcloud.h>
#include <pcl/octree/impl/octree_pointcloud.hpp>
// 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<pcl::PointXYZIT>::Ptr pc = std::make_shared<pcl::PointCloud<pcl::PointXYZIT>>();
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<pcl::PointXYZIT> 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<pcl::PointXYZIT>::Ptr pc2 = std::make_shared<pcl::PointCloud<pcl::PointXYZIT>>();
compress.decodePointCloud(ss,pc2);

std::cout << *pc2 << std::endl;

ImuDemo();
PointcloudDemo();

std::cout << "Done!!!" << std::endl;

Expand Down
39 changes: 39 additions & 0 deletions src/struct_pb/protoc-plugin/example/zpointcloud.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "zpointcloud.hpp"

#include <pcl/compression/octree_pointcloud_compression.h>
#include <pcl/octree/octree_pointcloud.h>

#include <pcl/io/impl/octree_pointcloud_compression.hpp>
#include <pcl/octree/impl/octree_pointcloud.hpp>

namespace converter {
// StructToClass declaration

// static pcl::io::OctreePointCloudCompression<pcl::PointXYZIT> s_compress(
// {pcl::io::compression_Profiles_e::MED_RES_ONLINE_COMPRESSION_WITH_COLOR}, true);
static pcl::io::OctreePointCloudCompression<pcl::PointXYZIT> s_compress;

::inner_class::ZPointCloudXYZIT StructToClass(inner_struct::sp_cZPointCloudXYZIT const& in) {
::inner_class::ZPointCloudXYZIT result;
*result.mutable_header() = StructToClass(*(std::shared_ptr<inner_struct::ZFrame const>)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<inner_struct::ZPointCloudXYZIT>();
pcl::PointCloud<pcl::PointXYZIT>::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
45 changes: 45 additions & 0 deletions src/struct_pb/protoc-plugin/example/zpointcloud.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#pragma once

#include <pcl/point_cloud.h>

#include "base.struct_pb.h"
#include "pointcloud.pb.h"
#include "xyzit_points.hpp"

// save to file
#include <pcl/io/pcd_io.h>
#include <pcl/io/impl/pcd_io.hpp>

namespace inner_struct {

template <typename _PointType>
struct ZPointCloud : public ZFrame, public pcl::PointCloud<_PointType> {

};

using ZPointCloudXYZIT = ::inner_struct::ZPointCloud<pcl::PointXYZIT>;
using spZPointCloudXYZIT = std::shared_ptr<::inner_struct::ZPointCloudXYZIT>;
using sp_cZPointCloudXYZIT = std::shared_ptr<::inner_struct::ZPointCloudXYZIT const>;


template <typename _PointType>
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

0 comments on commit 685f5e3

Please sign in to comment.