如何对点云数据进行排序?
How to sort point cloud data?
我想试试点云的优先级队列data.I觉得需要插入指向array.But的指针好像没有way.How我能解决这个问题吗?谢谢~~
typedef struct tagNode
{
double point_X;
double point_Y;
double point_Z;
} Node;
struct classcomp
{
bool operator() (const Node& a, const Node& b) const
{
return a.point_X < b.point_X;
}
};
int main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>("boudary.pcd", *cloud);
//Node arr[] = *cloud;
//Node a[] = { {1.01, 55.456, 10.136}, {3.416, 33.231 , 15.121}, {2.564, 44.12491, 96.123}, {5.123, 11.123, 62.176}, {4.135, 22.456, 56.141} };
priority_queue<Node, vector<Node>, classcomp> priQue;
for(unsigned int i = 0; i < sizeof(a)/sizeof(a[0]); ++i)
{
priQue.push(a[i]);
}
while(!priQue.empty())
{
const Node& topNode = priQue.top();
cout << "x:" << topNode.point_X << ", " << "y:" << topNode.point_Y << ", z:" << topNode.point_Z << endl;
priQue.pop();
}
return 0;
}
为什么需要定义自己的点类型? PCL 已经有 pcl::PointXYZ
。 cloud->points
实际上是 pcl::PointXYZ
的 std::vector
。
所以你要找的是:
struct classcomp
{
bool operator() (const pcl::PointXYZ& a, const pcl::PointXYZ& b) const
{
return a.x < b.x;
}
};
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->points = { {1.01, 55.456, 10.136}, {3.416, 33.231 , 15.121}, {2.564, 44.12491, 96.123}, {5.123, 11.123, 62.176}, {4.135, 22.456, 56.141} };
std::priority_queue<pcl::PointXYZ, vector<pcl::PointXYZ>, classcomp> priQue;
for (unsigned int i = 0; i < cloud->size(); ++i)
priQue.push(cloud->points[i]);
// Or:
// for (const auto& p: cloud->points)
// priQue.push(p);
while (!priQue.empty())
{
const pcl::PointXYZ& point = priQue.top();
cout << "x:" << point.x << ", " << "y:" << point.y << ", z:" << point.z << endl;
priQue.pop();
}
这给了我们以下输出:
x:5.123, y:11.123, z:62.176
x:4.135, y:22.456, z:56.141
x:3.416, y:33.231, z:15.121
x:2.564, y:44.1249, z:96.123
x:1.01, y:55.456, z:10.136
我想试试点云的优先级队列data.I觉得需要插入指向array.But的指针好像没有way.How我能解决这个问题吗?谢谢~~
typedef struct tagNode
{
double point_X;
double point_Y;
double point_Z;
} Node;
struct classcomp
{
bool operator() (const Node& a, const Node& b) const
{
return a.point_X < b.point_X;
}
};
int main(int argc, char** argv)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::PCDReader reader;
reader.read<pcl::PointXYZ>("boudary.pcd", *cloud);
//Node arr[] = *cloud;
//Node a[] = { {1.01, 55.456, 10.136}, {3.416, 33.231 , 15.121}, {2.564, 44.12491, 96.123}, {5.123, 11.123, 62.176}, {4.135, 22.456, 56.141} };
priority_queue<Node, vector<Node>, classcomp> priQue;
for(unsigned int i = 0; i < sizeof(a)/sizeof(a[0]); ++i)
{
priQue.push(a[i]);
}
while(!priQue.empty())
{
const Node& topNode = priQue.top();
cout << "x:" << topNode.point_X << ", " << "y:" << topNode.point_Y << ", z:" << topNode.point_Z << endl;
priQue.pop();
}
return 0;
}
为什么需要定义自己的点类型? PCL 已经有 pcl::PointXYZ
。 cloud->points
实际上是 pcl::PointXYZ
的 std::vector
。
所以你要找的是:
struct classcomp
{
bool operator() (const pcl::PointXYZ& a, const pcl::PointXYZ& b) const
{
return a.x < b.x;
}
};
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
cloud->points = { {1.01, 55.456, 10.136}, {3.416, 33.231 , 15.121}, {2.564, 44.12491, 96.123}, {5.123, 11.123, 62.176}, {4.135, 22.456, 56.141} };
std::priority_queue<pcl::PointXYZ, vector<pcl::PointXYZ>, classcomp> priQue;
for (unsigned int i = 0; i < cloud->size(); ++i)
priQue.push(cloud->points[i]);
// Or:
// for (const auto& p: cloud->points)
// priQue.push(p);
while (!priQue.empty())
{
const pcl::PointXYZ& point = priQue.top();
cout << "x:" << point.x << ", " << "y:" << point.y << ", z:" << point.z << endl;
priQue.pop();
}
这给了我们以下输出:
x:5.123, y:11.123, z:62.176
x:4.135, y:22.456, z:56.141
x:3.416, y:33.231, z:15.121
x:2.564, y:44.1249, z:96.123
x:1.01, y:55.456, z:10.136