find coordinates of holes inside a polygon

python

(Fabio) #1

Hi,

I have a polygon shape filled up with holes. I need to locate and collect the holes for further processing. Is there an easy way using python shell/script/filters to find those holes?

Thanks

Fabio


(Cory Quammen (Kitware)) #2

You can use the Feature Edge filter and check only the Boundary Edges option to find the borders of holes.


(Fabio) #3

Thanks Cory, I’ll look into that right away.

Haven’t bought the manual yet…are those feature well documented in it? If so I’ll order it right away

Thanks!


(Cory Quammen (Kitware)) #4

The community edition of the ParaView Guide is available at no cost. The Feature Edges filter is mentioned in passing. If you want to browse descriptions of various filters, look at the “Reader, Filter, and Writer” item in the Help menu.


(Fabio) #5

Hi Cory,

That’s perfect! Thanks a lot, I think I’m getting the hang of it!

Thanks for your help

Fabio


(Walter Alan Scott) #6

Fabio,
You can also get to the ParaView Guide through the Help menu. For those of us who forget where all of Paraview’s documentation is, this is my “go to” shortcut.
Alan


(Fabio) #7

Hi Cory,

I guess I have one more question…here below is my little script. Basically what I need to do is locate the holes in a polygon, calculate the distance between them and based on that, modify the array data of the points between them.

Now, the filter portion (thanks to you) works as expected (I can modify the data array and visualize it at will)

I can also see that the FetureEdges “works”…meaning of: once the script runs, I can see the edges of the holes getting highlighted in ParaView. What I still can’t find is a way to loop through either the holes shapes (if possible) or the
holes points. How can I access those information? I apologize for the dumb question

Importing the vtk file

reader = OpenDataFile("/home/fabior/Current_density-tm-mag-xyz_slice.vtk")

Show(reader)

SetDisplayProperties(Representation = “Surface”)

SetDisplayProperties(ColorArrayName = “scalars”)

SetDisplayProperties(LookupTable = MakeBlueToRedLT(-100, 1e10))

Render()

finding holes inside the polygon

featureEdges = FeatureEdges(reader)

selecting only the holes boundaries

featureEdges.BoundaryEdges = 1

featureEdges.FeatureEdges = 0

featureEdges.NonManifoldEdges = 0

featureEdges.UpdatePipeline()

finding distances between holes corners

adding programmable filter to remove false CD channels

programmableFilter = ProgrammableFilter(reader)

progrFilterFile = open("/home/fabior/myPrograms/paraview/programmable_filter.py")

programmableFilter.Script = progrFilterFile.read()

programmableFilter.UpdatePipeline()

w = CreateWriter("./modified_data.vtk")

w.UpdatePipeline()


(Fabio) #8

…I guess I first have to pass my featureEdges variable to a new ProgrammableFilter, don’t I?
:blush:


(Cory Quammen (Kitware)) #9

ProgrammableFilter(Input=featureEdges) should do the trick. Then, whatever you have in programmable_filter.py will be run with the input set to the output of the Feature Edges filter.

To get the points in the programmable_filter.py, add to your script file

inputs[0].PointData

which gives you a NumPy like array with the point locations.

You’ll probably want to isolate the boundaries around different holes, which you can do by running the Connectivity filter after the Feature Edges filter. This assigns a unique RegionID to each point, which you can use to differentiate among the hols.

BTW, when posting code here, you can add mark the start and end of a code section with ```. That will improve the code formatting. You can also specify the language (e.g., python) after the opening backticks to explicitly define what language highlighting should be used.


(Fabio) #10

Hi Cory,

After your inputs…I’m trying to come up with something more sophisticated. What I’d like to get is pass a area selection to the FeatureEdges filter, so that it can work on less data which are the only ones I want to focus on anyway.

I’m trying to use Clip to select the area of interest and then pass that to my “selection” variable (see below in bold red) and pass that one to the featureEdges variable before handing it over to my programmable filter.

The code errors out though…looks like ExtractSelection doesn’t like the clip…

I’m using paraview 3.14…so…it’s a bit old…

Am I doing anything wrong? (hope I’ve format the code properly with the `)

Thanks

Fabio

`python

from paraview.simple import *

import paraview.vtk as vtk

Importing the vtk file

reader = OpenDataFile("/home/fabior/tm-mag-xyz_slice.vtk")

Show(reader)

SetDisplayProperties(Representation = “Surface”)

SetDisplayProperties(ColorArrayName = “scalars”)

SetDisplayProperties(LookupTable = MakeBlueToRedLT(-100, 1e10))

Render()

collecting shape’s bounds

(xmin, xmax, ymin, ymax, zmin, zmax) = reader.GetDataInformation().GetBounds()

selecting points inside the comb

clipArea = Clip(reader)

clipArea.ClipType = ‘Box’

clipArea.ClipType.Bounds = [xmin, xmax, ymin + 150.0, ymax - 150.0, zmin, zmax]

clipArea.UpdatePipeline()

finding holes inside the polygon

selection = ExtractSelection(Input=reader, Selection=clipArea)

selection.UpdatePipeline()

featureEdges = FeatureEdges(selection)

selecting only the holes boundaries

featureEdges.BoundaryEdges = 1

featureEdges.FeatureEdges = 0

featureEdges.NonManifoldEdges = 0

featureEdges.UpdatePipeline()

connectivityFilter = Connectivity(featureEdges)

connectivityFilter.UpdatePipeline()

adding programmable filter to remove false CD channels

programmableFilter = ProgrammableFilter()

programmableFilter.Input = [reader, connectivityFilter]

progrFilterFile = open("/home/fabior/myPrograms/paraview/programmable_filter_holes.py")

programmableFilter.Script = progrFilterFile.read()

programmableFilter.UpdatePipeline()

w = CreateWriter("./modified_data.vtk")

w.UpdatePipeline()`