[vtkusers] How to dump images correctly in Python

Willi Huber surfersparadise85-vtk at yahoo.com
Tue Feb 12 14:03:08 EST 2013


Thanks a lot David,

One last thing. How do I delete an VTK object? In python I can't call Delete(). And how can I be sure the object is deleted? I know of DebugOn() and the vtkDebugMacro but how can it be printed? Whenever I am trying this little example in ipython:

------
import vtk
a = vtk.vtkObject()
a.DebugOn()

del a
------

nothing can be seen. Is the object deleted or can't I see the output? How can I make te output visible?

Cheers,
Wili



>________________________________
> Von: David Gobbi <david.gobbi at gmail.com>
>An: Willi Huber <surfersparadise85-vtk at yahoo.com> 
>CC: "vtkusers at vtk.org" <vtkusers at vtk.org> 
>Gesendet: 15:17 Dienstag, 12.Februar 2013
>Betreff: Re: [vtkusers] How to dump images correctly in Python
> 
>Hi Willi,
>
>An output exists for as long as its generator exists.  Likewise, the
>generator exists for as long as the output exists.  As long as your
>program is making use of one or the other, neither will be freed.  So
>what you should do is copy the output into a new data object:
>
>o = vtkImageData()
>o.DeepCopy(f.GetOutput())
>
>After you do that, you can delete the original output and the entire
>pipeline that it was connected to.  The new output (i.e. the copy) can
>be used as input to a new pipeline.  You can also try ShallowCopy()
>instead of DeepCopy(), but after ShallowCopy the original output and
>its copy share the same data array, so after ShallowCopy you should
>call ReleaseData on the original output.
>
>By the way, this is not wrapper-specific.  It is exactly the same for
>VTK in C++.
>
>- David
>
>On Tue, Feb 12, 2013 at 5:49 AM, Willi Huber
><surfersparadise85-vtk at yahoo.com> wrote:
>> Hello all,
>>
>> I still have the same problems.
>>
>> What is the deal with vtk GetOutput(), GetOutputPort() etc.?
>> How long does the generator object of this GetOutput() live? Can it be
>> dumped right after obtaining GetOutput(). How can it be dumped?
>> How long does the GetOutput()-object, e.g. an image, live? How can it make
>> it be collected by the garbage collection?
>>
>> I am generating a large amount of images which have to get dumped correctly.
>> Please advice me what to do. I think this advices are also helpful for later
>> generations of VTK-wrapper users.
>>
>> I have also problems generating only a plain image with a certain value.
>> What I am currently doing is:
>>
>> def generate_scalar_value_filled_3d_vtkImageData(spacing, origin, extent,
>> scalar_type, scalar_value):
>>     import vtk
>>
>>     image = vtk.vtkImageData()
>>     image.SetExtent([0, 0, 0, 0, 0, 0])
>>     image.SetOrigin(origin)
>>     image.SetSpacing(spacing)
>>     image.SetScalarType(scalar_type)
>>     image.AllocateScalars()
>>
>>     padder = vtk.vtkImageConstantPad()
>>     padder.SetOutputWholeExtent(extent)
>>     padder.SetConstant(scalar_value)
>>     padder.SetInput(image)
>>     padder.Update()
>>
>>     out = padder.GetOutput()
>>     # image.ReleaseData()
>>
>>     return out
>>
>> Whenever I call ReleaseData on the image my output is somewhat influenced. I
>> cannot explain in which way. Can somebody explain me all the underlying
>> structure and ideas? I am getting more and more confused from minute to
>> minute.
>>
>> Thanks in advance.
>>
>> Best,
>> Willi
>>
>>
>> ________________________________
>> Von: Willi Huber <surfersparadise85-vtk at yahoo.com>
>> An: "vtkusers at vtk.org" <vtkusers at vtk.org>
>> Gesendet: 20:30 Montag, 11.Februar 2013
>> Betreff: [vtkusers] How to dump images correctly in Python
>>
>> Hello all,
>>
>> I am having serious space problems. With my program I constantly generate
>> images and I thought the internal garbage collector of python takes care but
>> it doesn't seem so whenever I give an image to an other filter.
>> Now I am trying to delete all the unnecessary images by my own. Is there a
>> common way to do this? I am using ReleaseData(). Is there a way to see what
>> references a certain object?
>>
>> How is a image in vtk gernerated by a filter? Is it always a new image
>> whenever I call GetOutput() or still the same all the time?
>>
>> Best,
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20130212/22f0cbba/attachment.htm>


More information about the vtkusers mailing list