2D Polygon Boolean Operations

Hi all,

I have what I think should be an extremely easy problem, but I can’t figure out how to do it. I have two coplanar polygons generated from vtkContourWidget and stored as vtkPolyData, and I want to be able to perform boolean operations on them. I’m using vtk 6.2.

I’ve tried applying vtkIntersectionPolyDataFilter and vtkBooleanOperationPolyDataFilter, setting the inputs to the two polyData objects, with no luck - I get the error: “vtkMath::Jacobi: Error extracting eigenfunctions.” I’ve also tried transforming my polygons to implicit functions and applying vtkImplicitBoolean, but am not sure how to regenerate vtkPolyData in the end. One thing I haven’t tried yet is using vtkCollisionDetectionFilter as suggested here http://vtk.1045678.n5.nabble.com/Boolean-operation-for-vtkPolyData-td1238333.html, but I’d rather not have to use an extension.

My application is built in Qt, so at this point I think I may just translate all my points to QPoints, construct two QPolygons, use the Qt boolean tools, and then translate back to vtkPolyData… but surely there is a simple way to do what I want in vtk?

Thanks,
Harry

Harry,

vtkIntersectionPolyDataFilter and vtkBooleanOperationPolyDataFilter assume no co-planar overlapping triangles in the inputs, so it will not work for computing 2D boolean operations, unfortunately. I have updated the documentation for these filters in this merge request:

https://gitlab.kitware.com/vtk/vtk/merge_requests/5215

Thanks Cory!
I ended up implementing the solution I described above (using QPolygonF.united() and QPolygonF.subtracted()) and it works well. I feel that analogous vtk methods must exist, but have been unable to find them. I might come back to this problem when optimizing down the line, but for now I’m moving on!
Harry

1 Like

Hi Harry,

vtkCollisionDetectionFilter works fine for co-planar triangles. It wouldn’t take much to to include higher order cells too. You can alway use vtkTriangleFilter to decompose polys to triangles.

The class should be added to the VTK code base soon™

hth,

Goodwin

Thanks Goodwin,

The nabble thread explains that it is possible to use vtkCollisionDetectionFilter for basic union and subtraction, although it sounds like this is not the default behaviour, and the example (TestCollisionDetection1.cxx) no longer seems to be on the internet. If it does get added soon™, I’ll definitely try it out, but can I please ask that this example be reuploaded somewhere?

Thanks,
Harry

Hi Harry,

The examples are in the original repo here: https://github.com/glawlor/vtkbioeng/tree/master/Testing/Cxx

I’ll try and update them before the class is added to VTK.

Goodwin

1 Like

Goodwin, I have a MR I’m working on…

https://gitlab.kitware.com/vtk/vtk/merge_requests/5261

1 Like

Hi Bill,

I’m happy to help with code/docs/tests etc. - looks like it’s good to go though.

I had hard-coded the number of cells per OBB to 2 but have no idea if that is optimal. Maybe it is in some cases and not others. I see you’ve allowed the user to change that variable anyway and defaulted it to 2.

The only other variation on this class is a multi-input version.

Thanks,

Goodwin

Goodwin, you did the hard work. The MR is merged and now we can think pf adding a multi-input capability.

Thanks for your contribution. I only wish we had it in sooner.

Bill