Пример #1
0
    def contourf_paraview(self, array):
        assert array in self.reader.PointArrays
        renderView = pvs.GetActiveViewOrCreate("RenderView")

        # get color transfer function/color map for 'array'
        LUT = pvs.GetOpacityTransferFunction(array)

        # get color legend/bar for LUT in view renderView
        LUTColorBar = pvs.GetScalarBar(LUT, renderView)
        return renderView, LUTColorBar
Пример #2
0
def display_data(prefix,
                 data_dir,
                 render_view,
                 label,
                 color_func,
                 representation='Surface'):
    reader = pvs.LegacyVTKReader(FileNames=get_sample_fnames(prefix, data_dir),
                                 registrationName=label)
    display = pvs.Show(reader, render_view)
    display.Representation = representation
    display.ColorArrayName = ['CELLS', label]
    display.LookupTable = color_func
    display.ScaleFactor = 50.0
    display.SelectScaleArray = label
    display.GlyphTableIndexArray = label
    display.UseSeparateColorMap = True
    #print(dir(display))
    color_bar = pvs.GetScalarBar(color_func, render_view)
    color_bar.Title = label
    color_bar.ComponentTitle = ''
    color_bar.ScalarBarLength = 0.12
    display.SetScalarBarVisibility(render_view, True)
Пример #3
0
    def colorBy(self, representation, field):
        view = self.viewSubSurface if representation == self.subSurfaceRepresentation else self.viewSurface
        representation.SetScalarBarVisibility(view, False)

        simple.ColorBy(representation, ['CELLS', field])
        applyColorMap(representation)

        representation.SetScalarBarVisibility(view, True)

        lut = simple.GetColorTransferFunction(field)
        colorBar = simple.GetScalarBar(lut, view)

        colorBar.Enabled = 1
        colorBar.Selectable = 0
        colorBar.AutoOrient = 0
        colorBar.AutomaticLabelFormat = 1
        colorBar.AddRangeLabels = 0
        colorBar.ScalarBarLength = 0.9
        colorBar.LabelColor = [0, 0, 0]
        colorBar.Position = [0.8, 0.05]
        colorBar.LockPosition = 1
        colorBar.Repositionable = 1
        colorBar.Resizable = 1
        colorBar.TitleColor = [0, 0, 0]
        class Pipeline:

            grid = coprocessor.CreateProducer(datadescription, 'input')

            # Normalise radius - simplifies creating glyphs
            normalise = pvs.Calculator(Input=grid)
            normalise.CoordinateResults = 1
            normalise.Function = 'coords/%i' % sphere_radius

            # Visualise velocity field using arrows
            glyph = pvs.Glyph(Input=normalise, GlyphType='Arrow')
            glyph.Scalars = ['POINTS', 'None']
            glyph.Vectors = ['CELLS', 'u']
            glyph.ScaleFactor = 0.2
            glyph.GlyphTransform = 'Transform2'
            glyph.GlyphType.TipResolution = 12
            glyph.GlyphType.TipRadius = 0.05
            glyph.GlyphType.ShaftRadius = 0.015

            # Create a new 'Render View'
            renderView = pvs.CreateView('RenderView')
            renderView.ViewSize = [1500, 768]
            renderView.AxesGrid = 'GridAxes3DActor'
            renderView.StereoType = 0
            renderView.CameraPosition = [-5, -2, 4]
            renderView.CameraViewUp = [0.5, 0.3, 0.8]
            renderView.CameraParallelScale = 1.7
            renderView.Background = [0.32, 0.34, 0.43]

            # Register the view with coprocessor
            # and provide it with information such as the filename to use,
            # how frequently to write the images, etc.
            coprocessor.RegisterView(renderView,
                                     filename='velocity_field_%t.png',
                                     freq=1,
                                     fittoscreen=1,
                                     magnification=1,
                                     width=800,
                                     height=800,
                                     cinema={})
            renderView.ViewTime = datadescription.GetTime()

            # Create colour transfer function for velocity field
            uLUT = pvs.GetColorTransferFunction('u')
            uLUT.RGBPoints = [
                1.7, 0.23, 0.30, 0.75, 20.9, 0.87, 0.87, 0.87, 40.0, 0.71,
                0.016, 0.15
            ]
            uLUT.ScalarRangeInitialized = 1.0

            # Show velocity field magnitude
            velocitymagDisplay = pvs.Show(normalise, renderView)
            velocitymagDisplay.Representation = 'Surface'
            velocitymagDisplay.ColorArrayName = ['CELLS', 'u']
            velocitymagDisplay.LookupTable = uLUT

            # Show colour legend
            uLUTColorBar = pvs.GetScalarBar(uLUT, renderView)
            uLUTColorBar.Title = 'u'
            uLUTColorBar.ComponentTitle = 'Magnitude'
            velocitymagDisplay.SetScalarBarVisibility(renderView, True)

            # Show velocity field glyphs
            glyphDisplay = pvs.Show(glyph, renderView)
            glyphDisplay.Representation = 'Surface'
            glyphDisplay.ColorArrayName = [None, '']
