C++ – 3D contour plot C++ example using VTK


I tried to use VTK library from C++.

Is there any example of using VTK just to plot simple 3D contour graph like the one shown below?

The official VTK Wiki has dozens of code examples, but I cannot find any useful example of this simple task.

a 3d plot

Best Solution

I believe a rough sketch of a VTK pipeline that may work for you is as follows. If you create some x and y points as vtkPoints and then move them to the StructuredGrid datatype and then add the z-axis using the GeometryFilter you should produce a surface that by going through vtkWarpScalar and the usual Mapper and Actor pipeline.

The following example code may help /Examples/DataManipulation/Cxx/SGrid.cxx in your vtk build. Surface plotting could also be performed if you had a complete volume and extracted and isosurface. If that's not the case and you are plotting a 3D function, probably populating a structured grid is the way to go.

Related Question