# vtkContourGrid example

**URL:** https://discourse.vtk.org/t/vtkcontourgrid-example/10455
**Category:** Support
**Created:** [January 14, 2023, 5:33pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455 "2023-01-14T17:33:16Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [January 14, 2023, 5:33pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/1 "2023-01-14T17:33:16Z")

</div>

I am looking for a vtkContourGrid example since I couldn’t find one with the online vtkContourGrid class documentation.

I have scalar cell data assigned to my vtkUnstructuredGrid object. Based on the vtkContourFilter examples, I think that output from the vtkUnstructuredGrid object can be read into the vtkContourGrid.

If this works, do I then need to process normals for the contour surface?

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [January 15, 2023, 5:05pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/2 "2023-01-15T17:05:25Z")

</div>

vtkContourFilter calls vtkContourGrid internally when unstructured grid are processed, and i am pretty sure there are examples out there for vtkContourFilter .

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [January 15, 2023, 5:24pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/3 "2023-01-15T17:24:44Z")

</div>

Maybe I misunderstood, but contouring operations require point data (you refer to cell data).

---

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [January 15, 2023, 7:51pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/4 "2023-01-15T19:51:07Z")

</div>

Yes. I only have cell data available.

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [January 15, 2023, 9:26pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/5 "2023-01-15T21:26:19Z")

</div>

you can consider using vtkCellDataToPointData so that you have the array of cell data that you want interpolated as an array of point data and then use it as input for the contour filter.

---

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [January 16, 2023, 2:29pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/6 "2023-01-16T14:29:27Z")

</div>

I thought that there might be a method to convert cell data to point. I know that I wouldn’t have found that routine without asking. I’ll look into it.

---

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [January 18, 2023, 8:59pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/7 "2023-01-18T20:59:47Z")

</div>

To wrap this up, I was able to get this to work. This is all that I needed in this particular case:

```
            vtkNew<vtkCellDataToPointData> c2p;
            c2p->SetInputData(ugrid);

            vtkNew<vtkContourFilter> contour;
            contour->SetInputConnection(0, c2p->GetOutputPort(0));

```

Of course there is other code, but this is the essentials to the question that I asked.

I’ve a follow on to this I’ll put in another post.

---

<div class="post-metadata">

### Author: ![BlueKnight7](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/b/838e76/32.png) [@BlueKnight7](https://discourse.vtk.org/u/BlueKnight7)
#### Post date: [January 24, 2023, 7:35pm UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/8 "2023-01-24T19:35:10Z")

</div>

Using what I last posted to this topic, I’m not convinced that the cell data is being converted to point data as I thought it would. When I co-plot the cell data with a contour from the converted data, the two don’t align. That is, the contour doesn’t coincide with the cell data.

Is there a way that I can dump some of the data to see what is going on?

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [January 31, 2023, 3:17am UTC](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/9 "2023-01-31T03:17:11Z")

</div>

The vtkCellDataToPointData is a highly tested filter and it’s doing what it is supposed to do. But you should know that point values are set by averaging the neighboring cells, no weighted averaging the neighboring cells, that’s why you probably don’t get the results you expect.
