Advertisement
SUGIYAMA

normal writer ver2.00

Sep 25th, 2013
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.03 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <fstream>
  4. #include <iomanip>
  5.  
  6. #include <pcl/io/pcd_io.h>
  7. #include <pcl/point_types.h>
  8. #include <pcl/features/normal_3d.h>
  9.  
  10. using namespace std;
  11.  
  12. //関数のプロトタイプ宣言
  13. string getFileName();
  14.  
  15. int main(int argc, char** argv)
  16. {
  17.     float rad;
  18.         rad=atof(argv[3]);
  19.     pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
  20.  
  21.     //PCDファイルを読み込む (Input PCD file:XYZRGB)
  22.     cout << "PCDファイルを読み込みます" << endl;
  23.  
  24.     if(pcl::io::loadPCDFile<pcl::PointXYZRGB> (argv[1], *cloud) == -1)
  25.     {
  26.         PCL_ERROR("Coudn't read file\n");
  27.         return(-1);
  28.     }
  29.  
  30.     //法線の計算
  31.     cout << "法線を計算します" << endl;
  32.  
  33.     pcl::NormalEstimation <pcl::PointXYZRGB, pcl::Normal> ne;
  34.     ne.setInputCloud (cloud);
  35.  
  36.     pcl::search::KdTree <pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree <pcl::PointXYZRGB> ());
  37.     ne.setSearchMethod (tree);
  38.     ne.setRadiusSearch (rad);
  39.  
  40.     //法線の計算結果取得
  41.     pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
  42.         ne.compute (*normals);
  43.  
  44.     /*
  45.         法線の計算結果の書き出し
  46.         ファイルフォーマットは
  47.         x y z r g b normal_x normal_y normal_z
  48.     */
  49.    
  50.     cout << "計算結果を書き出します" << endl;
  51.     ofstream ofs;
  52.     ofs.open(argv[2]);
  53.  
  54.     for(size_t i=0; i < cloud->points.size() ; i++)
  55.     {
  56.         ofs << setprecision(10)
  57.             << fixed << cloud->points[i].x << " "
  58.             << fixed << cloud->points[i].y << " "
  59.             << fixed << cloud->points[i].z << " "
  60.             << (int)cloud->points[i].r << " "
  61.             << (int)cloud->points[i].g << " "
  62.             << (int)cloud->points[i].b << " "
  63.             << fixed << normals->points[i].normal_x << " "
  64.             << fixed << normals->points[i].normal_y << " "
  65.             << fixed << normals->points[i].normal_z << endl;
  66.     }
  67.  
  68.     ofs.close();
  69.  
  70.     return(0);
  71. }
  72.  
  73. /*ファイル名の取得*/
  74. string getFileName(){
  75.     fflush(stdin);
  76.     std::cout << "Input file name:";
  77.     std::string file_name;
  78.     std::getline( std::cin, file_name );
  79.     return file_name;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement