Program: gdcm
Module: $RCSfile: exConvert3DplusT.cxx,v $
Language: C++
- Date: $Date: 2006/07/26 17:46:02 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2006/09/01 13:42:02 $
+ Version: $Revision: 1.4 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
gdcm::DirList dirList(dirIn,false); // gets (at single level) the file list
gdcm::DirListType fileList = dirList.GetFilenames();
+
+ // hope sorting on the filename is enough!
+ // anyway, *no* filed is available to perform anything more clever.
+
+ std::sort(fileList.begin(), fileList.end() );
// 'Study Instance UID'
// The user is allowed to create his own Study,
else
strStudyUID = studyUID;
-
// 'Serie Instance UID'
// The user is allowed to create his own Series,
// keeping the same 'Serie Instance UID' for various images
size_t totalNumberOfPixels = imageDimX*imageDimY * imagetteLineNumber*imagetteRowNumber;
int16_t *imageTable = new int16_t[totalNumberOfPixels];
- //std::cout << " imageTable length " << totalNumberOfPixels;
memset(imageTable, 0, totalNumberOfPixels * imagePixelSize);
- int16_t **tabImageData = new int16_t *[nbOfImagesInVolume];
+ int16_t **tabImageData = new int16_t *[nbOfImagesInVolume];
+ gdcm::File **f = new gdcm::File *[nbOfImagesInVolume];
+ gdcm::FileHelper **fh = new gdcm::FileHelper *[nbOfImagesInVolume];
- gdcm::File *f;
- gdcm::FileHelper *fh;
std::string fullFilename, lastFilename;
float zPositionComponent = 0.0;
++it )
{
fullFilename = *it;
- f = gdcm::File::New( );
- f->SetLoadMode(loadMode);
- f->SetFileName( it->c_str() );
+ f[imageNumber] = gdcm::File::New( );
+ f[imageNumber]->SetLoadMode(loadMode);
+ f[imageNumber]->SetFileName( it->c_str() );
if (verbose)
- std::cout << "file [" << it->c_str() << "]" << std::endl;
- if ( !f->Load() )
+ std::cout << "file [" << it->c_str() << "], as imageNumber : " << imageNumber << std::endl;
+
+ if ( !f[imageNumber]->Load() )
{
if (verbose)
std::cout << "fail to load [" << it->c_str() << "]" << std::endl;
- f->Delete();
+ f[imageNumber]->Delete();
continue;
}
// Load the pixels in RAM.
- fh = gdcm::FileHelper::New(f);
+ fh[imageNumber] = gdcm::FileHelper::New(f[imageNumber]);
// Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
- tabImageData[imageNumber] = (int16_t *)fh->GetImageDataRaw();
+ tabImageData[imageNumber] = (int16_t *)fh[imageNumber]->GetImageDataRaw();
+
if (!tabImageData[imageNumber])
{
std::cout << "fail to read [" << it->c_str() << std::endl;
int16_t mini=32000;
int16_t maxi=-32000;
- if (imageNumber == nbOfImagesInVolume)
+ if (imageNumber == nbOfImagesInVolume-1)
{
for(imageNumber=0; imageNumber < nbOfImagesInVolume; imageNumber++)
{
imageTable[debLigne + j] = *(tabImageData[imageNumber] + i*imageDimY + j);
if (imageTable[debLigne + j] < 0) imageTable[debLigne + j]=0;
- if (imageTable[debLigne + j] > 100) imageTable[debLigne + j]=100;
//std::cout << debLigne + j << " : " << imageTable[debLigne + j] << std::endl;
if (*(tabImageData[imageNumber] + i*imageDimY + j) < mini)
// Set the image size
str.str("");
str << imageDimX*imagetteRowNumber;
- fh->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns
+ fh[imageNumber]->InsertEntryString(str.str(),0x0028,0x0011, "US"); // Columns
str.str("");
str << imageDimY*imagetteLineNumber;
- fh->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows
+ fh[imageNumber]->InsertEntryString(str.str(),0x0028,0x0010, "US"); // Rows
- fh->InsertEntryString(strStudyUID,0x0020,0x000d,"UI");
- fh->InsertEntryString(strSerieUID,0x0020,0x000e,"UI");
- fh->InsertEntryString(patName,0x0010,0x0010, "PN"); // Patient's Name
+ fh[imageNumber]->InsertEntryString(strStudyUID,0x0020,0x000d,"UI");
+ fh[imageNumber]->InsertEntryString(strSerieUID,0x0020,0x000e,"UI");
+ fh[imageNumber]->InsertEntryString(patName,0x0010,0x0010, "PN"); // Patient's Name
- fh->SetImageData((uint8_t *)imageTable, totalNumberOfPixels * imagePixelSize);
+ fh[imageNumber]->SetImageData((uint8_t *)imageTable, totalNumberOfPixels * imagePixelSize);
// ==================================================================================================
// Aware use is free to supply his own one !
/*
- if (! f->CheckIfEntryExist(0x0020,0x0037) ) // 0020 0037 DS 6 Image Orientation (Patient)
+ if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x0037) ) // 0020 0037 DS 6 Image Orientation (Patient)
{
- fh->InsertEntryString("1.0\\0.0\\0.0\\0.0\\1.0\\0.0",0x0020,0x0037, "DS"); //[1\0\0\0\1\0] : Axial
+ fh[imageNumber]->InsertEntryString("1.0\\0.0\\0.0\\0.0\\1.0\\0.0",0x0020,0x0037, "DS"); //[1\0\0\0\1\0] : Axial
char charImagePosition[256];
sprintf(charImagePosition,"%f\\0.0\\0.0",zPositionComponent);
zPositionComponent += zSpacing;
- if (! f->CheckIfEntryExist(0x0020,0x0032) ) //0020 0032 DS 3 Image Position (Patient)
- fh->InsertEntryString(charImagePosition,0x0020,0x0032, "DS");
+ if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x0032) ) //0020 0032 DS 3 Image Position (Patient)
+ fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x0032, "DS");
- if (! f->CheckIfEntryExist(0x0020,0x1041) ) // 0020 0x1041 DS 1 Slice Location
+ if (! f[imageNumber]->CheckIfEntryExist(0x0020,0x1041) ) // 0020 0x1041 DS 1 Slice Location
{
sprintf(charImagePosition,"%f",zPositionComponent);
- fh->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
+ fh[imageNumber]->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
}
}
-
*/
// ==================================================================================================
- fh->SetWriteTypeToDcmExplVR();
- fh->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
+ fh[imageNumber]->SetWriteTypeToDcmExplVR();
+ fh[imageNumber]->SetContentType(gdcm::UNMODIFIED_PIXELS_IMAGE);
lastFilename = gdcm::Util::GetName( fullFilename );
+ lastFilename;
if (verbose)
std::cout << "Write : [" << fullWriteFilename << "]" << std::endl;
- if (!fh->Write(fullWriteFilename))
+
+ if (!fh[imageNumber]->Write(fullWriteFilename))
{
std::cout << "Fail to write :[" << fullWriteFilename << "]"
<< std::endl;
}
- //break;
+
+ for(int k=0; k < nbOfImagesInVolume; k++)
+ {
+ fh[k]->Delete();
+ f[k]->Delete();
+ }
+
} // end : 'write the imagette'
- else
+
+ else // start a new 'volume'
{
imageNumber++;
}
- fh->Delete();
- f->Delete();
+
}
}