Hey folks,

I have created the attached script by using the Trace feature in Paraview
(version 4.2.0-RC1-128-gc89b0ad) and then tweaked it to run on multiple
.pvtu files. I don't doubt that there is a better way to do this but this
is what I came up with.

I run the script using pvbatch. The problem is that it'll run for a while
and then run out of memory. I also get the following errors on every pass
through the script after the first pass.

ERROR: In
/home/kitware/Dashboards/MyTests/NightlyMaster/ParaViewSuperbuild-Release/paraview/src/paraview/ParaViewCore/ServerManager/Rendering/vtkSMViewLayoutProxy.cxx,
line 481
vtkSMViewLayoutProxy (0x385f370): Cell identified by location '0' is
already split. Cannot split the cell again.

ERROR: In
/home/kitware/Dashboards/MyTests/NightlyMaster/ParaViewSuperbuild-Release/paraview/src/paraview/ParaViewCore/ServerManager/Rendering/vtkSMViewLayoutProxy.cxx,
line 551
vtkSMViewLayoutProxy (0x385f370): Cell is not empty.

It seems to me that Paraview is trying to reuse the slice created in the
last pass and perhaps I need to do something to reset the data or free the
data or something like that. I tried a few things like

Delete(fileReader)
del fileReader
Delete(slice1)
del slice1

etc. at the end of each pass but nothing I tried eliminated the errors.
Incidentally, these errors seemed to be irrelevant as the images exported
just fine until the pvbatch crashed after ' throwing an instance of
'std::bad_alloc' hat():  std::bad_alloc'

Does anybody mind taking a look at this and telling me what I'm doing
wrong, or at least pointing me to documentation/examples that might help me
to figure this out. I did read through the seemingly relevant Google search
results dealing with scripting with Paraview with no luck.

I appreciate your time,

-- 
*Ethan Alan Hereth*
#### import the simple module from the paraview
from paraview.simple import *

from glob import glob
import os.path as path

fileList = glob('./solution_[0-9]*.pvtu')

