Ported the obj parser.
This commit is contained in:
@@ -9,6 +9,141 @@
|
||||
#include "glm/gtx/euler_angles.hpp"
|
||||
#include <charconv>
|
||||
#include <fstream>
|
||||
#include <execution>
|
||||
#include <queue>
|
||||
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
std::error_code assets::generic_3dtk_loader<Normal, Color, Reflectance>::prefetch(
|
||||
path_id_lookups& lookups
|
||||
) {
|
||||
m_path_buffer.clear();
|
||||
lookups.meshes.by_extension(".3d", m_path_buffer);
|
||||
|
||||
auto path_buffer = std::filesystem::path{};
|
||||
|
||||
for (const auto entry : m_path_buffer)
|
||||
{
|
||||
path_buffer = entry->first;
|
||||
path_buffer.replace_extension(".pose");
|
||||
lookups.poses.try_emplace(path_buffer);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
std::error_code assets::generic_3dtk_loader<Normal, Color, Reflectance>::load(
|
||||
path_id_lookups& lookups,
|
||||
data_stores& stores,
|
||||
bool pedantic
|
||||
) {
|
||||
m_path_buffer.clear();
|
||||
lookups.point_clouds.by_extension(".3d", m_path_buffer);
|
||||
|
||||
std::for_each(
|
||||
std::execution::parallel_unsequenced_policy{},
|
||||
m_path_buffer.begin(),
|
||||
m_path_buffer.end(),
|
||||
parser_context{
|
||||
lookups,
|
||||
stores,
|
||||
}
|
||||
);
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
assets::generic_3dtk_loader<Normal, Color, Reflectance>::parser_context::parser_context(
|
||||
path_id_lookups& m_id_lookups,
|
||||
data_stores& m_stores
|
||||
) :
|
||||
m_id_lookups{ &m_id_lookups },
|
||||
m_stores{ &m_stores }
|
||||
{
|
||||
constexpr auto expected_vertex_count = 8192;
|
||||
m_mesh.positions().reserve(expected_vertex_count);
|
||||
m_mesh.normals().reserve(expected_vertex_count);
|
||||
m_mesh.colors().reserve(expected_vertex_count);
|
||||
m_mesh.reflectances().reserve(expected_vertex_count);
|
||||
m_mesh.tex_coords().reserve(expected_vertex_count);
|
||||
m_mesh.triangles().reserve(2 * expected_vertex_count);
|
||||
|
||||
m_position_buffer.reserve(expected_vertex_count);
|
||||
m_normal_buffer.reserve(expected_vertex_count);
|
||||
m_tex_coord_buffer.reserve(expected_vertex_count);
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
void assets::generic_3dtk_loader<Normal, Color, Reflectance>::parser_context::reset()
|
||||
{
|
||||
m_mesh.clear();
|
||||
m_position_buffer.clear();
|
||||
m_normal_buffer.clear();
|
||||
m_tex_coord_buffer.clear();
|
||||
m_vertex_comp_indices_to_vertex_index.clear();
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
void assets::generic_3dtk_loader<Normal, Color, Reflectance>::parser_context::operator()(lookup_type::const_pointer entry) noexcept
|
||||
{
|
||||
// TODO look up pose
|
||||
const auto& [ filename, id ] = *entry;
|
||||
|
||||
auto in = std::ifstream{ filename };
|
||||
if (not in.is_open())
|
||||
{
|
||||
ztu::logger::warn("Cannot open obj file %.", filename);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
std::size_t scan_index;
|
||||
|
||||
if (auto res = parse_index(filename))
|
||||
{
|
||||
scan_index = *res;
|
||||
}
|
||||
else [[unlikely]]
|
||||
{
|
||||
const auto error = res.error();
|
||||
ztu::logger::error(
|
||||
"Error occurred while parsing scan index in filename %: [%] %",
|
||||
error.category().name(),
|
||||
error.message()
|
||||
);
|
||||
}
|
||||
|
||||
auto pose = asset_lookup.poses.find();
|
||||
|
||||
|
||||
const auto id_it = id_lookup.find(filename);
|
||||
|
||||
if (id_it != id_lookup.end()) [[unlikely]]
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
in.open(filename);
|
||||
if (in.is_open())
|
||||
{
|
||||
if ((error = this->read_point_file(filename, buffer))) {
|
||||
return error;
|
||||
}
|
||||
|
||||
this->transform_point_cloud(buffer.positions(), pose);
|
||||
|
||||
const auto id = store.add(std::move(buffer));
|
||||
id_lookup.emplace_hint(id_it, filename, id);
|
||||
}
|
||||
else
|
||||
{
|
||||
ztu::logger::error("Cannot open 3dtk file %", filename);
|
||||
}
|
||||
|
||||
in.close();
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
ztu::result<pose_prefetch_lookup::index_type> generic_3dtk_loader<Normal, Color, Reflectance>::parse_index(
|
||||
@@ -37,35 +172,12 @@ ztu::result<pose_prefetch_lookup::index_type> generic_3dtk_loader<Normal, Color,
|
||||
return index;
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
std::error_code generic_3dtk_loader<Normal, Color, Reflectance>::prefetch(
|
||||
const file_dir_list& paths,
|
||||
prefetch_queue& queue
|
||||
) {
|
||||
|
||||
auto path_buffer = std::filesystem::path{};
|
||||
|
||||
for (const auto filename : paths.files)
|
||||
{
|
||||
path_buffer.assign(filename.begin(), filename.end());
|
||||
path_buffer.replace_extension(".pose");
|
||||
queue.uos_queue.files.push_back(path_buffer.c_str());
|
||||
}
|
||||
|
||||
// TODO optimize
|
||||
for (const auto directory : paths.directories)
|
||||
{
|
||||
queue.uos_queue.directories.push_back(directory);
|
||||
}
|
||||
}
|
||||
|
||||
template<bool Normal, bool Color, bool Reflectance>
|
||||
std::error_code generic_3dtk_loader<Normal, Color, Reflectance>::load(
|
||||
dynamic_point_cloud_buffer& buffer,
|
||||
const file_dir_list& paths,
|
||||
prefetch_lookup& asset_lookup,
|
||||
dynamic_point_cloud_store& store,
|
||||
const bool pedantic
|
||||
std::error_code assets::generic_3dtk_loader<Normal, Color, Reflectance>::load(
|
||||
path_id_lookups& lookups,
|
||||
data_stores& stores,
|
||||
bool pedantic = false
|
||||
) {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
@@ -127,8 +239,6 @@ std::error_code generic_3dtk_loader<Normal, Color, Reflectance>::load(
|
||||
load_file(filename.data());
|
||||
}
|
||||
|
||||
|
||||
|
||||
for (const auto directory : paths.directories)
|
||||
{
|
||||
directory_buffer.assign(directory.begin(), directory.end());
|
||||
|
||||
Reference in New Issue
Block a user