# Volume calculation (surface mesh) in paraview

**URL:** <https://discourse.paraview.org/t/volume-calculation-surface-mesh-in-paraview/17776>\
**Category:** ParaView Support\
**Created:** [October 26, 2026, 7:49am UTC](https://discourse.paraview.org/t/volume-calculation-surface-mesh-in-paraview/17776 "2026-10-26T07:49:22Z")\
**Posts on this page:** 1\
**Showing post:** 8

<div class="post-metadata">

**Author:** ![otaolafr](https://discourse.paraview.org/user_avatar/discourse.paraview.org/otaolafr/32/3595_2.png) [@otaolafr](https://discourse.paraview.org/u/otaolafr)\
**Post date:** [October 27, 2026, 9:35am UTC](https://discourse.paraview.org/t/volume-calculation-surface-mesh-in-paraview/17776/8 "2026-10-27T09:35:32Z")

</div>

In any case, for anyone that is looking for a solution and comes across this post:

```auto
from paraview import servermanager
from paraview.vtk.numpy_interface import dataset_adapter as dsa

#ensure that the filter is vtkPolyData type
if filter.GetDataInformation().GetDataSetTypeAsString()!='vtkPolyData':
    filterToUse=ExtractSurface(Input=filter)
else:
    filterToUse=filter

programmableFilter1 = ProgrammableFilter(registrationName='ProgrammableFilter1', Input=filter,OutputDataSetType='vtkPolyData',)
programmableFilter1.Script="""
import vtk
mesh = self.GetInputDataObject(0, 0)
surface = vtk.vtkDataSetSurfaceFilter()
surface.SetInputData(mesh)
surface.Update()
triangulate = vtk.vtkTriangleFilter()
triangulate.SetInputConnection(surface.GetOutputPort())
triangulate.Update()
mp = vtk.vtkMassProperties()
mp.SetInputConnection(triangulate.GetOutputPort())
mp.Update()
volume = mp.GetVolume()
area = mp.GetSurfaceArea()
# Create output: one point and one vertex cell
output.Initialize()
points = vtk.vtkPoints()
points.InsertNextPoint(0.0, 0.0, 0.0)
output.SetPoints(points)
vertices = vtk.vtkCellArray()
vertices.InsertNextCell(1)
vertices.InsertCellPoint(0)
output.SetVerts(vertices)
# Check boundary edges
boundaryEdges = vtk.vtkFeatureEdges()
boundaryEdges.SetInputConnection(triangulate.GetOutputPort())
boundaryEdges.BoundaryEdgesOn()
boundaryEdges.FeatureEdgesOff()
boundaryEdges.NonManifoldEdgesOff()
boundaryEdges.ManifoldEdgesOff()
boundaryEdges.Update()
nBoundary = boundaryEdges.GetOutput().GetNumberOfCells()
# Check non-manifold edges
nonManifoldEdges = vtk.vtkFeatureEdges()
nonManifoldEdges.SetInputConnection(triangulate.GetOutputPort())
nonManifoldEdges.BoundaryEdgesOff()
nonManifoldEdges.FeatureEdgesOff()
nonManifoldEdges.NonManifoldEdgesOn()
nonManifoldEdges.ManifoldEdgesOff()
nonManifoldEdges.Update()
nNonManifold = nonManifoldEdges.GetOutput().GetNumberOfCells()
isClosed = nBoundary == 0 and nNonManifold == 0
if not isClosed:
    print("Mesh is not closed!")
    volume=0
for name, value in [("Volume", volume), ("Area", area)]:
    array = vtk.vtkDoubleArray()
    array.SetName(name)
    array.InsertNextValue(value)
    output.GetCellData().AddArray(array)
print("Mesh area:", area)
print("Mesh volume:", volume)"""
data=dsa.WrapDataObject(servermanager.Fetch(programmableFilter1))
volume=data.CellData['Volume']
area=data.CellData['Area']

```

if the volume is still ==0 (meaning it is not manifold) one can use VESPA pluging with fill holes (or worst case scenario alpha wrapping) to create a new manifold watertight mesh in paraview itself, and extract the volume and area using the same ProgrammableFilter

best regards.

---

_[View the full topic](https://discourse.paraview.org/t/volume-calculation-surface-mesh-in-paraview/17776)._
