MCPcopy Create free account
hub / github.com/LimHyungTae/patchwork / PcdLoader

Class PcdLoader

include/tools/pcd_loader.hpp:11–60  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9
10template <typename T>
11class PcdLoader {
12 public:
13 explicit PcdLoader(const std::string &pcd_path) : pcd_path_(pcd_path) {
14 for (num_frames_ = 0;; num_frames_++) {
15 std::string filename = (boost::format("%s/%06d.pcd") % pcd_path % num_frames_).str();
16 if (!boost::filesystem::exists(filename)) {
17 break;
18 }
19 }
20
21 if (num_frames_ == 0) {
22 std::cerr << "error: no files in " << pcd_path << std::endl;
23 }
24 }
25
26 ~PcdLoader() {}
27
28 size_t size() const { return num_frames_; }
29
30 typename pcl::PointCloud<T>::ConstPtr cloud(size_t i) const {
31 std::string filename = (boost::format("%s/%06d.bin") % pcd_path_ % i).str();
32 FILE *file = fopen(filename.c_str(), "rb");
33 if (!file) {
34 std::cerr << "error: failed to load " << filename << std::endl;
35 return nullptr;
36 }
37
38 std::vector<float> buffer(1000000);
39 size_t num_points =
40 fread(reinterpret_cast<char *>(buffer.data()), sizeof(float), buffer.size(), file) / 4;
41 fclose(file);
42
43 pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>());
44 cloud->resize(num_points);
45
46 for (int i = 0; i < num_points; i++) {
47 auto &pt = cloud->at(i);
48 pt.x = buffer[i * 4];
49 pt.y = buffer[i * 4 + 1];
50 pt.z = buffer[i * 4 + 2];
51 // pt.intensity = buffer[i * 4 + 3];
52 }
53
54 return cloud;
55 }
56
57 private:
58 int num_frames_;
59 std::string pcd_path_;
60};
61#endif // INCLUDE_TOOLS_PCD_LOADER_HPP_

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected