Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /******************
- Normal Writer
- Input file:
- Output file:
- ********************/
- #include <iostream>
- #include <string>
- #include <fstream>
- #include <iomanip>
- #include <pcl/io/pcd_io.h>
- #include <pcl/point_types.h>
- #include <pcl/features/normal_3d.h>
- using namespace std;
- string getFileName();
- int main(int argc, char** argv)
- {
- pcl::PointCloud<pcl::PointXYZRGB>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB>);
- //PCDÉtÉ@ÉCÉãÇì«Ç›çûÇfi
- cout << "Load PCD File Format" << endl;
- if(pcl::io::loadPCDFile<pcl::PointXYZRGB> (getFileName().c_str(), *cloud) == -1)
- {
- PCL_ERROR("Coudn't read file\n");
- return(-1);
- }
- //ñ@ê¸ÇÃåvéZ
- //cout << "ñ@ê¸ÇåvéZǵNjÇ∑" << endl;
- pcl::NormalEstimation <pcl::PointXYZRGB, pcl::Normal> ne;
- ne.setInputCloud (cloud);
- pcl::search::KdTree <pcl::PointXYZRGB>::Ptr tree (new pcl::search::KdTree <pcl::PointXYZRGB> ());
- ne.setSearchMethod (tree);
- ne.setRadiusSearch (0.03);
- //ñ@ê¸ÇÃåvéZåãâ éÊìæ
- pcl::PointCloud <pcl::Normal>::Ptr normals (new pcl::PointCloud <pcl::Normal>);
- ne.compute (*normals);
- /*
- ñ@ê¸ÇÃåvéZåãâ ÇÃèëÇ´èoǵ
- ÉtÉ@ÉCÉãÉtÉHÅ[É}ÉbÉgÇÕ
- x y z r g b normal_x normal_y normal_z
- */
- cout << "Output filename" << endl;
- ofstream ofs;
- ofs.open(getFileName().c_str());
- for(size_t i=0; i < cloud->points.size() ; i++)
- {
- ofs << setprecision(10)
- << fixed << cloud->points[i].x << " "
- << fixed << cloud->points[i].y << " "
- << fixed << cloud->points[i].z << " "
- << (int)cloud->points[i].r << " "
- << (int)cloud->points[i].g << " "
- << (int)cloud->points[i].b << " "
- << fixed << normals->points[i].normal_x << " "
- << fixed << normals->points[i].normal_y << " "
- << fixed << normals->points[i].normal_z << endl;
- }
- ofs.close();
- return(0);
- }
- string getFileName()
- {
- fflush(stdin);
- std::cout << "Input file name:";
- std::string file_name;
- std::getline( std::cin, file_name );
- return file_name;
- }
Advertisement
Add Comment
Please, Sign In to add comment