# .vtr Import & Isosurfaces

**URL:** https://discourse.vtk.org/t/vtr-import-isosurfaces/506
**Category:** Support
**Created:** [March 16, 2019, 4:21pm UTC](https://discourse.vtk.org/t/vtr-import-isosurfaces/506 "2019-03-16T16:21:55Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![S97](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@S97](https://discourse.vtk.org/u/S97)
#### Post date: [March 16, 2019, 4:21pm UTC](https://discourse.vtk.org/t/vtr-import-isosurfaces/506/1 "2019-03-16T16:21:55Z")

</div>

Hello all,

I was wondering if I could get some help/clarification on a few things.

I have a 30x30x30 rectilinear grid vtk file, this has been pre generated using the pyevtk python extension(GridToVtk). I have successfully read it in and applied the vtkRectilinearGridGeometryFilter() which once renders allows me to view all the points of this grid.

In my grid, each point has 10 variables which I want to now use this data to draw isosurfaces. I cant seem to figure how I can access these ‘varaibles’ inside VTK which are stored at each point.

I have done lots of research into vtkContourFilter and MarchingCubes and fully understand how they work. I am not just sure how to set them to ‘draw’ on the point data variables inside the grid.

Thanks

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [March 17, 2019, 2:26am UTC](https://discourse.vtk.org/t/vtr-import-isosurfaces/506/2 "2019-03-17T02:26:30Z")

</div>

@S97, the scalar arrays your looking for can be accessed under the `PointData` of your dataset:

```python
...
arr = dataset.GetPointData().GetScalar('scalar name')

```

When using algorithms like `vtkContourFilter` where a scalar array is proccessed, you’ll have to call `.SetInputArrayToProcess(**args)`:

```python
alg = vtk.vtkContourFilter()
alg.SetInputDataObject(dataset)

# args: (idx, port, connection, field, name)
alg.SetInputArrayToProcess(0, 0, 0, field, scalars)

# make 10 contours between range -1 and 1
alg.GenerateValues(10, [-1, 1])
alg.Update()

result = alg.GetOutput()

```

## Easier Implementation

You may benefit from giving [`vtki`](http://docs.vtki.org) a try - it’s a streamlined Python interface to VTK. Your problem description would translate to:

```python
import vtki
import numpy as np

#######

# Create a similar dataset (30 by 30 by 30)
xrng = yrng = zrng = np.arange(-15, 15, 1)
grid = vtki.RectilinearGrid(xrng, yrng, zrng)
# Add ten scalar arrays
for i in range(10):
    grid.cell_arrays['scalar-{}'.format(i)] = np.random.rand(grid.n_cells)

# Or load from a data file
# grid = vtki.read('my-file.vtr')

#######

# Move all data to nodes
nodal = grid.cell_data_to_point_data()

# Extract external surface
geom = nodal.extract_geometry()

# Countour the 3D volume by the 'scalar-2' array
contours = nodal.contour(scalars='scalar-2')

# Plot by some other array
contours.plot(scalars='scalar-5')

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/25afe53a1a38ea4624b621be28cb2f9c720b4a94.png)

---

<div class="post-metadata">

### Author: ![S97](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/71c47a/32.png) [@S97](https://discourse.vtk.org/u/S97)
#### Post date: [March 17, 2019, 10:41am UTC](https://discourse.vtk.org/t/vtr-import-isosurfaces/506/4 "2019-03-17T10:41:05Z")

</div>

Great thank you, I have successfully managed to get both methods working! Thanks for your quick and detailed reply. I have just one follow up question.

I am struggling to understand the arguments for SetInputArrayToProcess. I currently have them as 0,0,0,0,[‘u’]). With ‘u’ being the scalars value in the array. Im unsure how they all link and how I can change etc. The information on the doc is hard to understand.

Also, when I set ‘arr = output.GetPointData().GetScalars(‘u’)’… I never actually use ‘arr’. Do I need this?

Thanks

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [March 17, 2019, 3:48pm UTC](https://discourse.vtk.org/t/vtr-import-isosurfaces/506/5 "2019-03-17T15:48:56Z")

</div>

> [@S97](#):
>
> arguments for SetInputArrayToProcess. I currently have them as 0,0,0,0,[‘u’]). With ‘u’ being the scalars value in the array

Try just passing the string name, not a list:

```python
# args: (idx, port, connection, field, name)
alg.SetInputArrayToProcess(0, 0, 0, 0, 'u')

```

> [@S97](#):
>
> Also, when I set ‘arr = output.GetPointData().GetScalars(‘u’)’… I never actually use ‘arr’. Do I need this?

You don’t need it - I was demonstrating a way to access the various scalar arrays
