Skip to content

Commit

Permalink
OctreePointCloudCompression compile done
Browse files Browse the repository at this point in the history
  • Loading branch information
171930433 committed Mar 9, 2024
1 parent 96d3135 commit e8cab8b
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 48 deletions.
8 changes: 6 additions & 2 deletions src/struct_pb/protoc-plugin/example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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}
Expand Down
88 changes: 42 additions & 46 deletions src/struct_pb/protoc-plugin/example/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,22 @@

// #include "addressbook.struct_pb.h"
#include "imu.struct_pb.h"
#include <pcl/compression/organized_pointcloud_compression.h>

#include <pcl/point_types.h>
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 <pcl/point_cloud.h>

#include <pcl/io/pcd_io.h>

// #include <pcl/compression/organized_pointcloud_compression.h>
// #include <pcl/io/impl/organized_pointcloud_compression.hpp>

#include <pcl/compression/octree_pointcloud_compression.h>
#include <pcl/io/impl/octree_pointcloud_compression.hpp>

#include <pcl/octree/octree_pointcloud.h>
#include <pcl/octree/impl/octree_pointcloud.hpp>


// 声明 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() {
Expand All @@ -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<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;


// pc2
pcl::PointCloud<pcl::PointXYZIT>::Ptr pc2 = std::make_shared<pcl::PointCloud<pcl::PointXYZIT>>();
compress.decodePointCloud(ss,pc2);

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


std::cout << "Done!!!" << std::endl;
Expand Down
43 changes: 43 additions & 0 deletions src/struct_pb/protoc-plugin/example/xyzit_points.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include <pcl/point_types.h>
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
)

0 comments on commit e8cab8b

Please sign in to comment.