From: jpr Date: Thu, 26 Aug 2004 15:29:52 +0000 (+0000) Subject: - now, DicomDir stuff stakes into account the 'new' structure X-Git-Tag: Version0.5.bp~10 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=3fd520b58c8d1939994de2c63cc038c3e7ac9522;p=gdcm.git - now, DicomDir stuff stakes into account the 'new' structure - gdcmObject is no longer composed of 2 pointers in a chained list, but is an SQItem - useless gdcmDicomDir::WriteEntries method is removed - useless gdcmDicomDir::AddObjectToEnd method is removed - WARNING : BuidUpDicomDir not yet debugged, but I prefer to commit right now. -> See you tomorow --- diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 3959a469..fb5f5559 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.cxx,v $ Language: C++ - Date: $Date: 2004/08/02 16:42:14 $ - Version: $Revision: 1.63 $ + Date: $Date: 2004/08/26 15:29:52 $ + Version: $Revision: 1.64 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -52,7 +52,7 @@ gdcmDicomDir::gdcmDicomDir() :gdcmDocument( ) { - Initialize(); + Initialize(); // sets all private fields to NULL std::string pathBidon = "Bidon"; // Sorry, NULL not allowed ... SetElement(pathBidon, GDCM_DICOMDIR_META, NULL); // Set the META elements @@ -77,12 +77,12 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ): // que l'on ai passe un root directory ou un DICOMDIR // et quelle que soit la valeur de parseDir, // on a deja lance gdcmDocument - Initialize(); + Initialize(); // sets all private fields to NULL // gdcmDocument already executed // if user passed a root directory, sure we didn't get anything - if ( TagHT.begin() == TagHT.end() ) + if ( TagHT.begin() == TagHT.end() ) // when user passed a Directory to parse { dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : entry HT empty"); @@ -92,13 +92,14 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ): // we get current directory name char* dummy = new char[1000]; getcwd(dummy, (size_t)1000); - std::cout << "Directory to parse : [" << dummy << "]" << std::endl; SetFileName( dummy ); // will be converted into a string delete[] dummy; // no longer needed } - if ( parseDir ) + if ( parseDir ) // user asked for a recursive parsing of a root directory { + metaElems = NewMeta(); + dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir : Parse directory" " and create the DicomDir"); ParseDirectory(); @@ -110,7 +111,7 @@ gdcmDicomDir::gdcmDicomDir(std::string const & fileName, bool parseDir ): // apres le constructeur } } - else + else // Only if user passed a DICOMDIR { // Directory record sequence gdcmDocEntry *e = GetDocEntryByNumber(0x0004, 0x1220); @@ -133,18 +134,16 @@ gdcmDicomDir::~gdcmDicomDir() SetStartMethod(NULL); SetProgressMethod(NULL); SetEndMethod(NULL); - - if ( metaElems ) - { - delete metaElems; - } - for(ListDicomDirPatient::iterator cc = patients.begin(); cc!= patients.end(); ++cc) { delete *cc; } + if ( metaElems ) + { + delete metaElems; + } } //----------------------------------------------------------------------------- @@ -341,81 +340,43 @@ void gdcmDicomDir::SetEndMethodArgDelete(gdcmMethod *method) */ bool gdcmDicomDir::Write(std::string const & fileName) -{ - FILE * fp1 = fopen(fileName.c_str(), "wb"); - if( !fp1 ) +{ + uint16_t sq[5] = { 0x0004, 0x1220, 0x0000, 0xffff, 0xffff }; + uint16_t sqt[3]= { 0xfffe, 0xe0dd, 0x0000 }; + + FILE * fp = fopen(fileName.c_str(), "wb"); + if( !fp ) { printf("Failed to open(write) File [%s] \n", fileName.c_str()); return false; } - char * filePreamble = new char[128]; - fwrite(filePreamble,128,1,fp1); - fwrite("DICM",4,1,fp1); + uint8_t* filePreamble = new uint8_t[128]; + memset(filePreamble, 0, 128); + fwrite(filePreamble,128,1,fp); + fwrite("DICM",4,1,fp); delete[] filePreamble; - UpdateDirectoryRecordSequenceLength(); - WriteEntries(fp1); - - fclose( fp1 ); + // UpdateDirectoryRecordSequenceLength(); // TODO (if *really* usefull) + gdcmDicomDirMeta *ptrMeta = GetDicomDirMeta(); + ptrMeta->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 + + 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 + fclose( fp ); return true; } -/** - * \brief Writes in a file using the tree-like structure. - * @param _fp already open file pointer - */ - -void gdcmDicomDir::WriteEntries(FILE *) //_fp -{ - /// \todo (?) tester les echecs en ecriture - /// (apres chaque fwrite, dans le WriteEntry) - - -/* TODO : to go on compiling - - gdcmDicomDirMeta *ptrMeta; - ListDicomDirPatient::iterator itPatient; - ListDicomDirStudy::iterator itStudy; - ListDicomDirSerie::iterator itSerie; - ListDicomDirImage::iterator itImage; - ListTag::iterator i; - - ptrMeta= GetDicomDirMeta(); - for(i=ptrMeta->debut();i!=ptrMeta->fin();++i) { - WriteEntry(*i,_fp, gdcmExplicitVR); - } - - itPatient = GetDicomDirPatients().begin(); - while ( itPatient != GetDicomDirPatients().end() ) { - for(i=(*itPatient)->debut();i!=(*itPatient)->fin();++i) { - WriteEntry(*i,_fp, gdcmExplicitVR); - } - itStudy = ((*itPatient)->GetDicomDirStudies()).begin(); - while (itStudy != (*itPatient)->GetDicomDirStudies().end() ) { - for(i=(*itStudy)->debut();i!=(*itStudy)->fin();++i) { - WriteEntry(*i,_fp, gdcmExplicitVR); - } - itSerie = ((*itStudy)->GetDicomDirSeries()).begin(); - while (itSerie != (*itStudy)->GetDicomDirSeries().end() ) { - for(i=(*itSerie)->debut();i!=(*itSerie)->fin();++i) { - WriteEntry(*i,_fp, gdcmExplicitVR); - } - itImage = ((*itSerie)->GetDicomDirImages()).begin(); - while (itImage != (*itSerie)->GetDicomDirImages().end() ) { - for(i=(*itImage)->debut();i!=(*itImage)->fin();++i) { - WriteEntry(*i,_fp, gdcmExplicitVR); - } - ++itImage; - } - ++itSerie; - } - ++itStudy; - } - ++itPatient; - } - */ -} - //----------------------------------------------------------------------------- // Protected @@ -475,8 +436,7 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path) std::string tmp = fileList.GetDirName(); //for each Header of the chained list, add/update the Patient/Study/Serie/Image info - SetElements(tmp, list); - + SetElements(tmp, list); CallEndMethod(); } @@ -484,18 +444,35 @@ void gdcmDicomDir::CreateDicomDirChainedList(std::string const & path) * \ingroup gdcmDicomDir * \brief adds *the* Meta to a partially created DICOMDIR */ - - /// \todo FIXME : Heuuuuu ! Il prend les Entries du Document deja parse, - /// il ne fabrique rien ! gdcmDicomDirMeta * gdcmDicomDir::NewMeta() { gdcmDicomDirMeta *m = new gdcmDicomDirMeta( &TagHT ); - for ( TagDocEntryHT::iterator cc = TagHT.begin(); - cc != TagHT.end(); ++cc) - { - m->AddDocEntry( cc->second ); + + if ( TagHT.begin() != TagHT.end() ) // after Document Parsing + { + TagDocEntryHT::iterator lastOneButSequence = TagHT.end(); + lastOneButSequence --; + // This works because ALL the 'out of Sequence' Tags belong to Meta Elems + // (we skip 0004|1220 [Directory record sequence] ) + for ( TagDocEntryHT::iterator cc = TagHT.begin(); + cc != lastOneButSequence; + ++cc) + { + m->AddDocEntry( cc->second ); + } } + else // after root directory parsing + { + //cout << "gdcmDicomDir::NewMeta avec FillObject" << endl; + std::list elemList; + elemList=gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements(); + m->FillObject(elemList); + // we create the Sequence manually + //gdcmSeqEntry *se =NewSeqEntryByNumber(0x0004, 0x1220); // NOT YET! + //m->AddEntry(se); + } + m->SetSQItemNumber(0); // To avoid further missprinting return m; } @@ -579,7 +556,7 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, gdcmDictEntry *dictEntry; gdcmValEntry *entry; std::string val; - //gdcmObject *o; + gdcmSQItem *si = new gdcmSQItem(0); // all the items will be at level 1 switch( type ) { case GDCM_DICOMDIR_IMAGE: @@ -600,30 +577,38 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, case GDCM_DICOMDIR_META: elemList = gdcmGlobal::GetDicomDirElements()->GetDicomDirMetaElements(); + // add already done ? break; default: return; } + // removed all the seems-to-be-useless stuff about Referenced Image Sequence + // to avoid further troubles + // 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 + // for all the relevant elements found in their own spot of the DicomDir.dic + // FIXME : troubles found when it's a SeqEntry for( it = elemList.begin(); it != elemList.end(); ++it) { tmpGr = it->group; tmpEl = it->elem; dictEntry = GetPubDict()->GetDictEntryByNumber(tmpGr, tmpEl); + entry = new gdcmValEntry( dictEntry ); // Be sure it's never a BinEntry ! entry->SetOffset(0); // just to avoid further missprinting + entry->SetLength(0); // just to avoid further missprinting if( header ) // NULL when we Build Up (ex nihilo) a DICOMDIR // or when we add the META elems - { val = header->GetEntryByNumber(tmpGr, tmpEl); - } else - { val = GDCM_UNFOUND; - } if( val == GDCM_UNFOUND) { @@ -641,24 +626,20 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, val = header->GetFileName(); } else - { val = &(header->GetFileName().c_str()[path.length()]); - } } else - { val = it->value; - } } else { if ( header->GetEntryLengthByNumber(tmpGr,tmpEl) == 0 ) - { val = it->value; - } } - entry->SetValue( val ); + // GDCM_UNFOUND or not ! + + entry->SetValue( val ); // troubles expected when vr=SQ ... if( dictEntry ) { @@ -683,13 +664,35 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type, entry->SetLength( entry->GetValue().length() ); } } - std::cout << " was TagHT[entry->GetKey()] = entry " << std::endl; - if ( type == GDCM_DICOMDIR_META ) { + + if ( type == GDCM_DICOMDIR_META ) // fusible : should never print ! std::cout << " special Treatment for GDCM_DICOMDIR_META" << std::endl; - - } - //TagHT[entry->GetKey()] = entry; // FIXME : use a SEQUENCE ! + si->AddEntry(entry); } + switch( type ) + { + case GDCM_DICOMDIR_IMAGE: + AddDicomDirImageToEnd(si); + break; + + case GDCM_DICOMDIR_SERIE: + AddDicomDirSerieToEnd(si); + break; + + case GDCM_DICOMDIR_STUDY: + AddDicomDirStudyToEnd(si); + break; + + case GDCM_DICOMDIR_PATIENT: + AddDicomDirPatientToEnd(si); + break; + + default: + return; + } + //int count=1; // find a trick to increment + //s->AddEntry(si, count); // Seg Faults + } /** @@ -788,25 +791,21 @@ void gdcmDicomDir::CreateDicomDir() if( v == "PATIENT " ) { AddDicomDirPatientToEnd( *i ); - //AddObjectToEnd(type,*i); type = gdcmDicomDir::GDCM_DICOMDIR_PATIENT; } else if( v == "STUDY " ) { AddDicomDirStudyToEnd( *i ); - // AddObjectToEnd(type,*i); type = gdcmDicomDir::GDCM_DICOMDIR_STUDY; } else if( v == "SERIES" ) { AddDicomDirSerieToEnd( *i ); - // AddObjectToEnd(type,*i); type = gdcmDicomDir::GDCM_DICOMDIR_SERIE; } else if( v == "IMAGE " ) { AddDicomDirImageToEnd( *i ); - // AddObjectToEnd(type,*i); type = gdcmDicomDir::GDCM_DICOMDIR_IMAGE; } else @@ -818,46 +817,6 @@ void gdcmDicomDir::CreateDicomDir() } } -/** - * \ingroup gdcmDicomDir - * \brief AddObjectToEnd - * @param type - * @param begin iterator on the first DocEntry within the chained List - * @param end iterator on the last DocEntry within the chained List - */ - -// now useless ? - -/*void gdcmDicomDir::AddObjectToEnd(gdcmDicomDirType type,gdcmSQItem *s) -{ - if(s==NULL) // ?? - return; - - switch(type) - { - case gdcmDicomDir::GDCM_DICOMDIR_META: - AddDicomDirMeta(); - break; - case gdcmDicomDir::GDCM_DICOMDIR_PATIENT: - AddDicomDirPatientToEnd(s); - break; - case gdcmDicomDir::GDCM_DICOMDIR_STUDY: - AddDicomDirStudyToEnd(s); - break; - case gdcmDicomDir::GDCM_DICOMDIR_SERIE: - AddDicomDirSerieToEnd(s); - break; - case gdcmDicomDir::GDCM_DICOMDIR_IMAGE: - AddDicomDirImageToEnd(s); - break; - case gdcmDicomDir::GDCM_DICOMDIR_NONE: - AddDicomDirImageToEnd(s); //FIXME - break; - } -} - -*/ - /** * \ingroup gdcmDicomDir * \brief Well ... there is only one occurence @@ -960,7 +919,7 @@ void gdcmDicomDir::SetElements(std::string &path, VectDocument &list) std::string studCurInstanceUID, studCurID; std::string serCurInstanceUID, serCurID; - SetElement( path, GDCM_DICOMDIR_META,NULL); + //SetElement( path, GDCM_DICOMDIR_META,NULL); // already done (NewMeta) for( VectDocument::iterator it = list.begin(); it != list.end(); ++it ) diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index 1c1af26a..4f80a623 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDir.h,v $ Language: C++ - Date: $Date: 2004/08/02 16:42:14 $ - Version: $Revision: 1.26 $ + Date: $Date: 2004/08/26 15:29:52 $ + Version: $Revision: 1.27 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -84,8 +84,7 @@ public: gdcmDicomDirMeta* NewMeta(); gdcmDicomDirPatient* NewPatient(); -// Write - void WriteEntries(FILE *_fp); +// Write bool Write(std::string const & fileName); /// Types of the gdcmObject within the gdcmDicomDir diff --git a/src/gdcmDicomDirImage.h b/src/gdcmDicomDirImage.h index 8365f400..dac05c64 100644 --- a/src/gdcmDicomDirImage.h +++ b/src/gdcmDicomDirImage.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirImage.h,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.6 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -30,7 +30,7 @@ public: ~gdcmDicomDirImage(); - virtual void Print(std::ostream &os = std::cout); + virtual void Print(std::ostream &os = std::cout); }; //----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDirMeta.cxx b/src/gdcmDicomDirMeta.cxx index 59d41128..15bfa8d0 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/01 02:39:09 $ - Version: $Revision: 1.5 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -44,9 +44,7 @@ gdcmDicomDirMeta::~gdcmDicomDirMeta() //----------------------------------------------------------------------------- // Print /** - * \ingroup gdcmDicomDirMeta * \brief Prints the Object - * @return */ void gdcmDicomDirMeta::Print(std::ostream &os) { @@ -54,9 +52,20 @@ void gdcmDicomDirMeta::Print(std::ostream &os) gdcmObject::Print(os); } + //----------------------------------------------------------------------------- // Public + +/** + * \brief Writes the Object + * @return + */ +void gdcmDicomDirMeta::Write(FILE *fp, FileType t) +{ + gdcmObject::Write(fp, t); +} + //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmDicomDirMeta.h b/src/gdcmDicomDirMeta.h index fe3de123..7f8bd579 100644 --- a/src/gdcmDicomDirMeta.h +++ b/src/gdcmDicomDirMeta.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirMeta.h,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.5 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -30,6 +30,7 @@ public: ~gdcmDicomDirMeta(); virtual void Print(std::ostream &os = std::cout); + virtual void Write(FILE * fp, FileType t); }; //----------------------------------------------------------------------------- diff --git a/src/gdcmDicomDirPatient.cxx b/src/gdcmDicomDirPatient.cxx index 3cc33bc7..625adecb 100644 --- a/src/gdcmDicomDirPatient.cxx +++ b/src/gdcmDicomDirPatient.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.cxx,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.10 $ + Date: $Date: 2004/08/26 15:29:52 $ + Version: $Revision: 1.11 $ 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,6 @@ //----------------------------------------------------------------------------- // Constructor / Destructor /** - * \ingroup gdcmDicomDirPatient * \brief Constructor * @param s SQ Item holding the elements related to this "PATIENT" part * @param ptagHT pointer to the HTable (gdcmObject needs it @@ -35,7 +34,6 @@ gdcmDicomDirPatient::gdcmDicomDirPatient(gdcmSQItem *s, TagDocEntryHT *ptagHT): docEntries = s->GetDocEntries(); } /** - * \ingroup gdcmDicomDirPatient * \brief Constructor * @param ptagHT pointer to the HTable (gdcmObject needs it * to build the gdcmHeaderEntries) @@ -45,7 +43,6 @@ gdcmDicomDirPatient::gdcmDicomDirPatient(TagDocEntryHT *ptagHT): { } /** - * \ingroup gdcmDicomDirPatient * \brief Canonical destructor. */ gdcmDicomDirPatient::~gdcmDicomDirPatient() @@ -60,7 +57,6 @@ gdcmDicomDirPatient::~gdcmDicomDirPatient() //----------------------------------------------------------------------------- // Print /** - * \ingroup gdcmDicomDirPatient * \brief Prints the Object * @return */ @@ -77,11 +73,23 @@ void gdcmDicomDirPatient::Print(std::ostream &os) } } +/** + * \brief Writes the Object + * @return + */ +void gdcmDicomDirPatient::Write(FILE *fp, FileType t) +{ + gdcmObject::Write(fp, t); + + for(ListDicomDirStudy::iterator cc = studies.begin();cc!=studies.end();++cc) + { + (*cc)->Write( fp, t ); + } +} //----------------------------------------------------------------------------- // Public /** - * \ingroup gdcmDicomDir * \brief adds a new Patient at the begining of the PatientList * of a partially created DICOMDIR */ diff --git a/src/gdcmDicomDirPatient.h b/src/gdcmDicomDirPatient.h index f4cc06e8..eb3e7bde 100644 --- a/src/gdcmDicomDirPatient.h +++ b/src/gdcmDicomDirPatient.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirPatient.h,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.6 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -35,7 +35,7 @@ public: ~gdcmDicomDirPatient(); virtual void Print(std::ostream &os = std::cout); - + virtual void Write(FILE *fp, FileType t); /// Returns the STUDY chained List for this PATIENT. ListDicomDirStudy &GetDicomDirStudies() { return studies; }; diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index 146d1c06..22f4b4d4 100644 --- a/src/gdcmDicomDirSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.cxx,v $ Language: C++ - Date: $Date: 2004/08/01 00:59:21 $ - Version: $Revision: 1.12 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -78,6 +78,21 @@ void gdcmDicomDirSerie::Print(std::ostream &os) //----------------------------------------------------------------------------- // Public + +/** + * \brief Writes the Object + * @return + */ +void gdcmDicomDirSerie::Write(FILE *fp, FileType t) +{ + gdcmObject::Write(fp, t); + + for(ListDicomDirImage::iterator cc = images.begin();cc!=images.end();++cc) + { + (*cc)->Write( fp, t ); + } +} + /** * \brief adds a new Image (with the basic elements) to a partially created DICOMDIR */ diff --git a/src/gdcmDicomDirSerie.h b/src/gdcmDicomDirSerie.h index 6305de86..ae419146 100644 --- a/src/gdcmDicomDirSerie.h +++ b/src/gdcmDicomDirSerie.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirSerie.h,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.6 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -35,6 +35,7 @@ public: ~gdcmDicomDirSerie(); virtual void Print(std::ostream &os = std::cout); + virtual void Write(FILE *fp, FileType t); /** * \ingroup gdcmDicomDirSerie * \brief returns the IMAGE chained List for this SERIE. diff --git a/src/gdcmDicomDirStudy.cxx b/src/gdcmDicomDirStudy.cxx index d1a66ff9..cd3b07c6 100644 --- a/src/gdcmDicomDirStudy.cxx +++ b/src/gdcmDicomDirStudy.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.cxx,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.9 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -80,6 +80,20 @@ void gdcmDicomDirStudy::Print(std::ostream &os) //----------------------------------------------------------------------------- // Public +/** + * \brief Writes the Object + * @return + */ +void gdcmDicomDirStudy::Write(FILE *fp, FileType t) +{ + gdcmObject::Write(fp, t); + + for(ListDicomDirSerie::iterator cc = series.begin();cc!=series.end();++cc) + { + (*cc)->Write( fp, t ); + } +} + /** * \ingroup gdcmDicomStudy * \brief adds a new Serie at the begining of the SerieList diff --git a/src/gdcmDicomDirStudy.h b/src/gdcmDicomDirStudy.h index bf57e91d..8c3c8d3e 100644 --- a/src/gdcmDicomDirStudy.h +++ b/src/gdcmDicomDirStudy.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDicomDirStudy.h,v $ Language: C++ - Date: $Date: 2004/08/01 02:39:09 $ - Version: $Revision: 1.6 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -35,6 +35,7 @@ public: ~gdcmDicomDirStudy(); virtual void Print(std::ostream &os = std::cout); + virtual void Write(FILE *fp, FileType t); /** * \ingroup gdcmDicomDirStudy * \brief returns the SERIE chained List for this STUDY. diff --git a/src/gdcmDocEntrySet.cxx b/src/gdcmDocEntrySet.cxx index e33a0cbc..ba497b5f 100644 --- a/src/gdcmDocEntrySet.cxx +++ b/src/gdcmDocEntrySet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.cxx,v $ Language: C++ - Date: $Date: 2004/08/01 03:20:23 $ - Version: $Revision: 1.15 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -56,7 +56,7 @@ gdcmDocEntrySet::~gdcmDocEntrySet() /** - * \brief Build a new Element Value from all the low level arguments. + * \brief Build a new Val 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 underlying DictEntry @@ -84,7 +84,7 @@ gdcmValEntry *gdcmDocEntrySet::NewValEntryByNumber(uint16_t group, /** - * \brief Build a new Element Value from all the low level arguments. + * \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 underlying DictEntry @@ -109,6 +109,31 @@ gdcmBinEntry *gdcmDocEntrySet::NewBinEntryByNumber(uint16_t group, } return newEntry; } + +/** + * \brief Build a new Seq 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 underlying DictEntry + * @param Elem element number of the underlying DictEntry + */ +gdcmSeqEntry *gdcmDocEntrySet::NewSeqEntryByNumber(uint16_t Group, + uint16_t Elem) +{ + // Find out if the tag we encountered is in the dictionaries: + gdcmDictEntry *DictEntry = GetDictEntryByNumber(Group, Elem); + if (!DictEntry) + DictEntry = NewVirtualDictEntry(Group, Elem); + + gdcmSeqEntry *NewEntry = new gdcmSeqEntry(DictEntry, 1); // FIXME : 1 + if (!NewEntry) + { + dbg.Verbose(1, "gdcmDocument::NewSeqEntryByNumber", + "failed to allocate gdcmSeqEntry"); + return NULL; + } + return NewEntry; +} //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmDocEntrySet.h b/src/gdcmDocEntrySet.h index e3af97b3..26fd1269 100644 --- a/src/gdcmDocEntrySet.h +++ b/src/gdcmDocEntrySet.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocEntrySet.h,v $ Language: C++ - Date: $Date: 2004/08/01 03:20:23 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/08/26 15:29:52 $ + 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 @@ -69,6 +69,8 @@ protected: gdcmDocEntry* NewDocEntryByNumber(uint16_t group, uint16_t element); gdcmDocEntry* NewDocEntryByName (std::string const & name); + gdcmSeqEntry* NewSeqEntryByNumber(uint16_t group, + uint16_t element); // DictEntry related utilities gdcmDictEntry *GetDictEntryByName (std::string const & name); diff --git a/src/gdcmDocument.cxx b/src/gdcmDocument.cxx index b6127549..37966499 100644 --- a/src/gdcmDocument.cxx +++ b/src/gdcmDocument.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.cxx,v $ Language: C++ - Date: $Date: 2004/08/16 04:34:56 $ - Version: $Revision: 1.67 $ + Date: $Date: 2004/08/26 15:29:53 $ + Version: $Revision: 1.68 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -94,7 +94,7 @@ gdcmDocument::gdcmDocument( std::string const & filename ) { return; } - + dbg.Verbose(0, "gdcmDocument::gdcmDocument: starting parsing of file: ", Filename.c_str()); rewind(Fp); @@ -260,8 +260,6 @@ bool gdcmDocument::IsReadable() { if( Filetype == gdcmUnknown) { - std::cout << " gdcmDocument::IsReadable: Filetype " << Filetype - << " " << "gdcmUnknown " << gdcmUnknown << std::endl; //JPR dbg.Verbose(0, "gdcmDocument::IsReadable: wrong filetype"); return false; } @@ -671,6 +669,35 @@ gdcmBinEntry * gdcmDocument::ReplaceOrCreateByNumber( return b; } + +/* + * \brief Modifies the value of a given Header Entry (Dicom Element) + * when it exists. Create it when unexistant. + * @param Group Group number of the Entry + * @param Elem Element number of the Entry + * \return pointer to the modified/created SeqEntry (NULL when creation + * failed). + */ +gdcmSeqEntry * gdcmDocument::ReplaceOrCreateByNumber( + uint16_t group, + uint16_t elem) +{ + gdcmSeqEntry* b = 0; + gdcmDocEntry* a = GetDocEntryByNumber( group, elem); + if (!a) + { + a = NewSeqEntryByNumber(group, elem); + if (!a) + { + return 0; + } + + b = new gdcmSeqEntry(a, 1); // FIXME : 1 (Depth) + AddEntry(b); + } + return b; +} + /** * \brief Set a new value if the invoked element exists * Seems to be useless !!! @@ -1207,7 +1234,7 @@ uint32_t gdcmDocument::SwapLong(uint32_t a) a=( ((a<< 8) & 0xff00ff00) | ((a>>8) & 0x00ff00ff) ); break; default : - std::cout << "swapCode= " << SwapCode << std::endl; + //std::cout << "swapCode= " << SwapCode << std::endl; dbg.Error(" gdcmDocument::SwapLong : unset swap code"); a = 0; } @@ -1372,7 +1399,6 @@ long gdcmDocument::ParseDES(gdcmDocEntrySet *set, } delete newDocEntry; } - return l; // Probably useless } @@ -1613,8 +1639,7 @@ void gdcmDocument::FindDocEntryLength( gdcmDocEntry *entry ) { uint16_t element = entry->GetElement(); std::string vr = entry->GetVR(); - uint16_t length16; - + uint16_t length16; if ( Filetype == gdcmExplicitVR && !entry->IsImplicitVR() ) { diff --git a/src/gdcmDocument.h b/src/gdcmDocument.h index 24e1cd2e..d43a644e 100644 --- a/src/gdcmDocument.h +++ b/src/gdcmDocument.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDocument.h,v $ Language: C++ - Date: $Date: 2004/08/02 16:42:14 $ - Version: $Revision: 1.30 $ + Date: $Date: 2004/08/26 15:29:53 $ + 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 @@ -141,6 +141,7 @@ public: gdcmBinEntry* ReplaceOrCreateByNumber(void *voidArea, int lgth, uint16_t group, uint16_t elem); + gdcmSeqEntry* ReplaceOrCreateByNumber(uint16_t group, uint16_t elem); bool ReplaceIfExistByNumber ( std::string const & value, uint16_t group, uint16_t elem ); @@ -199,8 +200,8 @@ protected: private: // Read - long ParseDES(gdcmDocEntrySet *set, long offset, long l_max,bool delim_mode); - long ParseSQ (gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode); + long ParseDES(gdcmDocEntrySet *set,long offset, long l_max, bool delim_mode); + long ParseSQ (gdcmSeqEntry *seq, long offset, long l_max, bool delim_mode); void LoadDocEntry (gdcmDocEntry *); void FindDocEntryLength(gdcmDocEntry *) throw ( gdcmFormatError ); diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index b016e992..484cc690 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmFile.cxx,v $ Language: C++ - Date: $Date: 2004/08/02 16:42:14 $ - Version: $Revision: 1.120 $ + Date: $Date: 2004/08/26 15:29:53 $ + Version: $Revision: 1.121 $ 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 @@ typedef std::pair IterHT; -//----------------------------------------------------------------------------- +//------------------------------------------------------------------------- // Constructor / Destructor /** * \ingroup gdcmFile diff --git a/src/gdcmObject.h b/src/gdcmObject.h index 2f4317fa..04363a85 100644 --- a/src/gdcmObject.h +++ b/src/gdcmObject.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmObject.h,v $ Language: C++ - Date: $Date: 2004/08/01 00:59:21 $ - Version: $Revision: 1.18 $ + Date: $Date: 2004/08/26 15:29:53 $ + Version: $Revision: 1.19 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -39,6 +39,9 @@ typedef std::list ListContent; class GDCM_EXPORT gdcmObject : public gdcmSQItem { public: + + gdcmObject(TagDocEntryHT *ptagHT, int depth = 0); + virtual ~gdcmObject(); /** * \brief Sets the print level for the Dicom Header * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy @@ -51,9 +54,8 @@ public: protected: // Constructor and destructor are protected to avoid end user to - // instanciate from this class. - gdcmObject(TagDocEntryHT *ptagHT, int depth = 0); - virtual ~gdcmObject(); + // instanciate from this class. + // NO ! gdcmDicomDir needs to instanciate it! // Members : ///\brief detail level to be printed diff --git a/src/gdcmSQItem.cxx b/src/gdcmSQItem.cxx index b861e9d9..7d61d3cc 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/01 03:20:23 $ - Version: $Revision: 1.23 $ + Date: $Date: 2004/08/26 15:29:53 $ + 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 @@ -78,7 +78,7 @@ gdcmSQItem::~gdcmSQItem() os << s.str(); Entry->SetPrintLevel(2); - Entry->Print(os); + Entry->Print(os); if ( gdcmSeqEntry* SeqEntry = dynamic_cast(Entry) ) { (void)SeqEntry; //not used diff --git a/src/gdcmSeqEntry.cxx b/src/gdcmSeqEntry.cxx index 38793b60..5ee43c77 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/07/21 14:02:11 $ - Version: $Revision: 1.22 $ + Date: $Date: 2004/08/26 15:29:53 $ + 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 @@ -36,8 +36,23 @@ gdcmSeqEntry::gdcmSeqEntry(gdcmDictEntry* e, int depth) delimitor_mode = false; seq_term = NULL; SQDepthLevel = depth; + UsableLength = 0; + ReadLength = 0xffffffff; } +/** + * \brief Constructor from a given gdcmSeqEntry + * @param e Pointer to existing Doc entry + */ +gdcmSeqEntry::gdcmSeqEntry(gdcmDocEntry* e, int depth) : gdcmDocEntry(e->GetDictEntry()) +{ + this->UsableLength = 0; + this->ReadLength = 0xffffffff; + this->ImplicitVR = e->IsImplicitVR(); + this->Offset = e->GetOffset(); + //this->printLevel = e->GetPrintLevel(); // no longer exists ?!? + this->SQDepthLevel = e->GetDepthLevel(); +} /** * \brief Canonical destructor. */ @@ -101,12 +116,15 @@ void gdcmSeqEntry::Write(FILE *fp, FileType filetype) ++cc) { (*cc)->Write(fp, filetype); - - 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 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 Delimitaion item + + //we force the writting of a Sequence Delimitation item // because we wrote the Sequence as a 'no Length' sequence fwrite ( &seq_term_gr,(size_t)2 ,(size_t)1 ,fp); fwrite ( &seq_term_el,(size_t)2 ,(size_t)1 ,fp); diff --git a/src/gdcmSeqEntry.h b/src/gdcmSeqEntry.h index 6eed4cb1..61c7d8b6 100644 --- a/src/gdcmSeqEntry.h +++ b/src/gdcmSeqEntry.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmSeqEntry.h,v $ Language: C++ - Date: $Date: 2004/07/02 13:55:28 $ - Version: $Revision: 1.14 $ + Date: $Date: 2004/08/26 15:29:53 $ + 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 @@ -32,6 +32,7 @@ class GDCM_EXPORT gdcmSeqEntry : public gdcmDocEntry { public: gdcmSeqEntry(gdcmDictEntry* e, int depth); + gdcmSeqEntry(gdcmDocEntry* d, int depth); virtual ~gdcmSeqEntry(); virtual void Print(std::ostream &os = std::cout);