Program: gdcm
Module: $RCSfile: exConvert3DplusT.cxx,v $
Language: C++
- Date: $Date: 2006/07/26 17:46:02 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2007/06/21 15:06:13 $
+ Version: $Revision: 1.5 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
// ----- Initialize Arguments Manager ------
- gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+ GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
if (am->ArgMgrDefined("usage") || argc == 1)
{
}
if (am->ArgMgrDefined("debug"))
- gdcm::Debug::DebugOn();
+ GDCM_NAME_SPACE::Debug::DebugOn();
int verbose = am->ArgMgrDefined("verbose");
int oververbose = am->ArgMgrDefined("oververbose");
int nbOfImagesInVolume = am->ArgMgrGetInt("imagesinvolume",
imagetteLineNumber*imagetteRowNumber);
- int loadMode = gdcm::LD_ALL;
+ int loadMode = GDCM_NAME_SPACE::LD_ALL;
if ( am->ArgMgrDefined("noshadowseq") )
- loadMode |= gdcm::LD_NOSHADOWSEQ;
+ loadMode |= GDCM_NAME_SPACE::LD_NOSHADOWSEQ;
else
{
if ( am->ArgMgrDefined("noshadow") )
- loadMode |= gdcm::LD_NOSHADOW;
+ loadMode |= GDCM_NAME_SPACE::LD_NOSHADOW;
if ( am->ArgMgrDefined("noseq") )
- loadMode |= gdcm::LD_NOSEQ;
+ loadMode |= GDCM_NAME_SPACE::LD_NOSEQ;
}
/* if unused Param we give up */
//std::cout << "dirIn [" << dirIn << "]" << std::endl;
- if ( ! gdcm::DirList::IsDirectory(dirIn) )
+ if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirIn) )
{
std::cout << "KO : [" << dirIn << "] is not a Directory." << std::endl;
return 0;
if (verbose)
std::cout << "Check for output directory :[" << dirOut << "]."
<<std::endl;
- if ( ! gdcm::DirList::IsDirectory(dirOut) ) // dirout not found
+ if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirOut) ) // dirout not found
{
systemCommand = "mkdir " +strDirNameout; // create it!
if (verbose)
std::cout << systemCommand << std::endl;
system (systemCommand.c_str());
- if ( ! gdcm::DirList::IsDirectory(dirOut) ) // be sure it worked
+ if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirOut) ) // be sure it worked
{
std::cout << "KO : not a dir : [" << dirOut
<< "] (creation failure ?)" << std::endl;
<< "] already exists; Used as is." << std::endl;
}
- gdcm::DirList dirList(dirIn,false); // gets (at single level) the file list
- gdcm::DirListType fileList = dirList.GetFilenames();
+ GDCM_NAME_SPACE::DirList dirList(dirIn,false); // gets (at single level) the file list
+ GDCM_NAME_SPACE::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,
// adding new Series to an already existing Study
std::string strStudyUID;
if ( !userDefinedStudy)
- strStudyUID = gdcm::Util::CreateUniqueUID();
+ strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
else
strStudyUID = studyUID;
-
// 'Serie Instance UID'
// The user is allowed to create his own Series,
// keeping the same 'Serie Instance UID' for various images
std::string strSerieUID;
if ( !userDefinedSerie)
- strSerieUID = gdcm::Util::CreateUniqueUID();
+ strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
else
strSerieUID = serieUID;
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_NAME_SPACE::File **f = new GDCM_NAME_SPACE::File *[nbOfImagesInVolume];
+ GDCM_NAME_SPACE::FileHelper **fh = new GDCM_NAME_SPACE::FileHelper *[nbOfImagesInVolume];
- gdcm::File *f;
- gdcm::FileHelper *fh;
std::string fullFilename, lastFilename;
float zPositionComponent = 0.0;
int imageNumber = 0;
- for( gdcm::DirListType::iterator it = fileList.begin();
+ for( GDCM_NAME_SPACE::DirListType::iterator it = fileList.begin();
it != fileList.end();
++it )
{
fullFilename = *it;
- f = gdcm::File::New( );
- f->SetLoadMode(loadMode);
- f->SetFileName( it->c_str() );
+ f[imageNumber] = GDCM_NAME_SPACE::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_NAME_SPACE::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_NAME_SPACE::UNMODIFIED_PIXELS_IMAGE);
- lastFilename = gdcm::Util::GetName( fullFilename );
- std::string fullWriteFilename = strDirNameout + gdcm::GDCM_FILESEPARATOR
+ lastFilename = GDCM_NAME_SPACE::Util::GetName( fullFilename );
+ std::string fullWriteFilename = strDirNameout + GDCM_NAME_SPACE::GDCM_FILESEPARATOR
+ 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();
+
}
}