CGAL / cgal

The public CGAL repository, see the README below
https://github.com/CGAL/cgal#readme
Other
4.99k stars 1.39k forks source link

Is the CGAL ability to simplify the texture? #4385

Closed KeepFaithMe closed 4 years ago

KeepFaithMe commented 4 years ago

Please use the following template to help us solving your issue.

Issue Details

I use the CGAL to simplify the mesh,and the mesh contains the texture coordinates.When I execute the process of simplifying the mesh,the geometric vertex changed,at the same time, I need the texture coordinayes to change in order to fit my geometric vertex . Whether there is a method to handle it??

Source Code

If your issue arises by using CGAL in your own source code, please provide a minimalist example that we can compile easily to reproduce the bug. If your issue arises from using a CGAL program (demo, example, etc.), please let us know which one. Helping you solving an issue is much easier and efficient if we can reproduce it.

Environment

sloriot commented 4 years ago

There is nothing working out-of-the-box but as pointed out by @maxGimeno here, you can use a uv-map per vertex and even track what happened using the visitor concept like in this example.

simonasdmd commented 4 years ago

@KeepFaithMe Hello, have you solved your problem? Now I have this problem

KeepFaithMe commented 4 years ago

The cgal can't handle this problem,can you show your problem detailed?

------------------ 原始邮件 ------------------ 发件人: "simonasdmd"<notifications@github.com>; 发送时间: 2020年1月8日(星期三) 上午9:50 收件人: "CGAL/cgal"<cgal@noreply.github.com>; 抄送: "张川"<1071244263@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [CGAL/cgal] Is the CGAL ability to simplify the texture? (#4385)

@KeepFaithMe Hello, have you solved your problem? Now I have this problem

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

simonasdmd commented 4 years ago

The cgal can't handle this problem,can you show your problem detailed? ------------------ 原始邮件 ------------------ 发件人: "simonasdmd"<notifications@github.com>; 发送时间: 2020年1月8日(星期三) 上午9:50 收件人: "CGAL/cgal"<cgal@noreply.github.com>; 抄送: "张川"<1071244263@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [CGAL/cgal] Is the CGAL ability to simplify the texture? (#4385) @KeepFaithMe Hello, have you solved your problem? Now I have this problem — You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

@KeepFaithMe
I want to simplify the model with texture mapping. But CGAL only simplifies the vertex mesh. There is no processing of the texture.

sloriot commented 4 years ago

The cgal can't handle this problem,can you show your problem detailed?

That's not what I said. You do have access to the two vertices being merged before it is done thanks to the visitor. That way you can apply the operation that is relevant for your application on the texture map.

simonasdmd commented 4 years ago

@sloriot hi~ You mean to store two copies of vertex and texture coordinates. Then use "SMS:: edge_collapse" to simplify. And put them together?

sloriot commented 4 years ago

Maybe I did not understand the initial question. I thought that the question was "how to simplify a texture while simplifying a mesh".

simonasdmd commented 4 years ago

@sloriot Your understanding is correct

sloriot commented 4 years ago

Then look at my initial comment about the visitor. The doc is linked and it should be easy to give it a try.

simonasdmd commented 4 years ago

@sloriot I want to simplify an obj file with textures. However, the current process of reading "surface" and then using "SMS:: edge" collapse "does not deal with the texture. Please tell me how to do this. I read the link, but I didn't get useful information. Can I mark it if I can. Thank you very much for your help.

sloriot commented 4 years ago

The first step to to get the UV map (i.e. the 2D parameterization) of the texture at each vertex of the input mesh. Then using the visitor upon the merge, you can update the value in the UV map for the vertex kept.

KeepFaithMe commented 4 years ago

there is a paper named Simplifying Surfaces with Color and Texture using Quadric Error Metrics,You can reade it,and the algorithm is in the vcglib,you can use the lib simplify you mesh with texture.

------------------ 原始邮件 ------------------ 发件人: "simonasdmd"<notifications@github.com>; 发送时间: 2020年1月8日(星期三) 下午2:33 收件人: "CGAL/cgal"<cgal@noreply.github.com>; 抄送: "张川"<1071244263@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [CGAL/cgal] Is the CGAL ability to simplify the texture? (#4385)

@sloriot I want to simplify an obj file with textures. However, the current process of reading "surface" and then using "SMS:: edge" collapse "does not deal with the texture. Please tell me how to do this. I read the link, but I didn't get useful information. Can I mark it if I can. Thank you very much for your help.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

simonasdmd commented 4 years ago

@KeepFaithMe Have you implemented it with vcglib

simonasdmd commented 4 years ago

@sloriot I see what you mean.

  1. Save the UV coordinates of each vertex according to the vertex (this is easy)
  2. After simplifying the vertices. Find the UVs of the remaining vertices according to the correspondence of the first step. (but there is a problem here. Some vertices are recalculated. They have no corresponding UV)
sloriot commented 4 years ago

That's where the visitor comes in. I assume you have a mapping vertex -> UV. The simplification works by collapsing edges, meaning at each step two vertices get merged, only one being kept (and it s point coordinate being updated). Using the visitor, you have access to the two points being merged, the one kept and the updated coordinates (called placement). Then you can update the UV map of the vertex kept before each collapse and maintain the texture mapping.

simonasdmd commented 4 years ago

@sloriot I understand the process. Last question. How to use visitor. Is it in the process of "SMS:: edge_collapse"? If you can take a screenshot and say the additional location or example.

KeepFaithMe commented 4 years ago

the vcglib implement this algorithm,you can use it directly

------------------ 原始邮件 ------------------ 发件人: "simonasdmd"<notifications@github.com>; 发送时间: 2020年1月8日(星期三) 下午3:06 收件人: "CGAL/cgal"<cgal@noreply.github.com>; 抄送: "张川"<1071244263@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [CGAL/cgal] Is the CGAL ability to simplify the texture? (#4385)

@KeepFaithMe Have you implemented it with vcglib

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

simonasdmd commented 4 years ago

@KeepFaithMe I haven't used vcglib. I still want to use CGAL if possible. Can you provide your process code? I want to use it as a reference. thank you very much.

KeepFaithMe commented 4 years ago

firstly CGAL can't handle this problem you have met,secondly the vcglib have examples which you can see .

------------------ 原始邮件 ------------------ 发件人: "simonasdmd"<notifications@github.com>; 发送时间: 2020年1月8日(星期三) 下午3:30 收件人: "CGAL/cgal"<cgal@noreply.github.com>; 抄送: "张川"<1071244263@qq.com>;"Mention"<mention@noreply.github.com>; 主题: Re: [CGAL/cgal] Is the CGAL ability to simplify the texture? (#4385)

@KeepFaithMe I haven't used vcglib. I still want to use CGAL if possible. Can you provide your process code? I want to use it as a reference. thank you very much.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub, or unsubscribe.

sloriot commented 4 years ago

@sloriot I understand the process. Last question. How to use visitor. Is it in the process of "SMS:: edge_collapse"? If you can take a screenshot and say the additional location or example.

See this example. I would say you only need to implement the OnCollapsed(profile, placement) function (you can remove the other one as default will be inherited). The vertices to be collapsed can be found in the profile.

simonasdmd commented 4 years ago

@sloriot I didn't find a place to call in this example. I don't know when to judge the use of it.

image

afabri commented 4 years ago

Have a look at the gist

It is simplisitc in the sense that I just take the midpoint of the uv-values of the two vertices that get collapsed, but it illustrates what Sébastien had in mind.

This could be a nice topic for CGAL@GSoC2020

simonasdmd commented 4 years ago

@afabri I can't access your link. Can you take a screenshot.

afabri commented 4 years ago

It'is public and on github. You can also git clone it https://gist.github.com/717c64e84f248a1c78cfdfbadd9eb9f9.git

simonasdmd commented 4 years ago

@afabri @sloriot @KeepFaithMe @MaelRL I have to try. None of the cases we discussed before are feasible. Because we have to put the case on the premise that "a vertex corresponds to a texture coordinate (one-to-one relationship)", but in fact, a vertex has multiple different texture coordinates.

This is an example of 3DMAX export.

image

afabri commented 4 years ago

Maybe have a look at the section Cutting a Mesh in the manual. There we associate the uv-value to a halfedge (the target vertex). It won't solve your problem out of the box, but at least it illustrates how we deal with several uv-coordinates for the "same" vertex.

maxGimeno commented 4 years ago

@afabri This is also how I implemented the ply version of surface_mesh for saving textured meshes. here is an example of how to add these properties to a SM

simonasdmd commented 4 years ago

CGAL does not read 'VT' for obj

image

After I simplify the triangulation, I don't know how to operate it.

image

maxGimeno commented 4 years ago

CGAL does not read 'VT' for obj

Indeed, we use ply for meshes with UVs.

simonasdmd commented 4 years ago

hi @maxGimeno I don't think CGAL should be limited to ply. Obj has a wider scope. Can we support it later?

maxGimeno commented 4 years ago

Sure, just fill a feature request

afabri commented 4 years ago

Sure, just fill a feature request

or develop and contribute, or pay for the development, in case it is important for your business.