Common
check if point is valid
#include <iostream>
#include <limits>
#include <pcl/point_types.h>
int main ()
{
pcl::PointXYZ p_valid; p_valid.x = 0; p_valid.y = 0; p_valid.z = 0;
std::cout << "Is p_valid valid? " << pcl::isFinite(p_valid) << std::endl;
pcl::PointXYZ p_invalid; p_invalid.x = std::numeric_limits<float>::quiet_NaN(); p_invalid.y = 0; p_invalid.z = 0;
std::cout << "Is p_invalid valid? " << pcl::isFinite(p_invalid) << std::endl;
return (0);
}
copy point cloud
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/common/io.h>
static void
sameType ();
static void
differenceType ();
int
main ()
{
sameType();
differenceType();
return 0;
}
void
sameType ()
{
typedef pcl::PointCloud<pcl::PointXYZ> CloudType;
CloudType::Ptr cloud (new CloudType);
CloudType::PointType p;
p.x = 1; p.y = 2; p.z = 3;
cloud->push_back(p);
std::cout << p.x << " " << p.y << " " << p.z << std::endl;
CloudType::Ptr cloud2(new CloudType);
copyPointCloud(*cloud, *cloud2);
CloudType::PointType p_retrieved = cloud2->points[0];
std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl;
}
void
differenceType ()
{
typedef pcl::PointCloud<pcl::PointXYZ> CloudType;
CloudType::Ptr cloud (new CloudType);
CloudType::PointType p;
p.x = 1; p.y = 2; p.z = 3;
cloud->push_back(p);
std::cout << p.x << " " << p.y << " " << p.z << std::endl;
typedef pcl::PointCloud<pcl::PointNormal> CloudType2;
CloudType2::Ptr cloud2(new CloudType2);
copyPointCloud(*cloud, *cloud2);
CloudType2::PointType p_retrieved = cloud2->points[0];
std::cout << p_retrieved.x << " " << p_retrieved.y << " " << p_retrieved.z << std::endl;
}
get max min coordinates
#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>
#include <pcl/common/common.h>
int main (int, char**)
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud;
cloud = pcl::PointCloud<pcl::PointXYZ>::Ptr (new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile<pcl::PointXYZ> ("your_pcd_file.pcd", *cloud);
pcl::PointXYZ minPt, maxPt;
pcl::getMinMax3D (*cloud, minPt, maxPt);
std::cout << "Max x: " << maxPt.x << std::endl;
std::cout << "Max y: " << maxPt.y << std::endl;
std::cout << "Max z: " << maxPt.z << std::endl;
std::cout << "Min x: " << minPt.x << std::endl;
std::cout << "Min y: " << minPt.y << std::endl;
std::cout << "Min z: " << minPt.z << std::endl;
return (0);
}
organized point cloud
#include <iostream>
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
int
main ()
{
typedef pcl::PointXYZ PointType;
typedef pcl::PointCloud<PointType> CloudType;
CloudType::Ptr cloud (new CloudType);
cloud->height = 10;
cloud->width = 10;
cloud->is_dense = true;
cloud->resize(cloud->height * cloud->width);
std::cout << (*cloud)(0,0) << std::endl;
PointType p; p.x = 1; p.y = 2; p.z = 3;
(*cloud)(0,0) = p;
std::cout << (*cloud)(0,0) << std::endl;
return (0);
}
scoped time
#include <iostream>
#include <pcl/common/time.h>
int main ()
{
pcl::ScopeTime scope_time ("Test loop");
{
float total = 0.0f;
for (size_t i = 0; i < 1e4; ++i)
{
total += static_cast<float> (i);
}
}
std::cout << scope_time.getTime() << "ms. Done." << std::endl;
return (0);
}
time elapse measurement
#include <pcl/console/time.h>
pcl::console::TicToc tt;
std::cerr << "Start\n", tt.tic ();
std::cerr << "Done:"<< tt.toc ()<<"\n";