@@ -17,7 +17,7 @@ void calculateCentroid(vector<htr::Point3D>& points){
1717}
1818
1919void readCloudFromFile (int argc, char ** argv, std::vector<htr::Point3D>& points,
20- pcl::PointCloud<pcl::PointXYZ >::Ptr& cloud){
20+ pcl::PointCloud<pcl::PointXYZRGB >::Ptr& cloud){
2121
2222 pcl::PolygonMesh cl;
2323 std::vector<int > filenames;
@@ -92,50 +92,112 @@ void readCloudFromFile(int argc, char** argv, std::vector<htr::Point3D>& points,
9292 pcl::console::print_value (" %d" , cloud->size ());
9393 pcl::console::print_info (" points]\n " );
9494
95- }else if (file_is_txt or file_is_xyz ){
95+ }else if (file_is_txt){
9696 std::ifstream file (argv[filenames[0 ]]);
9797 if (!file.is_open ()){
9898 std::cout << " Error: Could not find " << argv[filenames[0 ]] << std::endl;
9999 return std::exit (-1 );
100100 }
101+
102+ std::cout << " file opened." << std::endl;
101103 double x_,y_,z_;
102- while (file >> x_ >> y_ >> z_){
103- pcl::PointXYZ pt;
104+ unsigned int r, g, b;
105+
106+ while (file >> x_ >> y_ >> z_ >> r >> g >> b){
107+ pcl::PointXYZRGB pt;
104108 pt.x = x_;
105109 pt.y = y_;
106- pt.z = z_;
110+ pt.z = z_;
111+
112+ uint8_t r_, g_, b_;
113+ r_ = uint8_t (r);
114+ g_ = uint8_t (g);
115+ b_ = uint8_t (b);
116+
117+ uint32_t rgb_ = ((uint32_t )r_ << 16 | (uint32_t )g_ << 8 | (uint32_t )b_);
118+ pt.rgb = *reinterpret_cast <float *>(&rgb_);
119+
107120 cloud->points .push_back (pt);
121+ // std::cout << "pointXYZRGB:" << pt << std::endl;
122+ }
123+
124+ pcl::console::print_info (" \n Found txt file.\n " );
125+ pcl::console::print_info (" [done, " );
126+ pcl::console::print_value (" %g" , tt.toc ());
127+ pcl::console::print_info (" ms : " );
128+ pcl::console::print_value (" %d" , cloud->points .size ());
129+ pcl::console::print_info (" points]\n " );
130+
131+ }else if (file_is_xyz){
132+
133+ std::ifstream file (argv[filenames[0 ]]);
134+ if (!file.is_open ()){
135+ std::cout << " Error: Could not find " << argv[filenames[0 ]] << std::endl;
136+ return std::exit (-1 );
108137 }
138+
139+ std::cout << " file opened." << std::endl;
140+ double x_,y_,z_;
109141
110- pcl::console::print_info (" \n Found txt file.\n " );
142+ while (file >> x_ >> y_ >> z_){
143+
144+ pcl::PointXYZRGB pt;
145+ pt.x = x_;
146+ pt.y = y_;
147+ pt.z = z_;
148+
149+ cloud->points .push_back (pt);
150+ // std::cout << "pointXYZRGB:" << pt << std::endl;
151+ }
152+
153+ pcl::console::print_info (" \n Found xyz file.\n " );
111154 pcl::console::print_info (" [done, " );
112155 pcl::console::print_value (" %g" , tt.toc ());
113156 pcl::console::print_info (" ms : " );
114- pcl::console::print_value (" %d" , cloud->size ());
157+ pcl::console::print_value (" %d" , cloud->points . size ());
115158 pcl::console::print_info (" points]\n " );
116159 }
117160
161+
118162 cloud->width = (int ) cloud->points .size ();
119163 cloud->height = 1 ;
120164 cloud->is_dense = true ;
121165
122166 for (int i =0 ; i<cloud->points .size ();i++){
123167 htr::Point3D aux;
124168 aux.x = cloud->points [i].x ;
125- aux.y = cloud->points [i].y ;;
169+ aux.y = cloud->points [i].y ;
126170 aux.z = cloud->points [i].z ;
171+
172+ uint32_t rgb_ = *reinterpret_cast <int *>(&cloud->points [i].rgb );
173+ uint8_t r_, g_, b_;
174+
175+ r_ = (rgb_ >> 16 ) & 0x0000ff ;
176+ g_ = (rgb_ >> 8 ) & 0x0000ff ;
177+ b_ = (rgb_) & 0x0000ff ;
178+
179+ unsigned int r, g, b;
180+ r = *((uint8_t *) &r_);
181+ g = *((uint8_t *) &g_);
182+ b = *((uint8_t *) &b_);
183+
184+ aux.r = r;
185+ aux.g = g;
186+ aux.b = b;
187+
127188 points.push_back (aux);
189+
128190 }
129191
130- calculateCentroid (points);
192+ // calculateCentroid(points);
131193}
132194
133195void init (int argc, char ** argv,bool show){
134196
135197 std::vector<htr::Point3D> groupA;
136198 dbScanSpace::dbscan dbscan;
137199
138- pcl::PointCloud<pcl::PointXYZ >::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ >());
200+ pcl::PointCloud<pcl::PointXYZRGB >::Ptr cloud (new pcl::PointCloud<pcl::PointXYZRGB >());
139201 readCloudFromFile (argc, argv, groupA,cloud);
140202
141203 // ----------------------------------------------------------------
@@ -160,8 +222,8 @@ void init(int argc, char** argv,bool show){
160222 std::chrono::time_point<std::chrono::system_clock> start, end;
161223 start = std::chrono::system_clock::now ();
162224
163- dbscan.generateClusters ();
164- // dbscan.generateClusters_fast();
225+ // dbscan.generateClusters();
226+ dbscan.generateClusters_fast ();
165227 // dbscan.generateClusters_one_step();
166228
167229 ofstream fout;
@@ -174,18 +236,61 @@ void init(int argc, char** argv,bool show){
174236 std::string str1 = output_dir;
175237 str1 += " /cloud_cluster_" ;
176238 str1 += std::to_string (cont);
177- str1 += " .xyz " ;
239+ str1 += " .txt " ;
178240
179241 fout.open (str1.c_str ());
180242
181243 for (auto & point:cluster.clusterPoints ){
182-
183- fout << point.x << " " << point.y << " " << point.z << std::endl;
244+
245+ // fout << point.x << " " << point.y << " "<< point.z << " " << point.r << " " << point.g << " " << point.b << std::endl;
246+
247+ uint32_t rgb_ = *reinterpret_cast <int *>(&point.rgb );
248+ uint8_t r_, g_, b_;
249+
250+ r_ = (rgb_ >> 16 ) & 0x0000ff ;
251+ g_ = (rgb_ >> 8 ) & 0x0000ff ;
252+ b_ = (rgb_) & 0x0000ff ;
253+
254+ unsigned int r, g, b;
255+ r = *((uint8_t *) &r_);
256+ g = *((uint8_t *) &g_);
257+ b = *((uint8_t *) &b_);
258+
259+ fout << point.x << " " << point.y << " " << point.z << " " << r << " " << g << " " << b << std::endl;
260+ /*
261+
262+ for(size_t i=0;i<cloud->points.size();i++){
263+
264+ pcl::PointXYZRGB pt = cloud->points.at(i);
265+
266+ if(pt.x == point.x and pt.y == point.y and pt.z == point.z){
267+
268+ uint32_t rgb_ = *reinterpret_cast<int*>(&pt.rgb);
269+ uint8_t r_, g_, b_;
270+
271+ r_ = (rgb_ >> 16) & 0x0000ff;
272+ g_ = (rgb_ >> 8) & 0x0000ff;
273+ b_ = (rgb_) & 0x0000ff;
274+
275+ unsigned int r, g, b;
276+ r = *((uint8_t *) &r_);
277+ g = *((uint8_t *) &g_);
278+ b = *((uint8_t *) &b_);
279+
280+ fout << point.x << " " << point.y << " "<< point.z << " " << r << " " << g << " " << b << std::endl;
281+
282+ }else{
283+ continue;
284+ }
285+
184286 }
287+ */
288+
289+ }
185290
186291 fout.close ();
187292 cont +=1 ;
188- }
293+ }
189294
190295 ofstream fout2;
191296 std::string str2 = output_dir;
0 commit comments