Checking for contours of zero size

This is a follow on off vtkContourGrid example - #7 by BlueKnight7 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.

Roger,

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

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

Hope that helps.

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