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 #ifdef itkOverrideGetNameOfClassMacro
56  itkOverrideGetNameOfClassMacro(ImagXGeometryReader);
57 #else
59 #endif
60 
61 
63  itkNewMacro(Self);
64 
66  itkGetMacro(Geometry, GeometryType::Pointer);
67 
69  using InputImageType = TInputImage;
70  using InputImagePointer = typename InputImageType::Pointer;
71  using InputImageRegionType = typename InputImageType::RegionType;
72  using InputImagePixelType = typename InputImageType::PixelType;
73  using FileNamesContainer = std::vector<std::string>;
74 
77  itkGetMacro(CalibrationXMLFileName, std::string);
78  itkSetMacro(CalibrationXMLFileName, std::string);
80 
82  itkGetMacro(RoomXMLFileName, std::string);
83  itkSetMacro(RoomXMLFileName, std::string);
85 
88  void
90  {
91  if (m_ProjectionsFileNames != name)
92  {
93  m_ProjectionsFileNames = name;
94  this->Modified();
95  }
96  }
97  const FileNamesContainer &
99  {
100  return m_ProjectionsFileNames;
101  }
103 
104 protected:
106  : m_Geometry(nullptr)
107  , m_CalibrationXMLFileName("")
108  , m_RoomXMLFileName(""){};
109 
110  ~ImagXGeometryReader() override = default;
111 
112 
113 private:
114  void
115  GenerateData() override;
116 
117  // DICOM tag for AI versions
118  static const std::string m_AI_VERSION_1p2;
119  static const std::string m_AI_VERSION_1p5;
120  static const std::string m_AI_VERSION_2pX;
121 
122  // DICOM tags depend on AI version
123  std::string
124  getAIversion();
125 
126  // Structure containing the flexmap (for AI versions >= 2.0)
127  struct FlexmapType
128  {
129  bool isValid;
130  std::string activeArcName;
131  std::string activeGeocalUID;
132  float sid, sdd, sourceToNozzleOffsetAngle;
133  float constantDetectorOffset, xMinus, xPlus;
134  bool isCW;
135  std::vector<float> anglesDeg; // Gantry angles [deg]
136  std::vector<float> Px, Py, Pz, // Detector translations
137  Rx, Ry, Rz, // Detector rotations
138  Tx, Ty, Tz; // Source translations
139  };
140 
142  GetGeometryForAI2p1();
143 
145  {
146  int id0, id1; // indices of angles just below and above the target angle
147  float a0, a1; // weights (1/distance) to angles below and above
148  };
149 
151  interpolate(const std::vector<float> & flexAngles, bool bIsCW, float angleDegree);
152 
153  // Structure containing the calibration models (for AI versions < 2.0)
155  {
156  bool isValid;
157  float sid, sdd, sourceToNozzleOffsetAngle;
158  std::vector<float> Px, Py, Pz, // Detector translations model
159  Rx, Ry, Rz, // Detector rotations model
160  Tx, Ty, Tz; // Source translations model
161 
163  {
164  sourceToNozzleOffsetAngle = -90.f;
165  Px = std::vector<float>(5, 0.f);
166  Py = std::vector<float>(5, 0.f);
167  Pz = std::vector<float>(5, 0.f);
168  Rx = std::vector<float>(5, 0.f);
169  Ry = std::vector<float>(5, 0.f);
170  Rz = std::vector<float>(5, 0.f);
171  Tx = std::vector<float>(5, 0.f);
172  Ty = std::vector<float>(5, 0.f);
173  Tz = std::vector<float>(5, 0.f);
174  }
175  };
176 
177  CalibrationModelType
178  GetGeometryForAI1p5();
179 
180  CalibrationModelType
181  GetGeometryForAI1p5FromXMLFiles();
182 
183  bool
184  isCW(const std::vector<float> & angles);
185 
186  std::vector<float>
187  getInterpolatedValue(const InterpResultType & ires,
188  const std::vector<float> & Dx,
189  const std::vector<float> & Dy,
190  const std::vector<float> & Dz);
191 
192  // Evaluate the calibration models for a given angle
193  std::vector<float>
194  getDeformations(float gantryAngle,
195  const std::vector<float> & Dx,
196  const std::vector<float> & Dy,
197  const std::vector<float> & Dz);
198 
199  void
200  addEntryToGeometry(float gantryAngleDegree,
201  float nozzleToRadAngleOffset,
202  float sid,
203  float sdd,
204  std::vector<float> & detTrans,
205  std::vector<float> & detRot,
206  std::vector<float> & srcTrans);
207 
208  void
209  addEntryToGeometry(const FlexmapType & f, float gantryAngle);
210 
211  void
212  addEntryToGeometry(const CalibrationModelType & c, float gantryAngle);
213 
216  std::string m_RoomXMLFileName;
218 };
219 
220 } // namespace rtk
221 #ifndef ITK_MANUAL_INSTANTIATION
222 # include "rtkImagXGeometryReader.hxx"
223 #endif
224 
225 #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