Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY
10 {
11 }
12  without
13 even the implied warranty of MERCHANTABILITY or FITNESS FOR
14 A PARTICULAR PURPOSE.
15 
16 See LICENSE.txt or http://www.mitk.org for details.
17 
18 ===================================================================*/
19 
20 #include "mitkDICOMTag.h"
21 
22 #include <gdcmGlobal.h>
23 #include <gdcmDicts.h>
24 
25 #include <boost/algorithm/string.hpp>
26 
27 #include "mitkLogMacros.h"
28 #include "ofstd.h"
29 
31 ::DICOMTag(unsigned int group, unsigned int element)
32 :m_Group(group)
33 ,m_Element(element)
34 {
35 }
36 
38 ::DICOMTag(const DICOMTag& other)
39 :m_Group(other.m_Group)
40 ,m_Element(other.m_Element)
41 {
42 }
43 
44 bool
46 ::operator==(const DICOMTag& other) const
47 {
48  return
49  m_Group == other.m_Group &&
50  m_Element == other.m_Element
51  ;
52 }
53 
54 
57 ::operator=(const DICOMTag& other)
58 {
59  if (this != &other)
60  {
61  m_Group = other.m_Group;
62  m_Element = other.m_Element;
63  }
64  return *this;
65 }
66 
67 unsigned int
69 ::GetGroup() const
70 {
71  return m_Group;
72 }
73 
74 unsigned int
76 ::GetElement() const
77 {
78  return m_Element;
79 }
80 
81 bool
83 ::operator<(const DICOMTag& other) const
84 {
85  return
86  ( this->m_Group < other.m_Group )
87  ||
88  ( ( this->m_Group == other.m_Group )
89  &&
90  ( this->m_Element < other.m_Element )
91  );
92 }
93 
94 std::string
96 ::GetName() const
97 {
98  gdcm::Tag t(m_Group, m_Element);
99 
100  const gdcm::Global& g = gdcm::Global::GetInstance(); // sum of all knowledge !
101  const gdcm::Dicts& dicts = g.GetDicts();
102  const gdcm::Dict& pub = dicts.GetPublicDict(); // Part 6
103 
104  const gdcm::DictEntry& entry = pub.GetDictEntry(t);
105  std::string name = entry.GetName();
106  if (name.empty())
107  {
108  name = "Unknown Tag";
109  }
110 
111  return name;
112 }
113 
114 std::string
115 mitk::DICOMTag
116 ::toHexString(unsigned int i) const
117 {
118  std::stringstream ss;
119  ss << std::setfill ('0') << std::setw(4) << std::hex << i;
120  return ss.str();
121 }
122 
123 void
125 ::Print(std::ostream& os) const
126 {
127  os << "(" << toHexString(m_Group) << "," << toHexString(m_Element) << ") " << this->GetName();
128 }
129 
130 void mitk::DICOMStringToOrientationVectors( const std::string& s,
131  Vector3D& right,
132  Vector3D& up,
133  bool& successful )
134 {
135  successful = false;
136 
137  try
138  {
139  std::vector<std::string> strs;
140  boost::split( strs, s, boost::is_any_of( "\\" ) );
141  if ( strs.size() == 6 )
142  {
143  int i = 0;
144  for ( ; i < 3; ++i )
145  {
146  right[i] = OFStandard::atof( strs[i].c_str() );
147  }
148  for ( ; i < 6; ++i )
149  {
150  up[i - 3] = OFStandard::atof( strs[i].c_str() );
151  }
152  successful = true;
153  }
154  }
155  catch ( const std::exception& /*e*/ )
156  {
157  right.Fill( 0.0 );
158  right[0] = 1.0;
159 
160  up.Fill( 0.0 );
161  up[1] = 1.0;
162 
163  successful = false;
164  }
165 }
166 
167 
168 bool
169 mitk::DICOMStringToSpacing(const std::string& s, ScalarType& spacingX, ScalarType& spacingY)
170 {
171  bool successful = false;
172 
173  try
174  {
175  std::vector<std::string> strs;
176  boost::split( strs, s, boost::is_any_of( "\\" ) );
177  if ( strs.size() > 1 )
178  {
179  spacingY = OFStandard::atof( strs[0].c_str() );
180  spacingX = OFStandard::atof( strs[1].c_str() );
181  successful = true;
182  }
183  }
184  catch ( const std::exception& /*e*/ )
185  {
186  }
187 
188  return successful;
189 }
190 
191 
192 mitk::Point3D mitk::DICOMStringToPoint3D( const std::string& s, bool& successful )
193 {
194  Point3D p;
195  successful = true;
196 
197  try
198  {
199  std::vector<std::string> strs;
200  boost::split( strs, s, boost::is_any_of( "\\" ) );
201  if ( strs.size() == 3 )
202  {
203  for ( int i = 0; i < 3; ++i )
204  {
205  p[i] = OFStandard::atof( strs[i].c_str() );
206  }
207  }
208  }
209  catch ( const std::exception& /*e*/ )
210  {
211  p.Fill( 0.0 );
212  }
213 
214 
215  return p;
216 }
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:37
unsigned int GetGroup() const
DICOMTag(unsigned int group, unsigned int element)
bool operator<(const DICOMTag &other) const
unsigned int GetElement() const
DICOMTag & operator=(const DICOMTag &other)
bool operator==(const DICOMTag &other) const
static std::string GetName(std::string fileName, std::string suffix)
Point3D DICOMStringToPoint3D(const std::string &s, bool &successful)
Convert DICOM string describing a point to Point3D.
std::string GetName() const
Return the name of this tag (e.g. "SeriesDescription" instead of "(0008,103e)")
void Print(std::ostream &os) const
add "(group-id,element-id) name" to given stream
static std::vector< std::string > & split(const std::string &s, char delim, std::vector< std::string > &elems)