Пример #5
0
    -1e-10, 0.231373, 0.298039, 0.752941, 0, 1.0, 1.0, 1.0, 1e-10, 0.705882,
    0.0156863, 0.14902
]
LUT.NanColor = [0.500008, 0.0, 0.0]
LUT.ScalarRangeInitialized = 1.0

# get any opacity transfer function/opacity map
# Not used so far
PWF = simple.GetOpacityTransferFunction('HalliGalli')
PWF.Points = [-1e-10, 0.0, 0.5, 0.0, 1e-10, 1.0, 0.5, 0.0]
PWF.ScalarRangeInitialized = 1

# setup the color legend parameters for each legend in this view

# get color legend/bar for LUT in view renderView1
LUTColorBar = simple.GetScalarBar(LUT, renderView1)
LUTColorBar.Position = [0.8322310304209063, 0.50956937799043066]
LUTColorBar.Position2 = [0.12, 0.43000000000000077]
LUTColorBar.Title = 'K_x [s/m^3]'
LUTColorBar.ComponentTitle = ''
LUTColorBar.TitleColor = [0.3137, 0.3137, 0.3137]
LUTColorBar.LabelColor = [0.3137, 0.3137, 0.3137]

# Loop over all Point variables in file and print them
for data in kerner_kernelxdmf.PointData:
    if data.Name[0:3] == 'K_x':

        # Get complete array of this variable
        npoints = kerner_all.GetNumberOfPoints()
        data_list = []
        for i in range(0, npoints):
        class Pipeline:

            grid = coprocessor.CreateProducer(datadescription, 'input')

            # Simulation domain outline
            outline = pvs.Outline(Input=grid)

            # Horizontal slice at the bottom
            slice = pvs.Slice(Input=grid)
            slice.SliceType = 'Plane'
            slice.SliceOffsetValues = [0.0]
            slice.SliceType.Origin = [0.0, 0.0, 101.94]
            slice.SliceType.Normal = [0.0, 0.0, 1.0]
            slice.Triangulatetheslice = False

            # Glyphs for representing velocity field
            glyph = pvs.Glyph(Input=grid, GlyphType='Arrow')
            glyph.Vectors = ['CELLS', 'u']
            glyph.ScaleMode = 'vector'
            glyph.ScaleFactor = 0.01
            glyph.GlyphMode = 'Every Nth Point'
            glyph.Stride = 200

            # Create a new render view
            renderView = pvs.CreateView('RenderView')
            renderView.ViewSize = [800, 400]
            renderView.InteractionMode = '2D'
            renderView.AxesGrid = 'GridAxes3DActor'
            renderView.CenterOfRotation = [0.18, 0.0, 102]
            renderView.StereoType = 0
            renderView.CameraPosition = [-3.4, -6.8, 107]
            renderView.CameraFocalPoint = [-0.27, -0.41, 102]
            renderView.CameraViewUp = [0.057, 0.49, 0.87]
            renderView.CameraParallelScale = 1.0
            renderView.Background = [0.32, 0.34, 0.43]

            # Register the view with coprocessor
            coprocessor.RegisterView(renderView,
                                     filename='image_%t.png',
                                     freq=1,
                                     fittoscreen=0,
                                     magnification=1,
                                     width=800,
                                     height=400,
                                     cinema={})
            renderView.ViewTime = datadescription.GetTime()

            # Get color transfer function/color map for field rho
            rhoLUT = pvs.GetColorTransferFunction('rho')
            rhoLUT.RGBPoints = [
                1.17, 0.231, 0.298, 0.752, 1.33, 0.865, 0.865, 0.865, 1.49,
                0.706, 0.0157, 0.149
            ]
            rhoLUT.ScalarRangeInitialized = 1.0

            # Show slice
            sliceDisplay = pvs.Show(slice, renderView)
            sliceDisplay.Representation = 'Surface With Edges'
            sliceDisplay.ColorArrayName = ['CELLS', 'rho']
            sliceDisplay.LookupTable = rhoLUT
            sliceDisplay.ScaleFactor = 0.628
            sliceDisplay.SelectScaleArray = 'None'
            sliceDisplay.GlyphType = 'Arrow'
            sliceDisplay.GlyphTableIndexArray = 'None'
            sliceDisplay.DataAxesGrid = 'GridAxesRepresentation'
            sliceDisplay.PolarAxes = 'PolarAxesRepresentation'
            sliceDisplay.GaussianRadius = 0.314
            sliceDisplay.SetScaleArray = [None, '']
            sliceDisplay.ScaleTransferFunction = 'PiecewiseFunction'
            sliceDisplay.OpacityArray = [None, '']
            sliceDisplay.OpacityTransferFunction = 'PiecewiseFunction'

            # Show color legend
            sliceDisplay.SetScalarBarVisibility(renderView, True)

            # Show glyph
            glyphDisplay = pvs.Show(glyph, renderView)

            # Show outline
            outlineDisplay = pvs.Show(outline, renderView)

            # Get color legend/bar for rhoLUT in view renderView
            rhoLUTColorBar = pvs.GetScalarBar(rhoLUT, renderView)
            rhoLUTColorBar.WindowLocation = 'LowerRightCorner'
            rhoLUTColorBar.Title = 'rho'
            rhoLUTColorBar.ComponentTitle = ''
