CortidQCT  1.2.2.52
MeasurementModel.h
Go to the documentation of this file.
1 
12 #pragma once
13 
14 #include "DiscreteRange.h"
15 #include "Optional.h"
16 
17 #include <chrono>
18 #include <set>
19 #include <string>
20 #include <unordered_map>
21 #include <vector>
22 
23 namespace CortidQCT {
24 
25 #pragma clang diagnostic push
26 #pragma clang diagnostic ignored "-Wpadded"
27 
34 public:
36  using Label = unsigned int;
37 
38 private:
40  struct VOIData {
41  Label label;
42  double scale;
43  std::string name;
44  std::vector<float> data;
45  };
47  using DataStorage = std::unordered_map<Label, VOIData>;
48 
49 public:
52 
54  std::optional<std::string> name;
56  std::optional<std::string> description;
58  std::optional<std::string> author;
61  std::optional<std::string> creationDate;
62 
64  float kernelSigma = 1.f;
66  float sliceSpacing = 1.f;
67 
71  DiscreteRange<float> densityRange{-1000.f, 2000.f, 1.f};
74 
76 
79 
89  inline MeasurementModel() noexcept(noexcept(DataStorage())) {}
90 
95  explicit MeasurementModel(std::string const &filename);
96 
99  inline static MeasurementModel fromFile(std::string const &filename) {
100  return MeasurementModel(filename);
101  }
102 
104 
107 
113  MeasurementModel &loadFromFile(std::string const &filename);
114 
116 
119 
121  inline bool isEmpty() const noexcept { return data_.empty(); }
122 
124  inline auto labels() const {
125  std::set<Label> labels;
126  for (auto &&entry : data_) { labels.insert(entry.first); }
127 
128  return labels;
129  }
130 
132  inline std::size_t labelCount() const noexcept { return data_.size(); }
133 
135  inline double densityScale(Label const &label) const {
136  if (auto const voiIt = data_.find(label); voiIt != data_.end()) {
137  return voiIt->second.scale;
138  }
139  return std::numeric_limits<double>::quiet_NaN();
140  }
141 
143 
167  template <class F>
168  inline auto withUnsafeDataPointer(Label label, F &&f) const {
169  if (auto const store = data_.find(label); store != data_.end()) {
170  return f(store->second.data.data());
171  }
172 
173  throw std::invalid_argument("Label " + std::to_string(label) +
174  " not found");
175 
176  // Should never be called, but GCC complains if nothing is returned.
177  return f(nullptr);
178  }
179 
181 
182 private:
183 
185  void reorderData();
186 
188  DataStorage data_;
189 };
190 #pragma clang diagnostic pop
191 
192 } // namespace CortidQCT
Name namespace for CortidQCT library.
Definition: CortidQCT.h:23
auto labels() const
Returns all valid labels of the model.
Definition: MeasurementModel.h:124
DiscreteRange< float > densityRange
range for the density sampling
Definition: MeasurementModel.h:71
bool isEmpty() const noexcept
Returns true iff to model contains to data.
Definition: MeasurementModel.h:121
double densityScale(Label const &label) const
Returns the density scale parameter of the given VOI.
Definition: MeasurementModel.h:135
std::optional< std::string > author
Optional model author.
Definition: MeasurementModel.h:58
DiscreteRange< float > angleRange
range for the angle sampling
Definition: MeasurementModel.h:73
Type representing the measurement model.
Definition: MeasurementModel.h:33
MeasurementModel() noexcept(noexcept(DataStorage()))
Creates an empty measurement model.
Definition: MeasurementModel.h:89
std::optional< std::string > description
Optional model description.
Definition: MeasurementModel.h:56
This header contains the definition of the DiscreteRange template.
std::optional< std::string > name
Optional model name.
Definition: MeasurementModel.h:54
float kernelSigma
in-plane kernel width (sigma of gaussian kernel)
Definition: MeasurementModel.h:64
float sliceSpacing
slice thickness
Definition: MeasurementModel.h:66
static MeasurementModel fromFile(std::string const &filename)
Definition: MeasurementModel.h:99
std::optional< std::string > creationDate
Definition: MeasurementModel.h:61
DiscreteRange< float > samplingRange
sampling range for the line sampling
Definition: MeasurementModel.h:69
unsigned int Label
Label type.
Definition: MeasurementModel.h:36
MeasurementModel & loadFromFile(std::string const &filename)
Definition: MeasurementModel.cpp:47
auto withUnsafeDataPointer(Label label, F &&f) const
Calls the given functional with an unsafe pointer to the raw sample data storage. ...
Definition: MeasurementModel.h:168
std::size_t labelCount() const noexcept
Returns the number of valid labels of the model.
Definition: MeasurementModel.h:132
This header is a wrapper for including optional depending on the supported C++ standard version...