C++ & VTK : fail to find origins of DICOM image after write, load it

I’m in trouble with my DICOM images. I want to find the origins of my images after write it and load it, but I can’t. Nevertheless, I can find spacing and number of voxels, the same way as origins…

I will try to give you some pieces of code.
First of all, I wrote a DICOM image using vtkDICOMReader (maybe an old version of VTKDICOMImageReader?) on a VTKImageData. I took care to set up my vtkImageData with all the information :

vtkSmartPoint<vtkImageData> spectDada = vtkSmartPoint<vtkImageData>::New();
spectData->SetOrigin( 50, 50, 50 );  
spectData->SetDimension( 128, 128, 128);
spectData->SetSpacing( 4.667, 4.667, 4.667);
spectData->AllocateScalars(VTK_UNSIGNED_SHORT,3);
spectData->GetPointData()->SetScalars(scalars);  //scalar contains my voxel index and its values

vtkSmartPoint<vtkDICOMMetaData> meta = vtkSmartPoint<vtkDICOMMetaData>::New();
vtkSmartPoint<vtkDICOMMRGenerator> generator = vtkSmartPoint<vtkDICOMMRGenerator>::New();
vtkSmartPoint<vtkDICOMMRGenerator> writer = vtkSmartPoint<vtkDICOMWriter>::New();
writer->SetInputData(spectData);
writer->SetGenerator(generator);
writer->SetMetaData(meta);
writer->SetMemoryRowOrderToFileNative();
writer->Write();

Then, I load the images using vtkDICOMReader (not vtkDICOMImageReader -> old version?):

vtkSmartPoint<vtkStringArray> files = vtkSmartPoint<vtkStringArray>::New();
files->InsertNextValue(completePath);  //the folder path containing my DICOM images

vtkSmartPoint<vtkDICOMSorter> sorter = vtkSmartPoint<vtkDICOMSorter>::New();
sorter->SetInputFileNames(files);
sorter->Update();
vtkStringArray *a = sorter->GetOutputFileNames();

vtkSmartPointer<vtkDICOMReader> readerVTK = vtkSmartPointer<vtkDICOMReader>::New();
readerVTK->SetFileNames(a);
readerVTK->Update();
readerVTK->SetMemoryRowOrderTOTopDown();

int *extent =     reader->GetDataExtent();   //working
double *spacing = reader->GetDataSpacing();  //working
double *origin =  reader->GetDataOrigin();   //NOT working

If people understand what’s going on with finding origins, I will apreciate.

Florian


Source: c++

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.