[vtkusers] vtkImageViewer memory usage

Suresh Joshi sureshj at gmail.com
Tue Aug 30 17:43:58 EDT 2011


Hi Pratik and everyone else,

I've finally gotten around to re-visiting this problem and I'm getting
some strange results.

I've taken Pratik's advice and made a test app using the JPEGReader
example inside of a Win32 app. So, I initialize/show an empty HWND,
and then separately create 3 imageViewers (linked to 3 HWNDs that I
had previously created).

My memory consumption is as follows:
After InitInstance: 14.5 MB
After 1st ImageViewer: 34.1 MB
After 2nd ImageViewer: 40 MB
After 3rd ImageViewer: 46.2 MB

*Note: this is using a test image which has a file size of 27KB,
width=400pixels, height=400pixels and a bit depth of 8.

So, according to this, my first image viewer required 20MB to create,
second and third required closer to 6MB.

I have also re-tested this using 3 different JPEGReaders as inputs to
the imageViewers and there is negligible difference. As well, I used a
3kB version of my test-image and it showed the same memory footprint.

So, does anyone know why there is this sort of discrepancy? I have
little knowledge of how the internals of the renderers and windows
work, so I'm at a loss and would appreciate any help (as well, if
there is any way for me to reduce this footprint as much as possible,
as I could have as many as 40 of these windows open at once!).

Thanks!
-Suresh

P.S. I've attached my sample code

// inside main function:

// Perform application initialization:
if (!InitInstance1 (hInstance, nCmdShow))
{
  return FALSE;
}

vtkSmartPointer<vtkJPEGReader> jpegReader =
    vtkSmartPointer<vtkJPEGReader>::New();
jpegReader->SetFileName ( "D:\\Albert-Einstein.jpg" );

vtkSmartPointer<vtkImageViewer2> imageViewer;
imageViewer =  vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetInput(jpegReader->GetOutput());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer->SetParentId( hWnd1 );
imageViewer->SetupInteractor(renderWindowInteractor);
imageViewer->Render();
imageViewer->GetRenderer()->ResetCamera();
imageViewer->Render();


vtkSmartPointer<vtkImageViewer2> imageViewer1;
imageViewer1 =  vtkSmartPointer<vtkImageViewer2>::New();
imageViewer1->SetInput(jpegReader->GetOutput());
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor1 =
    vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer1->SetParentId( hWnd2 );
imageViewer1->SetupInteractor(renderWindowInteractor1);
imageViewer1->Render();
imageViewer1->GetRenderer()->ResetCamera();
imageViewer1->Render();


vtkSmartPointer<vtkImageViewer2> imageViewer2;
imageViewer2 =  vtkSmartPointer<vtkImageViewer2>::New();
imageViewer2->SetInput(jpegReader->GetOutput());
  vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor2 =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
imageViewer2->SetParentId( hWnd3 );
imageViewer2->SetupInteractor(renderWindowInteractor2);
imageViewer2->Render();
imageViewer2->GetRenderer()->ResetCamera();
imageViewer2->Render();












On Fri, Jun 17, 2011 at 11:25 PM, pratik <pratik.mallya.ml at gmail.com> wrote:
> Hi,
> You can try using this:
> http://www.vtk.org/Wiki/VTK/Examples/Cxx/IO/JPEGReader
> as a template.
> I ran it on Debian Linux and for a 104.9kb file the process is taking 12MB
>
> HTH,
> Pratik
> On Saturday 18 June 2011 08:24 AM, Suresh Joshi wrote:
>>
>> Hello everyone,
>>
>> Although I don't want to double post and spam the list, I haven't
>> heard any responses to a question I posted on May 27th, so I'll give
>> it another shot with some updated information:
>>
>> My question is still the same and I'm wondering why my stock
>> vtkImageViewer pipeline (quoted below) is using around 50MB of memory
>> on my Windows 7 machine. The jpeg I am displaying is 400x400 pixels.
>>
>> Also, if I were to create a separate
>> Renderer+Window+Interactor+Mapper+etc, the memory footprint should
>> still be the same, correct?
>>
>> Thanks everyone!
>> -SJ
>>
>>
>> On Fri, May 27, 2011 at 3:06 PM, Suresh Joshi<sureshj at gmail.com>  wrote:
>>
>>>
>>> Hello all,
>>>
>>> I've done a fair bit of Googling, but haven't found many topics about
>>> this.
>>>
>>> In most of my applications dealing with ITK/VTK, I haven't cared too
>>> much about the memory used by the viewer, because I'd usually also
>>> have a 3D volumetric reconstruction/registration running at the same
>>> time, but for the first time I've taken note of the memory used by the
>>> viewer window itself.
>>>
>>> In a naive application (in C++ usually, but for instance in python here):
>>> *******
>>> reader = vtkJPEGReader()
>>> # 27kb JPEG file
>>> reader.SetFileName( "Albert-Einstein.jpg" )
>>> reader.Update()
>>>
>>> viewer = vtkImageViewer()
>>> viewer.SetInputConnection( read.GetOutputPort() )
>>>
>>> interactor = vtkRenderWindowInteractor()
>>> viewer.SetupInteractor( interactor )
>>>
>>> viewer.Render()
>>> interactor.Start()
>>> *******
>>>
>>> This 'program' seems to use about 50MB of memory on my Windows 7 box
>>> (with VTK 5.6). When I place these viewers (in c++) in my
>>> applications, I notice a similar usage...
>>>
>>> Now, the problem for me this time is that I need a less
>>> memory-intensive viewer, because I would like to instantiate multiple
>>> (lets say at least 10) vtkImageViewers in my app (yet, greedily, I
>>> would like to keep similar functionality, with interactions and all).
>>>
>>> So I guess I have a few questions:
>>> a) Is there any documentation anywhere discussing the memory
>>> footprints of the vtk viewers/viewports/windows/etc and discussing the
>>> best practices when it comes to keeping memory usage down?
>>> b) Is my naive approach of creating multiple vtkImageViewers the worst
>>> thing I can do (keeping in mind that it gives the exact functionality
>>> that I desire right now)?
>>> c) Should I be looking at having one renderWindow with multiple
>>> viewports instead, with one or more interactors? (And is this
>>> noticeably better?)
>>>
>>> Thanks everyone!
>>> -SJ
>>>
>>>
>>
>> _______________________________________________
>> 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
>>
>
>



More information about the vtkusers mailing list