Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove Holes form Polygons #182

Closed
ethanVodka opened this issue Jun 20, 2023 · 7 comments
Closed

Remove Holes form Polygons #182

ethanVodka opened this issue Jun 20, 2023 · 7 comments

Comments

@ethanVodka
Copy link

I tryto remove a hole from a polygon in a gds file and save it as a new gds file,
Is there any good way to do this?
I am using C++ for the gdstk library.

Slide1

@heitzmann
Copy link
Owner

Not directly. You can first subtract the polygon from its bounding box (or the convex hull to get fewer false positives). That will leave you with all holes and concave cutouts. The idea is then to merge the original polygon with the holes or (better, in my opinion) subtract the cutouts from a new bounding box (or convex hull, if you started with it).

Sorting the pieces into holes and cutouts is the tricky part. The way I can see it being possible is by checking if each piece intersects with the external boundary (bounding box or convex hull): offset the bounding box (convex hull) inwards by a small amount and subtract it from the original. That will give the external contour. Then, intersect each piece with this contour: the ones with any intersection are exterior cutouts.

@ethanVodka
Copy link
Author

Thank you very much for your reply.

poly1 ={ {0, 0}, {50, 0}, {50, 50}, {0, 50} }
poly2 = {{20, 20}, {20, 30}, {30, 30}, {30, 20}}

I am now able to split inside and outside using Clipper, I am thinking of merging inside and outside to generate the points[] below

points[] = { {0, 0}, {50, 0}, {50, 50}, {20, 20}, {20, 30}, {30, 30}, {30, 20}, {20, 20} };

Is it possible to realize
poly1 + poly2 = points[]
in gdstk cpp? I would be very happy if you could show us the actual cpp code with it.

Here is my code split polygons into outer and inner

	List<List<GPoint^>^>^ outer = gcnew List<List<GPoint^>^>();
	List<List<GPoint^>^>^ inner = gcnew List<List<GPoint^>^>();

	for each (List<GPoint^> ^ poly in GdsPolygons[DisplayLayer]->plygons_list)
	{
		if (Utils::Common::UClipper::IsClockwise(poly))
		{
			outer->Add(poly);
		}
		else
		{
			inner->Add(poly);
		}
	}

@heitzmann
Copy link
Owner

I'm not sure I understand how you want to merge those points. The array you describe ({ {0, 0}, {50, 0}, {50, 50}, {20, 20}, {20, 30}, {30, 30}, {30, 20}, {20, 20} }) is not a valid polygon.

@heitzmann
Copy link
Owner

By the way: the suggestion I gave comes from #173, if you wanto to take a look.

@tvt173
Copy link

tvt173 commented Jun 26, 2023

hi @ethanVodka , I'd suggest you consider converting the polygons to a library which has a notion of shapes with holes. For example, in Klayout you can do this quite naturally: https://www.klayout.de/doc/code/class_Region.html#method79

In python, I also often use the shapely library. I believe it wraps the GEOS library from C++, so while I can't speak from experience, you can probably get the functionality you need from GEOS also.
https://shapely.readthedocs.io/en/stable/

For example, to do this with shapely, it is as simple as copying over all the polygons from gdstk, merging them, and then reporting out the exterior of all the resulting shapes.

@ethanVodka
Copy link
Author

hi @heitzmann , That issue was quite helpful. thank for your advice.

@ethanVodka
Copy link
Author

hi, @tvt173. I was able to find a library with similar functionality to shapely and will try it out.
Thank you too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants