您的位置:首页 > 理论基础 > 数据结构算法

可以自己定义数据结构,然后用PCL里面的函数运行了!

2017-08-18 17:38 651 查看
参考:

How to add a new PointT type

To add a new point type, you first have to define it. For example:

1
2
3
4


struct MyPointType
{
float test;
};


Then, you need to make sure your code includes the template header implementation of the specific class/algorithm in PCL that you want your new point type MyPointType to
work with. For example, say you want to use pcl::PassThrough. All you would have to do is:

#define PCL_NO_PRECOMPILE
#include <pcl/filters/passthrough.h>
#include <pcl/filters/impl/passthrough.hpp>

// the rest of the code goes here


If your code is part of the library, which gets used by others, it might also make sense to try to use explicit instantiations for your 
4000
MyPointType types,
for any classes that you expose (from PCL our outside PCL).

Note

Starting with PCL-1.7 you need to define PCL_NO_PRECOMPILE before you include any PCL headers to include the templated algorithms as well.

Example

The following code snippet example creates a new point type that contains XYZ data (SSE padded), together with a test float.

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


#define PCL_NO_PRECOMPILE
#include <pcl/point_types.h>
#include <pcl/point_cloud.h>
#include <pcl/io/pcd_io.h>

struct MyPointType
{
PCL_ADD_POINT4D;                  // preferred way of adding a XYZ+padding
float test;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW   // make sure our new allocators are aligned
} EIGEN_ALIGN16;                    // enforce SSE padding for correct memory alignment

POINT_CLOUD_REGISTER_POINT_STRUCT (MyPointType,           // here we assume a XYZ + "test" (as fields)
(float, x, x)
(float, y, y)
(float, z, z)
(float, test, test)
)

int
main (int argc, char** argv)
{
pcl::PointCloud<MyPointType> cloud;
cloud.points.resize (2);
cloud.width = 2;
cloud.height = 1;

cloud.points[0].test = 1;
cloud.points[1].test = 2;
cloud.points[0].x = cloud.points[0].y = cloud.points[0].z = 0;
cloud.points[1].x = cloud.points[1].y = cloud.points[1].z = 3;

pcl::io::savePCDFile ("test.pcd", cloud);
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