# Box clip with vtkTableBasedClipDataSet and sharp edges?

**URL:** https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286
**Category:** Support
**Created:** [July 5, 2019, 5:35pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286 "2019-07-05T17:35:13Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [July 5, 2019, 5:35pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/1 "2019-07-05T17:35:13Z")

</div>

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?](https://discourse.vtk.org/t/is-it-possible-to-turn-off-triangles-on-vtkclipdataset-filter/279)

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:

```python
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

```

 ![tri-box-clip](https://discourse.vtk.org/uploads/default/original/1X/c98dff84d517d82a778853b8c324f45404d09e55.png)

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

```python
...
# 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

```

 ![download](https://discourse.vtk.org/uploads/default/original/1X/b18eb69b8ad4a4fd0d70a9336a758bc59368ef25.png)

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`?

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [July 5, 2019, 5:45pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/2 "2019-07-05T17:45:43Z")

</div>

And just in case someone wants to reproduce this:

```auto
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](https://discourse.vtk.org/uploads/default/original/1X/24738589d12a1d55a42e8e3ebaaf59d21a067579.vtk) (13.8 KB)

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [July 15, 2019, 7:11pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/3 "2019-07-15T19:11:11Z")

</div>

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](https://stackoverflow.com/questions/30545052/calculate-signed-distance-between-point-and-rectangle).

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.

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [July 23, 2019, 2:40pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/4 "2019-07-23T14:40:48Z")

</div>

Is there any way to use the `vtkTableBasedClipDatatSet` filter and have sharp edges exactly like a `vtkBoxClipDataSet`? My goal is to not triangulate the output mesh where I don’t need to - which is why I’m interested in using the `vtkTableBasedClipDatatSet`.

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [July 23, 2019, 9:34pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/5 "2019-07-23T21:34:08Z")

</div>

Not to my knowledge.

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/banesullivan/32/7143_2.png) [@banesullivan](https://discourse.vtk.org/u/banesullivan)
#### Post date: [September 3, 2019, 8:39pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/6 "2019-09-03T20:39:44Z")

</div>

What about “crinkling”? ParaView seems to have this implemented… how might this be done in VTK?:

 ![58](https://discourse.vtk.org/uploads/default/original/1X/1189fec0a28286fee0e547276a1befc012f645bf.gif)

Crinkling isn’t exactly what I am hoping to do, but its pretty close

---

<div class="post-metadata">

### Author: ![cory.quammen](https://discourse.vtk.org/user_avatar/discourse.vtk.org/cory.quammen/32/6751_2.png) [@cory.quammen](https://discourse.vtk.org/u/cory.quammen)
#### Post date: [September 3, 2019, 8:56pm UTC](https://discourse.vtk.org/t/box-clip-with-vtktablebasedclipdataset-and-sharp-edges/1286/7 "2019-09-03T20:56:02Z")

</div>

ParaView uses `vtkExtractGeometry` to perform the “crinkle” clip using the following settings:

```auto
vtkExtractGeometry::SetExtractInside(1);
vtkExtractGeometry::SetExtractOnlyBoundaryCells(0);
vtkExtractGeometry::SetExtractBoundaryCells(1);

```
