mikedh / trimesh

Python library for loading and using triangular meshes.
https://trimesh.org
MIT License
3.03k stars 583 forks source link

`trimesh.points.PointCloud` is not displayed on colab/jupyter notebook #1198

Open Conchylicultor opened 3 years ago

Conchylicultor commented 3 years ago

Reproduction instruction: https://colab.research.google.com/drive/1XU6z7ni3bTjoCU-LUxbpekGcCzYFEeiI?authuser=1#scrollTo=BFRvA_GLVcS4

import numpy as np
import trimesh

print(trimesh.__version__)

v = np.random.random((1000,3))
p = trimesh.points.PointCloud(v)

s = trimesh.Scene()
s.add_geometry(trimesh.creation.axis())
s.add_geometry(p)
s.show()  # << Point cloud not displayed

The above code works well locally, but on colab/jupyter, only a black screen is displayed instead of the scene. Is there a workaround ?

(side question): Is there a way to customize the display of the points in addition of the color (e.g. size, square shape,...) ?

Antyos commented 3 years ago

Duplicate of #946.

playertr commented 3 years ago

Point cloud visualization is working for me on Jupyter (rendered through VSCode on a remote machine), but the points are nearly impossible to see with the default white background because they are colored white.

Default result:

Screen Shot 2021-08-11 at 3 50 54 PM

Modified result:

Screen Shot 2021-08-11 at 3 57 02 PM

And here's the modification to color the cloud black:

import numpy as np
import trimesh

print(trimesh.__version__)

v = np.random.random((1000,3))
p = trimesh.points.PointCloud(v, colors=np.tile(np.array([0, 0, 0, 1]), (len(v), 1)))

s = trimesh.Scene()
s.add_geometry(trimesh.creation.axis())
s.add_geometry(p)
s.show()
anna-charlotte commented 2 years ago

I encountered the same problem:

from IPython.display import display

pc = trimesh.points.PointCloud(vertices=self.tensor)
display(pc.show())

In a notebook, the point cloud does not appear.

damienallen commented 1 year ago

Thanks to @playertr, I was able to visualize the points albeit at an unworkable size.

I took a look at how the scene is bundled into a THREE.js compatible binary and came to the conclusion that a proper fix would not be very straightforward due to how materials are handled in the export to GLTF. Properties like size and sizeAttenuation do not seem available to the default PBRMaterial class used by trimesh.

Thus, I relied on a workaround of visualizing the points as spheres:

import trimesh
import numpy as np

def points_to_spheres(points, radius=1):
    """
    Convert points into spheres for notebook-friendly display
    """
    return [
        trimesh.primitives.Sphere(radius=radius, center=pt) for pt in points
    ]

# Similar example as above
v = np.random.random((1000,3))
p = points_to_spheres(v, radius=0.01)

s = trimesh.Scene()
s.add_geometry(trimesh.creation.axis())
s.add_geometry(p)
s.show()

Of course, this can be a one-liner instead of a function and you may still want to tweak things like color.


Result:

image