# Solving problem with duplicate vertices in obj mesh in OpenMesh

When apply Hole closing filter in Meshlab duplicate vertices can occur.

I have told about this filter in this post. Here we will see what problems can occur due to the presence of duplicate vertices in obj file and how we can fix it using MeshLab.

Let’s test on simple example. Create obj file with following content

`v 0 0 0 v 1 0 0 v 0 1 0 v 1 1 0 f 0 1 2 f 1 2 3`

Now create a script test_duplicates.py

import openmesh as om import numpy as npmesh_3 = om.read_trimesh('duplicate_vert_test.obj') print('Test duplicate vertices') for i, vh in enumerate(mesh_3.vertices()):

print('Vertices adjacent to vertex ', i)

for vh_n in mesh_3.vv(vh):

print(vh_n.idx())

Run it

`Vertices adjacent to vertex 0 2 1 Vertices adjacent to vertex 1 0 2 Vertices adjacent to vertex 2 1 0 Vertices adjacent to vertex 3`

Vertices adjacent to vertex 4

Now add duplicate

`v 0 0 0 v 1 0 0 v 0 1 0 v 1 1 0 v 1 0 0 f 0 1 2 f 4 2 3`

And run script:

`Vertices adjacent to vertex 0 Vertices adjacent to vertex 1 3 2`

Vertices adjacent to vertex 2 1 3 Vertices adjacent to vertex 3 2 1

Vertices adjacent to vertex 4

No adjacent vertices found for vertex 0. However vertex with index 3 get two adjacent vertices 2 and 1.

## Remove vertex duplicates in MeshLab

Here I will show how to remove duplicates on another mesh with more evident artifacts.

Import mesh with duplicate vertices

You can see many colored triangles. Let’s apply special filter to remove duplicate vertices in mesh.

Filters -> Cleaning and Repairing -> Remove duplicate Vertices

Result

When apply this filter on our initial simple test obj we will get following obj file content

`vn 0.000000 -nan(ind) 0.000000 v 0.000000 0.000000 0.000000 vn 0.000000 0.000000 -0.785398 v 1.000000 0.000000 0.000000 vn 0.000000 0.000000 -0.785398 v 0.000000 1.000000 0.000000 vn 0.000000 0.000000 -1.570796 v 1.000000 1.000000 0.000000 # 4 vertices, 0 vertices normals f 4//4 2//2 3//3 # 1 faces, 0 coords texture`

This time output will be:

`Vertices adjacent to vertex 0 Vertices adjacent to vertex 1 3 2 Vertices adjacent to vertex 2 1 3 Vertices adjacent to vertex 3 2 1`

At least we have only 4 vertices and only vertex 3 is associated with a face.