[vtkusers] Remeshing using Octree Filter

sebastian_a seb.an at icloud.com
Fri Sep 22 06:13:07 EDT 2017


I quickly wrote this handy script to iterate through a vtkPolyData and
subdivide the cells till they are smaller than a given boundary. It's not
very fast but maybe it could be an inspiration for a new vtk filter:


def extractPolyData(polydata, idsArrayOfPoints, FieldType, inverse):
#FieldType: cell = 0, point = 1
  selectionNode = vtk.vtkSelectionNode()
  selectionNode.SetFieldType(FieldType)
  selectionNode.SetContentType(4)
  selectionNode.SetSelectionList(idsArrayOfPoints)
  selectionNode.GetProperties().Set(vtk.vtkSelectionNode.CONTAINING_CELLS(),
1)

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

  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())

  extractionPolydata = vtk.vtkPolyData()
  extractionPolydata.SetPoints(selected.GetPoints())
  extractionPolydata.SetPolys(selected.GetCells())

  return extractionPolydata


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

  while largeFacePolyData.GetNumberOfCells() > 0:
    ids = vtk.vtkIdTypeArray() # IDs of cells
    ids.SetNumberOfComponents(1)
    for i in xrange(largeFacePolyData.GetNumberOfCells()):
      if getBoundaryOfCell(largeFacePolyData.GetCell(i)) > boundary:
        ids.InsertNextValue(i)

    smallFaces = extractPolyData(largeFacePolyData, ids, 0, True)
    if smallFacePolyData.GetNumberOfCells() > 0:
      appendFilter = vtk.vtkAppendPolyData()
      appendFilter.AddInputData(smallFaces)
      appendFilter.AddInputData(smallFacePolyData)
      appendFilter.Update()
      smallFacePolyData = appendFilter.GetOutput()
    else:
      smallFacePolyData = smallFaces

    # subdivide
    largeFaces = extractPolyData(largeFacePolyData, ids, 0, False)
    subdivisionFilter = vtk.vtkLinearSubdivisionFilter()
    subdivisionFilter.SetNumberOfSubdivisions(1)
    subdivisionFilter.SetInputData(largeFaces)
    subdivisionFilter.Update()
    largeFacePolyData = subdivisionFilter.GetOutput()

  return smallFacePolyData



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


More information about the vtkusers mailing list