Skip to content

Commit 9a9af2e

Browse files
committed
Import project files from Uni Bonn Sciebo
1 parent 7822635 commit 9a9af2e

File tree

6 files changed

+6874
-0
lines changed

6 files changed

+6874
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Data/PLY/*

Data/gt_poses.txt

Lines changed: 6770 additions & 0 deletions
Large diffs are not rendered by default.

dataloader/dataloader.cpp

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "dataloader.hpp"
2+
3+
#include <open3d/Open3D.h>
4+
5+
#include <Eigen/Core>
6+
#include <filesystem>
7+
#include <fstream>
8+
#include <string>
9+
#include <utility>
10+
#include <vector>
11+
12+
namespace fs = std::filesystem;
13+
14+
namespace {
15+
16+
std::vector<std::string> ReadPointCloudFiles(const fs::path& pointcloud_path) {
17+
std::vector<std::string> filenames;
18+
for (const auto& file : fs::directory_iterator(pointcloud_path)) {
19+
if (file.path().extension() == ".ply") {
20+
filenames.emplace_back(file.path().string());
21+
}
22+
}
23+
if (filenames.empty()) {
24+
std::cerr << pointcloud_path << "contains no files with .ply extension"
25+
<< std::endl;
26+
exit(1);
27+
}
28+
std::sort(filenames.begin(), filenames.end());
29+
30+
return filenames;
31+
}
32+
33+
Vector3dVector ExtractPointCloud(const std::string& filename) {
34+
open3d::geometry::PointCloud pointcloud;
35+
open3d::io::ReadPointCloudFromPLY(filename, pointcloud,
36+
open3d::io::ReadPointCloudOption());
37+
return pointcloud.points_;
38+
}
39+
40+
std::vector<Eigen::Matrix4d> ReadPoses(const std::string& filename) {
41+
std::ifstream file(filename);
42+
std::vector<Eigen::Matrix4d> poses;
43+
Eigen::Matrix4d pose = Eigen::Matrix4d::Identity();
44+
while (file >> pose(0, 0) >> pose(0, 1) >> pose(0, 2) >> pose(0, 3) >>
45+
pose(1, 0) >> pose(1, 1) >> pose(1, 2) >> pose(1, 3) >> pose(2, 0) >>
46+
pose(2, 1) >> pose(2, 2) >> pose(2, 3)) {
47+
poses.emplace_back(pose);
48+
}
49+
return poses;
50+
}
51+
52+
} // namespace
53+
54+
namespace dataloader {
55+
Dataset::Dataset(const std::string& data_dir) {
56+
pointcloud_files_ = ReadPointCloudFiles(fs::path(data_dir) / "PLY/");
57+
58+
poses_.reserve(pointcloud_files_.size());
59+
poses_ = ReadPoses(fs::path(data_dir) / "gt_poses.txt");
60+
}
61+
62+
PoseAndCloud Dataset::operator[](
63+
const int idx) const {
64+
return std::make_pair(poses_[idx], ExtractPointCloud(pointcloud_files_[idx]));
65+
}
66+
} // namespace dataloader

dataloader/dataloader.hpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#pragma once
2+
3+
#include <Eigen/Core>
4+
#include <string>
5+
#include <utility>
6+
#include <vector>
7+
8+
using Vector3dVector = std::vector<Eigen::Vector3d>;
9+
using PoseAndCloud = std::pair<Eigen::Matrix4d, Vector3dVector>;
10+
11+
namespace dataloader
12+
{
13+
class Dataset
14+
{
15+
public:
16+
Dataset(const std::string &data_dir);
17+
std::size_t size() const { return pointcloud_files_.size(); }
18+
PoseAndCloud operator[](const int idx) const;
19+
20+
private:
21+
std::vector<std::string> pointcloud_files_;
22+
std::vector<Eigen::Matrix4d> poses_;
23+
};
24+
} // namespace dataloader

project_assignment.pdf

42.5 KB
Binary file not shown.

visualizer/visualizer.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#pragma once
2+
3+
#include <Eigen/Core>
4+
#include <memory>
5+
#include <vector>
6+
7+
#include "open3d/Open3D.h"
8+
9+
inline void visualize(
10+
const std::vector<Eigen::Vector3d>& pointcloud) {
11+
open3d::visualization::DrawGeometries(
12+
{std::make_shared<open3d::geometry::PointCloud>(pointcloud)});
13+
}

0 commit comments

Comments
 (0)