# apply marching cube on unstructured grid with vtk voxel cells

**URL:** https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593
**Category:** Support
**Created:** [October 13, 2022, 9:51am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593 "2022-10-13T09:51:27Z")
**Posts on this page:** 11
**Page:** 1

<div class="post-metadata">

### Author: ![willk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/willk/32/4811_2.png) [@willk](https://discourse.vtk.org/u/willk)
#### Post date: [October 13, 2022, 9:51am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/1 "2022-10-13T09:51:27Z")

</div>

I am trying to use a vtkMarchingCubes algo on a Unstructuredgrid data. The problem i am facing is vtkMarchingCubes only work with vtkImageData.  
ERROR:root:Input for connection index 0 on input port index 0 for algorithm vtkMarchingCubes(0000018CC55BA9A0) is of type vtkUnstructuredGrid, but a vtkImageData is required.  
Do you have anyalternativ?  
Thanks a lot to take the time to answer me.

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [October 13, 2022, 10:01am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/2 "2022-10-13T10:01:11Z")

</div>

Use vtkContourFilter

---

<div class="post-metadata">

### Author: ![willk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/willk/32/4811_2.png) [@willk](https://discourse.vtk.org/u/willk)
#### Post date: [October 14, 2022, 9:06am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/3 "2022-10-14T09:06:50Z")

</div>

Is it possible to smooth an Unstructured grid without extracting the surface? Because all of the filters I use only extract the outer surface and the inside of the geometry is lost. But I want to smooth only the boundary of my data while conserving the inside, like in the picture.

 ![WANeM](https://discourse.vtk.org/uploads/default/original/2X/e/e45522f3f9b08630f39a87450aebbdd3962c6066.png)

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [October 14, 2022, 11:57am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/4 "2022-10-14T11:57:28Z")

</div>

You can probably use vtkConstrainedSmoothingFilter. You’ll likely have to use a constraint array to control the maximum amount each point can move. Note that allowing only boundary points to move (i.e., be smoothed) while fixing interior points can result in defects in the resulting mesh.

---

<div class="post-metadata">

### Author: ![willk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/willk/32/4811_2.png) [@willk](https://discourse.vtk.org/u/willk)
#### Post date: [October 17, 2022, 10:28am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/5 "2022-10-17T10:28:09Z")

</div>

> [@will.schroeder](#):
>
> vtkConstrainedSmoothingFilter

I have this error: AttributeError: module ‘vtkmodules.all’ has no attribute ‘vtkConstrainedSmoothingFilter’

---

<div class="post-metadata">

### Author: ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)
#### Post date: [October 17, 2022, 10:41am UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/6 "2022-10-17T10:41:52Z")

</div>

You need a very recent version of VTK

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 20, 2022, 2:58pm UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/7 "2022-10-20T14:58:12Z")

</div>

Hello,

If I understood it right, you basically want to:

1. Select the cells that are inside of some shell (e.g. a sphere);
2. Smooth the outermost cells as to coincide with the shell surface.

The second operation can be performed by projecting certain vertexes (those “exposed to the air”) of the outermost cells into the shell surface. If you don’t have a shell surface, you can genereate it _ad hoc_ by using the marching cubes as suggested above.

This is not a trivial operation, but you can start here: [data structure - How to smooth a voxel mesh? - Game Development Stack Exchange](https://gamedev.stackexchange.com/questions/185219/how-to-smooth-a-voxel-mesh). Follow the discussion and from there you can get some pointers.

take care,

Paulo

---

<div class="post-metadata">

### Author: ![willk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/willk/32/4811_2.png) [@willk](https://discourse.vtk.org/u/willk)
#### Post date: [October 24, 2022, 2:02pm UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/8 "2022-10-24T14:02:54Z")

</div>

Hello Mr Schroeder,  
when i use vtkDelaunay filter i get this error "vtkDelaunay3D.cxx:522 WARN| vtkDelaunay3D (00000225E6D4E820): 132 degenerate triangles encountered, mesh quality ". Do you know how to fix this error ?

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 24, 2022, 2:12pm UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/9 "2022-10-24T14:12:43Z")

</div>

Hi,

You can use `vtkCleanPolyData` to post-process the obtained mesh to treat or remove degenerate cells: [https://vtk.org/doc/nightly/html/classvtkCleanPolyData.html](https://vtk.org/doc/nightly/html/classvtkCleanPolyData.html).

regards,

Paulo

---

<div class="post-metadata">

### Author: ![willk](https://discourse.vtk.org/user_avatar/discourse.vtk.org/willk/32/4811_2.png) [@willk](https://discourse.vtk.org/u/willk)
#### Post date: [October 24, 2022, 2:24pm UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/10 "2022-10-24T14:24:35Z")

</div>

Hi,

the problem is I only work with UnstruncturedGrid not Polydata.

Regards

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [October 24, 2022, 2:45pm UTC](https://discourse.vtk.org/t/apply-marching-cube-on-unstructured-grid-with-vtk-voxel-cells/9593/11 "2022-10-24T14:45:03Z")

</div>

Hello,

Then I suggest you to review the first stages back in your processing pipeline. Check how the original unstructured grid is being generated/imported and processed. Original data is not supposed to contain degenerate cases. Degenerate cells usually arise after applying some processing to them.

all the best,

Paulo
