From 1b5fd950fda2fb2dbe9aa69bac545a8b588b71d0 Mon Sep 17 00:00:00 2001 From: jpr Date: Wed, 17 Mar 2004 14:26:09 +0000 Subject: [PATCH] * FIX now file names and directory name are written properly in the DICOMDIR now gdcmDicomDir constructor may be call without any trick about the name --- ChangeLog | 8 ++++ src/gdcmDicomDir.cxx | 81 ++++++++++++++++++--------------------- src/gdcmDicomDir.h | 14 ++++++- src/gdcmDicomDirElement.h | 5 +++ src/gdcmDicomDirSerie.cxx | 4 +- src/gdcmDirList.cxx | 5 ++- src/gdcmObject.cxx | 2 +- src/gdcmParser.cxx | 5 ++- src/gdcmParser.h | 11 +++++- src/gdcmUtil.cxx | 55 ++++++++++++++++++++++++++ src/gdcmUtil.h | 3 ++ 11 files changed, 138 insertions(+), 55 deletions(-) diff --git a/ChangeLog b/ChangeLog index 54ca67ea..48bbcc81 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2004-03-17 Jean-Pierre Roux + * REM (Eric Boix bug) : removal of meaningless + gdcmDicomDirImage::NewImage function. + * FIX now file names and directory name are written properly in the + DICOMDIR + now gdcmDicomDir constructor may be call without any trick + about the name + 2004-03-16 Eric Boix * FIX (JPR bug) : src/gdcmDicomDirImage.cxx added missing definition of gdcmDicomDirImage::NewImage as empty function. diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index 14b5b41b..f1c7e679 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -12,6 +12,7 @@ #include #include +#include //----------------------------------------------------------------------------- // For full DICOMDIR description, see: @@ -38,6 +39,10 @@ gdcmDicomDir::gdcmDicomDir(const char *Name, bool parseDir, // et quelle que soit la valeur de parseDir, // on a lance gdcmParser + cout << "---------------------------------------------- " << Name <GetDicomDirPatientElements(); std::list::iterator debInsertion, finInsertion, i,j; - - + debInsertion = metaElems->fin(); ++debInsertion; finInsertion=debInsertion; @@ -458,23 +470,6 @@ gdcmDicomDirPatient * gdcmDicomDir::NewPatient(void) { return p; } -/* - * \ingroup gdcmDicomDir - * \brief Get the DicomDir path - */ -std::string gdcmDicomDir::GetPath(void) -{ - std::string path=GetFileName(); - - int pos1=path.rfind("/"); - int pos2=path.rfind("\\"); - if(pos1>pos2) - path.resize(pos1); - else - path.resize(pos2); - - return(path); -} /* * \ingroup gdcmDicomDir * \brief CallStartMethod @@ -692,8 +687,8 @@ void gdcmDicomDir::AddDicomDirSerieToEnd(ListTag::iterator begin,ListTag::iterat /* * \ingroup gdcmDicomDir * \brief for each Header of the chained list, add/update the Patient/Study/Serie/Image info - * @param path - * @param list + * @param path path of the root directory + * @param list chained list of Headers */ void gdcmDicomDir::SetElements(std::string &path, ListHeader &list) { @@ -745,7 +740,7 @@ void gdcmDicomDir::SetElements(std::string &path, ListHeader &list) * \ingroup gdcmDicomDir * \brief adds to the HTable and at the end of the Chained List * the gdcmEntries (Dicom Elements) corresponding to the given type - * @param path file Path (only used when type = GDCM_DICOMDIR_IMAGE + * @param path full path file name(only used when type = GDCM_DICOMDIR_IMAGE * @param type gdcmObject type to create (GDCM_DICOMDIR_PATIENT, GDCM_DICOMDIR_STUDY, GDCM_DICOMDIR_SERIE ...) * @param header gdcmHeader of the current file */ @@ -783,7 +778,6 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader { tmpGr=it->group; tmpEl=it->elem; - dictEntry=GetPubDict()->GetDictEntryByNumber(tmpGr,tmpEl); entry=new gdcmHeaderEntry(dictEntry); entry->SetOffset(0); // just to avoid missprinting @@ -795,10 +789,10 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader if(val==GDCM_UNFOUND) { - if((tmpGr==0x0004) &&(tmpEl==0x1130) ) - { - // TODO force the *end* File Name(remove path) - val=path; + if((tmpGr==0x0004) &&(tmpEl==0x1130) ) // File-set ID + { + // force to the *end* File Name + val=GetName(path); } else if( (tmpGr==0x0004) && (tmpEl==0x1500) ) // Only used for image { @@ -807,8 +801,9 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader dbg.Verbose(0, "gdcmDicomDir::SetElement : the base path of file name is incorrect"); val=header->GetFileName(); } - else - val=&(header->GetFileName()[path.length()]); + else { + val=&(header->GetFileName().c_str()[path.length()]); + } } else { @@ -827,7 +822,7 @@ void gdcmDicomDir::SetElement(std::string &path,gdcmDicomDirType type,gdcmHeader { if(dictEntry->GetGroup()==0xfffe) { - entry->SetLength(entry->GetValue().length()); //JPR + entry->SetLength(entry->GetValue().length()); } else if( (dictEntry->GetVR()=="UL") || (dictEntry->GetVR()=="SL") ) { diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index cd700d34..30f86946 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -35,7 +35,18 @@ public: ~gdcmDicomDir(void); - void SetPrintLevel(int level) { printLevel = level; }; + /** + * \ingroup gdcmParser + * \brief Sets the print level for the Dicom Header + * \note 0 for Light Print; 1 for 'medium' Print, 2 for Heavy + */ + void SetPrintLevel(int level) + { printLevel = level; }; + /** + * \ingroup gdcmParser + * \brief canonical Printer + * \sa SetPrintLevel + */ virtual void Print(std::ostream &os = std::cout); // Informations contained in the parser @@ -86,7 +97,6 @@ public: protected: void CreateDicomDirChainedList(std::string path); - std::string GetPath(void); void CallStartMethod(void); void CallProgressMethod(void); diff --git a/src/gdcmDicomDirElement.h b/src/gdcmDicomDirElement.h index a11f4846..6a0e9410 100644 --- a/src/gdcmDicomDirElement.h +++ b/src/gdcmDicomDirElement.h @@ -36,6 +36,11 @@ public: gdcmDicomDirElement(void); ~gdcmDicomDirElement(void); + /** + * \ingroup gdcmParser + * \brief canonical Printer + * \sa SetPrintLevel + */ void Print(std::ostream &os); diff --git a/src/gdcmDicomDirSerie.cxx b/src/gdcmDicomDirSerie.cxx index 1415d6cd..1571d28d 100644 --- a/src/gdcmDicomDirSerie.cxx +++ b/src/gdcmDicomDirSerie.cxx @@ -71,9 +71,7 @@ gdcmDicomDirImage * gdcmDicomDirSerie::NewImage(void) { FillObject(elemList); gdcmDicomDirImage *st = new gdcmDicomDirImage(i, j, ptagHT, plistEntries); images.push_front(st); - return st; - - + return st; } //----------------------------------------------------------------------------- // Protected diff --git a/src/gdcmDirList.cxx b/src/gdcmDirList.cxx index 64eda53e..21c0c21b 100644 --- a/src/gdcmDirList.cxx +++ b/src/gdcmDirList.cxx @@ -57,7 +57,7 @@ gdcmDirList::~gdcmDirList(void) /* * \ingroup gdcmDirList * \brief Get the directory name - * @param + * @return the directory name */ std::string gdcmDirList::GetDirName(void) { @@ -86,7 +86,8 @@ void gdcmDirList::NormalizePath(std::string &dirName) /* * \ingroup gdcmDirList * \brief Explore a directory with possibility of recursion - * @param + * @param dirName directory to explore + * @param recursive whether we want recursion or not */ void gdcmDirList::Explore(std::string dirName,bool recursive) { diff --git a/src/gdcmObject.cxx b/src/gdcmObject.cxx index debbfdd5..eed5f4db 100644 --- a/src/gdcmObject.cxx +++ b/src/gdcmObject.cxx @@ -114,7 +114,7 @@ std::string gdcmObject::GetEntryByName(TagName name) { if ( ! ptagHT->count(key)) { // we assume a Public Dictionnary *is* loaded gdcmDict *PubDict = gdcmGlobal::GetDicts()->GetDefaultPubDict(); - // if the invoqued (group,elem) doesn't exist inside the Dictionary + // if the invoked (group,elem) doesn't exist inside the Dictionary // we create a VirtualDictEntry gdcmDictEntry *DictEntry = PubDict->GetDictEntryByNumber(group, element); if (DictEntry == NULL) { diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index 5bee7405..03fdde5d 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -3,6 +3,7 @@ #include "gdcmParser.h" #include "gdcmUtil.h" #include +#include // For nthos: #ifdef _MSC_VER @@ -112,7 +113,7 @@ gdcmParser::gdcmParser(const char *inFilename, enableSequences=enable_sequences; ignoreShadow =ignore_shadow; - SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); + SetMaxSizeLoadEntry(MAX_SIZE_LOAD_ELEMENT_VALUE); filename = inFilename; Initialise(); @@ -183,7 +184,7 @@ void gdcmParser::PrintPubDict(std::ostream & os) { /** * \ingroup gdcmParser - * \brief Prints The Dict Entries of THE shadow Dicom Dictionnry + * \brief Prints The Dict Entries of THE shadow Dicom Dictionnary * @return */ void gdcmParser::PrintShaDict(std::ostream & os) { diff --git a/src/gdcmParser.h b/src/gdcmParser.h index 10943f5f..4220bfba 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -159,7 +159,14 @@ protected: void WriteEntriesDeprecated(FILE *_fp,FileType type); // JPR void AddHeaderEntry (gdcmHeaderEntry *); - + + /** + * \ingroup gdcmParser + * \brief Set the external File Name + */ + inline void SetFileName(char* fileName) + {filename = fileName;} + // Variables /** * \brief File Pointer, open during Header parsing @@ -260,7 +267,7 @@ private: // Deprecated (Not used) --> commented out //gdcmHeaderEntry *NewManualHeaderEntryToPubDict(std::string NewTagName, - // std::string VR); + // std::string VR); guint32 GenerateFreeTagKeyInGroup(guint16 group); diff --git a/src/gdcmUtil.cxx b/src/gdcmUtil.cxx index 336be556..cfef1bee 100644 --- a/src/gdcmUtil.cxx +++ b/src/gdcmUtil.cxx @@ -153,3 +153,58 @@ std::string _CreateCleanString(std::string s) { return(str); } + +/////////////////////////////////////////////////////////////////////////// +/* + * \brief Add a SEPARATOR to the end of the name is necessary + * @param + */ +void NormalizePath(std::string &name) +{ +const char SEPARATOR_X = '/'; +const char SEPARATOR_WIN = '\\'; +const std::string SEPARATOR = "/"; + int size=name.size(); + if((name[size-1]!=SEPARATOR_X)&&(name[size-1]!=SEPARATOR_WIN)) + { + name+=SEPARATOR; + } +} + +/////////////////////////////////////////////////////////////////////////// +/* + * \brief Get the (directory) path from a full path file name + */ +std::string GetPath(std::string fullName) +{ + int pos1=fullName.rfind("/"); + int pos2=fullName.rfind("\\"); + if(pos1>pos2) + fullName.resize(pos1); + else + fullName.resize(pos2); + return(fullName); +} + +/////////////////////////////////////////////////////////////////////////// +/* + * \brief Get the (last) name of a full path file name + */ +std::string GetName(std::string fullName) +{ + int fin=fullName.length()-1; + char a =fullName.c_str()[fin]; + if (a == '/' || a == '\\') { + fin--; + } + int deb; + for (int i=fin;i!=0;i--) { + if (fullName.c_str()[i] == '/' || fullName.c_str()[i] == '\\') + break; + deb = i; + } + std::string lastName; + for (int i=deb;i