[vtkusers] vtkDataArray: Memory allocation problem

Liam Kurmos quantum.leaf at googlemail.com
Mon Feb 1 09:22:21 EST 2010


Hi,

I figured out how to do this recently too. Previously I was loading a 1D
array and then using setScalars for the whole volume (as per another
example). Eventually i found  SetScalarComponentFromDouble in the
documentation.

This example would have been helpful but I didn't find it. At first i didn't
appreciate that ImageData could be a volume. I'm not sure a beginner would
know that IterateImageData<http://www.cmake.org/Wiki/VTK/Examples/IterateImageData>is
what theyre looking for.

not sure how this could be best improved, but thought i'd give feedback,

Liam


On Mon, Feb 1, 2010 at 1:26 PM, michiel mentink <
michael.mentink at st-hughs.ox.ac.uk> wrote:

>
> Did you figure out how to create a vtkVolume yet?
> I've tackled the problem myself, can give you an example.
>
> cheers, Michael
>
>
> On Wed, Jan 27, 2010 at 10:33 AM, Malsoaz James <jmalsoaz at yahoo.fr> wrote:
>
>> 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<http://mc/compose?to=jmalsoaz@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<http://mc/compose?to=bill.lorensen@gmail.com>
>>> >* a écrit :
>>>
>>>
>>> De: Bill Lorensen <bill.lorensen at gmail.com<http://mc/compose?to=bill.lorensen@gmail.com>
>>> >
>>> Objet: Re: [vtkusers] vtkDataArray: Memory allocation problem
>>> À: "Malsoaz James" <jmalsoaz at yahoo.fr<http://mc/compose?to=jmalsoaz@yahoo.fr>
>>> >
>>> Cc: vtkusers at vtk.org <http://mc/compose?to=vtkusers@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<http://mc/compose?to=jmalsoaz@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
>>>
>>>
>>
>>
>
> _______________________________________________
> 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/20100201/929b2914/attachment.htm>


More information about the vtkusers mailing list