-
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
Draft
eclipse0922
wants to merge
23
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.
Draft
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
121603b
Add symmetric ICP implementation and tests
eclipse0922 f7b4db9
Adds Symmetric ICP registration method
eclipse0922 065c088
Adds symmetric point-to-plane distance estimation
eclipse0922 0c86832
Improves Symmetric ICP tests
eclipse0922 ee84b42
Refactors and improves SymmetricICP class
eclipse0922 2414c6c
Refactors and fixes Symmetric ICP
eclipse0922 6adc434
Improves Symmetric ICP estimation
eclipse0922 d570367
Removes unnecessary Eigen include
eclipse0922 47696d7
Removes unnecessary includes
eclipse0922 65e1fee
Implements Symmetric ICP registration on CUDA
eclipse0922 ba03c91
Removes outdated CLAUDE guidance file.
eclipse0922 6c88250
Updates attribute name in test assertion
eclipse0922 b6c383e
Enables symmetric ICP with normals
eclipse0922 a8f5aaa
Removes whitespace for code consistency
eclipse0922 231784b
Improves symmetric ICP registration stability
eclipse0922 8150f8c
Addres copilot review
eclipse0922 8ed52cb
Removes redundant device assertion
eclipse0922 b9298de
Address coments
eclipse0922 d20774a
Update python/test/test_symmetric_icp.py
eclipse0922 074c5b3
revert clone() usage
eclipse0922 f09006b
fit test case
eclipse0922 8c830fc
add examples and fixes
eclipse0922 efc44eb
Clarifies Jacobian calculation in symmetric ICP
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
| 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); | ||
| } | ||
eclipse0922 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| 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, | ||
eclipse0922 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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.