Пример #7
0
# get color transfer function/color map for 'velocity_mag'
velocity_magLUT = pv.GetColorTransferFunction('velocity_mag')
velocity_magLUT.RGBPoints = [0.0010371223324909806, 0.231373, 0.298039, 0.752941, 0.7069325454649515, 0.865003, 0.865003, 0.865003, 1.412827968597412, 0.705882, 0.0156863, 0.14902]
velocity_magLUT.ScalarRangeInitialized = 1.0

# get opacity transfer function/opacity map for 'velocity_mag'
velocity_magPWF = pv.GetOpacityTransferFunction('velocity_mag')
velocity_magPWF.Points = [0.0010371223324909806, 0.0, 0.5, 0.0, 1.412827968597412, 1.0, 0.5, 0.0]
velocity_magPWF.ScalarRangeInitialized = 1

# Apply a preset using its name. Note this may not work as expected when presets have duplicate names.
velocity_magLUT.ApplyPreset('Inferno (matplotlib)', True)

# get color legend/bar for velocity_magLUT in view renderView1
velocity_magLUTColorBar = pv.GetScalarBar(velocity_magLUT, renderView1)
velocity_magLUTColorBar.Title = 'velocity_mag'
velocity_magLUTColorBar.ComponentTitle = ''

# change scalar bar placement
velocity_magLUTColorBar.WindowLocation = 'AnyLocation'
velocity_magLUTColorBar.Position = [0.9087500000000001, 0.5390781563126252]
velocity_magLUTColorBar.ScalarBarLength = 0.3300000000000002

# change scalar bar placement
velocity_magLUTColorBar.Position = [0.9087500000000001, 0.13827655310621242]
velocity_magLUTColorBar.ScalarBarLength = 0.7308016032064131

# Rescale transfer function
velocity_magLUT.RescaleTransferFunction(0.0010371223324909806, 1.0)