Skip to content

Commit

Permalink
add a point type
Browse files Browse the repository at this point in the history
  • Loading branch information
171930433 committed Mar 9, 2024
1 parent 7c40c51 commit 96d3135
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 138 deletions.
57 changes: 53 additions & 4 deletions src/struct_pb/protoc-plugin/example/tutorial.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,52 @@

// #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);
}

}

// 声明 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 @@ -13,17 +59,20 @@ int main() {
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;


// 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;

// std::cout << p1 << std::endl;
pcl::PointXYZIT p2 {1,2};
std::cout << p2 << std::endl;


std::cout << "Done!!!" << std::endl;
Expand Down
157 changes: 55 additions & 102 deletions src/struct_pb/protoc-plugin/proto_to_struct.pb.cc

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

92 changes: 60 additions & 32 deletions src/struct_pb/protoc-plugin/proto_to_struct.pb.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 96d3135

Please sign in to comment.