X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;ds=sidebyside;f=Example%2FexExtractDicomTags.cxx;h=c981a61318cc4e7822ad5bff51b26ab1ee1079e0;hb=d0f6827609a499057f4bad725522060590af3d82;hp=f94d6ca57125835ed6e8030a33d14fafb528494d;hpb=16767fac37398a5864a19243c56352752e103c04;p=gdcm.git diff --git a/Example/exExtractDicomTags.cxx b/Example/exExtractDicomTags.cxx index f94d6ca5..c981a613 100644 --- a/Example/exExtractDicomTags.cxx +++ b/Example/exExtractDicomTags.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exExtractDicomTags.cxx,v $ Language: C++ - Date: $Date: 2005/09/29 08:49:27 $ - Version: $Revision: 1.1 $ + Date: $Date: 2008/04/03 17:00:24 $ + 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 @@ -18,12 +18,11 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" #include "gdcmDebug.h" #include "gdcmUtil.h" +#include "gdcmOrientation.h" #include "gdcmArgMgr.h" #include @@ -53,8 +52,8 @@ int main(int argc, char *argv[]) // ----- Initialize Arguments Manager ------ - gdcm::ArgMgr *am = new gdcm::ArgMgr(argc, argv); - + GDCM_NAME_SPACE::ArgMgr *am = new GDCM_NAME_SPACE::ArgMgr(argc, argv); + if (am->ArgMgrDefined("usage")) { am->ArgMgrUsage(usage); // Display 'usage' @@ -69,7 +68,7 @@ int main(int argc, char *argv[]) } if (am->ArgMgrDefined("debug")) - gdcm::Debug::DebugOn(); + GDCM_NAME_SPACE::Debug::DebugOn(); // if unused Params we give up if ( am->ArgMgrPrintUnusedLabels() ) @@ -85,14 +84,14 @@ int main(int argc, char *argv[]) int loadMode = 0x0; // load everything - gdcm::File *f = new gdcm::File(); + GDCM_NAME_SPACE::File *f = GDCM_NAME_SPACE::File::New(); f->SetLoadMode( loadMode ); f->SetFileName( fileName ); bool res = f->Load(); if ( !res ) { - delete f; + f->Delete(); return 0; } @@ -100,7 +99,7 @@ int main(int argc, char *argv[]) if (!f->IsReadable()) { std::cout << "NOT a Dicom File : " << fileName <Delete(); return 1; } @@ -125,51 +124,57 @@ int main(int argc, char *argv[]) std::string ProtocolName; -// ------------> Region (Organe) : aucun champ DICOM n'est prévu -// pour contenir cette information +// ------------> Region (Organ) : *no* DICOM field is expected +// to hold information // Get informations on the file : // Modality, Transfer Syntax, Study Date, Study Time // Patient Name, Media Storage SOP Instance UID, etc - MediaStSOPinstUID = f->GetEntryValue(0x0002,0x0002); - TransferSyntax = f->GetEntryValue(0x0002,0x0010); - StudyDate = f->GetEntryValue(0x0008,0x0020); - StudyTime = f->GetEntryValue(0x0008,0x0030); - PatientName = f->GetEntryValue(0x0010,0x0010); - PatientID = f->GetEntryValue(0x0010,0x0020); //patientid - PatientSex = f->GetEntryValue(0x0010,0x0040); //sexe - SOPInstanceUID = f->GetEntryValue(0x0008,0x0018); //imageid = SOPinsUID - StudyInstanceUID = f->GetEntryValue(0x0020,0x000d); //STUInsUID [Study Instance UID] [1.2.840.113680.1.103.56887.1017329008.714317] - SeriesInstanceUID = f->GetEntryValue(0x0020,0x000e); //SerInsUID - AcquistionDate = f->GetEntryValue(0x0008,0x0022); - AcquisitionTime = f->GetEntryValue(0x0008,0x0032); - AcquisitionDateTime = f->GetEntryValue(0x0008,0x002a); - - - Modality = f->GetEntryValue(0x0008,0x0060); //modality - InstitutionName = f->GetEntryValue(0x0008,0x0080); //hospital + MediaStSOPinstUID = f->GetEntryString(0x0002,0x0002); + TransferSyntax = f->GetEntryString(0x0002,0x0010); + StudyDate = f->GetEntryString(0x0008,0x0020); + StudyTime = f->GetEntryString(0x0008,0x0030); + PatientName = f->GetEntryString(0x0010,0x0010); + PatientID = f->GetEntryString(0x0010,0x0020); //patientid + PatientSex = f->GetEntryString(0x0010,0x0040); //sex + SOPInstanceUID = f->GetEntryString(0x0008,0x0018); //imageid = SOPinsUID + StudyInstanceUID = f->GetEntryString(0x0020,0x000d); //STUInsUID [Study Instance UID] [1.2.840.113680.1.103.56887.1017329008.714317] + SeriesInstanceUID = f->GetEntryString(0x0020,0x000e); //SerInsUID + AcquistionDate = f->GetEntryString(0x0008,0x0022); + AcquisitionTime = f->GetEntryString(0x0008,0x0032); + AcquisitionDateTime = f->GetEntryString(0x0008,0x002a); + + + Modality = f->GetEntryString(0x0008,0x0060); //modality + InstitutionName = f->GetEntryString(0x0008,0x0080); //hospital // always empty :-( InstitutionalDepartmentName - = f->GetEntryValue(0x0008,0x1040); //departement + = f->GetEntryString(0x0008,0x1040); //departement + // --> I'll have to ask people working on PACS which one they use. JPRx // Radiologist : // 0008|0090 [Referring Physician's Name] // 0008|1050 [Performing Physician's Name] // 0008|1060 [Name of Physician(s) Reading Study] // 0008|1048 [Physician(s) of Record] - // 0032|1032 [Requesting Physician] - - // --> I'll have to ask people working on PACS which one they use. JPRx - - ProtocolName = f->GetEntryValue(0x0018,0x1030); + // 0032|1032 [Requesting Physician] + + std::string ReferringPhysiciansName = f->GetEntryString(0x0008,0x0090); + std::string PerformingPhysiciansName = f->GetEntryString(0x0008,0x1050); + std::string NameofPhysiciansReadingStudy = f->GetEntryString(0x0008,0x1060); + std::string PhysiciansofRecord = f->GetEntryString(0x0008,0x1048); + std::string RequestingPhysician = f->GetEntryString(0x0032,0x1032); + + + ProtocolName = f->GetEntryString(0x0018,0x1030); - // --> Big trouble with nz (mb of planes) and nt (number of 'times') + // --> Big trouble with nz (number of planes) and nt (number of 'times') // --> that belong to LibIDO, not to DICOM. // --> DICOM has 'Number of Frames' (0028|0008), // that's more or less number of 'times' // Volumes are generaly stored in a 'Serie' - // (hope so ... a single Serie be xti-slice xti-times) + // (hope so ... a single Serie may be xti-slice xti-times) std::string Rows; @@ -183,15 +188,15 @@ int main(int argc, char *argv[]) std::string PixelRepresentation; std::string PixelType; - SamplesPerPixel = f->GetEntryValue(0x0028,0x0002); // 3 -> RGB - Rows = f->GetEntryValue(0x0028,0x0010); //ny - Columns = f->GetEntryValue(0x0028,0x0011); //nx - Planes = f->GetEntryValue(0x0028,0x0012); //nz + SamplesPerPixel = f->GetEntryString(0x0028,0x0002); // 3 -> RGB + Rows = f->GetEntryString(0x0028,0x0010); //ny + Columns = f->GetEntryString(0x0028,0x0011); //nx + Planes = f->GetEntryString(0x0028,0x0012); //nz - BitsAllocated = f->GetEntryValue(0x0028,0x0100); - BitsStored = f->GetEntryValue(0x0028,0x0101); - HighBit = f->GetEntryValue(0x0028,0x0102); - PixelRepresentation = f->GetEntryValue(0x0028,0x0103); + BitsAllocated = f->GetEntryString(0x0028,0x0100); + BitsStored = f->GetEntryString(0x0028,0x0101); + HighBit = f->GetEntryString(0x0028,0x0102); + PixelRepresentation = f->GetEntryString(0x0028,0x0103); PixelType = f->GetPixelType(); //type /* @@ -202,30 +207,31 @@ int main(int argc, char *argv[]) int iBitsAllocated = (uint32_t) atoi( BitsAllocated.c_str() ); */ - + float sx = f->GetXSpacing(); float sy = f->GetYSpacing(); float sz = f->GetZSpacing(); // meaningless for DICOM // (cannot be extracted from a single image) - std::cout << "Rows = [" << Rows << "]" << std::endl; - std::cout << "Columns = [" << Columns << "]" << std::endl; - std::cout << "Planes = [" << Planes << "]" << std::endl; - std::cout << "SamplesPerPixel = [" << SamplesPerPixel << "]" << std::endl; - std::cout << "BitsAllocated = [" << BitsAllocated << "]" << std::endl; - std::cout << "BitsStored = [" << BitsStored << "]" << std::endl; - std::cout << "HighBit = [" << HighBit << "]" << std::endl; + std::cout << "Rows = [" << Rows << "]" << std::endl; + std::cout << "Columns = [" << Columns << "]" << std::endl; + std::cout << "Planes = [" << Planes << "]" << std::endl; + std::cout << "SamplesPerPixel = [" << SamplesPerPixel << "]" << std::endl; + std::cout << "BitsAllocated = [" << BitsAllocated << "]" << std::endl; + std::cout << "BitsStored = [" << BitsStored << "]" << std::endl; + std::cout << "HighBit = [" << HighBit << "]" << std::endl; std::cout << "PixelRepresentation = [" << PixelRepresentation << "]" << std::endl; - std::cout << "PixelType = [" << PixelType << "]" << std::endl; + std::cout << "PixelType = [" << PixelType << "]" << std::endl; std::cout << "TransferSyntax = [" << TransferSyntax << "]" << std::endl; - std::cout << "StudyDate = [" << StudyDate << "]" << std::endl; - std::cout << "StudyTime = [" << StudyTime << "]" << std::endl; - std::cout << "Modality = [" << Modality << "]" << std::endl; - std::cout << "PatientName = [" << PatientName << "]" << std::endl; - std::cout << "PatientID = [" << PatientID << "]" << std::endl; - std::cout << "PatientSex = [" << PatientSex << "]" << std::endl; + std::cout << "StudyDate = [" << StudyDate << "]" << std::endl; + std::cout << "StudyTime = [" << StudyTime << "]" << std::endl; + std::cout << "Modality = [" << Modality << "]" << std::endl; + std::cout << "PatientName = [" << PatientName << "]" << std::endl; + std::cout << "PatientID = [" << PatientID << "]" << std::endl; + std::cout << "PatientSex = [" << PatientSex << "]" << std::endl; + std::cout << std::endl; std::cout << "SOPInstanceUID = [" << SOPInstanceUID << "]" << std::endl; std::cout << "StudyInstanceUID = [" << StudyInstanceUID @@ -238,16 +244,121 @@ int main(int argc, char *argv[]) << "]" << std::endl; std::cout << "AcquisitionDateTime = [" << AcquisitionDateTime << "]" << std::endl; - std::cout << "InstitutionName = [" << InstitutionName + + std::cout << std::endl; + + std::cout << "ReferringPhysiciansName = [" << ReferringPhysiciansName << "]" << std::endl; + std::cout << "PerformingPhysiciansName = [" << PerformingPhysiciansName + << "]" << std::endl; + std::cout << "NameofPhysiciansReadingStudy = [" << NameofPhysiciansReadingStudy + << "]" << std::endl; + std::cout << "PhysiciansofRecord = [" << PhysiciansofRecord + << "]" << std::endl; + std::cout << "RequestingPhysician = [" << RequestingPhysician + << "]" << std::endl; + + std::cout << std::endl; + std::cout << "InstitutionalDepartmentName = [" << InstitutionalDepartmentName << "]" << std::endl; + + std::cout << "InstitutionName = [" << InstitutionName + << "]" << std::endl; + std::cout << "ProtocolName = [" << ProtocolName << "]" << std::endl; std::cout << "GetXSpacing = [" << sx << "]" << std::endl; std::cout << "GetYSpacing = [" << sy << "]" << std::endl; std::cout << "GetZSpacing = [" << sz << "]" << 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(); + f->Delete(); return 0; }