STIR  6.2.0
ImagingModality.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2013, University College London
3  This file is part of STIR.
4 
5  SPDX-License-Identifier: Apache-2.0
6 
7  See STIR/LICENSE.txt for details
8 */
18 #ifndef __stir_ImagingModality_H__
19 #define __stir_ImagingModality_H__
20 
22 #include "stir/warning.h"
23 #include <string>
24 
25 namespace stir
26 {
27 
35 {
36 public:
39  {
40  Unknown,
41  PT,
42  NM,
43  MR,
44  CT,
45  US,
46  Optical
47  };
48 
50  ImagingModality(ImagingModalityValue modality_v = Unknown)
51  : modality(modality_v)
52  {
53  this->set_string();
54  }
55 
57 
68  explicit ImagingModality(const std::string& modality_string_v) { this->set_from_string(modality_string_v); }
69 
70  ImagingModalityValue get_modality() const { return this->modality; }
71 
73  std::string get_name() const { return this->modality_string; }
74 
75  bool operator==(const ImagingModality& mod) const { return this->modality == mod.modality; }
76  bool operator!=(const ImagingModality& mod) const { return !(*this == mod); }
77  bool is_known() const { return this->modality != Unknown; }
78  bool is_unknown() const { return this->modality == Unknown; }
79 
80 private:
81  ImagingModalityValue modality;
82  std::string modality_string;
83 
84  void set_string()
85  {
86  switch (this->modality)
87  {
88  case PT:
89  this->modality_string = "PT";
90  break;
91  case NM:
92  this->modality_string = "NM";
93  break;
94  case MR:
95  this->modality_string = "MR";
96  break;
97  case CT:
98  this->modality_string = "CT";
99  break;
100  case US:
101  this->modality_string = "US";
102  break;
103  case Optical:
104  this->modality_string = "Optical";
105  break;
106  default:
107  case Unknown:
108  this->modality_string = "Unknown";
109  break;
110  }
111  }
112 
113  void set_from_string(const std::string& modality)
114  {
115  const std::string mod = standardise_interfile_keyword(modality);
116  if (mod == "pt" || mod == "pet")
117  this->modality = PT;
118  else if (mod == "nm" || mod == "nucmed" || mod == "spect")
119  this->modality = NM;
120  else if (mod == "mr" || mod == "mri")
121  this->modality = MR;
122  else if (mod == "ct" || mod == "cat")
123  this->modality = CT;
124  else if (mod == "us" || mod == "ultrasound")
125  this->modality = US;
126  else if (mod == "optical")
127  this->modality = Optical;
128  else
129  {
130  if (!mod.empty() && mod != "unknown")
131  warning("Unrecognised modality: '" + mod + "'. Setting to Unknown");
132  this->modality = Unknown;
133  }
134  this->set_string();
135  }
136 };
137 
138 } // namespace stir
139 #endif
Namespace for the STIR library (and some/most of its applications)
Definition: General_Reconstruction.cxx:6
ImagingModality(ImagingModalityValue modality_v=Unknown)
Construct from enum, set string accordingly.
Definition: ImagingModality.h:50
std::string get_name() const
Returns name as a standardised string (in DICOM conventions)
Definition: ImagingModality.h:73
ImagingModalityValue
enum with possible values (using DICOM naming)
Definition: ImagingModality.h:38
Class for encoding the modality.
Definition: ImagingModality.h:34
string standardise_interfile_keyword(const string &keyword)
Put a (Interfile) keyword into a standard form.
Definition: interfile_keyword_functions.cxx:28
void warning(const char *const s,...)
Print warning with format string a la printf.
Definition: warning.cxx:41
Functions useful for manipulating Interfile keywords.
ImagingModality(const std::string &modality_string_v)
Construct from string, set enum accordingly.
Definition: ImagingModality.h:68
Declaration of stir::warning()