35 #include <boost/algorithm/string.hpp>
52 : m_numFiles(1), m_currentReadFile(0), m_openNextFile(false)
58 : m_numFiles(1), m_currentReadFile(0), m_openNextFile(false)
76 for (
size_t currentFile = 0; currentFile < filePaths.size(); currentFile++)
79 std::string filePath = filePaths[currentFile];
82 bool gotcolor =
false;
83 bool gotnormal =
false;
84 bool readHeader =
false;
86 if (boost::algorithm::contains(filePath,
".ply"))
89 currentAttr.
m_ply =
true;
93 currentAttr.
m_ply =
false;
96 std::ifstream ifs(filePath);
98 if (currentAttr.
m_ply)
103 std::getline(ifs, line);
104 if (boost::algorithm::contains(line,
"element vertex") ||
105 boost::algorithm::contains(line,
"element point"))
107 std::stringstream ss(line);
113 else if (boost::algorithm::contains(line,
"property float x") ||
114 boost::algorithm::contains(line,
"property float y") ||
115 boost::algorithm::contains(line,
"property float z") ||
116 boost::algorithm::contains(line,
"property float32 x") ||
117 boost::algorithm::contains(line,
"property float32 y") ||
118 boost::algorithm::contains(line,
"property float32 z"))
122 else if (boost::algorithm::contains(line,
"property uchar red") ||
123 boost::algorithm::contains(line,
"property uchar green") ||
124 boost::algorithm::contains(line,
"property uchar blue"))
128 else if (boost::algorithm::contains(line,
"property float nx") ||
129 boost::algorithm::contains(line,
"property float ny") ||
130 boost::algorithm::contains(line,
"property float nz"))
134 else if (boost::algorithm::contains(line,
"end_header"))
138 else if (boost::algorithm::contains(line,
"binary"))
142 else if (boost::algorithm::contains(line,
"ascii"))
146 else if (boost::algorithm::contains(line,
"property list"))
150 else if (boost::algorithm::contains(line,
"property"))
152 throw readException((line +
" is currently not supported \n supported "
153 "properties: x y z [red green blue] [nx ny nz]")
157 std::cout <<
"FINISHED READING HEADER" << std::endl;
158 std::cout <<
"XYT: " << gotxyz << std::endl;
159 std::cout <<
"COLOR: " << gotcolor << std::endl;
160 std::cout <<
"NORMAL: " << gotnormal << std::endl;
161 std::cout <<
"BINARY: " << currentAttr.
m_binary << std::endl;
166 std::cout <<
"File Type is not PLY, checking file... " << std::endl;
168 std::getline(ifs, line);
169 std::stringstream ss(line);
171 unsigned int number_of_line_elements = 0;
174 number_of_line_elements++;
175 if (number_of_line_elements >= 3)
177 if (number_of_line_elements == 6)
179 if (boost::algorithm::contains(tmp,
"."))
188 if (number_of_line_elements == 9)
193 if (number_of_line_elements > 9)
195 throw std::range_error(
"Wrong file format, expecting file ascii or ply file "
196 "format, ascii file format must have order: x y z [nx "
197 "ny nz] [cx cy cz] (points, normals, colors)");
205 if (gotxyz && gotcolor && gotnormal)
209 sizeof(float) * 3 +
sizeof(
unsigned char) * 3 +
sizeof(float) * 3;
211 else if (gotxyz && gotcolor && !gotnormal)
214 currentAttr.
m_PointBlockSize =
sizeof(float) * 3 +
sizeof(
unsigned char) * 3;
216 else if (gotxyz && !gotcolor && gotnormal)
221 else if (gotxyz && !gotcolor && !gotnormal)
228 throw std::range_error(
"Did not find any points in data");
237 std::vector<std::string> tmp;
238 tmp.push_back(filePath);
250 throw readException(
"There is no file with selected index\n (maybe you forgot to rewind "
251 "LineReader when reading file again?)");
269 boost::shared_ptr<void> tmp;
277 pFile = fopen(filePath.c_str(),
"r");
284 size_t current_pos = ftell(pFile);
285 fseek(pFile, 0, SEEK_END);
286 size_t last_pos = ftell(pFile);
287 size_t data_left = last_pos - current_pos;
291 size_t readSize = amount;
292 if (data_left < readSize)
294 readSize = data_left;
297 boost::shared_ptr<void> pArray(
299 std::default_delete<
char[]>());
300 bla = fread(pArray.get(),
309 if (return_amount < amount)
316 size_t readCount = 0;
321 std::vector<float> input;
322 input.reserve(amount * 3);
323 boost::shared_ptr<void> pArray(
325 std::default_delete<
char[]>());
327 char lineBuffer[1024];
328 while ((fgets(lineBuffer, 1024, pFile) !=
NULL) && readCount < amount)
330 sscanf(lineBuffer,
"%f %f %f", &ax, &ay, &az);
340 return_amount = readCount;
341 if (return_amount < amount)
349 std::vector<float> input;
350 input.reserve(amount * 3);
351 boost::shared_ptr<void> pArray(
353 std::default_delete<
char[]>());
355 while ((fscanf(pFile,
"%f %f %f", &ax, &ay, &az) != EOF) && readCount < amount)
366 return_amount = readCount;
367 if (return_amount < amount)
381 std::vector<float> input;
382 input.reserve(amount * 6);
383 boost::shared_ptr<void> pArray(
385 std::default_delete<
char[]>());
386 float ax, ay, az, nx, ny, nz;
387 while ((fscanf(pFile,
"%f %f %f %f %f %f", &ax, &ay, &az, &nx, &ny, &nz) != EOF) &&
398 return_amount = readCount;
399 if (return_amount < amount)
407 std::vector<xyzc> input;
408 input.reserve(amount * 6);
409 boost::shared_ptr<void> pArray(
411 std::default_delete<
char[]>());
413 float tmp_x, tmp_y, tmp_z;
414 unsigned char tmp_r, tmp_g, tmp_b;
415 while ((fscanf(pFile,
416 "%f %f %f %hhu %hhu %hhu",
437 return_amount = readCount;
438 if (return_amount < amount)
446 std::vector<xyznc> input;
447 input.reserve(amount * 6);
448 boost::shared_ptr<void> pArray(
450 std::default_delete<
char[]>());
452 float tmp_x, tmp_y, tmp_z, tmp_nx, tmp_ny, tmp_nz;
453 unsigned char tmp_r, tmp_g, tmp_b;
454 while ((fscanf(pFile,
455 "%f %f %f %hhu %hhu %hhu %f %f %f",
473 pc.normal.x = tmp_nx;
474 pc.normal.y = tmp_ny;
475 pc.normal.z = tmp_nz;
482 return_amount = readCount;
484 if (return_amount < amount)
496 std::cout <<
"SHIT could not open file: " << std::strerror(errno) << std::endl;
500 boost::shared_ptr<void> tmp;
506 std::vector<std::string> tmp;