[vtkusers] Question about memory allocation

Andreas Brüning mail-andi at web.de
Fri Dec 11 08:28:38 EST 2009


Dear VTK user,

i have a some questions about the vtk memory allocation and error handling. At first i should maybe explain what i want to do. I use VTK to perform some medical visualization such as MPR, MIP and VolumeRendering. The images are loaded with another library. So when i initialize the VTK part i put the single pixelvalues  imagesources into a large vtkImageData. To do this i convert ervery image into a vtkImageData. So i get a vector of vtkImageData. Than i use vtkImageAppend to create one big vtkImageData and get a volume out of all the single images. It looks like follows: 

m_vtkVolumeData = vtkImageData::New(); //<-- Result imageData
for (UINT j =0; j < vImageVector.size(); j++)
{
	m_vtkImageAppend->AddInput(vImageVector[j]);
	vImageVector[j]->Delete();
}

m_vtkImageAppend->Update();
m_vtkVolumeData->DeepCopy(m_vtkImageAppend->GetOutput());
m_vtkImageAppend->Delete();

 This volume is the base of all my visualizations. This works well but when i get large imagedata such as an CT series with 512x512px and 600 slices i get a problem creating the volume. I found out that VTK uses malloc to allocate memory for vtkImageData. malloc allocates always one big free memoryblock. If the memory is fragmented malloc fails even when there is enough free memory.

So is there another way to create a volume out of the single images? Most times i have the single images in the memory but the creation of the big volume fails. Is it necessary to create such a big imagedata or can i just connect vtkImageAppend(or maybe with another vtk object) to the rest of the pipline like:
m_vtkmageReslice->SetInput(m_vtkImageAppend->GetOutput());
Or is it the same? 
The next question is about errorhandling. When i don't get enough memory it appears this vtkOutputWindow which tells what is wrong. But how can i figure this out in the code? there is no returnvalue and can't find a way to aks the ImageData if it is correctly allocated or valid.  I tried already a try/catch block but it doesnt work. It crashes later but i want to prevent this. 

Thanks in advance and if you need more information please let me know
Andi






___________________________________________________________
Preisknaller: WEB.DE DSL Flatrate für nur 16,99 Euro/mtl.! 
http://produkte.web.de/go/02/




More information about the vtkusers mailing list