Forge Analytics

Creating Slices in ParaView

Instructions for creating slices in ParaView.

Overview

This article is intended to serve as an overview for creating slices from 3D data in ParaView.

For the purposes of this article, we will be using Paraview 5.4.1.

For installation instructions, please see the guide for CPU-based rendering or GPU-based rendering.

For help running ParaView scripts, please see the batch-execution instructions.

Manual Instructions

Before beginning, load your 3D data with whatever loader is appropriate for your use case. In this example, we’ve loaded the motorbike tutorial from OpenFOAM. To load an OpenFOAM case to ParaView, create a file called run.foam in the case directory.

1) With your data proxy selected in the pipeline browser on the left, click the “Slice” button on the “Common” toolbar at the top, or go to Filters >> Common >> Slice in the top menu.

Slice Button

2) Next, in the “Properties” tab for the Slice object, define your Origin point and Normal vector. Then hit “Apply”.

Slice Settings

3) Finally, set your camera view and slice representation.

Slice Final

Scripted Instructions

To create a slice in ParaView, first import the necessary module.

import paraview.simple

Loading the Data

In this guide, we’ll use the motorbike tutorial from OpenFOAM, as we did in the manual tutorial above. Your use-case may require a different procedure.

To create the slice, you’ll need to first begin with a 3D dataset in your Pipeline Browser.

Loading this case can be done with:

case = paraview.simple.OpenFOAMReader(FileName='/path/to/motorbike/run.foam')
case.MeshRegions = ['internalMesh']
case.CellArrays = ['U', 'p']

Where case.MeshRegions corresponds to the “Mesh Regions” selection you made in the “Properties” tab when loading the case manually, and case.CellArrays corresponds to the manual selection for “Cell Arrays”.

In this case, “internalMesh” is the 3D fluid data, and we are only interested in loading our velocity and pressure fields.

We’ll also create a RenderView window to display our slice, and set its resolution.

render_view = paraview.simple.GetActiveViewOrCreate('RenderView')
render_view.ViewSize = [1920, 1080]

Creating the Slice

To create the slice, first create the data object.

slice = paraview.simple.Slice(Input=case)
slice.SliceType = 'Plane'
slice.SliceOffsetValues = [0.0]

Additionally, set the origin point and normal vector for the slice.

slice.SliceType.Origin = [0.0, 0.0, 0.0]
slice.SliceType.Normal = [0.0, 1.0, 0.0]

Finally, show the data in your view and update the view.

slice_display = paraview.simple.Show(slice, render_view)
render_view.Update()

At this point, you can adjust the properties of your slice_display object to set its representation, adjust the legend, etc.

Note that you may need to hide the 3D data that the slice was created from, in case it was already displayed. This can be done with:

paraview.simple.Hide(case, render_view)

Similarly, if you have an active source that’s highlighted in the view, and wish to turn it off for screenshot capture, you can use:

paraview.simple.SetActiveSource(None)

Have a Question?

Contact Us