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

**URL:** https://discourse.vtk.org/t/i-want-to-convert-unstructuredgrid-data-to-polydata-and-then-to-imagedata-so-that-i-can-use-the-marching-cubes-algorithm/10971
**Category:** Support
**Tags:** code
**Created:** [March 15, 2023, 7:33am UTC](https://discourse.vtk.org/t/i-want-to-convert-unstructuredgrid-data-to-polydata-and-then-to-imagedata-so-that-i-can-use-the-marching-cubes-algorithm/10971 "2023-03-15T07:33:58Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![liuyankui1998](https://discourse.vtk.org/user_avatar/discourse.vtk.org/liuyankui1998/32/6725_2.png) [@liuyankui1998](https://discourse.vtk.org/u/liuyankui1998)
#### Post date: [March 15, 2023, 7:33am UTC](https://discourse.vtk.org/t/i-want-to-convert-unstructuredgrid-data-to-polydata-and-then-to-imagedata-so-that-i-can-use-the-marching-cubes-algorithm/10971/1 "2023-03-15T07:33:58Z")

</div>

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:

```auto
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.

 ![2023-03-15 15-30-31 的屏幕截图](https://discourse.vtk.org/uploads/default/original/2X/1/1eed198a652488900b7376beb3432ca834346b0c.png)  
 ![2023-03-15 15-30-40 的屏幕截图](https://discourse.vtk.org/uploads/default/original/2X/1/142617e9b097691ab046ec2bff6948bae92748fe.png)

**I hope someone can provide some suggestions or ideas，thanks！**

---

<div class="post-metadata">

### Author: ![rexthor](https://discourse.vtk.org/user_avatar/discourse.vtk.org/rexthor/32/6481_2.png) [@rexthor](https://discourse.vtk.org/u/rexthor)
#### Post date: [March 15, 2023, 1:26pm UTC](https://discourse.vtk.org/t/i-want-to-convert-unstructuredgrid-data-to-polydata-and-then-to-imagedata-so-that-i-can-use-the-marching-cubes-algorithm/10971/2 "2023-03-15T13:26:51Z")

</div>

Sometimes it is easier for me to read code when it is pasted as text in “code blocks” … this forum uses [Markdown](https://markdown.land/markdown-code-block) 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](https://vtk.org/doc/nightly/html/classvtkContourGrid.html). Perhaps that could save you the trouble of converting your data?
