# Checking for contours of zero size

**URL:** https://discourse.vtk.org/t/checking-for-contours-of-zero-size/10491
**Category:** Support
**Created:** [January 18, 2023, 9:16pm UTC](https://discourse.vtk.org/t/checking-for-contours-of-zero-size/10491 "2023-01-18T21:16:42Z")
**Posts on this page:** 3
**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 18, 2023, 9:16pm UTC](https://discourse.vtk.org/t/checking-for-contours-of-zero-size/10491/1 "2023-01-18T21:16:42Z")

</div>

This is a follow on off [vtkContourGrid example - #7 by BlueKnight7](https://discourse.vtk.org/t/vtkcontourgrid-example/10455/7) and requires a little background detail first.

I’ve setup my code to have multiple mesh objects using vtkUnstructuredGrid’s. I want to be able to create contours, but I know that some contours will not exist in some vtkUnstructuredGrid objects. Is there a way to check the vtkContourFilter (object) or the resulting vtkPolyDataMapper (object) to determine if there is anything there to display? I couldn’t spot anything in the online documentation for these 2 classes that would give me a size that I could check. It’s possible that I’m not looking at the right place.

With how I have this coded at the moment, I have a bunch of zero-sized contours / mappers that are created but aren’t displayed with the actors that are created from them. By zero-size, I mean that the objects exist, but they don’t contain any information that is displayed.

I’m open to suggestion on how to deal with the situation that I’ve just described.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [January 19, 2023, 3:23pm UTC](https://discourse.vtk.org/t/checking-for-contours-of-zero-size/10491/2 "2023-01-19T15:23:13Z")

</div>

Roger,

You could look at the data object output from the vtkContourFilter and check for the number of cells being greater than 0, eg.

```auto
vtkNew<vtkContourFilter> contour;
...
contour->Update();
vtkPolyData* pd = contour->GetOutput();
if (pd->GetNumberOfCells() < 1)
{
  // skip creation of mapper/actor
}

```

Hope that helps.

---

<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 19, 2023, 9:41pm UTC](https://discourse.vtk.org/t/checking-for-contours-of-zero-size/10491/3 "2023-01-19T21:41:47Z")

</div>

Cory,

That worked. Although, I would prefer that the vtkContourFilter GenerateValues function return something like a boolean: true is success in generating contours or false for no contours generated.

BK
