From 709489e13fe8c2b2a3f0cff5b5c948fd516bf855 Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 27 Aug 2004 15:48:43 +0000 Subject: [PATCH] light modif around DICOMDIR stuff --- Dicts/DicomDir.dic | 14 ++++---------- Example/makeDicomDir.cxx | 7 ------- src/gdcmDicomDir.cxx | 24 +++++++++++++++--------- src/gdcmDicomDirElement.cxx | 7 ++++--- src/gdcmDicomDirMeta.cxx | 19 +++++++++++++------ src/gdcmSQItem.cxx | 34 +++++++++++++++++++++------------- src/gdcmSeqEntry.cxx | 18 ++++++------------ src/gdcmValEntry.cxx | 10 ++++++++-- 8 files changed, 71 insertions(+), 62 deletions(-) diff --git a/Dicts/DicomDir.dic b/Dicts/DicomDir.dic index a109cf8a..377e0a1c 100644 --- a/Dicts/DicomDir.dic +++ b/Dicts/DicomDir.dic @@ -10,9 +10,8 @@ metaElem 0004 1130 "" // File-set ID metaElem 0004 1200 "0" // Offset of the first dir of root dir entity : to be computed later metaElem 0004 1202 "0" // Offset of the last dir of root dir entity : to be computed later metaElem 0004 1212 "0" // File-set consistency flag -metaElem 0004 1220 "" // Directory record sequence : *length* to be set to 0xffffffff later -patientElem fffe e000 "0" // 'no length' item : length to be set to 0xffffffff later +patientElem fffe e000 "255" // 'no length' item : length to be set to 0xffffffff later patientElem 0004 1400 "0" // Offset of next directory record : = 0x0 : fffe e00d at end ! patientElem 0004 1410 "65535" // Record in use flag : 65535 = 0xFFFF (see 03_10PU.PDF p 31) patientElem 0004 1420 "0" // Offset of referenced lower-level dir entity : to be computed later @@ -24,7 +23,7 @@ patientElem 0010 0030 "" // Patient's Birthdate patientElem 0010 0040 "" // Patient's Sex patientElem fffe e00d "" // Item delimitation : length to be set to ZERO later -studyElem fffe e000 "0" // 'no length' item : length to be set to 0xffffffff later +studyElem fffe e000 "-1" // 'no length' item : length to be set to 0xffffffff later studyElem 0004 1400 "0" // Offset of next directory record : = 0x0 : fffe e00d at end ! studyElem 0004 1410 "65535" // Record in use flag : 65535 = 0xFFFF (see 03_10PU.PDF p 31) studyElem 0004 1420 "0" // Offset of referenced lower-level dir entity : to be computed later @@ -38,7 +37,7 @@ studyElem 0020 000d "" // Study Instance UID : may be forg studyElem 0020 0010 "" // Study ID : may be forged later studyElem fffe e00d "" // Item delimitation : length to be set to ZERO later -serieElem fffe e000 "O" // 'no length' item : length to be set to 0xffffffff later +serieElem fffe e000 "-1" // 'no length' item : length to be set to 0xffffffff later serieElem 0004 1400 "0" // Offset of next directory record : = 0x0 : fffe e00d at end ! serieElem 0004 1410 "65535" // Record in use flag : 65535 = 0xFFFF (see 03_10PU.PDF p 31) serieElem 0004 1420 "0" // Offset of referenced lower-level dir entity : to be computed later @@ -54,7 +53,7 @@ serieElem 0020 000e "" // Series Instance UID : may be for serieElem 0020 0011 "0" // Series Number : may be forged later serieElem fffe e00d "" // Item delimitation : length to be set to ZERO later -imageElem fffe e000 "0" // 'no length' item : length to be set to 0xffffffff later +imageElem fffe e000 "-1" // 'no length' item : length to be set to 0xffffffff later imageElem 0004 1400 "0" // Offset of next directory record : = 0x0 : fffe e00d at end ! imageElem 0004 1410 "65535" // Record in use flag : 65535 = 0xFFFF (see 03_10PU.PDF p 31) imageElem 0004 1420 "0" // Offset of referenced lower-level dir entity : to be computed later @@ -69,11 +68,6 @@ imageElem 0008 0016 "" // SOP Class UID : to be set/for imageElem 0008 0018 "" // SOP Instance UID : to be set/forged later imageElem 0008 0023 "" // Content Date imageElem 0008 0033 "" // Content Time -imageElem 0008 1140 "" // Referenced Image Sequence -imageElem fffe e000 "" // 'no length' item : length to be set to 0xffffffff later -imageElem 0008 1150 "" // Referenced SOP Class UID : to be set/forged later -imageElem 0008 1155 "" // Referenced SOP Instance UID : to be set/forged later -imageElem fffe e00d "" // Item delimitation : length to be set to ZERO later imageElem 0020 0013 "0" // Image Number imageElem 0020 0032 "1.0\1.0\1.0 " // Image Position Patient imageElem 0020 0037 "1\0\0\0\1\0 " // Image Orientation Patient diff --git a/Example/makeDicomDir.cxx b/Example/makeDicomDir.cxx index 540842c9..e4b1b5ac 100644 --- a/Example/makeDicomDir.cxx +++ b/Example/makeDicomDir.cxx @@ -72,17 +72,10 @@ int main(int argc, char* argv[]) { << std::endl; return 1; } - - std::cout << "--------- dcmdir->Print() ------------" << std::endl; - - dcmdir->SetPrintLevel(-1); - //dcmdir->Print(); // just to see - std::cout << "---------end dcmdir->Print() ------------" << std::endl; dcmdir->Write("NewDICOMDIR"); std::cout<Write(fp, gdcmExplicitVR); // force writing 0004|1220 [SQ ], that CANNOT exist within gdcmDicomDirMeta fwrite(&sq[0],4,1,fp); // 0004 1220 - fwrite("SQ" ,2,1,fp); // SQ - fwrite(&sq[2],6,1,fp); // 00 ffffffff - + //fwrite("SQ" ,2,1,fp); // SQ // VR no written for 'No length' Sequences ! + //fwrite(&sq[2],6,1,fp); // 00 ffffffff + fwrite(&sq[3],4,1,fp); // ffffffff + for(ListDicomDirPatient::iterator cc = patients.begin();cc!=patients.end();++cc) { (*cc)->Write( fp, gdcmExplicitVR ); } + // force writing Sequence Delimitation Item - fwrite(&sqt[0],4,1,fp); // fffe e0dd - fwrite("UL" ,2,1,fp); // UL - fwrite(&sqt[2],1,1,fp); // 00 + fwrite(&sqt[0],8,1,fp); // fffe e0dd ffff ffff + fclose( fp ); return true; } @@ -666,7 +669,10 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, } if ( type == GDCM_DICOMDIR_META ) // fusible : should never print ! + { std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl; + entry->Print(); // just to see + } si->AddEntry(entry); } switch( type ) diff --git a/src/gdcmDicomDirElement.cxx b/src/gdcmDicomDirElement.cxx index 22530e7d..b7517e8d 100644 --- a/src/gdcmDicomDirElement.cxx +++ b/src/gdcmDicomDirElement.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirElement.cxx,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/08/27 15:48:44 $ + 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 @@ -37,7 +37,8 @@ gdcmDicomDirElement::gdcmDicomDirElement() { std::string filename = gdcmDictSet::BuildDictPath() + std::string(DICT_ELEM); std::ifstream from(filename.c_str()); - dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary",filename.c_str()); + dbg.Error(!from, "gdcmDicomDirElement::gdcmDicomDirElement: can't open dictionary", + filename.c_str()); char buff[1024]; std::string type; diff --git a/src/gdcmDicomDirMeta.cxx b/src/gdcmDicomDirMeta.cxx index 15bfa8d0..42997e8c 100644 --- a/src/gdcmDicomDirMeta.cxx +++ b/src/gdcmDicomDirMeta.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirMeta.cxx,v $ Language: C++ - Date: $Date: 2004/08/26 15:29:52 $ - Version: $Revision: 1.6 $ + Date: $Date: 2004/08/27 15:48: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 @@ -49,7 +49,11 @@ gdcmDicomDirMeta::~gdcmDicomDirMeta() void gdcmDicomDirMeta::Print(std::ostream &os) { os << "META" << std::endl; - gdcmObject::Print(os); + //gdcmObject::Print(os); + for (ListDocEntry::iterator i = docEntries.begin(); + i != docEntries.end(); + ++i) + (*i)->Print(); } @@ -58,12 +62,15 @@ void gdcmDicomDirMeta::Print(std::ostream &os) /** - * \brief Writes the Object + * \brief Writes the Meta Elements * @return */ void gdcmDicomDirMeta::Write(FILE *fp, FileType t) -{ - gdcmObject::Write(fp, t); +{ + for (ListDocEntry::iterator i = docEntries.begin(); + i != docEntries.end(); + ++i) + (*i)->Write(fp, t); } //----------------------------------------------------------------------------- diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index 7d61d3cc..2299b946 100644 --- a/src/gdcmSQItem.cxx +++ b/src/gdcmSQItem.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSQItem.cxx,v $ Language: C++ - Date: $Date: 2004/08/26 15:29:53 $ - Version: $Revision: 1.24 $ + Date: $Date: 2004/08/27 15:48:44 $ + 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 @@ -97,17 +97,22 @@ gdcmSQItem::~gdcmSQItem() */ void gdcmSQItem::Write(FILE *fp,FileType filetype) { + uint16_t item[4] = { 0xfffe, 0xe000, 0xffff, 0xffff }; + uint16_t itemt[4]= { 0xfffe, 0xe00d, 0xffff, 0xffff }; + + //we force the writting of an 'Item' Start Element + // because we want to write the Item as a 'no Length' item + fwrite(&item[0],8,1,fp); // fffe e000 ffff ffff + for (ListDocEntry::iterator i = docEntries.begin(); i != docEntries.end(); ++i) - { - // Item Delimitor Item IS the last one of a 'no length' SQItem - // (when it exists) we don't write it right now - // It will be written outside, because ALL the SQItems are written - // as 'no length' - if ( (*i)->IsItemDelimitor() ) + { + // we skip delimitors (start and end one) because + // we force them as 'no length' + if ( (*i)->GetGroup() == 0xfffe ) { - break; + continue; } // Fix in order to make some MR PHILIPS images e-film readable @@ -115,13 +120,16 @@ void gdcmSQItem::Write(FILE *fp,FileType filetype) // we just *always* ignore spurious fffe|0000 tag ! if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0x0000 ) { - break; + break; // FIXME : continue; ?!? } - // It's up to the gdcmDocEntry Writter to write the SQItem begin element - // (fffe|e000) as a 'no length' one (*i)->Write(fp, filetype); - } + } + + //we force the writting of an 'Item Delimitation' item + // because we wrote the Item as a 'no Length' item + fwrite(&itemt[0],8,1,fp); // fffe e000 ffff ffff + } //----------------------------------------------------------------------------- diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 5ee43c77..f418ccd2 100644 --- a/src/gdcmSeqEntry.cxx +++ b/src/gdcmSeqEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.cxx,v $ Language: C++ - Date: $Date: 2004/08/26 15:29:53 $ - Version: $Revision: 1.23 $ + Date: $Date: 2004/08/27 15:48:44 $ + 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 @@ -51,7 +51,7 @@ gdcmSeqEntry::gdcmSeqEntry(gdcmDocEntry* e, int depth) : gdcmDocEntry(e->GetDict this->ImplicitVR = e->IsImplicitVR(); this->Offset = e->GetOffset(); //this->printLevel = e->GetPrintLevel(); // no longer exists ?!? - this->SQDepthLevel = e->GetDepthLevel(); + this->SQDepthLevel = depth; } /** * \brief Canonical destructor. @@ -105,23 +105,17 @@ void gdcmSeqEntry::Write(FILE *fp, FileType filetype) { uint16_t seq_term_gr = 0xfffe; uint16_t seq_term_el = 0xe0dd; - uint32_t seq_term_lg = 0x00000000; + uint32_t seq_term_lg = 0xffffffff; uint16_t item_term_gr = 0xfffe; uint16_t item_term_el = 0xe00d; - + gdcmDocEntry::Write(fp, filetype); for(ListSQItem::iterator cc = GetSQItems().begin(); cc != GetSQItems().end(); ++cc) - { + { (*cc)->Write(fp, filetype); - - //we force the writting of an Item Delimitation item - // because we wrote the Item as a 'no Length' item - fwrite ( &item_term_gr,(size_t)2 ,(size_t)1 ,fp); - fwrite ( &item_term_el,(size_t)2 ,(size_t)1 ,fp); - fwrite ( &seq_term_lg, (size_t)4 ,(size_t)1 ,fp); // Heu ..... } //we force the writting of a Sequence Delimitation item diff --git a/src/gdcmValEntry.cxx b/src/gdcmValEntry.cxx index 08d791e0..8b14f72f 100644 --- a/src/gdcmValEntry.cxx +++ b/src/gdcmValEntry.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmValEntry.cxx,v $ Language: C++ - Date: $Date: 2004/08/16 16:30:32 $ - Version: $Revision: 1.21 $ + Date: $Date: 2004/08/27 15:48:44 $ + Version: $Revision: 1.22 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -181,6 +181,12 @@ void gdcmValEntry::Print(std::ostream & os) void gdcmValEntry::Write(FILE *fp, FileType filetype) { gdcmDocEntry::Write(fp, filetype); + + if ( GetGroup() == 0xfffe ) + { + return; //delimitors have NO value + } + std::string vr = GetVR(); int lgr = GetReadLength(); if (vr == "US" || vr == "SS") -- 2.46.1