KLayout / klayout

KLayout Main Sources
http://www.klayout.org
GNU General Public License v3.0
763 stars 198 forks source link

Bezier curves #681

Open lukasc-ubc opened 3 years ago

lukasc-ubc commented 3 years ago

Dear @klayoutmatthias,

Would it be possible to add bezier curves for polygons in the "Basic" library?

For photonics, we use them for drawing waveguides.

https://support.lumerical.com/hc/en-us/articles/360034382234-Waveguide-Simulation-Object

We have also implemented this in SiEPIC-Tools https://github.com/SiEPIC/SiEPIC-Tools, but it would be nice if it was natively supported in KLayout.

thank you Lukas

thomaslima commented 3 years ago

I have two questions: Q1: How do you envision using it in practice? For a Bezier you need four points. Do you suggest the user provides the four points as a path perhaps? Q2: Why would this be useful in the Basic Library if the SiEPIC library can provide the same functionality?

thomaslima commented 3 years ago

For reference, I found the implementation of the ROUND_PATH PCell from the basic library: It's only 150 lines. https://github.com/KLayout/klayout/blob/master/src/lib/lib/libBasicRoundPath.cc

The Bezier cell would be something similar. But I wonder what is the advantage of it being native if klayout needs extension anyways for photonics.

lukasc-ubc commented 3 years ago

@thomaslima – good questions.

In summary, the request here is to have a super efficient quality-controlled implementation that is universally accepted and used, not only by SiEPIC, but other users, including in other fields (MEMS).

regards Lukas

thomaslima commented 3 years ago

Okay. I suppose I would summarize your answer as "higher speed" and "creating a standard".

The cubic Bezier formula is uniquely defined by a function B(t), with 0<=t<=1 (lumerical and wikipedia agree), but one thing that is not trivial is where to sample along the bezier function. In zeropdk, I use a dynamic optimization that calculates where to sample the curve based on some tolerance. ROUND_PATH asks you to specify the number of points per circle, then samples uniformly at each arc. This optimization is computationally expensive and it doesn't sound like a good approach for this.

Another option is to uniformly sample in t [0,1], but that risks introducing bad artifacts in edge cases. A mid-way approach is to use guess-and-resample iterations, like in this article. I would recommend this approach.

Regarding the Bezier polygon, I wonder what are the use cases. If the idea is to draw an offset curve to the original bezier path, it won't work, since the offset curve is not a bezier curve, and it is actually quite expensive to compute analytically, but should be doable numerically, and it will introduce potentially self-intersecting polygons in edge cases.

I don't know if it is feasible to do the Polygon case and have it be based on an underlying Polygon because the way klayout orders the points for polygons is not preserved, I think.

I could take a stab at converting zeropdk's method to klayout c++, the remaining question being whether @klayoutmatthias would accept this addition to the library, since he'll have to maintain.

My recommendation, which would address your motivation, is to include a c++ algorithm that computes a bezier path, that you can call from ruby or python and use this function to create the waveguide PCell in third-party libraries. If everyone uses the same method, then it should be fast and it should be standard.

lukasc-ubc commented 3 years ago
thomaslima commented 3 years ago
thomaslima commented 3 years ago

Note: this is related to #193. In that discussion, I would favor the svg-path (composite Bezier) method, because as a designer I like to ensure the curve passes through some designated points, and I like to control the tangent vector at those points. It is also a simple extension, requiring just a list of points, not requiring weights as well.

It would be cool if klayout could support composite beziers. For a nice visual representation, we would need, I think, an extension of the path object that displays control points as well as knots.

riking commented 3 years ago

and the parameters from the technology specific for the waveguide type (Waveguides.XML) [radius, bezier parameter, gds layers, widths, offsets] into the required P0-P3 control points.

To be clear here -- the technology / DRC rules set restrictions on what radius / width / offset of curve is manufacturable, correct?

lukasc-ubc commented 3 years ago

@riking

I am less worried about manufacturing, but rather the performance of the device.

Specifically, I would like to make a 90º bend with the minimum amount of space and loss. Here is how I use it for strip waveguides at 1550 nm, with 220 nm thickness, and 500 nm width.

image