Program: gdcm
Module: $RCSfile: MakeDicomDir.cxx,v $
Language: C++
- Date: $Date: 2005/08/31 09:29:10 $
- Version: $Revision: 1.15 $
+ Date: $Date: 2006/01/26 15:52:42 $
+ Version: $Revision: 1.20 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include <iostream>
-// ---
-void StartMethod(void *toto) {
- (void)toto;
- std::cout<<"Start parsing"<<std::endl;
-}
-
-void EndMethod(void *toto) {
- (void)toto;
- std::cout<<"End parsing"<<std::endl;
-}
-// ---
-
/**
* \brief Explores recursively the given directory
* orders the gdcm-readable found Files
* according their Patient/Study/Serie/Image characteristics
* makes the gdcmDicomDir
- * and writes a file named NewDICOMDIR..
+ * and writes a file named DICOMDIR. (user may choose an other name)
*/
int main(int argc, char *argv[])
" and writes it as 'NewDICOMDIR' ",
" ",
" usage: MakeDicomDir dirname=rootDirectoryName ",
- " [noshadowseq][noshadow][noseq] [debug] ",
+ " name=DICOMDIR file name ",
+ " [noshadowseq][noshadow][noseq] [debug] [check] ",
" ",
+ " name : the default name for the generated dicomdir is 'DICOMDIR' ",
" noshadowseq: user doesn't want to load Private Sequences ",
" noshadow : user doesn't want to load Private groups (odd number) ",
" noseq : user doesn't want to load Sequences ",
" debug : user wants to run the program in 'debug mode' ",
+ " check : the dicomdir is checked as 'gdcm readable' ",
FINISH_USAGE
// ----- Initialize Arguments Manager ------
return 0;
}
- char *dirName;
- dirName = am->ArgMgrGetString("dirName",(char *)".");
+ const char *dirName;
+ dirName = am->ArgMgrGetString("dirName",".");
+ const char *name;
+ name = am->ArgMgrGetString("name","DICOMDIR");
+
int loadMode = gdcm::LD_ALL;
if ( am->ArgMgrDefined("noshadowseq") )
- loadMode |= gdcm::LD_NOSHADOWSEQ;
+ loadMode |= gdcm::LD_NOSHADOWSEQ;
else
{
if ( am->ArgMgrDefined("noshadow") )
if (am->ArgMgrDefined("debug"))
gdcm::Debug::DebugOn();
-
+
+ int check = am->ArgMgrDefined("check");
+
// if unused Param we give up
if ( am->ArgMgrPrintUnusedLabels() )
{
delete am;
return 0;
}
-
+
delete am; // we don't need Argument Manager any longer
// ----- Begin Processing -----
// we ask for Directory parsing
- dcmdir = new gdcm::DicomDir( );
-
- dcmdir->SetStartMethod(StartMethod);
- dcmdir->SetEndMethod(EndMethod);
+ dcmdir = gdcm::DicomDir::New( );
dcmdir->SetLoadMode(loadMode);
dcmdir->SetDirectoryName(dirName);
//dcmdir->SetParseDir(true);
dcmdir->Load();
+ if ( gdcm::Debug::GetDebugFlag() )
+ std::cout << "======================= End Parsing Directory" << std::endl;
+
// ----- Check the result
if ( !dcmdir->GetFirstPatient() )
{
std::cout << "makeDicomDir: no patient found. Exiting."
<< std::endl;
- delete dcmdir;
+ dcmdir->Delete();
return 1;
}
// ----- Create the corresponding DicomDir
- dcmdir->Write("NewDICOMDIR");
- delete dcmdir;
-
- // Read from disc the just written DicomDir
- gdcm::DicomDir *newDicomDir = new gdcm::DicomDir();
- newDicomDir->SetFileName( "NewDICOMDIR" );
- newDicomDir->Load();
- if( !newDicomDir->IsReadable() )
+ dcmdir->Write(name);
+ dcmdir->Delete();
+
+ if (check)
{
- std::cout<<" Written DicomDir 'NewDICOMDIR'"
- <<" is not readable"<<std::endl
- <<" ...Failed"<<std::endl;
+ if ( gdcm::Debug::GetDebugFlag() )
+ std::cout << "======================= End Writting DICOMDIR"
+ << std::endl;
- delete newDicomDir;
- return 1;
- }
-
- if( !newDicomDir->GetFirstPatient() )
- {
- std::cout<<" Written DicomDir 'NewDICOMDIR'"
- <<" has no patient"<<std::endl
- <<" ...Failed"<<std::endl;
-
- delete newDicomDir;
- return(1);
+ // Read from disc the just written DicomDir
+
+ gdcm::DicomDir *newDicomDir = gdcm::DicomDir::New();
+ newDicomDir->SetFileName( name );
+ newDicomDir->Load();
+ if ( gdcm::Debug::GetDebugFlag() )
+ std::cout << "======================= End Parsing DICOMDIR"
+ << std::endl;
+ if( !newDicomDir->IsReadable() )
+ {
+ std::cout<<" Written DicomDir [" << name << "] "
+ <<" is not readable"<<std::endl
+ <<" ...Failed"<<std::endl;
+
+ newDicomDir->Delete();
+ return 1;
+ }
+
+ if( !newDicomDir->GetFirstPatient() )
+ {
+ std::cout <<" Written DicomDir [" << name << "] "
+ <<" has no patient"<<std::endl
+ <<" ...Failed"<<std::endl;
+
+ newDicomDir->Delete();
+ return(1);
+ }
+ std::cout<<std::flush;
+ newDicomDir->Delete();
}
-
- std::cout<<std::flush;
-
- delete newDicomDir;
return 0;
}