+
+ GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
+ fh->SetPrintLevel( level );
+
+ fh->Print();
+
+ 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();
+ nY=f->GetYSize();
+ nZ=f->GetZSize();
+ nT=f->GetTSize();
+ std::cout << " DIMX=" << nX << " DIMY=" << nY
+ << " DIMZ=" << nZ << " DIMT=" << nT
+ << std::endl;
+
+ pixelType = f->GetPixelType();
+ sPP = f->GetSamplesPerPixel();
+ std::cout << " pixelType= [" << pixelType
+ << "] SamplesPerPixel= [" << sPP
+ << "] ";
+
+ if (sPP == 3)
+ {
+ planarConfig = f->GetPlanarConfiguration();
+ std::cout << " PlanarConfiguration= [" << planarConfig
+ << "] "<< std::endl;
+ }
+ std::cout << " PhotometricInterpretation= ["
+ << f->GetEntryString(0x0028,0x0004)
+ << "] "<< std::endl;
+
+ int numberOfScalarComponents=f->GetNumberOfScalarComponents();
+ std::cout << " NumberOfScalarComponents = " << numberOfScalarComponents
+ <<std::endl
+ << " LUT = " << (f->HasLUT() ? "TRUE" : "FALSE")
+ << std::endl;
+
+ if ( f->GetDataEntry(0x0002,0x0010) )
+ if ( f->GetDataEntry(0x0002,0x0010)->IsNotLoaded() )
+ {
+ std::cout << "Transfer Syntax not loaded. " << std::endl
+ << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE"
+ << std::endl;
+ f->Delete();
+ return 0;
+ }
+
+ std::string transferSyntaxName = f->GetTransferSyntaxName();
+ std::cout << " TransferSyntaxName= [" << transferSyntaxName << "]"
+ << std::endl;
+ std::cout << " SwapCode= " << f->GetSwapCode() << std::endl;
+ std::cout << " ------" << std::endl;
+
+ std::cout << "\n\n" << std::endl;
+ std::cout << "X spacing " << f->GetXSpacing() << std::endl;
+ std::cout << "Y spacing " << f->GetYSpacing() << std::endl;
+ std::cout << "Z spacing " << f->GetZSpacing() << std::endl;
+
+//------------------------------
+
+ // Let's get and print some usefull fields about 'Orientation'
+ // ------------------------------------------------------------
+
+ std::string strPatientPosition =
+ f->GetEntryString(0x0018,0x5100);
+ if ( strPatientPosition != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strPatientPosition != "" )
+ std::cout << "PatientPosition (0x0010,0x5100)= ["
+ << strPatientPosition << "]" << std::endl;
+
+ std::string strViewPosition =
+ f->GetEntryString(0x0018,0x5101);
+ if ( strViewPosition != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strViewPosition != "" )
+ std::cout << "View Position (0x0018,0x5101)= ["
+ << strViewPosition << "]" << std::endl;
+
+ std::string strPatientOrientation =
+ f->GetEntryString(0x0020,0x0020);
+ if ( strPatientOrientation != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strPatientOrientation != "")
+ std::cout << "PatientOrientation (0x0020,0x0020)= ["
+ << strPatientOrientation << "]" << std::endl;
+
+ std::string strImageOrientationPatient =
+ f->GetEntryString(0x0020,0x0037);
+ if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strImageOrientationPatient != "" )
+ std::cout << "ImageOrientationPatient (0x0020,0x0037)= ["
+ << strImageOrientationPatient << "]" << std::endl;
+
+ std::string strImageOrientationRET =
+ f->GetEntryString(0x0020,0x0035);
+ if ( strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strImageOrientationRET != "" )
+ std::cout << "ImageOrientationRET (0x0020,0x0035)= ["
+ << strImageOrientationRET << "]" << std::endl;
+
+ std::string strImagePositionPatient =
+ f->GetEntryString(0x0020,0x0032);
+ if ( strImagePositionPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strImagePositionPatient != "" )
+ std::cout << "ImagePositionPatient (0x0020,0x0032)= ["
+ << strImagePositionPatient << "]" << std::endl;
+
+ std::string strImagePositionPatientRET =
+ f->GetEntryString(0x0020,0x0030);
+ if ( strImagePositionPatientRET != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strImagePositionPatientRET != "" )
+ std::cout << "ImagePositionPatientRET (0x0020,0x0030)= ["
+ << strImagePositionPatientRET << "]" << std::endl;
+
+ float iop[6];
+ /*bool riop = */f->GetImageOrientationPatient(iop);
+ float ipp[3];
+ /*bool ripp = */f->GetImagePositionPatient(ipp);
+
+ std::cout << "Image Position (0x0020,0x0032|0x0030) : "
+ << ipp[0] << " , " << ipp[1] << " , "<< ipp[2]
+ << std::endl;
+ std::cout << "Image Orientation (0x0020,0x0037|0x0035) : "
+ << iop[0] << " , " << iop[1] << " , "<< iop[2] << " , "
+ << iop[3] << " , " << iop[4] << " , "<< iop[5]
+ << std::endl;
+
+
+ // Let's compute 'user friendly' results about 'Orientation'
+ // ---------------------------------------------------------
+
+ GDCM_NAME_SPACE::Orientation *o = GDCM_NAME_SPACE::Orientation::New();
+
+ if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND ||
+ strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND )
+ {
+
+ GDCM_NAME_SPACE::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;
+ o->Delete();
+/*
+std::vector <double> valueVector;
+GDCM_NAME_SPACE::DataEntry *e_0018_5212 = f->GetDataEntry(0x0018, 0x5212);
+bool resJP = e_0018_5212->GetDSValue(valueVector);
+if (resJP) {
+ double test;
+ for ( int i=0; i < 3; i++ ) {
+ test = valueVector[i];
+ std::cout << " test " << test << std::endl;
+ }
+}
+//e_0018_5212->Delete();
+*/
+
+}
+//------------------------------
+
+
+ // Display the LUT as an int array (for debugging purpose)
+ if ( f->HasLUT() && showlut )
+ {
+ uint8_t* lutrgba = fh->GetLutRGBA();
+ if ( lutrgba == 0 )
+ {
+ std::cout << "Lut RGBA (Palette Color) not built " << std::endl;
+
+ // Nothing is written yet to get LUT Data user friendly
+ // The following is to be moved into a PixelRedaConvert method
+
+ GDCM_NAME_SPACE::SeqEntry *modLutSeq = f->GetSeqEntry(0x0028,0x3000);
+ if ( modLutSeq !=0 )
+ {
+ GDCM_NAME_SPACE::SQItem *sqi= modLutSeq->GetFirstSQItem();
+ if ( !sqi )
+ {
+ std::string lutDescriptor = sqi->GetEntryString(0x0028,0x3002);
+ 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 );
+ if ( nbRead != 3 )
+ {
+ std::cout << "Wrong LUT descriptor" << std::endl;
+ }
+ GDCM_NAME_SPACE::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006);
+ if ( b != 0 )
+ {
+ if ( b->GetLength() != 0 )
+ {
+ std::cout << "---------------------------------------"
+ << " We should never reach this point "
+ << std::endl;
+ //LoadEntryBinArea(b); //LUT Data (CTX dependent)
+ }
+ }
+ }
+ }
+ else
+ std::cout << "No LUT Data (0x0028,0x3000) found " << std::endl;
+ }
+ /*
+ else
+ {
+ if ( fh->GetLutItemSize() == 8 )
+ {
+ for (int i=0;i<fh->GetLutItemNumber();i++)
+ std::cout << i << " : \t"
+ << (int)(lutrgba[i*4]) << " "
+ << (int)(lutrgba[i*4+1]) << " "
+ << (int)(lutrgba[i*4+2]) << std::endl;
+ }
+ else // LutItemSize assumed to be = 16
+ {
+ uint16_t* lutrgba16 = (uint16_t*)lutrgba;
+ for (int i=0;i<fh->GetLutItemNumber();i++)
+ std::cout << i << " : \t"
+ << (int)(lutrgba16[i*4]) << " "
+ << (int)(lutrgba16[i*4+1]) << " "
+ << (int)(lutrgba16[i*4+2]) << std::endl;
+ }
+ }
+ */
+ }
+ else if (showlut)
+ {
+ std::cout << "Try LUT Data "<< std::endl;
+ ShowLutData(f);
+ }
+
+ // Parsability of the GDCM_NAME_SPACE::Document already checked, after Load() !
+
+ if ( f->IsReadable() )
+ {
+ std::cout <<std::endl<<fileName<<" is Readable"<<std::endl;
+ }
+ else if ( f->GetSeqEntry(0x0041,0x1010) )
+ {
+ std::cout <<std::endl<<fileName<<" looks like a 'PAPYRUS image' file"
+ <<std::endl;
+ }
+ else if ( f->GetSeqEntry(0x0004,0x1220) )
+ {
+ std::cout <<std::endl<<fileName<<" looks like a 'DICOMDIR file'"
+ <<std::endl;
+ }
+ else
+ {
+ std::cout <<std::endl<<fileName<<" doesn't look like an image file "
+ <<std::endl;
+ }
+
+ std::cout<<std::flush;
+ f->Delete();
+ fh->Delete();
+ }
+ // ===========================================================================
+ else // =============================== Deal with a Directory =====================
+ { // ===========================================================================
+ std::cout << "dirName [" << dirName << "]" << std::endl;
+
+ 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 )
+ {
+ std::cout << std::endl<<" Start processing :[" << it->c_str() << "]"
+ << std::endl;
+ f = GDCM_NAME_SPACE::File::New();
+ f->SetLoadMode(loadMode);
+ f->SetFileName( it->c_str() );
+
+ for (int ri=0; ri<forceLoadNb; ri++)
+ {
+ printf("%04x,%04x\n",elemsToForceLoad[2*ri],
+ elemsToForceLoad[2*ri+1]);
+ f->AddForceLoadElement((uint32_t)elemsToForceLoad[2*ri],
+ (uint32_t)elemsToForceLoad[2*ri+1]);
+ }
+ res = f->Load();
+
+ if ( !res )
+ {
+ std::cout << "Cannot process file [" << it->c_str() << "]"
+ << std::endl;
+ 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::endl;
+ std::cout << "use 'PrintFile filein=... debug' "
+ << "to try to guess the pb"
+ << std::endl;
+ f->Delete();
+ continue;
+ }
+
+ GDCM_NAME_SPACE::FileHelper *fh = GDCM_NAME_SPACE::FileHelper::New(f);
+ fh->SetPrintLevel( level );
+ fh->Print();
+
+//------------------------------
+if (!noex)
+{
+ // Lets's get and print some usefull fields about 'Orientation'
+ // ------------------------------------------------------------
+
+ std::string strPatientPosition =
+ f->GetEntryString(0x0018,0x5100);
+ if ( strPatientPosition != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strPatientPosition != "" )
+ std::cout << "PatientPosition (0x0010,0x5100)= ["
+ << strPatientPosition << "]" << std::endl;
+
+ std::string strViewPosition =
+ f->GetEntryString(0x0018,0x5101);
+ if ( strViewPosition != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strViewPosition != "" )
+ std::cout << "strViewPosition (0x0010,0x5101)= ["
+ << strViewPosition << "]" << std::endl;
+
+ std::string strPatientOrientation =
+ f->GetEntryString(0x0020,0x0020);
+ if ( strPatientOrientation != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strPatientOrientation != "")
+ std::cout << "PatientOrientation (0x0020,0x0020)= ["
+ << strPatientOrientation << "]" << std::endl;
+
+ std::string strImageOrientationPatient =
+ f->GetEntryString(0x0020,0x0037);
+ if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strImageOrientationPatient != "" )
+ std::cout << "ImageOrientationPatient (0x0020,0x0037)= ["
+ << strImageOrientationPatient << "]" << std::endl;
+
+ std::string strImageOrientationRET =
+ f->GetEntryString(0x0020,0x0035);
+ if ( strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND
+ && strImageOrientationRET != "" )
+ {
+ std::cout << "ImageOrientationRET (0x0020,0x0035)= ["
+ << strImageOrientationRET << "]" << std::endl;
+ }
+
+ // Let's compute 'user friendly' results about 'Orientation'
+ // ---------------------------------------------------------
+
+ GDCM_NAME_SPACE::Orientation *o = GDCM_NAME_SPACE::Orientation::New();
+
+
+ if ( strImageOrientationPatient != GDCM_NAME_SPACE::GDCM_UNFOUND ||
+ strImageOrientationRET != GDCM_NAME_SPACE::GDCM_UNFOUND )
+ {
+
+ GDCM_NAME_SPACE::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;
+ o->Delete();
+}
+//-------------------------------
+
+ if (f->IsReadable())
+ {
+ if (load) // just to see warning messages at load time !
+ {
+ uint8_t *pixels = fh->GetImageData();
+ uint32_t lgth = fh->GetImageDataSize();
+ }
+
+ std::cout <<std::endl<<it->c_str()<<" is Readable"<<std::endl;
+ }
+ else
+ std::cout <<std::endl<<it->c_str()<<" is NOT Readable"<<std::endl;
+ std::cout << "\n\n" << std::endl;
+
+
+
+ f->Delete();
+ fh->Delete();
+ }
+ std::cout<<std::flush;
+ }