Creating a new vtkDataSet from an existing vtkDataSet

Hello,

I just met a question about creating a new vtkDataSet from an existing vtkDataSet. I have an original dataset A

vtkSmartPointer<vtkDataSet> A = CreateDataSetA();

And now I want to create a deepcopy of the DataSet A with all the PointData and CellData. I tried different ways and print the new Dataset B:

//***Not working in the compiling***
vtkSmartPointer<vtkDataSet> B = vtkSmartPointer<vtkDataSet>::New();
B->DeepCopy(A);

//***Working but probably Shallow copy***
vtkSmartPointer<vtkDataSet> B = vtkSmartPointer<vtkDataSet>(A);

//***Has coordinates of A but no Point Data***
vtkSmartPointer<vtkDataSet> B = vtkSmartPointer<vtkDataSet>(A);
B->DeepCopy(A);

//***Working***
vtkSmartPointer<vtkDataSet> B = vtkSmartPointer<vtkDataSet>::Newinstance(A);
B->DeepCopy(A);

//***Print function***
std::filebuf file_Buff;
file_Buff.open("./test.txt", std::ios::out);
std::ostream os(&file_Buff);
B->Print(os);
file_Buff.close();

The last one is working and I guess that is a Deep Copy. But I wonder why thoese weird things happen.

I would be appreciate if someone could explain that.

The last one is indeed correct. If you want to copy object A to object B, you first have to create object B with same type than object A. The NewInstance() does that. Then, the DeepCopy() will deep copy (meaning allocate new memory, not sharing pointers) all data from object A into object B.
HTH.

Thanks so much. I realize that after a while and the data structure in VTK is kind of different from the basic data type.