Program: gdcm
Module: $RCSfile: PrintFile.cxx,v $
Language: C++
- Date: $Date: 2007/05/23 14:18:04 $
- Version: $Revision: 1.84 $
+ Date: $Date: 2007/11/08 18:14:55 $
+ Version: $Revision: 1.88 $
Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de
l'Image). All rights reserved. See Doc/License.txt or
#include "gdcmOrientation.h"
#include <iostream>
-// TODO : code factorization, for 'single file' an 'whole directory' processing
+/// \todo : code factorization, for 'single file' an 'whole directory' processing
void ShowLutData(GDCM_NAME_SPACE::File *f);
" \n PrintFile : \n ",
" Display the header of a ACR-NEMA/PAPYRUS/DICOM File ",
" usage: PrintFile {filein=inputFileName|dirin=inputDirectoryName}[level=n]",
- " [forceload=listOfElementsToForceLoad] ",
+ " [forceload=listOfElementsToForceLoad] [rec] [noex] ",
" [4DLoc= ][dict= privateDirectory] ",
" [ { [noshadowseq] | [noshadow][noseq] } ] ",
" [debug] [warning] ",
" level = 0,1,2 : depending on the amount of details user wants to see",
+ " rec : user wants to parse recursively the directory ",
+ " noex : user doen't want extra 'user friendly' info ",
" 4DLoc: group-elem(in hexa, no space) of the DataEntry holdind 4thDim",
" listOfElementsToForceLoad : group-elem,g2-e2,... (in hexa, no space)",
" of Elements to load whatever their length ",
am->ArgMgrUsage(usage); // Display 'usage'
delete am;
return 1;
- }
-
+ }
+
+ bool noex = ( 0 != am->ArgMgrDefined("noex") );
+ bool rec = ( 0 != am->ArgMgrDefined("rec") );
+
if (am->ArgMgrDefined("debug"))
GDCM_NAME_SPACE::Debug::DebugOn();
int forceLoadNb;
uint16_t *elemsToForceLoad
= am->ArgMgrGetXInt16Enum("forceload", &forceLoadNb);
-
- int nbP;
+
+ int nbP =0;
uint16_t *FourthDimLoc;
if ( am->ArgMgrDefined("4DLoc") )
{
// ----------- End Arguments Manager ---------
-
+
if (ddict)
{
- GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->AddDict(dict);
+ GDCM_NAME_SPACE::Global::GetDicts()->GetDefaultPubDict()->AddDict(dict);
}
if ( fileName != 0 ) // ====== Deal with a single file ======
- {
+ {
GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New();
f->SetLoadMode(loadMode);
f->SetFileName( fileName );
+ f->SetMaxSizeLoadEntry(0xffff);
for (int ri=0; ri<forceLoadNb; ri++)
{
f->AddForceLoadElement((uint32_t)elemsToForceLoad[2*ri],
- (uint32_t)elemsToForceLoad[2*ri+1] );
+ (uint32_t)elemsToForceLoad[2*ri+1] );
}
// TODO : find why such a polution
-// To avoid polluting the output with messages
+// To avoid polluting the output with messages
// 'Last system error was : No such file or directory'
errno = 0;
- bool res = f->Load();
+ bool res = false;
+ try
+ {
+ f->Load();
+ }
+ catch(std::exception &ex)
+ {
+ std::cerr << "sorry an exception was thrown: " << ex.what() << std::endl;
+ }
// GDCM_NAME_SPACE::File::IsReadable() is no usable here, because we deal with
- // any kind of gdcm-Parsable *document*
+ // any kind of gdcm-Parsable *document*
// not only GDCM_NAME_SPACE::File (as opposed to GDCM_NAME_SPACE::DicomDir)
if ( !res )
{
std::cout << "Cannot process file [" << fileName << "]" << std::endl;
- std::cout << "Either it doesn't exist, or it's read protected "
+ std::cout << "Either it doesn't exist, or it's read protected "
<< std::endl;
- std::cout << "or it's not a Dicom File, or its 'header' is bugged"
+ std::cout << "or it's not a Dicom File, or its 'header' is bugged"
<< std::endl;
std::cout << "use 'PrintFile filein=... debug' to try to guess the pb"
<< std::endl;
f->Delete();
return 0;
}
+
if (nbP == 1)
f->SetFourthDimensionLocation(FourthDimLoc[0],FourthDimLoc[1]);
+
GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
fh->SetPrintLevel( level );
fh->Print();
- std::cout << "\n\n" << std::endl;
+ std::cout << "\n\n" << std::endl;
std::cout <<std::endl;
std::cout <<" dataSize " << fh->GetImageDataSize() << std::endl;
std::cout <<" dataSizeRaw " << fh->GetImageDataRawSize() << std::endl;
-
+if (!noex)
+{
int nX,nY,nZ,nT,sPP,planarConfig;
std::string pixelType;
nX=f->GetXSize();
std::string ori = o->GetOrientation ( f );
if (ori != "\\" )
std::cout << "Orientation [" << ori << "]" << std::endl;
-
- o->Delete();
+ o->Delete();
+}
//------------------------------
f->Delete();
fh->Delete();
}
- else // ====== Deal with a Directory ======
- {
+ // ===========================================================================
+ else // =============================== Deal with a Directory =====================
+ { // ===========================================================================
std::cout << "dirName [" << dirName << "]" << std::endl;
- GDCM_NAME_SPACE::DirList dirList(dirName,1); // gets recursively the file list
+
+ GDCM_NAME_SPACE::DirList dirList(dirName,rec); // gets recursively (or not) the file list
GDCM_NAME_SPACE::DirListType fileList = dirList.GetFilenames();
GDCM_NAME_SPACE::File *f;
bool res;
+ if (fileList.size() == 0)
+ {
+ std::cout << "No file found in : [" << dirName << "]" << std::endl;
+ }
+
for( GDCM_NAME_SPACE::DirListType::iterator it = fileList.begin();
it != fileList.end();
++it )
fh->Print();
//------------------------------
-
+if (!noex)
+{
// Lets's get and print some usefull fields about 'Orientation'
// ------------------------------------------------------------
if (ori != "\\" )
std::cout << "Orientation [" << ori << "]" << std::endl;
o->Delete();
-
+}
//-------------------------------
if (f->IsReadable())