drufat / triangle

Python bindings to the triangle library
GNU Lesser General Public License v3.0
224 stars 53 forks source link

How to use the 'regions' argument in the 'triangulate()' function? #43

Open QuentinRoyerDev opened 4 years ago

QuentinRoyerDev commented 4 years ago

In order to pass original attribute data of initals polygons to each generated triangle, i would like to know how to use the 'regions' argument in the 'triangulate()' function ? I haven't found any tips or examples.

mzucker commented 4 years ago

I figured out how to do this for a project of my own today. See https://gist.github.com/mzucker/b0846f304b48702ff2530294134ae879

Interestingly, I needed to monkey-patch the triangle Python library, otherwise I got a KeyError at https://github.com/drufat/triangle/blob/master/triangle/tri.py#L67

Adding the extra key/value pair ('triangleattributelist', 'triangle_attributes') to the terms at https://github.com/drufat/triangle/blob/master/triangle/tri.py#L3 would fix this – @drufat would you consider adding it?

Example input and output images attached.

tri_input

tri_output

drufat commented 4 years ago

@mzucker Thanks for the contribution. I would be happy to merge it. Could you add your example to the documentation as well?

mzucker commented 4 years ago

Created a pull request, let me know if it passes muster. This was my first time editing Sphinx and my first pull request on github in a very long time, if not ever.

QuentinRoyerDev commented 4 years ago

That's exactly what I was hoping for. Thank you very much for your responses.

mzucker commented 4 years ago

Glad to help!