[Paraview] injecting objects from python

Hal Canary hal at cs.unc.edu
Tue Jun 19 06:44:44 EDT 2012


On 06/19/2012 06:10 AM, Gertjan van Zwieten wrote:
> [...]
> So my question is simply if it is possible to inject objects from python
> into an already running or separately spawned paraview instance? If so,
> any pointers in that direction (an example script?) would of course be
> enormously helpful.

I use a programmable source.  Here's a macro to create an image:

#####################
script="""
image = self.GetImageDataOutput()
image.SetSpacing(0.01,0.01,0.01)
image.SetOrigin(0,0,0)
image.SetDimensions(101,101,101)
array = numpy.zeros((101,101,101,), dtype=numpy.float32)
space = numpy.linspace(0,1,101)
for i,x in enumerate(space):
	for j,y in enumerate(space):
		for k,z in enumerate(space):
			array[i,j,k] = (math.sin(4*x)
				+ math.sin(4*y) + math.sin(4*z))
image.GetPointData().AddArray(
	paraview.vtk.dataset_adapter.numpyTovtkDataArray(
		array.reshape(101*101*101), name="myarray"))
"""
script_request_information = """
from paraview import util
util.SetOutputWholeExtent(self, [0, 100, 0, 100, 0, 100])
"""
ps = ProgrammableSource(
   guiName="My Source",
   Script=script,
   ScriptRequestInformation=script_request_information,
   OutputDataSetType='vtkImageData' )
Show(ps)
###################################


More information about the ParaView mailing list