1212#include < pcl/io/ply_io.h>
1313#include < pcl/io/vtk_lib_io.h>
1414
15+ #include < fstream>
16+
1517#include " inteface_parser.hpp"
1618
1719namespace CloudParserLibrary {
@@ -29,13 +31,6 @@ class ParserPCD : public InterfaceParser {
2931class ParserPLY : public InterfaceParser {
3032 public:
3133 std::string parser_name = " ParserPLY" ;
32- bool cloud_is_good (pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cloud) {
33- if ((cloud->points .size () > 0 ) or
34- (cloud->points [0 ].x > 0 && cloud->points [0 ].y > 0 && cloud->points [0 ].z > 0 )) {
35- return true ;
36- }
37- return false ;
38- }
3934 void load_cloudfile (std::string filename, pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cloud) {
4035 pcl::io::loadPLYFile (filename, *cloud);
4136 if (cloud_is_good (cloud)) {
@@ -62,5 +57,44 @@ class ParserPLY : public InterfaceParser {
6257 std::exit (-1 );
6358 }
6459};
60+
61+ class ParserTXT : public InterfaceParser {
62+ public:
63+ std::string parser_name = " ParserTXT" ;
64+ void load_cloudfile (std::string filename, pcl::PointCloud<pcl::PointXYZRGB>::Ptr& cloud) {
65+ std::ifstream file (filename, std::ifstream::in);
66+ if (!file.is_open ()) {
67+ pcl::console::print_error (" \n Error: Could not find %s\n " , filename);
68+ std::exit (-1 );
69+ }
70+
71+ double x_, y_, z_, r, g, b;
72+
73+ while (file >> x_ >> y_ >> z_ >> r >> g >> b) {
74+ pcl::PointXYZRGB pt;
75+ pt.x = x_;
76+ pt.y = y_;
77+ pt.z = z_;
78+
79+ uint8_t r_, g_, b_;
80+ r_ = uint8_t (r);
81+ g_ = uint8_t (g);
82+ b_ = uint8_t (b);
83+
84+ uint32_t rgb_ = ((uint32_t )r_ << 16 | (uint32_t )g_ << 8 | (uint32_t )b_);
85+ pt.rgb = *reinterpret_cast <float *>(&rgb_);
86+
87+ cloud->points .push_back (pt);
88+ }
89+
90+ file.close ();
91+ if (cloud_is_good (cloud)) {
92+ return ;
93+ }
94+
95+ pcl::console::print_error (" \n Error empty cloud.\n " );
96+ std::exit (-1 );
97+ }
98+ };
6599} // namespace CloudParserLibrary
66100#endif
0 commit comments