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;

  // If any component is NaN, the point is not finite.
  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

// STL
#include <iostream>

// PCL
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>
#include <pcl/common/io.h>

static void
sameType ();

static void
differenceType ();

// We show this function as an example of what you cannot do.
// static void
// badConversion ();

int
main ()
{
  sameType();
  differenceType();
  // badConversion();
  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;
}

/*
// Of course you can't do this, because pcl::Normal does not have x,y,z members:
error: ‘pcl::PointCloud<pcl::Normal>::PointType’ has no member named ‘x’

void
badConversion ()
{
  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::Normal> 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

// STL
#include <iostream>

// PCL
#include <pcl/point_cloud.h>
#include <pcl/point_types.h>

int 
main ()
{
  // Setup the cloud
  typedef pcl::PointXYZ PointType;
  typedef pcl::PointCloud<PointType> CloudType;
  CloudType::Ptr cloud (new CloudType);

  // Make the cloud a 10x10 grid
  cloud->height = 10;
  cloud->width = 10;
  cloud->is_dense = true;
  cloud->resize(cloud->height * cloud->width);

  // Output the (0,0) point
  std::cout << (*cloud)(0,0) << std::endl;

  // Set the (0,0) point
  PointType p; p.x = 1; p.y = 2; p.z = 3;
  (*cloud)(0,0) = p;

  // Confirm that the point was set
  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 ();
//some calculation....
std::cerr << "Done:"<< tt.toc ()<<"\n";

results matching ""

    No results matching ""