Last active
May 2, 2017 22:48
-
-
Save takahub1/d69abb37a6964a5ce09ae8d0796e7c21 to your computer and use it in GitHub Desktop.
view pcd file
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
// install pcl https://github.com/PointCloudLibrary/pcl | |
// tutorial http://pointclouds.org/documentation/tutorials/cloud_viewer.php#cloud-viewer | |
#include <pcl/visualization/cloud_viewer.h> | |
#include <pcl/io/io.h> | |
#include <pcl/io/pcd_io.h> | |
#include <iostream> | |
// #include <cmath> | |
int user_data; | |
void addSphereContinuity(pcl::visualization::PCLVisualizer& viewer, | |
float sx,float sy,float ex,float ey){ | |
pcl::PointXYZ o; | |
static char s_cnt=33; | |
float xyLen=std::pow((ex-sx),2.0)+std::pow((ey-sy),2.0); | |
xyLen = std::sqrt(xyLen); | |
float split = 0.3; | |
float split_num = xyLen/split; | |
std::cout<<xyLen<<std::endl; | |
float diffx = (ex-sx)/split_num; | |
float diffy = (ey-sy)/split_num; | |
for(int cnt=0;cnt<split_num;cnt++){ | |
if(s_cnt++<125) std::cout<<s_cnt<<std::endl; | |
else{ | |
std::cout<<"up to s_cnt"<<std::endl; | |
exit(-1); | |
} | |
sx += diffx; | |
sy += diffy; | |
std::cout<<sx<<":"<<sy<<std::endl; | |
o.x = sx; | |
o.y = sy; | |
o.z = 0; | |
viewer.addSphere (o, 0.1, &s_cnt, 0); | |
} | |
} | |
void viewerOneOff (pcl::visualization::PCLVisualizer& viewer) | |
{ | |
viewer.setBackgroundColor (1.0, 0.5, 1.0); | |
// addSphereContinuity(viewer,-1.9,5,-0.9,1.6); | |
// addSphereContinuity(viewer,-0.9,1.6,-1.3,1.3); | |
// addSphereContinuity(viewer,-1.3,1.3,-0.5,-2.0); | |
std::cout << "i only run once" << std::endl; | |
} | |
void viewerPsycho (pcl::visualization::PCLVisualizer& viewer) | |
{ | |
static unsigned count = 0; | |
std::stringstream ss; | |
ss << "Once per viewer loop: " << count++; | |
viewer.removeShape ("text", 0); | |
viewer.addText (ss.str(), 200, 300, "text", 0); | |
//FIXME: possible race condition here: | |
user_data++; | |
} | |
int main (){ | |
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGBA>); | |
pcl::io::loadPCDFile ("myhouse.pcd", *cloud); | |
pcl::visualization::CloudViewer viewer("Cloud Viewer"); | |
//blocks until the cloud is actually rendered | |
viewer.showCloud(cloud); | |
//use the following functions to get access to the underlying more advanced/powerful | |
//PCLVisualizer | |
//This will only get called once | |
viewer.runOnVisualizationThreadOnce (viewerOneOff); | |
//This will get called once per visualization iteration | |
viewer.runOnVisualizationThread (viewerPsycho); | |
while (!viewer.wasStopped ()) | |
{ | |
//you can also do cool processing here | |
//FIXME: Note that this is running in a separate thread from viewerPsycho | |
//and you should guard against race conditions yourself... | |
user_data++; | |
} | |
return 0; | |
} |
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(cloud_viewer) | |
find_package(PCL 1.2 REQUIRED) | |
include_directories(${PCL_INCLUDE_DIRS}) | |
link_directories(${PCL_LIBRARY_DIRS}) | |
add_definitions(${PCL_DEFINITIONS}) | |
add_executable (cloud_viewer cloud_viewer.cpp) | |
target_link_libraries (cloud_viewer ${PCL_LIBRARIES}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment