Help: Contour lines displayed discontinous

I’m new on VTK, there’s a problem I do not know how to resolve: Select a contour to display using vtkContourFilter (The input data is a vtkUnstructuredGrid)

filter->SetInputData(grid);
filter->SetValue(0, 0.0);
filter->SetComputeScalars(true);
filter->SetNumberOfContours(10);
filter->Update();

actor->GetProperty()->SetLineWidth(3.);
actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
actor->GetProperty()->SetLineStipplePattern(0x1C47);

I also set the actor to make the display thick, but the displayed line still not continous.

Please give a direct help ( I’m not familiar with VTK).

Hi,

You commanded VTK to display the lines with a stippled pattern. Either change the argument of

to 0xFFFF to have a solid pattern or simply comment that line out.

More on actor properties: VTK: vtkProperty2D Class Reference

take care,

PC

Hi Paulo,
Thanks for your replay. After comment out the below two lines, the final display is the same discontinous:

filter->SetInputData(grid);
filter->SetValue(0, 0.0);
filter->SetComputeScalars(true);
// filter->SetNumberOfContours(10);
filter->Update();

actor->GetProperty()->SetLineWidth(3.);
actor->GetProperty()->SetColor(1.0, 0.0, 0.0);
// actor->GetProperty()->SetLineStipplePattern(0x1C47);

Below is another test result(which same whenever the two lines exist or comment out):

Do you think does need a customized contour filter ? Or any other guidances are appreciated.

Hi,

That’s an odd shape for contour lines. I maybe wrong, but I think you want to render the outline of an object and not contour lines. A contour filter won’t display the outline of watever you want. A vtkOutlineFilter will do: https://examples.vtk.org/site/Cxx/PolyData/Outline/ .

take care,

PC

If you are sure you want contour lines, please review the parameters passed to vtkContourFilter.

Here’s how I setup mine:

    vtkSmartPointer<vtkContourFilter> contourFilter = vtkSmartPointer<vtkContourFilter>::New();
    contourFilter->SetInputData( imageData );
    contourFilter->GenerateValues( 20, min, max); // (numContours, rangeStart, rangeEnd)
    contourFilter->Update();

Notice the importance of GenerateValues() which is missing in your code.

best,

PC

Hi Paulo,

Thanks for patience.

Apologize I’m not descripbe the background of my work requirement clearly.

At fist, there’s indeed contour display module in the work project. And the contour display module show the simulation field data use

contourFilter->GenerateValues(5, min, max);

Second, there’s another requirement to display the specified contour (value == 0) which has special meaning (So it displayed using highlight color, e.g. red).

I ask the chatGPT and got the answer using SetValue without GenerateValues:

// contourFilter->GenerateValues(5, min, max);
contourFilter->SetValue(0, 0.0);

Please correct me if this is wrong.

If you’re getting an unexpected contour line for 0.0, then you have to check the data or the simulation result. Try to get a histogram of the results or display the grid as is.