RTK  2.6.0
Reconstruction Toolkit
rtkImagXGeometryReader.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright RTK Consortium
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 
19 #ifndef rtkImagXGeometryReader_h
20 #define rtkImagXGeometryReader_h
21 
22 #include <itkLightProcessObject.h>
24 
25 #include <vector>
26 
27 namespace rtk
28 {
29 
40 template <typename TInputImage>
41 class ITK_TEMPLATE_EXPORT ImagXGeometryReader : public itk::LightProcessObject
42 {
43 public:
44  ITK_DISALLOW_COPY_AND_MOVE(ImagXGeometryReader);
45 
50 
53 
55  itkOverrideGetNameOfClassMacro(ImagXGeometryReader);
56 
58  itkNewMacro(Self);
59 
61  itkGetMacro(Geometry, GeometryType::Pointer);
62 
64  using InputImageType = TInputImage;
65  using InputImagePointer = typename InputImageType::Pointer;
66  using InputImageRegionType = typename InputImageType::RegionType;
67  using InputImagePixelType = typename InputImageType::PixelType;
68  using FileNamesContainer = std::vector<std::string>;
69 
72  itkGetMacro(CalibrationXMLFileName, std::string);
73  itkSetMacro(CalibrationXMLFileName, std::string);
75 
77  itkGetMacro(RoomXMLFileName, std::string);
78  itkSetMacro(RoomXMLFileName, std::string);
80 
83  void
85  {
86  if (m_ProjectionsFileNames != name)
87  {
88  m_ProjectionsFileNames = name;
89  this->Modified();
90  }
91  }
92  const FileNamesContainer &
94  {
95  return m_ProjectionsFileNames;
96  }
98 
99 protected:
101  : m_Geometry(nullptr)
102  , m_CalibrationXMLFileName("")
103  , m_RoomXMLFileName("") {};
104 
105  ~ImagXGeometryReader() override = default;
106 
107 
108 private:
109  void
110  GenerateData() override;
111 
112  // DICOM tag for AI versions
113  static const std::string m_AI_VERSION_1p2;
114  static const std::string m_AI_VERSION_1p5;
115  static const std::string m_AI_VERSION_2pX;
116 
117  // DICOM tags depend on AI version
118  std::string
119  getAIversion();
120 
121  // Structure containing the flexmap (for AI versions >= 2.0)
122  struct FlexmapType
123  {
124  bool isValid;
125  std::string activeArcName;
126  std::string activeGeocalUID;
127  float sid, sdd, sourceToNozzleOffsetAngle;
128  float constantDetectorOffset, xMinus, xPlus;
129  bool isCW;
130  std::vector<float> anglesDeg; // Gantry angles [deg]
131  std::vector<float> Px, Py, Pz, // Detector translations
132  Rx, Ry, Rz, // Detector rotations
133  Tx, Ty, Tz; // Source translations
134  };
135 
137  GetGeometryForAI2p1();
138 
140  {
141  int id0, id1; // indices of angles just below and above the target angle
142  float a0, a1; // weights (1/distance) to angles below and above
143  };
144 
146  interpolate(const std::vector<float> & flexAngles, bool bIsCW, float angleDegree);
147 
148  // Structure containing the calibration models (for AI versions < 2.0)
150  {
151  bool isValid;
152  float sid, sdd, sourceToNozzleOffsetAngle;
153  std::vector<float> Px, Py, Pz, // Detector translations model
154  Rx, Ry, Rz, // Detector rotations model
155  Tx, Ty, Tz; // Source translations model
156 
158  {
159  sourceToNozzleOffsetAngle = -90.f;
160  Px = std::vector<float>(5, 0.f);
161  Py = std::vector<float>(5, 0.f);
162  Pz = std::vector<float>(5, 0.f);
163  Rx = std::vector<float>(5, 0.f);
164  Ry = std::vector<float>(5, 0.f);
165  Rz = std::vector<float>(5, 0.f);
166  Tx = std::vector<float>(5, 0.f);
167  Ty = std::vector<float>(5, 0.f);
168  Tz = std::vector<float>(5, 0.f);
169  }
170  };
171 
172  CalibrationModelType
173  GetGeometryForAI1p5();
174 
175  CalibrationModelType
176  GetGeometryForAI1p5FromXMLFiles();
177 
178  bool
179  isCW(const std::vector<float> & angles);
180 
181  std::vector<float>
182  getInterpolatedValue(const InterpResultType & ires,
183  const std::vector<float> & Dx,
184  const std::vector<float> & Dy,
185  const std::vector<float> & Dz);
186 
187  // Evaluate the calibration models for a given angle
188  std::vector<float>
189  getDeformations(float gantryAngle,
190  const std::vector<float> & Dx,
191  const std::vector<float> & Dy,
192  const std::vector<float> & Dz);
193 
194  void
195  addEntryToGeometry(float gantryAngleDegree,
196  float nozzleToRadAngleOffset,
197  float sid,
198  float sdd,
199  std::vector<float> & detTrans,
200  std::vector<float> & detRot,
201  std::vector<float> & srcTrans);
202 
203  void
204  addEntryToGeometry(const FlexmapType & f, float gantryAngle);
205 
206  void
207  addEntryToGeometry(const CalibrationModelType & c, float gantryAngle);
208 
211  std::string m_RoomXMLFileName;
213 };
214 
215 } // namespace rtk
216 #ifndef ITK_MANUAL_INSTANTIATION
217 # include "rtkImagXGeometryReader.hxx"
218 #endif
219 
220 #endif // rtkImagXGeometryReader_h
GeometryType::Pointer m_Geometry
typename InputImageType::RegionType InputImageRegionType
static const std::string m_AI_VERSION_1p5
FileNamesContainer m_ProjectionsFileNames
Projection geometry for a source and a 2-D flat panel.
void SetProjectionsFileNames(const FileNamesContainer &name)
#define itkSetMacro(name, type)
typename InputImageType::PixelType InputImagePixelType
static const std::string m_AI_VERSION_2pX
typename InputImageType::Pointer InputImagePointer
static const std::string m_AI_VERSION_1p2
const FileNamesContainer & GetProjectionsFileNames() const
std::vector< std::string > FileNamesContainer