[vtkusers] vtkDataArray: Memory allocation problem
Malsoaz James
jmalsoaz at yahoo.fr
Tue Feb 16 08:24:38 EST 2010
Hi,
I'm still experiencing the same allocation problem even when I use the method given here to build the vtk volume.
Most of the time, my images have the following dimensions: 512*512. I have no allocation error when the number of slice is not important. Nevertheless, when the number of slices is important (more than 350), the error happends. I have realy no idea on how to solve this knowing that I have enough memory to store all this data (3Go of Ram) and that I have been able to construct a vtkVolume of the same size previously in the same program (by the way, I keep it in memory). Certainly the amount of 2 such volume is to big in size.
It is essential to note that I was using int scalars at first. With short, I have no error. I guess in this case, I divide the memory allocation by 2. If I take a volume with 700 slices and short type, the problem will come back.
Anybody with an idea or should I stay with short type hoping to have not too big volumes :) ?
Thank you.
James
--- En date de : Mer 27.1.10, Malsoaz James <jmalsoaz at yahoo.fr> a écrit :
De: Malsoaz James <jmalsoaz at yahoo.fr>
Objet: Re: [vtkusers] vtkDataArray: Memory allocation problem
À: "michiel mentink" <michael.mentink at st-hughs.ox.ac.uk>
Cc: "Bill Lorensen" <bill.lorensen at gmail.com>, vtkusers at vtk.org
Date: Mercredi 27 janvier 2010, 10h33
I need the ITK images data to do some processes. Thus, I use ITK to read the Dicom series. Then, I need to build "manually" the vtkVolume in order to display it.
--- En date de : Mer 27.1.10, michiel mentink <michael.mentink at st-hughs.ox.ac.uk> a écrit :
De: michiel mentink <michael.mentink at st-hughs.ox.ac.uk>
Objet: Re: [vtkusers] vtkDataArray: Memory allocation problem
À: "Malsoaz James" <jmalsoaz at yahoo.fr>
Cc: "Bill Lorensen" <bill.lorensen at gmail.com>, vtkusers at vtk.org
Date: Mercredi 27 Janvier 2010, 9h34
I'm curious, why don't you use the dicomseriesreader? Shown below here is an example to create a metaImage volume,
but writing a VTK volume should be
nearly identical:
int main(int argc, char *argv[])
{
if(argc != 3)
{
vtkstd::cout << "Required arguments: Folder containing .dcm files and also name of OutputFile" << vtkstd::endl;
}
vtkstd::string folder = argv[1];
vtkstd::string outputFile = argv[2];
// Read all the DICOM files in the specified directory.
vtkSmartPointer<vtkDICOMImageReader> reader = vtkSmartPointer<vtkDICOMImageReader>::New();
reader->SetDirectoryName(folder.c_str());
reader->Update();
vtkImageData* imagedata = reader->GetOutput();
vtkSmartPointer<vtkMetaImageWriter> metaImageWriter = vtkSmartPointer<vtkMetaImageWriter>::New();
metaImageWriter->SetInput(imagedata);
metaImageWriter->SetFileName(outputFile.c_str());
metaImageWriter->Update();
return 0;
} Michael
On Wed, Jan 27, 2010 at 8:21 AM, Malsoaz James <jmalsoaz at yahoo.fr> wrote:
Thanks for the answer. I guess I need to add some explanation to my application.
I'm reading a Dicom series using ITK to build a 3D vtk volume. This
part is working well whatever the number of slices. I have no problem
for the allocation with vtkIntArray.
Here is the code for this part:
scalars=vtkIntArray::New();
scalars->SetNumberOfValues(nbPixelX*nbPixelY*nbPixelZ);
std::vector <ImageType::Pointer>::iterator iterator;
iterator = SlicesList.begin();
for (unsigned int lz=0;lz<numberOfSlice;lz++)
{
itk::ImageRegionConstIterator<ImageType> inputIt(*iterator, (*iterator)->GetLargestPossibleRegion());
inputIt.GoToBegin();
int currentvalue;
while( !inputIt.IsAtEnd() )
{
lurrentvalue = inputIt.Get();
m_scalars->SetValue(offset,currentvalue);
offset++;
++inputIt;
iterator++;
}
As I said, this is working and I have been able to allocate X*Y*Z elements in my vtkIntArray.
Then, I'm working with ITK to do some process with ITK (threshold,
opening, closing, labeling, ...). At the end, I have the boundaries of
some objects in my slices.
In order to display these boundaries on the vtkVolume, I'm building a
new 3D volume with only the boundaries. Further to this, I'm displaying
the boundaries on the raw volume using Texture. The error of allocation
appears here and only when the number of slices in my volume is
important (more than 300 slices). Here is the code I'm using:
vtkIntArray* scalars = vtkIntArray::New();
scalars->SetNumberOfValues(nbPixelX*nbPixelY*nbPixelZ);
for (points in my boundaries)
{
scalars->SetValue(offset,1);
}
Note that the error appears at the first "SetValue". I have been trying
to fill the new volume with 0 using "InsertTuple1(offset, 0)". Thus,
I'm able to see where the allocation is crashing. It seems to be around
the 33 555 448th elements. I can't explain why.
I hope this has clarify my problem.
Best
James
--- En date de : Mar 26.1.10, Bill Lorensen <bill.lorensen at gmail.com> a écrit :
De: Bill Lorensen <bill.lorensen at gmail.com>
Objet: Re: [vtkusers] vtkDataArray: Memory allocation problem
À: "Malsoaz James" <jmalsoaz at yahoo.fr>
Cc: vtkusers at vtk.org
Date: Mardi 26 Janvier 2010, 16h10
Are there other filters involved in the processing? What does your vtk pipeline look like?
On Tue, Jan 26, 2010 at 10:59 AM, Malsoaz James <jmalsoaz at yahoo.fr> wrote:
Hello,
First of all, I would like to expose the context of my problem. I'm working on an application which is in charge of loading/building a 3D volume from Dicom files. The building of the 3D volume is working perfectly using a vtkIntArray and setScalars().
Unfortunately, later in the software, I need to rebuild a new 3D volume using one more time vtkIntArray with the same size but I got an error like: vtkIntArray: Unable to allocate X elements of size 4. Although I have enough memory (I have 3Go of RAM), I'm doing exactly the same thing as the first build and the charge on Windows for the application is always under 1Go. My application is working with small volume (ie 150 slices) and I got this allocation error with big volume (ie more than 300 slices).
For information, the images have a size of 512*512.
Do you know what is the
origin of the problem? How can I solve this ?
Best
James
_______________________________________________
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
_______________________________________________
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/20100216/12bfbb05/attachment.htm>
More information about the vtkusers
mailing list