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

Segmentation to mesh conversion #29

Merged
merged 14 commits into from
Mar 30, 2024

Conversation

LorenzLamm
Copy link
Contributor

As suggested in #27 , this PR adds a Widget that can convert an existing segmentation (labels layer) and transform it into a mesh.

To this end, I am using pyvista and the pyacvd package (which relies on pyvista).
The nice thing about this is about pyacvd is that it can uniformly remesh the surface to an approximate number of triangles. This seemed better suited to me than trimesh's subdivision operations because these can only subdivide already existing triangles.

However, I guess it's not ideal to have both pyvista and trimesh dependencies in here? I think most of the trimesh functions here could also be done in pyvista, but I'm also happy to replace the pyacvd functionality with some trimesh functions.

Let me know what you think :)

@@ -163,11 +167,9 @@ def _get_valid_image_layers(self, combo_box) -> List[Image]:
]

def get_point_colors(self, points):
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Also added this linear interpolation here. The direct sampling on coordinates gave some artifacts, particularly on the Chlamy thylakoid demo example.

Copy link
Contributor

@kevinyamauchi kevinyamauchi left a comment

Choose a reason for hiding this comment

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

This LGTM! I think there are just a few minor updates to the docstrings. Otherwise, good to go.

mask : np.ndarray
A binary mask.
barycentric_area : float, optional
The area of each triangle in the mesh, by default 1.0
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this the target area (i.e., it doesn't actually guarantee that this area is uniformly achieved)? If so, I think we should specify

Suggested change
The area of each triangle in the mesh, by default 1.0
The target area of each triangle in the mesh, by default 1.0

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You're right, it's only the target area.
But I checked again and it's actually the barycentric area of each vertex, not each triangle.
I.e. the clustering will results in the specified number of vertices.

I also updated the docstring for this

barycentric_area : float, optional
The area of each triangle in the mesh, by default 1.0
smoothing : int, optional
Number of iterations for mesh smoothing, by default 10
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be helpful to define which smoothing algorithm is used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good point. It's Laplacian smoothing. I updated it in the docstring

point_indices[:, 0], point_indices[:, 1], point_indices[:, 2]
]
point_values = map_coordinates(
self.volume, points.T, order=1, mode="nearest"
Copy link
Contributor

Choose a reason for hiding this comment

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

How is the speed when doing linear interpolation? Does it still feel responsive? Do you think this should be an option? In any case, we can make that option later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For the demo example on my local computer, it still ran very smooth with the demo examples (higher order interpolations were very slow though). But yes, I guess for larger meshes, this can become problematic.
Would be good to have that as an option.

@kevinyamauchi
Copy link
Contributor

Hey @LorenzLamm , thanks for the updates. Is this ready to merge now?

Regarding the dependencies, I agree that long term, we should aim to depend on just one mesh library. I think it's okay to add the stuff from the pyvista/vtk ecosystem for now. We can work on unifying in a follow up PR.

@LorenzLamm
Copy link
Contributor Author

Hey @LorenzLamm , thanks for the updates. Is this ready to merge now?

Regarding the dependencies, I agree that long term, we should aim to depend on just one mesh library. I think it's okay to add the stuff from the pyvista/vtk ecosystem for now. We can work on unifying in a follow up PR.

Hey @kevinyamauchi ,
Yes, ready to merge, thanks! :)
And yes, let's discuss how to best unify and only use one library.

@kevinyamauchi kevinyamauchi merged commit 1b11e88 into cellcanvas:main Mar 30, 2024
10 checks passed
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