[vtkusers] What is the order of calling delete methods on a pipeline?
Xiaofeng Z
xf10036 at hotmail.com
Wed May 11 14:55:03 EDT 2011
Hi Chasan,
You'll have to call Delete on each and every object you don't want to keep. The order of delete does not matter as each object is reference counted and will be actually deleted when the reference count goes to zero.
Another method is to not use vtkSmartPointer on the objects you want to batch delete. Say you want the Renderer to go away when the render window goes away, you would do it like this:
vtkRenderer* renderer = vtkRenderer::New(); // renderer has ref count 1
vtkRenderWindow* win = vtkRendererWindow::New();
win->AddRenderer(renderer); // renderer has ref count 2
renderer->Delete(); // renderer has ref count 1 from vtkRenderWindwo()
In the above example, when win is destroyed, win will remove the last ref count in renderer object, in turn causes renderer be destroyed.
Hope this helps!
Xiaofeng
P.S. Personally, I don't like to over use vtkSmartPointer
> Date: Wed, 11 May 2011 08:26:35 +0800
> From: pfb at exadios.com
> To: vtkusers at vtk.org
> Subject: Re: [vtkusers] What is the order of calling delete methods on a pipeline?
>
> Hi Chasan;
>
> I'm not clear what you want to keep. Which of the objects in the code
> below do you need to keep?
>
> On Sun, 8 May 2011, chasank wrote:
>
> > Hi Peter,
> >
> > I have designed a class containing many vtk objects, that's why I do not
> > want
> > to release memory resources by scope. The other vtk objects have to live.
> > I want to release only volume rendering pipeline on runtime. How can I do it
> > safely?
> > Thanks!
> >
> >
> > Peter F Bradshaw wrote:
> > >
> > > Hi Chasan;
> > >
> > > If you wish to release the pipeline below why not encase it in its own
> > > scope? If you are using vtkSmartPointer, which you are, then the
> > > pipeline will be destroyed when it goes out of scope.
> > >
> > > On Sat, 7 May 2011, Chasan KIOUTSOUKMOUSTAFA wrote:
> > >
> > >> I have a volume rendering pipeline and I want to release all the memory
> > >> resources of pipeline on runtime .
> > >> How can I release memory resources of the pipeline safely?
> > >> It seems the iren is the end of pipeline, if I call the iren->Delete(),
> > >> will
> > >> it delete recursively all of the pipeline?
> > >> What is the solution ? Pipeline is below. Thanks for answers!!
> > >>
> > >> renderer = vtkSmartPointer < vtkRenderer > :: New();
> > >> renderWindow = vtkSmartPointer < vtkWin32OpenGLRenderWindow > ::
> > >> New();
> > >> renderWindow->AddRenderer(renderer);
> > >> renderWindow->SetSize(width, height);
> > >>
> > >> iren = vtkSmartPointer < vtkWin32RenderWindowInteractor > :: New();
> > >> iren->SetRenderWindow(renderWindow);
> > >>
> > >> volumeMapper =
> > >> vtkSmartPointer<vtkFixedPointVolumeRayCastMapper>::New();
> > >> volumeMapper->SetInputConnection(reader->GetOutputPort());
> > >> volumeMapper->SetBlendModeToComposite();
> > >>
> > >> volumeColor = vtkSmartPointer<vtkColorTransferFunction>::New();
> > >> volumeColor->AddRGBPoint(0, 0.0, 0.0, 0.0);
> > >> volumeColor->AddRGBPoint(500, 1.0, 0.5, 0.3);
> > >> volumeColor->AddRGBPoint(1000, 1.0, 0.5, 0.3);
> > >> volumeColor->AddRGBPoint(1150, 1.0, 1.0, 0.9);
> > >>
> > >> volumeScalarOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New();
> > >> volumeScalarOpacity->AddPoint(0, 0.00);
> > >> volumeScalarOpacity->AddPoint(500, 0.15);
> > >> volumeScalarOpacity->AddPoint(1000, 0.15);
> > >> volumeScalarOpacity->AddPoint(1150, 0.90);
> > >>
> > >> volumeGradientOpacity = vtkSmartPointer<vtkPiecewiseFunction>::New();
> > >> volumeGradientOpacity->AddPoint(0, 0.0);
> > >> volumeGradientOpacity->AddPoint(90, 0.5);
> > >> volumeGradientOpacity->AddPoint(100, 1.0);
> > >>
> > >> volumeProperty = vtkSmartPointer<vtkVolumeProperty>::New();
> > >> volumeProperty->SetColor(volumeColor);
> > >> volumeProperty->SetScalarOpacity(volumeScalarOpacity);
> > >> volumeProperty->SetGradientOpacity(volumeGradientOpacity);
> > >> volumeProperty->SetInterpolationTypeToLinear();
> > >> volumeProperty->ShadeOff();
> > >> volumeProperty->SetAmbient(0.4);
> > >> volumeProperty->SetDiffuse(0.6);
> > >> volumeProperty->SetSpecular(0.2);
> > >>
> > >> LODProperty = vtkSmartPointer <vtkLODProp3D>::New();
> > >> int id = LODProperty->AddLOD(volumeMapper, volumeProperty, 0.0);
> > >> LODProperty->SetLODLevel(id, 0.0);
> > >>
> > >> renderer->AddViewProp(LODProperty);
> > >> renderer->ResetCamera();
> > >> renderer->Render();
> > >>
> > >> iren->Initialize();
> > >>
> > >
> > > Cheers
> > >
> > > --
> > > Peter F Bradshaw: http://www.exadios.com (public keys avaliable there).
> > > Personal site: http://personal.exadios.com
> > > "I love truth, and the way the government still uses it occasionally to
> > > keep us guessing." - Sam Kekovich.
>
> Cheers
>
> --
> Peter F Bradshaw: http://www.exadios.com (public keys avaliable there).
> Personal site: http://personal.exadios.com
> "I love truth, and the way the government still uses it occasionally to
> keep us guessing." - Sam Kekovich.
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110511/211dfcf3/attachment.htm>
More information about the vtkusers
mailing list