From bc69950a406d06c50f0fb75a96572784965cb534 Mon Sep 17 00:00:00 2001 From: regrain Date: Tue, 18 Oct 2005 08:35:42 +0000 Subject: [PATCH] * Minor coding-style clean up * Replace the ContentEntry and its derived classes (BinEntry and ValEntry) by the DataEntry. This unique entry considers all datas like binary datas. Some methods are added to interpret - at fly - the binary datas. Due to this important change, some methods of the DocEntrySet, concerning the BinEntry and ValEntry classes, are erased ; and new methods for the DataEntry class are created. Some methods to set the ValEntry or the BinEntry are renamed to correspond to the new DataEntry, like for example : - SetValEntry -> SetEntryString - SetBinEntry -> SetEntryBinArea This change will remove all useless creation of the string when working directly on values. -- BeNours --- ChangeLog | 15 + Example/AnonymizeDicomDir.cxx | 14 +- Example/FindTags.cxx | 16 +- Example/PrintDicomDir.cxx | 71 ++- Example/PrintFile.cxx | 54 +- Example/ReWrite.cxx | 6 +- Example/TestChangeHeader.cxx | 8 +- Example/TestCopyDicom.cxx | 21 +- Example/Volume2Dicom.cxx | 5 +- Example/WriteDicomSimple.cxx | 22 +- Example/exColorToRGB.cxx | 21 +- Example/exCurveData.cxx | 62 +- Example/exExtractDicomTags.cxx | 62 +- Example/exExtractTag.cxx | 40 +- Example/exGC.cxx | 21 +- Example/exGrey2RGB.cxx | 14 +- Example/exImageLighten.cxx | 21 +- Example/exOverlaysACR.cxx | 26 +- Example/exPrintWritePrint.cxx | 7 +- Example/exReadPapyrus.cxx | 71 ++- Example/exReadWriteFile.cxx | 64 +- Testing/CMakeLists.txt | 4 + Testing/TestAllEntryVerify.cxx | 6 +- Testing/TestAllPrint.cxx | 6 +- Testing/TestAllReadCompareDicom.cxx | 8 +- Testing/TestAnonymize.cxx | 6 +- Testing/TestBuildUpDicomDir.cxx | 74 +-- Testing/TestCopyDicom.cxx | 25 +- Testing/TestCopyRescaleDicom.cxx | 31 +- Testing/TestDataEntry.cxx | 495 ++++++++++++++++ Testing/TestDicomDir.cxx | 46 +- Testing/TestFileAccessors.cxx | 113 ++-- Testing/TestImageSet.cxx | 66 +-- Testing/TestLoadAllDocumentsNoPrivNoSeq.cxx | 7 +- Testing/TestMakeIcon.cxx | 105 ++-- Testing/TestPrintAllDocument.cxx | 10 +- Testing/TestReadWriteReadCompare.cxx | 13 +- Testing/TestWriteSimple.cxx | 43 +- gdcmPython/demo/PrintDicomDir.py.in | 2 +- src/CMakeLists.txt | 4 +- src/gdcm.h | 7 +- src/gdcmBinEntry.cxx | 240 -------- src/gdcmBinEntry.h | 71 --- src/gdcmContentEntry.cxx | 82 --- src/gdcmContentEntry.h | 70 --- src/gdcmDataEntry.cxx | 625 ++++++++++++++++++++ src/gdcmDataEntry.h | 137 +++++ src/gdcmDicomDir.cxx | 46 +- src/gdcmDicomDirImage.cxx | 9 +- src/gdcmDicomDirObject.cxx | 12 +- src/gdcmDicomDirVisit.cxx | 9 +- src/gdcmDictEntry.h | 12 +- src/gdcmDocEntry.cxx | 8 +- src/gdcmDocEntry.h | 24 +- src/gdcmDocEntrySet.cxx | 215 +++---- src/gdcmDocEntrySet.h | 43 +- src/gdcmDocument.cxx | 625 +++++--------------- src/gdcmDocument.h | 11 +- src/gdcmElementSet.cxx | 15 +- src/gdcmElementSet.h | 8 +- src/gdcmFile.cxx | 496 ++++++++++++---- src/gdcmFileHelper.cxx | 363 ++++-------- src/gdcmFileHelper.h | 31 +- src/gdcmOrientation.cxx | 6 +- src/gdcmPixelReadConvert.cxx | 12 +- src/gdcmSQItem.cxx | 6 +- src/gdcmSeqEntry.cxx | 5 +- src/gdcmSeqEntry.h | 6 +- src/gdcmSerieHelper.cxx | 16 +- src/gdcmUtil.cxx | 8 +- src/gdcmUtil.h | 6 +- src/gdcmVR.cxx | 32 +- src/gdcmVR.h | 6 +- src/gdcmValEntry.cxx | 306 ---------- src/gdcmValEntry.h | 81 --- src/gdcmValidator.cxx | 28 +- vtk/vtkGdcmWriter.cxx | 32 +- vtk/vtkgdcmSerieViewer.cxx | 16 +- 78 files changed, 2794 insertions(+), 2636 deletions(-) create mode 100644 Testing/TestDataEntry.cxx delete mode 100644 src/gdcmBinEntry.cxx delete mode 100644 src/gdcmBinEntry.h delete mode 100644 src/gdcmContentEntry.cxx delete mode 100644 src/gdcmContentEntry.h create mode 100644 src/gdcmDataEntry.cxx create mode 100644 src/gdcmDataEntry.h delete mode 100644 src/gdcmValEntry.cxx delete mode 100644 src/gdcmValEntry.h diff --git a/ChangeLog b/ChangeLog index d1ced5d2..2ed79e6f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +Mon Oct 18 10:27:49 2005 by regrain + * Minor coding-style clean up + * Replace the ContentEntry and its derived classes (BinEntry and ValEntry) + by the DataEntry. This unique entry considers all datas like binary datas. + Some methods are added to interpret - at fly - the binary datas. + Due to this important change, some methods of the DocEntrySet, concerning + the BinEntry and ValEntry classes, are erased ; and new methods for the + DataEntry class are created. + Some methods to set the ValEntry or the BinEntry are renamed to + correspond to the new DataEntry, like for example : + - SetValEntry -> SetEntryString + - SetBinEntry -> SetEntryBinArea + This change will remove all useless creation of the string when working + directly on values. + Thu Aug 25 16:59:49 2005 by jpr gdcmBinEntry.cxx Now Print displays the BinEntry Content (if it's printable, and loaded) diff --git a/Example/AnonymizeDicomDir.cxx b/Example/AnonymizeDicomDir.cxx index 388a92e0..02190c34 100644 --- a/Example/AnonymizeDicomDir.cxx +++ b/Example/AnonymizeDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: AnonymizeDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/21 04:55:50 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -22,7 +22,7 @@ #include "gdcmSQItem.h" #include "gdcmSeqEntry.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include "gdcmDocument.h" #include "gdcmFile.h" @@ -55,7 +55,7 @@ void AnoNoLoad(gdcm::SQItem *s, std::fstream *fp, if ( d == NULL) return; - if ( ! dynamic_cast(d) ) + if ( ! dynamic_cast(d) ) return; offset = d->GetOffset(); @@ -148,13 +148,13 @@ int main(int argc, char *argv[]) while(tmpSI) { d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type - if ( gdcm::ValEntry* valEntry = dynamic_cast(d) ) + if ( gdcm::DataEntry *dataEntry = dynamic_cast(d) ) { - v = valEntry->GetValue(); + v = dataEntry->GetString(); } else { - std::cout << "(0004,1430) not a ValEntry ?!?" << std::endl; + std::cout << "(0004,1430) not a DataEntry ?!?" << std::endl; continue; } diff --git a/Example/FindTags.cxx b/Example/FindTags.cxx index 3805438d..a1b9e4f7 100644 --- a/Example/FindTags.cxx +++ b/Example/FindTags.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: FindTags.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 12:02:02 $ - Version: $Revision: 1.14 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.15 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -55,14 +55,14 @@ int main(int argc, char *argv[]) int dataSize = h->GetImageDataSize(); std::cout << "---> pourFindTaggs : dataSize " << dataSize << std::endl; - h->SetValEntry(RecCode ,0x0008,0x0010); - h->SetValEntry(ManufacturerName ,0x0008,0x0070); + h->SetEntryString(RecCode ,0x0008,0x0010); + h->SetEntryString(ManufacturerName ,0x0008,0x0070); // ImagePositionPatient - ImagePositionPatient = h->GetFile()->GetEntryValue(0x0020,0x0032); + ImagePositionPatient = h->GetFile()->GetEntryString(0x0020,0x0032); // Image Position (RET) - h->SetValEntry(ImagePositionPatient, 0x0020,0x0030); + h->SetEntryString(ImagePositionPatient, 0x0020,0x0030); sscanf(ImagePositionPatient.c_str(), "%f%c%f%c%f", &x,&c,&y,&c,&z); @@ -78,7 +78,7 @@ int main(int argc, char *argv[]) // Location std::string zizi = gdcm::Util::Format("%f",l); Location = gdcm::Util::DicomString(zizi.c_str()); - h->SetValEntry(Location, 0x0020,0x0050); + h->SetEntryString(Location, 0x0020,0x0050); // sinon, la longueur du champ est erronée (?!?) // Probable sac de noeud entre strlen(xxx.c_str()) et xxx.length() @@ -93,7 +93,7 @@ int main(int argc, char *argv[]) zizi = gdcm::Util::Format("%d",0x7FE0); ImageLocation = gdcm::Util::DicomString(zizi.c_str()); -//h->SetValEntry(Location, 0x0028,0x0200); +//h->SetEntryString(Location, 0x0028,0x0200); //h->GetFile()->SetEntryLength(strlen(ImageLocation.c_str())-1, 0x0020,0x0050); // prudence ! // void *imageData= h->GetImageData(); diff --git a/Example/PrintDicomDir.cxx b/Example/PrintDicomDir.cxx index 7025c18d..2d40b7df 100644 --- a/Example/PrintDicomDir.cxx +++ b/Example/PrintDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: PrintDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/07/21 04:55:50 $ - Version: $Revision: 1.28 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.29 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,7 +17,6 @@ =========================================================================*/ #include "gdcmDocument.h" #include "gdcmDicomDir.h" -#include "gdcmValEntry.h" #include "gdcmDicomDirPatient.h" #include "gdcmDicomDirStudy.h" #include "gdcmDicomDirVisit.h" @@ -123,9 +122,9 @@ int main(int argc, char* argv[]) pa = f->GetFirstPatient(); while (pa) { - std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name + std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name std::cout << " Pat.ID:["; - std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID + std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID pa = f->GetNextPatient(); } break; @@ -138,13 +137,13 @@ int main(int argc, char* argv[]) pa = f->GetFirstPatient(); while ( pa ) // on degouline les PATIENT de ce DICOMDIR { - std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name + std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name std::cout << " Pat.ID:["; - std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID + std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID st = pa->GetFirstStudy(); while ( st ) { // on degouline les STUDY de ce patient - std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]"; // Study Description - std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010) << "]"; // Study ID + std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description + std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID std::cout << std::endl; st = pa->GetNextStudy(); } @@ -161,21 +160,21 @@ int main(int argc, char* argv[]) while ( pa ) // on degouline les PATIENT de ce DICOMDIR { // Patient's Name, Patient ID - std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name + std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name std::cout << " Pat.ID:["; - std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID + std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID st = pa->GetFirstStudy(); while ( st ) { // on degouline les STUDY de ce patient - std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]"; // Study Description - std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010) << "]"; // Study ID + std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description + std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID std::cout << std::endl; se = st->GetFirstSerie(); while ( se ) { // on degouline les SERIES de cette study - std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description - std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number - std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality + std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description + std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number + std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality std::cout << std::endl; se = st->GetNextSerie(); } @@ -183,10 +182,10 @@ int main(int argc, char* argv[]) vs = st->GetFirstVisit(); while ( vs ) { // on degouline les VISIT de cette study std::cout << "--- --- VISIT: "; - std::cout << " Ref. File ID :[" << vs->GetEntryValue(0x0004, 0x1500) << "]"; // Referenced File ID - std::cout << " Inst.Name:[" << vs->GetEntryValue(0x0008,0x0080) << "]"; // Institution Name - std::cout << " Adm.ID:[" << vs->GetEntryValue(0x0038, 0x0010) << "]"; // Admission ID - std::cout << " Adm. date:[" << vs->GetEntryValue(0x0038, 0x0020) << "]"; // Admitting Date + std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID + std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name + std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID + std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date std::cout << std::endl; vs = st->GetNextVisit(); } @@ -205,37 +204,37 @@ int main(int argc, char* argv[]) pa = f->GetFirstPatient(); while ( pa ) { // les PATIENT de ce DICOMDIR // Patient's Name, Patient ID - std::cout << "Pat.Name:[" << pa->GetEntryValue(0x0010, 0x0010) <<"]"; // Patient's Name + std::cout << "Pat.Name:[" << pa->GetEntryString(0x0010, 0x0010) <<"]"; // Patient's Name std::cout << " Pat.ID:["; - std::cout << pa->GetEntryValue(0x0010, 0x0020) << "]" << std::endl; // Patient ID + std::cout << pa->GetEntryString(0x0010, 0x0020) << "]" << std::endl; // Patient ID st = pa->GetFirstStudy(); while ( st ) { // on degouline les STUDY de ce patient - std::cout << "--- Stud.descr:[" << st->GetEntryValue(0x0008, 0x1030) << "]"; // Study Description - std::cout << " Stud.ID:[" << st->GetEntryValue(0x0020, 0x0010) << "]"; // Study ID + std::cout << "--- Stud.descr:[" << st->GetEntryString(0x0008, 0x1030) << "]"; // Study Description + std::cout << " Stud.ID:[" << st->GetEntryString(0x0020, 0x0010) << "]"; // Study ID std::cout << std::endl; vs = st->GetFirstVisit(); while ( vs ) { // on degouline les VISIT de cette study std::cout << "--- --- VISIT: "; - std::cout << " Ref. File ID :[" << vs->GetEntryValue(0x0004, 0x1500) << "]"; // Referenced File ID - std::cout << " Inst.Name:[" << vs->GetEntryValue(0x0008,0x0080) << "]"; // Institution Name - std::cout << " Adm.ID:[" << vs->GetEntryValue(0x0038, 0x0010) << "]"; // Admission ID - std::cout << " Adm. date:[" << vs->GetEntryValue(0x0038, 0x0020) << "]"; // Admitting Date + std::cout << " Ref. File ID :[" << vs->GetEntryString(0x0004, 0x1500) << "]"; // Referenced File ID + std::cout << " Inst.Name:[" << vs->GetEntryString(0x0008,0x0080) << "]"; // Institution Name + std::cout << " Adm.ID:[" << vs->GetEntryString(0x0038, 0x0010) << "]"; // Admission ID + std::cout << " Adm. date:[" << vs->GetEntryString(0x0038, 0x0020) << "]"; // Admitting Date std::cout << std::endl; vs = st->GetNextVisit(); } se = st->GetFirstSerie(); while ( se ) { // on degouline les SERIES de cette study - std::cout << "--- --- Ser.Descr:["<< se->GetEntryValue(0x0008, 0x103e)<< "]"; // Series Description - std::cout << " Ser.nb:[" << se->GetEntryValue(0x0020, 0x0011); // Series number - std::cout << "] Mod.:[" << se->GetEntryValue(0x0008, 0x0060) << "]"; // Modality + std::cout << "--- --- Ser.Descr:["<< se->GetEntryString(0x0008, 0x103e)<< "]"; // Series Description + std::cout << " Ser.nb:[" << se->GetEntryString(0x0020, 0x0011); // Series number + std::cout << "] Mod.:[" << se->GetEntryString(0x0008, 0x0060) << "]"; // Modality std::cout << std::endl; im = se->GetFirstImage(); while ( im ) { // on degouline les Images de cette serie - std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryValue(0x0004, 0x1500) + std::cout << "--- --- --- "<< " IMAGE Ref. File ID :[" << im->GetEntryString(0x0004, 0x1500) << "]" << std::endl; // File name (Referenced File ID) im = se->GetNextImage(); } @@ -271,16 +270,16 @@ int main(int argc, char* argv[]) itPatient = f->GetDicomDirPatients().begin(); while ( itPatient != f->GetDicomDirPatients().end() ) { // on degouline les PATIENT de ce DICOMDIR - std::cout << (*itPatient)->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name + std::cout << (*itPatient)->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { // on degouline les STUDY de ce patient - std::cout << "--- "<< (*itStudy)->GetEntryValue(0x0008, 0x1030) << std::endl; // Study Description + std::cout << "--- "<< (*itStudy)->GetEntryString(0x0008, 0x1030) << std::endl; // Study Description itSerie = ((*itStudy)->GetDicomDirSeries()).begin(); while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { // on degouline les SERIES de cette study - std::cout << "--- --- "<< (*itSerie)->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description + std::cout << "--- --- "<< (*itSerie)->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description itImage = ((*itSerie)->GetDicomDirImages()).begin(); while (itImage != (*itSerie)->GetDicomDirImages().end() ) { // on degouline les IMAGES de cette serie - std::cout << "--- --- --- "<< (*itImage)->GetEntryValue(0x0004, 0x1500) << std::endl; // File name + std::cout << "--- --- --- "<< (*itImage)->GetEntryString(0x0004, 0x1500) << std::endl; // File name ++itImage; } ++itSerie; diff --git a/Example/PrintFile.cxx b/Example/PrintFile.cxx index 0fe29970..71ef4ab5 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/13 09:18:34 $ - Version: $Revision: 1.62 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.63 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,7 +19,7 @@ #include "gdcmDocument.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include "gdcmFileHelper.h" #include "gdcmDebug.h" @@ -46,7 +46,7 @@ void ShowLutData(gdcm::File *f) gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem(); if ( sqi != 0 ) { - std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002); + std::string lutDescriptor = sqi->GetEntryString(0x0028,0x3002); if ( /*lutDescriptor == GDCM_UNFOUND*/ 0 ) { //gdcmWarningMacro( "LUT Descriptor is missing" ); @@ -72,7 +72,7 @@ void ShowLutData(gdcm::File *f) std::cout << "Wrong LUT descriptor" << std::endl; } //LUT Data (CTX dependent) - gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006); + gdcm::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006); if ( b != 0 ) { int BitsAllocated = f->GetBitsAllocated(); @@ -108,7 +108,7 @@ void ShowLutData(gdcm::File *f) } } else - std::cout << "No LUT Data BinEntry (0x0028,0x3006) found?!? " + std::cout << "No LUT Data DataEntry (0x0028,0x3006) found?!? " << std::endl; } else @@ -272,7 +272,7 @@ int main(int argc, char *argv[]) << "] PlanarConfiguration= [" << planarConfig << "] "<< std::endl << " PhotometricInterpretation= [" - << f->GetEntryValue(0x0028,0x0004) + << f->GetEntryString(0x0028,0x0004) << "] "<< std::endl; int numberOfScalarComponents=f->GetNumberOfScalarComponents(); @@ -281,19 +281,21 @@ int main(int argc, char *argv[]) << " LUT = " << (f->HasLUT() ? "TRUE" : "FALSE") << std::endl; - if ( f->GetEntryValue(0x0002,0x0010) == gdcm::GDCM_NOTLOADED ) - { - std::cout << "Transfer Syntax not loaded. " << std::endl - << "Better you increase MAX_SIZE_LOAD_ELEMENT_VALUE" - << std::endl; - return 0; - } + 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; + 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; @@ -304,35 +306,35 @@ int main(int argc, char *argv[]) // ------------------------------------------------------------ std::string strPatientPosition = - f->GetEntryValue(0x0018,0x5100); + f->GetEntryString(0x0018,0x5100); if ( strPatientPosition != gdcm::GDCM_UNFOUND && strPatientPosition != "" ) std::cout << "PatientPosition (0x0010,0x5100)= [" << strPatientPosition << "]" << std::endl; std::string strViewPosition = - f->GetEntryValue(0x0018,0x5101); + f->GetEntryString(0x0018,0x5101); if ( strViewPosition != gdcm::GDCM_UNFOUND && strViewPosition != "" ) std::cout << "strViewPosition (0x0010,0x5101)= [" << strViewPosition << "]" << std::endl; std::string strPatientOrientation = - f->GetEntryValue(0x0020,0x0020); + f->GetEntryString(0x0020,0x0020); if ( strPatientOrientation != gdcm::GDCM_UNFOUND && strPatientOrientation != "") std::cout << "PatientOrientation (0x0020,0x0020)= [" << strPatientOrientation << "]" << std::endl; std::string strImageOrientationPatient = - f->GetEntryValue(0x0020,0x0037); + f->GetEntryString(0x0020,0x0037); if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND && strImageOrientationPatient != "" ) std::cout << "ImageOrientationPatient (0x0020,0x0037)= [" << strImageOrientationPatient << "]" << std::endl; std::string strImageOrientationRET = - f->GetEntryValue(0x0020,0x0035); + f->GetEntryString(0x0020,0x0035); if ( strImageOrientationRET != gdcm::GDCM_UNFOUND && strImageOrientationRET != "" ) std::cout << "ImageOrientationRET (0x0020,0x0035)= [" @@ -377,7 +379,7 @@ int main(int argc, char *argv[]) gdcm::SQItem *sqi= modLutSeq->GetFirstSQItem(); if ( !sqi ) { - std::string lutDescriptor = sqi->GetEntryValue(0x0028,0x3002); + 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) @@ -391,7 +393,7 @@ int main(int argc, char *argv[]) //gdcmWarningMacro( "Wrong LUT descriptor" ); std::cout << "Wrong LUT descriptor" << std::endl; } - gdcm::BinEntry *b = sqi->GetBinEntry(0x0028,0x3006); + gdcm::DataEntry *b = sqi->GetDataEntry(0x0028,0x3006); if ( b != 0 ) { if ( b->GetLength() != 0 ) @@ -515,35 +517,35 @@ int main(int argc, char *argv[]) // ------------------------------------------------------------ std::string strPatientPosition = - f->GetEntryValue(0x0018,0x5100); + f->GetEntryString(0x0018,0x5100); if ( strPatientPosition != gdcm::GDCM_UNFOUND && strPatientPosition != "" ) std::cout << "PatientPosition (0x0010,0x5100)= [" << strPatientPosition << "]" << std::endl; std::string strViewPosition = - f->GetEntryValue(0x0018,0x5101); + f->GetEntryString(0x0018,0x5101); if ( strViewPosition != gdcm::GDCM_UNFOUND && strViewPosition != "" ) std::cout << "strViewPosition (0x0010,0x5101)= [" << strViewPosition << "]" << std::endl; std::string strPatientOrientation = - f->GetEntryValue(0x0020,0x0020); + f->GetEntryString(0x0020,0x0020); if ( strPatientOrientation != gdcm::GDCM_UNFOUND && strPatientOrientation != "") std::cout << "PatientOrientation (0x0020,0x0020)= [" << strPatientOrientation << "]" << std::endl; std::string strImageOrientationPatient = - f->GetEntryValue(0x0020,0x0037); + f->GetEntryString(0x0020,0x0037); if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND && strImageOrientationPatient != "" ) std::cout << "ImageOrientationPatient (0x0020,0x0037)= [" << strImageOrientationPatient << "]" << std::endl; std::string strImageOrientationRET = - f->GetEntryValue(0x0020,0x0035); + f->GetEntryString(0x0020,0x0035); if ( strImageOrientationRET != gdcm::GDCM_UNFOUND && strImageOrientationRET != "" ) std::cout << "ImageOrientationRET (0x0020,0x0035)= [" diff --git a/Example/ReWrite.cxx b/Example/ReWrite.cxx index 131c687f..1aa4b8f9 100644 --- a/Example/ReWrite.cxx +++ b/Example/ReWrite.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: ReWrite.cxx,v $ Language: C++ - Date: $Date: 2005/10/17 10:29:32 $ - Version: $Revision: 1.12 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.13 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -150,7 +150,7 @@ int main(int argc, char *argv[]) << " SampleserPixel=" << sPP << " PlanarConfiguration=" << planarConfig << " PhotometricInterpretation=" - << f->GetEntryValue(0x0028,0x0004) + << f->GetEntryString(0x0028,0x0004) << std::endl; int numberOfScalarComponents=f->GetNumberOfScalarComponents(); diff --git a/Example/TestChangeHeader.cxx b/Example/TestChangeHeader.cxx index bbc4d6fa..95bfbf88 100644 --- a/Example/TestChangeHeader.cxx +++ b/Example/TestChangeHeader.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestChangeHeader.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 12:02:02 $ - Version: $Revision: 1.15 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.16 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -47,11 +47,11 @@ int main(int argc, char *argv[]) f2->GetFile()->GetPubDict()->GetEntry( 0x0018, 1310 ); std::cerr << std::hex << dictEntry->GetGroup() << "," << dictEntry->GetElement() << std::endl; - std::string matrix = f2->GetFile()->GetEntryValue(0x0018, 0x1310); + std::string matrix = f2->GetFile()->GetEntryString(0x0018, 0x1310); if(matrix != "gdcm::Unfound") { std::cerr << "Aquisition Matrix:" << matrix << std::endl; - f1->GetFile()->InsertValEntry( matrix, 0x0018, 0x1310); + f1->GetFile()->InsertEntryString( matrix, 0x0018, 0x1310); } f1->GetImageData(); diff --git a/Example/TestCopyDicom.cxx b/Example/TestCopyDicom.cxx index f44754df..081c58c1 100644 --- a/Example/TestCopyDicom.cxx +++ b/Example/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/10/17 10:41:59 $ - Version: $Revision: 1.30 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.31 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,8 +18,7 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #ifndef _WIN32 #include //for access, unlink @@ -110,17 +109,11 @@ int main(int argc, char *argv[]) gdcm::DocEntry *d = original->GetFile()->GetFirstEntry(); while(d) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) + if ( gdcm::DataEntry *de = dynamic_cast(d) ) { - copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copy->GetFile()->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + copy->GetFile()->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { diff --git a/Example/Volume2Dicom.cxx b/Example/Volume2Dicom.cxx index facc30a4..8d18a440 100644 --- a/Example/Volume2Dicom.cxx +++ b/Example/Volume2Dicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: Volume2Dicom.cxx,v $ Language: C++ - Date: $Date: 2005/09/07 08:35:20 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -25,7 +25,6 @@ #include "gdcmFile.h" #include "gdcmDocEntry.h" -#include "gdcmBinEntry.h" #include "gdcmFileHelper.h" #include "gdcmUtil.h" diff --git a/Example/WriteDicomSimple.cxx b/Example/WriteDicomSimple.cxx index 84d98a92..455b9063 100644 --- a/Example/WriteDicomSimple.cxx +++ b/Example/WriteDicomSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: WriteDicomSimple.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 12:02:02 $ - Version: $Revision: 1.13 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.14 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -63,39 +63,39 @@ int main(int argc, char *argv[]) // Set the image size str.str(""); str << SIZE_X; - header->InsertValEntry(str.str(),0x0028,0x0011); // Columns + header->InsertEntryString(str.str(),0x0028,0x0011); // Columns str.str(""); str << SIZE_Y; - header->InsertValEntry(str.str(),0x0028,0x0010); // Rows + header->InsertEntryString(str.str(),0x0028,0x0010); // Rows // Set the pixel type str.str(""); str << COMPONENT_SIZE * 8; - header->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated - header->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored + header->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated + header->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << ( COMPONENT_SIZE * 8 ) - 1; - header->InsertValEntry(str.str(),0x0028,0x0102); // High Bit + header->InsertEntryString(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation str.str(""); str << "0"; // Unsigned - header->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation + header->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation // Set the samples per pixel str.str(""); str << COMPONENT; - header->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel + header->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel // Set the Window / Level str.str(""); str << COLOR_WINDOW; - header->InsertValEntry(str.str(),0x0028,0x1051); // Window Width + header->InsertEntryString(str.str(),0x0028,0x1051); // Window Width str.str(""); str << COLOR_LEVEL; - header->InsertValEntry(str.str(),0x0028,0x1050); // Window Center + header->InsertEntryString(str.str(),0x0028,0x1050); // Window Center if( !header->IsReadable() ) { diff --git a/Example/exColorToRGB.cxx b/Example/exColorToRGB.cxx index 583d44f6..12964570 100644 --- a/Example/exColorToRGB.cxx +++ b/Example/exColorToRGB.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exColorToRGB.cxx,v $ Language: C++ - Date: $Date: 2005/09/06 11:10:03 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,8 +19,7 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include "gdcmSeqEntry.h" #include // for exit @@ -112,17 +111,11 @@ int main(int argc, char *argv[]) && !( d->GetGroup()%2 ) ) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) + if ( gdcm::DataEntry *de = dynamic_cast(d) ) { - copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copy->GetFile()->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + copy->GetFile()->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { diff --git a/Example/exCurveData.cxx b/Example/exCurveData.cxx index 434a0dfe..47ec1b3c 100644 --- a/Example/exCurveData.cxx +++ b/Example/exCurveData.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exCurveData.cxx,v $ Language: C++ - Date: $Date: 2005/10/16 17:07:05 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/10/18 08:35:43 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,7 +20,7 @@ #include "gdcmCommon.h" #include "gdcmDebug.h" #include "gdcmDocEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" static const char* TypeOfDataArrays[13][2] = { { "TAC" , "time activity curve" }, @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) // ============================================================ //* B 5004|3000 [OW] [Curve Data] [gdcm::Binary data loaded;length = 1938] - std::string curve_data_str = f->GetEntryValue(0x5004, 0x3000); + std::string curve_data_str = f->GetEntryString(0x5004, 0x3000); if (curve_data_str == gdcm::GDCM_UNFOUND) { std::cout << " Image doesn't contain any Curve Data" << std::endl; @@ -142,27 +142,27 @@ int main(int argc, char *argv[]) // ============================================================ std::istringstream convert; //* V 5004|0005 [US] [Curve Dimensions] [1] x(1) - std::string curve_dim_str = f->GetEntryValue(0x5004,0x0005); + std::string curve_dim_str = f->GetEntryString(0x5004,0x0005); unsigned short curve_dim; convert.str(curve_dim_str); convert >> curve_dim; std::cout << "Curve Dimensions: " << curve_dim << std::endl; //* V 5004|0010 [US] [Number of Points] [969] x(3c9) - std::string num_points_str = f->GetEntryValue(0x5004,0x0010); + std::string num_points_str = f->GetEntryString(0x5004,0x0010); unsigned short num_points; convert.clear(); //important convert.str(num_points_str); convert >> num_points; std::cout << "Number of Points: " << num_points << std::endl; //* V 5004|0020 [CS] [Type of Data] [PHYSIO] - std::string data_type = f->GetEntryValue(0x5004,0x0020); + std::string data_type = f->GetEntryString(0x5004,0x0020); std::cout << "Type of Data: " << data_type << std::endl; std::cout << " this is thus a : " << ConvertTypeOfData(data_type) << std::endl; //* V 5004|0022 [LO] [Curve Description] [] - std::string curve_desc = f->GetEntryValue(0x5004,0x0022); + std::string curve_desc = f->GetEntryString(0x5004,0x0022); std::cout << "Curve Description: " << curve_desc << std::endl; //* V 5004|0103 [US] [Data Value Representation] [0] x(0) - std::string data_rep_str = f->GetEntryValue(0x5004,0x0103); + std::string data_rep_str = f->GetEntryString(0x5004,0x0103); unsigned short data_rep; convert.clear(); //important convert.str(data_rep_str); @@ -170,33 +170,33 @@ int main(int argc, char *argv[]) gdcm::DocEntry *pCurveDataDoc = f->GetDocEntry(0x5004, 0x3000); - gdcm::BinEntry *pCurveData = dynamic_cast(pCurveDataDoc); + gdcm::DataEntry *pCurveData = dynamic_cast(pCurveDataDoc); uint8_t *curve_data = pCurveData->GetBinArea(); // From Part3, C.10.2.1.2 Data value representation (p668) size_t sz; switch( data_rep) - { - case 0: - sz = PrintCurveData((unsigned short*)(curve_data), num_points); - break; - case 1: - sz = PrintCurveData((signed short*)(curve_data), num_points); - break; - case 2: - sz = PrintCurveData((float*)(curve_data), num_points); - break; - case 3: - sz = PrintCurveData((double*)(curve_data), num_points); - break; - case 4: - sz = PrintCurveData((signed long*)(curve_data), num_points); - break; - default: - std::cerr << "Error don't know the type: " << data_rep_str << std::endl; - delete f; - return 1; - } + { + case 0: + sz = PrintCurveData((unsigned short*)(curve_data), num_points); + break; + case 1: + sz = PrintCurveData((signed short*)(curve_data), num_points); + break; + case 2: + sz = PrintCurveData((float*)(curve_data), num_points); + break; + case 3: + sz = PrintCurveData((double*)(curve_data), num_points); + break; + case 4: + sz = PrintCurveData((signed long*)(curve_data), num_points); + break; + default: + std::cerr << "Error don't know the type: " << data_rep_str << std::endl; + delete f; + return 1; + } // Just to make sure that values read are consistant and we won't read out of bound data: assert( sz*num_points == pCurveData->GetLength()); diff --git a/Example/exExtractDicomTags.cxx b/Example/exExtractDicomTags.cxx index f94d6ca5..c799f927 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: 2005/10/18 08:35:44 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,8 +18,6 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" #include "gdcmDebug.h" @@ -132,26 +130,26 @@ int main(int argc, char *argv[]) // 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); //sexe + 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 // Radiologist : // 0008|0090 [Referring Physician's Name] @@ -162,7 +160,7 @@ int main(int argc, char *argv[]) // --> I'll have to ask people working on PACS which one they use. JPRx - ProtocolName = f->GetEntryValue(0x0018,0x1030); + ProtocolName = f->GetEntryString(0x0018,0x1030); // --> Big trouble with nz (mb of planes) and nt (number of 'times') // --> that belong to LibIDO, not to DICOM. @@ -183,15 +181,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 - - BitsAllocated = f->GetEntryValue(0x0028,0x0100); - BitsStored = f->GetEntryValue(0x0028,0x0101); - HighBit = f->GetEntryValue(0x0028,0x0102); - PixelRepresentation = f->GetEntryValue(0x0028,0x0103); + 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->GetEntryString(0x0028,0x0100); + BitsStored = f->GetEntryString(0x0028,0x0101); + HighBit = f->GetEntryString(0x0028,0x0102); + PixelRepresentation = f->GetEntryString(0x0028,0x0103); PixelType = f->GetPixelType(); //type /* diff --git a/Example/exExtractTag.cxx b/Example/exExtractTag.cxx index 297b149c..b1097a8e 100644 --- a/Example/exExtractTag.cxx +++ b/Example/exExtractTag.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exExtractTag.cxx,v $ Language: C++ - Date: $Date: 2005/10/10 21:57:57 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,7 +20,7 @@ #include "gdcmCommon.h" #include "gdcmDebug.h" #include "gdcmDocEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include @@ -29,11 +29,11 @@ int main(int argc, char *argv[]) gdcm::File *f; if( argc < 5 ) - { - std::cerr << "Usage :" << argv[0] << " input.dcm group element outputfile" << std::endl; - std::cerr << " Ex: " << argv[0] << " /tmp/bla.dcm 0029 2110 /tmp/out.raw" << std::endl; - return 1; - } + { + std::cerr << "Usage :" << argv[0] << " input.dcm group element outputfile" << std::endl; + std::cerr << " Ex: " << argv[0] << " /tmp/bla.dcm 0029 2110 /tmp/out.raw" << std::endl; + return 1; + } std::string fileName = argv[1]; std::cout << fileName << std::endl; @@ -72,7 +72,7 @@ int main(int argc, char *argv[]) convert >> std::hex >> elem; std::cout << "Extracting tag: (0x" << std::hex << std::setw(4) << std::setfill('0') << group << ",0x" << std::setw(4) << std::setfill('0') << elem << ")" << std::endl; - std::string dicom_tag_value = f->GetEntryValue(group, elem); + std::string dicom_tag_value = f->GetEntryString(group, elem); if (dicom_tag_value == gdcm::GDCM_UNFOUND) { gdcm::DictEntry *dictEntry = f->GetPubDict()->GetEntry( group, elem); @@ -82,22 +82,22 @@ int main(int argc, char *argv[]) } gdcm::DocEntry *dicom_tag_doc = f->GetDocEntry(group, elem); - gdcm::BinEntry *dicom_tag = dynamic_cast(dicom_tag_doc); + gdcm::DataEntry *dicom_tag = dynamic_cast(dicom_tag_doc); if( !dicom_tag ) - { - std::cerr << "Sorry BinEntry only please" << std::endl; //TODO support ValEntry - delete f; - return 1; - } + { + std::cerr << "Sorry DataEntry only please" << std::endl; + delete f; + return 1; + } // Write out the data as a file: std::ofstream o(argv[4]); if( !o ) - { - std::cerr << "Problem opening file: " << argv[4] << std::endl; - delete f; - return 1; - } + { + std::cerr << "Problem opening file: " << argv[4] << std::endl; + delete f; + return 1; + } o.write((char*)dicom_tag->GetBinArea(), dicom_tag->GetLength()); o.close(); diff --git a/Example/exGC.cxx b/Example/exGC.cxx index 9e1d4c48..68f8adff 100644 --- a/Example/exGC.cxx +++ b/Example/exGC.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exGC.cxx,v $ Language: C++ - Date: $Date: 2005/08/30 15:13:06 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,8 +19,7 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include "gdcmSeqEntry.h" #include // for exit @@ -132,17 +131,11 @@ int main(int argc, char *argv[]) && !( d->GetGroup()%2 ) ) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) + if ( gdcm::DataEntry *de = dynamic_cast(d) ) { - copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copy->GetFile()->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + copy->GetFile()->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { diff --git a/Example/exGrey2RGB.cxx b/Example/exGrey2RGB.cxx index cc3d5e4b..768228bb 100644 --- a/Example/exGrey2RGB.cxx +++ b/Example/exGrey2RGB.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exGrey2RGB.cxx,v $ Language: C++ - Date: $Date: 2005/07/19 15:19:25 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,8 +18,6 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmDebug.h" #ifndef _WIN32 @@ -90,7 +88,7 @@ int main(int argc, char *argv[]) uint8_t *imageDataRGB = new uint8_t[dataSize*3]; - if (fh->GetFile()->GetEntryValue(0x0028,0x0100) == "8" ) + if (fh->GetFile()->GetEntryString(0x0028,0x0100) == "8" ) { for (unsigned int i=0;iGetFile()->InsertValEntry( "3 " ,0x0028,0x0002); + fh->GetFile()->InsertEntryString( "3 " ,0x0028,0x0002); // Photometric Interpretation - fh->GetFile()->InsertValEntry( "RGB ",0x0028,0x0004 ); + fh->GetFile()->InsertEntryString( "RGB ",0x0028,0x0004 ); // Planar Configuration - fh->GetFile()->InsertValEntry( "1 ",0x0028,0x0006 ); + fh->GetFile()->InsertEntryString( "1 ",0x0028,0x0006 ); // TODO : free existing PixelData first ! diff --git a/Example/exImageLighten.cxx b/Example/exImageLighten.cxx index b82beab4..fe3ff421 100644 --- a/Example/exImageLighten.cxx +++ b/Example/exImageLighten.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exImageLighten.cxx,v $ Language: C++ - Date: $Date: 2005/09/08 14:33:50 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,8 +19,7 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include "gdcmSeqEntry.h" #include // for exit @@ -106,17 +105,11 @@ int main(int argc, char *argv[]) && !( d->GetGroup()%2 ) ) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) + if ( gdcm::DataEntry *de = dynamic_cast(d) ) { - copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copy->GetFile()->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + copy->GetFile()->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { diff --git a/Example/exOverlaysACR.cxx b/Example/exOverlaysACR.cxx index 3af7774c..f5eb508e 100644 --- a/Example/exOverlaysACR.cxx +++ b/Example/exOverlaysACR.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exOverlaysACR.cxx,v $ Language: C++ - Date: $Date: 2005/08/30 15:13:06 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -118,7 +118,7 @@ int main(int argc, char *argv[]) delete f; return 0; } - std::string s1 = f->GetEntryValue(0x6000, 0x0102); + std::string s1 = f->GetEntryString(0x6000, 0x0102); if (s1 == gdcm::GDCM_UNFOUND) { std::cout << " Image doesn't contain any Overlay " << std::endl; @@ -199,11 +199,11 @@ int main(int argc, char *argv[]) gdcm::FileHelper *fh = 0; -while ( (strOvlBitPosition = f->GetEntryValue(currentOvlGroup, 0x0102)) +while ( (strOvlBitPosition = f->GetEntryString(currentOvlGroup, 0x0102)) != gdcm::GDCM_UNFOUND ) { - strOverlayLocation = f->GetEntryValue(currentOvlGroup, 0x0200); + strOverlayLocation = f->GetEntryString(currentOvlGroup, 0x0200); if ( strOverlayLocation != gdcm::GDCM_UNFOUND ) { overlayLocation = atoi(strOverlayLocation.c_str()); @@ -241,18 +241,18 @@ while ( (strOvlBitPosition = f->GetEntryValue(currentOvlGroup, 0x0102)) str.str(""); str << nx; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns + fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns str.str(""); str << ny; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows + fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows - fileToBuild->InsertValEntry("8",0x0028,0x0100); // Bits Allocated - fileToBuild->InsertValEntry("8",0x0028,0x0101); // Bits Stored - fileToBuild->InsertValEntry("7",0x0028,0x0102); // High Bit - fileToBuild->InsertValEntry("0",0x0028,0x0103); // Pixel Representation - fileToBuild->InsertValEntry("1",0x0028,0x0002); // Samples per Pixel + fileToBuild->InsertEntryString("8",0x0028,0x0100); // Bits Allocated + fileToBuild->InsertEntryString("8",0x0028,0x0101); // Bits Stored + fileToBuild->InsertEntryString("7",0x0028,0x0102); // High Bit + fileToBuild->InsertEntryString("0",0x0028,0x0103); // Pixel Representation + fileToBuild->InsertEntryString("1",0x0028,0x0002); // Samples per Pixel - fileToBuild->InsertValEntry("MONOCHROME2 ",0x0028,0x0004); + fileToBuild->InsertEntryString("MONOCHROME2 ",0x0028,0x0004); // Other mandatory fields will be set automatically, // just before Write(), by FileHelper::CheckMandatoryElements() diff --git a/Example/exPrintWritePrint.cxx b/Example/exPrintWritePrint.cxx index 8a6ea759..476063b1 100644 --- a/Example/exPrintWritePrint.cxx +++ b/Example/exPrintWritePrint.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exPrintWritePrint.cxx,v $ Language: C++ - Date: $Date: 2005/08/30 15:13:06 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,9 +17,6 @@ =========================================================================*/ #include "gdcmFile.h" #include "gdcmFileHelper.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" - int main(int argc, char *argv[]) { diff --git a/Example/exReadPapyrus.cxx b/Example/exReadPapyrus.cxx index 99badbf8..185c84ae 100644 --- a/Example/exReadPapyrus.cxx +++ b/Example/exReadPapyrus.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exReadPapyrus.cxx,v $ Language: C++ - Date: $Date: 2005/07/07 17:31:54 $ - Version: $Revision: 1.3 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.4 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,8 +18,7 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" #include "gdcmDebug.h" @@ -178,12 +177,12 @@ int main(int argc, char *argv[]) // 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 = sqi->GetEntryValue(0x0008,0x0020); - StudyTime = sqi->GetEntryValue(0x0008,0x0030); - Modality = sqi->GetEntryValue(0x0008,0x0060); - PatientName = sqi->GetEntryValue(0x0010,0x0010); + MediaStSOPinstUID = f->GetEntryString(0x0002,0x0002); + TransferSyntax = f->GetEntryString(0x0002,0x0010); + StudyDate = sqi->GetEntryString(0x0008,0x0020); + StudyTime = sqi->GetEntryString(0x0008,0x0030); + Modality = sqi->GetEntryString(0x0008,0x0060); + PatientName = sqi->GetEntryString(0x0010,0x0010); std::cout << "TransferSyntax " << TransferSyntax << std::endl; @@ -198,17 +197,17 @@ int main(int argc, char *argv[]) // we brutally suppose all the images within a Papyrus file // have the same caracteristics. - // if you're aware they have not, just move the GetEntryValue + // if you're aware they have not, just move the GetEntryString // inside the loop // Get caracteristics of the first image - SamplesPerPixel = sqi->GetEntryValue(0x0028,0x0002); - Rows = sqi->GetEntryValue(0x0028,0x0010); - Columns = sqi->GetEntryValue(0x0028,0x0011); - BitsAllocated = sqi->GetEntryValue(0x0028,0x0100); - BitsStored = sqi->GetEntryValue(0x0028,0x0101); - HighBit = sqi->GetEntryValue(0x0028,0x0102); - PixelRepresentation = sqi->GetEntryValue(0x0028,0x0103); + SamplesPerPixel = sqi->GetEntryString(0x0028,0x0002); + Rows = sqi->GetEntryString(0x0028,0x0010); + Columns = sqi->GetEntryString(0x0028,0x0011); + BitsAllocated = sqi->GetEntryString(0x0028,0x0100); + BitsStored = sqi->GetEntryString(0x0028,0x0101); + HighBit = sqi->GetEntryString(0x0028,0x0102); + PixelRepresentation = sqi->GetEntryString(0x0028,0x0103); // just convert those needed to compute PixelArea length int iRows = (uint32_t) atoi( Rows.c_str() ); @@ -225,7 +224,7 @@ int main(int argc, char *argv[]) // allocate enough room to get the pixels of all images. uint8_t *PixelArea = new uint8_t[lgrImage*nbImages]; uint8_t *currentPosition = PixelArea; - gdcm::BinEntry *pixels; + gdcm::DataEntry *pixels; // declare and open the file std::ifstream *Fp; @@ -247,7 +246,7 @@ int main(int argc, char *argv[]) while (sqi) { std::cout << "One more image read. Keep waiting" << std::endl; - Rows = sqi->GetEntryValue(0x0028,0x0010); + Rows = sqi->GetEntryString(0x0028,0x0010); // minimum integrity check if (Rows != previousRows) { @@ -255,7 +254,7 @@ int main(int argc, char *argv[]) return 1; } // get the images pixels - pixels = sqi->GetBinEntry(0x7fe0,0x0010); + pixels = sqi->GetDataEntry(0x7fe0,0x0010); offset = pixels->GetOffset(); // perform a fseek, on offset length on the 'right' length Fp->seekg(offset, std::ios::beg); @@ -274,23 +273,23 @@ int main(int argc, char *argv[]) gdcm::File *n = new gdcm::File(); - n->InsertValEntry(MediaStSOPinstUID, 0x0002,0x0002); + n->InsertEntryString(MediaStSOPinstUID, 0x0002,0x0002); // Whe keep default gdcm Transfer Syntax (Explicit VR Little Endian) // since using Papyrus one (Implicit VR Little Endian) is a mess - //n->InsertValEntry(TransferSyntax, 0x0002,0x0010); - n->InsertValEntry(StudyDate, 0x0008,0x0020); - n->InsertValEntry(StudyTime, 0x0008,0x0030); - n->InsertValEntry(Modality, 0x0008,0x0060); - n->InsertValEntry(PatientName, 0x0010,0x0010); - - n->InsertValEntry(SamplesPerPixel, 0x0028,0x0002); - n->InsertValEntry(NumberOfFrames, 0x0028,0x0008); - n->InsertValEntry(Rows, 0x0028,0x0010); - n->InsertValEntry(Columns, 0x0028,0x0011); - n->InsertValEntry(BitsAllocated, 0x0028,0x0100); - n->InsertValEntry(BitsStored, 0x0028,0x0101); - n->InsertValEntry(HighBit, 0x0028,0x0102); - n->InsertValEntry(PixelRepresentation,0x0028,0x0103); + //n->InsertEntryString(TransferSyntax, 0x0002,0x0010); + n->InsertEntryString(StudyDate, 0x0008,0x0020); + n->InsertEntryString(StudyTime, 0x0008,0x0030); + n->InsertEntryString(Modality, 0x0008,0x0060); + n->InsertEntryString(PatientName, 0x0010,0x0010); + + n->InsertEntryString(SamplesPerPixel, 0x0028,0x0002); + n->InsertEntryString(NumberOfFrames, 0x0028,0x0008); + n->InsertEntryString(Rows, 0x0028,0x0010); + n->InsertEntryString(Columns, 0x0028,0x0011); + n->InsertEntryString(BitsAllocated, 0x0028,0x0100); + n->InsertEntryString(BitsStored, 0x0028,0x0101); + n->InsertEntryString(HighBit, 0x0028,0x0102); + n->InsertEntryString(PixelRepresentation,0x0028,0x0103); // create the file gdcm::FileHelper *file = new gdcm::FileHelper(n); diff --git a/Example/exReadWriteFile.cxx b/Example/exReadWriteFile.cxx index 757296ef..3666c6ee 100644 --- a/Example/exReadWriteFile.cxx +++ b/Example/exReadWriteFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: exReadWriteFile.cxx,v $ Language: C++ - Date: $Date: 2005/07/19 15:19:25 $ - Version: $Revision: 1.6 $ + Date: $Date: 2005/10/18 08:35:44 $ + Version: $Revision: 1.7 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,8 +19,7 @@ #include "gdcmFile.h" #include "gdcmFileHelper.h" #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include "gdcmSeqEntry.h" #include // for exit @@ -80,7 +79,7 @@ std::cout << " --- WARNING --- WARNING --- WARNING --- WARNING ---" <(d)) // We skip Shadow Groups, since nobody knows what they mean - && !( d->GetGroup()%2 ) - // we skip BinEntries, since their content is not human-readable - && !dynamic_cast(d) ) + && !( d->GetGroup()%2 ) ) { // If user just 'wants to see' //d->Print(); //std::cout << std::endl; // If user wants to get info about the entry - // (he is sure, here that DocEntry is a ValEntry) - valEntry = dynamic_cast(d); + // (he is sure, here that DocEntry is a DataEntry) + dataEntry = dynamic_cast(d); // Let's be carefull -maybe he commented out some previous line- - if (!valEntry) + if (!dataEntry) continue; - value = valEntry->GetValue(); - vr = valEntry->GetVR(); + value = dataEntry->GetString(); + vr = dataEntry->GetVR(); // user wants really to know everything about entry! - vm = valEntry->GetVM(); - name = valEntry->GetName(); + vm = dataEntry->GetVM(); + name = dataEntry->GetName(); std::cout //<< std::hex << group << "," << elem - << valEntry->GetKey() - << " VR :[" << vr << "] VM : [" << vm + << dataEntry->GetKey() + << " VR :[" << vr << "] VM : [" << vm << "] name : [" << name << "]" << " value : [" << value << "]" - - << std::endl; + << std::endl; } d = f1->GetNextEntry(); } @@ -197,21 +193,21 @@ std::cout << " --- WARNING --- WARNING --- WARNING --- WARNING ---" <GetEntryValue(0x0008,0x0070) + std::cout << "Manufacturer :[" << f1->GetEntryString(0x0008,0x0070) << "]" << std::endl; - std::cout << "Institution :[" << f1->GetEntryValue(0x0008,0x0080) + std::cout << "Institution :[" << f1->GetEntryString(0x0008,0x0080) << "]" << std::endl; - std::cout << "Patient's name :[" << f1->GetEntryValue(0x0010,0x0010) + std::cout << "Patient's name :[" << f1->GetEntryString(0x0010,0x0010) << "]" << std::endl; - std::cout << "Physician's name :[" << f1->GetEntryValue(0x0008,0x0090) + std::cout << "Physician's name :[" << f1->GetEntryString(0x0008,0x0090) << "]" << std::endl; - std::cout << "Study Date :[" << f1->GetEntryValue(0x0008,0x0020) + std::cout << "Study Date :[" << f1->GetEntryString(0x0008,0x0020) << "]" << std::endl; - std::cout << "Study inst UID :[" << f1->GetEntryValue(0x0020,0x000d) + std::cout << "Study inst UID :[" << f1->GetEntryString(0x0020,0x000d) << "]" << std::endl; - std::cout << "Serie inst UID :[" << f1->GetEntryValue(0x0020,0x000e) + std::cout << "Serie inst UID :[" << f1->GetEntryString(0x0020,0x000e) << "]" << std::endl; - std::cout << "Frame ref UID :[" << f1->GetEntryValue(0x0020,0x0052) + std::cout << "Frame ref UID :[" << f1->GetEntryString(0x0020,0x0052) << "]" << std::endl; // User wants to get info about the 'real world' vs image @@ -270,17 +266,11 @@ std::cout << " --- WARNING --- WARNING --- WARNING --- WARNING ---" <GetGroup()%2 ) ) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) + if ( gdcm::DataEntry *de = dynamic_cast(d) ) { - copy->GetFile()->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copy->GetFile()->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + copy->GetFile()->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index 0dd7dbc9..02295475 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -15,6 +15,7 @@ SET(TEST_SOURCES TestVR.cxx TestDictGroupName.cxx TestDict.cxx + TestDataEntry.cxx TestWriteSimple.cxx TestImageSet.cxx TestDicomDirElement.cxx @@ -145,6 +146,9 @@ SET(BLACK_LIST "MR_Philips_Intera_No_PrivateSequenceImplicitVR.dcm" "MR_Philips_Intera_PrivateSequenceImplicitVR.dcm" "MR_SIEMENS_forceLoad29-1010_29-1020.dcm" + # An element contains a value of 4, but no data follows + # So, the next (group, elem) is not correctly read + "gdcm-MR-PHILIPS-16-Multi-Seq.dcm" ) # Create a specific list of dicom files that we know are part of a sequence diff --git a/Testing/TestAllEntryVerify.cxx b/Testing/TestAllEntryVerify.cxx index d506661a..641b8f78 100644 --- a/Testing/TestAllEntryVerify.cxx +++ b/Testing/TestAllEntryVerify.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestAllEntryVerify.cxx,v $ Language: C++ - Date: $Date: 2005/07/11 14:47:19 $ - Version: $Revision: 1.28 $ + Date: $Date: 2005/10/18 08:35:45 $ + Version: $Revision: 1.29 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,7 +23,7 @@ #include #include -typedef std::string EntryValueType; // same type as ValEntry::value +typedef std::string EntryValueType; // same type as DataEntry::value typedef std::map< gdcm::TagKey, EntryValueType > MapEntryValues; typedef MapEntryValues *MapEntryValuesPtr; typedef std::string FileNameType; diff --git a/Testing/TestAllPrint.cxx b/Testing/TestAllPrint.cxx index 3962137b..e1d59cb2 100644 --- a/Testing/TestAllPrint.cxx +++ b/Testing/TestAllPrint.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestAllPrint.cxx,v $ Language: C++ - Date: $Date: 2005/08/30 15:13:07 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -25,14 +25,12 @@ #include "gdcmFileHelper.h" #include "gdcmUtil.h" #include "gdcmCommon.h" -#include "gdcmBinEntry.h" #include "gdcmDocEntry.h" #include "gdcmDocEntrySet.h" #include "gdcmDocument.h" #include "gdcmElementSet.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" #include diff --git a/Testing/TestAllReadCompareDicom.cxx b/Testing/TestAllReadCompareDicom.cxx index 7a7ab5c6..bb428fd0 100644 --- a/Testing/TestAllReadCompareDicom.cxx +++ b/Testing/TestAllReadCompareDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestAllReadCompareDicom.cxx,v $ Language: C++ - Date: $Date: 2005/08/30 15:13:07 $ - Version: $Revision: 1.47 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.48 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -485,10 +485,12 @@ int InternalTest(std::string const &filename, << " Scalar size: " << tested->GetFile()->GetPixelSize() << " # " << reference->GetScalarSize() << std::endl << " Number of scalar: " << tested->GetFile()->GetNumberOfScalarComponents() << " # " - << reference->GetNumberOfComponents() << std::endl; + << reference->GetNumberOfComponents() << std::endl + << " Pixel type: " << tested->GetFile()->GetPixelType() << std::endl; delete reference; delete tested; delete f; + return 1; } // Test the data size diff --git a/Testing/TestAnonymize.cxx b/Testing/TestAnonymize.cxx index ab359e14..0fff3b83 100644 --- a/Testing/TestAnonymize.cxx +++ b/Testing/TestAnonymize.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestAnonymize.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 13:39:56 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,8 +17,6 @@ =========================================================================*/ #include "gdcmFile.h" #include "gdcmFileHelper.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmGlobal.h" #include "gdcmDebug.h" diff --git a/Testing/TestBuildUpDicomDir.cxx b/Testing/TestBuildUpDicomDir.cxx index 524e5837..da7c881f 100644 --- a/Testing/TestBuildUpDicomDir.cxx +++ b/Testing/TestBuildUpDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestBuildUpDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/08/31 09:29:11 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -57,7 +57,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) // Create patient ONE // ------------------ p1 = dcmdir->NewPatient(); - p1->SetValEntry("patientONE",0x0010, 0x0010); + p1->SetEntryString("patientONE",0x0010, 0x0010); // fill here other patient characteristics gdcm::DicomDirStudy *s11; @@ -71,19 +71,19 @@ int TestBuildUpDicomDir(int argc, char *argv[]) // Let's create and add a Study for this Patient s11 = p1->NewStudy(); - s11->SetValEntry("StudyDescrOne.One_",0x0008, 0x1030); + s11->SetEntryString("StudyDescrOne.One_",0x0008, 0x1030); // we know entry (0008,1060) is not yet created - s11->InsertValEntry("Dr Mabuse", 0x0008, 0x1060); + s11->InsertEntryString("Dr Mabuse", 0x0008, 0x1060); // fill here other Study characteristics gdcm::DicomDirStudy *s12 = p1->NewStudy(); - s12->SetValEntry("StudyDescrOne.Two",0x0008, 0x1030); - s12->InsertValEntry("Dr Zorglub", 0x0008, 0x1060); + s12->SetEntryString("StudyDescrOne.Two",0x0008, 0x1030); + s12->InsertEntryString("Dr Zorglub", 0x0008, 0x1060); // fill here other Study characteristics gdcm::DicomDirStudy *s13 = p1->NewStudy(); - s13->SetValEntry("StudyDescrOne.Tree",0x0008, 0x1030); - s13->InsertValEntry("Dr Follamour", 0x0008, 0x1060); + s13->SetEntryString("StudyDescrOne.Tree",0x0008, 0x1030); + s13->InsertEntryString("Dr Follamour", 0x0008, 0x1060); // fill here other Study characteristics gdcm::DicomDirSerie *s111; @@ -97,7 +97,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) // Let's create and add a Serie for this Study s111 = s11->NewSerie(); - s111->SetValEntry("01-01-111", 0x0008, 0x0021); + s111->SetEntryString("01-01-111", 0x0008, 0x0021); // fill here other Serie characteristics gdcm::DicomDirImage *s1111; @@ -112,47 +112,47 @@ int TestBuildUpDicomDir(int argc, char *argv[]) // Let's create and add a Image for this Serie s1111 = s111->NewImage(); - s1111->SetValEntry("imageFileName1111",0x0004,0x1500); + s1111->SetEntryString("imageFileName1111",0x0004,0x1500); gdcm::DicomDirImage *s1112 = s111->NewImage(); - s1112->SetValEntry("imageFileName1112",0x0004,0x1500); + s1112->SetEntryString("imageFileName1112",0x0004,0x1500); // Create patient TWO // ------------------ gdcm::DicomDirPatient *p2 = dcmdir->NewPatient(); - p2->SetValEntry("patientTWO",0x0010, 0x0010); + p2->SetEntryString("patientTWO",0x0010, 0x0010); // fill here other patient characteristics gdcm::DicomDirStudy *s21 = p2->NewStudy(); - s21->SetValEntry("StudyDescrTwo.One",0x0008, 0x1030); + s21->SetEntryString("StudyDescrTwo.One",0x0008, 0x1030); // fill here other Study characteristics gdcm::DicomDirSerie *s211 = s21->NewSerie(); - s111->SetValEntry("01-01-211", 0x0008, 0x0021); + s111->SetEntryString("01-01-211", 0x0008, 0x0021); // fill here other Serie characteristics gdcm::DicomDirImage *s2111 = s211->NewImage(); - s2111->SetValEntry("imageFileName2111",0x0004,0x1500); + s2111->SetEntryString("imageFileName2111",0x0004,0x1500); // fill here other Image characteristics gdcm::DicomDirImage *s2112 = s211->NewImage(); - s2112->SetValEntry("imageFileName1122",0x0004,0x1500); + s2112->SetEntryString("imageFileName1122",0x0004,0x1500); // fill here other Image characteristics // Create patient TREE // ------------------- gdcm::DicomDirPatient *p3 = dcmdir->NewPatient(); - p3->SetValEntry("patientTHREE",0x0010, 0x0010); + p3->SetEntryString("patientTHREE",0x0010, 0x0010); // fill here other Patient characteristics // Add a new Serie/Image for a Patient's Study created a long time ago // ------------------------------------------------------------------- gdcm::DicomDirSerie *s131 = s13->NewSerie(); - s111->SetValEntry("01-01-131", 0x0008, 0x0021); + s111->SetEntryString("01-01-131", 0x0008, 0x0021); // fill here other Serie characteristics gdcm::DicomDirImage *s1311 = s131->NewImage(); - s1311->SetValEntry("imageFileName1311",0x0004,0x1500); + s1311->SetEntryString("imageFileName1311",0x0004,0x1500); // fill here other Image characteristics // Print @@ -218,16 +218,16 @@ int TestBuildUpDicomDir(int argc, char *argv[]) std::string valueStuff; for (;;) // exit on 'break' { - if ( p1->GetEntryValue(0x0010, 0x0010) != "patientONE" ) + if ( p1->GetEntryString(0x0010, 0x0010) != "patientONE" ) { std::cout << "0x0010,0x0010 [" - << p1->GetEntryValue(0x0010, 0x0010) + << p1->GetEntryString(0x0010, 0x0010) << "]" << std::endl; errorFound = true; break; } std::cout << "Patient : [" - << p1->GetEntryValue(0x0010, 0x0010) + << p1->GetEntryString(0x0010, 0x0010) << "]" << std::endl; if ( !(s11 = p1->GetFirstStudy()) ) @@ -236,7 +236,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) errorFound = true; break; } - valueStuff = s11->GetEntryValue(0x0008, 0x1030); + valueStuff = s11->GetEntryString(0x0008, 0x1030); if ( valueStuff.find("StudyDescrOne.One_") >= valueStuff.length() ) { std::cout << "1 : 0x0008,0x1030 [" @@ -249,11 +249,11 @@ int TestBuildUpDicomDir(int argc, char *argv[]) << valueStuff << "]" << std::endl; - valueStuff = s11->GetEntryValue(0x0008, 0x1060); + valueStuff = s11->GetEntryString(0x0008, 0x1060); if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Mabuse") ) { std::cout << "2 : 0x0008,0x1060 [" - << s11->GetEntryValue(0x0008,0x1060) + << s11->GetEntryString(0x0008,0x1060) << "]" << std::endl; errorFound = true; break; @@ -266,30 +266,30 @@ int TestBuildUpDicomDir(int argc, char *argv[]) errorFound = true; break; } - if ( gdcm::Util::DicomStringEqual(s12->GetEntryValue(0x0008, + if ( gdcm::Util::DicomStringEqual(s12->GetEntryString(0x0008, 0x1030),"StudyDescrOne.Two " )) { std::cout << "3 0x0008,0x1030 [" - << s12->GetEntryValue(0x0008,0x1030) + << s12->GetEntryString(0x0008,0x1030) << "]" << std::endl; errorFound = true; break; } std::cout << "Study Descr : [" - << s12->GetEntryValue(0x0008,0x1030) + << s12->GetEntryString(0x0008,0x1030) << "]" << std::endl; - if ( gdcm::Util::DicomStringEqual(s12->GetEntryValue(0x0008, + if ( gdcm::Util::DicomStringEqual(s12->GetEntryString(0x0008, 0x1060),"Dr Zorglub " )) { std::cout << "4 0x0008,0x1060 [" - << s12->GetEntryValue(0x0008,0x1060) + << s12->GetEntryString(0x0008,0x1060) << "]" << std::endl; errorFound = true; break; } std::cout << "Pysician : [" - << s12->GetEntryValue(0x0008,0x1060) + << s12->GetEntryString(0x0008,0x1060) << "]" << std::endl; if ( (s13 = p1->GetNextStudy()) == 0 ) @@ -297,7 +297,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) std::cout << "Study StudyDescrOne.Tree missing" << std::endl; break; } - if ( s13->GetEntryValue(0x0008, 0x1030) != "StudyDescrOne.Tree" ) + if ( s13->GetEntryString(0x0008, 0x1030) != "StudyDescrOne.Tree" ) { errorFound = true; break; @@ -306,7 +306,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) << valueStuff << "]" << std::endl; - valueStuff = s13->GetEntryValue(0x0008, 0x1060); + valueStuff = s13->GetEntryString(0x0008, 0x1060); if (!gdcm::Util::DicomStringEqual(valueStuff, "Dr Follamour") ) { std::cout << "5 0x0008,0x1060 [" @@ -326,7 +326,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) break; } - valueStuff = s111->GetEntryValue(0x0008, 0x0021); + valueStuff = s111->GetEntryString(0x0008, 0x0021); if (!gdcm::Util::DicomStringEqual(valueStuff, "01-01-131") ) { std::cout << "6 0x0008,0x0021 [" @@ -346,7 +346,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) break; } /* - if ( s1111->GetEntryValue(0x0004,0x1500) != "imageFileName1111 " ) + if ( s1111->GetEntryString(0x0004,0x1500) != "imageFileName1111 " ) { errorFound = true; break; @@ -359,7 +359,7 @@ int TestBuildUpDicomDir(int argc, char *argv[]) break; } /* - if ( s1112->GetEntryValue(0x0004,0x1500) != "imageFileName1112 " ) + if ( s1112->GetEntryString(0x0004,0x1500) != "imageFileName1112 " ) { errorFound = true; break; diff --git a/Testing/TestCopyDicom.cxx b/Testing/TestCopyDicom.cxx index c0c5164c..212e0d02 100644 --- a/Testing/TestCopyDicom.cxx +++ b/Testing/TestCopyDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyDicom.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 13:39:57 $ - Version: $Revision: 1.41 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.42 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,8 +17,7 @@ =========================================================================*/ #include "gdcmFile.h" #include "gdcmFileHelper.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" //Generated file: #include "gdcmDataImages.h" @@ -55,17 +54,11 @@ int CopyDicom(std::string const &filename, gdcm::DocEntry *d=originalH->GetFirstEntry(); while(d) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) - { - copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copyH->InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + if ( gdcm::DataEntry *de = dynamic_cast(d) ) + { + copyH->InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { @@ -82,7 +75,7 @@ int CopyDicom(std::string const &filename, uint8_t *imageData = original->GetImageData(); // Useless to set the image data, because it's already made when - // copying the corresponding BinEntry that contains the pixel data + // copying the corresponding DataEntry that contains the pixel data copy->SetImageData(imageData, dataSize); //////////////// Step 3: diff --git a/Testing/TestCopyRescaleDicom.cxx b/Testing/TestCopyRescaleDicom.cxx index 3d25e33c..58491763 100644 --- a/Testing/TestCopyRescaleDicom.cxx +++ b/Testing/TestCopyRescaleDicom.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestCopyRescaleDicom.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 13:39:57 $ - Version: $Revision: 1.20 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,8 +17,7 @@ =========================================================================*/ #include "gdcmFile.h" #include "gdcmFileHelper.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" +#include "gdcmDataEntry.h" #include #include @@ -89,17 +88,11 @@ int CopyRescaleDicom(std::string const &filename, gdcm::DocEntry *d = originalF.GetFirstEntry(); while(d) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) - { - copyF.InsertBinEntry( b->GetBinArea(),b->GetLength(), - b->GetGroup(),b->GetElement(), - b->GetVR() ); - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) - { - copyF.InsertValEntry( v->GetValue(), - v->GetGroup(),v->GetElement(), - v->GetVR() ); + if ( gdcm::DataEntry *de = dynamic_cast(d) ) + { + copyF.InsertEntryBinArea( de->GetBinArea(),de->GetLength(), + de->GetGroup(),de->GetElement(), + de->GetVR() ); } else { @@ -121,10 +114,10 @@ int CopyRescaleDicom(std::string const &filename, if( bitsStored == "16" ) { std::cout << "Rescale..."; - copyF.InsertValEntry( "8", 0x0028, 0x0100); // Bits Allocated - copyF.InsertValEntry( "8", 0x0028, 0x0101); // Bits Stored - copyF.InsertValEntry( "7", 0x0028, 0x0102); // High Bit - copyF.InsertValEntry( "0", 0x0028, 0x0103); // Pixel Representation + copyF.InsertEntryString( "8", 0x0028, 0x0100); // Bits Allocated + copyF.InsertEntryString( "8", 0x0028, 0x0101); // Bits Stored + copyF.InsertEntryString( "7", 0x0028, 0x0102); // High Bit + copyF.InsertEntryString( "0", 0x0028, 0x0103); // Pixel Representation // We assume the value were from 0 to uint16_t max rescaleSize = dataSize / 2; diff --git a/Testing/TestDataEntry.cxx b/Testing/TestDataEntry.cxx new file mode 100644 index 00000000..b9b2e542 --- /dev/null +++ b/Testing/TestDataEntry.cxx @@ -0,0 +1,495 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: TestDataEntry.cxx,v $ + Language: C++ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "gdcmDictEntry.h" +#include "gdcmDataEntry.h" + +// =============================================================== + +char data[]="1\\2\\3\\4\\5"; +char fdata[]="1.1\\2.2\\3.3\\4.4\\5.5"; + +short svalue[]={1,2,3,4,5}; +long lvalue[]={1,2,3,4,5}; +float fvalue[]={1.1f,2.2f,3.3f,4.4f,5.5f}; +double dvalue[]={1.1,2.2,3.3,4.4,5.5}; + +unsigned long nbvalue = 5; + +/** + * \brief Test the DataEntry object + */ +int TestDataEntry(int argc, char *argv[]) +{ + unsigned int error = 0; + gdcm::DictEntry *dict; + gdcm::DataEntry *entry; + + //------------------------------------------------------------------ + dict = new gdcm::DictEntry(0x0000,0x0000); + entry = new gdcm::DataEntry(dict); + dict->SetVR("US"); + + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + + entry->SetString("1"); + std::cout << "1: "; + entry->Print(std::cout); + std::cout << std::endl; + if( entry->GetValueCount() != 1 ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + + entry->SetString("1\\2"); + std::cout << "2: "; + entry->Print(std::cout); + std::cout << std::endl; + if( entry->GetValueCount() != 2 ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + + entry->SetString(""); + std::cout << "3: "; + entry->Print(std::cout); + std::cout << std::endl; + if( entry->GetValueCount() != 0 ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + + std::cout << std::endl; + delete dict; + delete entry; + + //------------------------------------------------------------------ + dict = new gdcm::DictEntry(0x0000,0x0000); + entry = new gdcm::DataEntry(dict); + dict->SetVR("LT"); + + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + entry->SetString(data); + entry->Print(std::cout); + std::cout << std::endl; + + if( entry->GetLength() != strlen(data) + strlen(data)%2 ) + { + std::cout << " Failed" << std::endl + << " Size of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( memcmp(entry->GetBinArea(),data,entry->GetLength()) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of bin area is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( memcmp(entry->GetString().c_str(),data,entry->GetLength()) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != svalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl + << " Found " << entry->GetValue(i) << " - Must be " << svalue[i] << std::endl; + delete dict; + delete entry; + return(1); + } + } + + std::cout << std::endl; + delete dict; + delete entry; + + //------------------------------------------------------------------ + dict = new gdcm::DictEntry(0x0000,0x0000); + entry = new gdcm::DataEntry(dict); + dict->SetVR("US"); + + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + entry->SetString(data); + std::cout << "1: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( entry->GetLength() != nbvalue*sizeof(uint16_t) ) + { + std::cout << " Failed" << std::endl + << " BinArea length is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != svalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + entry->SetLength(nbvalue*sizeof(uint16_t)); + entry->SetBinArea((uint8_t *)svalue,false); + std::cout << "2: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != svalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + std::cout << std::endl; + delete dict; + delete entry; + + //------------------------------------------------------------------ + dict = new gdcm::DictEntry(0x0000,0x0000); + entry = new gdcm::DataEntry(dict); + dict->SetVR("UL"); + + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + entry->SetString(data); + std::cout << "1: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( entry->GetLength() != nbvalue*sizeof(uint32_t) ) + { + std::cout << " Failed" << std::endl + << " BinArea length is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + std::cout<<"#"<GetString()<<"#"<<" / "<<"#"<GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != lvalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + entry->SetLength(nbvalue*sizeof(uint32_t)); + entry->SetBinArea((uint8_t *)lvalue,false); + std::cout << "2: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( memcmp(entry->GetString().c_str(),data,strlen(data)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != lvalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + std::cout << std::endl; + delete dict; + delete entry; + + //------------------------------------------------------------------ + dict = new gdcm::DictEntry(0x0000,0x0000); + entry = new gdcm::DataEntry(dict); + dict->SetVR("FL"); + + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + entry->SetString(fdata); + std::cout << "1: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( entry->GetLength() != nbvalue*sizeof(float) ) + { + std::cout << " Failed" << std::endl + << " BinArea length is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != fvalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + entry->SetLength(nbvalue*sizeof(float)); + entry->SetBinArea((uint8_t *)fvalue,false); + std::cout << "2: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != fvalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + std::cout << std::endl; + delete dict; + delete entry; + + //------------------------------------------------------------------ + dict = new gdcm::DictEntry(0x0000,0x0000); + entry = new gdcm::DataEntry(dict); + dict->SetVR("FD"); + + std::cout << "Test for VR = " << dict->GetVR() << "..." << std::endl; + entry->SetString(fdata); + std::cout << "1: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( entry->GetLength() != nbvalue*sizeof(double) ) + { + std::cout << " Failed" << std::endl + << " BinArea length is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != dvalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + entry->SetLength(nbvalue*sizeof(double)); + entry->SetBinArea((uint8_t *)dvalue,false); + std::cout << "2: "; + entry->Print(std::cout); + std::cout << std::endl; + + if( memcmp(entry->GetString().c_str(),fdata,strlen(fdata)) != 0 ) + { + std::cout << " Failed" << std::endl + << " Content of string is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + if( entry->GetValueCount() != nbvalue ) + { + std::cout << " Failed" << std::endl + << " Number of content values is incorrect" << std::endl; + delete dict; + delete entry; + return(1); + } + for(unsigned int i=0;iGetValueCount();i++) + { + if( entry->GetValue(i) != dvalue[i] ) + { + std::cout << " Failed" << std::endl + << " Content of entry's values is incorrect : id " << i << std::endl; + delete dict; + delete entry; + return(1); + } + } + + std::cout << std::endl; + delete dict; + delete entry; + + //------------------------------------------------------------------ + std::cout<(e1) || - !dynamic_cast(e2) ) + if ( !dynamic_cast(e1) || + !dynamic_cast(e2) ) continue; // a value is read as GDCM_UNFOUND - if ( ((gdcm::ValEntry*)e1)->GetValue() == gdcm::GDCM_UNFOUND ) + if ( ((gdcm::DataEntry *)e1)->GetString() == gdcm::GDCM_UNFOUND ) { std::cout << "for gdcm source DicomDir : element (" << std::hex << e1->GetGroup() << "," <GetElement() @@ -63,16 +63,16 @@ int CompareSQItem(gdcm::SQItem *pa1, gdcm::SQItem *pa2 ) } // values differ in source file and destination file - if ( ((gdcm::ValEntry*)e1)->GetValue() != - ((gdcm::ValEntry*)e2)->GetValue() ) + if ( ((gdcm::DataEntry *)e1)->GetString() != + ((gdcm::DataEntry *)e2)->GetString() ) { // serious trouble : values differ in source and destination file std::cout << "for gdcm DicomDir element (" << std::hex << e2->GetGroup() << "," <GetElement() << ") values differ [" - << ((gdcm::ValEntry*)e1)->GetValue() << "] != [" - << ((gdcm::ValEntry*)e2)->GetValue() << "]" + << ((gdcm::DataEntry *)e1)->GetString() << "] != [" + << ((gdcm::DataEntry *)e2)->GetString() << "]" << std::endl; return 1; } @@ -144,26 +144,26 @@ int TestDicomDir(int argc, char *argv[]) pa1 = dicomdir->GetFirstPatient(); while ( pa1 ) { // we process all the PATIENT of this DICOMDIR - std::cout << pa1->GetEntryValue(0x0010, 0x0010) << std::endl; // Patient's Name + std::cout << pa1->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name st1 = pa1->GetFirstStudy(); while ( st1 ) { // we process all the STUDY of this patient - std::cout << "--- "<< st1->GetEntryValue(0x0008, 0x1030) // Study Description + std::cout << "--- "<< st1->GetEntryString(0x0008, 0x1030) // Study Description << std::endl; - std::cout << " Stud.ID:[" << st1->GetEntryValue(0x0020, 0x0010) // Study ID + std::cout << " Stud.ID:[" << st1->GetEntryString(0x0020, 0x0010) // Study ID << "]"; se1 = st1->GetFirstSerie(); while ( se1 ) { // we process all the SERIES of this study - std::cout << "--- --- "<< se1->GetEntryValue(0x0008, 0x103e) << std::endl; // Serie Description - std::cout << " Ser.nb:[" << se1->GetEntryValue(0x0020, 0x0011); // Series number - std::cout << "] Mod.:[" << se1->GetEntryValue(0x0008, 0x0060) << "]"; // Modality + std::cout << "--- --- "<< se1->GetEntryString(0x0008, 0x103e) << std::endl; // Serie Description + std::cout << " Ser.nb:[" << se1->GetEntryString(0x0020, 0x0011); // Series number + std::cout << "] Mod.:[" << se1->GetEntryString(0x0008, 0x0060) << "]"; // Modality im1 = se1->GetFirstImage(); while ( im1 ) { // we process all the IMAGE of this serie - std::cout << "--- --- --- "<< im1->GetEntryValue(0x0004, 0x1500) << std::endl; // File name + std::cout << "--- --- --- "<< im1->GetEntryString(0x0004, 0x1500) << std::endl; // File name im1 = se1->GetNextImage(); } se1 = st1->GetNextSerie(); @@ -228,7 +228,7 @@ int TestDicomDir(int argc, char *argv[]) } // just to allow human reader to be sure ... - std::cout << pa2->GetEntryValue(0x0010, 0x0010) + std::cout << pa2->GetEntryString(0x0010, 0x0010) << std::endl; // Patient's Name st1 = pa1->GetFirstStudy(); @@ -244,10 +244,10 @@ int TestDicomDir(int argc, char *argv[]) } // just to allow human reader to be sure ... - std::cout << "--- "<< st2->GetEntryValue(0x0008, 0x1030); + std::cout << "--- "<< st2->GetEntryString(0x0008, 0x1030); // << std::endl; // Study Description std::cout << " Stud.ID:[" - << st2->GetEntryValue(0x0020, 0x0010) + << st2->GetEntryString(0x0020, 0x0010) << "]" << std::endl; // Study ID se1 = st1->GetFirstSerie(); @@ -257,9 +257,9 @@ int TestDicomDir(int argc, char *argv[]) { // we process all the SERIE of this study if ( CompareSQItem(se2,se1) == 1 ) return 1; - std::cout << "--- --- " << se2->GetEntryValue(0x0008, 0x103e); // Serie Description - std::cout << " Ser.nb:["<< se2->GetEntryValue(0x0020, 0x0011); // Series number - std::cout << "] Mod.:[" << se2->GetEntryValue(0x0008, 0x0060) << "]" << std::endl; // Modality + std::cout << "--- --- " << se2->GetEntryString(0x0008, 0x103e); // Serie Description + std::cout << " Ser.nb:["<< se2->GetEntryString(0x0020, 0x0011); // Series number + std::cout << "] Mod.:[" << se2->GetEntryString(0x0008, 0x0060) << "]" << std::endl; // Modality im1 = se1->GetFirstImage(); im2 = se2->GetFirstImage(); diff --git a/Testing/TestFileAccessors.cxx b/Testing/TestFileAccessors.cxx index 8be0e831..a6251ca5 100644 --- a/Testing/TestFileAccessors.cxx +++ b/Testing/TestFileAccessors.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestFileAccessors.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 13:39:57 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -25,20 +25,31 @@ #include "gdcmFileHelper.h" #include "gdcmUtil.h" #include "gdcmCommon.h" -#include "gdcmBinEntry.h" #include "gdcmDocEntry.h" #include "gdcmDocEntrySet.h" #include "gdcmDocument.h" #include "gdcmElementSet.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" #include //Generated file: #include "gdcmDataImages.h" +#define TestMethodMacro(mode,obj,name) \ + try \ + { \ + std::cout << " " << #name << "() : " << mode << obj->name() << std::endl; \ + } \ + catch(...) \ + { \ + std::cout << " --> Can't access to the '" << #name << "' method !" << std::endl; \ + delete f; \ + return 1; \ + } + + int TestFileAccessors(int, char *[]) { int i = 0; @@ -51,6 +62,7 @@ int TestFileAccessors(int, char *[]) filename += "/"; //doh! filename += gdcmDataImages[i]; + std::cout << "Begin with " << filename << std::endl; gdcm::File *f= new gdcm::File( ); f->SetFileName( filename ); f->Load( ); @@ -59,44 +71,44 @@ int TestFileAccessors(int, char *[]) // We just want to be sure no accessor seg faults on any image ... // And this will improve test coverage ;-) - std::cout << "GetSwapCode()" << f->GetSwapCode() << std::endl; - std::cout << "GetImageNumber()" << f->GetImageNumber() << std::endl; - std::cout << "GetModality()" << f->GetModality() << std::endl; - std::cout << "GetXSize()" << f->GetXSize() << std::endl; - std::cout << "GetYSize()" << f->GetYSize() << std::endl; - std::cout << "GetZSize()" << f->GetZSize() << std::endl; - std::cout << "GetXSpacing()" << f->GetXSpacing() << std::endl; - std::cout << "GetYSpacing()" << f->GetYSpacing() << std::endl; - std::cout << "GetZSpacing()" << f->GetZSpacing() << std::endl; - std::cout << "GetXOrigin()" << f->GetXOrigin() << std::endl; - std::cout << "GetYOrigin()" << f->GetYOrigin() << std::endl; - std::cout << "GetZOrigin()" << f->GetZOrigin() << std::endl; - std::cout << "GetBitsStored()" << f->GetBitsStored() << std::endl; - std::cout << "GetBitsAllocated()" << f->GetBitsAllocated() << std::endl; - std::cout << "GetHighBitPosition()" << f->GetHighBitPosition() << std::endl; - std::cout << "GetSamplesPerPixel()" << f->GetSamplesPerPixel() << std::endl; - std::cout << "GetPlanarConfiguration()" << f->GetPlanarConfiguration() << std::endl; - std::cout << "GetPixelSize()" << f->GetPixelSize() << std::endl; - std::cout << "GetPixelType()" << f->GetPixelType() << std::endl; - std::cout << "GetLUTNbits()" << f->GetLUTNbits() << std::endl; - std::cout << "GetRescaleIntercept()" << f->GetRescaleIntercept() << std::endl; - std::cout << "GetRescaleSlope()" << f->GetRescaleSlope() << std::endl; - std::cout << "GetGrPixel()" << std::hex << f->GetGrPixel() << std::endl; - std::cout << "GetNumPixel()" << std::hex << f->GetNumPixel() << std::endl; - std::cout << "GetPixelOffset()" << f->GetPixelOffset() << std::endl; - - std::cout << "GetPixelAreaLength()" << f->GetPixelAreaLength()<< std::endl; - std::cout << "GetNumberOfScalarComponents()" << f->GetNumberOfScalarComponents()<< std::endl; - std::cout << "GetNumberOfScalarComponentsRaw()" << f->GetNumberOfScalarComponentsRaw()<< std::endl; - std::cout << "IsSignedPixelData()" << f->IsSignedPixelData()<< std::endl; - std::cout << "IsMonochrome()" << f->IsMonochrome() << std::endl; - std::cout << "IsPaletteColor()" << f->IsPaletteColor() << std::endl; - std::cout << "IsYBRFull()" << f->IsYBRFull() << std::endl; - std::cout << "HasLut() " << f->HasLUT() << std::endl; - std::cout << "GetTransferSyntax()" << f->GetTransferSyntax() << std::endl; - std::cout << "GetTransferSyntaxName()" << f->GetTransferSyntaxName() << std::endl; - std::cout << "GetFileType()" << f->GetFileType() << std::endl; - std::cout << "GetFileName()" << f->GetFileName() << std::endl; + TestMethodMacro(std::dec,f,GetSwapCode) + TestMethodMacro(std::dec,f,GetImageNumber) + TestMethodMacro(std::dec,f,GetModality) + TestMethodMacro(std::dec,f,GetXSize) + TestMethodMacro(std::dec,f,GetYSize) + TestMethodMacro(std::dec,f,GetZSize) + TestMethodMacro(std::dec,f,GetXSpacing) + TestMethodMacro(std::dec,f,GetYSpacing) + TestMethodMacro(std::dec,f,GetZSpacing) + TestMethodMacro(std::dec,f,GetXOrigin) + TestMethodMacro(std::dec,f,GetYOrigin) + TestMethodMacro(std::dec,f,GetZOrigin) + TestMethodMacro(std::dec,f,GetBitsStored) + TestMethodMacro(std::dec,f,GetBitsAllocated) + TestMethodMacro(std::dec,f,GetHighBitPosition) + TestMethodMacro(std::dec,f,GetSamplesPerPixel) + TestMethodMacro(std::dec,f,GetPlanarConfiguration) + TestMethodMacro(std::dec,f,GetPixelSize) + TestMethodMacro(std::dec,f,GetPixelType) + TestMethodMacro(std::dec,f,GetLUTNbits) + TestMethodMacro(std::dec,f,GetRescaleIntercept) + TestMethodMacro(std::dec,f,GetRescaleSlope) + TestMethodMacro(std::hex,f,GetGrPixel) + TestMethodMacro(std::hex,f,GetNumPixel) + TestMethodMacro(std::dec,f,GetPixelOffset) + + TestMethodMacro(std::dec,f,GetPixelAreaLength) + TestMethodMacro(std::dec,f,GetNumberOfScalarComponents) + TestMethodMacro(std::dec,f,GetNumberOfScalarComponentsRaw) + TestMethodMacro(std::dec,f,IsSignedPixelData) + TestMethodMacro(std::dec,f,IsMonochrome) + TestMethodMacro(std::dec,f,IsPaletteColor) + TestMethodMacro(std::dec,f,IsYBRFull) + TestMethodMacro(std::dec,f,HasLUT) + TestMethodMacro(std::dec,f,GetTransferSyntax) + TestMethodMacro(std::dec,f,GetTransferSyntaxName) + TestMethodMacro(std::dec,f,GetFileType) + TestMethodMacro(std::dec,f,GetFileName) f->GetImageOrientationPatient( iop ); for (int j=0; j<6; j++) @@ -109,16 +121,12 @@ int TestFileAccessors(int, char *[]) gdcm::FileHelper *fh= new gdcm::FileHelper( f ); - // TODO : Newbe user would appreciate any comment ! - - std::cout << "GetImageDataSize()" << fh->GetImageDataSize() << std::endl; - std::cout << "GetImageDataRawSize()" << fh->GetImageDataRawSize() << std::endl; - // User Data - std::cout << "GetRGBDataSize()" << fh->GetRGBDataSize() << std::endl; - std::cout << "GetRawDataSize()" << fh->GetRawDataSize() << std::endl; - std::cout << "GetUserDataSize()" << fh->GetUserDataSize() << std::endl; - - std::cout << "GetWriteType()" << fh->GetWriteType() << std::endl; + TestMethodMacro(std::dec,fh,GetImageDataSize) + TestMethodMacro(std::dec,fh,GetImageDataRawSize) + TestMethodMacro(std::dec,fh,GetRGBDataSize) + TestMethodMacro(std::dec,fh,GetRawDataSize) + TestMethodMacro(std::dec,fh,GetUserDataSize) + TestMethodMacro(std::dec,fh,GetWriteType) delete fh; } @@ -131,6 +139,7 @@ int TestFileAccessors(int, char *[]) } delete f; + std::cout << "End with " << filename << std::endl; i++; } return 0; diff --git a/Testing/TestImageSet.cxx b/Testing/TestImageSet.cxx index 7bf62230..05e6c66f 100644 --- a/Testing/TestImageSet.cxx +++ b/Testing/TestImageSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestImageSet.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 13:39:57 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,7 +24,7 @@ */ #include "gdcmFile.h" #include "gdcmFileHelper.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include "gdcmUtil.h" #include "gdcmDebug.h" @@ -42,7 +42,7 @@ int CompareImages(FileList &list, bool sameSerie, bool sameStudy) if( sameSerie ) sameStudy = true; - gdcm::ValEntry *entry; + gdcm::DataEntry *entry; std::map instUID; std::map mediaUID; std::map serieUID; @@ -52,33 +52,33 @@ int CompareImages(FileList &list, bool sameSerie, bool sameStudy) for(it=list.begin();it!=list.end();++it) { // SOP Instance UID - entry=(*it)->GetValEntry(0x0008, 0x0018); + entry=(*it)->GetDataEntry(0x0008, 0x0018); if( entry ) - if( instUID.find(entry->GetValue())!=instUID.end() ) - instUID[entry->GetValue()]++; + if( instUID.find(entry->GetString())!=instUID.end() ) + instUID[entry->GetString()]++; else - instUID[entry->GetValue()]=1; + instUID[entry->GetString()]=1; // Media Storage SOP Instance UID - entry=(*it)->GetValEntry(0x0002,0x0003); + entry=(*it)->GetDataEntry(0x0002,0x0003); if( entry ) - if( mediaUID.find(entry->GetValue())!=mediaUID.end() ) - mediaUID[entry->GetValue()]++; + if( mediaUID.find(entry->GetString())!=mediaUID.end() ) + mediaUID[entry->GetString()]++; else - mediaUID[entry->GetValue()]=1; + mediaUID[entry->GetString()]=1; // Series Instance UID - entry=(*it)->GetValEntry(0x0020,0x000e); + entry=(*it)->GetDataEntry(0x0020,0x000e); if( entry ) - if( serieUID.find(entry->GetValue())!=serieUID.end() ) - serieUID[entry->GetValue()]++; + if( serieUID.find(entry->GetString())!=serieUID.end() ) + serieUID[entry->GetString()]++; else - serieUID[entry->GetValue()]=1; + serieUID[entry->GetString()]=1; // Study Instance UID - entry=(*it)->GetValEntry(0x0020,0x000d); + entry=(*it)->GetDataEntry(0x0020,0x000d); if( entry ) - if( studyUID.find(entry->GetValue())!=studyUID.end() ) - studyUID[entry->GetValue()]++; + if( studyUID.find(entry->GetString())!=studyUID.end() ) + studyUID[entry->GetString()]++; else - studyUID[entry->GetValue()]=1; + studyUID[entry->GetString()]=1; } if( sameSerie ) @@ -152,19 +152,19 @@ gdcm::File *WriteImage(gdcm::File *file, const std::string &fileName) std::ostringstream str; // Set the image size - file->InsertValEntry("256",0x0028,0x0011); // Columns - file->InsertValEntry("256",0x0028,0x0010); // Rows + file->InsertEntryString("256",0x0028,0x0011); // Columns + file->InsertEntryString("256",0x0028,0x0010); // Rows // Set the pixel type - file->InsertValEntry("8",0x0028,0x0100); // Bits Allocated - file->InsertValEntry("8",0x0028,0x0101); // Bits Stored - file->InsertValEntry("7",0x0028,0x0102); // High Bit + file->InsertEntryString("8",0x0028,0x0100); // Bits Allocated + file->InsertEntryString("8",0x0028,0x0101); // Bits Stored + file->InsertEntryString("7",0x0028,0x0102); // High Bit // Set the pixel representation - file->InsertValEntry("0",0x0028,0x0103); // Pixel Representation + file->InsertEntryString("0",0x0028,0x0103); // Pixel Representation // Set the samples per pixel - file->InsertValEntry("1",0x0028,0x0002); // Samples per Pixel + file->InsertEntryString("1",0x0028,0x0002); // Samples per Pixel // The so called 'prepared image', built ex nihilo just before, // has NO Pixel Element yet. @@ -252,10 +252,10 @@ int TestImageSet(int argc, char *argv[]) // It's up to the user to initialize Serie UID and Study UID // Study Instance UID studyUID = gdcm::Util::CreateUniqueUID(); - file->InsertValEntry(studyUID, 0x0020, 0x000d); + file->InsertEntryString(studyUID, 0x0020, 0x000d); // Series Instance UID serieUID = gdcm::Util::CreateUniqueUID(); - file->InsertValEntry(serieUID, 0x0020, 0x000e); + file->InsertEntryString(serieUID, 0x0020, 0x000e); newFile = WriteImage(file, fileName.str()); if( !newFile ) @@ -287,8 +287,8 @@ int TestImageSet(int argc, char *argv[]) std::ostringstream fileName; fileName << "FileSeq" << i << ".dcm"; file = new gdcm::File(); - file->InsertValEntry(studyUID, 0x0020, 0x000d); - file->InsertValEntry(serieUID, 0x0020, 0x000e); + file->InsertEntryString(studyUID, 0x0020, 0x000d); + file->InsertEntryString(serieUID, 0x0020, 0x000e); newFile = WriteImage(file, fileName.str()); if( !newFile ) @@ -319,9 +319,9 @@ int TestImageSet(int argc, char *argv[]) std::ostringstream fileName; fileName << "FileSeq" << i << ".dcm"; file = new gdcm::File(); - file->InsertValEntry(studyUID, 0x0020, 0x000d); + file->InsertEntryString(studyUID, 0x0020, 0x000d); serieUID = gdcm::Util::CreateUniqueUID(); - file->InsertValEntry(serieUID, 0x0020, 0x000e); + file->InsertEntryString(serieUID, 0x0020, 0x000e); newFile = WriteImage(file, fileName.str()); if( !newFile ) { diff --git a/Testing/TestLoadAllDocumentsNoPrivNoSeq.cxx b/Testing/TestLoadAllDocumentsNoPrivNoSeq.cxx index b10a018a..42a337ae 100644 --- a/Testing/TestLoadAllDocumentsNoPrivNoSeq.cxx +++ b/Testing/TestLoadAllDocumentsNoPrivNoSeq.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestLoadAllDocumentsNoPrivNoSeq.cxx,v $ Language: C++ - Date: $Date: 2005/09/22 14:42:37 $ - Version: $Revision: 1.2 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.3 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,15 +24,14 @@ #include "gdcmFile.h" #include "gdcmUtil.h" #include "gdcmCommon.h" -#include "gdcmBinEntry.h" #include "gdcmDocEntry.h" #include "gdcmDocEntrySet.h" #include "gdcmDocument.h" #include "gdcmElementSet.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" #include "gdcmOrientation.h" + #include #include #include // for std::ios::left, ... diff --git a/Testing/TestMakeIcon.cxx b/Testing/TestMakeIcon.cxx index e78c37f1..1ff478a8 100644 --- a/Testing/TestMakeIcon.cxx +++ b/Testing/TestMakeIcon.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestMakeIcon.cxx,v $ Language: C++ - Date: $Date: 2005/07/21 14:05:09 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -20,10 +20,9 @@ #include "gdcmCommon.h" #include "gdcmFile.h" #include "gdcmFileHelper.h" +#include "gdcmDataEntry.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" // 0088 0200 SQ 1 Icon Image Sequence @@ -73,16 +72,16 @@ int TestMakeIcon (int argc, char *argv[]) uint16_t binVal[3]={0x52f7,0xf358,0xad9b}; - sqi->InsertValEntry( "MONOCHROME2", 0x0028,0x0004); - sqi->InsertValEntry( "128", 0x0028,0x0010); - sqi->InsertValEntry( "8", 0x0028,0x0100); - sqi->InsertValEntry( "8", 0x0028,0x0101); - sqi->InsertValEntry( "7", 0x0028,0x0102); - sqi->InsertValEntry( "0", 0x0028,0x0103); - sqi->InsertBinEntry( (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW"); - sqi->InsertBinEntry( pixels, lgth, 0x7fe0,0x0010); + sqi->InsertEntryString( "MONOCHROME2", 0x0028,0x0004); + sqi->InsertEntryString( "128", 0x0028,0x0010); + sqi->InsertEntryString( "8", 0x0028,0x0100); + sqi->InsertEntryString( "8", 0x0028,0x0101); + sqi->InsertEntryString( "7", 0x0028,0x0102); + sqi->InsertEntryString( "0", 0x0028,0x0103); + sqi->InsertEntryBinArea( (uint8_t *)binVal, 3*2, 0x0005,0x0010,"OW"); + sqi->InsertEntryBinArea( pixels, lgth, 0x7fe0,0x0010); // just to see if it's stored a the right place - sqi->InsertValEntry( "128", 0x0028,0x0011); + sqi->InsertEntryString( "128", 0x0028,0x0011); fh->WriteDcmExplVR(output); @@ -119,19 +118,19 @@ int TestMakeIcon (int argc, char *argv[]) std::cout << "First Item found" << std::endl; // Test for entry 0028|0010 - if ( !sqi->GetValEntry(0x0028,0x0010) ) + if ( !sqi->GetDataEntry(0x0028,0x0010) ) { - std::cout << "ValEntry 0028|0010 not found" << std::endl + std::cout << "GetDataEntry 0028|0010 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->ValEntry 0028|0010 found" << std::endl; - if ( sqi->GetValEntry(0x0028,0x0010)->GetValue() != "128" ) + std::cout << "First Item ->DataEntry 0028|0010 found" << std::endl; + if ( sqi->GetDataEntry(0x0028,0x0010)->GetString() != "128" ) { std::cout << "Value 0028|0010 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0028,0x0010)->GetValue() + << "Read : " << sqi->GetDataEntry(0x0028,0x0010)->GetString() << " - Expected : 128" << std::endl << " ... Failed" << std::endl; delete fh; @@ -140,19 +139,19 @@ int TestMakeIcon (int argc, char *argv[]) } // Test for entry 0028|0011 - if ( !sqi->GetValEntry(0x0028,0x0011) ) + if ( !sqi->GetDataEntry(0x0028,0x0011) ) { - std::cout << "ValEntry 0028|0011 not found" << std::endl + std::cout << "GetDataEntry 0028|0011 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->ValEntry 0028|0011 found" << std::endl; - if ( sqi->GetValEntry(0x0028,0x0011)->GetValue() != "128" ) + std::cout << "First Item ->DataEntry 0028|0011 found" << std::endl; + if ( sqi->GetDataEntry(0x0028,0x0011)->GetString() != "128" ) { std::cout << "Value 0028|0011 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0028,0x0011)->GetValue() + << "Read : " << sqi->GetDataEntry(0x0028,0x0011)->GetString() << " - Expected : 128" << std::endl << " ... Failed" << std::endl; delete fh; @@ -161,19 +160,19 @@ int TestMakeIcon (int argc, char *argv[]) } // Test for entry 0028|0100 - if ( !sqi->GetValEntry(0x0028,0x0100) ) + if ( !sqi->GetDataEntry(0x0028,0x0100) ) { - std::cout << "ValEntry 0028|0100 not found" << std::endl + std::cout << "GetDataEntry 0028|0100 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->ValEntry 0028|0100 found" << std::endl; - if ( sqi->GetValEntry(0x0028,0x0100)->GetValue() != "8" ) + std::cout << "First Item ->DataEntry 0028|0100 found" << std::endl; + if ( sqi->GetDataEntry(0x0028,0x0100)->GetString() != "8" ) { std::cout << "Value 0028|0100 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0028,0x0100)->GetValue() + << "Read : " << sqi->GetDataEntry(0x0028,0x0100)->GetString() << " - Expected : 8" << std::endl << " ... Failed" << std::endl; delete fh; @@ -182,19 +181,19 @@ int TestMakeIcon (int argc, char *argv[]) } // Test for entry 0028|0101 - if ( !sqi->GetValEntry(0x0028,0x0101) ) + if ( !sqi->GetDataEntry(0x0028,0x0101) ) { - std::cout << "ValEntry 0028|0101 not found" << std::endl + std::cout << "GetDataEntry 0028|0101 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->ValEntry 0028|0101 found" << std::endl; - if ( sqi->GetValEntry(0x0028,0x0101)->GetValue() != "8" ) + std::cout << "First Item ->DataEntry 0028|0101 found" << std::endl; + if ( sqi->GetDataEntry(0x0028,0x0101)->GetString() != "8" ) { std::cout << "Value 0028|0101 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0028,0x0101)->GetValue() + << "Read : " << sqi->GetDataEntry(0x0028,0x0101)->GetString() << " - Expected : 8" << std::endl << " ... Failed" << std::endl; delete fh; @@ -203,19 +202,19 @@ int TestMakeIcon (int argc, char *argv[]) } // Test for entry 0028|0102 - if ( !sqi->GetValEntry(0x0028,0x0102) ) + if ( !sqi->GetDataEntry(0x0028,0x0102) ) { - std::cout << "ValEntry 0028|0102 not found" << std::endl + std::cout << "DataEntry 0028|0102 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->ValEntry 0028|0102 found" << std::endl; - if ( sqi->GetValEntry(0x0028,0x0102)->GetValue() != "7" ) + std::cout << "First Item ->DataEntry 0028|0102 found" << std::endl; + if ( sqi->GetDataEntry(0x0028,0x0102)->GetString() != "7" ) { std::cout << "Value 0028|0102 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0028,0x0102)->GetValue() + << "Read : " << sqi->GetDataEntry(0x0028,0x0102)->GetString() << " - Expected : 7" << std::endl << " ... Failed" << std::endl; delete fh; @@ -224,19 +223,19 @@ int TestMakeIcon (int argc, char *argv[]) } // Test for entry 0028|0103 - if ( !sqi->GetValEntry(0x0028,0x0103) ) + if ( !sqi->GetDataEntry(0x0028,0x0103) ) { - std::cout << "ValEntry 0028|0010 not found" << std::endl + std::cout << "GetDataEntry 0028|0010 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->ValEntry 0028|0103 found" << std::endl; - if ( sqi->GetValEntry(0x0028,0x0103)->GetValue() != "0" ) + std::cout << "First Item ->DataEntry 0028|0103 found" << std::endl; + if ( sqi->GetDataEntry(0x0028,0x0103)->GetString() != "0" ) { std::cout << "Value 0028|0103 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0028,0x0103)->GetValue() + << "Read : " << sqi->GetDataEntry(0x0028,0x0103)->GetString() << " - Expected : 0" << std::endl << " ... Failed" << std::endl; delete fh; @@ -245,19 +244,19 @@ int TestMakeIcon (int argc, char *argv[]) } // Test for entry 0005|0010 - if ( !sqi->GetBinEntry(0x0005,0x0010) ) + if ( !sqi->GetDataEntry(0x0005,0x0010) ) { - std::cout << "BinEntry 0005|0010 not found" << std::endl + std::cout << "GetDataEntry 0005|0010 not found" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "First Item ->BinEntry 0005|0010 found" << std::endl; - if( sqi->GetBinEntry(0x0005,0x0010)->GetLength() != 6 ) + std::cout << "First Item ->GetDataEntry 0005|0010 found" << std::endl; + if( sqi->GetDataEntry(0x0005,0x0010)->GetLength() != 6 ) { - std::cout << "BinEntry size 0005|0010 don't match" << std::endl - << "Read : " << sqi->GetValEntry(0x0005,0x0010)->GetLength() + std::cout << "GetDataEntry size 0005|0010 don't match" << std::endl + << "Read : " << sqi->GetDataEntry(0x0005,0x0010)->GetLength() << " - Expected : 6" << std::endl << " ... Failed" << std::endl; delete fh; @@ -265,17 +264,17 @@ int TestMakeIcon (int argc, char *argv[]) return 1; } - std::cout << "Length BinEntry 0005|0010 OK" << std::endl; + std::cout << "Length GetDataEntry 0005|0010 OK" << std::endl; - if( memcmp(sqi->GetBinEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 ) + if( memcmp(sqi->GetDataEntry(0x0005,0x0010)->GetBinArea(),binVal,6)!=0 ) { - std::cout << "Value 0005|0010 don't match (BinEntry)" << std::endl + std::cout << "Value 0005|0010 don't match (DataEntry)" << std::endl << " ... Failed" << std::endl; delete fh; delete f; return 1; } - std::cout << "Value BinEntry 0005|0010 OK" << std::endl; + std::cout << "Value DataEntry 0005|0010 OK" << std::endl; delete fh; delete f; diff --git a/Testing/TestPrintAllDocument.cxx b/Testing/TestPrintAllDocument.cxx index 26af718e..76215a24 100644 --- a/Testing/TestPrintAllDocument.cxx +++ b/Testing/TestPrintAllDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestPrintAllDocument.cxx,v $ Language: C++ - Date: $Date: 2005/10/01 19:39:15 $ - Version: $Revision: 1.8 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.9 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -24,14 +24,12 @@ #include "gdcmFile.h" #include "gdcmUtil.h" #include "gdcmCommon.h" -#include "gdcmBinEntry.h" #include "gdcmDocEntry.h" #include "gdcmDocEntrySet.h" #include "gdcmDocument.h" #include "gdcmElementSet.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" #include "gdcmOrientation.h" #include #include @@ -84,7 +82,7 @@ int TestPrintAllDocument(int, char *[]) std::cout << " Smpl.P.Pix.=" << f->GetSamplesPerPixel() << " Plan.Config.=" << f->GetPlanarConfiguration(); - photomInterp = f->GetEntryValue(0x0028,0x0004); + photomInterp = f->GetEntryString(0x0028,0x0004); std::cout << " Photom.Interp.=" << photomInterp; for (j=0; jGetEntryValue(0x0020,0x0037); + f->GetEntryString(0x0020,0x0037); if ( strImageOrientationPatient != gdcm::GDCM_UNFOUND ) { gdcm::Orientation o; diff --git a/Testing/TestReadWriteReadCompare.cxx b/Testing/TestReadWriteReadCompare.cxx index cadead8a..f6a2a7eb 100644 --- a/Testing/TestReadWriteReadCompare.cxx +++ b/Testing/TestReadWriteReadCompare.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestReadWriteReadCompare.cxx,v $ Language: C++ - Date: $Date: 2005/07/21 04:51:26 $ - Version: $Revision: 1.24 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.25 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -33,7 +33,8 @@ int CompareInternal(std::string const &filename, std::string const &output) file->Load (); if( !file->IsReadable() ) { - std::cerr << "Test::TestReadWriteReadCompare: Image not gdcm compatible:" + std::cout << "Failed" << std::endl + << "Test::TestReadWriteReadCompare: Image not gdcm compatible:" << filename << std::endl; delete file; return 1; @@ -59,10 +60,10 @@ int CompareInternal(std::string const &filename, std::string const &output) fileout->SetFileName( output ); fileout->Load(); // gdcm::FileHelper *reread = new gdcm::FileHelper( output ); // deprecated - + if( !fileout->IsReadable() ) { - std::cerr << "Failed" << std::endl + std::cout << "Failed" << std::endl << "Test::TestReadWriteReadCompare: Could not parse the newly " << "written image:" << filename << std::endl; delete file; @@ -144,7 +145,7 @@ int TestReadWriteReadCompare(int argc, char *argv[]) } else if( argc > 4 || argc == 2 ) { - std::cerr << "Please read the manual" << std::endl; + std::cout << "Please read the manual" << std::endl; } else { diff --git a/Testing/TestWriteSimple.cxx b/Testing/TestWriteSimple.cxx index 6958b8a3..1b508c76 100644 --- a/Testing/TestWriteSimple.cxx +++ b/Testing/TestWriteSimple.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: TestWriteSimple.cxx,v $ Language: C++ - Date: $Date: 2005/10/11 14:24:29 $ - Version: $Revision: 1.38 $ + Date: $Date: 2005/10/18 08:35:46 $ + Version: $Revision: 1.39 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -99,6 +99,8 @@ Image Images [] = { {0, 0, 1, 1, 8, 8, 0, 'i'} // to find the end }; +const unsigned int MAX_NUMBER_OF_DIFFERENCE = 10; + int WriteSimple(Image &img) { std::ostringstream fileName; @@ -114,16 +116,16 @@ int WriteSimple(Image &img) // Set the image size str.str(""); str << img.sizeX; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0011); // Columns + fileToBuild->InsertEntryString(str.str(),0x0028,0x0011); // Columns str.str(""); str << img.sizeY; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0010); // Rows + fileToBuild->InsertEntryString(str.str(),0x0028,0x0010); // Rows if(img.sizeZ>1) { str.str(""); str << img.sizeZ; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames + fileToBuild->InsertEntryString(str.str(),0x0028,0x0008); // Number of Frames } fileName << "-" << img.sizeX << "-" << img.sizeY << "-" << img.sizeZ; @@ -131,20 +133,20 @@ int WriteSimple(Image &img) // Set the pixel type str.str(""); str << img.componentSize; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated + fileToBuild->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated str.str(""); str << img.componentUse; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored + fileToBuild->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << ( img.componentSize - 1 ); - fileToBuild->InsertValEntry(str.str(),0x0028,0x0102); // High Bit + fileToBuild->InsertEntryString(str.str(),0x0028,0x0102); // High Bit // Set the pixel representation str.str(""); str << img.sign; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation + fileToBuild->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation fileName << "-" << img.componentSize; if(img.sign == 0) @@ -167,7 +169,7 @@ int WriteSimple(Image &img) // Set the samples per pixel str.str(""); str << img.components; - fileToBuild->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel + fileToBuild->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel // Step 2 : Create the output image std::cout << "2..."; @@ -236,7 +238,7 @@ int WriteSimple(Image &img) if( !fileH->Write(fileName.str()) ) { std::cout << "Failed for [" << fileName.str() << "]\n" - << " File in unwrittable\n"; + << " File is unwrittable\n"; delete fileH; delete fileToBuild; @@ -331,6 +333,23 @@ int WriteSimple(Image &img) { std::cout << "Failed" << std::endl << " Pixel differ (as expanded in memory)." << std::endl; + std::cout << " list of the first " << MAX_NUMBER_OF_DIFFERENCE + << " pixels differing (pos : test - ref) :" + << std::endl; + int i; + unsigned int j; + for(i=0, j=0;i -#include -#include // for std::ios_base, since does not exist on gcc/Solaris - -namespace gdcm -{ -//----------------------------------------------------------------------------- -// Constructor / Destructor -/** - * \brief Constructor from a given BinEntry - */ -BinEntry::BinEntry(DictEntry *e) - :ContentEntry(e) -{ - BinArea = 0; - SelfArea = true; -} - -/** - * \brief Constructor from a given BinEntry - * @param e Pointer to existing Doc entry - */ -BinEntry::BinEntry(DocEntry *e) - : ContentEntry(e->GetDictEntry()) -{ - Copy(e); - - BinArea = 0; - SelfArea = true; -} - -/** - * \brief Canonical destructor. - */ -BinEntry::~BinEntry() -{ - if (BinArea && SelfArea) - { - delete[] BinArea; - BinArea = 0; // let's be carefull ! - } -} - -//----------------------------------------------------------------------------- -// Public -/** - * \brief canonical Writer - * @param fp already open file pointer - * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) -*/ -void BinEntry::WriteContent(std::ofstream *fp, FileType filetype) -{ - DocEntry::WriteContent(fp, filetype); - uint8_t *binArea8 = BinArea; //safe notation - size_t lgr = GetLength(); - if (BinArea) // the binArea was *actually* loaded - { - - // The same operation should be done if we wanted - // to write image with Big Endian Transfer Syntax, - // while working on Little Endian Processor - // --> forget Big Endian Transfer Syntax writting! - // Next DICOM version will give it up ... - - // --> - // --> FIXME - // --> - // The stuff looks nice, but it's probably bugged, - // since troubles occur on big endian processors (SunSparc, Motorola) - // while reading the pixels of a - // gdcm-written Little-Endian 16 bits per pixel image - -#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) - - /// \todo FIXME : Right now, we only care of Pixels element - /// we should deal with *all* the BinEntries - /// Well, not really since we are not interpreting values read... - - // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW - // -value forced while Reading process- - - //--> - // --> - // --> WARNING - // --> the following lines *looked* very clever, - // --> but they don't work on big endian processors. - // --> since I've no access for the moment to a big endian proc :-( - // --> I comment them out, to see the result on the dash board - // --> - - // --> Revert to initial code : TestWriteSimple hangs on Darwin :-( - if (GetGroup() == 0x7fe0 && GetVR() == "OW") - { - uint16_t *binArea16 = (uint16_t*)binArea8; - binary_write (*fp, binArea16, lgr ); - } - else - { - // For any other VR, BinEntry is re-written as-is - binary_write (*fp, binArea8, lgr ); - } - - //--> - // --> - // --> WARNING - // --> remove the following line, an uncomment the previous ones, - // --> if it doesn't work better - // --> - /*binary_write ( *fp, binArea8, lgr ); // Elem value*/ - -#else - binary_write ( *fp, binArea8, lgr ); // Elem value -#endif //GDCM_WORDS_BIGENDIAN - - } - else - { - // nothing was loaded, but we need to skip space on disc - - // --> WARNING : nothing is written; - // --> the initial data (on the the source image) is lost - // --> user is *not* informed ! - - fp->seekp(lgr, std::ios::cur); - } -} - -/** - * \brief Sets the value (non string) of the current Dicom Header Entry - */ -void BinEntry::SetBinArea( uint8_t *area, bool self ) -{ - if (BinArea && SelfArea) - delete[] BinArea; - - BinArea = area; - SelfArea=self; -} - -//----------------------------------------------------------------------------- -// Protected - -//----------------------------------------------------------------------------- -// Private - -//----------------------------------------------------------------------------- -// Print -/** - * \brief Prints a BinEntry (Dicom entry) - * @param os ostream we want to print in - * @param indent Indentation string to be prepended during printing - */ -void BinEntry::Print(std::ostream &os, std::string const & ) -{ - os << "B "; - DocEntry::Print(os); - std::ostringstream s; - void* binArea = GetBinArea(); - if (binArea) - { - if ( GetVR() == "FL" ) - { - int l = GetReadLength()/4 - 1; - float *beg = (float *)GetBinArea(); - s << " [" << *beg; - if ( l!= 0) - for (int i=0;i - -namespace gdcm -{ - -//----------------------------------------------------------------------------- -/** - * \brief Any Dicom Document (File or DicomDir) contains - * a set of DocEntry - Dicom entries - - * BinEntry is an elementary DocEntry (i.e. a ContentEntry, - * as opposed to SeqEntry) whose content is non std::string - * representable - * BinEntry is a specialisation of ContentEntry - */ - -class GDCM_EXPORT BinEntry : public ContentEntry -{ -public: - BinEntry( DictEntry *e ); - BinEntry( DocEntry *d ); - - ~BinEntry(); - - void Print( std::ostream &os = std::cout, std::string const &indent = "" ); - - void WriteContent( std::ofstream *fp, FileType ft); - - /// \brief Returns the area value of the current Dicom Entry - /// when it's not string-translatable (e.g : LUT table, overlay, icon) - uint8_t *GetBinArea() { return BinArea; } - void SetBinArea( uint8_t *area, bool self = true ); - - /// \brief Sets SelfArea - void SetSelfArea(bool area) { SelfArea = area; } - /// \brief Returns SelfArea - bool IsSelfArea() { return SelfArea; } - -private: - /// \brief memory area to hold 'non std::string' representable values - /// (ie : Lookup Tables, overlays, icons) - uint8_t *BinArea; - /// \brief Whether BinEntry has its own BinArea or not - bool SelfArea; -}; - -} // end namespace gdcm -//----------------------------------------------------------------------------- -#endif - diff --git a/src/gdcmContentEntry.cxx b/src/gdcmContentEntry.cxx deleted file mode 100644 index 97c949e9..00000000 --- a/src/gdcmContentEntry.cxx +++ /dev/null @@ -1,82 +0,0 @@ -/*========================================================================= - - Program: gdcm - Module: $RCSfile: gdcmContentEntry.cxx,v $ - Language: C++ - Date: $Date: 2005/06/24 10:55:58 $ - Version: $Revision: 1.10 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - -#include "gdcmContentEntry.h" -#include "gdcmVR.h" -#include "gdcmTS.h" -#include "gdcmGlobal.h" -#include "gdcmUtil.h" -#include "gdcmDebug.h" - -#include - -namespace gdcm -{ - -//----------------------------------------------------------------------------- -// Constructor / Destructor -/** - * \brief Constructor for a given DictEntry - * @param e Pointer to existing dictionary entry - */ -ContentEntry::ContentEntry(DictEntry *e) - : DocEntry(e) -{ - Value = GDCM_UNFOUND; -} - -/** - * \brief Constructor for a given DocEntry - * @param e Pointer to existing Doc entry - */ -ContentEntry::ContentEntry(DocEntry *e) - : DocEntry(e->GetDictEntry()) -{ - Copy(e); -} - -/** - * \brief Canonical destructor. - */ -ContentEntry::~ContentEntry () -{ -} - -//----------------------------------------------------------------------------- -// Print - -//----------------------------------------------------------------------------- -// Public -void ContentEntry::Copy(DocEntry *doc) -{ - DocEntry::Copy(doc); - - ContentEntry *entry = dynamic_cast(doc); - if ( entry ) - Value = entry->Value; -} - -//----------------------------------------------------------------------------- -// Protected - -//----------------------------------------------------------------------------- -// Private - -//----------------------------------------------------------------------------- -} // end namespace gdcm - diff --git a/src/gdcmContentEntry.h b/src/gdcmContentEntry.h deleted file mode 100644 index 0b61d9c1..00000000 --- a/src/gdcmContentEntry.h +++ /dev/null @@ -1,70 +0,0 @@ -/*========================================================================= - - Program: gdcm - Module: $RCSfile: gdcmContentEntry.h,v $ - Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - 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 - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - -#ifndef GDCMCONTENTENTRY_H -#define GDCMCONTENTENTRY_H - -#include "gdcmDocEntry.h" - -#include - -namespace gdcm -{ -//----------------------------------------------------------------------------- -/** - * \brief Any Dicom Document (File or DicomDir) contains - * a set of DocEntry - Dicom entries - - * (when successfuly parsed against a given Dicom dictionary) - * ContentEntry is an elementary DocEntry (as opposed to SeqEntry). - * Depending on the type of its content, - * ContentEntry is specialized as a ValEntry or a BinEntry - */ -class GDCM_EXPORT ContentEntry : public DocEntry -{ -public: - virtual void WriteContent(std::ofstream *fp, FileType filetype) = 0; - - /// Sets the value (string) of the current Dicom entry - virtual void SetValue(std::string const &val) { Value = val; } - /// \brief Returns the 'Value' (e.g. "Dupond^Marcel") converted - /// into a 'string', event if it's physically stored on disk as an integer - /// (e.g. : 0x000c returned as "12") - std::string const &GetValue() const { return Value; } - - void Copy(DocEntry *doc); - -protected: - // Contructors are protected, not to be invoked by end user. - ContentEntry(DictEntry *e); - ContentEntry(DocEntry *d); - // Destructor is protected, not to be invoked by end user. - ~ContentEntry(); - -private: -// Members : - /// \brief Dicom entry value, internaly represented as a std::string. - /// The Value Representation (\ref VR) is independently used - /// in order to interpret (decode) this field. - std::string Value; -}; - -} // end namespace gdcm - -//----------------------------------------------------------------------------- -#endif - diff --git a/src/gdcmDataEntry.cxx b/src/gdcmDataEntry.cxx new file mode 100644 index 00000000..a35ef4e7 --- /dev/null +++ b/src/gdcmDataEntry.cxx @@ -0,0 +1,625 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmDataEntry.cxx,v $ + Language: C++ + Date: $Date: 2005/10/18 08:35:51 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "gdcmDataEntry.h" +#include "gdcmVR.h" +#include "gdcmTS.h" +#include "gdcmGlobal.h" +#include "gdcmUtil.h" +#include "gdcmDebug.h" + +#include + +namespace gdcm +{ +//----------------------------------------------------------------------------- +#define MAX_SIZE_PRINT_ELEMENT_VALUE 0x7fffffff +uint32_t DataEntry::MaxSizePrintEntry = MAX_SIZE_PRINT_ELEMENT_VALUE; + +//----------------------------------------------------------------------------- +// Constructor / Destructor +/** + * \brief Constructor for a given DictEntry + * @param e Pointer to existing dictionary entry + */ +DataEntry::DataEntry(DictEntry *e) + : DocEntry(e) +{ + State = STATE_LOADED; + Flag = FLAG_NONE; + + BinArea = 0; + SelfArea = true; +} + +/** + * \brief Constructor for a given DocEntry + * @param e Pointer to existing Doc entry + */ +DataEntry::DataEntry(DocEntry *e) + : DocEntry(e->GetDictEntry()) +{ + Flag = 0; + BinArea = 0; + SelfArea = true; + + Copy(e); +} + +/** + * \brief Canonical destructor. + */ +DataEntry::~DataEntry () +{ + DeleteBinArea(); +} + +//----------------------------------------------------------------------------- +// Print + +//----------------------------------------------------------------------------- +// Public +/** + * \brief Sets the value (non string) of the current Dicom Header Entry + */ +void DataEntry::SetBinArea( uint8_t *area, bool self ) +{ + DeleteBinArea(); + + BinArea = area; + SelfArea = self; + + State = STATE_LOADED; +} + +void DataEntry::CopyBinArea( uint8_t *area, uint32_t length ) +{ + DeleteBinArea(); + + uint32_t lgh = length + length%2; + SetLength(lgh); + + if( area && length > 0 ) + { + NewBinArea(); + memcpy(BinArea,area,length); + if( length!=lgh ) + BinArea[length]=0; + + State = STATE_LOADED; + } +} + +void DataEntry::SetValue(const uint32_t &id,const double &val) +{ + if( !BinArea ) + NewBinArea(); + State = STATE_LOADED; + + if( id > GetValueCount() ) + { + gdcmErrorMacro("Index (" << id << ")is greater than the data size"); + return; + } + + const VRKey &vr = GetVR(); + if( vr == "US" || vr == "SS" ) + { + uint16_t *data = (uint16_t *)BinArea; + data[id] = (uint16_t)val; + } + else if( vr == "UL" || vr == "SL" ) + { + uint32_t *data = (uint32_t *)BinArea; + data[id] = (uint32_t)val; + } + else if( vr == "FL" ) + { + float *data = (float *)BinArea; + data[id] = (float)val; + } + else if( vr == "FD" ) + { + double *data = (double *)BinArea; + data[id] = (double)val; + } + else if( Global::GetVR()->IsVROfStringRepresentable(vr) ) + { + gdcmErrorMacro("SetValue on String representable not implemented yet"); + } + else + { + BinArea[id] = (uint8_t)val; + } +} + +double DataEntry::GetValue(const uint32_t &id) const +{ + if( !BinArea ) + { + gdcmErrorMacro("BinArea not set. Can't get the value"); + return 0; + } + + uint32_t count = GetValueCount(); + if( id > count ) + { + gdcmErrorMacro("Index (" << id << ")is greater than the data size"); + return 0; + } + + const VRKey &vr = GetVR(); + if( vr == "US" || vr == "SS" ) + return ((uint16_t *)BinArea)[id]; + else if( vr == "UL" || vr == "SL" ) + return ((uint32_t *)BinArea)[id]; + else if( vr == "FL" ) + return ((float *)BinArea)[id]; + else if( vr == "FD" ) + return ((double *)BinArea)[id]; + else if( Global::GetVR()->IsVROfStringRepresentable(vr) ) + { + if( GetLength() ) + { + // Don't use std::string to accelerate processing + double val = 0.0; + char *tmp = new char[GetLength()+1]; + memcpy(tmp,BinArea,GetLength()); + tmp[GetLength()]=0; + + if( count == 0 ) + { + val = atof(tmp); + } + else + { + count = id; + char *beg = tmp; + for(uint32_t i=0;iIsVROfStringRepresentable(vr) ) + { + // Don't use std::string to accelerate processing + uint32_t count = 1; + for(uint32_t i=0;i tokens; + Util::Tokenize (value, tokens, "\\"); + SetLength(tokens.size()*sizeof(uint16_t)); + NewBinArea(); + + uint16_t *data = (uint16_t *)BinArea; + for (unsigned int i=0; i tokens; + Util::Tokenize (value, tokens, "\\"); + SetLength(tokens.size()*sizeof(uint32_t)); + NewBinArea(); + + uint32_t *data = (uint32_t *)BinArea; + for (unsigned int i=0; i tokens; + Util::Tokenize (value, tokens, "\\"); + SetLength(tokens.size()*sizeof(float)); + NewBinArea(); + + float *data = (float *)BinArea; + for (unsigned int i=0; i tokens; + Util::Tokenize (value, tokens, "\\"); + SetLength(tokens.size()*sizeof(double)); + NewBinArea(); + + double *data = (double *)BinArea; + for (unsigned int i=0; i 0 ) + { + std::string finalVal = Util::DicomString( value.c_str() ); + SetLength(finalVal.size()); + NewBinArea(); + + memcpy(BinArea, &(finalVal[0]), finalVal.size()); + } + } + State = STATE_LOADED; +} + +std::string const &DataEntry::GetString() const +{ + static std::ostringstream s; + const VRKey &vr = GetVR(); + + s.str(""); + StrArea=""; + + if( !BinArea ) + return StrArea; + + if( vr == "US" || vr == "SS" ) + { + uint16_t *data=(uint16_t *)BinArea; + + for (int i=0; i < GetValueCount(); i++) + { + if( i!=0 ) + s << '\\'; + s << data[i]; + } + StrArea=s.str(); + } + // See above comment on multiple integers (mutatis mutandis). + else if( vr == "UL" || vr == "SL" ) + { + uint32_t *data=(uint32_t *)BinArea; + + for (int i=0; i < GetValueCount(); i++) + { + if( i!=0 ) + s << '\\'; + s << data[i]; + } + StrArea=s.str(); + } + else if( vr == "FL" ) + { + float *data=(float *)BinArea; + + for (int i=0; i < GetValueCount(); i++) + { + if( i!=0 ) + s << '\\'; + s << data[i]; + } + StrArea=s.str(); + } + else if( vr == "FD" ) + { + double *data=(double *)BinArea; + + for (int i=0; i < GetValueCount(); i++) + { + if( i!=0 ) + s << '\\'; + s << data[i]; + } + StrArea=s.str(); + } + else + StrArea.append((const char *)BinArea,GetLength()); + + return StrArea; +} + +void DataEntry::Copy(DocEntry *doc) +{ + DocEntry::Copy(doc); + + DataEntry *entry = dynamic_cast(doc); + if ( entry ) + { + State = entry->State; + Flag = entry->Flag; + CopyBinArea(entry->BinArea,entry->GetLength()); + } +} + +void DataEntry::WriteContent(std::ofstream *fp, FileType filetype) +{ + DocEntry::WriteContent(fp, filetype); + + if ( GetGroup() == 0xfffe ) + { + return; //delimitors have NO value + } + + uint8_t *binArea8 = BinArea; //safe notation + size_t lgr = GetLength(); + if (BinArea) // the binArea was *actually* loaded + { + + // The same operation should be done if we wanted + // to write image with Big Endian Transfer Syntax, + // while working on Little Endian Processor + // --> forget Big Endian Transfer Syntax writting! + // Next DICOM version will give it up ... + + // --> FIXME + // The stuff looks nice, but it's probably bugged, + // since troubles occur on big endian processors (SunSparc, Motorola) + // while reading the pixels of a + // gdcm-written Little-Endian 16 bits per pixel image + +#if defined(GDCM_WORDS_BIGENDIAN) || defined(GDCM_FORCE_BIGENDIAN_EMULATION) + + /// \todo FIXME : Right now, we only care of Pixels element + /// we should deal with *all* the BinEntries + /// Well, not really since we are not interpreting values read... + + // 8 Bits Pixels *are* OB, 16 Bits Pixels *are* OW + // -value forced while Reading process- + + // --> WARNING + // --> the following lines *looked* very clever, + // --> but they don't work on big endian processors. + // --> since I've no access for the moment to a big endian proc :-( + // --> I comment them out, to see the result on the dash board + // --> + + // --> Revert to initial code : TestWriteSimple hangs on Darwin :-( + if (GetGroup() == 0x7fe0 && GetVR() == "OW") + { + uint16_t *binArea16 = (uint16_t*)binArea8; + binary_write (*fp, binArea16, lgr ); + } + else + { + // For any other VR, DataEntry is re-written as-is + binary_write (*fp, binArea8, lgr ); + } + + // --> WARNING + // --> remove the following line, an uncomment the previous ones, + // --> if it doesn't work better + // --> + /*binary_write ( *fp, binArea8, lgr ); // Elem value*/ + +#else + binary_write ( *fp, binArea8, lgr ); // Elem value +#endif //GDCM_WORDS_BIGENDIAN + } + else + { + // nothing was loaded, but we need to skip space on disc + + // --> WARNING : nothing is written; + // --> the initial data (on the the source image) is lost + // --> user is *not* informed ! + + fp->seekp(lgr, std::ios::cur); + } +} + +//----------------------------------------------------------------------------- +// Protected +void DataEntry::NewBinArea(void) +{ + DeleteBinArea(); + if( GetLength() > 0 ) + BinArea = new uint8_t[GetLength()]; + SelfArea = true; +} + +void DataEntry::DeleteBinArea(void) +{ + if (BinArea && SelfArea) + { + delete[] BinArea; + BinArea = NULL; + } +} + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- +// Print +/** + * \brief Prints a DataEntry (Dicom entry) + * @param os ostream we want to print in + * @param indent Indentation string to be prepended during printing + */ +void DataEntry::Print(std::ostream &os, std::string const & ) +{ + os << "D "; + DocEntry::Print(os); + + std::ostringstream s; + TSAtr v; + + if( BinArea ) + { + v = GetString(); + const VRKey &vr = GetVR(); + + if( vr == "US" || vr == "SS" ) + s << " [" << GetString() << "]"; + else if( vr == "UL" || vr == "SL" ) + s << " [" << GetString() << "]"; + else if ( vr == "FL" ) + s << " [" << GetString() << "]"; + else if ( vr == "FD" ) + s << " [" << GetString() << "]"; + else + { + if(Global::GetVR()->IsVROfStringRepresentable(vr)) + { + std::string cleanString = Util::CreateCleanString(v); // replace non printable characters by '.' + if ( cleanString.length() <= GetMaxSizePrintEntry() + || PrintLevel >= 3 + || IsNotLoaded() ) + { + s << " [" << cleanString << "]"; + } + else + { + s << " [gdcm::too long for print (" << cleanString.length() << ") ]"; + } + } + else + { + if ( Util::IsCleanArea( GetBinArea(),GetLength() ) ) + { + std::string cleanString = + Util::CreateCleanString( BinArea,GetLength() ); + s << " [" << cleanString << "]"; + } + else + { + s << " [" << GDCM_BINLOADED << ";" + << "length = " << GetLength() << "]"; + } + } + } + } + else + { + if( IsNotLoaded() ) + s << " [" << GDCM_NOTLOADED << "]"; + else if( IsUnfound() ) + s << " [" << GDCM_UNFOUND << "]"; + else if( IsUnread() ) + s << " [" << GDCM_UNREAD << "]"; + else if ( GetLength() == 0 ) + s << " []"; + } + + if( IsPixelData() ) + s << " (" << GDCM_PIXELDATA << ")"; + + // Display the UID value (instead of displaying only the rough code) + // First 'clean' trailing character (space or zero) + if(BinArea) + { + const uint16_t &gr = GetGroup(); + const uint16_t &elt = GetElement(); + TS *ts = Global::GetTS(); + + if (gr == 0x0002) + { + // Any more to be displayed ? + if ( elt == 0x0010 || elt == 0x0002 ) + { + if ( v.length() != 0 ) // for brain damaged headers + { + if ( ! isdigit((unsigned char)v[v.length()-1]) ) + { + v.erase(v.length()-1, 1); + } + } + s << " ==>\t[" << ts->GetValue(v) << "]"; + } + } + else if (gr == 0x0008) + { + if ( elt == 0x0016 || elt == 0x1150 ) + { + if ( v.length() != 0 ) // for brain damaged headers + { + if ( ! isdigit((unsigned char)v[v.length()-1]) ) + { + v.erase(v.length()-1, 1); + } + } + s << " ==>\t[" << ts->GetValue(v) << "]"; + } + } + else if (gr == 0x0004) + { + if ( elt == 0x1510 || elt == 0x1512 ) + { + if ( v.length() != 0 ) // for brain damaged headers + { + if ( ! isdigit((unsigned char)v[v.length()-1]) ) + { + v.erase(v.length()-1, 1); + } + } + s << " ==>\t[" << ts->GetValue(v) << "]"; + } + } + } + + os << s.str(); +} + +//----------------------------------------------------------------------------- +} // end namespace gdcm + diff --git a/src/gdcmDataEntry.h b/src/gdcmDataEntry.h new file mode 100644 index 00000000..24073836 --- /dev/null +++ b/src/gdcmDataEntry.h @@ -0,0 +1,137 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmDataEntry.h,v $ + Language: C++ + Date: $Date: 2005/10/18 08:35:51 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef GDCMDATAENTRY_H +#define GDCMDATAENTRY_H + +#include "gdcmDocEntry.h" + +#include + +namespace gdcm +{ +//----------------------------------------------------------------------------- +/** + * \brief Any Dicom Document (File or DicomDir) contains + * a set of DocEntry - Dicom entries - + * (when successfuly parsed against a given Dicom dictionary) + * DataEntry is an elementary DocEntry (as opposed to SeqEntry). + * Depending on the type of its content, + */ +class GDCM_EXPORT DataEntry : public DocEntry +{ +public: + DataEntry(DictEntry *e); + DataEntry(DocEntry *d); + ~DataEntry(); + +// Print + void Print(std::ostream &os = std::cout, std::string const &indent = ""); + +// Write + virtual void WriteContent(std::ofstream *fp, FileType filetype); + +// Set/Get datas + /// Sets the value (string) of the current Dicom entry + //virtual void SetValue(std::string const &val); + /// \brief Returns the 'Value' (e.g. "Dupond^Marcel") converted + /// into a 'string', event if it's physically stored on disk as an integer + /// (e.g. : 0x000c returned as "12") + //virtual std::string const &GetValue() const { return Value; } + + /// \brief Returns the area value of the current Dicom Entry + /// when it's not string-translatable (e.g : LUT table, overlay, icon) + uint8_t *GetBinArea() { return BinArea; } + void SetBinArea( uint8_t *area, bool self = true ); + void CopyBinArea( uint8_t *area, uint32_t length ); + + void SetValue(const uint32_t &id,const double &val); + double GetValue(const uint32_t &id) const; + uint32_t GetValueCount(void) const; + + void SetString(std::string const &value); + std::string const &GetString() const; + + /// \brief Sets SelfArea + void SetSelfArea(bool area) { SelfArea = area; } + /// \brief Returns SelfArea + bool IsSelfArea() { return SelfArea; } + + // State + void SetState(const char &state) { State = state; } + const char &GetState() const { return State; } + bool IsNotLoaded() { return State == STATE_NOTLOADED; } + bool IsUnfound() { return State == STATE_UNFOUND; } + bool IsUnread() { return State == STATE_UNREAD; } + bool IsGoodValue() { return State == 0; } + + // Flags + void SetFlag(const char &flag) { Flag = flag; } + const char &GetFlag() const { return Flag; } + bool IsPixelData() { return (Flag & FLAG_PIXELDATA) != 0; } + + void Copy(DocEntry *doc); + + /// \brief returns the size threshold above which an element value + /// will NOT be *printed* in order no to polute the screen output + static const uint32_t &GetMaxSizePrintEntry() { return MaxSizePrintEntry; } + /// \brief Header Elements too long will not be printed + static void SetMaxSizePrintEntry(const uint32_t &size) { MaxSizePrintEntry = size; } + + typedef enum + { + STATE_LOADED = 0x00, + STATE_NOTLOADED = 0x01, + STATE_UNFOUND = 0x02, + STATE_UNREAD = 0x03, + } TValueState; + + typedef enum + { + FLAG_NONE = 0x00, + FLAG_PIXELDATA = 0x01, + } TValueFlag; + +protected: +// Methods : + void NewBinArea(void); + void DeleteBinArea(void); + +// Members : + /// \brief memory area to hold 'non std::string' representable values + /// (ie : Lookup Tables, overlays, icons) + uint8_t *BinArea; + /// \brief Whether DataEntry has its own BinArea or not + bool SelfArea; + + mutable std::string StrArea; + +private: + char Flag; + char State; + + /// \brief Size threshold above which an element val + /// By default, this upper bound is fixed to 64 bytes. + static uint32_t MaxSizePrintEntry; +}; + +} // end namespace gdcm + +//----------------------------------------------------------------------------- +#endif + diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 123b0fa6..67195605 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2005/08/31 16:24:19 $ - Version: $Revision: 1.159 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.160 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -36,7 +36,7 @@ #include "gdcmFile.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include #include @@ -582,7 +582,7 @@ bool DicomDir::Write(std::string const &fileName) bool DicomDir::Anonymize() { - ValEntry *v; + DataEntry *v; // Something clever to be found to forge the Patient names std::ostringstream s; int i = 1; @@ -591,22 +591,22 @@ bool DicomDir::Anonymize() ++cc) { s << i; - v = (*cc)->GetValEntry(0x0010, 0x0010) ; // Patient's Name + v = (*cc)->GetDataEntry(0x0010, 0x0010) ; // Patient's Name if (v) { - v->SetValue(s.str()); + v->SetString(s.str()); } - v = (*cc)->GetValEntry(0x0010, 0x0020) ; // Patient ID + v = (*cc)->GetDataEntry(0x0010, 0x0020) ; // Patient ID if (v) { - v->SetValue(" "); + v->SetString(" "); } - v = (*cc)->GetValEntry(0x0010, 0x0030) ; // Patient's BirthDate + v = (*cc)->GetDataEntry(0x0010, 0x0030) ; // Patient's BirthDate if (v) { - v->SetValue(" "); + v->SetString(" "); } s << ""; i++; @@ -778,13 +778,13 @@ void DicomDir::CreateDicomDir() while(tmpSI) { d = tmpSI->GetDocEntry(0x0004, 0x1430); // Directory Record Type - if ( ValEntry* valEntry = dynamic_cast(d) ) + if ( DataEntry *dataEntry = dynamic_cast(d) ) { - v = valEntry->GetValue(); + v = dataEntry->GetString(); } else { - gdcmWarningMacro( "(0004,1430) not a ValEntry ?!?"); + gdcmWarningMacro( "(0004,1430) not a DataEntry ?!?"); continue; } @@ -981,12 +981,12 @@ void DicomDir::SetElements(std::string const &path, VectDocument const &list) ++it ) { // get the current file characteristics - patCurName = (*it)->GetEntryValue(0x0010,0x0010); - patCurID = (*it)->GetEntryValue(0x0010,0x0011); - studCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000d); - studCurID = (*it)->GetEntryValue(0x0020,0x0010); - serCurInstanceUID = (*it)->GetEntryValue(0x0020,0x000e); - serCurID = (*it)->GetEntryValue(0x0020,0x0011); + patCurName = (*it)->GetEntryString(0x0010,0x0010); + patCurID = (*it)->GetEntryString(0x0010,0x0011); + studCurInstanceUID = (*it)->GetEntryString(0x0020,0x000d); + studCurID = (*it)->GetEntryString(0x0020,0x0010); + serCurInstanceUID = (*it)->GetEntryString(0x0020,0x000e); + serCurID = (*it)->GetEntryString(0x0020,0x0011); if ( patCurName != patPrevName || patCurID != patPrevID || first ) { @@ -1037,7 +1037,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, ListDicomDirElem::const_iterator it; uint16_t tmpGr, tmpEl; DictEntry *dictEntry; - ValEntry *entry; + DataEntry *entry; std::string val; SQItem *si; @@ -1109,7 +1109,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, tmpEl = it->Elem; dictEntry = GetPubDict()->GetEntry(tmpGr, tmpEl); - entry = new ValEntry( dictEntry ); // Be sure it's never a BinEntry ! + entry = new DataEntry( dictEntry ); // Be sure it's never a DataEntry ! entry->SetOffset(0); // just to avoid further missprinting @@ -1117,7 +1117,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, { // NULL when we Build Up (ex nihilo) a DICOMDIR // or when we add the META elems - val = header->GetEntryValue(tmpGr, tmpEl); + val = header->GetEntryString(tmpGr, tmpEl); } else { @@ -1154,7 +1154,7 @@ void DicomDir::SetElement(std::string const &path, DicomDirType type, val = it->Value; } - entry->SetValue( val ); // troubles expected when vr=SQ ... + entry->SetString( val ); // troubles expected when vr=SQ ... if ( type == GDCM_DICOMDIR_META ) // fusible : should never print ! { diff --git a/src/gdcmDicomDirImage.cxx b/src/gdcmDicomDirImage.cxx index 00728428..06dde6d5 100644 --- a/src/gdcmDicomDirImage.cxx +++ b/src/gdcmDicomDirImage.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirImage.cxx,v $ Language: C++ - Date: $Date: 2005/06/24 10:55:58 $ - Version: $Revision: 1.23 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,8 +17,8 @@ =========================================================================*/ #include "gdcmDicomDirImage.h" -#include "gdcmValEntry.h" #include "gdcmGlobal.h" +#include "gdcmDataEntry.h" namespace gdcm { @@ -72,7 +72,8 @@ void DicomDirImage::Print(std::ostream &os, std::string const & ) { if ( (*i)->GetGroup() == 0x0004 && (*i)->GetElement() == 0x1500 ) { - os << (dynamic_cast(*i))->GetValue(); //FIXME + if( dynamic_cast(*i) ) + os << (dynamic_cast(*i))->GetString(); } } os << std::endl; diff --git a/src/gdcmDicomDirObject.cxx b/src/gdcmDicomDirObject.cxx index 84a53876..e5300269 100644 --- a/src/gdcmDicomDirObject.cxx +++ b/src/gdcmDicomDirObject.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirObject.cxx,v $ Language: C++ - Date: $Date: 2005/07/12 17:08:12 $ - Version: $Revision: 1.20 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.21 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -19,8 +19,8 @@ #include "gdcmDicomDirObject.h" #include "gdcmGlobal.h" #include "gdcmDebug.h" -#include "gdcmValEntry.h" #include "gdcmDictSet.h" +#include "gdcmDataEntry.h" namespace gdcm { @@ -59,7 +59,7 @@ void DicomDirObject::FillObject(ListDicomDirMetaElem const &elemList) ListDicomDirMetaElem::const_iterator it; uint16_t tmpGr,tmpEl; DictEntry *dictEntry; - ValEntry *entry; + DataEntry *entry; // for all the Elements found in they own part of the DicomDir dict. for(it = elemList.begin(); it != elemList.end(); ++it) @@ -67,9 +67,9 @@ void DicomDirObject::FillObject(ListDicomDirMetaElem const &elemList) tmpGr = it->Group; tmpEl = it->Elem; dictEntry = Global::GetDicts()->GetDefaultPubDict()->GetEntry(tmpGr,tmpEl); - entry = new ValEntry(dictEntry); + entry = new DataEntry(dictEntry); entry->SetOffset(0); // just to avoid further missprinting - entry->SetValue(it->Value); + entry->SetString(it->Value); AddEntry(entry); } diff --git a/src/gdcmDicomDirVisit.cxx b/src/gdcmDicomDirVisit.cxx index b5c9eaba..98e9226c 100644 --- a/src/gdcmDicomDirVisit.cxx +++ b/src/gdcmDicomDirVisit.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirVisit.cxx,v $ Language: C++ - Date: $Date: 2005/07/08 19:07:12 $ - Version: $Revision: 1.1 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.2 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,8 +17,8 @@ =========================================================================*/ #include "gdcmDicomDirVisit.h" -#include "gdcmValEntry.h" #include "gdcmGlobal.h" +#include "gdcmDataEntry.h" namespace gdcm { @@ -72,7 +72,8 @@ void DicomDirVisit::Print(std::ostream &os, std::string const & ) { if ( (*i)->GetGroup() == 0x0004 && (*i)->GetElement() == 0x1500 ) { - os << (dynamic_cast(*i))->GetValue(); //FIXME // ???? + if( dynamic_cast(*i) ) + os << (dynamic_cast(*i))->GetString(); } } os << std::endl; diff --git a/src/gdcmDictEntry.h b/src/gdcmDictEntry.h index 780c7afd..11425127 100644 --- a/src/gdcmDictEntry.h +++ b/src/gdcmDictEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictEntry.h,v $ Language: C++ - Date: $Date: 2005/07/11 14:40:40 $ - Version: $Revision: 1.35 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.36 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -54,19 +54,19 @@ public: /// \brief tells if the V(alue) R(epresentation) is known (?!) /// @return - bool IsVRUnknown() { return VR == GDCM_UNKNOWN; } + bool IsVRUnknown() const { return VR == GDCM_UNKNOWN; } /// \brief tells if the V(alue) M(ultiplicity) is known (?!) /// @return - bool IsVMUnknown() { return VM == GDCM_UNKNOWN; } + bool IsVMUnknown() const { return VM == GDCM_UNKNOWN; } /// \brief Returns the Dicom Group Number of the current DictEntry /// @return the Dicom Group Number - uint16_t GetGroup() { return Group; } + const uint16_t &GetGroup() const { return Group; } /// \brief Returns the Dicom Element Number of the current DictEntry /// @return the Dicom Element Number - uint16_t GetElement() { return Element; } + const uint16_t &GetElement() const { return Element; } /// \brief Returns the Dicom Value Representation of the current /// DictEntry diff --git a/src/gdcmDocEntry.cxx b/src/gdcmDocEntry.cxx index 2da966c8..729fe8cc 100644 --- a/src/gdcmDocEntry.cxx +++ b/src/gdcmDocEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.cxx,v $ Language: C++ - Date: $Date: 2005/09/21 09:44:59 $ - Version: $Revision: 1.69 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.70 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -50,7 +50,7 @@ DocEntry::DocEntry(DictEntry *in) //----------------------------------------------------------------------------- // Public /** - * \brief Writes the common part of any ValEntry, BinEntry, SeqEntry + * \brief Writes the common part of any DataEntry, SeqEntry * @param fp already open ofstream pointer * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) */ @@ -223,7 +223,7 @@ void DocEntry::Copy(DocEntry *doc) //----------------------------------------------------------------------------- // Print /** - * \brief Prints the common part of ValEntry, BinEntry, SeqEntry + * \brief Prints the common part of DataEntry, SeqEntry * @param os ostream we want to print in * @param indent Indentation string to be prepended during printing */ diff --git a/src/gdcmDocEntry.h b/src/gdcmDocEntry.h index 29a2522e..d7fecfc3 100644 --- a/src/gdcmDocEntry.h +++ b/src/gdcmDocEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntry.h,v $ Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - Version: $Revision: 1.49 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.50 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -28,8 +28,6 @@ namespace gdcm { class File; -class ValEntry; -class BinEntry; class SeqEntry; //----------------------------------------------------------------------------- @@ -52,10 +50,10 @@ public: DictEntry * GetDictEntry() { return DicomDict; } /// Returns the Dicom Group number of the current Dicom entry - uint16_t GetGroup() { return DicomDict->GetGroup(); } + const uint16_t &GetGroup() const { return DicomDict->GetGroup(); } /// Returns the Dicom Element number of the current Dicom entry - uint16_t GetElement() { return DicomDict->GetElement();} + const uint16_t &GetElement() const { return DicomDict->GetElement();} /// Set the 'key' of the current Dicom entry void SetKey( TagKey const &key ) { Key = key; } @@ -83,7 +81,7 @@ public: /// \brief Returns offset (since the beginning of the file, including /// the File Preamble, if any) of the value of the current Dicom entry /// \warning offset of the *value*, not of the Dicom entry - size_t GetOffset() { return Offset; } + const size_t &GetOffset() const { return Offset; } /// \brief Sets only 'Read Length' (*not* 'Usable Length') of the current /// Dicom entry @@ -92,15 +90,15 @@ public: /// \warning this value is the one stored in the Dicom header but not /// mandatoryly the one thats's used (in case on SQ, or delimiters, /// the usable length is set to zero) - uint32_t GetReadLength() { return ReadLength; } + const uint32_t &GetReadLength() const { return ReadLength; } /// \brief Sets both 'Read Length' and 'Usable Length' of the current /// Dicom entry - void SetLength(uint32_t l) { Length = l; } + virtual void SetLength(uint32_t l) { Length = l; } /// \brief Returns the actual value length of the current Dicom entry /// \warning this value is not *always* the one stored in the Dicom header /// in case of well knowned bugs - uint32_t GetLength() { return Length; } + const uint32_t &GetLength() const { return Length; } uint32_t GetFullLength(); @@ -115,15 +113,15 @@ public: /// \brief Tells us if the current Dicom entry was checked as ImplicitVr /// @return true if the current Dicom entry was checked as ImplicitVr - bool IsImplicitVR() { return ImplicitVR; } + bool IsImplicitVR() const { return ImplicitVR; } /// \brief Tells us if the VR of the current Dicom entry is Unknown /// @return true if the VR is unknown - bool IsVRUnknown() { return DicomDict->IsVRUnknown(); } + bool IsVRUnknown() const { return DicomDict->IsVRUnknown(); } /// \brief Tells us if the VM of the current Dicom entry is Unknown /// @return true if the VM is unknown - bool IsVMUnknown() { return DicomDict->IsVMUnknown(); } + bool IsVMUnknown() const { return DicomDict->IsVMUnknown(); } bool IsItemDelimitor(); bool IsItemStarter(); diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index a054d86e..8aa79663 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.cxx,v $ Language: C++ - Date: $Date: 2005/09/06 15:28:49 $ - Version: $Revision: 1.59 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.60 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,9 +23,9 @@ #include "gdcmGlobal.h" #include "gdcmDocEntry.h" #include "gdcmSeqEntry.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmUtil.h" +#include "gdcmDataEntry.h" +#include "gdcmVR.h" namespace gdcm { @@ -44,11 +44,19 @@ DocEntrySet::DocEntrySet() * @return Corresponding element value when it exists, * and the string GDCM_UNFOUND otherwise. */ -std::string DocEntrySet::GetEntryValue(uint16_t group, uint16_t elem) +std::string DocEntrySet::GetEntryString(uint16_t group, uint16_t elem) { - ContentEntry *entry = dynamic_cast(GetDocEntry(group,elem)); + DataEntry *entry = dynamic_cast(GetDocEntry(group,elem)); if ( entry ) - return entry->GetValue(); + { + if( entry->IsNotLoaded() ) + return GDCM_NOTLOADED; + if( entry->IsUnfound() ) + return GDCM_UNFOUND; + if( entry->IsUnread() ) + return GDCM_UNREAD; + return entry->GetString(); + } return GDCM_UNFOUND; } @@ -60,14 +68,14 @@ std::string DocEntrySet::GetEntryValue(uint16_t group, uint16_t elem) */ void *DocEntrySet::GetEntryBinArea(uint16_t group, uint16_t elem) { - BinEntry *entry = GetBinEntry(group, elem); + DataEntry *entry = GetDataEntry(group, elem); if ( entry ) return entry->GetBinArea(); return 0; } /** - * \brief Return the value of the BinEntry if it's "std::string representable" + * \brief Return the value of the DataEntry if it's "std::string representable" * @param group Group number of the searched tag. * @param elem Element number of the searched tag. * @return Corresponding element value when it's "std::string representable" @@ -79,17 +87,24 @@ std::string DocEntrySet::GetEntryForcedAsciiValue(uint16_t group, uint16_t elem) if ( !d ) return GDCM_UNFOUND; - if (ValEntry *v = dynamic_cast(d)) - return v->GetValue(); - - if (BinEntry *b = dynamic_cast(d)) + DataEntry *de = dynamic_cast(d); + if ( de ) { - uint8_t *a = b->GetBinArea(); - if (!b) + if( de->IsNotLoaded() ) return GDCM_NOTLOADED; - // TODO : unify those two methods. - if (Util::IsCleanArea(a, b->GetLength()) ) - return Util::CreateCleanString(a, b->GetLength()); + if( de->IsUnfound() ) + return GDCM_UNFOUND; + if( de->IsUnread() ) + return GDCM_UNREAD; + } + + if( Global::GetVR()->IsVROfStringRepresentable( de->GetVR() ) ) + return de->GetString(); + else + { + uint8_t *a = de->GetBinArea(); + if( Util::IsCleanArea(a, de->GetLength()) ) + return Util::CreateCleanString(a, de->GetLength()); } return GDCM_NOTASCII; } @@ -134,39 +149,18 @@ std::string DocEntrySet::GetEntryVR(uint16_t group, uint16_t elem) /** * \brief Same as \ref Document::GetDocEntry except it only * returns a result when the corresponding entry is of type - * ValEntry. + * DataEntry. * @param group Group number of the searched Dicom Element * @param elem Element number of the searched Dicom Element - * @return When present, the corresponding ValEntry. + * @return When present, the corresponding DataEntry. */ -ValEntry *DocEntrySet::GetValEntry(uint16_t group, uint16_t elem) +DataEntry *DocEntrySet::GetDataEntry(uint16_t group, uint16_t elem) { DocEntry *currentEntry = GetDocEntry(group, elem); if ( !currentEntry ) return NULL; - return dynamic_cast(currentEntry); -} - -/** - * \brief Same as \ref Document::GetDocEntry except it only - * returns a result when the corresponding entry is of type - * BinEntry. - * @param group Group number of the searched Dicom Element - * @param elem Element number of the searched Dicom Element - * @return When present, the corresponding BinEntry. - */ -BinEntry *DocEntrySet::GetBinEntry(uint16_t group, uint16_t elem) -{ - DocEntry *currentEntry = GetDocEntry(group, elem); - if ( !currentEntry ) - { - gdcmWarningMacro( "No corresponding BinEntry " << std::hex << group << - "," << elem); - return NULL; - } - - return dynamic_cast(currentEntry); + return dynamic_cast(currentEntry); } /** @@ -198,17 +192,17 @@ SeqEntry *DocEntrySet::GetSeqEntry(uint16_t group, uint16_t elem) * @param group group number of the Dicom Element to modify * @param elem element number of the Dicom Element to modify */ -bool DocEntrySet::SetValEntry(std::string const &content, - uint16_t group, uint16_t elem) +bool DocEntrySet::SetEntryString(std::string const &content, + uint16_t group, uint16_t elem) { - ValEntry *entry = GetValEntry(group, elem); + DataEntry *entry = GetDataEntry(group, elem); if (!entry ) { - gdcmWarningMacro( "No corresponding ValEntry " << std::hex << group << + gdcmWarningMacro( "No corresponding DataEntry " << std::hex << group << "," << elem << " element (try promotion first)."); return false; } - return SetValEntry(content,entry); + return SetEntryString(content,entry); } /** @@ -220,18 +214,18 @@ bool DocEntrySet::SetValEntry(std::string const &content, * @param group group number of the Dicom Element to modify * @param elem element number of the Dicom Element to modify */ -bool DocEntrySet::SetBinEntry(uint8_t *content, int lgth, - uint16_t group, uint16_t elem) +bool DocEntrySet::SetEntryBinArea(uint8_t *content, int lgth, + uint16_t group, uint16_t elem) { - BinEntry *entry = GetBinEntry(group, elem); + DataEntry *entry = GetDataEntry(group, elem); if (!entry ) { - gdcmWarningMacro( "No corresponding ValEntry " << std::hex << group << + gdcmWarningMacro( "No corresponding DataEntry " << std::hex << group << "," << elem << " element (try promotion first)."); return false; } - return SetBinEntry(content,lgth,entry); + return SetEntryBinArea(content,lgth,entry); } /** @@ -240,30 +234,29 @@ bool DocEntrySet::SetBinEntry(uint8_t *content, int lgth, * @param content new value (string) to substitute with * @param entry Entry to be modified */ -bool DocEntrySet::SetValEntry(std::string const &content, ValEntry *entry) +bool DocEntrySet::SetEntryString(std::string const &content, DataEntry *entry) { if (entry) { - entry->SetValue(content); + entry->SetString(content); return true; } return false; } /** - * \brief Accesses an existing BinEntry (i.e. a Dicom Element) + * \brief Accesses an existing DataEntry (i.e. a Dicom Element) * and modifies it's content with the given value. * @param content new value (void* -> uint8_t*) to substitute with * @param entry Entry to be modified * @param lgth new value length */ -bool DocEntrySet::SetBinEntry(uint8_t *content, int lgth, BinEntry *entry) +bool DocEntrySet::SetEntryBinArea(uint8_t *content, int lgth, DataEntry *entry) { if (entry) { - entry->SetBinArea(content); entry->SetLength(lgth); - entry->SetValue(GDCM_BINLOADED); + entry->SetBinArea(content); return true; } return false; @@ -279,51 +272,50 @@ bool DocEntrySet::SetBinEntry(uint8_t *content, int lgth, BinEntry *entry) * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ -ValEntry *DocEntrySet::InsertValEntry(std::string const &value, - uint16_t group, uint16_t elem, - TagName const &vr ) +DataEntry *DocEntrySet::InsertEntryString(std::string const &value, + uint16_t group, uint16_t elem, + TagName const &vr ) { - ValEntry *valEntry = 0; + DataEntry *dataEntry = 0; DocEntry *currentEntry = GetDocEntry( group, elem ); if (currentEntry) { - valEntry = dynamic_cast(currentEntry); + dataEntry = dynamic_cast(currentEntry); // Verify the VR - if ( valEntry ) - if ( valEntry->GetVR()!=vr ) - valEntry = NULL; + if ( dataEntry ) + if ( dataEntry->GetVR()!=vr ) + dataEntry = NULL; - // if currentEntry doesn't correspond to the requested valEntry - if ( !valEntry) + // if currentEntry doesn't correspond to the requested dataEntry + if ( !dataEntry) { if ( !RemoveEntry(currentEntry) ) { gdcmWarningMacro( "Removal of previous DocEntry failed."); - return NULL; } } } - // Create a new valEntry if necessary - if ( !valEntry ) + // Create a new dataEntry if necessary + if ( !dataEntry ) { - valEntry = NewValEntry( group, elem, vr ); + dataEntry = NewDataEntry( group, elem, vr ); - if ( !AddEntry(valEntry) ) + if ( !AddEntry(dataEntry) ) { gdcmWarningMacro("AddEntry failed although this is a creation."); - delete valEntry; + delete dataEntry; return NULL; } } - // Set the binEntry value - SetValEntry(value, valEntry); // The std::string value - return valEntry; + // Set the dataEntry value + SetEntryString(value, dataEntry); // The std::string value + return dataEntry; } /** @@ -338,50 +330,49 @@ ValEntry *DocEntrySet::InsertValEntry(std::string const &value, * \return pointer to the modified/created Header Entry (NULL when creation * failed). */ -BinEntry *DocEntrySet::InsertBinEntry(uint8_t *binArea, int lgth, - uint16_t group, uint16_t elem, - TagName const &vr ) +DataEntry *DocEntrySet::InsertEntryBinArea(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem, + TagName const &vr ) { - BinEntry *binEntry = 0; + DataEntry *dataEntry = 0; DocEntry *currentEntry = GetDocEntry( group, elem ); // Verify the currentEntry if (currentEntry) { - binEntry = dynamic_cast(currentEntry); + dataEntry = dynamic_cast(currentEntry); // Verify the VR - if ( binEntry ) - if ( binEntry->GetVR()!=vr ) - binEntry = NULL; + if ( dataEntry ) + if ( dataEntry->GetVR()!=vr ) + dataEntry = NULL; - // if currentEntry doesn't correspond to the requested valEntry - if ( !binEntry) + // if currentEntry doesn't correspond to the requested dataEntry + if ( !dataEntry) { if ( !RemoveEntry(currentEntry) ) { gdcmWarningMacro( "Removal of previous DocEntry failed."); - return NULL; } } } - // Create a new binEntry if necessary - if ( !binEntry) + // Create a new dataEntry if necessary + if ( !dataEntry) { - binEntry = NewBinEntry(group, elem, vr); + dataEntry = NewDataEntry(group, elem, vr); - if ( !AddEntry(binEntry) ) + if ( !AddEntry(dataEntry) ) { gdcmWarningMacro( "AddEntry failed although this is a creation."); - delete binEntry; + delete dataEntry; return NULL; } } - // Set the binEntry value + // Set the dataEntry value uint8_t *tmpArea; if ( lgth>0 && binArea ) { @@ -392,7 +383,7 @@ BinEntry *DocEntrySet::InsertBinEntry(uint8_t *binArea, int lgth, { tmpArea = 0; } - if ( !SetBinEntry(tmpArea,lgth,binEntry) ) + if ( !SetEntryBinArea(tmpArea,lgth,dataEntry) ) { if ( tmpArea ) { @@ -400,7 +391,7 @@ BinEntry *DocEntrySet::InsertBinEntry(uint8_t *binArea, int lgth, } } - return binEntry; + return dataEntry; } /** @@ -474,40 +465,16 @@ bool DocEntrySet::CheckIfEntryExist(uint16_t group, uint16_t elem ) * @param elem Element number of the new Entry * @param vr V(alue) R(epresentation) of the new Entry */ -ValEntry *DocEntrySet::NewValEntry(uint16_t group,uint16_t elem, - TagName const &vr) -{ - DictEntry *dictEntry = GetDictEntry(group, elem, vr); - gdcmAssertMacro(dictEntry); - - ValEntry *newEntry = new ValEntry(dictEntry); - if (!newEntry) - { - gdcmWarningMacro( "Failed to allocate ValEntry"); - return 0; - } - return newEntry; -} - - -/** - * \brief Build a new Bin Entry from all the low level arguments. - * Check for existence of dictionary entry, and build - * a default one when absent. - * @param group Group number of the new Entry - * @param elem Element number of the new Entry - * @param vr V(alue) R(epresentation) of the new Entry - */ -BinEntry *DocEntrySet::NewBinEntry(uint16_t group, uint16_t elem, +DataEntry *DocEntrySet::NewDataEntry(uint16_t group,uint16_t elem, TagName const &vr) { DictEntry *dictEntry = GetDictEntry(group, elem, vr); gdcmAssertMacro(dictEntry); - BinEntry *newEntry = new BinEntry(dictEntry); + DataEntry *newEntry = new DataEntry(dictEntry); if (!newEntry) { - gdcmWarningMacro( "Failed to allocate BinEntry"); + gdcmWarningMacro( "Failed to allocate DataEntry"); return 0; } return newEntry; diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index 81425d0e..4502a78a 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2005/09/06 15:28:49 $ - Version: $Revision: 1.56 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.57 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,8 +26,7 @@ namespace gdcm { //----------------------------------------------------------------------------- class DocEntry; -class ValEntry; -class BinEntry; +class DataEntry; class SeqEntry; class DictEntry; @@ -80,32 +79,30 @@ public: /// Gets the next entry of any type of set virtual DocEntry *GetNextEntry()=0; - virtual std::string GetEntryValue(uint16_t group, uint16_t elem); + virtual std::string GetEntryString(uint16_t group, uint16_t elem); virtual void *GetEntryBinArea(uint16_t group, uint16_t elem); - virtual int GetEntryLength(uint16_t group, uint16_t elem); virtual std::string GetEntryVR(uint16_t group, uint16_t elem); virtual std::string GetEntryForcedAsciiValue(uint16_t group, uint16_t elem); + /// \brief Gets any type of DocEntry, identified by its (group,elem) virtual DocEntry *GetDocEntry(uint16_t group, uint16_t elem) = 0; - /// \brief Gets a ValEntry, identified by its (group, elem) - ValEntry *GetValEntry(uint16_t group, uint16_t elem); - /// \brief Gets a BinEntry, identified by its (group,elem) - BinEntry *GetBinEntry(uint16_t group, uint16_t elem); + /// \brief Gets a DataEntry, identified by its (group, elem) + DataEntry *GetDataEntry(uint16_t group, uint16_t elem); /// \brief Gets a SeqEntry, identified by its (group,elem) SeqEntry *GetSeqEntry(uint16_t group, uint16_t elem); - bool SetValEntry(std::string const &content, - uint16_t group, uint16_t elem); - bool SetBinEntry(uint8_t *content, int lgth, - uint16_t group, uint16_t elem); - bool SetValEntry(std::string const &content, ValEntry *entry); - bool SetBinEntry(uint8_t *content, int lgth, BinEntry *entry); - - ValEntry *InsertValEntry(std::string const &value, - uint16_t group, uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); - BinEntry *InsertBinEntry(uint8_t *binArea, int lgth, + bool SetEntryString(std::string const &content, + uint16_t group, uint16_t elem); + bool SetEntryBinArea(uint8_t *content, int lgth, + uint16_t group, uint16_t elem); + bool SetEntryString(std::string const &content, DataEntry *entry); + bool SetEntryBinArea(uint8_t *content, int lgth, DataEntry *entry); + + DataEntry *InsertEntryString(std::string const &value, + uint16_t group, uint16_t elem, + TagName const &vr = GDCM_UNKNOWN); + DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth, uint16_t group, uint16_t elem, TagName const &vr = GDCM_UNKNOWN); SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem); @@ -114,9 +111,7 @@ public: virtual bool CheckIfEntryExist(uint16_t group, uint16_t elem); // DocEntry related utilities - ValEntry *NewValEntry(uint16_t group,uint16_t elem, - TagName const &vr = GDCM_UNKNOWN); - BinEntry *NewBinEntry(uint16_t group, uint16_t elem, + DataEntry *NewDataEntry(uint16_t group,uint16_t elem, TagName const &vr = GDCM_UNKNOWN); SeqEntry *NewSeqEntry(uint16_t group, uint16_t elem); diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index f5b27b98..703d7ef7 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2005/10/17 14:55:01 $ - Version: $Revision: 1.288 $ + Date: $Date: 2005/10/18 08:35:49 $ + Version: $Revision: 1.289 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -17,8 +17,6 @@ =========================================================================*/ #include "gdcmDocument.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmSeqEntry.h" #include "gdcmGlobal.h" #include "gdcmUtil.h" @@ -27,6 +25,7 @@ #include "gdcmDictSet.h" #include "gdcmDocEntrySet.h" #include "gdcmSQItem.h" +#include "gdcmDataEntry.h" #include #include @@ -137,21 +136,6 @@ bool Document::DoTheLoadingDocumentJob( ) if ( ! IsDocumentModified ) // Nothing to do ! return true; - // if ( Filename == fileName ) - // { - // gdcmWarningMacro( "The file was already parsed inside this " - // << "gdcm::Document (its name is: " - // << Filename.c_str() ); - // return true; - // } - - //gdcmWarningMacro( "A file was already parsed inside this " - // << "gdcm::Document (previous name was: " - // << Filename.c_str() << ". New name is :" - // << fileName ); - // clean out the Entries, if already parsed - // (probabely a mistake from the user) - ClearEntry(); Fp = 0; @@ -204,7 +188,7 @@ bool Document::DoTheLoadingDocumentJob( ) // Load 'non string' values - std::string PhotometricInterpretation = GetEntryValue(0x0028,0x0004); + std::string PhotometricInterpretation = GetEntryString(0x0028,0x0004); if ( PhotometricInterpretation == "PALETTE COLOR " ) { // FIXME @@ -217,16 +201,16 @@ bool Document::DoTheLoadingDocumentJob( ) /// defined as having an US Value Representation in the public /// dictionary. BUT the semantics implied by the three following /// lines state that the corresponding tag contents are in fact - /// the ones of a BinEntry. + /// the ones of a DataEntry. /// In order to fix things "Quick and Dirty" the dictionary was /// altered on PURPOSE but now contains a WRONG value. /// In order to fix things and restore the dictionary to its /// correct value, one needs to decided of the semantics by deciding /// whether the following tags are either : - /// - multivaluated US, and hence loaded as ValEntry, but afterwards - /// also used as BinEntry, which requires the proper conversion, - /// - OW, and hence loaded as BinEntry, but afterwards also used - /// as ValEntry, which requires the proper conversion. + /// - multivaluated US, and hence loaded as DataEntry, but afterwards + /// also used as DataEntry, which requires the proper conversion, + /// - OW, and hence loaded as DataEntry, but afterwards also used + /// as DataEntry, which requires the proper conversion. LoadEntryBinArea(0x0028,0x1201); // R LUT LoadEntryBinArea(0x0028,0x1202); // G LUT LoadEntryBinArea(0x0028,0x1203); // B LUT @@ -246,12 +230,12 @@ bool Document::DoTheLoadingDocumentJob( ) SQItem *sqi= modLutSeq->GetFirstSQItem(); if ( sqi != 0 ) { - BinEntry *b = sqi->GetBinEntry(0x0028,0x3006); - if ( b != 0 ) + DataEntry *dataEntry = sqi->GetDataEntry(0x0028,0x3006); + if ( dataEntry != 0 ) { - if ( b->GetLength() != 0 ) + if ( dataEntry->GetLength() != 0 ) { - LoadEntryBinArea(b); //LUT Data (CTX dependent) + LoadEntryBinArea(dataEntry); //LUT Data (CTX dependent) } } } @@ -277,26 +261,7 @@ bool Document::DoTheLoadingDocumentJob( ) continue; } - if ( dynamic_cast(d) ) - { - LoadDocEntry(d, true); - continue; - } - - BinEntry *b = dynamic_cast(d); - if ( b ) - { - LoadEntryBinArea(b); - b->SetValue(GDCM_BINLOADED); - continue; - } - - if ( dynamic_cast(d) ) - { - gdcmWarningMacro( "You cannot 'ForceLoad' a SeqEntry :" << std::hex - << (*it).Group <<"|"<< (*it).Elem ); - continue; - } + LoadDocEntry(d, true); } CloseFile(); @@ -312,16 +277,16 @@ bool Document::DoTheLoadingDocumentJob( ) // we switch lineNumber and columnNumber // std::string RecCode; - RecCode = GetEntryValue(0x0008, 0x0010); // recognition code (RET) + RecCode = GetEntryString(0x0008, 0x0010); // recognition code (RET) if (RecCode == "ACRNEMA_LIBIDO_1.1" || RecCode == "CANRME_AILIBOD1_1." ) // for brain-damaged softwares // with "little-endian strings" { Filetype = ACR_LIBIDO; - std::string rows = GetEntryValue(0x0028, 0x0010); - std::string columns = GetEntryValue(0x0028, 0x0011); - SetValEntry(columns, 0x0028, 0x0010); - SetValEntry(rows , 0x0028, 0x0011); + std::string rows = GetEntryString(0x0028, 0x0010); + std::string columns = GetEntryString(0x0028, 0x0011); + SetEntryString(columns, 0x0028, 0x0010); + SetEntryString(rows , 0x0028, 0x0011); } // --- End of ACR-LibIDO kludge --- return true; @@ -457,9 +422,9 @@ std::string Document::GetTransferSyntax() // The entry might be present but not loaded (parsing and loading // happen at different stages): try loading and proceed with check... LoadDocEntrySafe(entry); - if (ValEntry *valEntry = dynamic_cast< ValEntry* >(entry) ) + if (DataEntry *dataEntry = dynamic_cast(entry) ) { - std::string transfer = valEntry->GetValue(); + std::string transfer = dataEntry->GetString(); // The actual transfer (as read from disk) might be padded. We // first need to remove the potential padding. We can make the // weak assumption that padding was not executed with digits... @@ -471,6 +436,11 @@ std::string Document::GetTransferSyntax() while ( !isdigit((unsigned char)transfer[transfer.length()-1]) ) { transfer.erase(transfer.length()-1, 1); + if ( transfer.length() == 0 ) + { + // for brain damaged headers + return GDCM_UNKNOWN; + } } return transfer; } @@ -484,7 +454,7 @@ std::string Document::GetTransferSyntax() std::string Document::GetTransferSyntaxName() { // use the TS (TS : Transfer Syntax) - std::string transferSyntax = GetEntryValue(0x0002,0x0010); + std::string transferSyntax = GetEntryString(0x0002,0x0010); if ( (transferSyntax.find(GDCM_NOTLOADED) < transferSyntax.length()) ) { @@ -692,21 +662,21 @@ void Document::WriteContent(std::ofstream *fp, FileType filetype) void Document::LoadEntryBinArea(uint16_t group, uint16_t elem) { // Search the corresponding DocEntry - DocEntry *docElement = GetDocEntry(group, elem); - if ( !docElement ) + DocEntry *docEntry = GetDocEntry(group, elem); + if ( !docEntry ) { gdcmWarningMacro(std::hex << group << "|" << elem << "doesn't exist" ); return; } - BinEntry *binElement = dynamic_cast(docElement); - if ( !binElement ) + DataEntry *dataEntry = dynamic_cast(docEntry); + if ( !dataEntry ) { gdcmWarningMacro(std::hex << group << "|" << elem - << "is NOT a BinEntry"); + << "is NOT a DataEntry"); return; } - LoadEntryBinArea(binElement); + LoadEntryBinArea(dataEntry); } /** @@ -714,36 +684,70 @@ void Document::LoadEntryBinArea(uint16_t group, uint16_t elem) * when a string is not suitable * @param elem Entry whose binArea is going to be loaded */ -void Document::LoadEntryBinArea(BinEntry *elem) +void Document::LoadEntryBinArea(DataEntry *entry) { - if (elem->GetBinArea() ) + if( entry->GetBinArea() ) return; bool openFile = !Fp; if ( openFile ) OpenFile(); - size_t o =(size_t)elem->GetOffset(); + size_t o =(size_t)entry->GetOffset(); Fp->seekg(o, std::ios::beg); - size_t l = elem->GetLength(); - uint8_t *a = new uint8_t[l]; - if ( !a ) + size_t l = entry->GetLength(); + uint8_t *data = new uint8_t[l]; + if ( !data ) { - gdcmWarningMacro( "Cannot allocate BinEntry content for : " - << std::hex << elem->GetGroup() - << "|" << elem->GetElement() ); + gdcmWarningMacro( "Cannot allocate DataEntry content for : " + << std::hex << entry->GetGroup() + << "|" << entry->GetElement() ); return; } - Fp->read((char*)a, l); + // Read the datas + Fp->read((char*)data, l); if ( Fp->fail() || Fp->eof() ) { - delete[] a; + delete[] data; + entry->SetState(DataEntry::STATE_UNREAD); return; } - elem->SetBinArea(a); + // Swap the data content if necessary + uint32_t i; + unsigned short vrLgth = Global::GetVR()->GetAtomicElementLength(entry->GetVR()); + if( entry->GetVR() == "OW" ) + vrLgth = 1; + + switch(vrLgth) + { + case 2: + { + uint16_t *data16 = (uint16_t *)data; + for(i=0;iSetBinArea(data); if ( openFile ) CloseFile(); @@ -775,8 +779,8 @@ void Document::LoadDocEntrySafe(DocEntry *entry) bool Document::operator<(Document &document) { // Patient Name - std::string s1 = GetEntryValue(0x0010,0x0010); - std::string s2 = document.GetEntryValue(0x0010,0x0010); + std::string s1 = GetEntryString(0x0010,0x0010); + std::string s2 = document.GetEntryString(0x0010,0x0010); if (s1 < s2) { return true; @@ -788,8 +792,8 @@ bool Document::operator<(Document &document) else { // Patient ID - s1 = GetEntryValue(0x0010,0x0020); - s2 = document.GetEntryValue(0x0010,0x0020); + s1 = GetEntryString(0x0010,0x0020); + s2 = document.GetEntryString(0x0010,0x0020); if ( s1 < s2 ) { return true; @@ -801,8 +805,8 @@ bool Document::operator<(Document &document) else { // Study Instance UID - s1 = GetEntryValue(0x0020,0x000d); - s2 = document.GetEntryValue(0x0020,0x000d); + s1 = GetEntryString(0x0020,0x000d); + s2 = document.GetEntryString(0x0020,0x000d); if ( s1 < s2 ) { return true; @@ -814,8 +818,8 @@ bool Document::operator<(Document &document) else { // Serie Instance UID - s1 = GetEntryValue(0x0020,0x000e); - s2 = document.GetEntryValue(0x0020,0x000e); + s1 = GetEntryString(0x0020,0x000e); + s2 = document.GetEntryString(0x0020,0x000e); if ( s1 < s2 ) { return true; @@ -959,8 +963,7 @@ void Document::ParseDES(DocEntrySet *set, long offset, long l_max, bool delim_mode) { DocEntry *newDocEntry; - ValEntry *newValEntry; - BinEntry *newBinEntry; + DataEntry *newDataEntry; SeqEntry *newSeqEntry; VRKey vr; bool used; // will be set to false when something wrong happens to an Entry. @@ -979,12 +982,11 @@ void Document::ParseDES(DocEntrySet *set, long offset, newDocEntry = ReadNextDocEntry( ); // FIXME : - // Private tag, in IMplicit VR are defaulted as a BinEntry, + // Private tag, in IMplicit VR are defaulted as a DataEntry, // Very often they are only composed of Printable characters, - // and could be defaulted as a ValEntry. + // and could be defaulted as a DataEntry. // It's too late to do the Job // (we should check the value, but we know it after LoadDocEntry ...) - // --> in next gdcm major release let's unify ValEntry and BinEntry ! // Uncoment this printf line to be able to 'follow' the DocEntries // when something *very* strange happens @@ -1012,124 +1014,66 @@ void Document::ParseDES(DocEntrySet *set, long offset, } used = true; - newValEntry = dynamic_cast(newDocEntry); - newBinEntry = dynamic_cast(newDocEntry); + newDataEntry = dynamic_cast(newDocEntry); - if ( newValEntry || newBinEntry ) + if ( newDataEntry ) { - //////////////////////////// ContentEntry - if ( newBinEntry ) - { - vr = newDocEntry->GetVR(); - if ( Filetype == ExplicitVR && - !Global::GetVR()->IsVROfBinaryRepresentable(vr) ) - { - ////// Neither ValEntry NOR BinEntry: should mean UNKOWN VR - gdcmWarningMacro( std::hex << newDocEntry->GetGroup() - << "|" << newDocEntry->GetElement() - << " : Neither Valentry, nor BinEntry." - "Probably unknown VR."); - } - - //////////////////// BinEntry or UNKOWN VR: - - // When "this" is a Document the Key is simply of the - // form ( group, elem )... - //if ( set == this ) // ( dynamic_cast< Document* > ( set ) ) - //{ - // newBinEntry->SetKey( newBinEntry->GetKey() ); - //} - // but when "this" is a SQItem, we are inserting this new - // valEntry in a sequence item, and the key has the - // generalized form (refer to \ref BaseTagKey): + //////////////////////////// DataEntry + vr = newDocEntry->GetVR(); + if ( Filetype == ExplicitVR && + !Global::GetVR()->IsVROfBinaryRepresentable(vr) ) + { + ////// No DataEntry: should mean UNKOWN VR + gdcmWarningMacro( std::hex << newDocEntry->GetGroup() + << "|" << newDocEntry->GetElement() + << " : No DataEntry." + "Probably unknown VR."); + } - // time waste hunting - //if (SQItem *parentSQItem = dynamic_cast< SQItem* > ( set ) ) - //{ - // newBinEntry->SetKey( parentSQItem->GetBaseTagKey() - // + newBinEntry->GetKey() ); - //} - - if ( !set->AddEntry( newBinEntry ) ) - { - gdcmWarningMacro( "in ParseDES : cannot add a BinEntry " - << newBinEntry->GetKey() - << " (at offset : " - << newBinEntry->GetOffset() << " )" ); - used=false; - } - else - { - // Load only if we can add (not a duplicate key) - LoadDocEntry( newBinEntry ); - } - } // end BinEntry + if ( !set->AddEntry( newDataEntry ) ) + { + gdcmWarningMacro( "in ParseDES : cannot add a DataEntry " + << newDataEntry->GetKey() + << " (at offset : " + << newDataEntry->GetOffset() << " )" ); + used=false; + } else { - /////////////////////// ValEntry - - // When "set" is a Document, then we are at the top of the - // hierarchy and the Key is simply of the form ( group, elem )... - //if ( set == this ) // ( dynamic_cast< Document* > ( set ) ) - //{ - // newValEntry->SetKey( newValEntry->GetKey() ); - //} - // ...but when "set" is a SQItem, we are inserting this new - // valEntry in a sequence item. Hence the key has the - // generalized form (refer to \ref BaseTagKey): - - // time waste hunting - //if (SQItem *parentSQItem = dynamic_cast< SQItem* > ( set ) ) - //{ - // newValEntry->SetKey( parentSQItem->GetBaseTagKey() - // + newValEntry->GetKey() ); - //} - - if ( !set->AddEntry( newValEntry ) ) - { - gdcmWarningMacro( "in ParseDES : cannot add a ValEntry " - << newValEntry->GetKey() - << " (at offset : " - << newValEntry->GetOffset() << " )" ); - used=false; - } - else - { - // Load only if we can add (not a duplicate key) - LoadDocEntry( newValEntry ); - } + // Load only if we can add (not a duplicate key) + LoadDocEntry( newDataEntry ); + } - if ( newValEntry->GetElement() == 0x0000 ) // if on group length + if ( newDataEntry->GetElement() == 0x0000 ) // if on group length + { + if ( newDataEntry->GetGroup()%2 != 0 ) // if Shadow Group { - if ( newValEntry->GetGroup()%2 != 0 ) // if Shadow Group + if ( LoadMode & LD_NOSHADOW ) // if user asked to skip shad.gr { - if ( LoadMode & LD_NOSHADOW ) // if user asked to skip shad.gr + std::string strLgrGroup = newDataEntry->GetString(); + int lgrGroup; + if ( newDataEntry->IsUnfound() ) { - std::string strLgrGroup = newValEntry->GetValue(); - int lgrGroup; - if ( strLgrGroup != GDCM_UNFOUND) - { - lgrGroup = atoi(strLgrGroup.c_str()); - Fp->seekg(lgrGroup, std::ios::cur); - //used = false; // never used - RemoveEntry( newDocEntry ); // Remove and delete - // bcc 5.5 is right "assigned a value that's never used" - // newDocEntry = 0; - continue; - } + lgrGroup = atoi(strLgrGroup.c_str()); + Fp->seekg(lgrGroup, std::ios::cur); + //used = false; // never used + RemoveEntry( newDocEntry ); // Remove and delete + // bcc 5.5 is right "assigned a value that's never used" + // newDocEntry = 0; + continue; } } } + } - bool delimitor = newValEntry->IsItemDelimitor(); + bool delimitor = newDataEntry->IsItemDelimitor(); - if ( (delimitor) || - (!delim_mode && ((long)(Fp->tellg())-offset) >= l_max) ) - { - if ( !used ) - delete newDocEntry; - break; - } + if ( (delimitor) || + (!delim_mode && ((long)(Fp->tellg())-offset) >= l_max) ) + { + if ( !used ) + delete newDocEntry; + break; } // Just to make sure we are at the beginning of next entry. @@ -1277,14 +1221,6 @@ void Document::ParseSQ( SeqEntry *seqEntry, } // create the current SQItem SQItem *itemSQ = new SQItem( seqEntry->GetDepthLevel() ); -/* - std::ostringstream newBase; - newBase << seqEntry->GetKey() - << "/" - << SQItemNumber - << "#"; - itemSQ->SetBaseTagKey( newBase.str() ); -*/ unsigned int l = newDocEntry->GetReadLength(); if ( l == 0xffffffff ) @@ -1348,7 +1284,7 @@ DocEntry *Document::Backtrack(DocEntry *docEntry) Fp->seekg( 0, std::ios::beg); Fp->seekg(offset, std::ios::cur); -return newEntry; + return newEntry; } /** @@ -1369,16 +1305,22 @@ void Document::LoadDocEntry(DocEntry *entry, bool forceLoad) // (fffe e000) tells us an Element is beginning // (fffe e00d) tells us an Element just ended // (fffe e0dd) tells us the current SeQuence just ended - if ( group == 0xfffe ) + if ( group == 0xfffe || vr == "SQ" ) { // NO more value field for SQ ! return; } + DataEntry *dataEntryPtr = dynamic_cast< DataEntry* >(entry); + if( !dataEntryPtr ) + { + return; + } + // When the length is zero things are easy: if ( length == 0 ) { - ((ValEntry *)entry)->SetValue(""); + dataEntryPtr->SetBinArea(NULL,true); return; } @@ -1392,30 +1334,8 @@ void Document::LoadDocEntry(DocEntry *entry, bool forceLoad) { if (length > MaxSizeLoadEntry) { - if (BinEntry *binEntryPtr = dynamic_cast< BinEntry* >(entry) ) - { - s << GDCM_NOTLOADED; - s << " Ad.:" << (long)entry->GetOffset(); - s << " x(" << std::hex << entry->GetOffset() << ")"; - s << std::dec; - s << " Lgt:" << entry->GetLength(); - s << " x(" << std::hex << entry->GetLength() << ")"; - binEntryPtr->SetValue(s.str()); - } - else if (ValEntry *valEntryPtr = dynamic_cast< ValEntry* >(entry) ) - { - s << GDCM_NOTLOADED; - s << " Address:" << (long)entry->GetOffset(); - s << " Length:" << entry->GetLength(); - s << " x(" << std::hex << entry->GetLength() << ")"; - valEntryPtr->SetValue(s.str()); - } - else - { - // fusible - gdcmErrorMacro( "MaxSizeLoadEntry exceeded, neither a BinEntry " - << "nor a ValEntry ?! Should never print that !" ); - } + dataEntryPtr->SetBinArea(NULL,true); + dataEntryPtr->SetState(DataEntry::STATE_NOTLOADED); // to be sure we are at the end of the value ... Fp->seekg((long)entry->GetOffset()+(long)entry->GetLength(), @@ -1424,117 +1344,7 @@ void Document::LoadDocEntry(DocEntry *entry, bool forceLoad) } } - // When we find a BinEntry not very much can be done : - if (BinEntry *binEntryPtr = dynamic_cast< BinEntry* >(entry) ) - { - s << GDCM_BINLOADED; - binEntryPtr->SetValue(s.str()); - LoadEntryBinArea(binEntryPtr); // last one, not to erase length ! - return; - } - - if ( IsDocEntryAnInteger(entry) ) - { - uint32_t NewInt; - int nbInt; - // When short integer(s) are expected, read and convert the following - // (n * 2) characters properly i.e. consider them as short integers as - // opposed to strings. - // Elements with Value Multiplicity > 1 - // contain a set of integers (not a single one) - if (vr == "US" || vr == "SS") - { - nbInt = length / 2; - NewInt = ReadInt16(); - s << NewInt; - if (nbInt > 1) - { - for (int i=1; i < nbInt; i++) - { - s << '\\'; - NewInt = ReadInt16(); - s << NewInt; - } - } - } - // See above comment on multiple integers (mutatis mutandis). - else if (vr == "UL" || vr == "SL") - { - nbInt = length / 4; - NewInt = ReadInt32(); - s << NewInt; - if (nbInt > 1) - { - for (int i=1; i < nbInt; i++) - { - s << '\\'; - NewInt = ReadInt32(); - s << NewInt; - } - } - } -#ifdef GDCM_NO_ANSI_STRING_STREAM - s << std::ends; // to avoid oddities on Solaris -#endif //GDCM_NO_ANSI_STRING_STREAM - - ((ValEntry *)entry)->SetValue(s.str()); - return; - } - - // FIXME: We need an additional byte for storing \0 that is not on disk - char *str = new char[length+1]; - Fp->read(str, (size_t)length); - str[length] = '\0'; //this is only useful when length is odd - // Special DicomString call to properly handle \0 and even length - std::string newValue; - if ( length % 2 ) - { - newValue = Util::DicomString(str, length+1); - gdcmWarningMacro("Warning: bad length: " << length << - " For string :" << newValue.c_str()); - // Since we change the length of string update it length - //entry->SetReadLength(length+1); - } - else - { - newValue = Util::DicomString(str, length); - } - delete[] str; - - if ( ValEntry *valEntry = dynamic_cast(entry) ) - { - if ( Fp->fail() || Fp->eof()) - { - if ( Fp->fail() ) - gdcmWarningMacro("--> fail"); - - gdcmWarningMacro("Unread element value " << valEntry->GetKey() - << " lgt : " << valEntry->GetReadLength() - << " at " << std::hex << valEntry->GetOffset()); - valEntry->SetValue(GDCM_UNREAD); - return; - } - -// if ( vr == "UI" ) -// { -// // Because of correspondance with the VR dic -// valEntry->SetValue(newValue); -// } -// else -// { -// valEntry->SetValue(newValue); -// } - -// Anybody remembers the genesis of strange previous (commented out) code? - valEntry->SetValue(newValue); - - } - else - { - gdcmWarningMacro("Should have a ValEntry, here ! " << valEntry->GetKey() - << " lgt : " << valEntry->GetReadLength() - << " at " << std::hex << valEntry->GetOffset()); - } + LoadEntryBinArea(dataEntryPtr); // last one, not to erase length ! } /** @@ -1727,136 +1537,6 @@ bool Document::CheckDocEntryVR(VRKey vr) return true; } -/** - * \brief Get the transformed value of the header entry. The VR value - * is used to define the transformation to operate on the value - * \warning NOT end user intended method ! - * @param entry entry to tranform - * @return Transformed entry value - */ -std::string Document::GetDocEntryValue(DocEntry *entry) -{ - if ( IsDocEntryAnInteger(entry) && entry->IsImplicitVR() ) - { - std::string val = ((ValEntry *)entry)->GetValue(); - std::string vr = entry->GetVR(); - uint32_t length = entry->GetLength(); - std::ostringstream s; - int nbInt; - - // When short integer(s) are expected, read and convert the following - // n * 2 bytes properly i.e. as a multivaluated strings - // (each single value is separated fromthe next one by '\' - // as usual for standard multivaluated filels - // Elements with Value Multiplicity > 1 - // contain a set of short integers (not a single one) - - if ( vr == "US" || vr == "SS" ) - { - uint16_t newInt16; - - nbInt = length / 2; - for (int i=0; i < nbInt; i++) - { - if ( i != 0 ) - { - s << '\\'; - } - newInt16 = ( val[2*i+0] & 0xFF ) + ( ( val[2*i+1] & 0xFF ) << 8); - newInt16 = SwapShort( newInt16 ); - s << newInt16; - } - } - - // When integer(s) are expected, read and convert the following - // n * 4 bytes properly i.e. as a multivaluated strings - // (each single value is separated fromthe next one by '\' - // as usual for standard multivaluated filels - // Elements with Value Multiplicity > 1 - // contain a set of integers (not a single one) - else if ( vr == "UL" || vr == "SL" ) - { - uint32_t newInt32; - - nbInt = length / 4; - for (int i=0; i < nbInt; i++) - { - if ( i != 0) - { - s << '\\'; - } - newInt32 = ( val[4*i+0] & 0xFF ) - + (( val[4*i+1] & 0xFF ) << 8 ) - + (( val[4*i+2] & 0xFF ) << 16 ) - + (( val[4*i+3] & 0xFF ) << 24 ); - newInt32 = SwapLong( newInt32 ); - s << newInt32; - } - } -#ifdef GDCM_NO_ANSI_STRING_STREAM - s << std::ends; // to avoid oddities on Solaris -#endif //GDCM_NO_ANSI_STRING_STREAM - return s.str(); - } - return ((ValEntry *)entry)->GetValue(); -} - -/** - * \brief Get the reverse transformed value of the header entry. The VR - * value is used to define the reverse transformation to operate on - * the value - * \warning NOT end user intended method ! - * @param entry Entry to reverse transform - * @return Reverse transformed entry value - */ -std::string Document::GetDocEntryUnvalue(DocEntry *entry) -{ - if ( IsDocEntryAnInteger(entry) && entry->IsImplicitVR() ) - { - std::string vr = entry->GetVR(); - std::vector tokens; - std::ostringstream s; - - if ( vr == "US" || vr == "SS" ) - { - uint16_t newInt16; - - tokens.erase( tokens.begin(), tokens.end()); // clean any previous value - Util::Tokenize (((ValEntry *)entry)->GetValue(), tokens, "\\"); - for (unsigned int i=0; i> 8 ) & 0xFF ); - } - tokens.clear(); - } - if ( vr == "UL" || vr == "SL") - { - uint32_t newInt32; - - tokens.erase(tokens.begin(),tokens.end()); // clean any previous value - Util::Tokenize (((ValEntry *)entry)->GetValue(), tokens, "\\"); - for (unsigned int i=0; i> 8 ) & 0xFF ) - << (char)(( newInt32 >> 16 ) & 0xFF ) - << (char)(( newInt32 >> 24 ) & 0xFF ); - } - tokens.clear(); - } - -#ifdef GDCM_NO_ANSI_STRING_STREAM - s << std::ends; // to avoid oddities on Solaris -#endif //GDCM_NO_ANSI_STRING_STREAM - return s.str(); - } - - return ((ValEntry *)entry)->GetValue(); -} - /** * \brief Skip a given Header Entry * \warning NOT end user intended method ! @@ -2311,10 +1991,11 @@ DocEntry *Document::ReadNextDocEntry() DocEntry *newEntry; if ( Global::GetVR()->IsVROfSequence(realVR) ) newEntry = NewSeqEntry(group, elem); - else if ( Global::GetVR()->IsVROfStringRepresentable(realVR) ) - newEntry = NewValEntry(group, elem, realVR); - else - newEntry = NewBinEntry(group, elem, realVR); + else + { + newEntry = NewDataEntry(group, elem, realVR); + static_cast(newEntry)->SetState(DataEntry::STATE_NOTLOADED); + } if ( vr == GDCM_UNKNOWN ) { diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 790291e9..977124ba 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2005/09/07 08:55:23 $ - Version: $Revision: 1.122 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.123 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -30,8 +30,6 @@ namespace gdcm { -class ValEntry; -class BinEntry; class SeqEntry; class Dict; @@ -92,7 +90,7 @@ typedef std::list ListElements; // Content entries virtual void LoadEntryBinArea(uint16_t group, uint16_t elem); - virtual void LoadEntryBinArea(BinEntry *entry); + virtual void LoadEntryBinArea(DataEntry *entry); void LoadDocEntrySafe(DocEntry *entry); void AddForceLoadElement(uint16_t group, uint16_t elem); @@ -196,9 +194,6 @@ private: std::string FindDocEntryVR(); bool CheckDocEntryVR (VRKey k); - std::string GetDocEntryValue (DocEntry *entry); - std::string GetDocEntryUnvalue(DocEntry *entry); - void SkipDocEntry (DocEntry *entry); void SkipToNextDocEntry (DocEntry *entry); diff --git a/src/gdcmElementSet.cxx b/src/gdcmElementSet.cxx index 8dddf320..0c662dd0 100644 --- a/src/gdcmElementSet.cxx +++ b/src/gdcmElementSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.cxx,v $ Language: C++ - Date: $Date: 2005/10/11 08:24:10 $ - Version: $Revision: 1.64 $ + Date: $Date: 2005/10/18 08:35:50 $ + 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 @@ -18,9 +18,8 @@ #include "gdcmElementSet.h" #include "gdcmDebug.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmSeqEntry.h" +#include "gdcmDataEntry.h" namespace gdcm { @@ -196,11 +195,11 @@ void ElementSet::Print(std::ostream &os, std::string const & ) { // Let's change the 'warning value' for Pixel Data, // to avoid human reader to be confused by 'gdcm::NotLoaded'. - gdcm::BinEntry *pixelElement = GetBinEntry(0x7fe0,0x0010); + DataEntry *pixelElement = GetDataEntry(0x7fe0,0x0010); if ( pixelElement != 0 ) { - pixelElement->SetValue( gdcm::GDCM_PIXELDATA); - } + pixelElement->SetFlag( DataEntry::FLAG_PIXELDATA ); + } for( TagDocEntryHT::const_iterator i = TagHT.begin(); i != TagHT.end(); ++i) { @@ -209,7 +208,7 @@ void ElementSet::Print(std::ostream &os, std::string const & ) entry->SetPrintLevel(PrintLevel); entry->Print(os); - if ( dynamic_cast(entry) ) + if ( dynamic_cast(entry) ) { // Avoid the newline for a sequence: continue; diff --git a/src/gdcmElementSet.h b/src/gdcmElementSet.h index fe681ee4..abb272e8 100644 --- a/src/gdcmElementSet.h +++ b/src/gdcmElementSet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmElementSet.h,v $ Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - Version: $Revision: 1.45 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.46 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -27,8 +27,6 @@ namespace gdcm { -class ValEntry; -class BinEntry; class SeqEntry; typedef std::map TagDocEntryHT; @@ -71,8 +69,6 @@ private: TagDocEntryHT TagHT; /// iterator, used to visit the TagHT variable TagDocEntryHT::iterator ItTagHT; - /// iterator, used to visit the TagHT variable, seeking only for ValEntries - TagDocEntryHT::iterator ItValEntryTagHT; }; } // end namespace gdcm //----------------------------------------------------------------------------- diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 68848968..066959ab 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2005/10/17 14:26:44 $ - Version: $Revision: 1.275 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.276 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -92,11 +92,10 @@ #include "gdcmUtil.h" #include "gdcmDebug.h" #include "gdcmTS.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmSeqEntry.h" #include "gdcmRLEFramesInfo.h" #include "gdcmJPEGFragmentsInfo.h" +#include "gdcmDataEntry.h" #include #include //sscanf @@ -168,7 +167,7 @@ bool File::DoTheLoadingJob( ) // Note: this IS the right place for the code // Image Location - const std::string &imgLocation = GetEntryValue(0x0028, 0x0200); + const std::string &imgLocation = GetEntryString(0x0028, 0x0200); if ( imgLocation == GDCM_UNFOUND ) { // default value @@ -213,11 +212,11 @@ bool File::DoTheLoadingJob( ) ComputeJPEGFragmentInfo(); CloseFile(); - // Create a new BinEntry to change the DictEntry + // Create a new DataEntry to change the DictEntry // The changed DictEntry will have // - a correct PixelVR OB or OW) // - the name to "Pixel Data" - BinEntry *oldEntry = dynamic_cast(entry); + DataEntry *oldEntry = dynamic_cast(entry); if (oldEntry) { std::string PixelVR; @@ -234,7 +233,7 @@ bool File::DoTheLoadingJob( ) DictEntry* newDict = NewVirtualDictEntry(GrPixel,NumPixel, PixelVR,"1","Pixel Data"); - BinEntry *newEntry = new BinEntry(newDict); + DataEntry *newEntry = new DataEntry(newDict); newEntry->Copy(entry); newEntry->SetBinArea(oldEntry->GetBinArea(),oldEntry->IsSelfArea()); oldEntry->SetSelfArea(false); @@ -261,7 +260,7 @@ bool File::IsReadable() return false; } - const std::string &res = GetEntryValue(0x0028, 0x0005); + const std::string &res = GetEntryString(0x0028, 0x0005); if ( res != GDCM_UNFOUND && atoi(res.c_str()) > 4 ) { gdcmWarningMacro("Wrong Image Dimensions" << res); @@ -318,7 +317,7 @@ bool File::IsReadable() int File::GetImageNumber() { //0020 0013 : Image Number - std::string strImNumber = GetEntryValue(0x0020,0x0013); + std::string strImNumber = GetEntryString(0x0020,0x0013); if ( strImNumber != GDCM_UNFOUND ) { return atoi( strImNumber.c_str() ); @@ -333,7 +332,7 @@ int File::GetImageNumber() ModalityType File::GetModality() { // 0008 0060 : Modality - std::string strModality = GetEntryValue(0x0008,0x0060); + std::string strModality = GetEntryString(0x0008,0x0060); if ( strModality != GDCM_UNFOUND ) { if ( strModality.find("AU") < strModality.length()) return AU; @@ -398,12 +397,10 @@ ModalityType File::GetModality() */ int File::GetXSize() { - const std::string &strSize = GetEntryValue(0x0028,0x0011); - if ( strSize == GDCM_UNFOUND ) - { - return 0; - } - return atoi( strSize.c_str() ); + DataEntry *entry = GetDataEntry(0x0028,0x0011); + if( entry ) + return (int)entry->GetValue(0); + return 0; } /** @@ -414,11 +411,10 @@ int File::GetXSize() */ int File::GetYSize() { - const std::string &strSize = GetEntryValue(0x0028,0x0010); - if ( strSize != GDCM_UNFOUND ) - { - return atoi( strSize.c_str() ); - } + DataEntry *entry = GetDataEntry(0x0028,0x0010); + if( entry ) + return (int)entry->GetValue(0); + if ( IsDicomV3() ) { return 0; @@ -442,18 +438,14 @@ int File::GetZSize() { // Both DicomV3 and ACR/Nema consider the "Number of Frames" // as the third dimension. - const std::string &strSize = GetEntryValue(0x0028,0x0008); - if ( strSize != GDCM_UNFOUND ) - { - return atoi( strSize.c_str() ); - } + DataEntry *entry = GetDataEntry(0x0028,0x0008); + if( entry ) + return (int)entry->GetValue(0); // We then consider the "Planes" entry as the third dimension - const std::string &strSize2 = GetEntryValue(0x0028,0x0012); - if ( strSize2 != GDCM_UNFOUND ) - { - return atoi( strSize2.c_str() ); - } + entry = GetDataEntry(0x0028,0x0012); + if( entry ) + return (int)entry->GetValue(0); return 1; } @@ -466,12 +458,31 @@ int File::GetZSize() float File::GetXSpacing() { float xspacing = 1.0; - float yspacing = 1.0; - int nbValues; + uint32_t nbValue; // To follow David Clunie's advice, we first check ImagerPixelSpacing - const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164); + DataEntry *entry = GetDataEntry(0x0018,0x1164); + if( entry ) + { + nbValue = entry->GetValueCount(); + if( nbValue >= 3 ) + xspacing = (float)entry->GetValue(2); + if( nbValue >= 2 ) + xspacing = (float)entry->GetValue(1); + else + xspacing = (float)entry->GetValue(0); + + if ( xspacing == 0.0 ) + xspacing = 1.0; + return xspacing; + } + else + { + gdcmWarningMacro( "Unfound Pixel Spacing (0018,1164)" ); + } + +/* const std::string &strImagerPixelSpacing = GetEntryString(0x0018,0x1164); if ( strImagerPixelSpacing != GDCM_UNFOUND ) { if ( ( nbValues = sscanf( strImagerPixelSpacing.c_str(), @@ -488,10 +499,29 @@ float File::GetXSpacing() xspacing = 1.0; } return xspacing; - } + }*/ + + entry = GetDataEntry(0x0028,0x0030); + if( entry ) + { + nbValue = entry->GetValueCount(); + if( nbValue >= 3 ) + xspacing = (float)entry->GetValue(2); + if( nbValue >= 2 ) + xspacing = (float)entry->GetValue(1); + else + xspacing = (float)entry->GetValue(0); - const std::string &strSpacing = GetEntryValue(0x0028,0x0030); + if ( xspacing == 0.0 ) + xspacing = 1.0; + return xspacing; + } + else + { + gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" ); + } +/* const std::string &strSpacing = GetEntryString(0x0028,0x0030); if ( strSpacing == GDCM_UNFOUND ) { gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" ); @@ -510,11 +540,12 @@ float File::GetXSpacing() if ( xspacing == 0.0 ) xspacing = 1.0; - } return xspacing; + }*/ + // to avoid troubles with David Clunie's-like images (at least one) - if ( xspacing == 0.0 && yspacing == 0.0) +/* if ( xspacing == 0.0 && yspacing == 0.0) return 1.0; if ( xspacing == 0.0) @@ -524,7 +555,7 @@ float File::GetXSpacing() nbValues = sscanf( strSpacing.c_str(), "%f \\0\\%f ", &yspacing, &xspacing); gdcmAssertMacro( nbValues == 2 ); } - +*/ return xspacing; } @@ -537,10 +568,22 @@ float File::GetXSpacing() float File::GetYSpacing() { float yspacing = 1.0; - int nbValues; // To follow David Clunie's advice, we first check ImagerPixelSpacing - const std::string &strImagerPixelSpacing = GetEntryValue(0x0018,0x1164); + DataEntry *entry = GetDataEntry(0x0018,0x1164); + if( entry ) + { + yspacing = (float)entry->GetValue(0); + + if ( yspacing == 0.0 ) + yspacing = 1.0; + return yspacing; + } + else + { + gdcmWarningMacro( "Unfound Pixel Spacing (0018,1164)" ); + } +/* const std::string &strImagerPixelSpacing = GetEntryString(0x0018,0x1164); if ( strImagerPixelSpacing != GDCM_UNFOUND ) { nbValues = sscanf( strImagerPixelSpacing.c_str(), "%f", &yspacing); @@ -553,9 +596,22 @@ float File::GetYSpacing() yspacing = 1.0; return yspacing; - } + }*/ - std::string strSpacing = GetEntryValue(0x0028,0x0030); + entry = GetDataEntry(0x0028,0x0030); + if( entry ) + { + yspacing = (float)entry->GetValue(0); + + if ( yspacing == 0.0 ) + yspacing = 1.0; + return yspacing; + } + else + { + gdcmWarningMacro( "Unfound Pixel Spacing (0028,0030)" ); + } +/* std::string strSpacing = GetEntryString(0x0028,0x0030); if ( strSpacing == GDCM_UNFOUND ) { gdcmWarningMacro("Unfound Pixel Spacing (0028,0030)"); @@ -570,7 +626,7 @@ float File::GetYSpacing() yspacing = 1.0; if ( yspacing == 0.0 ) - yspacing = 1.0; + yspacing = 1.0;*/ return yspacing; } @@ -583,6 +639,17 @@ float File::GetYSpacing() */ float File::GetZSpacing() { + // ---> + // ---> Warning : + // ---> + // For *Dicom* images, ZSpacing should be calculated using + // XOrigin, YOrigin, ZOrigin (of the top left image corner) + // of 2 consecutive images, and the Orientation + // + // Computing ZSpacing on a single image is not really meaningfull ! + + float zspacing = 1.0f; + // Spacing Between Slices : distance between the middle of 2 slices // Slices may be : // jointives (Spacing between Slices = Slice Thickness) @@ -592,24 +659,41 @@ float File::GetZSpacing() // It only concerns the MRI guys, not people wanting to visualize volumes // If Spacing Between Slices is missing, // we suppose slices joint together + DataEntry *entry = GetDataEntry(0x0018,0x0088); + if( entry ) + { + zspacing = (float)entry->GetValue(0); - // ---> - // ---> Warning : - // ---> - - // - // For *Dicom* images, ZSpacing should be calculated using - // XOrigin, YOrigin, ZOrigin (of the top left image corner) - // of 2 consecutive images, and the Orientation - // - // Computing ZSpacing on a single image is not really meaningfull ! - - const std::string &strSpacingBSlices = GetEntryValue(0x0018,0x0088); + if ( zspacing == 0.0 ) + zspacing = 1.0; + return zspacing; + } + else + gdcmWarningMacro("Unfound Spacing Between Slices (0018,0088)"); + // if no 'Spacing Between Slices' is found, + // we assume slices join together + // (no overlapping, no interslice gap) + // if they don't, we're fucked up + entry = GetDataEntry(0x0018,0x0050); + if( entry ) + { + zspacing = (float)entry->GetValue(0); + + if ( zspacing == 0.0 ) + zspacing = 1.0; + return zspacing; + } + else + gdcmWarningMacro("Unfound Slice Thickness (0018,0050)"); + + return zspacing; + +/* const std::string &strSpacingBSlices = GetEntryString(0x0018,0x0088); if ( strSpacingBSlices == GDCM_UNFOUND ) { gdcmWarningMacro("Unfound Spacing Between Slices (0018,0088)"); - const std::string &strSliceThickness = GetEntryValue(0x0018,0x0050); + const std::string &strSliceThickness = GetEntryString(0x0018,0x0050); if ( strSliceThickness == GDCM_UNFOUND ) { gdcmWarningMacro("Unfound Slice Thickness (0018,0050)"); @@ -624,12 +708,11 @@ float File::GetZSpacing() return (float)atof( strSliceThickness.c_str() ); } } - //else float zsp = (float)atof( strSpacingBSlices.c_str()); if (zsp == 0.0) // last change not to break further computations ... zsp = 1.0; - return zsp; + return zsp;*/ } /** @@ -640,13 +723,27 @@ float File::GetZSpacing() */ float File::GetXOrigin() { - float xImPos, yImPos, zImPos; - std::string strImPos = GetEntryValue(0x0020,0x0032); + DataEntry *entry = GetDataEntry(0x0020,0x0032); + if( !entry ) + { + gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)"); + entry = GetDataEntry(0x0020,0x0030); + if( !entry ) + { + gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)"); + return 0.0f; + } + } + + if( entry->GetValueCount() == 3 ) + return (float)entry->GetValue(0); + return 0.0f; +/* std::string strImPos = GetEntryString(0x0020,0x0032); if ( strImPos == GDCM_UNFOUND ) { gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)"); - strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images + strImPos = GetEntryString(0x0020,0x0030); // For ACR-NEMA images if ( strImPos == GDCM_UNFOUND ) { gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)"); @@ -659,7 +756,7 @@ float File::GetXOrigin() return 0.0; } - return xImPos; + return xImPos;*/ } /** @@ -670,13 +767,28 @@ float File::GetXOrigin() */ float File::GetYOrigin() { - float xImPos, yImPos, zImPos; - std::string strImPos = GetEntryValue(0x0020,0x0032); + DataEntry *entry = GetDataEntry(0x0020,0x0032); + if( !entry ) + { + gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)"); + entry = GetDataEntry(0x0020,0x0030); + if( !entry ) + { + gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)"); + return 0.0f; + } + } + + if( entry->GetValueCount() == 3 ) + return (float)entry->GetValue(1); + return 0.0f; +/* float xImPos, yImPos, zImPos; + std::string strImPos = GetEntryString(0x0020,0x0032); if ( strImPos == GDCM_UNFOUND) { gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)"); - strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images + strImPos = GetEntryString(0x0020,0x0030); // For ACR-NEMA images if ( strImPos == GDCM_UNFOUND ) { gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)"); @@ -689,7 +801,7 @@ float File::GetYOrigin() return 0.; } - return yImPos; + return yImPos;*/ } /** @@ -702,8 +814,16 @@ float File::GetYOrigin() */ float File::GetZOrigin() { - float xImPos, yImPos, zImPos; - std::string strImPos = GetEntryValue(0x0020,0x0032); + DataEntry *entry = GetDataEntry(0x0020,0x0032); + if( entry ) + { + if( entry->GetValueCount() == 3 ) + return (float)entry->GetValue(0); + gdcmWarningMacro( "Wrong Image Position Patient (0020,0032)"); + return 0.0f; + } +/* float xImPos, yImPos, zImPos; + std::string strImPos = GetEntryString(0x0020,0x0032); if ( strImPos != GDCM_UNFOUND ) { @@ -716,9 +836,17 @@ float File::GetZOrigin() { return zImPos; } - } + }*/ - strImPos = GetEntryValue(0x0020,0x0030); // For ACR-NEMA images + entry = GetDataEntry(0x0020,0x0030); + if( entry ) + { + if( entry->GetValueCount() == 3 ) + return (float)entry->GetValue(0); + gdcmWarningMacro( "Wrong Image Position (RET) (0020,0030)"); + return 0.0f; + } +/* strImPos = GetEntryString(0x0020,0x0030); // For ACR-NEMA images if ( strImPos != GDCM_UNFOUND ) { if ( sscanf( strImPos.c_str(), @@ -731,10 +859,18 @@ float File::GetZOrigin() { return zImPos; } - } + }*/ // for *very* old ACR-NEMA images - std::string strSliceLocation = GetEntryValue(0x0020,0x1041); + entry = GetDataEntry(0x0020,0x1041); + if( entry ) + { + if( entry->GetValueCount() == 1 ) + return (float)entry->GetValue(0); + gdcmWarningMacro( "Wrong Slice Location (0020,1041)"); + return 0.0f; + } +/* std::string strSliceLocation = GetEntryString(0x0020,0x1041); if ( strSliceLocation != GDCM_UNFOUND ) { if ( sscanf( strSliceLocation.c_str(), "%f ", &zImPos) != 1) @@ -747,9 +883,18 @@ float File::GetZOrigin() return zImPos; } } - gdcmWarningMacro( "Unfound Slice Location (0020,1041)"); + gdcmWarningMacro( "Unfound Slice Location (0020,1041)");*/ - std::string strLocation = GetEntryValue(0x0020,0x0050); + entry = GetDataEntry(0x0020,0x0050); + if( entry ) + { + gdcmWarningMacro( "Unfound Location (0020,0050)"); + if( entry->GetValueCount() == 1 ) + return (float)entry->GetValue(0); + gdcmWarningMacro( "Wrong Location (0020,0050)"); + return 0.0f; + } +/* std::string strLocation = GetEntryString(0x0020,0x0050); if ( strLocation != GDCM_UNFOUND ) { if ( sscanf( strLocation.c_str(), "%f ", &zImPos) != 1 ) @@ -762,7 +907,7 @@ float File::GetZOrigin() return zImPos; } } - gdcmWarningMacro( "Unfound Location (0020,0050)"); + gdcmWarningMacro( "Unfound Location (0020,0050)");*/ return 0.; // Hopeless } @@ -782,7 +927,7 @@ bool File::GetImageOrientationPatient( float iop[6] ) iop[0] = iop[1] = iop[2] = iop[3] = iop[4] = iop[5] = 0.; // 0020 0037 DS REL Image Orientation (Patient) - if ( (strImOriPat = GetEntryValue(0x0020,0x0037)) != GDCM_UNFOUND ) + if ( (strImOriPat = GetEntryString(0x0020,0x0037)) != GDCM_UNFOUND ) { if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ", &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 ) @@ -794,7 +939,7 @@ bool File::GetImageOrientationPatient( float iop[6] ) } //For ACR-NEMA // 0020 0035 DS REL Image Orientation (RET) - else if ( (strImOriPat = GetEntryValue(0x0020,0x0035)) != GDCM_UNFOUND ) + else if ( (strImOriPat = GetEntryString(0x0020,0x0035)) != GDCM_UNFOUND ) { if ( sscanf( strImOriPat.c_str(), "%f \\ %f \\%f \\%f \\%f \\%f ", &iop[0], &iop[1], &iop[2], &iop[3], &iop[4], &iop[5]) != 6 ) @@ -817,14 +962,22 @@ bool File::GetImageOrientationPatient( float iop[6] ) */ int File::GetBitsStored() { - std::string strSize = GetEntryValue( 0x0028, 0x0101 ); + DataEntry *entry = GetDataEntry(0x0028,0x0101); + if( !entry ) + { + gdcmWarningMacro("(0028,0101) is supposed to be mandatory"); + return 0; + } + return (int)entry->GetValue(0); + +/* std::string strSize = GetEntryString( 0x0028, 0x0101 ); if ( strSize == GDCM_UNFOUND ) { gdcmWarningMacro("(0028,0101) is supposed to be mandatory"); return 0; // It's supposed to be mandatory // the caller will have to check } - return atoi( strSize.c_str() ); + return atoi( strSize.c_str() );*/ } /** @@ -835,14 +988,22 @@ int File::GetBitsStored() */ int File::GetBitsAllocated() { - std::string strSize = GetEntryValue(0x0028,0x0100); + DataEntry *entry = GetDataEntry(0x0028,0x0100); + if( !entry ) + { + gdcmWarningMacro("(0028,0100) is supposed to be mandatory"); + return 0; + } + return (int)entry->GetValue(0); + +/* std::string strSize = GetEntryString(0x0028,0x0100); if ( strSize == GDCM_UNFOUND ) { gdcmWarningMacro( "(0028,0100) is supposed to be mandatory"); return 0; // It's supposed to be mandatory // the caller will have to check } - return atoi( strSize.c_str() ); + return atoi( strSize.c_str() );*/ } /** @@ -853,13 +1014,21 @@ int File::GetBitsAllocated() */ int File::GetHighBitPosition() { - std::string strSize = GetEntryValue( 0x0028, 0x0102 ); + DataEntry *entry = GetDataEntry(0x0028,0x0102); + if( !entry ) + { + gdcmWarningMacro("(0028,0102) is supposed to be mandatory"); + return 0; + } + return (int)entry->GetValue(0); + +/* std::string strSize = GetEntryString( 0x0028, 0x0102 ); if ( strSize == GDCM_UNFOUND ) { gdcmWarningMacro( "(0028,0102) is supposed to be mandatory"); return 0; } - return atoi( strSize.c_str() ); + return atoi( strSize.c_str() );*/ } /** @@ -870,14 +1039,23 @@ int File::GetHighBitPosition() */ int File::GetSamplesPerPixel() { - const std::string &strSize = GetEntryValue(0x0028,0x0002); + DataEntry *entry = GetDataEntry(0x0028,0x0002); + if( !entry ) + { + gdcmWarningMacro("(0028,0002) is supposed to be mandatory"); + return 1; // Well, it's supposed to be mandatory ... + // but sometimes it's missing : *we* assume Gray pixels + } + return (int)entry->GetValue(0); + +/* const std::string &strSize = GetEntryString(0x0028,0x0002); if ( strSize == GDCM_UNFOUND ) { gdcmWarningMacro( "(0028,0002) is supposed to be mandatory"); return 1; // Well, it's supposed to be mandatory ... // but sometimes it's missing : *we* assume Gray pixels } - return atoi( strSize.c_str() ); + return atoi( strSize.c_str() );*/ } /** @@ -887,13 +1065,21 @@ int File::GetSamplesPerPixel() */ int File::GetPlanarConfiguration() { - std::string strSize = GetEntryValue(0x0028,0x0006); + DataEntry *entry = GetDataEntry(0x0028,0x0006); + if( !entry ) + { + gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)"); + return 0; + } + return (int)entry->GetValue(0); + +/* std::string strSize = GetEntryString(0x0028,0x0006); if ( strSize == GDCM_UNFOUND ) { gdcmWarningMacro( "Not found : Planar Configuration (0028,0006)"); return 0; } - return atoi( strSize.c_str() ); + return atoi( strSize.c_str() );*/ } /** @@ -905,9 +1091,7 @@ int File::GetPixelSize() { // 0028 0100 US IMG Bits Allocated // (in order no to be messed up by old ACR-NEMA RGB images) - // if (File::GetEntryValue(0x0028,0x0100) == "24") - // return 3; - assert( !(GetEntryValue(0x0028,0x0100) == "24") ); + assert( !(GetEntryString(0x0028,0x0100) == "24") ); std::string pixelType = GetPixelType(); if ( pixelType == "8U" || pixelType == "8S" ) @@ -926,7 +1110,7 @@ int File::GetPixelSize() { return 8; } - gdcmWarningMacro( "Unknown pixel type"); + gdcmWarningMacro( "Unknown pixel type: " << pixelType); return 0; } @@ -947,7 +1131,7 @@ int File::GetPixelSize() */ std::string File::GetPixelType() { - std::string bitsAlloc = GetEntryValue(0x0028, 0x0100); // Bits Allocated + std::string bitsAlloc = GetEntryString(0x0028, 0x0100); // Bits Allocated if ( bitsAlloc == GDCM_UNFOUND ) { gdcmWarningMacro( "Missing Bits Allocated (0028,0100)"); @@ -969,7 +1153,39 @@ std::string File::GetPixelType() bitsAlloc = "8"; } - std::string sign = GetEntryValue(0x0028, 0x0103);//"Pixel Representation" + std::string sign; + if( IsSignedPixelData() ) + { + sign = "S"; + } + else + { + sign = "U"; + } + +/* std::string bitsAlloc = GetEntryString(0x0028, 0x0100); // Bits Allocated + if ( bitsAlloc == GDCM_UNFOUND ) + { + gdcmWarningMacro( "Missing Bits Allocated (0028,0100)"); + bitsAlloc = "16"; // default and arbitrary value, not to polute the output + } + + if ( bitsAlloc == "64" ) + { + return "FD"; + } + else if ( bitsAlloc == "12" ) + { + // It will be unpacked + bitsAlloc = "16"; + } + else if ( bitsAlloc == "24" ) + { + // (in order no to be messed up by old RGB images) + bitsAlloc = "8"; + } + + std::string sign = GetEntryString(0x0028, 0x0103);//"Pixel Representation" if (sign == GDCM_UNFOUND ) { @@ -983,7 +1199,7 @@ std::string File::GetPixelType() else { sign = "S"; - } + }*/ return bitsAlloc + sign; } @@ -997,7 +1213,14 @@ std::string File::GetPixelType() */ bool File::IsSignedPixelData() { - std::string strSign = GetEntryValue( 0x0028, 0x0103 ); + DataEntry *entry = GetDataEntry(0x0028, 0x0103);//"Pixel Representation" + if( !entry ) + { + gdcmWarningMacro( "Missing Pixel Representation (0028,0103)"); + return false; + } + return entry->GetValue(0) != 0; +/* std::string strSign = GetEntryString( 0x0028, 0x0103 ); if ( strSign == GDCM_UNFOUND ) { gdcmWarningMacro( "(0028,0103) is supposed to be mandatory"); @@ -1008,7 +1231,7 @@ bool File::IsSignedPixelData() { return false; } - return true; + return true;*/ } /** @@ -1018,7 +1241,7 @@ bool File::IsSignedPixelData() */ bool File::IsMonochrome() { - const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 ); + const std::string &PhotometricInterp = GetEntryString( 0x0028, 0x0004 ); if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") || Util::DicomStringEqual(PhotometricInterp, "MONOCHROME2") ) { @@ -1038,7 +1261,7 @@ bool File::IsMonochrome() */ bool File::IsMonochrome1() { - const std::string &PhotometricInterp = GetEntryValue( 0x0028, 0x0004 ); + const std::string &PhotometricInterp = GetEntryString( 0x0028, 0x0004 ); if ( Util::DicomStringEqual(PhotometricInterp, "MONOCHROME1") ) { return true; @@ -1057,7 +1280,7 @@ bool File::IsMonochrome1() */ bool File::IsPaletteColor() { - std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 ); + std::string PhotometricInterp = GetEntryString( 0x0028, 0x0004 ); if ( PhotometricInterp == "PALETTE COLOR " ) { return true; @@ -1076,7 +1299,7 @@ bool File::IsPaletteColor() */ bool File::IsYBRFull() { - std::string PhotometricInterp = GetEntryValue( 0x0028, 0x0004 ); + std::string PhotometricInterp = GetEntryString( 0x0028, 0x0004 ); if ( PhotometricInterp == "YBR_FULL" ) { return true; @@ -1150,7 +1373,7 @@ int File::GetLUTNbits() //Just hope Lookup Table Desc-Red = Lookup Table Desc-Red // = Lookup Table Desc-Blue // Consistency already checked in GetLUTLength - std::string lutDescription = GetEntryValue(0x0028,0x1101); + std::string lutDescription = GetEntryString(0x0028,0x1101); if ( lutDescription == GDCM_UNFOUND ) { return 0; @@ -1173,9 +1396,18 @@ int File::GetLUTNbits() */ float File::GetRescaleIntercept() { - float resInter = 0.; + // 0028 1052 DS IMG Rescale Intercept + DataEntry *entry = GetDataEntry(0x0028, 0x1052); + if( !entry ) + { + gdcmWarningMacro( "Missing Rescale Intercept (0028,1052)"); + return 0.0f; + } + return (float)entry->GetValue(0); + +/* float resInter = 0.; /// 0028 1052 DS IMG Rescale Intercept - const std::string &strRescInter = GetEntryValue(0x0028,0x1052); + const std::string &strRescInter = GetEntryString(0x0028,0x1052); if ( strRescInter != GDCM_UNFOUND ) { if ( sscanf( strRescInter.c_str(), "%f ", &resInter) != 1 ) @@ -1185,7 +1417,7 @@ float File::GetRescaleIntercept() } } - return resInter; + return resInter;*/ } /** @@ -1194,9 +1426,17 @@ float File::GetRescaleIntercept() */ float File::GetRescaleSlope() { - float resSlope = 1.; + // 0028 1053 DS IMG Rescale Slope + DataEntry *entry = GetDataEntry(0x0028, 0x1053); + if( !entry ) + { + gdcmWarningMacro( "Missing Rescale Slope (0028,1053)"); + return 1.0f; + } + return (float)entry->GetValue(0); +/* float resSlope = 1.; //0028 1053 DS IMG Rescale Slope - std::string strRescSlope = GetEntryValue(0x0028,0x1053); + std::string strRescSlope = GetEntryString(0x0028,0x1053); if ( strRescSlope != GDCM_UNFOUND ) { if ( sscanf( strRescSlope.c_str(), "%f ", &resSlope) != 1 ) @@ -1206,7 +1446,7 @@ float File::GetRescaleSlope() } } - return resSlope; + return resSlope;*/ } /** @@ -1222,15 +1462,15 @@ int File::GetNumberOfScalarComponents() { return 3; } - + // 0028 0100 US IMG Bits Allocated // (in order no to be messed up by old RGB images) - if ( GetEntryValue(0x0028,0x0100) == "24" ) + if ( GetEntryString(0x0028,0x0100) == "24" ) { return 3; } - - std::string strPhotometricInterpretation = GetEntryValue(0x0028,0x0004); + + std::string strPhotometricInterpretation = GetEntryString(0x0028,0x0004); if ( ( strPhotometricInterpretation == "PALETTE COLOR ") ) { @@ -1270,7 +1510,7 @@ int File::GetNumberOfScalarComponentsRaw() { // 0028 0100 US IMG Bits Allocated // (in order no to be messed up by old RGB images) - if ( File::GetEntryValue(0x0028,0x0100) == "24" ) + if ( File::GetEntryString(0x0028,0x0100) == "24" ) { return 3; } @@ -1384,7 +1624,7 @@ void File::AnonymizeNoLoad() /** * \brief anonymize a File (remove Patient's personal info passed with * AddAnonymizeElement() - * \note You cannot Anonymize a BinEntry (to be fixed) + * \note You cannot Anonymize a DataEntry (to be fixed) */ bool File::AnonymizeFile() { @@ -1392,22 +1632,22 @@ bool File::AnonymizeFile() if ( UserAnonymizeList.begin() == UserAnonymizeList.end() ) { // If exist, replace by spaces - SetValEntry (" ",0x0010, 0x2154); // Telephone - SetValEntry (" ",0x0010, 0x1040); // Adress - SetValEntry (" ",0x0010, 0x0020); // Patient ID + SetEntryString(" ",0x0010, 0x2154); // Telephone + SetEntryString(" ",0x0010, 0x1040); // Adress + SetEntryString(" ",0x0010, 0x0020); // Patient ID - DocEntry* patientNameHE = GetDocEntry (0x0010, 0x0010); + DocEntry *patientNameHE = GetDocEntry (0x0010, 0x0010); if ( patientNameHE ) // we replace it by Study Instance UID (why not ?) { - std::string studyInstanceUID = GetEntryValue (0x0020, 0x000d); + std::string studyInstanceUID = GetEntryString (0x0020, 0x000d); if ( studyInstanceUID != GDCM_UNFOUND ) { - SetValEntry(studyInstanceUID, 0x0010, 0x0010); + SetEntryString(studyInstanceUID, 0x0010, 0x0010); } else { - SetValEntry("anonymized", 0x0010, 0x0010); + SetEntryString("anonymized", 0x0010, 0x0010); } } } @@ -1429,13 +1669,13 @@ bool File::AnonymizeFile() continue; } - if ( dynamic_cast(d) ) + if ( dynamic_cast(d) ) { - gdcmWarningMacro( "To 'Anonymize' a BinEntry, better use AnonymizeNoLoad (FIXME) "); + gdcmWarningMacro( "To 'Anonymize' a DataEntry, better use AnonymizeNoLoad (FIXME) "); continue; } else - SetValEntry ((*it).Value, (*it).Group, (*it).Elem); + SetEntryString ((*it).Value, (*it).Group, (*it).Elem); } } @@ -1513,12 +1753,12 @@ bool File::Write(std::string fileName, FileType writetype) } // Entry : 0002|0000 = group length -> recalculated - ValEntry*e0000 = GetValEntry(0x0002,0x0000); + DataEntry *e0000 = GetDataEntry(0x0002,0x0000); if ( e0000 ) { std::ostringstream sLen; sLen << ComputeGroup0002Length( ); - e0000->SetValue(sLen.str()); + e0000->SetString(sLen.str()); } int i_lgPix = GetEntryLength(GrPixel, NumPixel); @@ -1527,7 +1767,7 @@ bool File::Write(std::string fileName, FileType writetype) // no (GrPixel, NumPixel) element std::string s_lgPix = Util::Format("%d", i_lgPix+12); s_lgPix = Util::DicomString( s_lgPix.c_str() ); - InsertValEntry(s_lgPix,GrPixel, 0x0000); + InsertEntryString(s_lgPix,GrPixel, 0x0000); } Document::WriteContent(fp, writetype); diff --git a/src/gdcmFileHelper.cxx b/src/gdcmFileHelper.cxx index 9090bda6..86405421 100644 --- a/src/gdcmFileHelper.cxx +++ b/src/gdcmFileHelper.cxx @@ -4,8 +4,8 @@ Module: $RCSfile: gdcmFileHelper.cxx,v $ Language: C++ - Date: $Date: 2005/10/07 09:54:53 $ - Version: $Revision: 1.59 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.60 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -23,11 +23,9 @@ #include "gdcmDocument.h" #include "gdcmDebug.h" #include "gdcmUtil.h" -#include "gdcmBinEntry.h" -#include "gdcmValEntry.h" #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmContentEntry.h" +#include "gdcmDataEntry.h" #include "gdcmFile.h" #include "gdcmPixelReadConvert.h" #include "gdcmPixelWriteConvert.h" @@ -267,10 +265,10 @@ bool FileHelper::Load() * @param elem element number of the Dicom Element to modify * \return false if DocEntry not found */ -bool FileHelper::SetValEntry(std::string const &content, - uint16_t group, uint16_t elem) +bool FileHelper::SetEntryString(std::string const &content, + uint16_t group, uint16_t elem) { - return FileInternal->SetValEntry(content, group, elem); + return FileInternal->SetEntryString(content, group, elem); } @@ -284,10 +282,10 @@ bool FileHelper::SetValEntry(std::string const &content, * @param elem element number of the Dicom Element to modify * \return false if DocEntry not found */ -bool FileHelper::SetBinEntry(uint8_t *content, int lgth, - uint16_t group, uint16_t elem) +bool FileHelper::SetEntryBinArea(uint8_t *content, int lgth, + uint16_t group, uint16_t elem) { - return FileInternal->SetBinEntry(content, lgth, group, elem); + return FileInternal->SetEntryBinArea(content, lgth, group, elem); } /** @@ -299,10 +297,10 @@ bool FileHelper::SetBinEntry(uint8_t *content, int lgth, * \return pointer to the modified/created Dicom entry (NULL when creation * failed). */ -ValEntry *FileHelper::InsertValEntry(std::string const &content, - uint16_t group, uint16_t elem) +DataEntry *FileHelper::InsertEntryString(std::string const &content, + uint16_t group, uint16_t elem) { - return FileInternal->InsertValEntry(content, group, elem); + return FileInternal->InsertEntryString(content, group, elem); } /** @@ -316,10 +314,10 @@ ValEntry *FileHelper::InsertValEntry(std::string const &content, * \return pointer to the modified/created Dicom entry (NULL when creation * failed). */ -BinEntry *FileHelper::InsertBinEntry(uint8_t *binArea, int lgth, - uint16_t group, uint16_t elem) +DataEntry *FileHelper::InsertEntryBinArea(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem) { - return FileInternal->InsertBinEntry(binArea, lgth, group, elem); + return FileInternal->InsertEntryBinArea(binArea, lgth, group, elem); } /** @@ -705,8 +703,8 @@ bool FileHelper::Write(std::string const &fileName) // and forgets to create any Entry belonging to group 0008 // (shame on him !) // We add Recognition Code (RET) - if ( ! FileInternal->GetValEntry(0x0008, 0x0010) ) - FileInternal->InsertValEntry("", 0x0008, 0x0010); + if ( ! FileInternal->GetDataEntry(0x0008, 0x0010) ) + FileInternal->InsertEntryString("", 0x0008, 0x0010); SetWriteFileTypeToACR(); // SetWriteFileTypeToImplicitVR(); // ACR IS implicit VR ! break; @@ -816,7 +814,8 @@ bool FileHelper::CheckWriteIntegrity() } break; } - } + } + return true; } @@ -834,14 +833,14 @@ void FileHelper::SetWriteToRaw() } else { - ValEntry *photInt = CopyValEntry(0x0028,0x0004); + DataEntry *photInt = CopyDataEntry(0x0028,0x0004); if (FileInternal->HasLUT() ) { - photInt->SetValue("PALETTE COLOR "); + photInt->SetString("PALETTE COLOR "); } else { - photInt->SetValue("MONOCHROME2 "); + photInt->SetString("MONOCHROME2 "); } PixelWriteConverter->SetReadData(PixelReadConverter->GetRaw(), @@ -852,9 +851,9 @@ void FileHelper::SetWriteToRaw() vr = "OW"; if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files vr = "OB"; - BinEntry *pixel = - CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr); - pixel->SetValue(GDCM_BINLOADED); + DataEntry *pixel = + CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr); + pixel->SetFlag(DataEntry::FLAG_PIXELDATA); pixel->SetBinArea(PixelWriteConverter->GetData(),false); pixel->SetLength(PixelWriteConverter->GetDataSize()); @@ -876,14 +875,14 @@ void FileHelper::SetWriteToRGB() { PixelReadConverter->BuildRGBImage(); - ValEntry *spp = CopyValEntry(0x0028,0x0002); - spp->SetValue("3 "); + DataEntry *spp = CopyDataEntry(0x0028,0x0002); + spp->SetString("3 "); - ValEntry *planConfig = CopyValEntry(0x0028,0x0006); - planConfig->SetValue("0 "); + DataEntry *planConfig = CopyDataEntry(0x0028,0x0006); + planConfig->SetString("0 "); - ValEntry *photInt = CopyValEntry(0x0028,0x0004); - photInt->SetValue("RGB "); + DataEntry *photInt = CopyDataEntry(0x0028,0x0004); + photInt->SetString("RGB "); if ( PixelReadConverter->GetRGB() ) { @@ -901,9 +900,9 @@ void FileHelper::SetWriteToRGB() vr = "OW"; if ( FileInternal->GetBitsAllocated()==24 ) // For RGB ACR files vr = "OB"; - BinEntry *pixel = - CopyBinEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr); - pixel->SetValue(GDCM_BINLOADED); + DataEntry *pixel = + CopyDataEntry(GetFile()->GetGrPixel(),GetFile()->GetNumPixel(),vr); + pixel->SetFlag(DataEntry::FLAG_PIXELDATA); pixel->SetBinArea(PixelWriteConverter->GetData(),false); pixel->SetLength(PixelWriteConverter->GetDataSize()); @@ -928,14 +927,14 @@ void FileHelper::SetWriteToRGB() // samples per pixels = 1 (in the read file) if ( FileInternal->GetBitsAllocated()==24 ) { - ValEntry *bitsAlloc = CopyValEntry(0x0028,0x0100); - bitsAlloc->SetValue("8 "); + DataEntry *bitsAlloc = CopyDataEntry(0x0028,0x0100); + bitsAlloc->SetString("8 "); - ValEntry *bitsStored = CopyValEntry(0x0028,0x0101); - bitsStored->SetValue("8 "); + DataEntry *bitsStored = CopyDataEntry(0x0028,0x0101); + bitsStored->SetString("8 "); - ValEntry *highBit = CopyValEntry(0x0028,0x0102); - highBit->SetValue("7 "); + DataEntry *highBit = CopyDataEntry(0x0028,0x0102); + highBit->SetString("7 "); Archive->Push(bitsAlloc); Archive->Push(bitsStored); @@ -1017,8 +1016,8 @@ void FileHelper::SetWriteFileTypeToExplicitVR() std::string ts = Util::DicomString( Global::GetTS()->GetSpecialTransferSyntax(TS::ExplicitVRLittleEndian) ); - ValEntry *tss = CopyValEntry(0x0002,0x0010); - tss->SetValue(ts); + DataEntry *tss = CopyDataEntry(0x0002,0x0010); + tss->SetString(ts); Archive->Push(tss); } @@ -1031,8 +1030,8 @@ void FileHelper::SetWriteFileTypeToImplicitVR() std::string ts = Util::DicomString( Global::GetTS()->GetSpecialTransferSyntax(TS::ImplicitVRLittleEndian) ); - ValEntry *tss = CopyValEntry(0x0002,0x0010); - tss->SetValue(ts); + DataEntry *tss = CopyDataEntry(0x0002,0x0010); + tss->SetString(ts); Archive->Push(tss); } @@ -1050,30 +1049,28 @@ void FileHelper::RestoreWriteFileType() */ void FileHelper::SetWriteToLibido() { - ValEntry *oldRow = dynamic_cast - (FileInternal->GetDocEntry(0x0028, 0x0010)); - ValEntry *oldCol = dynamic_cast - (FileInternal->GetDocEntry(0x0028, 0x0011)); + DataEntry *oldRow = FileInternal->GetDataEntry(0x0028, 0x0010); + DataEntry *oldCol = FileInternal->GetDataEntry(0x0028, 0x0011); if ( oldRow && oldCol ) { std::string rows, columns; - ValEntry *newRow=new ValEntry(oldRow->GetDictEntry()); - ValEntry *newCol=new ValEntry(oldCol->GetDictEntry()); + DataEntry *newRow=new DataEntry(oldRow->GetDictEntry()); + DataEntry *newCol=new DataEntry(oldCol->GetDictEntry()); newRow->Copy(oldCol); newCol->Copy(oldRow); - newRow->SetValue(oldCol->GetValue()); - newCol->SetValue(oldRow->GetValue()); + newRow->SetString(oldCol->GetString()); + newCol->SetString(oldRow->GetString()); Archive->Push(newRow); Archive->Push(newCol); } - ValEntry *libidoCode = CopyValEntry(0x0008,0x0010); - libidoCode->SetValue("ACRNEMA_LIBIDO_1.1"); + DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010); + libidoCode->SetString("ACRNEMA_LIBIDO_1.1"); Archive->Push(libidoCode); } @@ -1082,14 +1079,13 @@ void FileHelper::SetWriteToLibido() */ void FileHelper::SetWriteToNoLibido() { - ValEntry *recCode = dynamic_cast - (FileInternal->GetDocEntry(0x0008,0x0010)); + DataEntry *recCode = FileInternal->GetDataEntry(0x0008,0x0010); if ( recCode ) { - if ( recCode->GetValue() == "ACRNEMA_LIBIDO_1.1" ) + if ( recCode->GetString() == "ACRNEMA_LIBIDO_1.1" ) { - ValEntry *libidoCode = CopyValEntry(0x0008,0x0010); - libidoCode->SetValue(""); + DataEntry *libidoCode = CopyDataEntry(0x0008,0x0010); + libidoCode->SetString(""); Archive->Push(libidoCode); } } @@ -1112,55 +1108,31 @@ void FileHelper::RestoreWriteOfLibido() } /** - * \brief Duplicates a ValEntry or creates it. - * @param group Group number of the Entry - * @param elem Element number of the Entry - * \return pointer to the new Val Entry (NULL when creation failed). - */ -ValEntry *FileHelper::CopyValEntry(uint16_t group, uint16_t elem) -{ - DocEntry *oldE = FileInternal->GetDocEntry(group, elem); - ValEntry *newE; - - if ( oldE ) - { - newE = new ValEntry(oldE->GetDictEntry()); - newE->Copy(oldE); - } - else - { - newE = GetFile()->NewValEntry(group, elem); - } - - return newE; -} - -/** - * \brief Duplicates a BinEntry or creates it. + * \brief Duplicates a DataEntry or creates it. * @param group Group number of the Entry * @param elem Element number of the Entry * @param vr Value Representation of the Entry * FIXME : what is it used for? * \return pointer to the new Bin Entry (NULL when creation failed). */ -BinEntry *FileHelper::CopyBinEntry(uint16_t group, uint16_t elem, - const std::string &vr) +DataEntry *FileHelper::CopyDataEntry(uint16_t group, uint16_t elem, + const TagName &vr) { DocEntry *oldE = FileInternal->GetDocEntry(group, elem); - BinEntry *newE; + DataEntry *newE; - if ( oldE ) + if ( oldE && vr != GDCM_UNKNOWN ) if ( oldE->GetVR()!=vr ) oldE = NULL; if ( oldE ) { - newE = new BinEntry(oldE->GetDictEntry()); + newE = new DataEntry(oldE->GetDictEntry()); newE->Copy(oldE); } else { - newE = GetFile()->NewBinEntry(group, elem, vr); + newE = GetFile()->NewDataEntry(group, elem, vr); } return newE; @@ -1213,43 +1185,28 @@ void FileHelper::CheckMandatoryElements() // Create them if not found // Always modify the value // Push the entries to the archive. - ValEntry *e_0002_0000 = CopyValEntry(0x0002,0x0000); - e_0002_0000->SetValue("0"); // for the moment - Archive->Push(e_0002_0000); + CopyMandatoryEntry(0x0002,0x0000,"0"); - BinEntry *e_0002_0001 = CopyBinEntry(0x0002,0x0001, "OB"); + DataEntry *e_0002_0001 = CopyDataEntry(0x0002,0x0001, "OB"); e_0002_0001->SetBinArea((uint8_t*)Util::GetFileMetaInformationVersion(), false); e_0002_0001->SetLength(2); Archive->Push(e_0002_0001); // 'Media Stored SOP Class UID' - ValEntry *e_0002_0002 = CopyValEntry(0x0002,0x0002); // [Secondary Capture Image Storage] - e_0002_0002->SetValue("1.2.840.10008.5.1.4.1.1.7"); - Archive->Push(e_0002_0002); + CopyMandatoryEntry(0x0002,0x0002,"1.2.840.10008.5.1.4.1.1.7"); // 'Media Stored SOP Instance UID' - ValEntry *e_0002_0003 = CopyValEntry(0x0002,0x0003); - e_0002_0003->SetValue(Util::CreateUniqueUID()); - Archive->Push(e_0002_0003); + CopyMandatoryEntry(0x0002,0x0003,Util::CreateUniqueUID()); // 'Implementation Class UID' - ValEntry *e_0002_0012 = CopyValEntry(0x0002,0x0012); - e_0002_0012->SetValue(Util::CreateUniqueUID()); - Archive->Push(e_0002_0012); + CopyMandatoryEntry(0x0002,0x0012,Util::CreateUniqueUID()); // 'Implementation Version Name' - ValEntry *e_0002_0013 = CopyValEntry(0x0002,0x0013); std::string version = "GDCM "; version += Util::GetVersion(); - e_0002_0013->SetValue(version); - Archive->Push(e_0002_0013); - - //'Source Application Entity Title' Not Mandatory - //ValEntry *e_0002_0016 = CopyValEntry(0x0002,0x0016); - // e_0002_0016->SetValue("1.2.840.10008.5.1.4.1.1.7"); - // Archive->Push(e_0002_0016); + CopyMandatoryEntry(0x0002,0x0013,version); } // Push out 'LibIDO-special' entries, if any @@ -1260,11 +1217,9 @@ void FileHelper::CheckMandatoryElements() // Deal with the pb of (Bits Stored = 12) // - we're gonna write the image as Bits Stored = 16 - if ( FileInternal->GetEntryValue(0x0028,0x0100) == "12") + if ( FileInternal->GetEntryString(0x0028,0x0100) == "12") { - ValEntry *e_0028_0100 = CopyValEntry(0x0028,0x0100); - e_0028_0100->SetValue("16"); - Archive->Push(e_0028_0100); + CopyMandatoryEntry(0x0028,0x0100,"16"); } // Check if user wasn't drunk ;-) @@ -1274,9 +1229,7 @@ void FileHelper::CheckMandatoryElements() int nbBitsAllocated = FileInternal->GetBitsAllocated(); if ( nbBitsAllocated == 0 || nbBitsAllocated > 32) { - ValEntry *e_0028_0100 = CopyValEntry(0x0028,0x0100); - e_0028_0100->SetValue("16"); - Archive->Push(e_0028_0100); + CopyMandatoryEntry(0x0028,0x0100,"16"); gdcmWarningMacro("(0028,0100) changed from " << nbBitsAllocated << " to 16 for consistency purpose"); nbBitsAllocated = 16; @@ -1285,10 +1238,9 @@ void FileHelper::CheckMandatoryElements() int nbBitsStored = FileInternal->GetBitsStored(); if ( nbBitsStored == 0 || nbBitsStored > nbBitsAllocated ) { + s.str(""); s << nbBitsAllocated; - ValEntry *e_0028_0101 = CopyValEntry(0x0028,0x0101); - e_0028_0101->SetValue( s.str() ); - Archive->Push(e_0028_0101); + CopyMandatoryEntry(0x0028,0x0101,s.str()); gdcmWarningMacro("(0028,0101) changed from " << nbBitsStored << " to " << nbBitsAllocated << " for consistency purpose" ); @@ -1300,11 +1252,9 @@ void FileHelper::CheckMandatoryElements() highBitPosition > nbBitsAllocated-1 || highBitPosition < nbBitsStored-1 ) { - ValEntry *e_0028_0102 = CopyValEntry(0x0028,0x0102); - + s.str(""); s << nbBitsStored - 1; - e_0028_0102->SetValue( s.str() ); - Archive->Push(e_0028_0102); + CopyMandatoryEntry(0x0028,0x0102,s.str()); gdcmWarningMacro("(0028,0102) changed from " << highBitPosition << " to " << nbBitsAllocated-1 << " for consistency purpose"); @@ -1315,8 +1265,8 @@ void FileHelper::CheckMandatoryElements() // we create the 'Source Image Sequence' SeqEntry // to hold informations about the Source Image - ValEntry *e_0008_0016 = FileInternal->GetValEntry(0x0008, 0x0016); - if ( e_0008_0016 != 0 ) + DataEntry *e_0008_0016 = FileInternal->GetDataEntry(0x0008, 0x0016); + if ( e_0008_0016 ) { // Create 'Source Image Sequence' SeqEntry SeqEntry *sis = new SeqEntry ( @@ -1324,16 +1274,16 @@ void FileHelper::CheckMandatoryElements() SQItem *sqi = new SQItem(1); // (we assume 'SOP Instance UID' exists too) // create 'Referenced SOP Class UID' - ValEntry *e_0008_1150 = new ValEntry( + DataEntry *e_0008_1150 = new DataEntry( Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1150) ); - e_0008_1150->SetValue( e_0008_0016->GetValue()); + e_0008_1150->SetString( e_0008_0016->GetString()); sqi->AddEntry(e_0008_1150); // create 'Referenced SOP Instance UID' - ValEntry *e_0008_0018 = FileInternal->GetValEntry(0x0008, 0x0018); - ValEntry *e_0008_1155 = new ValEntry( + DataEntry *e_0008_0018 = FileInternal->GetDataEntry(0x0008, 0x0018); + DataEntry *e_0008_1155 = new DataEntry( Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x1155) ); - e_0008_1155->SetValue( e_0008_0018->GetValue()); + e_0008_1155->SetString( e_0008_0018->GetString()); sqi->AddEntry(e_0008_1155); sis->AddSQItem(sqi,1); @@ -1341,9 +1291,7 @@ void FileHelper::CheckMandatoryElements() Archive->Push(sis); // 'Image Type' (The written image is no longer an 'ORIGINAL' one) - ValEntry *e_0008_0008 = CopyValEntry(0x0008,0x0008); - e_0008_0008->SetValue("DERIVED\\PRIMARY"); - Archive->Push(e_0008_0008); + CopyMandatoryEntry(0x0008,0x0008,"DERIVED\\PRIMARY"); } else { @@ -1351,35 +1299,21 @@ void FileHelper::CheckMandatoryElements() // the source image was NOT a true Dicom one. // We consider the image is a 'Secondary Capture' one // SOP Class UID - e_0008_0016 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0016) ); // [Secondary Capture Image Storage] - e_0008_0016 ->SetValue("1.2.840.10008.5.1.4.1.1.7"); - Archive->Push(e_0008_0016); + SetMandatoryEntry(0x0008,0x0016,"1.2.840.10008.5.1.4.1.1.7"); } // ---- The user will never have to take any action on the following ----. - // new value for 'SOP Instance UID' - ValEntry *e_0008_0018 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0018) ); - e_0008_0018->SetValue( Util::CreateUniqueUID() ); - Archive->Push(e_0008_0018); + SetMandatoryEntry(0x0008,0x0018,Util::CreateUniqueUID()); // Instance Creation Date - ValEntry *e_0008_0012 = CopyValEntry(0x0008,0x0012); - std::string date = Util::GetCurrentDate(); - e_0008_0012->SetValue(date.c_str()); - Archive->Push(e_0008_0012); + CopyMandatoryEntry(0x0008,0x0012,Util::GetCurrentDate().c_str()); // Instance Creation Time - ValEntry *e_0008_0013 = CopyValEntry(0x0008,0x0013); - std::string time = Util::GetCurrentTime(); - e_0008_0013->SetValue(time.c_str()); - Archive->Push(e_0008_0013); + CopyMandatoryEntry(0x0008,0x0013,Util::GetCurrentTime().c_str()); // ----- Add Mandatory Entries if missing --- - // Entries whose type is 1 are mandatory, with a mandatory value // Entries whose type is 1c are mandatory-inside-a-Sequence // Entries whose type is 2 are mandatory, with a optional value @@ -1392,14 +1326,7 @@ void FileHelper::CheckMandatoryElements() // keeping the same 'Serie Instance UID' for various images // The user shouldn't add any image to a 'Manufacturer Serie' // but there is no way no to allowed him to do that - ValEntry *e_0020_000e = FileInternal->GetValEntry(0x0020, 0x000e); - if ( !e_0020_000e ) - { - e_0020_000e = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0020, 0x000e) ); - e_0020_000e->SetValue(Util::CreateUniqueUID() ); - Archive->Push(e_0020_000e); - } + CheckMandatoryEntry(0x0020,0x000e,Util::CreateUniqueUID()); // 'Study Instance UID' // Keep the value if exists @@ -1407,107 +1334,69 @@ void FileHelper::CheckMandatoryElements() // keeping the same 'Study Instance UID' for various images // The user may add images to a 'Manufacturer Study', // adding new series to an already existing Study - ValEntry *e_0020_000d = FileInternal->GetValEntry(0x0020, 0x000d); - if ( !e_0020_000d ) - { - e_0020_000d = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0020, 0x000d) ); - e_0020_000d->SetValue(Util::CreateUniqueUID() ); - Archive->Push(e_0020_000d); - } + CheckMandatoryEntry(0x0020,0x000d,Util::CreateUniqueUID()); // Modality : if missing we set it to 'OTher' - ValEntry *e_0008_0060 = FileInternal->GetValEntry(0x0008, 0x0060); - if ( !e_0008_0060 ) - { - e_0008_0060 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0060) ); - e_0008_0060->SetValue("OT"); - Archive->Push(e_0008_0060); - } + CheckMandatoryEntry(0x0008,0x0060,"OT"); // Manufacturer : if missing we set it to 'GDCM Factory' - ValEntry *e_0008_0070 = FileInternal->GetValEntry(0x0008, 0x0070); - if ( !e_0008_0070 ) - { - e_0008_0070 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0070) ); - e_0008_0070->SetValue("GDCM Factory"); - Archive->Push(e_0008_0070); - } + CheckMandatoryEntry(0x0008,0x0070,"GDCM Factory"); // Institution Name : if missing we set it to 'GDCM Hospital' - ValEntry *e_0008_0080 = FileInternal->GetValEntry(0x0008, 0x0080); - if ( !e_0008_0080 ) - { - e_0008_0080 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0080) ); - e_0008_0080->SetValue("GDCM Hospital"); - Archive->Push(e_0008_0080); - } + CheckMandatoryEntry(0x0008,0x0080,"GDCM Hospital"); // Patient's Name : if missing, we set it to 'GDCM^Patient' - ValEntry *e_0010_0010 = FileInternal->GetValEntry(0x0010, 0x0010); - if ( !e_0010_0010 ) - { - e_0010_0010 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0010) ); - e_0010_0010->SetValue("GDCM^Patient"); - Archive->Push(e_0010_0010); - } + CheckMandatoryEntry(0x0010,0x0010,"GDCM^Patient"); // Patient's Birth Date : 'type 2' entry -> must exist, value not mandatory - ValEntry *e_0010_0030 = FileInternal->GetValEntry(0x0010, 0x0030); - if ( !e_0010_0030 ) - { - e_0010_0030 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0030) ); - e_0010_0030->SetValue(""); - Archive->Push(e_0010_0030); - } + CheckMandatoryEntry(0x0010,0x0030,""); // Patient's Sex :'type 2' entry -> must exist, value not mandatory - ValEntry *e_0010_0040 = FileInternal->GetValEntry(0x0010, 0x0040); - if ( !e_0010_0040 ) - { - e_0010_0040 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0010, 0x0040) ); - e_0010_0040->SetValue(""); - Archive->Push(e_0010_0040); - } + CheckMandatoryEntry(0x0010,0x0040,""); // Referring Physician's Name :'type 2' entry -> must exist, value not mandatory - ValEntry *e_0008_0090 = FileInternal->GetValEntry(0x0008, 0x0090); - if ( !e_0008_0090 ) - { - e_0008_0090 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0008, 0x0090) ); - e_0008_0090->SetValue(""); - Archive->Push(e_0008_0090); - } + CheckMandatoryEntry(0x0008,0x0090,""); // Pixel Spacing : defaulted to 1.0\1.0 - ValEntry *e_0028_0030 = FileInternal->GetValEntry(0x0028, 0x0030); - if ( !e_0028_0030 ) - { - e_0028_0030 = new ValEntry( - Global::GetDicts()->GetDefaultPubDict()->GetEntry(0x0028, 0x0030) ); - e_0028_0030->SetValue("1.0\\1.0"); - Archive->Push(e_0028_0030); - } + CheckMandatoryEntry(0x0028,0x0030,"1.0\\1.0"); // Remove some inconstencies (probably some more will be added) // if (0028 0008)Number of Frames exists // Push out (0020 0052),Frame of Reference UID // (only meaningfull within a Serie) - ValEntry *e_0028_0008 = FileInternal->GetValEntry(0x0028, 0x0008); + DataEntry *e_0028_0008 = FileInternal->GetDataEntry(0x0028, 0x0008); if ( !e_0028_0008 ) { Archive->Push(0x0020, 0X0052); } } - + +void FileHelper::CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value) +{ + DataEntry *entry = FileInternal->GetDataEntry(group,elem); + if ( !entry ) + { + entry = new DataEntry(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem)); + entry->SetString(value); + Archive->Push(entry); + } +} + +void FileHelper::SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value) +{ + DataEntry *entry = new DataEntry(Global::GetDicts()->GetDefaultPubDict()->GetEntry(group,elem)); + entry->SetString(value); + Archive->Push(entry); +} + +void FileHelper::CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value) +{ + DataEntry *entry = CopyDataEntry(group,elem); + entry->SetString(value); + Archive->Push(entry); +} + /** * \brief Restore in the File the initial group 0002 */ @@ -1592,7 +1481,7 @@ uint8_t *FileHelper::GetRaw() //----------------------------------------------------------------------------- /** - * \brief Prints the common part of ValEntry, BinEntry, SeqEntry + * \brief Prints the common part of DataEntry, SeqEntry * @param os ostream we want to print in * @param indent (unused) */ diff --git a/src/gdcmFileHelper.h b/src/gdcmFileHelper.h index ee5e9d77..1c1d0d8d 100644 --- a/src/gdcmFileHelper.h +++ b/src/gdcmFileHelper.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFileHelper.h,v $ Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - Version: $Revision: 1.22 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.23 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -28,8 +28,7 @@ namespace gdcm { class File; -class ValEntry; -class BinEntry; +class DataEntry; class SeqEntry; class PixelReadConvert; class PixelWriteConvert; @@ -72,15 +71,15 @@ public: void SetUserFunction( VOID_FUNCTION_PUINT8_PFILE_POINTER userFunc ) { UserFunction = userFunc; } // File methods - bool SetValEntry(std::string const &content, - uint16_t group, uint16_t elem); - bool SetBinEntry(uint8_t *content, int lgth, - uint16_t group, uint16_t elem); - - ValEntry *InsertValEntry(std::string const &content, - uint16_t group, uint16_t elem); - BinEntry *InsertBinEntry(uint8_t *binArea, int lgth, + bool SetEntryString(std::string const &content, + uint16_t group, uint16_t elem); + bool SetEntryBinArea(uint8_t *content, int lgth, uint16_t group, uint16_t elem); + + DataEntry *InsertEntryString(std::string const &content, + uint16_t group, uint16_t elem); + DataEntry *InsertEntryBinArea(uint8_t *binArea, int lgth, + uint16_t group, uint16_t elem); SeqEntry *InsertSeqEntry(uint16_t group, uint16_t elem); // File helpers @@ -165,10 +164,12 @@ protected: void SetWriteToNoLibido(); void RestoreWriteOfLibido(); - ValEntry *CopyValEntry(uint16_t group, uint16_t elem); - BinEntry *CopyBinEntry(uint16_t group, uint16_t elem, - const std::string &vr); + DataEntry *CopyDataEntry(uint16_t group, uint16_t elem, + const TagName &vr = GDCM_UNKNOWN); void CheckMandatoryElements(); + void CheckMandatoryEntry(uint16_t group,uint16_t elem,std::string value); + void SetMandatoryEntry(uint16_t group,uint16_t elem,std::string value); + void CopyMandatoryEntry(uint16_t group,uint16_t elem,std::string value); void RestoreWriteMandatory(); private: diff --git a/src/gdcmOrientation.cxx b/src/gdcmOrientation.cxx index b6a33bb8..d23402ca 100644 --- a/src/gdcmOrientation.cxx +++ b/src/gdcmOrientation.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmOrientation.cxx,v $ Language: C++ - Date: $Date: 2005/10/03 14:54:16 $ - Version: $Revision: 1.16 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.17 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -336,7 +336,7 @@ try: val=image.GetFirstEntry() dic={} while(val): - if isinstance(val,gdcm.ValEntryPtr): + if isinstance(val,gdcm.DataEntryPtr): dic[val.GetName()]=val.GetValue() val=image.GetNextEntry() return dic diff --git a/src/gdcmPixelReadConvert.cxx b/src/gdcmPixelReadConvert.cxx index 05402379..689ab46c 100644 --- a/src/gdcmPixelReadConvert.cxx +++ b/src/gdcmPixelReadConvert.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmPixelReadConvert.cxx,v $ Language: C++ - Date: $Date: 2005/10/13 07:14:45 $ - Version: $Revision: 1.78 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.79 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -148,9 +148,9 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) if ( HasLUT ) { // Just in case some access to a File element requires disk access. - LutRedDescriptor = file->GetEntryValue( 0x0028, 0x1101 ); - LutGreenDescriptor = file->GetEntryValue( 0x0028, 0x1102 ); - LutBlueDescriptor = file->GetEntryValue( 0x0028, 0x1103 ); + LutRedDescriptor = file->GetEntryString( 0x0028, 0x1101 ); + LutGreenDescriptor = file->GetEntryString( 0x0028, 0x1102 ); + LutBlueDescriptor = file->GetEntryString( 0x0028, 0x1103 ); // The following comment is probabely meaningless, since LUT are *always* // loaded at parsing time, whatever their length is. @@ -164,7 +164,7 @@ void PixelReadConvert::GrabInformationsFromFile( File *file ) // \TODO Reading a [Bin|Val]Entry directly from disk is a kludge. // We should NOT bypass the [Bin|Val]Entry class. Instead // an access to an UNLOADED content of a [Bin|Val]Entry occurence - // (e.g. BinEntry::GetBinArea()) should force disk access from + // (e.g. DataEntry::GetBinArea()) should force disk access from // within the [Bin|Val]Entry class itself. The only problem // is that the [Bin|Val]Entry is unaware of the FILE* is was // parsed from. Fix that. FIXME. diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 88c93b3a..0ed62981 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2005/09/06 17:15:25 $ - Version: $Revision: 1.75 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.76 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,8 +18,6 @@ #include "gdcmSQItem.h" #include "gdcmSeqEntry.h" -#include "gdcmValEntry.h" -#include "gdcmBinEntry.h" #include "gdcmGlobal.h" #include "gdcmDictSet.h" #include "gdcmUtil.h" diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 8f5e4731..0cfd3643 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.cxx,v $ Language: C++ - Date: $Date: 2005/08/24 03:42:40 $ - Version: $Revision: 1.57 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.58 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,7 +18,6 @@ #include "gdcmSeqEntry.h" #include "gdcmSQItem.h" -#include "gdcmValEntry.h" #include "gdcmTS.h" #include "gdcmGlobal.h" #include "gdcmUtil.h" diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index 7804b6cf..cae73c89 100644 --- a/src/gdcmSeqEntry.h +++ b/src/gdcmSeqEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.h,v $ Language: C++ - Date: $Date: 2005/02/11 15:22:18 $ - Version: $Revision: 1.34 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.35 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,7 +31,7 @@ typedef std::list ListSQItem; //----------------------------------------------------------------------------- /** - * \brief a SeqEntry (as opposed to a ValEntry) is a non elementary DocEntry. + * \brief a SeqEntry (as opposed to a DataEntry) is a non elementary DocEntry. * It is composed by a set of SQItems. * Each SQItem is composed by a set of DocEntry * A DocEntry may be a SeqEntry diff --git a/src/gdcmSerieHelper.cxx b/src/gdcmSerieHelper.cxx index d90e68c5..f62883e9 100644 --- a/src/gdcmSerieHelper.cxx +++ b/src/gdcmSerieHelper.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSerieHelper.cxx,v $ Language: C++ - Date: $Date: 2005/10/17 15:45:38 $ - Version: $Revision: 1.23 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.24 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -106,7 +106,7 @@ void SerieHelper::AddFileName(std::string const &filename) ++it2) { const ExRule &r = *it2; - s = header->GetEntryValue( r.group, r.elem ); + s = header->GetEntryString( r.group, r.elem ); if ( !Util::CompareDicomString(s, r.value.c_str(), r.op) ) { // Argh ! This rule is unmatched; let's just quit @@ -121,7 +121,7 @@ void SerieHelper::AddFileName(std::string const &filename) // Let's add it! // 0020 000e UI REL Series Instance UID - const std::string &uid = header->GetEntryValue (0x0020, 0x000e); + const std::string &uid = header->GetEntryString(0x0020, 0x000e); // if uid == GDCM_UNFOUND then consistently we should find GDCM_UNFOUND // no need here to do anything special @@ -486,11 +486,11 @@ XCoherentFileSetmap SerieHelper::SplitOnPosition(FileList *fileSet) // 0020,0032 : Image Position Patient // 0020,0030 : Image Position (RET) - strImPos = (*it)->GetEntryValue(0x0020,0x0032); + strImPos = (*it)->GetEntryString(0x0020,0x0032); if ( strImPos == GDCM_UNFOUND) { gdcmWarningMacro( "Unfound Image Position Patient (0020,0032)"); - strImPos = (*it)->GetEntryValue(0x0020,0x0030); // For ACR-NEMA images + strImPos = (*it)->GetEntryString(0x0020,0x0030); // For ACR-NEMA images if ( strImPos == GDCM_UNFOUND ) { gdcmWarningMacro( "Unfound Image Position (RET) (0020,0030)"); @@ -559,7 +559,7 @@ XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet, // 0020,0032 : Image Position Patient // 0020,0030 : Image Position (RET) - strTagValue = (*it)->GetEntryValue(group,element); + strTagValue = (*it)->GetEntryString(group,element); if ( CoherentFileSet.count(strTagValue) == 0 ) { @@ -569,7 +569,7 @@ XCoherentFileSetmap SerieHelper::SplitOnTagValue(FileList *fileSet, } // Current Tag value and DICOM header match; add the file: CoherentFileSet[strTagValue]->push_back( (*it) ); - } + } return CoherentFileSet; } diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 5c06e5ab..b1feafb0 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmUtil.cxx,v $ Language: C++ - Date: $Date: 2005/10/06 18:49:30 $ - Version: $Revision: 1.164 $ + Date: $Date: 2005/10/18 08:35:50 $ + Version: $Revision: 1.165 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -186,7 +186,7 @@ int Util::CountSubstring (const std::string &str, */ bool Util::IsCleanString(std::string const &s) { - std::cout<< std::endl << s << std::endl; + std::cout<< std::endl << s << std::endl; for(unsigned int i=0; i &tokens, const std::string &delimiters = " "); static int CountSubstring (const std::string &str, - const std::string &subStr); + const std::string &subStr); static std::string CreateCleanString(std::string const &s); static std::string CreateCleanString(uint8_t *s, int l); diff --git a/src/gdcmVR.cxx b/src/gdcmVR.cxx index 57b93016..77bbf231 100644 --- a/src/gdcmVR.cxx +++ b/src/gdcmVR.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmVR.cxx,v $ Language: C++ - Date: $Date: 2005/09/07 14:12:23 $ - Version: $Revision: 1.40 $ + Date: $Date: 2005/10/18 08:35:51 $ + Version: $Revision: 1.41 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -85,7 +85,7 @@ VR::~VR() /** * \brief Simple predicate that checks whether the given argument - * corresponds to the Value Representation of a \ref BinEntry . + * corresponds to the Value Representation of a \ref DataEntry . * @param tested value representation to check for. */ bool VR::IsVROfBinaryRepresentable(VRKey const &tested) @@ -108,14 +108,12 @@ bool VR::IsVROfBinaryRepresentable(VRKey const &tested) /** * \brief Simple predicate that checks whether the given argument - * corresponds to the Value Representation of a \ref ValEntry - * but NOT a \ref BinEntry. + * corresponds to the Value Representation of a representable + * string. * @param tested value representation to be checked. */ bool VR::IsVROfStringRepresentable(VRKey const &tested) { - - return tested == "AE" || tested == "AS" || tested == "CS" || @@ -146,6 +144,26 @@ bool VR::IsVROfStringRepresentable(VRKey const &tested) */ } +unsigned short VR::GetAtomicElementLength(VRKey const &vr) +{ + // Unsigned & signed short + if( vr == "US" || vr == "SS" ) + return 2; + // Unsigned & signed long + if( vr == "UL" || vr == "SL" ) + return 4; + // Float + if( vr == "FL" ) + return 4; + // Double + if( vr == "FD" ) + return 8; + // Word string + if( vr == "OW" ) + return 2; + return 1; +} + //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmVR.h b/src/gdcmVR.h index 118ad3d8..9b74d486 100644 --- a/src/gdcmVR.h +++ b/src/gdcmVR.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmVR.h,v $ Language: C++ - Date: $Date: 2005/09/06 15:36:03 $ - Version: $Revision: 1.19 $ + Date: $Date: 2005/10/18 08:35:51 $ + 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 @@ -58,6 +58,8 @@ public: bool IsValidVR(VRKey const &key) { return vr.find(key) != vr.end(); } + unsigned short GetAtomicElementLength(VRKey const &vr); + private: VRHT vr; }; diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx deleted file mode 100644 index 671e6bd3..00000000 --- a/src/gdcmValEntry.cxx +++ /dev/null @@ -1,306 +0,0 @@ -/*========================================================================= - - Program: gdcm - Module: $RCSfile: gdcmValEntry.cxx,v $ - Language: C++ - Date: $Date: 2005/07/05 14:55:24 $ - Version: $Revision: 1.63 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - -#include "gdcmValEntry.h" -#include "gdcmVR.h" -#include "gdcmTS.h" -#include "gdcmGlobal.h" -#include "gdcmUtil.h" -#include "gdcmDebug.h" -#include "gdcmDocument.h" - -#include -#include // for isdigit -#include // for atoi - -namespace gdcm -{ -//----------------------------------------------------------------------------- -#define MAX_SIZE_PRINT_ELEMENT_VALUE 0x7fffffff -uint32_t ValEntry::MaxSizePrintEntry = MAX_SIZE_PRINT_ELEMENT_VALUE; -//----------------------------------------------------------------------------- -// Constructor / Destructor -/** - * \brief Constructor from a given DictEntry - * @param e Pointer to existing dictionary entry - */ -ValEntry::ValEntry(DictEntry *e) - : ContentEntry(e) -{ -} - -/** - * \brief Constructor from a given DocEntry - * @param e Pointer to existing Doc entry - */ -ValEntry::ValEntry(DocEntry *e) - : ContentEntry(e->GetDictEntry()) -{ - Copy(e); -} - -/** - * \brief Canonical destructor. - */ -ValEntry::~ValEntry () -{ -} - -//----------------------------------------------------------------------------- -// Public -/** - * \brief Writes the std::string representable' value of a ValEntry - * @param fp already open ofstream pointer - * @param filetype type of the file (ACR, ImplicitVR, ExplicitVR, ...) - */ -void ValEntry::WriteContent(std::ofstream *fp, FileType filetype) -{ - DocEntry::WriteContent(fp, filetype); - - if ( GetGroup() == 0xfffe ) - { - return; //delimitors have NO value - } - - const VRKey &vr = GetVR(); - unsigned int lgth = GetLength(); - if (vr == "US" || vr == "SS") - { - // some 'Short integer' fields may be multivaluated - // each single value is separated from the next one by '\' - // we split the string and write each value as a short int - std::vector tokens; - tokens.erase(tokens.begin(),tokens.end()); // clean any previous value - Util::Tokenize (GetValue(), tokens, "\\"); - for (unsigned int i=0; i tokens; - tokens.erase(tokens.begin(),tokens.end()); // clean any previous value - Util::Tokenize (GetValue(), tokens, "\\"); - for (unsigned int i=0; i= (uint32_t)0xffffffff ) - { - ValEntry::MaxSizePrintEntry = 0xffffffff; - return; - } - ValEntry::MaxSizePrintEntry = newSize; -} - - -/** - * \brief Sets the std::string representable' value of a ValEntry - * @param val value to set - */ -void ValEntry::SetValue(std::string const &val) -{ - // Integers have a special treatement for their length: - int l = val.length(); - if ( l != 0) // To avoid to be cheated by 'zero length' integers - { - const VRKey &vr = GetVR(); - if ( vr == "US" || vr == "SS" ) - { - // for multivaluated items - l = (Util::CountSubstring(val, "\\") + 1) * 2; - ContentEntry::SetValue(val); - } - else if ( vr == "UL" || vr == "SL" ) - { - // for multivaluated items - l = (Util::CountSubstring(val, "\\") + 1) * 4;; - ContentEntry::SetValue(val); - } - else - { - std::string finalVal = Util::DicomString( val.c_str() ); - gdcmAssertMacro( !(finalVal.size() % 2) ); - - l = finalVal.length(); - ContentEntry::SetValue(finalVal); - } - } - else - { - std::string finalVal = Util::DicomString( val.c_str() ); - gdcmAssertMacro( !(finalVal.size() % 2) ); - - l = finalVal.length(); - ContentEntry::SetValue(finalVal); - } - - SetLength(l); -} - -//----------------------------------------------------------------------------- -// Protected - -//----------------------------------------------------------------------------- -// Private - -//----------------------------------------------------------------------------- -// Print -/** - * \brief Prints the 'std::string representable' value of ValEntry - * @param os ostream we want to print in - * @param indent Indentation string to be prepended during printing - */ -void ValEntry::Print(std::ostream &os, std::string const &) -{ - uint16_t g = GetGroup(); - uint16_t e = GetElement(); - VRKey vr = GetVR(); - std::ostringstream s; - std::string st; - std::string d2; - - os << "V "; - DocEntry::Print(os); - - if (g == 0xfffe) // delimiters have NO value - { - // just to avoid identing all the remaining code - return; - } - - TS *ts = Global::GetTS(); - - TSAtr v = GetValue(); - d2 = Util::CreateCleanString(v); // replace non printable characters by '.' - if ( (long)GetLength() <= ValEntry::GetMaxSizePrintEntry() - || PrintLevel >= 3 - || d2.find(GDCM_NOTLOADED) < d2.length() ) - { - s << " [" << d2 << "]"; - } - else - { - s << " [gdcm::too long for print (" << GetLength() << ") ]"; - } - - // Display the UID value (instead of displaying only the rough code) - // First 'clean' trailing character (space or zero) - if (g == 0x0002) - { - // Any more to be displayed ? - if ( e == 0x0010 || e == 0x0002 ) - { - if ( v.length() != 0 ) // for brain damaged headers - { - if ( ! isdigit((unsigned char)v[v.length()-1]) ) - { - v.erase(v.length()-1, 1); - } - } - s << " ==>\t[" << ts->GetValue(v) << "]"; - } - } - else - { - if (g == 0x0008) - { - if ( e == 0x0016 || e == 0x1150 ) - { - if ( v.length() != 0 ) // for brain damaged headers - { - if ( ! isdigit((unsigned char)v[v.length()-1]) ) - { - v.erase(v.length()-1, 1); - } - } - s << " ==>\t[" << ts->GetValue(v) << "]"; - } - } - else - { - if (g == 0x0004) - { - if ( e == 0x1510 || e == 0x1512 ) - { - if ( v.length() != 0 ) // for brain damaged headers - { - if ( ! isdigit((unsigned char)v[v.length()-1]) ) - { - v.erase(v.length()-1, 1); - } - } - s << " ==>\t[" << ts->GetValue(v) << "]"; - } - } - } - } - //if (e == 0x0000) { // elem 0x0000 --> group length - if ( vr == "UL" || vr == "US" || vr == "SL" || vr == "SS" ) - { - if (v == "4294967295") // to avoid troubles in convertion - { - st = "ffffffff"; - } - else - { - if ( GetLength() != 0 ) - { - st = Util::Format(" x(%x)", atoi(v.c_str()));//FIXME - } - else - { - st = " "; - } - } - s << st; - } - os << s.str(); -} - -//----------------------------------------------------------------------------- -} // end namespace gdcm - diff --git a/src/gdcmValEntry.h b/src/gdcmValEntry.h deleted file mode 100644 index d5c52034..00000000 --- a/src/gdcmValEntry.h +++ /dev/null @@ -1,81 +0,0 @@ -/*========================================================================= - - Program: gdcm - Module: $RCSfile: gdcmValEntry.h,v $ - Language: C++ - Date: $Date: 2005/09/02 07:10:03 $ - Version: $Revision: 1.42 $ - - Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de - l'Image). All rights reserved. See Doc/License.txt or - http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - - This software is distributed WITHOUT ANY WARRANTY; without even - the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - PURPOSE. See the above copyright notices for more information. - -=========================================================================*/ - -#ifndef GDCMVALENTRY_H -#define GDCMVALENTRY_H - -#include "gdcmDocEntry.h" -#include "gdcmContentEntry.h" - -#include - -namespace gdcm -{ -//----------------------------------------------------------------------------- -/** - * \brief Any Dicom Document (File or DicomDir) contains - * a set of DocEntry - Dicom entries - - * ValEntry is an elementary DocEntry (i.e. a ContentEntry, - * as opposed to SeqEntry) - * whose content is 'std::string representable' : characters, - * or integers (loaded in memory as a std::string) - * ValEntry is a specialisation of ContentEntry - */ -class GDCM_EXPORT ValEntry : public ContentEntry -{ -public: - - // Contructors and Destructor are public. - ValEntry(DictEntry *e); - ValEntry(DocEntry *d); - - ~ValEntry(); - - // Other accessors are inherited from gdcm::ContentEntry - - void Print(std::ostream &os = std::cout, std::string const &indent = ""); - - void WriteContent(std::ofstream *fp, FileType filetype); - - /// Sets the value (string) of the current Dicom entry. - /// The size is updated - void SetValue(std::string const &val); - - - /// \brief returns the size threshold above which an element value - /// will NOT be *printed* in order no to polute the screen output - static long GetMaxSizePrintEntry() { return ValEntry::MaxSizePrintEntry; } - - static void SetMaxSizePrintEntry(long); - -protected: - -private: - - /// \brief Size threshold above which an element val - /// By default, this upper bound is fixed to 64 bytes. - - static uint32_t MaxSizePrintEntry; - -}; - -} // end namespace gdcm - -//----------------------------------------------------------------------------- -#endif - diff --git a/src/gdcmValidator.cxx b/src/gdcmValidator.cxx index c62079f1..f4cac476 100644 --- a/src/gdcmValidator.cxx +++ b/src/gdcmValidator.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValidator.cxx,v $ Language: C++ - Date: $Date: 2005/06/24 10:55:59 $ - Version: $Revision: 1.4 $ + Date: $Date: 2005/10/18 08:35:51 $ + Version: $Revision: 1.5 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -18,8 +18,7 @@ #include "gdcmValidator.h" #include "gdcmElementSet.h" -#include "gdcmBinEntry.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include @@ -34,11 +33,11 @@ Validator::~Validator() { } -// Function to compare the VM found while parsing d->GetValue() +// Function to compare the VM found while parsing d->GetString() // compare to the one from the dictionary -bool CheckVM(ValEntry *v) +bool CheckVM(DataEntry *entry) { - const std::string &s = v->GetValue(); + const std::string &s = entry->GetString(); std::string::size_type n = s.find("\\"); if ( n == s.npos ) // none found { @@ -48,7 +47,7 @@ bool CheckVM(ValEntry *v) unsigned int m; std::istringstream os; - os.str( v->GetVM()); + os.str( entry->GetVM()); os >> m; return n == m; @@ -57,22 +56,15 @@ bool CheckVM(ValEntry *v) void Validator::SetInput(ElementSet *input) { // berk for now SetInput do two things at the same time - gdcm::DocEntry *d=input->GetFirstEntry(); + DocEntry *d=input->GetFirstEntry(); while(d) { - if ( gdcm::BinEntry *b = dynamic_cast(d) ) - { -// copyH->InsertBinEntry( b->GetBinArea(),b->GetLength(), -// b->GetGroup(),b->GetElement(), -// b->GetVR() ); - (void)b; - } - else if ( gdcm::ValEntry *v = dynamic_cast(d) ) + if ( DataEntry *v = dynamic_cast(d) ) { if ( !CheckVM(v) ) { std::cout << "Rah this DICOM contains one wrong tag:" << - v->GetValue() << " " << + v->GetString() << " " << v->GetGroup() << "," << v->GetElement() << "," << v->GetVR() << " " << v->GetVM() << " " << v->GetName() << std::endl; } diff --git a/vtk/vtkGdcmWriter.cxx b/vtk/vtkGdcmWriter.cxx index 4cf4db2d..e5b3b519 100644 --- a/vtk/vtkGdcmWriter.cxx +++ b/vtk/vtkGdcmWriter.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkGdcmWriter.cxx,v $ Language: C++ - Date: $Date: 2005/08/22 12:23:26 $ - Version: $Revision: 1.24 $ + Date: $Date: 2005/10/18 08:35:55 $ + Version: $Revision: 1.25 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -31,7 +31,7 @@ #define vtkFloatingPointType float #endif -vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.24 $") +vtkCxxRevisionMacro(vtkGdcmWriter, "$Revision: 1.25 $") vtkStandardNewMacro(vtkGdcmWriter) //----------------------------------------------------------------------------- @@ -137,29 +137,29 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) str.str(""); str << dim[0]; - file->InsertValEntry(str.str(),0x0028,0x0011); // Columns + file->InsertEntryString(str.str(),0x0028,0x0011); // Columns str.str(""); str << dim[1]; - file->InsertValEntry(str.str(),0x0028,0x0010); // Rows + file->InsertEntryString(str.str(),0x0028,0x0010); // Rows if(dim[2]>1) { str.str(""); str << dim[2]; //file->Insert(str.str(),0x0028,0x0012); // Planes - file->InsertValEntry(str.str(),0x0028,0x0008); // Number of Frames + file->InsertEntryString(str.str(),0x0028,0x0008); // Number of Frames } // Pixel type str.str(""); str << image->GetScalarSize()*8; - file->InsertValEntry(str.str(),0x0028,0x0100); // Bits Allocated - file->InsertValEntry(str.str(),0x0028,0x0101); // Bits Stored + file->InsertEntryString(str.str(),0x0028,0x0100); // Bits Allocated + file->InsertEntryString(str.str(),0x0028,0x0101); // Bits Stored str.str(""); str << image->GetScalarSize()*8-1; - file->InsertValEntry(str.str(),0x0028,0x0102); // High Bit + file->InsertEntryString(str.str(),0x0028,0x0102); // High Bit // Pixel Repr // FIXME : what do we do when the ScalarType is @@ -176,12 +176,12 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) { str << "1"; // Signed } - file->InsertValEntry(str.str(),0x0028,0x0103); // Pixel Representation + file->InsertEntryString(str.str(),0x0028,0x0103); // Pixel Representation // Samples per pixel str.str(""); str << image->GetNumberOfScalarComponents(); - file->InsertValEntry(str.str(),0x0028,0x0002); // Samples per Pixel + file->InsertEntryString(str.str(),0x0028,0x0002); // Samples per Pixel /// \todo : Spacing Between Slices is meaningfull ONLY for CT an MR modality /// We should perform some checkings before forcing the Entry creation @@ -195,10 +195,10 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) // thus forcing to fixed point value str.setf( std::ios::fixed ); str << sp[1] << "\\" << sp[0]; - file->InsertValEntry(str.str(),0x0028,0x0030); // Pixel Spacing + file->InsertEntryString(str.str(),0x0028,0x0030); // Pixel Spacing str.str(""); str << sp[2]; - file->InsertValEntry(str.str(),0x0018,0x0088); // Spacing Between Slices + file->InsertEntryString(str.str(),0x0018,0x0088); // Spacing Between Slices // Origin vtkFloatingPointType *org = image->GetOrigin(); @@ -208,7 +208,7 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) str.str(""); str << org[0] << "\\" << org[1] << "\\" << org[2]; - file->InsertValEntry(str.str(),0x0020,0x0032); // Image Position Patient + file->InsertEntryString(str.str(),0x0020,0x0032); // Image Position Patient str.unsetf( std::ios::fixed ); //done with floating point values // Window / Level @@ -216,10 +216,10 @@ void SetImageInformation(gdcm::FileHelper *file, vtkImageData *image) str.str(""); str << rng[1]-rng[0]; - file->InsertValEntry(str.str(),0x0028,0x1051); // Window Width + file->InsertEntryString(str.str(),0x0028,0x1051); // Window Width str.str(""); str << (rng[1]+rng[0])/2.0; - file->InsertValEntry(str.str(),0x0028,0x1050); // Window Center + file->InsertEntryString(str.str(),0x0028,0x1050); // Window Center // Pixels unsigned char *data; diff --git a/vtk/vtkgdcmSerieViewer.cxx b/vtk/vtkgdcmSerieViewer.cxx index fbf81e16..a7b0b101 100644 --- a/vtk/vtkgdcmSerieViewer.cxx +++ b/vtk/vtkgdcmSerieViewer.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: vtkgdcmSerieViewer.cxx,v $ Language: C++ - Date: $Date: 2005/09/07 08:21:28 $ - Version: $Revision: 1.11 $ + Date: $Date: 2005/10/18 08:35:55 $ + Version: $Revision: 1.12 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -43,7 +43,7 @@ #include "gdcmDocument.h" // for NO_SHADOWSEQ #include "gdcmSerieHelper.h" #include "gdcmDebug.h" -#include "gdcmValEntry.h" +#include "gdcmDataEntry.h" #include "gdcmArgMgr.h" // for Argument Manager functions #include // for strcmp @@ -453,17 +453,17 @@ bool userSuppliedLessThanFunction(gdcm::File *f1, gdcm::File *f2) // for *this* user supplied function, I supposed only ValEntries are checked. // std::string s1, s2; - gdcm::ValEntry *e1,*e2; + gdcm::DataEntry *e1,*e2; for (int ri=0; rigdcm::Document::GetValEntry( elemsToOrderOn[2*ri], + e1= f1->gdcm::Document::GetDataEntry( elemsToOrderOn[2*ri], elemsToOrderOn[2*ri+1]); - e2= f2->gdcm::Document::GetValEntry( elemsToOrderOn[2*ri], + e2= f2->gdcm::Document::GetDataEntry( elemsToOrderOn[2*ri], elemsToOrderOn[2*ri+1]); if(!e2 || !e2) { @@ -472,8 +472,8 @@ bool userSuppliedLessThanFunction(gdcm::File *f1, gdcm::File *f2) << " not found" << std::endl; continue; } - s1 = e1->gdcm::ValEntry::GetValue(); - s2 = e2->gdcm::ValEntry::GetValue(); + s1 = e1->GetString(); + s2 = e2->GetString(); std::cout << "[" << s1 << "] vs [" << s2 << "]" << std::endl; if ( s1 < s2 ) return true; -- 2.45.1