How can I combine a series of polydata to a 3D object in c++?

Hello, I am a newcomer to VTK recently. Now I have a task to finish. I need to construct a 3D object from a several sections of an object. To be more specifically, I need to first construct a section from multiple points and then stack all scetions into a 3D object.

Here is my current thought and code. I combine points in a single section and store them in vtkpolyData. Later I want to stack all vtkpolyData and then show them in the vtk renderer windows.

dsg_ch0 is the section variable, whose structure is vector<vector>, Distance contains x, y, z coordination.

Does anyone know how to solve this problem properly? Thank you

If you need the ability to access properties, pick each individual polydata, you can use the vtkCompositeDataSet / vtkPartitionedDataSetCollection API for managing the whole model.
If you would simply like to combine them into a single vtkPolyData object, use vtkAppendPolyData.

Thank you sir! I actually tried vtkAppendPolyData before. However, it seemed to not work with vtkNew.

Here is my code using vtkAppendPolyData:

And here is the result I got:

I am quite confused what happended. If I use vtkNew to replace all the pointer, it still not work.

When I did not use vtkAppendPolyData, it will work well to show me the polynomial line. Do you know what’s going on?

I think it is your use of Get here: appendFilter->AddInputData(polyData.Get()); , polyData.Get()) is returning a raw pointer to the contained object. In this case it goes out of scope after the for loop exits, hence no PolyData.

Don’t use Get and see what happens. Also look at CombinePolyData.

I change to this, but it still not work.

But since you mentioned raw pointer. I come out that I first store all polydata I get in my own class. And then I use appendpolydata to store the polydata I store in the class.

BTW, I want to ask does this issue relative to the difference between vtkNew and vtkSmartPointer?

@yen I think the issue is that your polydata doesn’t have any cells. You are using InsertCellPoint without calling InsertNextCell. You need both of those calls for adding a valid cell to the lines cellarray.

Something like:


Thank you very much, I indeed miss InsertNextCell. Thank you very much, now I can continue my work!