Last active
June 11, 2018 12:10
-
-
Save frozar/172b2fa06e2417aa5343cab61b3aafdb to your computer and use it in GitHub Desktop.
Point cloud visualisation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cmake_minimum_required(VERSION 2.8 FATAL_ERROR) | |
project(jeyaram) | |
find_package(PCL 1.2 REQUIRED) | |
include_directories(${PCL_INCLUDE_DIRS}) | |
link_directories(${PCL_LIBRARY_DIRS}) | |
add_definitions(${PCL_DEFINITIONS}) | |
add_executable (main main.cpp) | |
target_link_libraries (main ${PCL_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <pcl/io/auto_io.h> | |
#include <pcl/visualization/pcl_visualizer.h> | |
#include <pcl/common/centroid.h> | |
int | |
main (int argc, char ** argv) | |
{ | |
if (argc != 2) | |
{ | |
std::cout << "Usage: " << argv[0] << " <input_point_cloud_file>" << std::endl; | |
exit (0); | |
} | |
// Read the input point cloud | |
char * point_cloud_path = argv[1]; | |
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>); | |
if (pcl::io::load (point_cloud_path, *cloud)) | |
{ | |
std::cout << "Error: Cannot read input file" << std::endl; | |
return 0; | |
} | |
std::cout << "Nb points read: " << cloud->points.size () << std::endl; | |
// Compute the centroid of the point cloud | |
Eigen::Vector4d centroid; | |
pcl::compute3DCentroid<pcl::PointXYZ> (*cloud, centroid); | |
std::cout << "centroid: " << centroid[0] << ", " | |
<< centroid[1] << ", " << centroid[2] << std::endl; | |
// Center the point cloud around the origin: easy the handle through the visualiser | |
pcl::demeanPointCloud <pcl::PointXYZ, double> (*cloud, centroid, *cloud); | |
// Setup the visualisation | |
boost::shared_ptr<pcl::visualization::PCLVisualizer> viewer (new pcl::visualization::PCLVisualizer ("3D Viewer")); | |
viewer->setBackgroundColor (0, 0, 0); | |
viewer->addPointCloud<pcl::PointXYZ> (cloud); | |
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_POINT_SIZE, | |
1); | |
viewer->setPointCloudRenderingProperties (pcl::visualization::PCL_VISUALIZER_COLOR, | |
1, 1, 1); | |
viewer->addCoordinateSystem (1.0); | |
viewer->initCameraParameters (); | |
// Interactive visualisation loop | |
while (!viewer->wasStopped ()) | |
{ | |
viewer->spinOnce (100); | |
boost::this_thread::sleep (boost::posix_time::microseconds (100000)); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment