-
Notifications
You must be signed in to change notification settings - Fork 5
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
Conversation
@@ -163,11 +167,9 @@ def _get_valid_image_layers(self, combo_box) -> List[Image]: | |||
] | |||
|
|||
def get_point_colors(self, points): |
There was a problem hiding this comment.
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.
There was a problem hiding this 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.
src/surforama/io/mesh.py
Outdated
mask : np.ndarray | ||
A binary mask. | ||
barycentric_area : float, optional | ||
The area of each triangle in the mesh, by default 1.0 |
There was a problem hiding this comment.
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
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 |
There was a problem hiding this comment.
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
src/surforama/io/mesh.py
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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 , |
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 :)