I want to convert UnstructuredGrid data to PolyData, and then to ImageData, so that I can use the Marching cubes algorithm.

I use vtkSurfaceDataSetFilter to convert UnStrcuturedGrid Data to PolyData,then transfer the converted data into the method I wrote according to the PolyDataToImageData provided by VTK.
the main function:

vtkSmartPointer<vtkUnstructuredGridReader> reader = vtkSmartPointer<vtkUnstructuredGridReader>::New();
reader->SetFileName(filename.c_str());
reader->Update();
surrfaceFliter->SetInputConnection(reader->GetOutputPort());
vtkSmartPointer<vtkImageData> imageData = vtkSmartPointer<vtkImageData>::New();
vtkSmartPointer<vtkPolyData> pData = vtkSmartPointer<vtkPolyData>::New();
pData = geometryFilter->GetOutput();
vtkPolyData* polydata = surrfaceFliter->GetOutput();
imageData = polyDataToImageData(polydata);

Here is the polyDataToImageData(),and I encountered the following error on the terminal.


I hope someone can provide some suggestions or ideas,thanks!

Sometimes it is easier for me to read code when it is pasted as text in “code blocks” … this forum uses Markdown to do that, but there are tools on the top of the text window that simplify that (specifically, the </> button, just select your code and press that button - and then you don’t have to paste images of your code).

Part of the documentation for vtkMarchingCubes is a warning that the class is specialized for volumes, and that if your data is more generic, that vtkContourFilter might be more appropriate?

Without more of your code, we probably won’t be able to help you figure out your error. However, I did a Google search for “vtk unstructured grid isosurface” and found vtkContourGrid. Perhaps that could save you the trouble of converting your data?

1 Like