Skip to content

Commit

Permalink
MAINT: debug PLY file and clean up code.
Browse files Browse the repository at this point in the history
  • Loading branch information
Odd Kiva committed May 26, 2024
1 parent b908422 commit c436042
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
18 changes: 12 additions & 6 deletions cpp/src/DO/Sara/SfM/BuildingBlocks/PointCloudGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ auto PointCloudGenerator::filter_by_non_max_suppression(
}

auto PointCloudGenerator::find_feature_vertex_at_pose(
const FeatureTrack& track, const PoseVertex pose_vertex) const
-> std::optional<FeatureVertex>
const FeatureTrack& track,
const PoseVertex pose_vertex) const -> std::optional<FeatureVertex>
{
auto v = std::find_if(track.begin(), track.end(),
[this, pose_vertex](const auto& v) {
Expand Down Expand Up @@ -392,7 +392,8 @@ auto PointCloudGenerator::grow_point_cloud(

// Calculate the scene point.
const Eigen::Vector3d coords = X.col(j).hnormalized();
if (coords.squaredNorm() > distance_max_squared()) // We deem it to be a point at infinity.
if (coords.squaredNorm() >
distance_max_squared()) // We deem it to be a point at infinity.
continue;

const auto color = retrieve_scene_point_color(coords, image, //
Expand Down Expand Up @@ -474,11 +475,16 @@ auto PointCloudGenerator::write_ply(const std::filesystem::path& out_ply) const
-> void
{
auto coords = std::vector<Eigen::Vector3d>(_point_cloud.size());
auto colors = std::vector<Eigen::Vector3d>(_point_cloud.size());
auto colors = std::vector<Eigen::Vector3<std::uint8_t>>(_point_cloud.size());
std::transform(_point_cloud.begin(), _point_cloud.end(), coords.begin(),
[](const ScenePoint& x) { return x.coords(); });
std::transform(_point_cloud.begin(), _point_cloud.end(), colors.begin(),
[](const ScenePoint& x) { return x.color(); });
[](const ScenePoint& x) -> Eigen::Vector3<std::uint8_t> {
Eigen::Vector3d x255 = x.color() * 255;
for (auto i = 0; i < 3; ++i)
x255(i) = std::clamp(x255(i), 0., 255.);
return x255.cast<std::uint8_t>();
});

auto fb = std::filebuf{};
fb.open(out_ply, std::ios::out);
Expand All @@ -493,7 +499,7 @@ auto PointCloudGenerator::write_ply(const std::filesystem::path& out_ply) const
tinyply::Type::INVALID, 0);

ply.add_properties_to_element("vertex", {"red", "green", "blue"},
tinyply::Type::FLOAT64, colors.size(),
tinyply::Type::UINT8, colors.size(),
reinterpret_cast<std::uint8_t*>(colors.data()),
tinyply::Type::INVALID, 0);

Expand Down
14 changes: 6 additions & 8 deletions cpp/src/DO/Sara/SfM/Odometry/OdometryPipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include <DO/Sara/SfM/Helpers/Utilities.hpp>


// #define USE_ABSOLUTE_ROTATION
// #define DEBUG_ABSOLUTE_POSE_RECOVERY


Expand Down Expand Up @@ -254,7 +255,6 @@ auto OdometryPipeline::grow_geometry() -> bool
_tracks_alive_without_scene_point) =
_point_cloud_generator->split_by_scene_point_knowledge(_tracks_alive);

// #define USE_ABSOLUTE_ROTATION
#if defined(USE_ABSOLUTE_ROTATION)
const auto [abs_pose_mat, abs_pose_est_successful] =
_abs_pose_estimator.estimate_pose(
Expand Down Expand Up @@ -282,16 +282,10 @@ auto OdometryPipeline::grow_geometry() -> bool
}

// 8. Grow point cloud by triangulation.
//
// TODO: don't add 3D scene points that are too far, like points in the sky
const auto frame_corrected = _distortion_corrector->frame_rgb8();
_point_cloud_generator->grow_point_cloud(_tracks_alive_without_scene_point,
frame_corrected, pose_edge,
_camera_corrected);
#if defined(DEBUG_ABSOLUTE_POSE_RECOVERY)
const auto scene_csv_fp = fmt::format("scene_{}.csv", _pose_curr);
_point_cloud_generator->write_point_cloud(_tracks_alive, scene_csv_fp);
#endif

adjust_bundles();

Expand All @@ -308,7 +302,11 @@ auto OdometryPipeline::grow_geometry() -> bool
//
// ---------------------------------------------------------------------------

_point_cloud_generator->write_ply(fmt::format("scene_{:04d}.ply", _pose_curr));
#if defined(DEBUG_ABSOLUTE_POSE_RECOVERY)
const auto scene_ply = fmt::format("scene_{:04d}.ply", _pose_curr);
SARA_LOGI(logger, "Saving PLY {}", scene_ply);
_point_cloud_generator->write_ply(scene_ply);
#endif

return true;
}
Expand Down

0 comments on commit c436042

Please sign in to comment.