Medical Imaging Interaction Toolkit  2018.4.99-12ad79a3
Medical Imaging Interaction Toolkit
mitkDICOMTag.cpp
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #include "mitkDICOMTag.h"
14 
15 #include <gdcmGlobal.h>
16 #include <gdcmDicts.h>
17 
18 #include <boost/algorithm/string.hpp>
19 
20 #include "mitkLogMacros.h"
21 #include "dcmtk/ofstd/ofstd.h"
22 
24 ::DICOMTag(unsigned int group, unsigned int element)
25 :m_Group(group)
26 ,m_Element(element)
27 {
28 }
29 
31 ::DICOMTag(const DICOMTag& other)
32 :m_Group(other.m_Group)
33 ,m_Element(other.m_Element)
34 {
35 }
36 
37 bool
39 ::operator==(const DICOMTag& other) const
40 {
41  return
42  m_Group == other.m_Group &&
43  m_Element == other.m_Element
44  ;
45 }
46 
47 
50 ::operator=(const DICOMTag& other)
51 {
52  if (this != &other)
53  {
54  m_Group = other.m_Group;
55  m_Element = other.m_Element;
56  }
57  return *this;
58 }
59 
60 unsigned int
62 ::GetGroup() const
63 {
64  return m_Group;
65 }
66 
67 unsigned int
69 ::GetElement() const
70 {
71  return m_Element;
72 }
73 
74 bool
76 ::operator<(const DICOMTag& other) const
77 {
78  return
79  ( this->m_Group < other.m_Group )
80  ||
81  ( ( this->m_Group == other.m_Group )
82  &&
83  ( this->m_Element < other.m_Element )
84  );
85 }
86 
87 std::string
89 ::GetName() const
90 {
91  gdcm::Tag t(m_Group, m_Element);
92 
93  const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
94  const gdcm::Dicts& dicts = g.GetDicts();
95  const gdcm::Dict& pub = dicts.GetPublicDict(); // Part 6
96 
97  const gdcm::DictEntry& entry = pub.GetDictEntry(t);
98  std::string name = entry.GetName();
99  if (name.empty())
100  {
101  name = "Unknown Tag";
102  }
103 
104  return name;
105 }
106 
107 std::string
108 mitk::DICOMTag
109 ::toHexString(unsigned int i) const
110 {
111  std::stringstream ss;
112  ss << std::setfill ('0') << std::setw(4) << std::hex << i;
113  return ss.str();
114 }
115 
116 void
118 ::Print(std::ostream& os) const
119 {
120  os << "(" << toHexString(m_Group) << "," << toHexString(m_Element) << ") " << this->GetName();
121 }
122 
123 void mitk::DICOMStringToOrientationVectors( const std::string& s,
124  Vector3D& right,
125  Vector3D& up,
126  bool& successful )
127 {
128  successful = false;
129 
130  try
131  {
132  std::vector<std::string> strs;
133  boost::split( strs, s, boost::is_any_of( "\\" ) );
134  if ( strs.size() == 6 )
135  {
136  int i = 0;
137  for ( ; i < 3; ++i )
138  {
139  right[i] = OFStandard::atof( strs[i].c_str() );
140  }
141  for ( ; i < 6; ++i )
142  {
143  up[i - 3] = OFStandard::atof( strs[i].c_str() );
144  }
145  successful = true;
146  }
147  }
148  catch ( const std::exception& /*e*/ )
149  {
150  right.Fill( 0.0 );
151  right[0] = 1.0;
152 
153  up.Fill( 0.0 );
154  up[1] = 1.0;
155 
156  successful = false;
157  }
158 }
159 
160 
161 bool
162 mitk::DICOMStringToSpacing(const std::string& s, ScalarType& spacingX, ScalarType& spacingY)
163 {
164  bool successful = false;
165 
166  try
167  {
168  std::vector<std::string> strs;
169  boost::split( strs, s, boost::is_any_of( "\\" ) );
170  if ( strs.size() > 1 )
171  {
172  spacingY = OFStandard::atof( strs[0].c_str() );
173  spacingX = OFStandard::atof( strs[1].c_str() );
174  successful = true;
175  }
176  }
177  catch ( const std::exception& /*e*/ )
178  {
179  }
180 
181  return successful;
182 }
183 
184 
185 mitk::Point3D mitk::DICOMStringToPoint3D( const std::string& s, bool& successful )
186 {
187  Point3D p;
188  successful = true;
189 
190  try
191  {
192  std::vector<std::string> strs;
193  boost::split( strs, s, boost::is_any_of( "\\" ) );
194  if ( strs.size() == 3 )
195  {
196  for ( int i = 0; i < 3; ++i )
197  {
198  p[i] = OFStandard::atof( strs[i].c_str() );
199  }
200  }
201  }
202  catch ( const std::exception& /*e*/ )
203  {
204  p.Fill( 0.0 );
205  }
206 
207 
208  return p;
209 }
unsigned int GetElement() const
void Print(std::ostream &os) const
add "(group-id,element-id) name" to given stream
double ScalarType
bool DICOMStringToSpacing(const std::string &s, ScalarType &spacingX, ScalarType &spacingY)
void DICOMStringToOrientationVectors(const std::string &s, Vector3D &right, Vector3D &up, bool &successful)
Convert DICOM string describing a point two Vector3D.
Representation of a DICOM tag.
Definition: mitkDICOMTag.h:32
DICOMTag(unsigned int group, unsigned int element)
bool operator==(const DICOMTag &other) const
DICOMTag & operator=(const DICOMTag &other)
std::string GetName() const
Return the name of this tag (e.g. "SeriesDescription" instead of "(0008,103e)")
bool operator<(const DICOMTag &other) const
Point3D DICOMStringToPoint3D(const std::string &s, bool &successful)
Convert DICOM string describing a point to Point3D.
unsigned int GetGroup() const