Program: gdcm
Module: $RCSfile: DenseMultiFramesToDicom.cxx,v $
Language: C++
- Date: $Date: 2006/07/26 17:02:55 $
- Version: $Revision: 1.4 $
+ Date: $Date: 2007/06/27 08:38:44 $
+ Version: $Revision: 1.7 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
* WARNING : directory must contain ONLY .txt files
*/
-
void Load(std::ifstream &from, std::string imageName, std::string patName,
- std::string strStudyUID, int serieNumber);
+ std::string strStudyUID, std::string strSerieUID, int serieNumber, int verbose);
//std::ifstream& eatwhite(std::ifstream& is);
int main(int argc, char *argv[])
{
START_USAGE(usage)
- " \n DenseMultiFramessToDicom : \n",
+ " \n DenseMultiFramesToDicom : \n",
" - explores recursively the given (single Patient, single Study) directory",
" - examines the '.txt' files ",
" - Converts the files into 16 bits Dicom files, ",
" [studyUID = ] [patName = ] ",
" [listonly] [verbose] [debug] ",
" ",
- "studyUID : *aware* user wants to add the serie ",
+ " studyUID : *aware* user wants to add the serie ",
" to an already existing study ",
" verbose : user wants to run the program in 'verbose mode' ",
" debug : *developer* wants to run the program in 'debug mode' ",
// ----- Initialize Arguments Manager ------
- gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv);
+ GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv);
if (argc == 1 || am->ArgMgrDefined("usage"))
{
dirNamein = am->ArgMgrGetString("dirin",".");
if (am->ArgMgrDefined("debug"))
- gdcm::Debug::DebugOn();
+ GDCM_NAME_SPACE::Debug::DebugOn();
int verbose = am->ArgMgrDefined("verbose");
int listonly = am->ArgMgrDefined("listonly");
std::string patName = am->ArgMgrGetString("patname", dirNamein);
bool userDefinedStudy = am->ArgMgrDefined("studyUID");
- const char *studyUID = am->ArgMgrGetString("studyUID");
+ const char *studyUID;
+ if (userDefinedStudy)
+ studyUID = am->ArgMgrGetString("studyUID");
-// not described *on purpose* in the Usage !
+ // not described *on purpose* in the Usage !
+
bool userDefinedSerie = am->ArgMgrDefined("serieUID");
- const char *serieUID = am->ArgMgrGetString("serieUID");
-
-
+ const char *serieUID;
+ if(userDefinedSerie)
+ serieUID = am->ArgMgrGetString("serieUID");
+
// if unused Param we give up
if ( am->ArgMgrPrintUnusedLabels() )
{
// ----- Begin Processing -----
- if ( ! gdcm::DirList::IsDirectory(dirNamein) )
+ if ( ! GDCM_NAME_SPACE::DirList::IsDirectory(dirNamein) )
{
std::cout << "KO : [" << dirNamein << "] is not a Directory."
<< std::endl;
}
else
{
- std::cout << "OK : [" << dirNamein << "] is a Directory." << std::endl;
+ if (verbose)
+ std::cout << "OK : [" << dirNamein << "] is a Directory." << std::endl;
}
std::string strDirNamein(dirNamein);
- gdcm::DirList dirList(strDirNamein, true); // (recursively) the list of files
+ GDCM_NAME_SPACE::DirList dirList(strDirNamein, true); // (recursively) the list of files
if (listonly)
{
std::string filenameout;
+
+
+
std::string strStudyUID;
- strStudyUID = gdcm::Util::CreateUniqueUID();
+ std::string strSerieUID;
+
+ if (userDefinedStudy)
+ strSerieUID = studyUID;
+ else
+ strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
+
+ if (userDefinedStudy)
+ strSerieUID = serieUID;
+ else
+ strStudyUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
+
+
int serieNumber =0;
- gdcm::DirListType fileNames;
+ GDCM_NAME_SPACE::DirListType fileNames;
fileNames = dirList.GetFilenames();
- for (gdcm::DirListType::iterator it = fileNames.begin();
+ for (GDCM_NAME_SPACE::DirListType::iterator it = fileNames.begin();
it != fileNames.end();
++it)
{
- if ( gdcm::Util::GetName((*it)).c_str()[0] == '.' )
+ if ( GDCM_NAME_SPACE::Util::GetName((*it)).c_str()[0] == '.' )
{
// skip hidden files
continue;
}
else
{
- std::cout << "Success in open file" << *it << std::endl;
- Load(from, *it, patName, strStudyUID, serieNumber);
+ if (verbose)
+ std::cout << "Success in open file" << *it << std::endl;
+ Load(from, *it, patName, strStudyUID, strSerieUID, serieNumber, verbose);
serieNumber+=2;
//return 0;
}
void Load(std::ifstream &from, std::string imageName, std::string patName,
- std::string strStudyUID, int serieNumber)
+ std::string strStudyUID, std::string strSerieUID, int serieNumber, int verbose)
{
- std::cout << " ========= Deal with file [" << imageName << "]" << std::endl;
+ if (verbose)
+ std::cout << " ========= Deal with file [" << imageName << "]" << std::endl;
if (!from)
return;
- std::cout << " ========= Create Parametric images" << std::endl;
+ if (verbose)
+ std::cout << " ========= Create Parametric images" << std::endl;
/* was OK for single frames
eg :
---------------------------
from >> str1;
from >> str1; // 52x59x14
- std::cout << "[" << str1 << "]" << std::endl;
+ if(verbose)
+ std::cout << "[" << str1 << "]" << std::endl;
sscanf( str1.c_str(),"%dx%dx%d", &nx,&ny,&nf);
std::cout << nx << " " << ny << " " << nf << std::endl;
float temporalResolution;
sscanf( str1.c_str(),"%f",&temporalResolution);
- std::cout << "temporal Resolution = " << temporalResolution << std::endl;
+ if(verbose)
+ std::cout << "temporal Resolution = " << temporalResolution << std::endl;
std::getline(from, str1);
from >> str1; // First
}
//float *f = new float(nx*ny);
+ // -->float *f = new float[nx*ny]; // Would be better !
float *f = (float *) malloc(nx*ny*nf*sizeof(float));
// float mini = FLT_MAX, maxi = FLT_MIN;
float val;
-
- std::string strSerieUID;
- strSerieUID = gdcm::Util::CreateUniqueUID();
+
int imageNumber = 0;
float currentTime;
currentTime = timeStart;
- for (int l=0; l<nf; l++) // Loop on the frames
- {
- //std::cout << "Frame nb " << l << std::endl;
+ int l1;
+ for (l1=0; l1<nf; l1++) // Loop on the frames
+ {
+ //std::cout << "Frame nb " << l1 << std::endl;
for( int j=0; j<ny; j++)
{
for (int i=0; i<nx; i++)
ptr++;
}
- // gdcm::Debug::DebugOn();
+ // GDCM_NAME_SPACE::Debug::DebugOn();
std::ostringstream str;
- gdcm::File *file;
- file = gdcm::File::New();
+ GDCM_NAME_SPACE::File *file;
+ file = GDCM_NAME_SPACE::File::New();
// Set the image size
str.str("");
// 0020 0032 DS 3 Image Position (Patient)
char charImagePosition[256];
- sprintf(charImagePosition,"0.0\\0.0\\%f",float(l%nf));
+ sprintf(charImagePosition,"0.0\\0.0\\%f",float(l1%nf));
// 0020 0x1041 DS 1 Slice Location
- sprintf(charImagePosition,"%f",float(l%nf));
+ sprintf(charImagePosition,"%f",float(l1%nf));
file->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
//0008 103e LO 1 Series Description
// file->Print();
- gdcm::FileHelper *fh;
- fh = gdcm::FileHelper::New(file);
+ GDCM_NAME_SPACE::FileHelper *fh;
+ fh = GDCM_NAME_SPACE::FileHelper::New(file);
// cast is just to avoid warnings (*no* conversion)
fh->SetImageData((uint8_t *)img,nx*ny*sizeof(uint16_t));
fh->SetWriteModeToRaw();
fh->SetWriteTypeToDcmExplVR();
char numero[10];
- sprintf(numero, "%02d", l);
+ sprintf(numero, "%02d", l1);
std::string fileName = imageName + "." + numero + ".dcm";
- std::cout << "fileName " << fileName << std::endl;
+ if(verbose)
+ std::cout << "fileName " << fileName << std::endl;
if( !fh->Write(fileName))
std::cout << "Failed for [" << fileName << "]\n"
// Anatomical Images.
std::cout << " ========= Create Anatomical images" << std::endl;
- strSerieUID = gdcm::Util::CreateUniqueUID();
+ strSerieUID = GDCM_NAME_SPACE::Util::CreateUniqueUID();
imageNumber = 0;
currentTime = timeStart;
- for (int l=0; l<nf; l++) // Loop on the frames
+ for (int fr=0; fr<nf; fr++) // Loop on the frames
{
//std::cout << "Frame nb " << l << std::endl;
for( int j=0; j<ny; j++)
ptr++;
}
std::ostringstream str;
- gdcm::File *file;
- file = gdcm::File::New();
+ GDCM_NAME_SPACE::File *file;
+ file = GDCM_NAME_SPACE::File::New();
// Set the image size
str.str("");
// 0020 0032 DS 3 Image Position (Patient)
char charImagePosition[256];
- sprintf(charImagePosition,"0.0\\0.0\\%f",float(l%nf));
+ sprintf(charImagePosition,"0.0\\0.0\\%f",float(l1%nf));
// 0020 0x1041 DS 1 Slice Location
- sprintf(charImagePosition,"%f",float(l%nf));
+ sprintf(charImagePosition,"%f",float(l1%nf));
file->InsertEntryString(charImagePosition,0x0020,0x1041, "DS");
//0008 103e LO 1 Series Description
file->InsertEntryString(charImagePosition,0x0018,0x1060, "DS");
// file->Print();
- gdcm::FileHelper *fh;
- fh = gdcm::FileHelper::New(file);
+ GDCM_NAME_SPACE::FileHelper *fh;
+ fh = GDCM_NAME_SPACE::FileHelper::New(file);
// cast is just to avoid warnings (*no* conversion)
fh->SetImageData((uint8_t *)img,nx*ny*sizeof(uint16_t));
fh->SetWriteModeToRaw();
fh->SetWriteTypeToDcmExplVR();
char numero[10];
- sprintf(numero, "%02d", l);
+ sprintf(numero, "%02d", l1);
std::string fileName = imageName + ".Anatomical." + numero + ".dcm";
std::cout << "fileName " << fileName << std::endl;
} // end loop on frames
from.close();
-}
+} // end void Load(