[vtkusers] Iterative subdivision causes holes

sebastian_a seb.an at icloud.com
Tue Sep 26 12:12:53 EDT 2017


Hello,
I created this python script to subdivide each cell of a polydata depending
on its size.
Unfortunately, if the input polydata is more complex, the output polydata
has holes in it like shown on the picture. Do you know what could be the
reason?



def extractCells(polydata, ids, inverse):
  selectionNode = vtk.vtkSelectionNode()
  selectionNode.SetFieldType(vtk.vtkSelectionNode.CELL)
  selectionNode.SetContentType(vtk.vtkSelectionNode.INDICES)
  selectionNode.SetSelectionList(ids)

  if inverse == True:
    selectionNode.GetProperties().Set(vtk.vtkSelectionNode.INVERSE(),1)
  else:
    selectionNode.GetProperties().Set(vtk.vtkSelectionNode.INVERSE(),0)

  selection = vtk.vtkSelection()
  selection.AddNode(selectionNode)

  extractSelection = vtk.vtkExtractSelection()
  extractSelection.SetInputData(0, polydata)
  extractSelection.SetInputData(1, selection)
  extractSelection.Update()

  selected = vtk.vtkUnstructuredGrid()
  selected.ShallowCopy(extractSelection.GetOutput())

  geometryFilter = vtk.vtkGeometryFilter()
  geometryFilter.SetInputData(selected)
  geometryFilter.Update()

  return geometryFilter.GetOutput()



def subdivide(polyData, edgeLength):
  # Find Large Faces
  largeFacePolyData = polyData
  smallFacePolyData = vtk.vtkPolyData()

  while largeFacePolyData.GetNumberOfPoints() > 0:
    idsLarge = vtk.vtkIdTypeArray() # IDs of cells
    idsLarge.SetNumberOfComponents(1)
    
    idsSmall = vtk.vtkIdTypeArray() # IDs of cells
    idsSmall.SetNumberOfComponents(1)

    idsname = "Ids" 
    ids = vtk.vtkIdFilter() 
    ids.SetInputData(largeFacePolyData) 
    ids.PointIdsOff() 
    ids.CellIdsOn()
    ids.FieldDataOff() 
    ids.SetIdsArrayName(idsname) 
    ids.Update()
    cellIds = ids.GetOutput().GetCellData().GetArray(idsname)

    for i in xrange(cellIds.GetNumberOfValues()):
      cell = largeFacePolyData.GetCell(cellIds.GetValue(i))
      if getCircumferenceOfCell(cell) > edgeLength:
        idsLarge.InsertNextValue(cellIds.GetValue(i))
      else:
        idsSmall.InsertNextValue(cellIds.GetValue(i))
      

    smallFaces = extractCells(largeFacePolyData, idsSmall, False)
    largeFaces = extractCells(largeFacePolyData, idsLarge, False)

    if smallFacePolyData.GetNumberOfPoints() > 0:
      appendFilter = vtk.vtkAppendPolyData()
      appendFilter.AddInputData(smallFacePolyData)
      appendFilter.AddInputData(smallFaces)
      appendFilter.Update()
      # clean
      clean = vtk.vtkCleanPolyData()
      clean.SetInputConnection(appendFilter.GetOutputPort())
      clean.Update()

      smallFacePolyData = clean.GetOutput()
    else:
      smallFacePolyData = smallFaces

    # subdivide
    
    if largeFaces.GetNumberOfPoints() > 0:
      subdivisionFilter = vtk.vtkLinearSubdivisionFilter()
      subdivisionFilter.SetNumberOfSubdivisions(1)
      subdivisionFilter.SetInputData(largeFaces)
      subdivisionFilter.Update()
      largeFacePolyData = subdivisionFilter.GetOutput()
    else:
      largeFacePolyData = largeFaces

  return smallFacePolyData


<http://vtk.1045678.n5.nabble.com/file/t341915/Screen_Shot_2017-09-26_at_17.png> 


Thank you very much,
Sebastian



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html


More information about the vtkusers mailing list