Volume of vtkTrimmedExtrusionFilter
For the task of extruding a Mesh onto a plane in a PyVista environment, i was guided by the PyVista Comunity to use the VTK class directly.
The extrusion works just fine and everything looks the right way, but computing the Volume leads to some weird results. Volume results change depending on the global position in {x, y, z}.
To show, i load a PyVista Example mesh, transform it to the y-direction and compute the volume between the x-y Plane at z = -1. Transforming should not affect the mesh Volume.
The following Code produces the attached output
import numpy as np
import pyvista as pv
import vtk
import random
def extrusion_handle(mesh, surface):
alg = vtk.vtkTrimmedExtrusionFilter()
alg.SetInputData(0, mesh)
alg.SetInputData(1, surface)
alg.SetCappingStrategy(0) # <-- ensure that the cap is defined by the intersection
alg.SetExtrusionDirection(0, 0, 1.0) # <-- set this with the plane normal
alg.Update()
return pv.core.filters._get_output(alg)
mesh = pv.ParametricRandomHills(randomseed=2)
plane = pv.Plane(center=(0, 10, -1), direction=(0, 0, 1), i_size=25, j_size=25)
p = pv.Plotter()
p.show_bounds()
p.add_mesh(plane, color='w', opacity=0.7)
p.add_mesh(mesh, color='w', style='wireframe', opacity=0.5)
t = 30
for i in range(5):
mesh.translate((0, t, 0), inplace=True)
plane.translate((0, t, 0), inplace=True)
output = extrusion_handle(mesh, plane)
print("z = ", i, output.volume)
c = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255))
p.add_mesh(output, opacity=0.5, color=c)
p.show()
OUTPUT:
Volume[0] = 784.6841821451919
Volume[1] = 900.3043203591214
Volume[2] = 1015.924465875751
Volume[3] = 1131.5445591324187
Volume[4] = 1247.164727166394
Dose anybody know why this is happening?
This issue dose not occur if computing the volume of a primitv, e.g. a Sphere. Eeven if a cut it by boolean operators.