[vtkusers] Access the points of a certain region extracted by vtkPolyDataConnectivityFilter
Cory Quammen
cory.quammen at kitware.com
Mon Feb 22 08:44:25 EST 2016
On Mon, Feb 22, 2016 at 4:09 AM, normanius <juch at zhaw.ch> wrote:
> Hi Cory
>
> Strange, in the web-view of the mailing list, the code is visible.
Yeah, I think folks have had some problems with attachments on nabble
before - I didn't know formatting would be a problem.
> I repost/rephrase my question, this time without any formatting:
>
> # How I use vtkPolyDataConnectivityFilter:
> largest = vtk.vtkPolyDataConnectivityFilter()
> largest.SetInputConnection(input.GetOutputPort())
> largest.SetExtractionModeToLargestRegion()
> largest.Update()
>
> # How I would like to extract the points from the largest region,
> # but this does not work: It gives me all the points of input
> polyData = largest.GetOutput()
> N = polyData.GetNumberOfPoints()
> for i in range(0, N):
> p = sourceData.GetPoint(i)
>
> # What I currently do to extract those points:
> lines = largest.GetOutput().GetLines() # cell array
> lines.InitTraversal()
> idList = vtk.vtkIdList()
> I = set()
> while lines.GetNextCell(idList):
> for i in range(0, idList.GetNumberOfIds()):
> index = idList.GetId(i)
> if index not in I:
> p = sourceData.GetPoint(index)
> I.add(index)
>
> # Is there a more direct way of extracting only the connected region
> # of interest?
Hmm, I seem to remember there is a way to remove unused points in a
poly data, but the class name escapes me. You could use such a class
after the connectivity filter to do this. Otherwise, if you just need
the points and not the cells, you could try vtkThresholdPoints and
give the threshold value in terms of the region whose points you want
to keep.
HTH,
Cory
--
Cory Quammen
R&D Engineer
Kitware, Inc.
More information about the vtkusers
mailing list