From ac6281627c9571b711bd4d6e55a4adabc8b91afb Mon Sep 17 00:00:00 2001 From: jpr Date: Fri, 23 Apr 2004 16:21:58 +0000 Subject: [PATCH] 2004-04-22 Jean-Pierre Roux * ENH Minor changes to the Print() methods * ADD gdcmParser::PrintEntryNiceSQ() to allow SQ-indented Header printing. Example given with : PrintHeader fileName 2 new (SQ based tree-like structure still to be done for the Header ...) --- ChangeLog | 32 ++++++-- src/gdcmHeaderEntry.cxx | 2 +- src/gdcmHeaderEntry.h | 1 + src/gdcmParser.cxx | 164 +++++++++++++++++++++++++++++----------- src/gdcmParser.h | 2 +- vtk/vtkGdcmReader.cxx | 14 +++- vtk/vtkgdcmViewer.cxx | 2 + 7 files changed, 161 insertions(+), 56 deletions(-) diff --git a/ChangeLog b/ChangeLog index 081c3929..5873b1dd 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,12 +1,32 @@ +2004-04-22 Jean-Pierre Roux + * ENH Minor changes to the Print() methods + * ADD gdcmParser::PrintEntryNiceSQ() to allow SQ-indented + Header printing. Example given with : + PrintHeader fileName 2 new + (SQ based tree-like structure still to be done for the Header ...) + 2004-04-22 Mathieu Malaterre * ENH: Some cosmetic clean up for compilation with -W -Wall -Werror - * ENH: Change malloc/calloc/free with c++ equivalent - -2004-21-02 Jean-Pierre Roux + 1. I have added some unsigned where needed + 2. Some function parameter not used -> (void) + 3. In gdcmDicomDir.cxx, add GDCM_DICOMDIR_NONE case + 4. g++ don't like character '\' in comment + 5. #define jpeg_create_decompress jCreaDecompress + this really need to be fixed + 6. virtualize destructor of gdcmObject ... leakage + 7. sscanf(g->first.c_str(),"%x",&gr_bid); + this also really need to be fixed + 8. gdcm/src/jpeg/libijg8/CMakeLists.txt, + remove compression file + (as we only do decompression, right ?) + * ENH: Change malloc/calloc/free with c++ equivalent + +2004-04-21 Jean-Pierre Roux * FIX gdcmHeaderHelper::GetXSpacing - when a single value is found, xpacing is now defaulted to yspacing + when a single value is found (bug ?), xpacing is now + defaulted to yspacing -2004-19-02 Jean-Pierre Roux +2004-04-19 Jean-Pierre Roux * ADD gdcmData/Wrist.pap (PAPYRUS 3.0 -single frame-) for checking purpose * ENH add parameters : bool exception_on_error = false, @@ -16,7 +36,7 @@ * FIX vtk/vtkGdcmReader.cxx now uses enable_sequences = true in gdcmFile to allow reading of PAPYRUS 3.0 files -2004-06-02 Jean-Pierre Roux +2004-04-06 Jean-Pierre Roux * ADD gdcmData/E00001S03I0015.dcm for SQ checking purpose 2004-04-02 Jean-Pierre Roux diff --git a/src/gdcmHeaderEntry.cxx b/src/gdcmHeaderEntry.cxx index cdb3522e..fef886cb 100644 --- a/src/gdcmHeaderEntry.cxx +++ b/src/gdcmHeaderEntry.cxx @@ -104,7 +104,7 @@ void gdcmHeaderEntry::Print(std::ostream & os) { s << " [gdcm::too long for print (" << GetLength() << ") ]"; } - // Display the UID value (instead of displaying the rough code) + // Display the UID value (instead of displaying only the rough code) if (g == 0x0002) { // Any more to be displayed ? if ( (e == 0x0010) || (e == 0x0002) ) s << " ==>\t[" << ts->GetValue(v) << "]"; diff --git a/src/gdcmHeaderEntry.h b/src/gdcmHeaderEntry.h index 3d86e54c..8210809b 100644 --- a/src/gdcmHeaderEntry.h +++ b/src/gdcmHeaderEntry.h @@ -120,6 +120,7 @@ public: * of the current Dicom Header Entry */ inline void SetReadLength(guint32 l) { ReadLength = l; }; + /** * \ingroup gdcmHeaderEntry * \brief Sets only 'Usable Length' (*not* 'Read Length') diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 7df46969..0ec0e22f 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -28,6 +28,11 @@ #define UI1_2_840_10008_1_2_2 "1.2.840.10008.1.2.2" #define UI1_2_840_10008_1_2_1_99 "1.2.840.10008.1.2.1.99" +typedef struct { + guint32 totalSQlength; + guint32 alreadyParsedlength; +} pileElem; + //----------------------------------------------------------------------------- // Refer to gdcmParser::CheckSwap() const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256; @@ -126,7 +131,7 @@ void gdcmParser::PrintEntry(std::ostream & os) { * \ingroup gdcmParser * \brief Prints the Header Entries (Dicom Elements) * from the chained list - * and skips the elements belonging to a SeQuence + * and skips the elements belonging to a 'no length' SeQuence * @return */ void gdcmParser::PrintEntryNoSQ(std::ostream & os) { @@ -155,38 +160,115 @@ void gdcmParser::PrintEntryNoSQ(std::ostream & os) { * \ingroup gdcmParser * \brief Prints the Header Entries (Dicom Elements) * from the chained list - * and indents the elements belonging to a SeQuence + * and indents the elements belonging to any SeQuence + * \warning : will be removed * @return */ void gdcmParser::PrintEntryNiceSQ(std::ostream & os) { + pileElem pile[50]; // Hope embedded sequence depth is no more than 50 + int top =-1; int countSQ = 0; + int currentParsedlength = 0; + int totalElementlength; std::ostringstream tab; tab << " "; + + int DEBUG = 0; // Sorry; Dealing with e-film breaker images + // will (certainly) cause a lot of troubles ... + // I prefer keeping my 'trace' on . + for (ListTag::iterator i = listEntries.begin(); - i != listEntries.end(); - ++i) - { - // we ignore '0 length' SeQuences - if ( (*i)->GetVR() == "SQ" && (*i)->GetReadLength()!=0){ - countSQ ++; - } - // a SeQuence is over when a Sequence Delimiter Item is found - // pb : 'actual length' Sequence have NO Sequence Delimiter - // --> They 'never' finish : check the global length ! - if ( (*i)->GetGroup() == 0xfffe && (*i)->GetElement() == 0xe0dd){ - countSQ --; - continue; - } - - - if (countSQ != 0) { - for (int i=0;iSetPrintLevel(printLevel); - (*i)->Print(os); - } + i != listEntries.end(); + ++i) { + if ( (*i)->GetVR() == "SQ" && (*i)->GetReadLength() != 0) { // SQ found + countSQ++; + top ++; + if ( top >= 50) { + std::cout << "Kaie ! Kaie! SQ stack overflow" << std::endl; + return; + } + if (DEBUG) cout << "\n >>>>> empile niveau " << top + << "; Lgr SeQ: " << (*i)->GetReadLength() + << "\n" <GetReadLength(); + pile[top].alreadyParsedlength = 0; + currentParsedlength = 0; + + } else { // non SQ found + + if (countSQ != 0) { // we are 'inside a SeQuence' + if ( (*i)->GetGroup()==0xfffe && (*i)->GetElement()==0xe0dd){ + // we just found 'end of SeQuence' + + if (DEBUG) + std::cout << "fffe,e0dd : depile" << std::endl; + currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2 + countSQ --; + top --; + pile[top].alreadyParsedlength += currentParsedlength; + } else { + // we are on a 'standard' elem + // or a Zero-length SeQuence + + totalElementlength = (*i)->GetFullLength(); + currentParsedlength += totalElementlength; + pile[top].alreadyParsedlength += totalElementlength; + + if (pile[top].totalSQlength == 0xffffffff) { + if (DEBUG) + std::cout << "totalSeQlength == 0xffffffff" + << std::endl; + } else { + if (DEBUG) + cout << "alrdyPseLgt:" + << pile[top].alreadyParsedlength << " totSeQlgt: " + << pile[top].totalSQlength << " curPseLgt: " + << currentParsedlength + << endl; + while (pile[top].alreadyParsedlength==pile[top].totalSQlength) { + + if (DEBUG) + std::cout << " \n<<<<<< On depile niveau " << top + << "\n" << std::endl; + + currentParsedlength = pile[top].alreadyParsedlength; + countSQ --; + top --; + if (top >=0) { + + pile[top].alreadyParsedlength += currentParsedlength +12; + // 12 : length of 'SQ embedded' SQ element + currentParsedlength += 8; // gr:2 elem:2 vr:2 lgt:2 + + if (DEBUG) + std::cout << pile[top].alreadyParsedlength << " " + << pile[top].totalSQlength << " " + << currentParsedlength + << std::endl; + } + if (top == -1) { + currentParsedlength = 0; + break; + } + } + } + } + } // end : 'inside a SeQuence' + } + + if (countSQ != 0) { + for (int i=0;iSetPrintLevel(printLevel); + (*i)->Print(os); + + } // end for } + + + /** * \brief Prints The Dict Entries of THE public Dicom Dictionary * @return @@ -1380,25 +1462,14 @@ void gdcmParser::LoadHeaderEntry(gdcmHeaderEntry *Entry) { guint16 group = Entry->GetGroup(); std::string vr= Entry->GetVR(); guint32 length = Entry->GetLength(); - bool SkipLoad = false; fseek(fp, (long)Entry->GetOffset(), SEEK_SET); - - // the test was commented out to 'go inside' the SeQuences - // we don't any longer skip them ! - - // if( vr == "SQ" ) // (DO NOT remove this comment) - // SkipLoad = true; // A SeQuence "contains" a set of Elements. // (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 ) - SkipLoad = true; - - if ( SkipLoad ) { - Entry->SetLength(0); + if( group == 0xfffe ) { Entry->SetValue("gdcm::Skipped"); return; } @@ -1508,6 +1579,7 @@ void gdcmParser::AddHeaderEntry(gdcmHeaderEntry *newHeaderEntry) { //guint16 group = Entry->GetGroup(); //FIXME std::string vr = Entry->GetVR(); guint16 length16; + if ( (filetype == ExplicitVR) && (! Entry->IsImplicitVR()) ) { @@ -1862,8 +1934,7 @@ void gdcmParser::SkipHeaderEntry(gdcmHeaderEntry *entry) */ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 FoundLength) { - Entry->SetReadLength(FoundLength); // will be updated only if a bug is found - + Entry->SetReadLength(FoundLength); // will be updated only if a bug is found if ( FoundLength == 0xffffffff) { FoundLength = 0; } @@ -1879,7 +1950,7 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found } // Sorry for the patch! - // XMedCom did the trick to read some nasty GE images ... + // XMedCom did the trick to read some naughty GE images ... if (FoundLength == 13) { // The following 'if' will be removed when there is no more // images on Creatis HDs with a 13 length for Manufacturer... @@ -1907,15 +1978,16 @@ void gdcmParser::FixHeaderEntryFoundLength(gdcmHeaderEntry *Entry, guint32 Found FoundLength =0; // ReadLength is unchanged } - // a SeQuence Element is beginning - // fffe|e000 is just a marker, its length *should be* zero + // we found a 'delimiter' element + // fffe|xxxx is just a marker, we don't take its length into account else if(Entry->GetGroup() == 0xfffe) - { + { // *normally, fffe|0000 doesn't exist ! if( Entry->GetElement() != 0x0000 ) // gdcm-MR-PHILIPS-16-Multi-Seq.dcm - // causes extra troubles :-( - FoundLength =0; - } + // causes extra troubles :-( + FoundLength =0; + } + Entry->SetUsableLength(FoundLength); } diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 4cd3311e..239ff644 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -107,8 +107,8 @@ public: {PrintEntry(os);}; virtual void PrintEntry (std::ostream &os = std::cout); virtual void PrintEntryNoSQ (std::ostream &os = std::cout); + // the 2 following will be merged virtual void PrintEntryNiceSQ(std::ostream &os = std::cout); - virtual void PrintPubDict (std::ostream &os = std::cout); virtual void PrintShaDict (std::ostream &os = std::cout); diff --git a/vtk/vtkGdcmReader.cxx b/vtk/vtkGdcmReader.cxx index 0b240f61..34f53f25 100644 --- a/vtk/vtkGdcmReader.cxx +++ b/vtk/vtkGdcmReader.cxx @@ -422,7 +422,6 @@ int vtkGdcmReader::CheckFileCoherence() } fclose(fp); - cout << " Try to gdcmHeader ... " << endl; // Stage 1.2: check for Gdcm parsability gdcmHeaderHelper GdcmHeader(FileName->c_str(), false, true); // true : for enableSequences @@ -635,7 +634,8 @@ size_t vtkGdcmReader::LoadImageInMemory( { size = GdcmFile.GetImageDataSize(); Source = (unsigned char*)GdcmFile.GetImageData(); - } + } + unsigned char * pSource = Source; //pointer for later deletion unsigned char * Destination = Dest + size - LineSize; @@ -655,6 +655,16 @@ size_t vtkGdcmReader::LoadImageInMemory( UpdateProgressCount++; } } + +// DO NOT remove this commented out code . +// Nobody knows what's expecting you ... +// Just to 'see' what was actually read on disk :-( + +// FILE * f2; +// f2 = fopen("SpuriousFile.RAW","wb"); +// fwrite(Dest,size,1,f2); +// fclose(f2); + //GetImageData allocate a (void*)malloc, remove it: free(pSource); return size; diff --git a/vtk/vtkgdcmViewer.cxx b/vtk/vtkgdcmViewer.cxx index e0a17943..b9caec87 100644 --- a/vtk/vtkgdcmViewer.cxx +++ b/vtk/vtkgdcmViewer.cxx @@ -67,6 +67,7 @@ int main(int argc, char *argv[]) vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); vtkImageViewer2 *viewer = vtkImageViewer2::New(); + if( reader->GetLookupTable() ) { //convert to color: @@ -78,6 +79,7 @@ int main(int argc, char *argv[]) map->Delete(); } else + { viewer->SetInput ( reader->GetOutput() ); } -- 2.48.1