[vtkusers] vtkDataArray: Memory allocation problem
michiel mentink
michael.mentink at st-hughs.ox.ac.uk
Wed Jan 27 04:34:54 EST 2010
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<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
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20100127/f28c8aa3/attachment.htm>
More information about the vtkusers
mailing list