Is it possible to turn off triangles on vtkClipDataSet filter?

That actually might work… perhaps I could keep track of the original cell ID’s and then use those to extract the cells from the original mesh using a selection routine with vtkSelectionNode, vtkSelection, and vtkExtractSelection. That parts easy… but how do I keep track of the original cell IDs when using the vtkClipDataSet filter?

I could add the cell IDs to the cell data of the input then catch them on the output :man_facepalming: :bulb:

Only issue is that the clipping plane wouldn’t be preserved in the output and I wouldn’t be able to make intersection polygons:

...
ids = np.arange(0, subsurface.n_cells, dtype=int)
subsurface['ids'] = ids
clp = subsurface.clip([-1,1,1])
clp.plot(show_edges=True, color='w', use_panel=False)

clp_preserved = subsurface.extract_cells(np.unique(clp['ids']))
clp_preserved.plot(show_edges=True, color='w', use_panel=False)

Hm… maybe I could use the slice filter and leverage the fact that vtk.vtkCutter has an awesome GenerateTrianglesOff() method to make those intersection polygons then merge the slice and the clipped mesh using IDs to make a hack of a solution. But I think it’ll work and could be generalized… I’ll try it!

ClipPolyData does preserve original polygons that are not clipped. Only triangles if clipped. I guess you probably know that.
See this example.

2 Likes

Yeah, the ClipPolyData filter is great for 2D cells - but I’m mostly clipping volumetric cells in rectilinear grids, un/structured grids, and image data so having a clear way to clip and preserve topology not intersected by the clip would be huge for me

Have you tried vtkGenericClip?

When you clip volumetric meshes, you have the option of not cutting into the cells, just keep or remove whole cells.

I just checked, GenericClip also generates triangles…

1 Like

Could you share a sample dataset? I may have a solution using vtkMultiThreshold. I can extract the inside and border voxels as separate datasets. hen clip the border cells and append them with the inside.

I’m not done yet, but here is the result of the MultiThreshold.

@lorensen, that looks awesome! Here is an unstructured grid that I have been working with lately where the cell resolution is really important: https://www.dropbox.com/s/5ivldekj8weqc79/treemesh.vtk?dl=0

It’d be awesome if we could find a way to preserve cells not touched by the clipping plane and generate intersection polygons where the plane intersect cells in the mesh.

Hi,

Did you try vtkTableBasedClipDataSet ?
From documentation it says:
" It is worth mentioning that vtkTableBasedClipDataSet is capable of addressing the artifacts that may occur with vtkClipDataSet due to the possibly inconsistent triangulation modes between neighboring cells. In addition, the former is much faster than the latter. Furthermore, the former produces less cells (with ratio usually being 5~6) than by the latter in the output. In other words, this filter retains the original cells (i.e., without triangulation / tetrahedralization) wherever possible"

1 Like

Vincent is correct. This example shows that triangles are NOT produced as shown in this closeup.

. Bane, ill try it with your dataset later today.

1 Like

And, This example clips a rectilinear grid. It also reports the cell types of the clipped data.

The clipped dataset(inside) contains a 
vtkUnstructuredGrid that has 14176 cells
Cell type vtkTetra occurs 3084 times.
Cell type vtkHexahedron occurs 6820 times.
Cell type vtkWedge occurs 1196 times.
Cell type vtkPyramid occurs 3076 times.

The clipped dataset(outside) contains a 
vtkUnstructuredGrid that has 125600 cells
Cell type vtkTetra occurs 3276 times.
Cell type vtkHexahedron occurs 117732 times.
Cell type vtkWedge occurs 1260 times.
Cell type vtkPyramid occurs 3332 times.

1 Like

This did it!! So far I am having success with the vtkTableBasedClipDataSet filter and using it the same way as I would a vtkClipDataSet filter. Thanks for your input, @Vincent_Rivola!

vtkTableBasedClipDataSet provides exactly what I want! Preserved cells where the clip doesn’t happen and intersection polygons along the implicit clip function:

One last lingering question…

Is there any advantage to using vtkClipVolume over vtkTableBasedClipDataSet for vtkImageData? From my perspective it looks like I always want to use the vtkTableBasedClipDataSet filter because it will preserve the cells in the image data while vtkClipVolume triangulates the volume.

Use of vtkClipVolume with vtkImageData (plane clip):

Use of vtkTableBasedClipDataSet with the same dataset and clip function. Note that there are no triangulated cells which is likely preferred when working with vtkImageData:

Bane,

As you discovered, looks like TableBasedClipDataSet is the way to go. I ran it on the data you provided and got this result.
BTW: Can I use your dataset in the VTKExamples Project?

TableBasedClip

That should be fine!

Also, any input on this new thread which is highly related would be greatly appreciated!: Box clip with vtkTableBasedClipDataSet and sharp edges? - #2 by banesullivan

I’ve added two nex examples to the VTKExamples Project. They illustrate the difference between vtkTableBasedClipDataSet and vtkClipDataSet.

  1. ClipUnstructuredGridWithPlane
  2. ClipUnstructuredGridWithPlane2

The former is faster and produces many fewer cells because it retains the original cells outside the clip boundary. See the difference in these images:
TestClipUnstructuredGridWithPlane
TestClipUnstructuredGridWithPlane2

If you have been using vtkClipDataSet you may wish to switch to vtkTableBasedClipDataSet.

Thanks to Bane Sullivan for bringing up the original problem and for helping to track down a solution.

Also, he provided a great unstructured grid test dataset.

1 Like