From 3a9e9df62b3198c4f93d1768074b6be828ac7308 Mon Sep 17 00:00:00 2001 From: regrain Date: Tue, 5 Apr 2005 10:56:22 +0000 Subject: [PATCH] * src/gdcmDictGroupName.[h|cxx] : add a correlation between a group (number) and it's representation name (for the NIH) -- BeNours --- CMakeLists.txt | 6 +- ChangeLog | 4 ++ Dicts/CMakeLists.txt | 25 +++++++- Dicts/DictGroupName.dic | 68 ++++++++++++++++++++ Testing/CMakeLists.txt | 1 + Testing/TestDictGroupName.cxx | 34 ++++++++++ gdcmPython/gdcm.i | 6 ++ src/CMakeLists.txt | 1 + src/gdcmCommon.h | 5 +- src/gdcmDefaultDicts.cxx.in | 22 ++++--- src/gdcmDictGroupName.cxx | 117 ++++++++++++++++++++++++++++++++++ src/gdcmDictGroupName.h | 56 ++++++++++++++++ src/gdcmDictSet.cxx | 12 ++-- src/gdcmGlobal.cxx | 32 +++++++--- src/gdcmGlobal.h | 9 ++- 15 files changed, 367 insertions(+), 31 deletions(-) create mode 100644 Dicts/DictGroupName.dic create mode 100644 Testing/TestDictGroupName.cxx create mode 100644 src/gdcmDictGroupName.cxx create mode 100644 src/gdcmDictGroupName.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b0db95b..c6c273db 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -135,7 +135,11 @@ FIND_PATH(GDCM_DATA_ROOT gdcm-ACR-LibIDO.acr ) # Set the place for the public dictionary, must be set before gdcmConfigure.h -SET( GDCM_PUB_DICT_PATH "${CMAKE_INSTALL_PREFIX}${GDCM_DATA_DIR}") +#SET( GDCM_PUB_DICT_PATH "${CMAKE_INSTALL_PREFIX}${GDCM_DATA_DIR}") +FIND_PATH(GDCM_PUB_DICT_PATH dicomV3.dic + ${GDCM_SOURCE_DIR}/Dicts + $ENV{PUB_DICT_PATH} +) #----------------------------------------------------------------------------- # SunOS + old gcc fixes: diff --git a/ChangeLog b/ChangeLog index 898c0f59..9f9b46b5 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2005-04-05 Benoit Regrain + * src/gdcmDictGroupName.[h|cxx] : add a correlation between a group (number) + and it's representation name (for the NIH) + 2005-03-31 Benoit Regrain * src/gdcmPixelReadConvert.cxx : problems of around of double to uint8, when conversion of YBR to RGB pixels. So, now, the conversion is made using diff --git a/Dicts/CMakeLists.txt b/Dicts/CMakeLists.txt index 99254666..20e988a3 100644 --- a/Dicts/CMakeLists.txt +++ b/Dicts/CMakeLists.txt @@ -7,6 +7,7 @@ INSTALL_FILES(${GDCM_DATA_DIR} .dic dicomVR dicomTS DicomDir + DictGroupName ) # Nice trick to avoid creating a .h file each time we compile gdcm @@ -28,6 +29,8 @@ ENDFOREACH(line) SET(DICOM_DATA_DICTIONARY "${DICOM_DATA_DICTIONARY} \n {0,0,0,0,0}") +#----------------------------------------------------------------------------- +# ... for DicomTS file FILE(READ "dicomTS.dic" ENT_TS) STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}") SET(DICOM_TS_DICTIONARY "") @@ -39,6 +42,8 @@ FOREACH(line ${ENT_TS}) SET(DICOM_TS_DICTIONARY "${DICOM_TS_DICTIONARY}\n${nline}") ENDFOREACH(line) +#----------------------------------------------------------------------------- +# ... for DicomVR file FILE(READ "dicomVR.dic" ENT_VR) STRING(REGEX REPLACE ";" "/" ENT_VR "${ENT_VR}") # CMake doesn't like ';' STRING(REGEX REPLACE "\r?\n" ";" ENT_VR "${ENT_VR}") @@ -51,6 +56,21 @@ FOREACH(line ${ENT_VR}) SET(DICOM_VR_DICTIONARY "${DICOM_VR_DICTIONARY}\n${nline}") ENDFOREACH(line) +#----------------------------------------------------------------------------- +# ... for DictGroupName file +FILE(READ "DictGroupName.dic" ENT_TS) +STRING(REGEX REPLACE "\r?\n" ";" ENT_TS "${ENT_TS}") +SET(DICT_GROUP_NAME_DICTIONARY "") + +FOREACH(line ${ENT_TS}) + STRING(REGEX REPLACE + "^([0-9a-f]+) +(.*)$" + " groupName[0x\\1] = \\2; " nline "${line}") + SET(DICT_GROUP_NAME_DICTIONARY "${DICT_GROUP_NAME_DICTIONARY}\n${nline}") +ENDFOREACH(line) + +#----------------------------------------------------------------------------- +# ... for DicomDir file FILE(READ "DicomDir.dic" ENT_DIR) STRING(REGEX REPLACE "\\\\" "\\\\\\\\" ENT_DIR "${ENT_DIR}") STRING(REGEX REPLACE ";" "/" ENT_DIR "${ENT_DIR}") # CMake doesn't like ';' @@ -64,10 +84,11 @@ FOREACH(line ${ENT_DIR}) SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY}\n${nline}") ENDFOREACH(line) +#----------------------------------------------------------------------------- +# ... Set the dictionnary SET(DICOM_DIR_DICTIONARY "${DICOM_DIR_DICTIONARY} \n {0,0,0,0}") -# See above -FOREACH(file dicomV3.dic dicomTS.dic dicomVR.dic DicomDir.dic) +FOREACH(file dicomV3.dic dicomTS.dic dicomVR.dic DicomDir.dic DictGroupName.dic) CONFIGURE_FILE("${GDCM_SOURCE_DIR}/Dicts/${file}" "${GDCM_BINARY_DIR}/Dicts/${file}.out") ENDFOREACH(file) diff --git a/Dicts/DictGroupName.dic b/Dicts/DictGroupName.dic new file mode 100644 index 00000000..1fc65c57 --- /dev/null +++ b/Dicts/DictGroupName.dic @@ -0,0 +1,68 @@ +0000 "Command" +0002 "Meta Elements" +0004 "Directory" +0008 "Identifing" +0010 "Patient" +0012 "Clinical Trial" +0018 "Acquisition" +0020 "Relationship" +0028 "Image Presentaion" +0032 "Study" +0038 "Visit" +003a "Waveform" +0040 "Procedure" +0050 "Device" +0054 "Nuclear Medicine" +0060 "???" +0070 "???" +0088 "???" +0100 "???" +0400 "???" +2000 "BFS" +2010 "BFB" +2020 "BAB" +2040 "IOB" +2100 "Print Job" +2110 "Printer" +3002 "Radio Therapy" +3004 "DVH" +3006 "SSET" +300a "RT" +300b "RT" +300c "???" +300e "Review" +4000 "Text" +4008 "Results" +5000 "Curves" +5002 "Curves" +5004 "Curves" +5006 "Curves" +5008 "Curves" +500a "Curves" +500c "Curves" +500e "Curves" +5010 "Curves" +5012 "Curves" +5014 "Curves" +5016 "Curves" +5018 "Curves" +501a "Curves" +501c "Curves" +501e "Curves" +6000 "Overlays" +6002 "Overlays" +6004 "Overlays" +6006 "Overlays" +6008 "Overlays" +600a "Overlays" +600c "Overlays" +600e "Overlays" +6010 "Overlays" +6012 "Overlays" +6014 "Overlays" +6016 "Overlays" +6018 "Overlays" +601a "Overlays" +601c "Overlays" +601e "Overlays" +7fe0 "Pixels" diff --git a/Testing/CMakeLists.txt b/Testing/CMakeLists.txt index a77c35b0..57973d13 100644 --- a/Testing/CMakeLists.txt +++ b/Testing/CMakeLists.txt @@ -13,6 +13,7 @@ SET(TEST_SOURCES TestHash.cxx TestTS.cxx TestVR.cxx + TestDictGroupName.cxx TestDict.cxx TestWriteSimple.cxx TestImageSet.cxx diff --git a/Testing/TestDictGroupName.cxx b/Testing/TestDictGroupName.cxx new file mode 100644 index 00000000..d8ee7016 --- /dev/null +++ b/Testing/TestDictGroupName.cxx @@ -0,0 +1,34 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: TestDictGroupName.cxx,v $ + Language: C++ + Date: $Date: 2005/04/05 10:56:24 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ +#include "gdcmDictGroupName.h" +#include "gdcmGlobal.h" +#include "gdcmCommon.h" + +int TestDictGroupName(int , char *[]) +{ + gdcm::DictGroupName groupName; + groupName.Print( std::cout ); + + std::cout << std::endl; + std::cout << "Group : 0x0002 : " << groupName.GetName(0x0002) << " - " + << (bool)(groupName.GetName(0x0002)=="Meta Elements") << std::endl; + std::cout << "Group : 0x0007 : " << groupName.GetName(0x0007) << " - " + << (bool)(groupName.GetName(0x0007)==gdcm::GDCM_UNFOUND) << std::endl; + + return groupName.GetName( 0x7fe0 ) != ""; +} diff --git a/gdcmPython/gdcm.i b/gdcmPython/gdcm.i index 399f6f4f..6d00135e 100644 --- a/gdcmPython/gdcm.i +++ b/gdcmPython/gdcm.i @@ -31,6 +31,9 @@ #include "gdcmValEntry.h" #include "gdcmBinEntry.h" #include "gdcmSeqEntry.h" +#include "gdcmVR.h" +#include "gdcmTS.h" +#include "gdcmDictGroupName.h" //////////////////////////////////////////////////////////////////////////// /// Refer (below) to the definition of multi-argument typemap @@ -377,6 +380,9 @@ typedef unsigned long long uint64_t; %include "gdcmValEntry.h" %include "gdcmBinEntry.h" %include "gdcmSeqEntry.h" +%include "gdcmVR.h" +%include "gdcmTS.h" +%include "gdcmDictGroupName.h" //////////////////////////////////////////////////////////////////////////// // Notes on swig and this file gdcm.i: diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index af714e85..ef844c44 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -27,6 +27,7 @@ SET(libgdcm_la_SOURCES gdcmDicomDirStudy.cxx gdcmDict.cxx gdcmDictEntry.cxx + gdcmDictGroupName.cxx gdcmDictSet.cxx gdcmDirList.cxx gdcmDocEntry.cxx diff --git a/src/gdcmCommon.h b/src/gdcmCommon.h index 0a115ec2..26ded6d3 100644 --- a/src/gdcmCommon.h +++ b/src/gdcmCommon.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmCommon.h,v $ Language: C++ - Date: $Date: 2005/02/11 15:22:18 $ - Version: $Revision: 1.62 $ + Date: $Date: 2005/04/05 10:56:25 $ + Version: $Revision: 1.63 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -92,6 +92,7 @@ namespace gdcm #define DICT_ELEM "DicomDir.dic" #define DICT_TS "dicomTS.dic" #define DICT_VR "dicomVR.dic" +#define DICT_GROUP_NAME "DictGroupName.dic" GDCM_EXPORT extern const std::string GDCM_UNKNOWN; GDCM_EXPORT extern const std::string GDCM_UNFOUND; diff --git a/src/gdcmDefaultDicts.cxx.in b/src/gdcmDefaultDicts.cxx.in index f7657fa9..2622cc23 100644 --- a/src/gdcmDefaultDicts.cxx.in +++ b/src/gdcmDefaultDicts.cxx.in @@ -1,19 +1,19 @@ /*========================================================================= - + Program: gdcm Module: $RCSfile: gdcmDefaultDicts.cxx.in,v $ Language: C++ - Date: $Date: 2005/02/09 21:37:11 $ - Version: $Revision: 1.8 $ - + Date: $Date: 2005/04/05 10:56:25 $ + Version: $Revision: 1.9 $ + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. - + This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. - + =========================================================================*/ #ifndef GDCMDEFAULTDICTS_H @@ -23,6 +23,7 @@ #include "gdcmDictEntry.h" #include "gdcmTS.h" #include "gdcmVR.h" +#include "gdcmDictGroupName.h" #include "gdcmDicomDirElement.h" namespace gdcm @@ -53,16 +54,21 @@ void FillDefaultDataDict(Dict *d) } } -void FillDefaultTSDict(TSHT & ts) +void FillDefaultTSDict(TSHT &ts) { @DICOM_TS_DICTIONARY@ } -void FillDefaultVRDict(VRHT & vr) +void FillDefaultVRDict(VRHT &vr) { @DICOM_VR_DICTIONARY@ } +void FillDefaultDictGroupName(DictGroupNameHT &groupName) +{ +@DICT_GROUP_NAME_DICTIONARY@ +} + typedef struct { const char *type; diff --git a/src/gdcmDictGroupName.cxx b/src/gdcmDictGroupName.cxx new file mode 100644 index 00000000..680c199d --- /dev/null +++ b/src/gdcmDictGroupName.cxx @@ -0,0 +1,117 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmDictGroupName.cxx,v $ + Language: C++ + Date: $Date: 2005/04/05 10:56:25 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#include "gdcmDictGroupName.h" +#include "gdcmUtil.h" +#include "gdcmDictSet.h" +#include "gdcmDebug.h" + +#include +#include + +namespace gdcm +{ +//----------------------------------------------------------------------------- +/// \brief auto generated function, to fill up the 'Value Representation' +/// Dictionnary, if relevant file is not found on user's disk +void FillDefaultDictGroupName(DictGroupNameHT &groupName); + +//----------------------------------------------------------------------------- +// Constructor / Destructor +/** + * \brief Constructor + */ +DictGroupName::DictGroupName() +{ + std::string filename = DictSet::BuildDictPath() + DICT_GROUP_NAME; + std::ifstream from(filename.c_str()); + if(!from) + { + gdcmWarningMacro("Can't open dictionary" << filename.c_str()); + FillDefaultDictGroupName(groupName); + } + else + { + char buff[1024]; + uint16_t key; + GroupName value; + + while (!from.eof()) + { + from >> std::ws; + from >> std::hex; + from >> key; + from >> std::ws; + from.getline(buff, 1024, '"'); + from.getline(buff, 1024, '"'); + value = buff; + if(!from.eof()) + groupName[key] = value; + + from.getline(buff, 1024, '\n'); + } + from.close(); + } +} + +/** + * \brief Destructor + */ +DictGroupName::~DictGroupName() +{ + groupName.clear(); +} + +//----------------------------------------------------------------------------- +// Public +const GroupName &DictGroupName::GetName(uint16_t group) +{ + DictGroupNameHT::const_iterator it = groupName.find(group); + if (it == groupName.end()) + { + return GDCM_UNFOUND; + } + return it->second; +} + +//----------------------------------------------------------------------------- +// Protected + +//----------------------------------------------------------------------------- +// Private + +//----------------------------------------------------------------------------- +// Print +/** + * \brief Print all + * @param os The output stream to be written to. + */ +void DictGroupName::Print(std::ostream &os) +{ + std::ostringstream s; + + for (DictGroupNameHT::iterator it = groupName.begin(); it != groupName.end(); ++it) + { + s << "DictGroupName : " << std::hex << it->first << std::dec + << " = " << it->second << std::endl; + } + os << s.str(); +} + +//----------------------------------------------------------------------------- +} // end namespace gdcm diff --git a/src/gdcmDictGroupName.h b/src/gdcmDictGroupName.h new file mode 100644 index 00000000..50954354 --- /dev/null +++ b/src/gdcmDictGroupName.h @@ -0,0 +1,56 @@ +/*========================================================================= + + Program: gdcm + Module: $RCSfile: gdcmDictGroupName.h,v $ + Language: C++ + Date: $Date: 2005/04/05 10:56:25 $ + Version: $Revision: 1.1 $ + + Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de + l'Image). All rights reserved. See Doc/License.txt or + http://www.creatis.insa-lyon.fr/Public/Gdcm/License.html for details. + + This software is distributed WITHOUT ANY WARRANTY; without even + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the above copyright notices for more information. + +=========================================================================*/ + +#ifndef GDCMDICTGROUPNAME_H +#define GDCMDICTGROUPNAME_H + +#include "gdcmCommon.h" +#include +#include +#include + +namespace gdcm +{ + +//----------------------------------------------------------------------------- +typedef std::string GroupName; +/// Group Name Hash Table +typedef std::map DictGroupNameHT; + +//----------------------------------------------------------------------------- +/** + * \brief Container for dicom Value Representation Hash Table + * \note This is a singleton + */ +class GDCM_EXPORT DictGroupName +{ +public: + DictGroupName(void); + ~DictGroupName(); + + void Print(std::ostream &os = std::cout); + + const GroupName &GetName(uint16_t group); + +private: + DictGroupNameHT groupName; +}; +} // end namespace gdcm + +//----------------------------------------------------------------------------- +#endif diff --git a/src/gdcmDictSet.cxx b/src/gdcmDictSet.cxx index a8e5903d..8ec72b61 100644 --- a/src/gdcmDictSet.cxx +++ b/src/gdcmDictSet.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmDictSet.cxx,v $ Language: C++ - Date: $Date: 2005/02/25 15:49:54 $ - Version: $Revision: 1.61 $ + Date: $Date: 2005/04/05 10:56:25 $ + Version: $Revision: 1.62 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -170,16 +170,16 @@ std::string DictSet::BuildDictPath() if (envPath && (strlen(envPath) != 0)) { resultPath = envPath; - if ( resultPath[resultPath.length()-1] != '/' ) - { - resultPath += '/'; - } gdcmWarningMacro( "Dictionary path set from environnement"); } else { resultPath = PUB_DICT_PATH; } + if ( resultPath[resultPath.length()-1] != '/' ) + { + resultPath += '/'; + } return resultPath; } diff --git a/src/gdcmGlobal.cxx b/src/gdcmGlobal.cxx index 09cb9ec0..0ced5657 100644 --- a/src/gdcmGlobal.cxx +++ b/src/gdcmGlobal.cxx @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmGlobal.cxx,v $ Language: C++ - Date: $Date: 2005/03/22 11:41:24 $ - Version: $Revision: 1.22 $ + Date: $Date: 2005/04/05 10:56:25 $ + 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 @@ -21,6 +21,7 @@ #include "gdcmDebug.h" #include "gdcmVR.h" #include "gdcmTS.h" +#include "gdcmDictGroupName.h" #include "gdcmDictSet.h" #include "gdcmDicomDirElement.h" @@ -40,10 +41,11 @@ const std::string GDCM_NOTLOADED = "gdcm::NotLoaded"; const std::string GDCM_UNREAD = "gdcm::UnRead"; //----------------------------------------------------------------------------- -DictSet *Global::Dicts = (DictSet *)0; -VR *Global::ValRes = (VR *)0; -TS *Global::TranSyn = (TS *)0; -DicomDirElement *Global::ddElem = (DicomDirElement *)0; +DictSet *Global::Dicts = (DictSet *)0; +VR *Global::ValRes = (VR *)0; +TS *Global::TranSyn = (TS *)0; +DictGroupName *Global::GroupName = (DictGroupName *)0; +DicomDirElement *Global::ddElem = (DicomDirElement *)0; //----------------------------------------------------------------------------- /** @@ -63,10 +65,11 @@ Global::Global() gdcmWarningMacro( "VR or TS or Dicts already allocated"); return; } - Dicts = new DictSet(); - ValRes = new VR(); - TranSyn = new TS(); - ddElem = new DicomDirElement(); + Dicts = new DictSet(); + ValRes = new VR(); + TranSyn = new TS(); + GroupName = new DictGroupName(); + ddElem = new DicomDirElement(); } /** @@ -77,6 +80,7 @@ Global::~Global() delete Dicts; delete ValRes; delete TranSyn; + delete GroupName; delete ddElem; } @@ -106,6 +110,14 @@ TS *Global::GetTS() return TranSyn; } +/** + * \brief returns a pointer to the Group name correspondance table + */ +DictGroupName *Global::GetDictGroupName() +{ + return GroupName; +} + /** * \brief returns a pointer to the DicomDir related elements Table */ diff --git a/src/gdcmGlobal.h b/src/gdcmGlobal.h index 893af415..74997e63 100644 --- a/src/gdcmGlobal.h +++ b/src/gdcmGlobal.h @@ -3,8 +3,8 @@ Program: gdcm Module: $RCSfile: gdcmGlobal.h,v $ Language: C++ - Date: $Date: 2005/02/04 16:51:36 $ - Version: $Revision: 1.7 $ + Date: $Date: 2005/04/05 10:56:25 $ + Version: $Revision: 1.8 $ Copyright (c) CREATIS (Centre de Recherche et d'Applications en Traitement de l'Image). All rights reserved. See Doc/License.txt or @@ -26,6 +26,7 @@ namespace gdcm class DictSet; class VR; class TS; +class DictGroupName; class DicomDirElement; //----------------------------------------------------------------------------- /** @@ -41,6 +42,7 @@ public: static DictSet *GetDicts(); static VR *GetVR(); static TS *GetTS(); + static DictGroupName *GetDictGroupName(); static DicomDirElement *GetDicomDirElements(); private: @@ -51,6 +53,9 @@ private: /// \brief Pointer to a hash table containing the Transfer Syntax codes /// and their english description static TS *TranSyn; + /// \brief Pointer to a hash table containing the Group codes + /// and their english name (from NIH) + static DictGroupName *GroupName; /// \brief Pointer to the hash table containing the Dicom Elements necessary /// to describe each part of a DICOMDIR static DicomDirElement *ddElem; -- 2.45.1