Program: gdcm
Module: $RCSfile: PhilipsToBrucker.cxx,v $
Language: C++
- Date: $Date: 2005/12/22 15:03:52 $
- Version: $Revision: 1.2 $
+ Date: $Date: 2006/01/26 15:52:42 $
+ Version: $Revision: 1.6 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmDicomDir.h"
#include "gdcmDicomDirPatient.h"
#include "gdcmFile.h"
+#include "gdcmFileHelper.h"
#include "gdcmDirList.h"
#include "gdcmDebug.h"
#include "gdcmArgMgr.h"
* according to their Patient/Study/Serie/Image characteristics
* - fills a single level Directory with *all* the files,
* converted into a Brucker-like Dicom, Intags compliant
- *
+ *
*/
typedef std::map<std::string, gdcm::File*> SortedFiles;
int main(int argc, char *argv[])
{
-
START_USAGE(usage)
" \n PhilipsToBrucker :\n ",
" - explores recursively the given directory, ",
return 0;
}
- char *dirNamein;
- dirNamein = am->ArgMgrGetString("dirin",(char *)".");
+ const char *dirNamein;
+ dirNamein = am->ArgMgrGetString("dirin",".");
- char *dirNameout;
- dirNameout = am->ArgMgrGetString("dirout",(char *)".");
+ const char *dirNameout;
+ dirNameout = am->ArgMgrGetString("dirout",".");
int loadMode = gdcm::LD_ALL;
if ( am->ArgMgrDefined("noshadowseq") )
int nbSeriesToDrop;
int *seriesToDrop = am->ArgMgrGetListOfInt("drop", &nbSeriesToDrop);
- std::cout << nbSeriesToKeep << " " << nbSeriesToDrop << std::endl;
if ( nbSeriesToKeep!=0 && nbSeriesToDrop!=0)
{
std::cout << "KEEP and DROP are mutually exclusive !" << std::endl;
return 0;
}
- char *extent = am->ArgMgrGetString("extent",".DCM");
+ const char *extent = am->ArgMgrGetString("extent",".DCM");
// if unused Param we give up
if ( am->ArgMgrPrintUnusedLabels() )
if ( ! gdcm::DirList::IsDirectory(dirNamein) )
{
- std::cout << "not a directory : [" << dirNamein << "]" << std::endl;
+ std::cout << "KO : [" << dirNamein << "] is not a Directory : " << std::endl;
exit(0);
}
+ else
+ {
+ std::cout << "OK : [" << dirNamein << "]" << " is a Directory" << std::endl;
+ }
+
+
std::string systemCommand;
- if ( ! gdcm::DirList::IsDirectory(dirNameout) ) // dirout not found
+ if ( ! gdcm::DirList::IsDirectory(dirNameout) ) // dirout not found
{
- std::string strDirNameout(dirNameout); // to please gcc 4
- systemCommand = "mkdir " +strDirNameout; // create it!
+ std::string strDirNameout(dirNameout); // to please gcc 4
+ systemCommand = "mkdir " +strDirNameout; // create it!
+ if (verbose)
+ std::cout << systemCommand << std::endl;
system (systemCommand.c_str());
if ( ! gdcm::DirList::IsDirectory(dirNameout) ) // be sure it worked
{
- std::cout << "not a dir : [" << dirNameout << "]" << std::endl;
+ std::cout << "KO : not a dir : [" << dirNameout << "] (creation failure ?)" << std::endl;
exit(0);
}
+ else
+ {
+ std::cout << "Directory [" << dirNameout << "]" << " created" << std::endl;
+ }
+ }
+ else
+ {
+ std::cout << "Output Directory [" << dirNameout << "]" << " already exists; Used as is." << std::endl;
}
-
std::string strDirNamein(dirNamein);
gdcm::DirList dirList(strDirNamein, true); // get recursively the list of files
- /*
- std::cout << "---------------File list found ------------" << std::endl;
+/*
+ std::cout << "---------------List of found files ------------" << std::endl;
dirList.Print();
*/
gdcm::DirListType fileNames;
fileNames = dirList.GetFilenames();
- gdcm::SerieHelper *s; // Needed only to may use SerieHelper::AddSeriesDetail()
+ gdcm::SerieHelper *s; // Needed only to may use SerieHelper::AddSeriesDetail()
s = gdcm::SerieHelper::New();
/*
*/
gdcm::File *f;
-
-/*
+ gdcm::FileHelper *fh;
+/*
std::cout << "---------------Print Unique Series identifiers---------"
<< std::endl;
std::string uniqueSeriesIdentifier;
}
}
if ( !keep)
- continue;
+ {
+ f->Delete();
+ continue;
+ }
}
// drop all unrequested Series
bool drop = false;
for (j=0;j<nbSeriesToDrop; j++)
{
if(seriesNumber == seriesToDrop[j])
- {
+ {
drop = true;
break;
}
}
if (drop)
+ {
+ f->Delete();
continue;
+ }
}
userFileIdentifier=s->CreateUserDefinedFileIdentifier(f);
fullFilename = currentFile->GetFileName();
lastFilename = gdcm::Util::GetName( fullFilename );
- if (verbose)
- std::cout << "==== === === === " << it2->first << " "
- << (it2->second)->GetFileName() << " "
- << gdcm::Util::GetName( fullFilename ) <<std::endl;
+
tokens.clear();
gdcm::Util::Tokenize (it2->first, tokens, "_");
if (verbose)
std::cout << "==== new Patient " << currentPatientName << std::endl;
previousPatientName = currentPatientName;
- previousSerieInstanceUID = currentSerieInstanceUID;
- previousImagePosition = currentImagePosition;
- previousPhaseEncodingDirection = currentPhaseEncodingDirection;
+ previousSerieInstanceUID = ""; //currentSerieInstanceUID;
+ previousImagePosition = ""; //currentImagePosition;
+ previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
currentWriteDir = writeDir + currentPatientName;
if ( ! gdcm::DirList::IsDirectory(currentWriteDir) )
{
systemCommand = "mkdir " + currentWriteDir;
+ if (verbose)
+ std::cout << systemCommand << std::endl;
system ( systemCommand.c_str() );
}
}
std::cout << "==== === new Serie " << currentSerieInstanceUID
<< std::endl;
previousSerieInstanceUID = currentSerieInstanceUID;
- previousImagePosition = currentImagePosition;
- previousPhaseEncodingDirection = currentPhaseEncodingDirection;
+ previousImagePosition = ""; //currentImagePosition;
+ previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
}
if (previousImagePosition != currentImagePosition)
{
if (verbose)
- std::cout << "==== === === new Position " << currentImagePosition
+ std::cout << "=== === === new Position " << currentImagePosition
<< std::endl;
previousImagePosition = currentImagePosition;
- previousPhaseEncodingDirection = currentPhaseEncodingDirection;
+ previousPhaseEncodingDirection = ""; //currentPhaseEncodingDirection;
sliceIndex += 1;
}
{
if (verbose)
std::cout << "==== === === === new PhaseEncodingDirection "
- << currentImagePosition << std::endl;
+ << currentPhaseEncodingDirection << std::endl;
previousPhaseEncodingDirection = currentPhaseEncodingDirection;
- }
-
- frameIndex++;
-
+ }
+ frameIndex++;
+ if (verbose)
+ std::cout << "--- --- --- --- --- " << (it2->second)->GetFileName()
+ << std::endl;
+ if ( gdcm::Debug::GetDebugFlag())
+ std::cout << "--- --- --- --- --- " << it2->first << " "
+ << (it2->second)->GetFileName() << " "
+ << gdcm::Util::GetName( fullFilename ) << std::endl;
// Transform the image to be 'Brucker-Like'
// ----------------------------------------
float pxSzY = currentFile->GetYSpacing();
char fov[64];
sprintf(fov, "%f\\%f",nX*pxSzX, nY*pxSzY);
- std::cout << fov << std::endl;
currentFile->InsertEntryString(fov, 0x0019, 0x1000, "DS");
// Deal with 0x0020, 0x0012 : 'SESSION INDEX'
sprintf(chFrameIndex, "%04d", frameIndex);
currentFile->InsertEntryString(chFrameIndex, 0x0021, 0x1040, "IS");
- std::string strExtent(extent);
- systemCommand = "cp " + fullFilename + " " + currentWriteDir +
- "/" + lastFilename + strExtent;
+ std::string strExtent(extent);
+ std::string fullWriteFilename = currentWriteDir + gdcm::GDCM_FILESEPARATOR + lastFilename + strExtent;
+
+ /*
+ systemCommand = "cp " + fullFilename + " " + fullWriteFilename;
std::cout << systemCommand << std::endl;
- //system ( systemCommand.c_str() );
-
+ system ( systemCommand.c_str() );
+ */
+
+ // Load the pixels in RAM.
+
+ fh = gdcm::FileHelper::New(currentFile);
+ fh->GetImageDataRaw(); // Don't convert (Gray Pixels + LUT) into (RGB pixels) ?!?
+ fh->SetWriteTypeToDcmExplVR();
+ fh->Write(fullWriteFilename);
+ fh->Delete();
}
}