Skip to content
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

add option to retrieve origin data from point cloud generation #6564

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

dmitrishastin
Copy link
Contributor

Type

  • Bug fix (non-breaking change which fixes an issue): Fixes #
  • New feature (non-breaking change which adds functionality). Resolves #
  • Breaking change (fix or feature that would cause existing functionality to not work as expected) Resolves #

Motivation and Context

Record the origin of points in the data used for generating those points. In my context, this is is a triangular mesh where I wish to record triangle ID and UV coordinates per point, to then relate a number functions on the same surface to the sampled point cloud.

Tried to code such that this pull request is: (1) non-breaking / does not slow existing functionality, (2) easily scalable so other origin data types (e.g., voxel ID / relative coordinates) can be added.

However, I am not fluent in C++ and not sure if the proposed implementation is reasonable. Further, I wasn't sure this suggested functionality will be considered useful / accepted. As such, I only added the option to record origin data data in

  • PointCloud::operator+=
  • TriangleMesh::SamplePointsUniformlyImpl
  • TriangleMesh::SamplePointsUniformly
  • TriangleMesh::SamplePointsPoissonDisk

Checklist:

  • I have run python util/check_style.py --apply to apply Open3D code style
    to my code.
  • This PR changes Open3D behavior or adds new functionality.
    • Both C++ (Doxygen) and Python (Sphinx / Google style) documentation is
      updated accordingly.
    • I have added or updated C++ and / or Python unit tests OR included test
      results
      (e.g. screenshots or numbers) here.
  • I will follow up and update the code if CI fails.
  • For fork PRs, I have selected Allow edits from maintainers.

Description

import open3d as o3d
import numpy as np
cube = o3d.geometry.TriangleMesh.create_box()                                                
pts = cube.sample_points_uniformly(4000)     
pts.origin_data()
{'tri_id': [], 'tri_uv': std::vector<Eigen::Vector2d> with 0 elements.
Use numpy.asarray() to access data.}

pts.has_origin_data()                                                                                            
False
                                                                                                                
pts = cube.sample_points_uniformly(4000, record_origin=True)
pts.has_origin_data()
True

pts.origin_data().keys()
dict_keys(['tri_id', 'tri_uv'])

np.asarray(pts.origin_data()['tri_uv'])                                                                          
array([[0.65370755, 0.25589466],                                                                                            
       [0.81755558, 0.14071095],                                                                                            
       [0.5513747 , 0.32234846],                                                                                            
       ...,                                                                                                                 
       [0.96641095, 0.02235785],                                                                                            
       [0.29790422, 0.39937283],                                                                                            
       [0.70699849, 0.17731053]])

v = np.asarray(cube.vertices) 
t = np.asarray(cube.triangles)
tidx = np.array(pts.origin_data()['tri_id']) # simple list
uv = np.asarray(pts.origin_data()['tri_uv'])
w = 1 - np.sum(uv, axis = 1)
c = v[t[tidx, 0], :] * uv[:, 0][:, None] + v[t[tidx, 1], :] * uv[:, 1][:, None] + v[t[tidx, 2], :] * w[:, None] # point coordinates from barycentric coordinates
np.allclose(c, np.asarray(pts.points))
True

Copy link

update-docs bot commented Jan 4, 2024

Thanks for submitting this pull request! The maintainers of this repository would appreciate if you could update the CHANGELOG.md based on your changes.

@dmitrishastin
Copy link
Contributor Author

dmitrishastin commented Jan 8, 2024

Afraid I am not certain regarding the Codacy findings above (under tests) - I thought I applied logic similar to other Boolean flags (e.g., use_triangle_normal), but it does not seem to like it. Will be grateful for advice.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant