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

color per triangle? #6060

Closed
3 tasks done
cwreynolds opened this issue Apr 4, 2023 · 4 comments
Closed
3 tasks done

color per triangle? #6060

cwreynolds opened this issue Apr 4, 2023 · 4 comments
Labels

Comments

@cwreynolds
Copy link

Checklist

My Question

(I may not understand the second question above, but I think I am running the most recent released version: Open3D 0.17.0, Python 3.10.10, macOS 12.6.3)

For a diagram-like rendering, I would like to use color per triangle instead of interpolated color per vertex (via open3d.geometry.TriangleMesh.vertex_colors). But this comment suggests per-triangle support was added to Open3D by December 2021. If so, I am unable to get it to run. This Python test code:

import open3d as o3d
import numpy as np

def face_color_test():
    mesh = o3d.geometry.TriangleMesh.create_octahedron()
    rgb = [[0,0,0],[0,0,1],[0,1,0],[0,1,1],[1,0,0],[1,0,1],[1,1,0],[1,1,1]]
    # face_colors = o3d.utility.Vector3dVector(np.array(rgb, np.float32))
    face_colors = o3d.utility.Vector3iVector(np.array(rgb, np.int32))
    mesh.triangles["colors"] = face_colors
    vis = o3d.visualization.Visualizer()
    vis.create_window()
    vis.add_geometry(mesh)
    vis.run()
    vis.destroy_window()

gets an error on mesh.triangles["colors"] = face_colors:

Traceback (most recent call last):
  File "/Users/cwr/Documents/code/flock/flock.py", line 158, in <module>
    face_color_test()
  File "/Users/cwr/Documents/code/flock/flock.py", line 133, in face_color_test
    mesh.triangles["colors"] = face_colors
TypeError: __setitem__(): incompatible function arguments. The following argument types are supported:
    1. (self: open3d.cpu.pybind.utility.Vector3iVector, arg0: int, arg1: numpy.ndarray[numpy.int32[3, 1]]) -> None
    2. (self: open3d.cpu.pybind.utility.Vector3iVector, arg0: slice, arg1: open3d.cpu.pybind.utility.Vector3iVector) -> None

I am currently using one of the workarounds discussed on that earlier Issue. But if there is a supported way to apply face colors directly I would prefer to use that. Any suggestions? Is this feature mentioned in the documentation? I have failed to find it, and the keywords (triangles, colors) are too common for searching.

(I would expect the color data to be rgb triples of floats, but changed it from Vector3dVector to Vector3iVector based on the error message. I also tried o3d.core.Tensor(...) as suggested in the previous Issue, but got the same error.)

@cwreynolds
Copy link
Author

Since all I know about this feature is from a comment by @errissa I tag them here in case they want to comment.

@lucagrementieri
Copy link

The property triangle cited in the comment exists for the object open3d.t.geometry.TriangleMesh based on tensors, see http://www.open3d.org/docs/release/python_api/open3d.t.geometry.TriangleMesh.html#open3d.t.geometry.TriangleMesh

In you example, you are using the legacy TriangleMesh that has no support for colors on faces.

@cwreynolds
Copy link
Author

Thanks @lucagrementieri — just a few days ago I discovered the “t”/“tensor” subworld of Open3D, via experimenting with o3d.visualization.draw(). I made the connection with this question, thinking I should update/close it. Thanks for the reminder.

I would suggest that there is a bigger problem in the docs and sample code. After I started to understand the “t”/“legacy” distinction I looked for a description of that distinction and failed. (Similarly the doc for o3d.visualization.draw() is almost nonexistent, as mentioned here: #6094 ) As you indicate there is doc on (say)
open3d.geometry.TriangleMesh and open3d.t.geometry.TriangleMesh but no “narrative” on why both exist, nor when you should use either.

My intuition is that the “legacy” code is deprecated and that all new development has been on o3d.visualization.draw() and the tensor classes. However, all of the “getting started” docs and sample code talk about the legacy API. This steers new users astray and leads to the sort of confusion seen in this issue (#6060).

@cwreynolds
Copy link
Author

(This issue of legacy-vs-tensor confusion came up a day later here: #6130)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants