gtsam_points
Loading...
Searching...
No Matches
read_points.hpp
1// SPDX-License-Identifier: MIT
2// Copyright (c) 2021 Kenji Koide (k.koide@aist.go.jp)
3
4#pragma once
5
6#include <vector>
7#include <fstream>
8#include <iostream>
9#include <Eigen/Core>
10
11namespace gtsam_points {
12
13static std::vector<float> read_times(const std::string& path) {
14 std::ifstream ifs(path, std::ios::binary | std::ios::ate);
15 if (!ifs) {
16 std::cerr << "error: failed to open " << path << std::endl;
17 return std::vector<float>();
18 }
19
20 std::streamsize points_bytes = ifs.tellg();
21 size_t num_data = points_bytes / sizeof(float);
22
23 ifs.seekg(0, std::ios::beg);
24 std::vector<float> times(num_data);
25 ifs.read(reinterpret_cast<char*>(times.data()), sizeof(float) * num_data);
26
27 return times;
28}
29
30static std::vector<Eigen::Vector3f> read_points(const std::string& path) {
31 std::ifstream ifs(path, std::ios::binary | std::ios::ate);
32 if (!ifs) {
33 std::cerr << "error: failed to open " << path << std::endl;
34 return std::vector<Eigen::Vector3f>();
35 }
36
37 std::streamsize points_bytes = ifs.tellg();
38 size_t num_points = points_bytes / (sizeof(Eigen::Vector3f));
39
40 ifs.seekg(0, std::ios::beg);
41 std::vector<Eigen::Vector3f> points(num_points);
42 ifs.read(reinterpret_cast<char*>(points.data()), sizeof(Eigen::Vector3f) * num_points);
43
44 return points;
45}
46
47static std::vector<Eigen::Vector4f> read_points4(const std::string& path) {
48 std::ifstream ifs(path, std::ios::binary | std::ios::ate);
49 if (!ifs) {
50 std::cerr << "error: failed to open " << path << std::endl;
51 return std::vector<Eigen::Vector4f>();
52 }
53
54 std::streamsize points_bytes = ifs.tellg();
55 size_t num_points = points_bytes / (sizeof(Eigen::Vector4f));
56
57 ifs.seekg(0, std::ios::beg);
58 std::vector<Eigen::Vector4f> points(num_points);
59 ifs.read(reinterpret_cast<char*>(points.data()), sizeof(Eigen::Vector4f) * num_points);
60
61 return points;
62}
63
64} // namespace gtsam_points