[vtkusers] the question about smart pointer
Franks
masterwangzx at gmail.com
Thu Nov 1 08:44:52 EDT 2018
Hi list,
I have got a problem about the use of vtkSmartPointer. For
vtkSmartPointer<vtkXMLPolyDataReader> Reader =
vtkSmartPointer<vtkXMLPolyDataReader>::New();
vtkPolyData* pd = Reader->GetOutput(); ,
/VTK/Tutorials/SmartPointers/ says *when the reader object goes out of
scope, the data is deleted*. I just can not understand What is the meaning
of out of scope. Does it means out of {}? I write some code to confirm it.
vtkSmartPointer<vtkImageChangeInformation> test() {
auto reader = vtkSmartPointer<vtkBMPReader>::New();
reader->SetFileName("../res/lena.bmp");
reader->Update();
auto changer = vtkSmartPointer<vtkImageChangeInformation>::New();
changer->SetInputData(reader->GetOutput());
return changer;
}
TEST_F(VTKTest,Execute){
auto changer = test();
auto imgActor = vtkSmartPointer<vtkImageActor>::New();
imgActor->GetMapper()->SetInputConnection(changer->GetOutputPort());
auto renderer = vtkSmartPointer<vtkRenderer>::New();
renderer->AddActor(imgActor);
renderer->SetBackground(1.0, 1.0, 1.0);
auto renderWindow = vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
renderWindow->Render();
auto renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
auto style = vtkSmartPointer<vtkInteractorStyleImage>::New();
renderWindowInteractor->SetInteractorStyle(style);
renderWindowInteractor->SetRenderWindow(renderWindow);
renderWindowInteractor->Initialize();
renderWindowInteractor->Start();
}
>From the above code, I think the object reader will delete when the function
test() return. When the object reader deleted, the reader's output data
delete and no data streams to object changer and the following object. But
my thought was wrong, the program run well. I do not konw where am I wrong.
I look forward to hearing from you.
Best regards,
Frank
--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
More information about the vtkusers
mailing list