tpaviot / pythonocc-core

Python package for 3D geometry CAD/BIM/CAM
GNU Lesser General Public License v3.0
1.35k stars 376 forks source link

Are there any polygon morphology operations I'm missing? #937

Closed inventor2525 closed 3 years ago

inventor2525 commented 3 years ago

Such as OpenCV does here

I'm looking mostly for erosion and dilation of OCC faces.

Currently I'm using Shapely to (they call their function) "buffer" a polygon, and then convert it to an OCC face and extrude my 3d geometry up from there, but Shapely builds it's polygons of solely line segments and I'd like to use the full descriptive power of a b rep (eg, actual arcs for end caps).

Closest I've seen is Geom2d_OffsetCurve, but there's be a pretty bit to build on top for that.

tpaviot commented 3 years ago

I'm not sure to fully understand what you need to finally achieve, you may check https://github.com/mathLab/PyGeM

inventor2525 commented 3 years ago

PyGeM's probably? a bit much.

I'm imagining a single occ function I've yet to find (if there is one), but vocab changes slightly in different contexts.

I think sudo code here may clear this this up more completely, but the picture here really helps more maybe once you're close. The left side of the image shows the effect of buffering a linestripe (akin to a wire -- shown there in dark blue), and the light blue polygon that results. The right, what happens when you buffer a polygon by a negative value (grey being input, blue being result). -- If you continued the first, holes would disappear, if you continued the second, eventually the polygon would disappear.

Apologies for the accidental early post, and thank you for this awesome framework and support!

tpaviot commented 3 years ago

Ok, I got it. OCC provides good 2d primitives and algorithms (offset, trimming, boolean ops), it can certainly be done. It requires quite a piece of work though.

inventor2525 commented 3 years ago

Gotcha. Ok, well, if I end up making it I'll go ahead and post it, but I may be able to do what I need for now in other ways easier. Thank you!