-
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
Add mesh 3d #376
Add mesh 3d #376
Conversation
@g5t would be great if you could also give this a go, to see if it does what you want. |
"source": [ | ||
"## Creating a mesh plot\n", | ||
"\n", | ||
"We can now send the data to the `mesh3d` function for rendering (we color the mesh according to z position):" |
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.
Can you make mesh3d
a link to the function?
edgecolor: str | None = None, | ||
artist_number: int = 0, | ||
): | ||
import pythreejs as p3 |
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.
What if pythreejs is not installed or python is not running in Jupyter? Does the backend manager raise an appropriate exception or does this need to happen here?
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.
No idea. It's the same in scatter3d
.
I don't think it's an issue not running in Jupyter, as the unit tests pass fine.
If it's not installed, you will just get ImportError
on pythreejs
?
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.
If it's not installed, you will just get ImportError on pythreejs?
I would assume so. Maybe this is something that the backend manager can catch so we don't have to handle it in everywhere. But that is unrelated to this PR.
self._data.coords["y"].values.astype('float32', copy=False), | ||
self._data.coords["z"].values.astype('float32', copy=False), | ||
] | ||
).T |
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.
Don't know what size of mesh this can or should support. But you could avoid extra copies here by not taking x,y,z apart into separate variables. Instead, you could use
p3.BufferAttribute(positions.values.astype('float32', copy=False))
(copy=False
doesn't do anything here because the positions vector is always float64
.)
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 split up the coordinates because I wanted the mesh3dfigure to behave a bit like scatter3dfigure
, with checking the units of the x,y,z coordinates and setting the axis labels.
I guess I could keep the vector vertices also in the data and use that directly if they are present (fallback to the x,y,z if a vector coord is not found)? That would maybe only make 1 copy instead of 2? It would be a slightly strange interface/convention, but maybe the reduced cost is worth it?
# TODO: for now we only update the colors of the mesh. Updating the positions | ||
# of the vertices is doable but is made more complicated by the edges geometry, | ||
# whose positions cannot just be updated. A new geometry and edge lines would | ||
# have to be created, the old one removed from the scene and the new one added. |
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.
It doesn't looks like update
changes the colours to me. That is what set_colors
does. So could update
simply raise an exception instead.
As it stands, this could hide errors.
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.
It's true that the colors are not changed. However, the values of the ._data
should be updated, because this is what the colormapper
uses to determine the colorbar range. So it should not raise, but I will update the comment.
"source": [ | ||
"## Loading mesh data\n", | ||
"\n", | ||
"We load a file containing the data to construct the [Utah teapot](https://en.wikipedia.org/wiki/Utah_teapot)." |
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.
Can you explain the data format? It is not obvious to me how to encode vertices and faces.
Co-authored-by: Jan-Lukas Wynen <jan-lukas.wynen@ess.eu>
This adds a plot that can take in a list of vertices and faces and construct a 3D mesh.
This opens the way for representing full instrument geometries in 3D.
Notes:
For now we only support vertex colors, we could add face colors in the future.
This also supports showing only a single mesh at a time, unlike the scatter3d plot who can take in a dict of data arrays.
Supersedes #346