X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=Example%2FPrintFile.cxx;h=6a01b9041faab88f618a916b8b98e268ae82d95e;hb=1eace7fe2d9708f674da4abe0461f4bb1d734c52;hp=71ef4ab5d2916a8c04d5523f1c8fcb9696a132fe;hpb=bc69950a406d06c50f0fb75a96572784965cb534;p=gdcm.git diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index 71ef4ab5..6a01b904 100644 --- a/Example/PrintFile.cxx +++ b/Example/PrintFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PrintFile.cxx,v $ Language: C++ - Date: $Date: 2005/10/18 08:35:43 $ - Version: $Revision: 1.63 $ + Date: $Date: 2005/10/20 08:53:21 $ + Version: $Revision: 1.65 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -40,85 +40,85 @@ void ShowLutData(gdcm::File *f); void ShowLutData(gdcm::File *f) { - gdcm::SeqEntry *modLutSeq = f->GetSeqEntry(0x0028,0x3000); - if ( modLutSeq !=0 ) + gdcm::SeqEntry *modLutSeq = f->GetSeqEntry(0x0028,0x3000); + if ( modLutSeq !=0 ) + { + gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem(); + if ( sqi != 0 ) { - gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem(); - if ( sqi != 0 ) + std::string lutDescriptor = sqi->GetEntryString(0x0028,0x3002); + if ( /*lutDescriptor == GDCM_UNFOUND*/ 0 ) { - std::string lutDescriptor = sqi->GetEntryString(0x0028,0x3002); - if ( /*lutDescriptor == GDCM_UNFOUND*/ 0 ) - { - //gdcmWarningMacro( "LUT Descriptor is missing" ); - std::cout << "LUT Descriptor is missing" << std::endl; - return; - } - int length; // LUT length in Bytes - int deb; // Subscript of the first Lut Value - int nbits; // Lut item size (in Bits) - - int nbRead; // nb of items in LUT descriptor (must be = 3) - - nbRead = sscanf( lutDescriptor.c_str(), - "%d\\%d\\%d", - &length, &deb, &nbits ); - std::cout << "length " << length - << " deb " << deb - << " nbits " << nbits - << std::endl; - if ( nbRead != 3 ) - { - //gdcmWarningMacro( "Wrong LUT descriptor" ); - std::cout << "Wrong LUT descriptor" << std::endl; - } - //LUT Data (CTX dependent) - gdcm::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006); - if ( b != 0 ) + //gdcmWarningMacro( "LUT Descriptor is missing" ); + std::cout << "LUT Descriptor is missing" << std::endl; + return; + } + int length; // LUT length in Bytes + int deb; // Subscript of the first Lut Value + int nbits; // Lut item size (in Bits) + + int nbRead; // nb of items in LUT descriptor (must be = 3) + + nbRead = sscanf( lutDescriptor.c_str(), + "%d\\%d\\%d", + &length, &deb, &nbits ); + std::cout << "length " << length + << " deb " << deb + << " nbits " << nbits + << std::endl; + if ( nbRead != 3 ) + { + //gdcmWarningMacro( "Wrong LUT descriptor" ); + std::cout << "Wrong LUT descriptor" << std::endl; + } + //LUT Data (CTX dependent) + gdcm::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006); + if ( b != 0 ) + { + int BitsAllocated = f->GetBitsAllocated(); + if ( BitsAllocated <= 8 ) { - int BitsAllocated = f->GetBitsAllocated(); - if ( BitsAllocated <= 8 ) - { - int mult; - if ( ( nbits == 16 ) && ( BitsAllocated == 8 ) ) - { - // when LUT item size is different than pixel size - mult = 2; // high byte must be = low byte - } - else - { - // See PS 3.3-2003 C.11.1.1.2 p 619 - mult = 1; - } - uint8_t *lut = b->GetBinArea(); - for( int i=0; i < length; ++i ) - { - std::cout << i+deb << " : \t" - << (int) (lut[i*mult + 1]) << std::endl; - } + int mult; + if ( ( nbits == 16 ) && ( BitsAllocated == 8 ) ) + { + // when LUT item size is different than pixel size + mult = 2; // high byte must be = low byte } else { - uint16_t *lut = (uint16_t *)(b->GetBinArea()); - for( int i=0; i < length; ++i ) - { - std::cout << i+deb << " : \t" - << (int) (((uint16_t *)lut)[i]) - << std::endl; - } + // See PS 3.3-2003 C.11.1.1.2 p 619 + mult = 1; } - } + uint8_t *lut = b->GetBinArea(); + for( int i=0; i < length; ++i ) + { + std::cout << i+deb << " : \t" + << (int) (lut[i*mult + 1]) << std::endl; + } + } else - std::cout << "No LUT Data DataEntry (0x0028,0x3006) found?!? " - << std::endl; - } + { + uint16_t *lut = (uint16_t *)(b->GetBinArea()); + for( int i=0; i < length; ++i ) + { + std::cout << i+deb << " : \t" + << (int) (((uint16_t *)lut)[i]) + << std::endl; + } + } + } else - std::cout << "No First SQ Item within (0x0028,0x3000) ?!? " - << std::endl; + std::cout << "No LUT Data DataEntry (0x0028,0x3006) found?!? " + << std::endl; } else - std::cout << "No LUT Data SeqEntry (0x0028,0x3000) found " - << std::endl; + std::cout << "No First SQ Item within (0x0028,0x3000) ?!? " + << std::endl; } + else + std::cout << "No LUT Data SeqEntry (0x0028,0x3000) found " + << std::endl; +} int main(int argc, char *argv[]) { @@ -148,23 +148,22 @@ int main(int argc, char *argv[]) { am->ArgMgrUsage(usage); // Display 'usage' delete am; - return 0; + return 1; } char *fileName = am->ArgMgrGetString("filein",(char *)0); char *dirName = am->ArgMgrGetString("dirin",(char *)0); - if ( (fileName == 0 && dirName == 0) - || + if ( (fileName == 0 && dirName == 0) || (fileName != 0 && dirName != 0) ) { - std::cout <ArgMgrDefined("debug")) gdcm::Debug::DebugOn(); @@ -201,7 +200,7 @@ int main(int argc, char *argv[]) { am->ArgMgrUsage(usage); delete am; - return 0; + return 1; } delete am; // we don't need Argument Manager any longer @@ -438,13 +437,15 @@ int main(int argc, char *argv[]) //if( !f->gdcm::Document::IsReadable()) // Try downcast to please MSVC - if ( !((gdcm::Document *)f)->IsReadable() ) - { + if ( !((gdcm::Document *)f)->IsReadable() ) + { std::cout <IsReadable()) + if ( f->IsReadable() ) + { std::cout <GetSeqEntry(0x0041,0x1010) ) { std::cout <GetEntryString(0x0018,0x5100); - if ( strPatientPosition != gdcm::GDCM_UNFOUND - && strPatientPosition != "" ) - std::cout << "PatientPosition (0x0010,0x5100)= [" - << strPatientPosition << "]" << std::endl; - - std::string strViewPosition = - f->GetEntryString(0x0018,0x5101); - if ( strViewPosition != gdcm::GDCM_UNFOUND - && strViewPosition != "" ) - std::cout << "strViewPosition (0x0010,0x5101)= [" - << strViewPosition << "]" << std::endl; - - std::string strPatientOrientation = - f->GetEntryString(0x0020,0x0020); - if ( strPatientOrientation != gdcm::GDCM_UNFOUND - && strPatientOrientation != "") - std::cout << "PatientOrientation (0x0020,0x0020)= [" - << strPatientOrientation << "]" << std::endl; - - std::string strImageOrientationPatient = - f->GetEntryString(0x0020,0x0037); - if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND - && strImageOrientationPatient != "" ) - std::cout << "ImageOrientationPatient (0x0020,0x0037)= [" - << strImageOrientationPatient << "]" << std::endl; - - std::string strImageOrientationRET = - f->GetEntryString(0x0020,0x0035); - if ( strImageOrientationRET != gdcm::GDCM_UNFOUND - && strImageOrientationRET != "" ) - std::cout << "ImageOrientationRET (0x0020,0x0035)= [" - << strImageOrientationRET << "]" << std::endl; + // Lets's get and print some usefull fields about 'Orientation' + // ------------------------------------------------------------ + + std::string strPatientPosition = + f->GetEntryString(0x0018,0x5100); + if ( strPatientPosition != gdcm::GDCM_UNFOUND + && strPatientPosition != "" ) + std::cout << "PatientPosition (0x0010,0x5100)= [" + << strPatientPosition << "]" << std::endl; + + std::string strViewPosition = + f->GetEntryString(0x0018,0x5101); + if ( strViewPosition != gdcm::GDCM_UNFOUND + && strViewPosition != "" ) + std::cout << "strViewPosition (0x0010,0x5101)= [" + << strViewPosition << "]" << std::endl; + + std::string strPatientOrientation = + f->GetEntryString(0x0020,0x0020); + if ( strPatientOrientation != gdcm::GDCM_UNFOUND + && strPatientOrientation != "") + std::cout << "PatientOrientation (0x0020,0x0020)= [" + << strPatientOrientation << "]" << std::endl; + + std::string strImageOrientationPatient = + f->GetEntryString(0x0020,0x0037); + if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND + && strImageOrientationPatient != "" ) + std::cout << "ImageOrientationPatient (0x0020,0x0037)= [" + << strImageOrientationPatient << "]" << std::endl; + + std::string strImageOrientationRET = + f->GetEntryString(0x0020,0x0035); + if ( strImageOrientationRET != gdcm::GDCM_UNFOUND + && strImageOrientationRET != "" ) + { + std::cout << "ImageOrientationRET (0x0020,0x0035)= [" + << strImageOrientationRET << "]" << std::endl; + } - // Let's compute 'user friendly' results about 'Orientation' - // --------------------------------------------------------- - - gdcm::Orientation o; + // Let's compute 'user friendly' results about 'Orientation' + // --------------------------------------------------------- + + gdcm::Orientation o; - if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND || - strImageOrientationRET != gdcm::GDCM_UNFOUND ) - { - - gdcm::OrientationType orient = o.GetOrientationType( f ); - - std::cout << "TypeOrientation = " << orient << " (-> " - << o.GetOrientationTypeString(orient) << " )" << std::endl; - } + if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND || + strImageOrientationRET != gdcm::GDCM_UNFOUND ) + { + + gdcm::OrientationType orient = o.GetOrientationType( f ); + + std::cout << "TypeOrientation = " << orient << " (-> " + << o.GetOrientationTypeString(orient) << " )" << std::endl; + } - std::string ori = o.GetOrientation ( f ); - if (ori != "\\" ) - std::cout << "Orientation [" << ori << "]" << std::endl; + std::string ori = o.GetOrientation ( f ); + if (ori != "\\" ) + std::cout << "Orientation [" << ori << "]" << std::endl; //------------------------------- @@ -583,4 +585,5 @@ int main(int argc, char *argv[]) } std::cout<