further fixes

This commit is contained in:
ZY4N
2024-12-22 21:52:05 +01:00
parent db8db8f9d7
commit b385b3b1c8
5 changed files with 214 additions and 115 deletions

View File

@@ -42,9 +42,9 @@ std::error_code kitti_pose_loader::load(
auto path_buffer = fs::path{};
auto in = std::ifstream{}; // TODO disable exceptions (for other loaders as well)
auto pose_buffer = dynamic_pose_buffer{};
pose_buffer = glm::identity<glm::mat4>();
// Needed to initialize 4th row and col
buffer = glm::identity<glm::mat4>();
auto processed_filenames = ztu::string_list{};
@@ -62,13 +62,12 @@ std::error_code kitti_pose_loader::load(
ztu::logger::error("Kitti pose file does not exist: %", path_buffer);
return;
}
processed_filenames.push_back(path_buffer.c_str());
};
for (const auto directory : paths.directories) {
path_buffer.assign(directory.begin(), directory.end());
path_buffer /= "pose.txt";
path_buffer /= pose_filename;
preprocess_file();
}
@@ -79,6 +78,16 @@ std::error_code kitti_pose_loader::load(
for (const auto filename : processed_filenames)
{
// TODO if (not) removing the path separator creates issues.
const auto directory = filename.substr(0, filename.length() - pose_filename.length());
auto [ dir_it, dir_match ] = id_lookup.poses.find_directory(directory);
if (not dir_match) [[unlikely]]
{
dir_it = id_lookup.poses.emplace_dir(dir_it, directory);
}
in.open(filename.data()); // Safe because string list adds null terminator
if (not in.is_open())
{
@@ -90,7 +99,7 @@ std::error_code kitti_pose_loader::load(
for (auto i = pose_prefetch_lookup::index_type{}; in.peek() != std::ifstream::traits_type::eof(); ++i)
{
if (const auto error = parse_pose(in, pose_buffer))
if (const auto error = parse_pose(in, buffer))
{
ztu::logger::error(
"Error occurred while parsing kitti pose % in file %: [%] %",
@@ -102,62 +111,10 @@ std::error_code kitti_pose_loader::load(
continue;
}
const auto id = store.poses.add(pose_buffer);
// TODO if (not) removing the path separator creates issues.
const auto directory = filename.substr(0, filename.length() - pose_filename.length());
id_lookup.poses.emplace(directory, i, id);
const auto id = store.poses.add(buffer);
id_lookup.poses.emplace_hint_dir(dir_it, i, id);
}
in.close();
}
}
void kitti_pose_loader::load(
const ztu::string_list& directories,
dynamic_pose_store& store,
pose_prefetch_lookup& id_lookup
) {
auto filename_buffer = std::filesystem::path{};
auto in = std::ifstream{}; // TODO disable exceptions (for other loaders as well)
auto pose_buffer = dynamic_pose_buffer{};
pose_buffer = glm::identity<glm::mat4>();
for (const auto directory : directories)
{
filename_buffer = directory;
filename_buffer /= "pose.txt";
in.open(filename_buffer);
if (not in.is_open())
{
ztu::logger::error("Cannot open kitti pose file %", filename_buffer);
continue;
}
in >> std::skipws;
for (auto i = pose_prefetch_lookup::index_type{}; in.peek() != std::ifstream::traits_type::eof(); ++i)
{
if (const auto error = parse_pose(in, pose_buffer))
{
ztu::logger::error(
"Error occurred while parsing kitti pose % in file %: [%] %",
i,
filename_buffer,
error.category().name(),
error.message()
);
continue;
}
const auto id = store.add(pose_buffer);
id_lookup.emplace(directory, i, id);
}
in.close();
}
}