MeshLib icon indicating copy to clipboard operation
MeshLib copied to clipboard

curve offset on the surface

Open czc98 opened this issue 1 year ago • 19 comments

Hi, I found that Meshlib has the concept of offset, but it applies to mesh. I have a curve made of a series of points, and that curve is attached to the Mesh surface. Does Meshlib have any methods to implement the effect shown in the image? image.

czc98 avatar Oct 17 '23 14:10 czc98

Hello! Can you please show what is desired input and output?

Grantim avatar Oct 17 '23 14:10 Grantim

The input is a curve made of a series of points, and the curve is made of line segments, and the line segments are made of two adjacent points. The input is the same as the output.

czc98 avatar Oct 17 '23 16:10 czc98

I guess @czc98 means a 3d curve offset constrained to the mesh surface. In this case, this recent Siggraph paper on winding numbers on discrete surfaces could come in handy: https://nzfeng.github.io/research/WNoDS/index.html

mariuszhermansdorfer avatar Oct 17 '23 21:10 mariuszhermansdorfer

275867924-e634afca-9219-4ed3-b7d3-5b042d64eef9(1) Curve 1 moves d distance along the surface to get curve 2.

czc98 avatar Oct 18 '23 03:10 czc98

https://ieeexplore.ieee.org/document/4751993 I don't know if this paper will work.

czc98 avatar Oct 18 '23 03:10 czc98

I guess @czc98 means a 3d curve offset constrained to the mesh surface. In this case, this recent Siggraph paper on winding numbers on discrete surfaces could come in handy: https://nzfeng.github.io/research/WNoDS/index.html

Thanks for one more great reference. But as far as I can see this paper deals with a set of closed curves on a surface (or closed curves with small gaps), but not completely open curves as in your example.

What we can easily do is to draw a closed curved offset on fixed distance along the surface around your input curve. And you will select some part on offset curve by yourself.

Fedr avatar Oct 18 '23 08:10 Fedr

I guess @czc98 means a 3d curve offset constrained to the mesh surface. In this case, this recent Siggraph paper on winding numbers on discrete surfaces could come in handy: https://nzfeng.github.io/research/WNoDS/index.html

Thanks for one more great reference. But as far as I can see this paper deals with a set of closed curves on a surface (or closed curves with small gaps), but not completely open curves as in your example.

What we can easily do is to draw a closed curved offset on fixed distance along the surface around your input curve. And you will select some part on offset curve by yourself.

In fact, all I need is a closed curve offset. The picture is just an explanation.

czc98 avatar Oct 18 '23 08:10 czc98

Is there any way in Meshlib to do that?

czc98 avatar Oct 18 '23 08:10 czc98

Thanks for one more great reference. But as far as I can see this paper deals with a set of closed curves on a surface (or closed curves with small gaps), but not completely open curves as in your example.

I thought it could be relevant for bowties removal when an open curve offset creates self-intersections.

mariuszhermansdorfer avatar Oct 18 '23 09:10 mariuszhermansdorfer

This task can be solved this way:

  1. Calculate surface distances for vertices near the path: https://github.com/MeshInspector/MeshLib/blob/master/source/MRMesh/MRSurfaceDistance.h
  2. Extract iso-lines of found distance field: https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRExtractIsolines.h#L15-L17

You can find example code in implementation of this function: https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRToolPath.h#L162-L165

Grantim avatar Oct 18 '23 10:10 Grantim

function

This task can be solved this way:

  1. Calculate surface distances for vertices near the path: https://github.com/MeshInspector/MeshLib/blob/master/source/MRMesh/MRSurfaceDistance.h
  2. Extract iso-lines of found distance field: https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRExtractIsolines.h#L15-L17

You can find example code in implementation of this function:

https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRToolPath.h#L162-L165

I'm confused about the MR::computeSurfaceDistances function. It seems to apply only to line segments, not to curves (collections of line segments).

czc98 avatar Oct 18 '23 11:10 czc98

https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRToolPath.cpp#L1588-L1595 startVerticesWithDists here is vertices that are neighbors with original curve with values equal to distance to the curve.

So:

  1. You find all neighbor vertices to original curve
  2. Make Polyline3 from the curve
  3. Fill up startVerticesWithDists like here https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRToolPath.cpp#L1564-L1586
  4. Then do this https://github.com/MeshInspector/MeshLib/blob/7f950aebf4cf5e0bff7e1cf189b01b26bfc35d7d/source/MRMesh/MRToolPath.cpp#L1588-L1595

Grantim avatar Oct 18 '23 11:10 Grantim

Whether points on a curve are required to be vertices?

czc98 avatar Oct 18 '23 12:10 czc98

They are not, but you need to manually setup distances in the vertices closest to the curve (as Grantim explained above) before calling computeSurfaceDistances. Also this method is limited to offsets larger than edge length.

Alternatively, you can cut the mesh along the curve using cutMesh function. This will introduce vertices and edges in the mesh, coinciding with the curve. After that the call to computeSurfaceDistances becomes much simpler.

Fedr avatar Oct 18 '23 12:10 Fedr

They are not, but you need to manually setup distances in the vertices closest to the curve (as Grantim explained above) before calling computeSurfaceDistances. Also this method is limited to offsets larger than edge length.

Alternatively, you can cut the mesh along the curve using cutMesh function. This will introduce vertices and edges in the mesh, coinciding with the curve. After that the call to computeSurfaceDistances becomes much simpler.

Do I not need the dists[v] = -dists[v] operation if I use the cutMesh function? Do I just need to find the vertices adjacent to Polyline3 through a topological relationship, construct startVerticesWithDists by calculating the distance from the vertices to Polyline3, and then call the extractIsolines function?

czc98 avatar Oct 18 '23 14:10 czc98

Do I just need to find the vertices adjacent to Polyline3 through a topological relationship, construct startVerticesWithDists by calculating the distance from the vertices to Polyline3, and then call the extractIsolines function?

You need to do so. dists[v] = -dists[v] this is needed to separate inside and outside parts of the path. Later we will write and show the function. for simplier usage.

Grantim avatar Oct 18 '23 14:10 Grantim

Do I just need to find the vertices adjacent to Polyline3 through a topological relationship, construct startVerticesWithDists by calculating the distance from the vertices to Polyline3, and then call the extractIsolines function?

You need to do so. dists[v] = -dists[v] this is needed to separate inside and outside parts of the path. Later we will write and show the function. for simplier usage.

Do I just need to find the vertices adjacent to Polyline3 through a topological relationship, construct startVerticesWithDists by calculating the distance from the vertices to Polyline3, and then call the extractIsolines function?

You need to do so. dists[v] = -dists[v] this is needed to separate inside and outside parts of the path. Later we will write and show the function. for simplier usage.

What are inside and outside? image Is it the concept in the picture?

czc98 avatar Oct 19 '23 07:10 czc98

If I have open curves,yellow Curve moves d distance along the surface to get green curve. 5334cf120e6d4538c6db0633f5db3f4 I can know the average curvature of the surface.Now a problem is that some points may disappear during the offset process. How should I do it better?

xiaodongdong101 avatar Oct 19 '23 07:10 xiaodongdong101

Hello! Sorry for late response, we are now a bit busy with other tasks. We are going to make function to demonstrate how it works hopefully in the begining of 2024.

Grantim avatar Nov 17 '23 10:11 Grantim