Last active
August 10, 2022 02:17
-
-
Save UnaNancyOwen/e7f52cd4b43458874a9ecb55d19fedc0 to your computer and use it in GitHub Desktop.
Start Project for Point Cloud Library
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 3.6 ) | |
# Language | |
enable_language( CXX ) | |
# Compiler Settings | |
set( CMAKE_CXX_STANDARD 17 ) | |
set( CMAKE_CXX_STANDARD_REQUIRED ON ) | |
set( CMAKE_CXX_EXTENSIONS OFF ) | |
# Project | |
project( point_cloud LANGUAGES CXX ) | |
add_executable( point_cloud main.cpp ) | |
# (Option) Start-Up Project for Visual Studio | |
set_property( DIRECTORY PROPERTY VS_STARTUP_PROJECT "point_cloud" ) | |
# Find Package | |
find_package( PCL 1.12 REQUIRED ) | |
# Set Package to Project | |
if( PCL_FOUND ) | |
include_directories( ${PCL_INCLUDE_DIRS} ) | |
link_directories( ${PCL_LIBRARY_DIRS} ) | |
add_definitions( ${PCL_DEFINITIONS} ) | |
target_link_libraries( point_cloud ${PCL_LIBRARIES} ) | |
endif() |
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 <pcl/io/ply_io.h> | |
#include <pcl/visualization/pcl_visualizer.h> | |
typedef pcl::PointXYZRGBA PointType; | |
int main( int argc, char* argv[] ) | |
{ | |
// Load Point Cloud | |
pcl::PointCloud<PointType>::Ptr cloud = pcl::make_shared<pcl::PointCloud<PointType>>(); | |
const std::string file_name = "../cloud.ply"; | |
const int32_t result = pcl::io::loadPLYFile( file_name, *cloud ); | |
if( result == -1 ){ | |
return -1; | |
} | |
// Create Visualizer | |
pcl::visualization::PCLVisualizer::Ptr viewer = pcl::make_shared<pcl::visualization::PCLVisualizer>( "Point Cloud Viewer" ); | |
// Create Color Handler | |
pcl::visualization::PointCloudColorHandler<PointType>::Ptr handler; | |
const std::type_info& type = typeid( PointType ); | |
if( type == typeid( pcl::PointXYZ ) ){ | |
std::vector<double> color = { 255.0, 255.0, 255.0 }; | |
handler = pcl::make_shared<pcl::visualization::PointCloudColorHandlerCustom<PointType>>( color[0], color[1], color[2] ); | |
} | |
else if( type == typeid( pcl::PointXYZI ) ){ | |
handler = pcl::make_shared<pcl::visualization::PointCloudColorHandlerGenericField<PointType>>( "intensity" ); | |
} | |
else if( type == typeid( pcl::PointXYZRGBA ) ){ | |
handler = pcl::make_shared<pcl::visualization::PointCloudColorHandlerRGBField<PointType>>(); | |
} | |
// Show Point Cloud | |
while( !viewer->wasStopped() ){ | |
if( cloud ){ | |
handler->setInputCloud( cloud ); | |
if( !viewer->updatePointCloud( cloud, *handler, "cloud" ) ){ | |
viewer->addPointCloud( cloud, *handler, "cloud" ); | |
} | |
} | |
viewer->spinOnce(); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment