From: jpr Date: Fri, 30 Jan 2004 10:38:34 +0000 (+0000) Subject: some DICOMDIR writting purpose modif X-Git-Tag: Version0.4~49 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=45bf98d79625d7efdb227b07c8746a918b49568b;p=gdcm.git some DICOMDIR writting purpose modif --- diff --git a/src/gdcmCommon.h b/src/gdcmCommon.h index 3775c317..5647a486 100644 --- a/src/gdcmCommon.h +++ b/src/gdcmCommon.h @@ -69,7 +69,8 @@ enum FileType { ExplicitVR, ImplicitVR, ACR, - ACR_LIBIDO + ACR_LIBIDO, + DICOMDIR }; //For now gdcm is not willing cmake, try to be more quiet diff --git a/src/gdcmDicomDir.cxx b/src/gdcmDicomDir.cxx index a3441303..078c3575 100644 --- a/src/gdcmDicomDir.cxx +++ b/src/gdcmDicomDir.cxx @@ -25,7 +25,6 @@ gdcmDicomDir::gdcmDicomDir(std::string & FileName, { dbg.Verbose(0, "gdcmDicomDir::gdcmDicomDir entry list empty"); } - CreateDicomDir(); } @@ -35,14 +34,18 @@ gdcmDicomDir::gdcmDicomDir(std::string & FileName, * \brief * @param exception_on_error */ -gdcmDicomDir::gdcmDicomDir(bool exception_on_error): +gdcmDicomDir::gdcmDicomDir(ListTag *l, + bool exception_on_error): gdcmParser(exception_on_error ) { - + listEntries=*l; + CreateDicomDir(); } - - +/* + * \ingroup gdcmDicomDir + * \brief Canonical destructor + */ gdcmDicomDir::~gdcmDicomDir() { for(ListPatient::iterator cc = patients.begin();cc!=patients.end();++cc) @@ -51,6 +54,8 @@ gdcmDicomDir::~gdcmDicomDir() } } + + //----------------------------------------------------------------------------- // Print void gdcmDicomDir::Print(std::ostream &os) @@ -65,12 +70,45 @@ void gdcmDicomDir::Print(std::ostream &os) //----------------------------------------------------------------------------- // Public + +/** + * \ingroup gdcmDicomDir + * \brief writes on disc a DICOMDIR + * \ warning does NOT add the missing elements in the header : + * \ it's up to the user doing it ! + * @param fileName file to be written to + * @return + */ +bool gdcmDicomDir::Write(std::string fileName) { + + FILE * fp1; + fp1 = fopen(fileName.c_str(),"wb"); + if (fp1 == NULL) { + printf("Failed to open (write) File [%s] \n",fileName.c_str()); + return (false); + } + char * filePreamble; + filePreamble=(char*)calloc(128,1); + fwrite(filePreamble,128,1,fp1); + fwrite("DICM",4,1,fp1); + free (filePreamble); + WriteEntries(DICOMDIR,fp1); + + return true; + +} + //----------------------------------------------------------------------------- // Protected //----------------------------------------------------------------------------- // Private -void gdcmDicomDir::CreateDicomDir(void) +/* + * \ingroup gdcmDicomDir + * \brief + * @param + */ +void gdcmDicomDir::CreateDicomDir() { // The list is parsed. When a tag is found : // 1 - we save the beginning iterator @@ -83,9 +121,9 @@ void gdcmDicomDir::CreateDicomDir(void) ListTag::iterator begin; ListTag::iterator end; - begin=GetListEntry().begin(); + begin=listEntries.begin(); end=begin; - for(ListTag::iterator i=GetListEntry().begin();i != GetListEntry().end();++i) + for(ListTag::iterator i=listEntries.begin();i != listEntries.end();++i) { // std::cout << std::hex << (*i)->GetGroup() << // " " << (*i)->GetElement() << endl; @@ -93,7 +131,7 @@ void gdcmDicomDir::CreateDicomDir(void) std::string v = (*i)->GetValue(); if (v == "PATIENT ") { -// std::cout<<"PATIENT"<0) { @@ -172,7 +224,11 @@ void gdcmDicomDir::AddStudyToEnd(ListTag::iterator begin,ListTag::iterator end) (*itp)->AddStudy(new gdcmStudy(begin,end)); } } - +/* + * \ingroup gdcmDicomDir + * \brief + * @param + */ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end) { if(patients.size()>0) @@ -189,7 +245,12 @@ void gdcmDicomDir::AddSerieToEnd(ListTag::iterator begin,ListTag::iterator end) } } -void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end) +/* + * \ingroup gdcmDicomDir + * \brief + * @param + */ + void gdcmDicomDir::AddImageToEnd(ListTag::iterator begin,ListTag::iterator end) { if(patients.size()>0) { diff --git a/src/gdcmDicomDir.h b/src/gdcmDicomDir.h index ed91ea96..d5c70ffa 100644 --- a/src/gdcmDicomDir.h +++ b/src/gdcmDicomDir.h @@ -19,8 +19,8 @@ typedef std::list ListPatient; class GDCM_EXPORT gdcmDicomDir: public gdcmParser { public: - gdcmDicomDir(bool exception_on_error = false); - gdcmDicomDir(std::string &FileName,bool exception_on_error = false ); + gdcmDicomDir(ListTag *l, bool exception_on_error = false); + gdcmDicomDir(std::string &FileName,bool exception_on_error = false); ~gdcmDicomDir(void); @@ -28,6 +28,8 @@ public: virtual void Print(std::ostream &os = std::cout); inline ListPatient &GetPatients() {return patients;}; + bool Write(std::string fileName); + typedef enum { diff --git a/src/gdcmFile.cxx b/src/gdcmFile.cxx index 4b9022fc..6dfb630c 100644 --- a/src/gdcmFile.cxx +++ b/src/gdcmFile.cxx @@ -541,8 +541,8 @@ bool gdcmFile::SetImageData(void * inData, size_t ExpectedSize) { /** * \ingroup gdcmFile - * \brief Ecrit sur disque les pixels d'UNE image - * Aucun test n'est fait sur l'"Endiannerie" du processeur. + * \brief Writes on disk A SINGLE Dicom file + * NO test is performed on processor "Endiannity". * Ca sera à l'utilisateur d'appeler son Reader correctement * (Equivalent a IdImaWriteRawFile) * @@ -565,10 +565,8 @@ bool gdcmFile::WriteRawData (std::string fileName) { /** * \ingroup gdcmFile - * \brief Ecrit sur disque UNE image Dicom - * Aucun test n'est fait sur l'"Endiannerie" du processeur. - * Ca fonctionnera correctement (?) sur processeur Intel - * (Equivalent a IdDcmWrite) + * \brief Writes on disk A SINGLE Dicom file + * NO test is performed on processor "Endiannity". * * @param fileName name of the file to be created * (any already existing file is overwritten) @@ -638,7 +636,7 @@ bool gdcmFile::WriteBase (std::string fileName, FileType type) { FILE * fp1; fp1 = fopen(fileName.c_str(),"wb"); if (fp1 == NULL) { - printf("Echec ouverture (ecriture) Fichier [%s] \n",fileName.c_str()); + printf("Failed to open (write) File [%s] \n",fileName.c_str()); return (false); } @@ -648,6 +646,7 @@ bool gdcmFile::WriteBase (std::string fileName, FileType type) { filePreamble=(char*)calloc(128,1); fwrite(filePreamble,128,1,fp1); fwrite("DICM",4,1,fp1); + free (filePreamble); } // -------------------------------------------------------------- diff --git a/src/gdcmHeader.cxx b/src/gdcmHeader.cxx index bfe4b672..fdfc651c 100644 --- a/src/gdcmHeader.cxx +++ b/src/gdcmHeader.cxx @@ -9,12 +9,6 @@ #include "gdcmUtil.h" #include "gdcmTS.h" -//----------------------------------------------------------------------------- -// Refer to gdcmHeader::CheckSwap() -//const unsigned int gdcmHeader::HEADER_LENGTH_TO_READ = 256; - -// Refer to gdcmHeader::SetMaxSizeLoadEntry() -//const unsigned int gdcmHeader::MAX_SIZE_LOAD_ELEMENT_VALUE = 4096; //----------------------------------------------------------------------------- // Constructor / Destructor @@ -60,6 +54,7 @@ gdcmHeader::~gdcmHeader (void) { //----------------------------------------------------------------------------- // Print +// see gdcmParser.cxx //----------------------------------------------------------------------------- // Public /** diff --git a/src/gdcmHeaderEntry.cxx b/src/gdcmHeaderEntry.cxx index e5312074..34424cc5 100644 --- a/src/gdcmHeaderEntry.cxx +++ b/src/gdcmHeaderEntry.cxx @@ -13,6 +13,9 @@ #endif #include // for std::ios::left, ... + +#define MAX_SIZE_PRINT_ELEMENT_VALUE 64 + //----------------------------------------------------------------------------- // Constructor / Destructor /** @@ -76,12 +79,17 @@ void gdcmHeaderEntry::Print(std::ostream & os) { if (printLevel>=1) { s.setf(std::ios::left); s << std::setw(66-GetName().length()) << " "; - } + } + + s << "[" << GetName()<< "]"; + - s << "[" << GetName()<< "]"; - if( (GetLength()<64) || (printLevel>=3) ) + + if( (GetLength()=3) || + (d2.find("gdcm::NotLoaded.") < d2.length()) ) s << " [" << d2 << "]"; - else + else s << " [ gdcm::too long for print (" << GetLength() << ") ]"; // Display the UID value (instead of displaying the rough code) diff --git a/src/gdcmParser.cxx b/src/gdcmParser.cxx index fc523630..93f2f56f 100644 --- a/src/gdcmParser.cxx +++ b/src/gdcmParser.cxx @@ -68,9 +68,13 @@ // Refer to gdcmParser::CheckSwap() const unsigned int gdcmParser::HEADER_LENGTH_TO_READ = 256; -// Refer to gdcmParser::SetMaxSizeLoadElementValue() +// Refer to gdcmParser::SetMaxSizeLoadEntry() const unsigned int gdcmParser::MAX_SIZE_LOAD_ELEMENT_VALUE = 4096; +// Refer to gdcmParser::SetMaxSizePrintEntry() +// TODO : Right now, better see "define, in gdcmHederEntry.cxx +const unsigned int gdcmParser::MAX_SIZE_PRINT_ELEMENT_VALUE = 64; + //----------------------------------------------------------------------------- // Constructor / Destructor /** @@ -1071,7 +1075,7 @@ void gdcmParser::WriteEntries(FileType type, FILE * _fp) // === Deal with the value // ------------------- - if (vr == "SQ") continue; // vo "value" to write for the SEQuences + if (vr == "SQ") continue; // no "value" to write for the SEQuences if (gr == 0xfffe)continue; if (vr == "US" || vr == "SS") @@ -2105,7 +2109,6 @@ void gdcmParser::SwitchSwapToBigEndian(void) * \ingroup gdcmParser * \brief * @param NewSize - * @return */ void gdcmParser::SetMaxSizeLoadEntry(long NewSize) { @@ -2119,6 +2122,28 @@ void gdcmParser::SetMaxSizeLoadEntry(long NewSize) MaxSizeLoadEntry = NewSize; } + +/** + * \ingroup gdcmParser + * \brief + * \warning TODO : not yet usable + * (see MAX_SIZE_PRINT_ELEMENT_VALUE + * in gdcmHeaderEntry gdcmLoadEntry) + * + * @param NewSize + */ +void gdcmParser::SetMaxSizePrintEntry(long NewSize) +{ + if (NewSize < 0) + return; + if ((guint32)NewSize >= (guint32)0xffffffff) + { + MaxSizePrintEntry = 0xffffffff; + return; + } + MaxSizePrintEntry = NewSize; +} + /** * \ingroup gdcmParser * \brief Searches both the public and the shadow dictionary (when they diff --git a/src/gdcmParser.h b/src/gdcmParser.h index cf2cc947..65bbdc71 100644 --- a/src/gdcmParser.h +++ b/src/gdcmParser.h @@ -139,6 +139,7 @@ protected: static const unsigned int HEADER_LENGTH_TO_READ; static const unsigned int MAX_SIZE_LOAD_ELEMENT_VALUE; + static const unsigned int MAX_SIZE_PRINT_ELEMENT_VALUE; protected: int enableSequences; @@ -175,6 +176,7 @@ private: void CheckSwap(void); void SwitchSwapToBigEndian(void); void SetMaxSizeLoadEntry(long); + void SetMaxSizePrintEntry(long); // DictEntry related utilities gdcmDictEntry *GetDictEntryByName (std::string Name); @@ -221,6 +223,11 @@ private: // this upper bound is fixed to 1024 bytes (which might look reasonable // when one considers the definition of the various VR contents). guint32 MaxSizeLoadEntry; + // Size treshold above which an element value will NOT be *printed* in + // order no to polute the screen output. By default, + // this upper bound is fixed to 64 bytes. + guint32 MaxSizePrintEntry; + }; //-----------------------------------------------------------------------------