7 #ifndef __FWGDCMIO_HELPER_DICOMDATAREADER_HXX__ 8 #define __FWGDCMIO_HELPER_DICOMDATAREADER_HXX__ 10 #include "fwGdcmIO/config.hpp" 11 #include "fwGdcmIO/helper/Encoding.hpp" 13 #include <fwLog/Logger.hpp> 15 #include <gdcmAttribute.h> 16 #include <gdcmDataSet.h> 44 template< std::u
int16_t GROUP, std::u
int16_t ELEMENT >
45 static std::string
getTagValue(const ::gdcm::DataSet& dataset,
46 const std::string& charset =
"",
47 const ::fwLog::Logger::sptr& logger =
nullptr)
49 std::string result =
"";
51 const ::gdcm::Tag tag(GROUP, ELEMENT);
53 if (dataset.FindDataElement(tag))
55 const ::gdcm::DataElement& dataElement = dataset.GetDataElement(tag);
57 if (!dataElement.IsEmpty())
60 const ::gdcm::ByteValue* bv = dataElement.GetByteValue();
64 std::string buffer(bv->GetPointer(), bv->GetLength());
67 const std::string trimmedBuffer = ::gdcm::LOComp::Trim(buffer.c_str());
73 catch(
const std::runtime_error& e)
78 ss <<
"Could not read tag " << tag <<
" : " << e.what();
79 logger->warning(ss.str());
81 result = trimmedBuffer;
101 template< std::u
int16_t GROUP, std::u
int16_t ELEMENT >
103 const std::string& charset =
"",
104 const ::fwLog::Logger::sptr& logger = 0)
106 std::string result =
"";
108 const ::gdcm::Tag tag = ::gdcm::Attribute< GROUP, ELEMENT >::GetTag();
111 const std::string trimmedBuffer = ::gdcm::LOComp::Trim(buffer.c_str());
117 catch(
const std::runtime_error& e)
121 std::stringstream ss;
122 ss <<
"Could not read tag " << tag <<
" : " << e.what();
123 logger->warning(ss.str());
125 result = trimmedBuffer;
139 template< std::u
int16_t GROUP, std::u
int16_t ELEMENT,
typename T >
142 ::gdcm::Attribute< GROUP, ELEMENT > attribute;
143 attribute.SetFromDataSet(dataset);
144 return attribute.GetValue();
152 #endif // __FWGDCMIO_HELPER_DICOMDATAREADER_HXX__ This class contains helpers to handle GDCM data reading.
static std::string getTagValue(const ::gdcm::DataSet &dataset, const std::string &charset="", const ::fwLog::Logger::sptr &logger=nullptr)
Return a string from a tag found in dataset. An empty string returned means the tag is not found or e...
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
static std::string getTagValue(const std::string &buffer, const std::string &charset="", const ::fwLog::Logger::sptr &logger=0)
Return an utf-8 tag value from the tag value's buffer.
static const T getTagValue(const ::gdcm::DataSet &dataset)
Return a value from a tag found in dataset.
static FWGDCMIO_API std::string convertString(const std::string &source, const std::string &definedCharsetTerm, const std::shared_ptr< ::fwLog::Logger > &logger=nullptr)
Convert a DICOM string from the specified charset to utf-8.