marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.05k stars 266 forks source link

How to show the face orientation? #532

Closed LogWell closed 2 years ago

LogWell commented 2 years ago

Left: in Blender, Right: in MeshLab image

marcomusy commented 2 years ago

Try

mymesh.print()
n = mymesh.celldata["Normals"] # whatever the name is
pts = mymesh.cellCenters()
arrs = Arrows(pts, pts+n*10)
show(mymesh, arrs)

Useful methods: mymesh.computeNormals(cells=True) mymesh.reverse()

LogWell commented 2 years ago

Here is the solution:

mymesh.c((200, 200, 200))
mymesh.bc((255, 0, 0))

image

BTY: how to get the actual number of vertices in vedo?

marcomusy commented 2 years ago

it's simply mymesh.NPoints().

LogWell commented 2 years ago

In many cases, NPoints = NCells * 3, how can I get a result like openmesh?

    mesh_om = om.read_trimesh(path_mesh)
    print(mesh_om.n_vertices())  # 49998
    print(mesh_om.n_faces())  # 100024

    mesh_vedo = load(path_mesh)
    print(mesh_vedo.NPoints())  # 300072 = 100024*3
    print(mesh_vedo.NCells())  # 100024
LogWell commented 2 years ago

In fact, the problem is how to get the real number starting with "v" stored in the obj file.

Of course, I can also use with open to read and get the length, but there will be one more read operation:

data_v = []
with open(path_mesh, "r") as fp:
    for line in fp:
        if line.startswith("#"):
            continue

        values = line.split()
        if not values:
            continue

        if values[0] == "v":
            data_v.append(list(map(float, values[1:4])))
data_v = np.array(data_v)
num_v = data_v.shape[0]

This issue may be a bit related.

marcomusy commented 2 years ago

yes - indeed if you add mesh1.clean() you should get the 49998 vertices.