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 checked attribute view and float generic in compute centroid #24

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

Conversation

dan-jfisher
Copy link

@dan-jfisher dan-jfisher commented Nov 15, 2023

#23
Downside of this approach is that it requires the user to specify if their pointcloud has f32 or f64 precision.

If it's important, we can maintain backwards compatibility with some clever naming.

\Edit: for centroid, which I used as an example, we could get around that with a private generic function and a public function that always returns f64 and checks the data_type of the point cloud attribute at runtime. I am not crazy about that solution though.

@dan-jfisher
Copy link
Author

It would probably be better to take an AttributeView which has already been typed rather than taking the entire cloud. However, if we are going to do that we need to expand AttributeView so that it includes things like len and is_empty.

I am happy to go in that direction though.

Copy link
Collaborator

@Mortano Mortano left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that algorithms over attribute views would probably be better (though some algorithms might require multiple attributes or even mutate data, these would have to take a PointBuffer). If you want to implement it as a PoC for the compute_centroid function that would be fine for me, with the suggested changes (len and is_empty for the views). If not, I'm also fine with merging the changes as is.

Apart from that, for completeness there should be _checked functions for the other view accessors as well, i.e. view, view_attribute_with_conversion and the mutable ones view_mut and view_attribute_mut. Would be great if you could add those.

@dan-jfisher
Copy link
Author

What do you think about making view_attribute_checked the default behavior (i.e. view_attribute) and calling the standard function view_attribute_unchecked?

Regardless, I removed that part of PR so that this one is focused on AttributeView and compute_centroid as PoC for generic algorithms.

We can handle view_attribute_checked vs unchecked in a separate issue.

@dan-jfisher dan-jfisher force-pushed the checked_attribute_view_and_generic_centroid branch from 778a1f1 to 94c1e43 Compare November 15, 2023 15:06
if point_cloud.is_empty() {
panic!("The point cloud is empty!");
pub fn compute_centroid<'a, 'b, T, F>(
attribute_view: &AttributeView<'a, 'b, T, Vector3<F>>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AttributeView is Copy, so you can pass by value here. This prevents you from having to implement IntoIterator for &AttributeView

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.

2 participants