1616#include < string>
1717
1818void printUsage (const char * progName){
19- std::cout << " \n Usage: " << progName << " <file.pcd> or <file.ply>" << std::endl <<
19+ std::cout << " \n Use: " << progName << " <file>" << std::endl <<
20+ " support: .pcd .ply .txt .xyz" << std::endl <<
2021 " [q] to exit" << std::endl;
2122}
2223
@@ -102,7 +103,8 @@ int main(int argc, char **argv){
102103 pcl::console::print_info (" ms : " );
103104 pcl::console::print_value (" %d" , cloud->points .size ());
104105 pcl::console::print_info (" points]\n " );
105- }else if (file_is_txt or file_is_xyz){
106+
107+ }else if (file_is_txt){
106108 std::ifstream file (argv[filenames[0 ]]);
107109 if (!file.is_open ()){
108110 std::cout << " Error: Could not find " << argv[filenames[0 ]] << std::endl;
@@ -111,13 +113,21 @@ int main(int argc, char **argv){
111113
112114 std::cout << " file opened." << std::endl;
113115 double x_,y_,z_;
114- uint8_t r_,g_,b_ ;
116+ unsigned int r, g, b ;
115117
116- while (file >> x_ >> y_ >> z_ /* >> r_ >> g_ >> b_ */ ){
118+ while (file >> x_ >> y_ >> z_ >> r >> g >> b ){
117119 pcl::PointXYZRGB pt;
118120 pt.x = x_;
119121 pt.y = y_;
120- pt.z = z_;
122+ pt.z = z_;
123+
124+ uint8_t r_, g_, b_;
125+ r_ = uint8_t (r);
126+ g_ = uint8_t (g);
127+ b_ = uint8_t (b);
128+
129+ uint32_t rgb_ = ((uint32_t )r_ << 16 | (uint32_t )g_ << 8 | (uint32_t )b_);
130+ pt.rgb = *reinterpret_cast <float *>(&rgb_);
121131
122132 cloud->points .push_back (pt);
123133 // std::cout << "pointXYZRGB:" << pt << std::endl;
@@ -129,7 +139,36 @@ int main(int argc, char **argv){
129139 pcl::console::print_info (" ms : " );
130140 pcl::console::print_value (" %d" , cloud->points .size ());
131141 pcl::console::print_info (" points]\n " );
132- }
142+
143+ }else if (file_is_xyz){
144+
145+ std::ifstream file (argv[filenames[0 ]]);
146+ if (!file.is_open ()){
147+ std::cout << " Error: Could not find " << argv[filenames[0 ]] << std::endl;
148+ return -1 ;
149+ }
150+
151+ std::cout << " file opened." << std::endl;
152+ double x_,y_,z_;
153+
154+ while (file >> x_ >> y_ >> z_){
155+
156+ pcl::PointXYZRGB pt;
157+ pt.x = x_;
158+ pt.y = y_;
159+ pt.z = z_;
160+
161+ cloud->points .push_back (pt);
162+ // std::cout << "pointXYZRGB:" << pt << std::endl;
163+ }
164+
165+ pcl::console::print_info (" \n Found xyz file.\n " );
166+ pcl::console::print_info (" [done, " );
167+ pcl::console::print_value (" %g" , tt.toc ());
168+ pcl::console::print_info (" ms : " );
169+ pcl::console::print_value (" %d" , cloud->points .size ());
170+ pcl::console::print_info (" points]\n " );
171+ }
133172
134173 cloud->width = (int ) cloud->points .size ();
135174 cloud->height = 1 ;
@@ -159,7 +198,6 @@ int main(int argc, char **argv){
159198 viewer->addPointCloud (cloud," POINTCLOUD" );
160199 }
161200
162- // viewer->addPointCloud(cloud,"POINTCLOUD");
163201 viewer->initCameraParameters ();
164202 viewer->resetCamera ();
165203
0 commit comments