-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Add Symmetric ICP Implementation #7276
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
eclipse0922
wants to merge
44
commits into
isl-org:main
Choose a base branch
from
eclipse0922:zyu8e9-codex/implement-symmetric-icp-with-objective-function
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
44 commits
Select commit
Hold shift + click to select a range
5bf2471
Add symmetric ICP implementation and tests
eclipse0922 73ee74d
Adds Symmetric ICP registration method
eclipse0922 31faa3b
Adds symmetric point-to-plane distance estimation
eclipse0922 845f25f
Improves Symmetric ICP tests
eclipse0922 ce36485
Refactors and improves SymmetricICP class
eclipse0922 ab961f9
Refactors and fixes Symmetric ICP
eclipse0922 ef2e7fc
Improves Symmetric ICP estimation
eclipse0922 d429c68
Removes unnecessary Eigen include
eclipse0922 9be8f65
Removes unnecessary includes
eclipse0922 c3453ef
Implements Symmetric ICP registration on CUDA
eclipse0922 801235a
Removes outdated CLAUDE guidance file.
eclipse0922 c201fbd
Updates attribute name in test assertion
eclipse0922 b80f32d
Enables symmetric ICP with normals
eclipse0922 3e1f53a
Removes whitespace for code consistency
eclipse0922 456f14c
Improves symmetric ICP registration stability
eclipse0922 df1ec10
Addres copilot review
eclipse0922 c34eba2
Removes redundant device assertion
eclipse0922 9e751e6
Address coments
eclipse0922 ed48504
Update python/test/test_symmetric_icp.py
eclipse0922 334187e
revert clone() usage
eclipse0922 28846fc
fit test case
eclipse0922 3550f4e
Fix Ubuntu CI (#7319)
ssheorey 3e5c88a
Add symmetric ICP implementation and tests
eclipse0922 737d5c8
Adds Symmetric ICP registration method
eclipse0922 8e37764
Adds symmetric point-to-plane distance estimation
eclipse0922 ee1d19c
Improves Symmetric ICP tests
eclipse0922 92f7596
Refactors and improves SymmetricICP class
eclipse0922 6dcab73
Refactors and fixes Symmetric ICP
eclipse0922 352d8a1
Improves Symmetric ICP estimation
eclipse0922 2aa20cc
Removes unnecessary Eigen include
eclipse0922 4a02102
Removes unnecessary includes
eclipse0922 7db59e2
Implements Symmetric ICP registration on CUDA
eclipse0922 aea9f6c
Removes outdated CLAUDE guidance file.
eclipse0922 bbe45c5
Updates attribute name in test assertion
eclipse0922 ff3bae6
Enables symmetric ICP with normals
eclipse0922 57edff8
Removes whitespace for code consistency
eclipse0922 ce26ccd
Improves symmetric ICP registration stability
eclipse0922 e795716
Addres copilot review
eclipse0922 b599c76
Removes redundant device assertion
eclipse0922 838db51
Address coments
eclipse0922 02d778b
Update python/test/test_symmetric_icp.py
eclipse0922 3ea6ae0
revert clone() usage
eclipse0922 89ede24
fit test case
eclipse0922 5a87926
Merge remote-tracking branch 'open3d/zyu8e9-codex/implement-symmetric…
eclipse0922 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,134 @@ | ||
// ---------------------------------------------------------------------------- | ||
// - Open3D: www.open3d.org - | ||
// ---------------------------------------------------------------------------- | ||
// Copyright (c) 2018-2024 www.open3d.org | ||
// SPDX-License-Identifier: MIT | ||
// ---------------------------------------------------------------------------- | ||
|
||
#include "open3d/pipelines/registration/SymmetricICP.h" | ||
|
||
#include "open3d/geometry/PointCloud.h" | ||
#include "open3d/utility/Eigen.h" | ||
#include "open3d/utility/Logging.h" | ||
|
||
namespace open3d { | ||
namespace pipelines { | ||
namespace registration { | ||
|
||
double TransformationEstimationSymmetric::ComputeRMSE( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
const CorrespondenceSet &corres) const { | ||
if (corres.empty() || !target.HasNormals() || !source.HasNormals()) { | ||
return 0.0; | ||
} | ||
double err = 0.0; | ||
for (const auto &c : corres) { | ||
const Eigen::Vector3d &vs = source.points_[c[0]]; | ||
const Eigen::Vector3d &vt = target.points_[c[1]]; | ||
const Eigen::Vector3d &ns = source.normals_[c[0]]; | ||
const Eigen::Vector3d &nt = target.normals_[c[1]]; | ||
Eigen::Vector3d d = vs - vt; | ||
double r1 = d.dot(nt); | ||
double r2 = d.dot(ns); | ||
err += r1 * r1 + r2 * r2; | ||
} | ||
return std::sqrt(err / (double)corres.size()); | ||
} | ||
|
||
Eigen::Matrix4d TransformationEstimationSymmetric::ComputeTransformation( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
const CorrespondenceSet &corres) const { | ||
if (corres.empty() || !target.HasNormals() || !source.HasNormals()) { | ||
return Eigen::Matrix4d::Identity(); | ||
} | ||
|
||
auto compute_jacobian_and_residual = | ||
[&](int i, | ||
std::vector<Eigen::Vector6d, utility::Vector6d_allocator> &J_r, | ||
std::vector<double> &r, std::vector<double> &w) { | ||
const Eigen::Vector3d &vs = source.points_[corres[i][0]]; | ||
const Eigen::Vector3d &vt = target.points_[corres[i][1]]; | ||
const Eigen::Vector3d &ns = source.normals_[corres[i][0]]; | ||
const Eigen::Vector3d &nt = target.normals_[corres[i][1]]; | ||
const Eigen::Vector3d d = vs - vt; | ||
|
||
// Symmetric ICP always uses exactly 2 jacobians/residuals | ||
// Ensure vectors have correct size (only resizes on first call) | ||
if (J_r.size() != 2) { | ||
J_r.resize(2); | ||
r.resize(2); | ||
w.resize(2); | ||
} | ||
|
||
r[0] = d.dot(nt); | ||
w[0] = kernel_->Weight(r[0]); | ||
J_r[0].block<3, 1>(0, 0) = vs.cross(nt); | ||
J_r[0].block<3, 1>(3, 0) = nt; | ||
|
||
r[1] = d.dot(ns); | ||
w[1] = kernel_->Weight(r[1]); | ||
J_r[1].block<3, 1>(0, 0) = vs.cross(ns); | ||
J_r[1].block<3, 1>(3, 0) = ns; | ||
}; | ||
|
||
Eigen::Matrix6d JTJ; | ||
Eigen::Vector6d JTr; | ||
double r2; | ||
std::tie(JTJ, JTr, r2) = | ||
utility::ComputeJTJandJTr<Eigen::Matrix6d, Eigen::Vector6d>( | ||
compute_jacobian_and_residual, (int)corres.size()); | ||
|
||
bool is_success; | ||
Eigen::Matrix4d extrinsic; | ||
std::tie(is_success, extrinsic) = | ||
utility::SolveJacobianSystemAndObtainExtrinsicMatrix(JTJ, JTr); | ||
|
||
return is_success ? extrinsic : Eigen::Matrix4d::Identity(); | ||
} | ||
|
||
std::tuple<std::shared_ptr<const geometry::PointCloud>, | ||
std::shared_ptr<const geometry::PointCloud>> | ||
TransformationEstimationSymmetric::InitializePointCloudsForTransformation( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
double max_correspondence_distance) const { | ||
if (!target.HasNormals() || !source.HasNormals()) { | ||
utility::LogError( | ||
"SymmetricICP requires both source and target to " | ||
"have normals."); | ||
} | ||
std::shared_ptr<const geometry::PointCloud> source_initialized_c( | ||
&source, [](const geometry::PointCloud *) {}); | ||
std::shared_ptr<const geometry::PointCloud> target_initialized_c( | ||
&target, [](const geometry::PointCloud *) {}); | ||
if (!source_initialized_c || !target_initialized_c) { | ||
utility::LogError( | ||
"Internal error: InitializePointCloudsFor" | ||
"Transformation returns nullptr."); | ||
} | ||
return std::make_tuple(source_initialized_c, target_initialized_c); | ||
} | ||
|
||
RegistrationResult RegistrationSymmetricICP( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
double max_correspondence_distance, | ||
const Eigen::Matrix4d &init, | ||
const TransformationEstimationSymmetric &estimation, | ||
const ICPConvergenceCriteria &criteria) { | ||
// Validate that both point clouds have normals | ||
if (!source.HasNormals() || !target.HasNormals()) { | ||
utility::LogError( | ||
"SymmetricICP requires both source and target to have " | ||
"normals."); | ||
} | ||
|
||
return RegistrationICP(source, target, max_correspondence_distance, init, | ||
estimation, criteria); | ||
} | ||
|
||
} // namespace registration | ||
} // namespace pipelines | ||
} // namespace open3d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// ---------------------------------------------------------------------------- | ||
// - Open3D: www.open3d.org - | ||
// ---------------------------------------------------------------------------- | ||
// Copyright (c) 2018-2024 www.open3d.org | ||
// SPDX-License-Identifier: MIT | ||
// ---------------------------------------------------------------------------- | ||
|
||
#pragma once | ||
|
||
#include "open3d/pipelines/registration/Registration.h" | ||
#include "open3d/pipelines/registration/RobustKernel.h" | ||
#include "open3d/pipelines/registration/TransformationEstimation.h" | ||
|
||
namespace open3d { | ||
|
||
namespace geometry { | ||
class PointCloud; | ||
} | ||
|
||
namespace pipelines { | ||
namespace registration { | ||
|
||
class RegistrationResult; | ||
|
||
/// \brief Transformation estimation for symmetric point-to-plane ICP. | ||
class TransformationEstimationSymmetric : public TransformationEstimation { | ||
public: | ||
~TransformationEstimationSymmetric() override {}; | ||
|
||
TransformationEstimationType GetTransformationEstimationType() | ||
const override { | ||
return type_; | ||
}; | ||
explicit TransformationEstimationSymmetric( | ||
std::shared_ptr<RobustKernel> kernel = std::make_shared<L2Loss>()) | ||
: kernel_(std::move(kernel)) {} | ||
double ComputeRMSE(const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
const CorrespondenceSet &corres) const override; | ||
Eigen::Matrix4d ComputeTransformation( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
const CorrespondenceSet &corres) const override; | ||
|
||
std::tuple<std::shared_ptr<const geometry::PointCloud>, | ||
std::shared_ptr<const geometry::PointCloud>> | ||
InitializePointCloudsForTransformation( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
double max_correspondence_distance) const override; | ||
|
||
/// shared_ptr to an Abstract RobustKernel that could mutate at runtime. | ||
std::shared_ptr<RobustKernel> kernel_ = std::make_shared<L2Loss>(); | ||
|
||
private: | ||
const TransformationEstimationType type_ = | ||
TransformationEstimationType::PointToPlane; | ||
}; | ||
|
||
/// \brief Function for symmetric ICP registration using point-to-plane error. | ||
RegistrationResult RegistrationSymmetricICP( | ||
const geometry::PointCloud &source, | ||
const geometry::PointCloud &target, | ||
double max_correspondence_distance, | ||
const Eigen::Matrix4d &init = Eigen::Matrix4d::Identity(), | ||
const TransformationEstimationSymmetric &estimation = | ||
TransformationEstimationSymmetric(), | ||
const ICPConvergenceCriteria &criteria = ICPConvergenceCriteria()); | ||
|
||
} // namespace registration | ||
} // namespace pipelines | ||
} // namespace open3d |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.