SEG-MAT icon indicating copy to clipboard operation
SEG-MAT copied to clipboard

Is there a way to get the individual segments?

Open anikimmel opened this issue 1 year ago • 4 comments

Hello!

Is there a way to save the individual segments as separate meshes?

Thanks!

anikimmel avatar Mar 29 '24 15:03 anikimmel

Hi, you can amend this function, to output different meshes based on the face labels https://github.com/clinplayer/SEG-MAT/blob/400ee4d6901987606c542219ff93a2d3cc44c049/src/Decomposer.cpp#L35

You can also try to use the colors of the output mesh to categorize the face triangles, here is a simple code with Python. Note it is for obj and you can slightly change it to adapt the off format.

import numpy as np
import trimesh
def process_obj(filename):
    mesh = trimesh.load_mesh(filename)
    vertex_colors = np.array(mesh.visual.vertex_colors)
    vertex_colors = np.round(vertex_colors).astype(int)
    face_classes = []
    # For each face, finds its category id
    for face in mesh.faces:
        face_color = vertex_colors[face[0]]
        face_class = None
        for i, c in enumerate(face_classes):
            if np.array_equal(c, face_color):
                face_class = i
                break
        if face_class is None:
            face_classes.append(face_color)
            face_class = len(face_classes) - 1

clinplayer avatar Apr 01 '24 07:04 clinplayer

Awesome, thanks!

Also, does the qmat code have a command line interface? I can't seem to find one in the source.

anikimmel avatar Apr 15 '24 16:04 anikimmel

I'm afraid not. But you can download the source code provided by the author and convert it to command line interface

https://binwangthss.github.io/qmat/qmat.html

clinplayer avatar May 11 '24 03:05 clinplayer