mkazhdan / TextureSignalProcessing

Gradient-Domain Processing within a Texture Atlas
69 stars 13 forks source link

[EXCEPTION] InitializeGridChartsActiveNodes: Node ( 24 , 70 ) covered by two triangles: 27732 27731 #14

Closed niyunsheng closed 2 years ago

niyunsheng commented 2 years ago

When I using the TextureStitching application, I got the [EXCEPTION]:

[EXCEPTION] InitializeGridChartsActiveNodes: Node ( 24 , 70 ) covered by two triangles: 27732 27731

I noticed the similar issus: https://github.com/mkazhdan/TextureSignalProcessing/issues/11. But my question doesn't seem like the watertight problem.

The coordinate points and visualization diagram of the two triangles are as follows:

[27731]:  31133 47205 31134
[27732]:  31134 47205 14397

error

Thanks for any help.

mkazhdan commented 2 years ago

Would you be able to provide:

  1. The 3D coordinates of the vertices 14397, 31133, 31134, 47205.
  2. The 2D texture coordinates for the same vertices. It seems like you have two triangles whose image in texture coordinate space overlap the same (discrete) texture coordinate.
niyunsheng commented 2 years ago

The texture coordinates of the two triangles are as follows, while 3 followed by the coordinate id and 6 followd by the each texture coordinates

[27731]:  3 31133 47205 31134 6 0.188872 0.931736 0.190389 0.931257 0.189103 0.933672 
[27732]:  3 31134 47205 14397 6 0.189103 0.933672 0.190389 0.931257 0.190075 0.933559 

The 3D coordinates of the verices are as follows:

[14397]: 57.0999 15.2552 60.5664 
[31133]: 59.0817 13.5186 57.0087 
[31134]: 60.0602 13.5186 60.5664 
[47205]: 53.4949 17.0764 53.4509 

Thanks for your reply.

I visualized the texture coordinates on the mask map. It seems that they do not coincide. The length and width of the image are 4096, and the coordinates I visualize are:

verice id 3D coordinates texture coordinates texture coordinates (int)
14397 57.0999 15.2552 60.5664 0.190075, 0.933559 778, 3823
31133 59.0817 13.5186 57.0087 0.188872, 0.931736 773, 3816
31134 60.0602 13.5186 60.5664 0.189103, 0.933672 774, 3824
47205 53.4949 17.0764 53.4509 0.190389, 0.931257 779, 3814

coor

mkazhdan commented 2 years ago

Thanks. Out of curiosity, what do you mean by "texture coordinates (int)"? When I multiply the texture coordinates by 4096, I don't get an integer.

If I had to guess, the problem might be due to the fact that, in texture space, the line segment through vertices 31134 and 47205 goes exactly through an integer coordinate, making the code confused about which triangle "owns" that texel.

So you still get the error if you jitter the texture coordinates a tiny bit?

niyunsheng commented 2 years ago

Sorry, "texture coordinates (int)" meaning "texture coordinates" multipy by 4096 and converted to int type. I made several wrong figures and have corrected them now in upper comments.

Thanks for your reply, I using --jitter in the command line and get the same error message.

I also print out intermediate results in the function InitializeHierarchy and structure TexturedMesh< GeometryReal > mesh / AtlasMesh< GeometryReal > atlasMesh / std::vector< AtlasChart< GeometryReal > > atlasCharts.

triangles_id 27731 27732
mesh.triangles[triangles_id] 31133 47205 31134 31134 47205 14397
atlasMesh.triangles[triangles_id] 31811 31812 31813 31813 31812 14600
atlasMesh.vertexMap[atlasMesh.triangles[triangles_id][0..2]] 31133 47205 31134 31134 47205 14397
atlasMesh.triangleChartIndex[triangles_id] 38 38
atlasCharts[38].meshVertexIndices[atlasCharts[38].triangles[t][0..2]] 31133 47205 31134 31134 47205 252

In addition, I I found the vertex and texture coordinates of 252:

verice id 3D coordinates texture coordinates texture coordinates (int)
252 53.5422 0.43647 49.8931 0.186364 0.921429 763, 3774
niyunsheng commented 2 years ago

As a supplement, I found that two triangles with the same vertex belong to different charts. The details are as follows:

triangles_id 10162 27732
atlasCharts chartID 932 38
verice ids 14395 14396 14397 31134 47205 14397

The two triangles in the mesh is

27732_10162

And the Related 3D and texture coordinates is

verice id 3D coordinates texture coordinates texture coordinates (int)
14395 53.5422 15.4348 64.1242 0.190907 0.936615 781, 3836
14396 57.0999 14.5667 64.1242 0.190087 0.936159 778, 3834
14397 57.0999 15.2552 60.5664 0.190075 0.933559 778, 3823
31134 60.0602 13.5186 60.5664 0.189103 0.933672 774, 3824
47205 53.4949 17.0764 53.4509 0.190389 0.931257 779, 3814

And the texture coordinates I visualized in the mask image is:

niyunsheng commented 2 years ago

I have made some new discoveries and found the reason why two triangles do not belong to a same chart.

The vertex with 3d coordinates 57.0999 15.2552 60.5664 are divided into three vertices after uv expansion: 14397/36323/46730.

The five triangles are visualized in the following figure.

The two triangles 10162/27732 are not neighbours, so they are divided into different charts.

Do you know what the problem is? Is it the uv unfolding problem? Can your program TextureStitching handle this situation?

niyunsheng commented 2 years ago

This problem is "manifold vertices" and I can using MeshLab to repaire it. Is this the best solution ?

mkazhdan commented 2 years ago

The fact of a non-manifold vertex, belonging to 10162 and 27732, but separated by 35734, 10163, and 27768, could definitely be causing a problem.

I think the fix would be assigning a separate texture coordinate to the corner associated to vertex 14397 so you get four charts meeting at that corner instead of three. Not sure if MeshLab can help with that.

niyunsheng commented 2 years ago

Thanks, I finally repair the mesh using MeshLab, now it works. Thanks for your great job!

niyunsheng commented 2 years ago

There are some questions remaining: The warning [[WARNING] InitializeMassAndStiffness: Zero row at index 33498. Try running with jittering.] occurs sometimes even using --jitter. What is puzzling is that this warning sometimes appears and sometimes does not appear. Do you know why ?

mkazhdan commented 2 years ago

My guess is it's a numerical precision issue that can be affected by the parallelism. If you ran the code with just one thread, I would guess the results would be consistent.

niyunsheng commented 2 years ago

The warning appears sometimes even using --threads 1. Do you have any other suggestions? Thank you.