[vtkusers] creating a texture costs extra 30MB memory,

Francois Bertel francois.bertel at kitware.com
Sat Feb 21 12:45:10 EST 2009


I don't know if the jpeg reader can load an image piece by piece. If
the JPEG Reader can load an image piece by piece, maybe look at class
vtkMemoryLimitImageDataStreamer (I just found it, I don't know how to
use it, maybe somebody else on the list can tell you).

There are two other things to consider:

1. Even if you can load an image piece by piece, in OpenGL, when you
send a texture to the graphics card, the data is copied first from the
process space (RAM) to the driver space (RAM), and then from the
driver space to the card (VRAM). So if your image takes 1MB in RAM
once loaded and uncompressed by the jpeg reader from the disk, just
sending the texture will make the RAM footprint jump to 2MB.

2. On a pretty advanced graphics card (nVidia Quadro FX 3600M, 512MB),
any 2D texture cannot be larger than 8192x8192. It means in the best
case your image
will be divided into two textures. It will be divided in even more
textures on a less advanced graphics card (for example, it is
4096x4096 on an nVidia GeForce 6).



On Fri, Feb 20, 2009 at 11:28 PM, Tracy Hu <tracy.hu at yahoo.com> wrote:
> thanks a lot for help. But is there anyway at all to use the same picture
> for texture, but reduce the memory cost? perhaps at the cost of slower
> rendering?
>
> thanks
>
> tracy
>
>
>
> Assuming your image is one component and a component takes one byte:
> 11083x823/1024/1024=8.7MB.
> If you have three components (RGB), this is 26.1MB (close to 30MB).
>
> So, I guess your 1015KB is actually the size of the compressed jpg file...
>
>
> On Fri, Feb 20, 2009 at 3:16 PM, Tracy Hu <tracy.hu at yahoo.com> wrote:
>> I wrote simple code as following to decide how much memory a vtkTexture
>> would result.
>> without using texture (by commenting out the line
>> "actor->SetTexture(pTexture)" ), the process takes 74MB memory,
>> using texture(by uncommenting the line "actor->SetTexture(pTexture)" ),
>> the
>> process takes 105MB memory.
>> the dimension of picture FOREST011.jpg is 11083 X 823, and takes
>  1,015KB
>>
>> Can somebody give me any idea what's going on, or how to avoid this memory
>> expense?
>>
>> thanks a lot
>> Tracy
>>
>> int main_vtk(int argc, char* argv[])
>> {
>>     vtkJPEGReader* pJPEGReader = vtkJPEGReader::New();
>>         pJPEGReader->SetFileName("D:\\FOREST011.jpg");
>>         pJPEGReader->ReleaseDataFlagOn();
>>     vtkTexture* pTexture = vtkTexture::New();
>>         pTexture->SetInputConnection(pJPEGReader->GetOutputPort());
>>         pTexture->InterpolateOn();
>>         pTexture->ReleaseDataFlagOn();
>>     pJPEGReader->Delete();
>>
>>     vtkSphereSource *sphere = vtkSphereSource::New();
>>     vtkPolyDataMapper *mapper = vtkPolyDataMapper::New();
>>
>       mapper->SetInputConnection(sphere->GetOutputPort());
>>         mapper->ScalarVisibilityOff();
>>     vtkActor *actor = vtkActor::New();
>>         actor->SetMapper(mapper);
>>         actor->GetProperty()->SetColor(0.0, 0.0, 1.0);
>>         actor->SetTexture(pTexture);
>>
>>     vtkRenderer* ren = vtkRenderer::New();
>>         ren->SetBackground(1, 1, 1);
>>         ren->AddActor(actor);
>>
>>     vtkRenderWindow* renWin = vtkRenderWindow::New();
>>         renWin->AddRenderer(ren);
>>
>>     vtkRenderWindowInteractor* iren = vtkRenderWindowInteractor::New();
>>         iren->SetRenderWindow(renWin);
>>     vtkInteractorStyleTrackballCamera *style =
>> vtkInteractorStyleTrackballCamera::New();
>>
>     iren->SetInteractorStyle(style);
>>
>>     renWin->SetSize(600,600);
>>     renWin->SetPosition(600, 100);
>>     renWin->Render();
>>
>>     iren->Initialize();
>>     iren->Start();
>>
>>     return 0;
>> }
>>
>>
>>
>> _______________________________________________
>> 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
>>
>>
>
>
>
> --
> François Bertel, PhD  | Kitware Inc. Suite 204
> 1 (518) 371 3971 x113 | 28 Corporate Drive
>                       | Clifton Park NY 12065, USA
>
>
>
> _______________________________________________
> 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
>
>



-- 
François Bertel, PhD  | Kitware Inc. Suite 204
1 (518) 371 3971 x113 | 28 Corporate Drive
                      | Clifton Park NY 12065, USA



More information about the vtkusers mailing list