vtkClipVolume using an implicit function (vtkCylinder) - errors on output grid

Hello!

I’m clipping a vtkUnstructuredGrid with a vtkCylinder. I got both parts (making use of GenerateClippedOutputOn()).

However, one of my resultant grid has artifacts. I wasn’t able to be sure what are the problem, but I think there are some tetrahedras which are “degenarated”.

Part of my source code:

clipCylinder->SetRadius(float(size/3));

auto clipper2 = vtkSmartPointer< vtkClipDataSet>::New();
clipper2->SetClipFunction(clipCylinder);
clipper2->SetGenerateClipScalars(true);
clipper2->SetUseValueAsOffset(true);
clipper2->SetMergeTolerance(0.001); // I change this number and noting happens
clipper2->GenerateClippedOutputOn();
clipper2->SetInsideOut(0);
clipper2->SetInputData(unstGrid2);
clipper2->Update();

auto unstGrid3 = vtkSmartPointer::New();
auto unstGrid4 = vtkSmartPointer::New();

unstGrid3 = clipper2->GetOutput();
unstGrid4 = clipper2->GetClippedOutput();

unstGrid3 in Paraview:

Another piece of information: if I try to filter it in Paraview, I get the same result with Clean Cells To Grid and another erroneus grid with Clean to Grid. However, in this case, the “empty faces” are fine but other faces become “empty”.

My questions:

  1. Any clues on what can be happening?
  2. Should I use a filter after getting the vtkUnstructuredGrid from clipping? Somthing like “close volume surface”.

Using VTK version 7.1.1

I’ve been struggling with this issue for quite some time now and I could not find any tips from vtk examples nor from google. Since I’m pretty new to VTK, I believe I am missing something of the process.

Thanks in advance,

Vitor Silva
2020-05-03T23:00:00Z

Can you provide a full example such that we can reproduce your problem? How does your input volume look like? You can also upload the geometry or tell us what to do in ParaView.

Not sure what is going on. Based on your screenshot, I’d guess it’s a numerical/rounding problem. I assume you have played around with the parameters of the clipper? The following code (in python) works for me to clip an surface mesh with an implicit cylinder. (You probably can simply replace vtkClipPolyData with vtkClipVolume to match your use-case…)

def clipImplicit(source, implicitFunction, functionValue=0):
    clip = vtk.vtkClipPolyData()
    clip.GenerateClippedOutputOn()
    clip.SetInputConnection(source.GetOutputPort())
    clip.SetClipFunction(implicitFunction)
    clip.SetValue(functionValue)
    clip.GenerateClipScalarsOn()
    clip.Update()

    # Also return the clipped parts.
    clippedParts = vtk.vtkPassThroughFilter()
    clippedParts.SetInputConnection(clip.GetOutputPort(1))
    clippedParts.Update()
    return clip, clippedParts

I’m personally not super fond of implicit functions. Find here one of my struggles with implicit clipping (of a surface mesh in my case). Not sure though, if the same applies to you as well.

Hi Normanius, thanks for your reply.

Well, to be honest, after digging a bit more on the forum (I was checking the old mail-list system as was configured in my e-mail reader, my fault. I’m not yet used to discourse) and missed some interesting discussions about the topic.

But first of all: I was able to solve my problem by simply replacing the vtkClipDataSet class by the vtkTableBasedClipDataSet. I must say sometimes the number of classes (and despite de great work on the examples page) is overwhelming and I often find myself with 6 or 7 open tabs on VTK classes trying to find the one which best fit to my needs. But in this case problem is solved.

That said, my apologies for not being able to provide a working example. I was afraid of having too much unrelated code posted which could make it less readable. But in response to you question:

How does your input volume look like?
It is simply a vtkImage block of i x k x j dimensions. From this block, I use implicit functions to extract volumes, both the the clipped region and the ‘remaining’ of the clipped region.

This is the post that lead me to the solution (Is it possible to turn off triangles on vtkClipDataSet filter?) that lead me to the solution.

Well, thanks a lot for your reply. Since I’m just starting with VTK, you’ll probably see me again with more questions. I’ll try to dig deeper next time before posting, but it seems that only after trying to organize the ideas down do a text to ask a proper question, it happens that I easily find the aswer to the very question…

Regards,

Vitor