7 #include "fwGdcmIO/helper/tags.hpp" 9 #include "fwGdcmIO/exception/InvalidTag.hpp" 10 #include "fwGdcmIO/helper/CsvIO.hpp" 12 #include <fwCore/exceptionmacros.hpp> 14 #include <boost/filesystem/operations.hpp> 15 #include <boost/numeric/conversion/cast.hpp> 27 ::gdcm::Tag getGdcmTag(
const std::string& group,
const std::string& element)
29 SLM_ASSERT(
"Group and element can not be empty", !group.empty() && !element.empty());
31 typedef std::uint16_t DestType;
37 const unsigned long groupL = std::stoul(group,
nullptr, 16);
38 const unsigned long elementL = std::stoul(element,
nullptr, 16);
40 groupDest = ::boost::numeric_cast< DestType >(groupL);
41 elementDest = ::boost::numeric_cast< DestType >(elementL);
43 catch(std::out_of_range& e)
46 "Unable to read DICOM tag from '" + group +
"," + element +
"' : " + e.what()));
48 catch(std::invalid_argument& e)
51 "Unable to read DICOM tag from '" + group +
"," + element +
"' : " + e.what()));
53 catch(::boost::bad_numeric_cast& e)
56 "Unable to read DICOM tag from '" + group +
"," + element +
"' : " + e.what()));
59 return ::gdcm::Tag(groupDest, elementDest);
64 PrivateTagVecType loadPrivateTags(const ::boost::filesystem::path& tagsPath)
66 SLM_ASSERT(
"File '" + tagsPath.string() +
"' must exists",
67 ::boost::filesystem::exists(tagsPath) && ::boost::filesystem::is_regular_file(tagsPath));
69 PrivateTagVecType privateTags;
70 auto csvStream = std::ifstream(tagsPath.string());
76 OSLM_WARN_IF(
"Unxpected token count : " << tag.size() <<
" (3 expected : group, element, manufacturer)",
78 FW_RAISE_IF(
"Unable to read private tag file", tag.size() < 2);
80 privateTags.push_back(::fwGdcmIO::helper::getGdcmTag(tag[0], tag[1]));
81 tag = reader.getLine();
The namespace fwGdcmIO contains reader, writer and helper for dicom data.
#define SLM_ASSERT(message, cond)
work like 'assert' from 'cassert', with in addition a message logged by spylog (with FATAL loglevel) ...
std::vector< std::string > TokenContainerType
Containers to store parsed tokens.
Read CSV file and returns parsed tokens. The input file is supposed to use comma separator, but another separator can be used when reading file.
#define OSLM_WARN_IF(message, cond)