PixarAnimationStudios / OpenSubdiv

An Open-Source subdivision surface library.
graphics.pixar.com/opensubdiv
Other
2.88k stars 558 forks source link

Interpolating a rectangular grid with a piecewise surface #1279

Closed Seifalla closed 1 year ago

Seifalla commented 1 year ago

I have been looking for a tutorial on this on the web but without much success so far. Does anybody have examples? I saw a picture of a piecewise Bézier surface on this page, which lead me to think that somebody did it. I just can't find any examples or explanation of this.

barfowl commented 1 year ago

Could you confirm what you mean by "interpolate", i.e. do you really want to generate a piecewise surface that actually interpolates all of the control points of the grid?

If so, that is not a trivial problem and so simple examples or explanations are going to be scarce -- and that explanation is going to assume some level of familiarity with parametric surface representations. If not, your time is probably better spent looking into B-spline surfaces rather than Bezier.

And how does this relate to OpenSubdiv?

OpenSubdiv makes use of individual parametric patches to assemble a piecewise surface for meshes of arbitrary topology. So regardless of the interpolating or approximating nature of the control points and their surfaces (and OpenSubdiv surfaces do not interpolate the mesh vertices), OpenSubdiv does not deal with rectangular grids. So you won't find any useful examples here.

Seifalla commented 1 year ago

Sorry, I thought that OpenSubdiv dealt with rectangular grids. That was a misconception on my part. There have actually been some developments since I created this issue. I found that I could generate a rectangular mesh for the shape that I want to render using Catmull-Clark subdivision surfaces (but without refining the mesh too much) and then interpolate the mesh with Bézier surface patches. The grid has to be rectangular since a Bézier surface patch interpolates the four corner points of its control net. If you have any advice/suggestions, please let me know. Otherwise, you can go ahead and close this issue as completed.

Thanks.

barfowl commented 1 year ago

Glad you're making progress. I'm a little uncertain and curious as to where your "interpolation" is taking place though.

From your comment "without refining the mesh too much" do mean you are subdividing ("refining") the rectangular mesh of the grid before interpolating with Bezier patches?

A rectangular grid for a Catmull-Clark surface is just a grid of uniform B-spline patches. Subdividing/refining gives you the same shape at every level, just with more patches. If you fit Bezier patches to the control net at each level, you get a different shape at each level. Are you interpolating the original grid or one that's been refined once or twice?

Thanks

Seifalla commented 1 year ago

Let's say we want to render a sphere. My idea is to generate a hexahedron, subdivide it once or twice, and then interpolate the resulting grid with a piecewise Bézier surface.

I actually did more research over the last couple of days and found that I don't even have to generate a mesh myself; there are a lot of 3D models out there, plus you can use image processing techniques to convert an image to a 3D mesh. So, if my idea is infeasible or something (feedback is welcome, here), I can just resort to those alternatives.

Thanks.

barfowl commented 1 year ago

You definitely have a lot of options to explore with rectangular grids, so by all means check them out and see what works best for you.

The problem that poses a different challenge -- and the reason I focused on your intention with "interpolate" -- is fitting a high quality piecewise surface through a rectangular set of control points when the positions of those points is critical (so an emphasis on "interpolate").

Since you're subdividing once or twice, clearly the positions of an original control cage are not critical. And interpolating with Bezier patches typically only yields tangent continuity -- not the higher quality curvature continuity you get with B-splines (or regular Catmull-Clark surfaces) -- but it sounds like tangent continuity is good enough for your purposes.

There are lots of solutions to that surface interpolation/fitting problem out there if its ever an issue, but you apparently have a lot more flexibility with yours.

Good luck