Home > Back-end >  PCLS in custom type Point, there is a problem when using KDtree
PCLS in custom type Point, there is a problem when using KDtree

Time:11-30

For the convenience of data processing, custom me a little bit of type of point cloud, and then using kdtreeFlann neighbor search, but the following problems



The complete code is as follows, hope heavyweight directions, I was a novice c + +
 
#include
#include//PCD, speaking, reading and writing class header file,
#include//photo support some type of header files,
#include
#include
#include
#include

Using namespace STD.

Struct PointWithLabel {
PCL_ADD_POINT4D;
Int the label;
EIGEN_MAKE_ALIGNED_OPERATOR_NEW
} EIGEN_ALIGN16;
POINT_CLOUD_REGISTER_POINT_STRUCT (PointWithLabel,
(float, x, x)
(float, y, y)
(float, z, z)
(int, label, label)
)
Int main () {

//photo: : PointXYZ ins;
Photo: : PointCloud : : Ptr cloud (new photo: : PointCloud//photo: : PointCloud Cloud;
Char strfilepath [256]="label. The PCD";
If (1==PCLS: : IO: : loadPCDFile (strfilepath, * cloud))//open the point cloud file
{
Cout & lt; <"Error input!" return -1;
}
for (int i=0; i <10; I++) {
Cout & lt; <"" & lt; <"" & lt; <"" & lt; <"" & lt; }
Photo: : KdTreeFLANN & lt; PointWithLabel & gt; Kdtree;//create a KDtree

Kdtree. SetInputCloud (cloud);

PointWithLabel searchPoint;//create the target point, search point (neighbour)
SearchPoint. X=cloud - & gt; Points [100]. X;
SearchPoint. Y=cloud - & gt; Points [100]. Y;
SearchPoint. Z=cloud - & gt; Points [100]. Z;
SearchPoint. Label=cloud - & gt; Points [100]. The label;

//the number of query neighbor points
Int k=10;//the number of neighbor points
STD: : vector PointIdxNKNSearch (k);//store near point set index
STD: : vector PointNKNSquareDistance (k);//near the distance of the point set
If (kdtree. NearestKSearch (searchPoint, k, pointIdxNKNSearch pointNKNSquareDistance) & gt; 0)
{
For (size_t I=0; i STD: : cout & lt; <"" & lt; <"" & lt; <"" & lt; //& lt; <"" & lt; <"(squared short:" & lt; }
system("pause");
return 0;


}

CodePudding user response:

CodePudding user response:

# define PCL_NO_PRECOMPILE
In the file header and the macro
If your code is part of the library, which gets 2 by others, it took also make sense to try to use explicit instantiations for MyPointType types, for any classes that expose (from PCLS our outside PCLS).

CodePudding user response:

As if can't use their definition of point cloud types using kdtree
  • Related