Box clip with vtkTableBasedClipDataSet and sharp edges?

(Bane Sullivan) #1

The vtkBoxClipDataSet is great, however, it produces a triangulated mesh outside of the clipping box much like the vtkClipDataSet filter as discussed in the thread: Is it possible to turn off triangles on vtkClipDataSet filter?

I’m wondering how I might perform a box clip with the vtkTableBasedClipDataSet filter to avoid mesh triangulation. For example, a typical BoxClip of ImageData looks like this:

import vtk
...
alg = vtk.vtkBoxClipDataSet()
alg.SetBoxClip(xmin, xmax, ymin, ymax, zmin, zmax)
alg.SetInputDataObject(dataset) # pass image data in this example
alg.GenerateClippedOutputOn()
alg.Update()
result = alg.GetOutputDataObject(1)
...
# Plot result

Then you could try to do the same thing with vtkTableBasedClipDataSet, but the result is a bit curvey:

...
# Make implicit function
box = vtk.vtkBox()
box.SetBounds(xmin, xmax, ymin, ymax, zmin, zmax)

# Perfrom box clip
alg = vtk.vtkTableBasedClipDataSet()
alg.SetInputDataObject(dataset)
alg.SetClipFunction(box)
alg.SetInsideOut(False)
alg.Update()
result = alg.GetOutput()
...
# Plot result

This is super close to what I want - no triangulation - but the box clipped from the dataset is curved along the edges which is not prefered. How would I get sharp edges from vtkTableBasedClipDataSet?

(Bane Sullivan) #2

And just in case someone wants to reproduce this:

xmin, xmax, ymin, ymax, zmin, zmax = 5.818, 9.0315 5.818, 9.0315, 5.818, 9.0315

And the ImageData used in this example: uniform.vtk (13.8 KB)

Is it possible to turn off triangles on vtkClipDataSet filter?
(Cory Quammen (Kitware)) #3

I believe you are seeing the effects of clipping by an implicit box function. The volume is clipped by a scalar field which is defined as the distance from the box. This distance field is only box-like when the cut value is set to 0. To see what the distance field looks like outside the box, see the images in this StackOverflow post.

The box function is effectively evaluated at points in the input data set. The problem is that in general, edges of your box function will not coincide with points in the input grid. In such cases vtkTableBasedClipDatatSet will perform linear interpolation between the points. The linear interpolation fails in the case of the non-linear distance function from the box, and is responsible for the rounded edges you see.