Created
September 30, 2018 03:27
-
-
Save YHaruoka/6a8bd64dbc25beb6d161ff99d80239c3 to your computer and use it in GitHub Desktop.
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/visualization/cloud_viewer.h> | |
#include <pcl/io/pcd_io.h> | |
#include <iostream> | |
using namespace std; | |
// ビューワー起動時の一回だけ呼ばれる | |
void viewerOneOff(pcl::visualization::PCLVisualizer& viewer) | |
{ | |
viewer.setBackgroundColor(0.2, 0.2, 0.2); | |
cout << "viewerOneOff" << std::endl; | |
} | |
// ビューワー起動中の毎フレーム実行される | |
void viewerPsycho(pcl::visualization::PCLVisualizer& viewer) | |
{ | |
cout << "viewerPsycho" << std::endl; | |
} | |
int main() | |
{ | |
pcl::PointCloud<pcl::PointXYZRGBA>::Ptr p_cloud(new pcl::PointCloud<pcl::PointXYZRGBA>); | |
// PointCloudの大きさを決定 | |
p_cloud->width = 10; | |
p_cloud->height = 10; | |
p_cloud->points.resize(p_cloud->width * p_cloud->height); | |
cout << "Size : " << p_cloud->width * p_cloud->height << endl; | |
// 直接、値を入力してPointCloudを作成 | |
for (int h = 0; h < p_cloud->height; h++) { | |
for (int w = 0; w < p_cloud->width; w++) { | |
pcl::PointXYZRGBA &point = p_cloud->points[w + h * p_cloud->width]; | |
point.x = w * 0.1; | |
point.y = h * 0.1; | |
point.z = 0.0; | |
point.r = 255; | |
point.g = 0; | |
point.b = 0; | |
point.a = 0; | |
} | |
} | |
// 作成したPointCloudをPCD形式で保存する | |
cout << "savePCDFileASCII" << endl; | |
pcl::io::savePCDFileASCII("p_cloud_ascii.pcd", *p_cloud); // テキスト形式で保存する | |
cout << "savePCDFileBinary" << endl; | |
pcl::io::savePCDFileBinary("p_cloud_binary.pcd", *p_cloud); // バイナリ形式で保存する | |
// ビューワーの作成 | |
pcl::visualization::CloudViewer viewer("PointCloudViewer"); | |
viewer.showCloud(p_cloud); | |
// ビューワー起動時の一回だけ呼ばれる関数をセット | |
viewer.runOnVisualizationThreadOnce(viewerOneOff); | |
// ビューワー起動中の毎フレーム実行される関数をセット | |
viewer.runOnVisualizationThread(viewerPsycho); | |
// ビューワー視聴用ループ | |
while (!viewer.wasStopped()) | |
{ | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment