How to merge two PolyData into one

Hello,

I would like to merge two vtkpolydata if it is possible, but I want to know at the end which point comes from which dataset. Also, I want to be sure that BuildLinks() will work and be able to find the correct neighbor points at the end.

I am not sure which is the best approach and if it is feasible.

Thanks

1 Like

You could identify each PolyData with a scalar point data array (PolyDataIdx). There might be a filter to do this, I’m not sure there is.

Setup a pipeline with vtkAppendPolyData---->vtkCleanPolyData. Add inputs to Append and Update(). Call BuildLinks() on pipeline’s output after clean up.

1 Like

You can create an array that contains a constant value using vtkArrayCalculator.

This works well if the two meshes do not intersect. If they do then you need to do Boolean mesh operation.

Thank you for the information.

I try the following:

union = vtk.vtkBooleanOperationPolyDataFilter()
union.SetOperationToUnion()
union.SetInputData(0, polydata)
union.SetInputData(1, polydata2)
union.Update()

outPoly = union.GetOutput()
outPoly.GetNumberOfCells()
0
outPoly.GetNumberOfPoints()
0

but the output has 0 cells or points. Do I miss something here?

Thanks

Boolean mesh operations in VTK do not work reliably (may provide invalid outputs for completely valid inputs, randomly). vtkBool is supposed to work much better.

Are the polys 2D or 3D? Last I checked, the Boolean filters didn’t work for polydata with 2D cells. Straight up outputs an empty polydata. What I mean is the BooleanOperation filters will work only when your polydata has a surface that encloses some volume.

My polys are 3D, does it mean that it should work? Could you please give me a working example with data?
Thanks

Will vtkBool be integrated in the vtk library at some point? The unreliable vtkBooleanOperationPolyDataFilter is a real drawback.

1 Like