Python how to generate ghost cells?

https://gitlab.kitware.com/vtk/vtk/-/blob/v9.3.0/Filters/ParallelDIY2/Testing/Cxx/TestGhostCellsGenerator.cxx

I noticed there is a C++ test code for vtkGhostCellsGenerator.h but it is in C++
wondering is there a matching Python SPI?

BTW, I am creating an overlappingAMR vth with all vti (ImageData). But there are gaps between each block. That’s why thinking is there a convenient Python way to generate Ghost cells to fill in those gaps?
Attached screenshot along with vth and vti files.
99abecc63fbb7788349f020a1e38d46d3ae66ea4_2_690x476
TestAMR.zip (463.0 KB)

# trace generated using paraview version 5.13.0
#import paraview
#paraview.compatibility.major = 5
#paraview.compatibility.minor = 13

#### import the simple module from the paraview
from paraview.simple import *
#### disable automatic camera reset on 'Show'
paraview.simple._DisableFirstRenderCameraReset()

# create a new 'Sphere'
sphere1 = Sphere(registrationName='Sphere1')

# get active view
renderView1 = GetActiveViewOrCreate('RenderView')

# show data in view
sphere1Display = Show(sphere1, renderView1, 'GeometryRepresentation')

# trace defaults for the display properties.
sphere1Display.Representation = 'Surface'

# reset view to fit data
renderView1.ResetCamera(False, 0.9)

# get the material library
materialLibrary1 = GetMaterialLibrary()

# update the view to ensure updated data information
renderView1.Update()

# create a new 'Ghost Cells Generator'
ghostCells1 = GhostCells(registrationName='GhostCells1', Input=sphere1)

# show data in view
ghostCells1Display = Show(ghostCells1, renderView1, 'GeometryRepresentation')

# trace defaults for the display properties.
ghostCells1Display.Representation = 'Surface'

# hide data in view
Hide(sphere1, renderView1)

# update the view to ensure updated data information
renderView1.Update()

#================================================================
# addendum: following script captures some of the application
# state to faithfully reproduce the visualization during playback
#================================================================

# get layout
layout1 = GetLayout()

#--------------------------------
# saving layout sizes for layouts

# layout/tab size in pixels
layout1.SetSize(3132, 888)

#-----------------------------------
# saving camera placements for views

# current camera placement for renderView1
renderView1.CameraPosition = [0.0, 0.0, 3.2903743041222895]
renderView1.CameraParallelScale = 0.8516115354228021


##--------------------------------------------
## You may need to add some code at the end of this python script depending on your usage, eg:
#
## Render all views to see them appears
# RenderAllViews()
#
## Interact with the view, usefull when running from pvpython
# Interact()
#
## Save a screenshot of the active view
# SaveScreenshot("path/to/screenshot.png")
#
## Save a screenshot of a layout (multiple splitted view)
# SaveScreenshot("path/to/screenshot.png", GetLayout())
#
## Save all "Extractors" from the pipeline browser
# SaveExtracts()
#
## Save a animation of the current active view
# SaveAnimation()
#
## Please refer to the documentation of paraview.simple
## https://kitware.github.io/paraview-docs/latest/python/paraview.simple.html
##--------------------------------------------

Spiros’ example here shows that you can create a GhostCells filter in ParaView’s Python scripting layer. ParaView’s Python scripting ultimately lets you use the code in vtkGhostCellsGenerator.h/.cxx.

1 Like

Thank you both!!!
I see there is paraview filter can do the work.
But I hit many problems of Python ParaView package install.
Is there any specific guidance for MacOS to install ParaView Python package?

Am I able to write both data and ghost cells to vti(imageData) file?
(only noticed CreateWriter(“/…/vti”, reader) write from a reader.)

Another question, is this right? read a vti file as the Sphere, then generate ghost cells,
reader = OpenDataFile(‘…/xxx.vti’)
ghostCells = GhostCells(registrationName=‘GhostCells’, Input=reader)

Then it comes to the same problem above, I want both data and ghost to be saved to another file.

Are you trying to use the Python installation that comes with ParaView? That should just work from pvpython or in the Python Console within ParaView. Or are you trying to use a system Python and set it up to provide access to the ParaView Python modules?

Yes, that looks fine.

Use the following Python to save to another file

SaveData('/path/to/data/filename.vti', proxy=ghostCells)
1 Like

Yes, system wise, I want to directly import paraview.simple module to my code.
Run pvpython with my code from terminal, it is slow and I cannot really why SPIs are available directly from editor.