if len(fileList):
    print "Found %d solution data sets..." % len(fileList)
    count = 0

    for fileName in fileList:
        print "\tProcessing %s" % fileName

        #### disable automatic camera reset on 'Show'
        paraview.simple._DisableFirstRenderCameraReset()

        # create a new 'XML Partitioned Unstructured Grid Reader'
        fileReader = XMLPartitionedUnstructuredGridReader(FileName=[fileName])
        fileReader.CellArrayStatus = ['treeid', 'level', 'mpirank', 'status', 'rho', 'xMomentum', 'yMomentum', 'zMomentum', 'totalEnergy']

        # Properties modified on fileReader
        fileReader.CellArrayStatus = ['treeid', 'mpirank', 'rho', 'xMomentum', 'yMomentum', 'zMomentum', 'totalEnergy']

        # get active view
        renderView1 = GetActiveViewOrCreate('RenderView')
        renderView1.OrientationAxesVisibility = 0
        # uncomment following to set a specific view size
        # renderView1.ViewSize = [1376, 845]

        # show data in view
        fileReaderDisplay = Show(fileReader, renderView1)
        # trace defaults for the display properties.
        fileReaderDisplay.ColorArrayName = [None, '']
        fileReaderDisplay.ScalarOpacityUnitDistance = 0.009934439403087353

        # reset view to fit data
        renderView1.ResetCamera()

        # create a new 'Slice'
        slice1 = Slice(Input=fileReader)
        slice1.SliceType = 'Plane'
        slice1.SliceOffsetValues = [0.0]

        # init the 'Plane' selected for 'SliceType'
        slice1.SliceType.Origin = [1.5, 0.5, 0.0]

        # toggle 3D widget visibility (only when running from the GUI)
        Hide3DWidgets(proxy=slice1)

        # Properties modified on slice1
        slice1.Triangulatetheslice = 0

        # Properties modified on slice1.SliceType
        slice1.SliceType.Normal = [0.0, 0.0, 1.0]

        # show data in view
        slice1Display = Show(slice1, renderView1)
        # trace defaults for the display properties.
        slice1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(fileReader, renderView1)

        # create a new 'Calculator'
        calculator1 = Calculator(Input=slice1)
        calculator1.Function = ''

        # Properties modified on calculator1
        calculator1.AttributeMode = 'Cell Data'
        calculator1.ResultArrayName = 'Velocity'
        calculator1.Function = 'xMomentum/rho*iHat+yMomentum/rho*jHat+zMomentum/rho*kHat'

        # show data in view
        calculator1Display = Show(calculator1, renderView1)
        # trace defaults for the display properties.
        calculator1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(slice1, renderView1)

        # get layout
        viewLayout1 = GetLayout()

        # split cell
        viewLayout1.SplitHorizontal(0, 0.5)

        # set active view
        SetActiveView(None)

        # Create a new 'Render View'
        renderView2 = CreateView('RenderView')
        renderView2.ViewSize = [684, 845]
        renderView2.Background = [0.32, 0.34, 0.43]

        # place view in the layout
        viewLayout1.AssignView(2, renderView2)

        # set active view
        SetActiveView(renderView1)

        # set active view
        SetActiveView(renderView2)

        # reset view to fit data
        renderView2.ResetCamera()

        # set active view
        SetActiveView(renderView1)

        # set active source
        SetActiveSource(calculator1)

        # reset view to fit data
        renderView1.ResetCamera()

        # set scalar coloring
        ColorBy(calculator1Display, ('CELLS', 'Velocity'))

        # rescale color and/or opacity maps used to include current data range
        calculator1Display.RescaleTransferFunctionToDataRange(True)

        # show color bar/color legend
        calculator1Display.SetScalarBarVisibility(renderView1, True)

        # get color transfer function/color map for 'Velocity'
        velocityLUT = GetColorTransferFunction('Velocity')
        velocityLUT.RGBPoints = [2.7716872731675397, 0.231373, 0.298039, 0.752941, 2.88584363658377, 0.865003, 0.865003, 0.865003, 3.0, 0.705882, 0.0156863, 0.14902]
        velocityLUT.ScalarRangeInitialized = 1.0

        # get opacity transfer function/opacity map for 'Velocity'
        velocityPWF = GetOpacityTransferFunction('Velocity')
        velocityPWF.Points = [2.7716872731675397, 0.0, 0.5, 0.0, 3.0, 1.0, 0.5, 0.0]
        velocityPWF.ScalarRangeInitialized = 1

        # reset view to fit data
        renderView1.ResetCamera()

        # create a new 'Cell Data to Point Data'
        cellDatatoPointData1 = CellDatatoPointData(Input=calculator1)

        # show data in view
        cellDatatoPointData1Display = Show(cellDatatoPointData1, renderView1)
        # trace defaults for the display properties.
        cellDatatoPointData1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(calculator1, renderView1)

        # set scalar coloring
        ColorBy(cellDatatoPointData1Display, ('POINTS', 'Velocity'))

        # rescale color and/or opacity maps used to include current data range
        cellDatatoPointData1Display.RescaleTransferFunctionToDataRange(True)

        # show color bar/color legend
        cellDatatoPointData1Display.SetScalarBarVisibility(renderView1, True)

        # hide color bar/color legend
        cellDatatoPointData1Display.SetScalarBarVisibility(renderView1, False)

        # set active view
        SetActiveView(renderView2)

        # create a new 'Glyph'
        glyph1 = Glyph(Input=cellDatatoPointData1,
                GlyphType='Arrow')
        glyph1.Scalars = ['POINTS', 'xMomentum']
        glyph1.Vectors = ['POINTS', 'Velocity']
        glyph1.ScaleMode = 'vector_components'
        glyph1.ScaleFactor = 0.05

        glyph1.GlyphTransform = 'Transform2'

        # get color transfer function/color map for 'xMomentum'
        xMomentumLUT = GetColorTransferFunction('xMomentum')
        xMomentumLUT.RGBPoints = [2.9800820350646973, 0.231373, 0.298039, 0.752941, 2.9900410175323486, 0.865003, 0.865003, 0.865003, 3.0, 0.705882, 0.0156863, 0.14902]
        xMomentumLUT.ScalarRangeInitialized = 1.0

        # show data in view
        glyph1Display = Show(glyph1, renderView2)
        # trace defaults for the display properties.
        glyph1Display.ColorArrayName = ['POINTS', 'xMomentum']
        glyph1Display.LookupTable = xMomentumLUT

        # reset view to fit data
        renderView2.ResetCamera()

        # get opacity transfer function/opacity map for 'xMomentum'
        xMomentumPWF = GetOpacityTransferFunction('xMomentum')
        xMomentumPWF.Points = [2.9800820350646973, 0.0, 0.5, 0.0, 3.0, 1.0, 0.5, 0.0]
        xMomentumPWF.ScalarRangeInitialized = 1

        # hide color bar/color legend
        glyph1Display.SetScalarBarVisibility(renderView2, False)

        # reset view to fit data
        renderView2.ResetCamera()

        # Properties modified on glyph1
        glyph1.ScaleMode = 'vector'

        # reset view to fit data
        renderView2.ResetCamera()

        # Properties modified on glyph1Display
        glyph1Display.Opacity = 0.5

        # create a new 'Contour'
        contour1 = Contour(Input=glyph1)
        contour1.ContourBy = ['POINTS', 'xMomentum']
        contour1.Isosurfaces = [2.9900410175323486]
        contour1.PointMergeMethod = 'Uniform Binning'

        # Properties modified on contour1
        contour1.ContourBy = ['POINTS', 'rho']
        contour1.Isosurfaces = [1.0, 1.0015344897959184, 1.0030689795918366, 1.0046034693877552, 1.0061379591836734, 1.0076724489795919, 1.0092069387755103, 1.0107414285714287, 1.0122759183673469, 1.0138104081632653, 1.0153448979591837, 1.0168793877551021, 1.0184138775510203, 1.0199483673469387, 1.0214828571428571, 1.0230173469387756, 1.024551836734694, 1.0260863265306124, 1.0276208163265306, 1.029155306122449, 1.0306897959183674, 1.0322242857142858, 1.033758775510204, 1.0352932653061224, 1.0368277551020408, 1.0383622448979593, 1.0398967346938774, 1.0414312244897959, 1.0429657142857143, 1.0445002040816327, 1.046034693877551, 1.0475691836734695, 1.049103673469388, 1.0506381632653063, 1.0521726530612245, 1.053707142857143, 1.0552416326530611, 1.0567761224489796, 1.058310612244898, 1.0598451020408164, 1.0613795918367348, 1.0629140816326532, 1.0644485714285716, 1.0659830612244898, 1.0675175510204082, 1.0690520408163267, 1.0705865306122448, 1.0721210204081633, 1.0736555102040817, 1.07519]

        # show data in view
        contour1Display = Show(contour1, renderView2)
        # trace defaults for the display properties.
        contour1Display.ColorArrayName = [None, '']

        # hide data in view
        Hide(glyph1, renderView2)

        # reset view to fit data
        renderView2.ResetCamera()

        # Properties modified on contour1
        contour1.Isosurfaces = [1.0, 1.0083544444444443, 1.0167088888888889, 1.0250633333333334, 1.0334177777777778, 1.0417722222222223, 1.0501266666666669, 1.0584811111111112, 1.0668355555555555, 1.07519]

        # set active view
        SetActiveView(renderView1)

        # set active source
        SetActiveSource(cellDatatoPointData1)

        # reset view to fit data
        renderView1.ResetCamera()

        # set active view
        SetActiveView(renderView2)

        # set active source
        SetActiveSource(glyph1)

        # show data in view
        glyph1Display = Show(glyph1, renderView2)

        # hide color bar/color legend
        glyph1Display.SetScalarBarVisibility(renderView2, False)

        # reset view to fit data
        renderView2.ResetCamera()

        # set active view
        SetActiveView(renderView1)

        # current camera placement for renderView1
        renderView1.CameraPosition = [1.5750000476837158, 0.4999999925494194, 7.81776063600701]
        renderView1.CameraFocalPoint = [1.5750000476837158, 0.4999999925494194, 0.0]
        renderView1.CameraParallelScale = 2.047162736490416

        # save Velocity screenshot
        velocityImageName = path.splitext(fileName)[0] + "_velocity_" + str(count) + ".png"
        print "\tExporting %s" % velocityImageName
        SaveScreenshot(velocityImageName, magnification=3, quality=100, view=renderView1)

        # set active view
        SetActiveView(renderView2)

        # current camera placement for renderView2
        renderView2.CameraPosition = [1.5750000476837158, 0.4999999925494194, 7.81776063600701]
        renderView2.CameraFocalPoint = [1.5750000476837158, 0.4999999925494194, 0.0]
        renderView2.CameraParallelScale = 2.047162736490416

        # save Density contour screenshot
        densityImageName = path.splitext(fileName)[0] + "_density_" + str(count) + ".png"
        print "\tExporting %s" % densityImageName
        SaveScreenshot(densityImageName, magnification=3, quality=100, view=renderView2)

        count = count + 1

        # set active source
        SetActiveSource(None)

        # set active view
        SetActiveView(None)

        #### saving camera placements for all active views

        # current camera placement for renderView1_1

        #### uncomment the following to render all views
        # RenderAllViews()
        # alternatively, if you want to write images, you can use SaveScreenshot(...).
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the ParaView Wiki at: 
http://paraview.org/Wiki/ParaView

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/paraview

Reply via email to