Mercurial > hg > orthanc
diff OrthancServer/FromDcmtkBridge.cpp @ 1657:5360cdba70d8
New function "OrthancPluginRegisterDictionaryTag()" to declare DICOM tags
author | Sebastien Jodogne <s.jodogne@gmail.com> |
---|---|
date | Tue, 29 Sep 2015 16:31:48 +0200 |
parents | d3ba98d6b6e9 |
children | 14a32b2fa63e |
line wrap: on
line diff
--- a/OrthancServer/FromDcmtkBridge.cpp Tue Sep 29 15:13:34 2015 +0200 +++ b/OrthancServer/FromDcmtkBridge.cpp Tue Sep 29 16:31:48 2015 +0200 @@ -157,43 +157,74 @@ #endif + namespace + { + class DictionaryLocker + { + private: + DcmDataDictionary& dictionary_; + + public: + DictionaryLocker() : dictionary_(dcmDataDict.wrlock()) + { + } + + ~DictionaryLocker() + { + dcmDataDict.unlock(); + } + + DcmDataDictionary& operator*() + { + return dictionary_; + } + + DcmDataDictionary* operator->() + { + return &dictionary_; + } + }; + } + + void FromDcmtkBridge::InitializeDictionary() { /* Disable "gethostbyaddr" (which results in memory leaks) and use raw IP addresses */ dcmDisableGethostbyaddr.set(OFTrue); - dcmDataDict.clear(); - DcmDataDictionary& d = dcmDataDict.wrlock(); + { + DictionaryLocker locker; + + locker->clear(); #if DCMTK_USE_EMBEDDED_DICTIONARIES == 1 - LOG(WARNING) << "Loading the embedded dictionaries"; - /** - * Do not load DICONDE dictionary, it breaks the other tags. The - * command "strace storescu 2>&1 |grep dic" shows that DICONDE - * dictionary is not loaded by storescu. - **/ - //LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICONDE); + LOG(WARNING) << "Loading the embedded dictionaries"; + /** + * Do not load DICONDE dictionary, it breaks the other tags. The + * command "strace storescu 2>&1 |grep dic" shows that DICONDE + * dictionary is not loaded by storescu. + **/ + //LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICONDE); - LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_DICOM); - LoadEmbeddedDictionary(d, EmbeddedResources::DICTIONARY_PRIVATE); + LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_DICOM); + LoadEmbeddedDictionary(*locker, EmbeddedResources::DICTIONARY_PRIVATE); #elif defined(__linux) || defined(__FreeBSD_kernel__) - std::string path = DCMTK_DICTIONARY_DIR; + std::string path = DCMTK_DICTIONARY_DIR; - const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE); - if (env != NULL) - { - path = std::string(env); - } + const char* env = std::getenv(DCM_DICT_ENVIRONMENT_VARIABLE); + if (env != NULL) + { + path = std::string(env); + } - LoadExternalDictionary(d, path, "dicom.dic"); - LoadExternalDictionary(d, path, "private.dic"); + LoadExternalDictionary(*locker, path, "dicom.dic"); + LoadExternalDictionary(*locker, path, "private.dic"); #else #error Support your platform here #endif - - dcmDataDict.unlock(); + } /* make sure data dictionary is loaded */ if (!dcmDataDict.isDictionaryLoaded()) @@ -214,6 +245,45 @@ } + void FromDcmtkBridge::RegisterDictionaryTag(const DicomTag& tag, + const DcmEVR& vr, + const std::string& name, + unsigned int minMultiplicity, + unsigned int maxMultiplicity) + { + if (minMultiplicity < 1) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + if (maxMultiplicity == 0) + { + maxMultiplicity = DcmVariableVM; + } + else if (maxMultiplicity < minMultiplicity) + { + throw OrthancException(ErrorCode_ParameterOutOfRange); + } + + std::auto_ptr<DcmDictEntry> entry(new DcmDictEntry(tag.GetGroup(), + tag.GetElement(), + vr, name.c_str(), + static_cast<int>(minMultiplicity), + static_cast<int>(maxMultiplicity), + NULL /* version */, + OFTrue /* doCopyString */, + NULL /* private creator */)); + + entry->setGroupRangeRestriction(DcmDictRange_Unspecified); + entry->setElementRangeRestriction(DcmDictRange_Unspecified); + + { + DictionaryLocker locker; + locker->addEntry(entry.release()); + } + } + + Encoding FromDcmtkBridge::DetectEncoding(DcmDataset& dataset) { // By default, Latin1 encoding is assumed