Skip to content

Conversation

@anna-charlotte
Copy link
Contributor

@anna-charlotte anna-charlotte commented Feb 9, 2023

Goals:

Add display methods to PointCloud 3D and Mesh3D urls and the corresponding tensors. For the tensors, first add classes to store those in: VerticesAndFaces for mesh (to store vertices: AnyTensor, faces: AnyTensor), PointAndColors for point cloud (to store points: AnyTensor, colors: AnyTensor).

For PointCloud3D you can call .display() on its url or tensors:

doc = PointCloud3D(url='tests/toydata/tetrahedron.obj')
doc.tensors = doc.url.load(samples=10000)
doc.tensors.display()
# or via url
doc.url.display()

image

For Mesh3D you can call .display() on its url or tensors:

doc = Mesh3D(url='tests/toydata/tetrahedron.obj')
doc.tensors = doc.url.load()
doc.tensors.display()
# or via url
doc.url.display()

image

  • check and update documentation, if required. See guide

@anna-charlotte anna-charlotte changed the base branch from main to feat-rewrite-v2 February 9, 2023 07:56
@anna-charlotte anna-charlotte reopened this Feb 9, 2023
@anna-charlotte anna-charlotte mentioned this pull request Feb 9, 2023
47 tasks
@anna-charlotte
Copy link
Contributor Author

Problem with poetry:
To display a mesh, we need to install trimesh[easy] instead of only trimesh, because we need scipy and pyglet, too. There is a problem when adding this with poetry though, as the dependency scipy does not support the python versions 3.7 and 3.12:

Because scipy (1.10.0) requires Python <3.12,>=3.8

I guess therefore for now one needs to install trimesh[easy] via pip, such as we do for tensorflow as of right now, yes?

@anna-charlotte anna-charlotte requested review from JohannesMessner and samsja and removed request for samsja February 10, 2023 08:14
@anna-charlotte
Copy link
Contributor Author

After talking to @samsja we think that it would be nice to not have the .display() method on Document level, but rather type level, so that you call pc_doc.url.display() or pc_doc.tensor.display() instead of pc_doc.display(display_from='url'). For Image, Audio, Video this should work, since we have ImageTensor, ImageUrl and so on.
For Mesh3D however we don't have such a tensor type, and also the display depends on both vertices and face. Same goes for the pointcloud display, which depends on a vertices tensor and optional color tensor.
We could introduce documents for those instead of type, something like:

class VerticesAndFaces(BaseDocument):
    vertices: AnyTensor
    faces: AnyTensor

    def display():
        """display mesh from tensors"""

@JohannesMessner do you have any thought on this?

@github-actions github-actions bot added size/m and removed size/l labels Feb 10, 2023
@anna-charlotte anna-charlotte marked this pull request as ready for review February 10, 2023 14:08
@JohannesMessner
Copy link
Member

After talking to @samsja we think that it would be nice to not have the .display() method on Document level, but rather type level, so that you call pc_doc.url.display() or pc_doc.tensor.display() instead of pc_doc.display(display_from='url'). For Image, Audio, Video this should work, since we have ImageTensor, ImageUrl and so on. For Mesh3D however we don't have such a tensor type, and also the display depends on both vertices and face. Same goes for the pointcloud display, which depends on a vertices tensor and optional color tensor. We could introduce documents for those instead of type, something like:

class VerticesAndFaces(BaseDocument):
    vertices: AnyTensor
    faces: AnyTensor

    def display():
        """display mesh from tensors"""

@JohannesMessner do you have any thought on this?

fully agree with putting it at the type level.

I am not 100% convinced with having "magic" documents such as VerticesAndFaces that add display, but probably it's the only way, right?

return Mesh3DLoadResult(vertices=vertices, faces=faces)
return VerticesAndFaces(vertices=vertices, faces=faces)

def display(self) -> None:
Copy link
Member

Choose a reason for hiding this comment

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

url.display feels a bit weird to me, because in this case it doesn't really display the url, it displays the thing the url points to.
And to do that, it has to load from that url under the hood.

So is it necessary to expose this? Why not url.load().display()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah i see your point, but its not quite the same, when displaying it from url as it is now, we can display it with color because we just call .show() on the trimesh instance. For url.load().display() we extract the vertices and faces information but as of right now there is no way to extract the color information. Therefore this displays without colors. I think it would be nice to keep the color display if url content includes this information.
What do you think?

Copy link
Member

Choose a reason for hiding this comment

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

but this is true that it is weird to display some data (the color) that we cannot load in our tools

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes true, can be a bit misleading or confusing, too. do u suggest to remove it then for the url, and do the url.load().display() if someone doesn't want to load it into the tensors? I think this won't change on trimesh side any time soon, to easily extract color information.

Copy link
Member

Choose a reason for hiding this comment

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

let me think about it

Copy link
Member

Choose a reason for hiding this comment

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

so what's the conclusion here? keep it as it is? I see the point of being able to show colors, so I don't have a strong opinion anymore

Copy link
Member

Choose a reason for hiding this comment

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

@anna-charlotte what did you decided ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would keep it like this, for the colors and also to have the display method for all urls

@anna-charlotte anna-charlotte linked an issue Feb 13, 2023 that may be closed by this pull request
2 tasks
Signed-off-by: anna-charlotte <[email protected]>
anna-charlotte added 16 commits February 15, 2023 16:18
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Signed-off-by: anna-charlotte <[email protected]>
Plot mesh in notebook from url.
This loads the Trimesh instance of the 3D mesh, and then displays it.
"""
from IPython.display import display
Copy link
Member

Choose a reason for hiding this comment

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

what ahppened if we are not inside IPython ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think for mesh and point cloud it would still open a pyglet window and display it, but for the other IPython displays it would just print something like '< IPython.display.Audio obj >'.

anna-charlotte added 2 commits February 15, 2023 16:41
@github-actions
Copy link

📝 Docs are deployed on https://ft-feat-display-mesh-v2--jina-docs.netlify.app 🎉

@anna-charlotte anna-charlotte merged commit 96cd383 into feat-rewrite-v2 Feb 16, 2023
@anna-charlotte anna-charlotte deleted the feat-display-mesh-v2 branch February 16, 2023 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

v2: plot image, video, audio, mesh

4 participants