ranahanocka / MeshCNN

Convolutional Neural Network for 3D meshes in PyTorch
MIT License
1.56k stars 314 forks source link

About the function "__get_invalids" #43

Open liangqianqian123 opened 4 years ago

liangqianqian123 commented 4 years ago

Could you please explain the function "get_invalids" which is defined in file "mesh_pool.py"? I want to know what will happen after these operations? " MeshPool.redirect_edges(mesh, edge_id, side, update_key_a, update_side_a) MeshPool.redirect_edges(mesh, edge_id, side + 1, update_key_b, update_side_b) MeshPool.redirect_edges(mesh, update_key_a, MeshPool.get_other_side(update_side_a), update_key_b, MeshPool.get_other_side(update_side_b)) MeshPool.union_groups(mesh, edge_groups, key_a, edge_id) MeshPool.union_groups(mesh, edge_groups, key_b, edge_id) MeshPool.union_groups(mesh, edge_groups, key_a, update_key_a) MeshPool.__union_groups(mesh, edge_groups, middle_edge, update_key_a) MeshPool.union_groups(mesh, edge_groups, key_b, update_key_b) MeshPool.__union_groups(mesh, edge_groups, middle_edge, update_key_b) " Thank you very much!

ranahanocka commented 4 years ago

Hi @liangqianqian123 ,

When encountering "bad" (valence 3) vertices (aka "invalids"), we clean them if possible. The issue is that these "valence 3" vertices cause many edges to be unable to be collapsed. See this illustration, on the left is a valid edge collapse, on the right is a collapse which results in a non-manifold geometry: image When we encounter such a vertex we clean it.

chengzg commented 4 years ago

@ranahanocka , Thanks for the reply. I also encounter a problem about the invalid edges. In my case, the __remove_triplete get asserted after getting the invalid_edges. The invalid_edges = [3534, 3547, 3543].

  def __remove_triplete(mesh, mask, edge_groups, invalid_edges):
        vertex = set(mesh.edges[invalid_edges[0]])
        for edge_key in invalid_edges:
            vertex &= set(mesh.edges[edge_key])
            mask[edge_key] = False
            MeshPool.__remove_group(mesh, edge_groups, edge_key)
        mesh.edges_count -= 3
        vertex = list(vertex)
        assert(len(vertex) == 1)

The assert(len(vertex) ==1) is triggered. I debugged a little bit is that: it seems it is caused by wrong neighbour information. The label information is as below: edge id: gemm_edge 3534 [3547 3543 3547 3543] 3543 [3547 3534 3547 3534] 3547 [3543 3534 3543 3534]

Have you encounter this problem before? What could be the reason and any recommendation to solve the problem?

Thanks & Regards, Spencer

chengzg commented 4 years ago

@ranahanocka , I found the answer from https://github.com/ranahanocka/MeshCNN/issues/7, so it is caused due to a very small connected but isolated component. Do you have any idea that how we can solve it in programming way?

ranahanocka commented 4 years ago

Hi @chengzg ,

You can remove small connected components using meshlab (via scripting).

chengzg commented 4 years ago

Hi @ranahanocka ,

Thanks very much for your reply.

I am thinking of solving the problem in MeshCNN code. For example, in the scenario mentioned above, i could delete the whole triangle or adding another array to reduce its priority to be collapsed. Do you think will it work?

Also you added the assert there, it must be some reason. May i know what problem you have experienced before?

Thanks & Regards, Spencer

ranahanocka commented 4 years ago

Hi @chengzg ,

It is certainly possible, but it is more complicated. I believe meshlab is an easier approach. Here is a script which will do it

<!DOCTYPE FilterScript>
<FilterScript>
 <filter name="Remove Isolated pieces (wrt Face Num.)">
  <Param type="RichInt" value="25" name="MinComponentSize"/>
 </filter>
 <filter name="Remove Unreferenced Vertex"/>
</FilterScript>

You need to save that to a file and call it something that ends with .mlx, for example remove_island.mlx. Also, install meshlab and then you can call it from the command line:

meshlabserver -i cube.obj -s remove_island.mlx -o cube_out.obj

where cube.obj is the input file and cube_out.obj is the output file.

ranahanocka commented 4 years ago

Also you added the assert there, it must be some reason. May i know what problem you have experienced before?

So if the smallest connected component (a pyramid object) cannot have any more edges removed. It is the smallest genus-0 primitive that exists. Basically, removing an edge on this small object will result in non-manifold geometry.

chengzg commented 4 years ago

@ranahanocka ,

Again thanks very much for your reply.

Thanks & Regards, Spencer