gdstk icon indicating copy to clipboard operation
gdstk copied to clipboard

get_polygons/labels/paths for gdstk.Reference object

Open cecial opened this issue 3 years ago • 2 comments

Hi, will add get_polygons/labels/paths for gdstk.Reference object in the future? like in gdspy. this will help get postions of reference cell polygons based on current cell coordinates easily, or else, i need to do some thing like refcell.origin + polygon.points

cecial avatar Jun 07 '22 08:06 cecial

Surely it can be done. I can replicate the Cell methods for references when I have some time off. Meanwhile, you can get the same results easier by creating a temporary cell:

temp_cell = gstk.Cell("TEMP")
temp_cell.add(some_reference)
polygons = temp_cell.get_polygons()
paths = temp_cell.get_paths()
labels = temp_cell.get_labels()

heitzmann avatar Jun 07 '22 14:06 heitzmann

Waiting for the update.

cell_a = gdstk.Cell('A')
cell_a.add(gdstk.Label('LabelA',(5,5),layer=10,datatype=0)
cell_b = gdstk.Cell('B')
cell_b.add(gdstk.Label('LabelB',(5,5),layer=10,datatype=0)
cell_c = gdstk.Cell('C')
cell_c.add(gdstk.Reference(cell_a,(10,10)),gdstk.Reference(cell_b,(20,20)))

for ref in cell_c.references :
    for label in ref.get_labels(layer=10,texttype=0) : 
        print(f'{label.text} posision in cell C is {label.origin}')
    

will get output as :

LabelA position in cell C is (15,15)
LabelB position in cell C is (25,25)

cecial avatar Jun 08 '22 01:06 cecial

Yes, and that's correct…

heitzmann avatar Oct 28 '22 21:10 heitzmann

using the TEMP cell leads to terrible performance for thousands of references of very populous cells. As do any get_polygons calls (on the ref or ref.cell). Using ref.cell.polygons yields results of untranslated (i.e. leaf cell) coordinates (but is quite fast).

What is the most performant way to operate on reference's polygons transparently and without heavy memory penalty due to copy actions?

I am running version 0.9.35.

nmz787-intel avatar Jan 20 '23 05:01 nmz787-intel

It depends on what exactly you want to do. If you need to get the actual polygons, there is going to be a penalty for transforming them on the reference.

Please don't mix issues, though. Open a new one explaining precisely what you need and I'll be happy to help any way I can!

heitzmann avatar Jan 20 '23 21:01 heitzmann

It seemed the OP in this issue was asking for a Reference object to have a get_polygons method which provided transformed (with respect to the Reference origin) polygons, is this how the API now works in version 0.9.35? The docs and comments above just aren't 100% clear on the outcome with respect to this ticket being closed.

That's all I wanted to know. I don't think I need anything now since I learned calling .get_polygons on the cell-level actually will get transformed polygons from any children/References, and I was able to get the performance I wanted by passing layer and datatype when making the call. Thanks again!

nmz787-intel avatar Jan 20 '23 21:01 nmz787-intel