//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
| 1354 | |
| 1355 | /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// |
| 1356 | int |
| 1357 | pcl::PCDWriter::writeBinaryCompressed (std::ostream &os, const pcl::PCLPointCloud2 &cloud, |
| 1358 | const Eigen::Vector4f &origin, const Eigen::Quaternionf &orientation) |
| 1359 | { |
| 1360 | if (cloud.data.empty ()) |
| 1361 | { |
| 1362 | PCL_WARN ("[pcl::PCDWriter::writeBinaryCompressed] Input point cloud has no data!\n"); |
| 1363 | } |
| 1364 | if (cloud.fields.empty()) |
| 1365 | { |
| 1366 | PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] Input point cloud has no field data!\n"); |
| 1367 | return (-1); |
| 1368 | } |
| 1369 | |
| 1370 | |
| 1371 | if (generateHeaderBinaryCompressed (os, cloud, origin, orientation)) |
| 1372 | { |
| 1373 | return (-1); |
| 1374 | } |
| 1375 | |
| 1376 | std::size_t fsize = 0; |
| 1377 | std::size_t data_size = 0; |
| 1378 | std::size_t nri = 0; |
| 1379 | std::vector<pcl::PCLPointField> fields (cloud.fields.size ()); |
| 1380 | std::vector<int> fields_sizes (cloud.fields.size ()); |
| 1381 | // Compute the total size of the fields |
| 1382 | for (const auto &field : cloud.fields) |
| 1383 | { |
| 1384 | if (field.name == "_") |
| 1385 | continue; |
| 1386 | |
| 1387 | fields_sizes[nri] = field.count * pcl::getFieldSize (field.datatype); |
| 1388 | fsize += fields_sizes[nri]; |
| 1389 | fields[nri] = field; |
| 1390 | ++nri; |
| 1391 | } |
| 1392 | fields_sizes.resize (nri); |
| 1393 | fields.resize (nri); |
| 1394 | |
| 1395 | // Compute the size of data |
| 1396 | data_size = cloud.width * cloud.height * fsize; |
| 1397 | |
| 1398 | // If the data is too large the two 32 bit integers used to store the |
| 1399 | // compressed and uncompressed size will overflow. |
| 1400 | if (data_size * 3 / 2 > std::numeric_limits<std::uint32_t>::max ()) |
| 1401 | { |
| 1402 | PCL_ERROR ("[pcl::PCDWriter::writeBinaryCompressed] The input data exceeds the maximum size for compressed version 0.7 pcds of %l bytes.\n", |
| 1403 | static_cast<std::size_t> (std::numeric_limits<std::uint32_t>::max ()) * 2 / 3); |
| 1404 | return (-2); |
| 1405 | } |
| 1406 | |
| 1407 | std::vector<char> temp_buf (data_size * 3 / 2 + 8); |
| 1408 | if (data_size != 0) { |
| 1409 | |
| 1410 | ////////////////////////////////////////////////////////////////////// |
| 1411 | // Empty array holding only the valid data |
| 1412 | // data_size = nr_points * point_size |
| 1413 | // = nr_points * (sizeof_field_1 + sizeof_field_2 + ... sizeof_field_n) |