CTL  0.6.1
Computed Tomography Library
abstractreconstructor.h
Go to the documentation of this file.
1 #ifndef CTL_ABSTRACTRECONSTRUCTOR_H
2 #define CTL_ABSTRACTRECONSTRUCTOR_H
3 
4 #include "img/projectiondataview.h"
6 #include <memory>
7 
8 namespace CTL {
9 
10 class AbstractDynamicVolumeData;
11 class AcquisitionSetup;
12 class CompositeVolume;
13 class SparseVoxelVolume;
14 class SpectralVolumeData;
15 template <typename> class VoxelVolume;
16 
34 class ReconstructorNotifier : public QObject
35 {
36 public:
37  void connectToMessageHandler(bool includeProgress);
38 
39  Q_OBJECT
40 Q_SIGNALS:
41  void progress(qreal portionCompleted);
42  void information(QString info);
43 
44 private:
45  QMetaObject::Connection _progressConnection;
46 };
47 
164 {
166 
167  public:virtual void configure(const AcquisitionSetup& setup) = 0;
168 
169 public:
170  AbstractReconstructor() = default;
173  AbstractReconstructor& operator=(const AbstractReconstructor&) = delete;
174  AbstractReconstructor& operator=(AbstractReconstructor&&) = default;
175  ~AbstractReconstructor() override = default;
176 
177  virtual bool isApplicableTo(const AcquisitionSetup& setup) const; // { return true; }
178 
179  // reconstruction methods
180  virtual bool reconstructToPlain(const ProjectionDataView& projections,
181  VoxelVolume<float>& targetVolume);
182  virtual bool reconstructToSpectral(const ProjectionDataView& projections,
183  SpectralVolumeData& targetVolume);
184  virtual bool reconstructToDynamic(const ProjectionDataView& projections,
185  AbstractDynamicVolumeData& targetVolume);
186  virtual bool reconstructToComposite(const ProjectionDataView& projections,
187  CompositeVolume& targetVolume);
188  virtual bool reconstructToSparse(const ProjectionDataView& projections,
189  SparseVoxelVolume& targetVolume);
190 
191  template <class VolumeType>
192  bool reconstructTo(const ProjectionDataView& projections, VolumeType& targetVolume);
193 
194  template <class VolumeType>
196  const ProjectionDataView& projections,
197  VolumeType& targetVolume);
198 
199  // value returner
200  template <class VolumeType,
201  class = typename std::enable_if<!std::is_lvalue_reference<VolumeType>::value>::type>
202  Q_REQUIRED_RESULT
203  VolumeType reconstruct(const ProjectionDataView& projections,
204  const VolumeType& initialVolume,
205  bool* ok = nullptr);
206 
207  template <class VolumeType,
208  class = typename std::enable_if<!std::is_lvalue_reference<VolumeType>::value>::type>
209  Q_REQUIRED_RESULT
210  VolumeType reconstruct(const ProjectionDataView& projections,
211  VolumeType&& initialVolume,
212  bool* ok = nullptr);
213 
214  template <class VolumeType,
215  class = typename std::enable_if<!std::is_lvalue_reference<VolumeType>::value>::type>
216  Q_REQUIRED_RESULT
217  VolumeType configureAndReconstruct(const AcquisitionSetup& setup,
218  const ProjectionDataView& projections,
219  const VolumeType& initialVolume,
220  bool* ok = nullptr);
221 
222  template <class VolumeType,
223  class = typename std::enable_if<!std::is_lvalue_reference<VolumeType>::value>::type>
224  Q_REQUIRED_RESULT
225  VolumeType configureAndReconstruct(const AcquisitionSetup& setup,
226  const ProjectionDataView& view,
227  VolumeType&& initialVolume,
228  bool* ok = nullptr);
229 
230  // SerializationInterface interface
231  virtual QVariant parameter() const;
232  virtual void setParameter(const QVariant& parameter);
233 
234  void fromVariant(const QVariant& variant) override; // { }
235  QVariant toVariant() const override; // { return QVariant(); }
236 
237  virtual ReconstructorNotifier* notifier();
238  void connectNotifierToMessageHandler(bool includeProgress = false);
239 
240 private:
243  };
244 };
245 
246 template <>
247 bool AbstractReconstructor::reconstructTo(const ProjectionDataView& projections,
248  VoxelVolume<float>& targetVolume);
249 template <>
250 bool AbstractReconstructor::reconstructTo(const ProjectionDataView& projections,
251  SpectralVolumeData& targetVolume);
252 template <>
253 bool AbstractReconstructor::reconstructTo(const ProjectionDataView& projections,
254  CompositeVolume& targetVolume);
255 template <>
256 bool AbstractReconstructor::reconstructTo(const ProjectionDataView& projections,
257  SparseVoxelVolume& targetVolume);
264 template <class DynamicVolumeType>
266  DynamicVolumeType& targetVolume)
267 {
268  static_assert(std::is_convertible<DynamicVolumeType*, AbstractDynamicVolumeData*>::value,
269  "Method call defaulted to dynamic case, because the passed volume type is not covered "
270  "by any available specialization. Consider explicitly providing the required base type "
271  "(e.g. reconstruct[To]<SpectralVolumeData>()).");
272 
273  return reconstructToDynamic(projections, targetVolume);
274 }
275 
279 template <>
281  const ProjectionDataView& projections,
282  VoxelVolume<float>& targetVolume);
286 template <>
288  const ProjectionDataView& projections,
289  SpectralVolumeData& targetVolume);
293 template <>
295  const ProjectionDataView& projections,
296  CompositeVolume& targetVolume);
300 template <>
302  const ProjectionDataView& projections,
303  SparseVoxelVolume& targetVolume);
310 template <class DynamicVolumeType>
312  const ProjectionDataView& projections,
313  DynamicVolumeType& targetVolume)
314 {
315  static_assert(std::is_convertible<DynamicVolumeType*, AbstractDynamicVolumeData*>::value,
316  "Method call defaulted to dynamic case, because the passed volume type is not covered "
317  "by any available specialization. Consider explicitly providing the required base type "
318  "(e.g. reconstruct[To]<SpectralVolumeData>()).");
319 
320  configure(setup);
321  return reconstructToDynamic(projections, targetVolume);
322 }
323 
327 template <class VolumeType, class>
329  const VolumeType& initialVolume,
330  bool* ok)
331 {
332  VolumeType ret(initialVolume);
333 
334  const auto recoOk = reconstructTo(projections, ret);
335 
336  if(ok) *ok = recoOk;
337 
338  return ret;
339 }
340 
344 template <class VolumeType, class>
346  VolumeType&& initialVolume,
347  bool* ok)
348 {
349  VolumeType ret(std::move(initialVolume));
350 
351  const auto recoOk = reconstructTo(projections, ret);
352 
353  if(ok) *ok = recoOk;
354 
355  return ret;
356 }
357 
361 template <class VolumeType, class>
363  const ProjectionDataView& projections,
364  const VolumeType& initialVolume,
365  bool* ok)
366 {
367  configure(setup);
368  return reconstruct(projections, initialVolume, ok);
369 }
370 
374 template <class VolumeType, class>
376  const ProjectionDataView& projections,
377  VolumeType&& initialVolume,
378  bool* ok)
379 {
380  configure(setup);
381  return reconstruct(projections, std::move(initialVolume), ok);
382 }
383 
472 // factory function `makeReconstructor`
473 template <typename ReconstructorType, typename... ConstructorArguments>
474 auto makeReconstructor(ConstructorArguments&&... arguments) ->
475  typename std::enable_if<std::is_convertible<ReconstructorType*, AbstractReconstructor*>::value,
476  std::unique_ptr<ReconstructorType>>::type
477 {
478  return std::unique_ptr<ReconstructorType>(new ReconstructorType(
479  std::forward<ConstructorArguments>(arguments)...));
480 }
481 
482 } // namespace CTL
483 
485 
500 
502 #endif // CTL_ABSTRACTRECONSTRUCTOR_H
virtual void setParameter(const QVariant &parameter)
Sets the parameters of this instance based on the passed QVariant parameter.
Definition: abstractreconstructor.cpp:183
bool reconstructTo(const ProjectionDataView &projections, VolumeType &targetVolume)
Convenience method wrapping up all reconstructToXXX() methods.
void progress(qreal portionCompleted)
Helper class that can emit signals during calculations of a certain reconstructor.
Definition: abstractreconstructor.h:34
std::unique_ptr< ReconstructorNotifier > _notifier
The notifier object used for signal emission.
Definition: abstractreconstructor.h:241
void connectToMessageHandler(bool includeProgress)
Connects this instance's signals to the CTL's MessageHandler.
Definition: abstractreconstructor.cpp:382
bool configureAndReconstructTo(const AcquisitionSetup &setup, const ProjectionDataView &projections, VolumeType &targetVolume)
Combines the calls to configure() and reconstructTo().
void information(QString info)
QVariant toVariant() const override
Stores the contents of this instance in a QVariant.
Definition: abstractreconstructor.cpp:355
The VoxelVolume class provides a simple container for storage of voxelized 3D volume data.
Definition: ctsystemview.h:14
Holds a CTSystem together with the information about the system settings for all views from which pro...
Definition: acquisitionsetup.h:175
virtual ReconstructorNotifier * notifier()
Returns a pointer to the notifier of the reconstructor.
Definition: abstractreconstructor.cpp:315
The ProjectionDataView class is a read-only wrapper for a reference to ProjectionData.
Definition: projectiondataview.h:51
Definition: sparsevoxelvolume.h:14
Specify an interface for de-/serialization from/to QVariants.
Definition: serializationinterface.h:17
Q_REQUIRED_RESULT VolumeType reconstruct(const ProjectionDataView &projections, const VolumeType &initialVolume, bool *ok=nullptr)
Reconstructs projections into a new volume object initialized with initialVolume and returns the resu...
virtual bool reconstructToDynamic(const ProjectionDataView &projections, AbstractDynamicVolumeData &targetVolume)
Reconstruct data (in-place) from projections into volume.
Definition: abstractreconstructor.cpp:102
The AbstractReconstructor class defined the interface for reconstruction types.
Definition: abstractreconstructor.h:163
int type() const override
Definition: abstractreconstructor.h:165
void fromVariant(const QVariant &variant) override
Sets the contents of the object based on the QVariant variant.
Definition: abstractreconstructor.cpp:338
The CompositeVolume class is a container to hold multiple volume datasets of any type from the CTL.
Definition: compositevolume.h:108
virtual bool reconstructToSparse(const ProjectionDataView &projections, SparseVoxelVolume &targetVolume)
Reconstruct data (in-place) from projections into volume.
Definition: abstractreconstructor.cpp:141
virtual bool reconstructToPlain(const ProjectionDataView &projections, VoxelVolume< float > &targetVolume)
Reconstruct data (in-place) from projections into volume.
Definition: abstractreconstructor.cpp:59
virtual void configure(const AcquisitionSetup &setup)=0
Configures the reconstructor.
virtual QVariant parameter() const
Returns the parameters of this instance as a QVariant.
Definition: abstractreconstructor.cpp:164
#define CTL_TYPE_ID(newIndex)
Definition: serializationinterface.h:189
The SpectralVolumeData class holds voxelized data (for a single material) along with information on i...
Definition: spectralvolumedata.h:40
virtual bool reconstructToSpectral(const ProjectionDataView &projections, SpectralVolumeData &targetVolume)
Reconstruct data (in-place) from projections into volume.
Definition: abstractreconstructor.cpp:80
Definition: abstractdynamicvolumedata.h:14
virtual bool isApplicableTo(const AcquisitionSetup &setup) const
Returns true if the reconstruction method can be applied to data whose acquisition is described by se...
Definition: abstractreconstructor.cpp:41
virtual bool reconstructToComposite(const ProjectionDataView &projections, CompositeVolume &targetVolume)
Reconstruct data (in-place) from projections into volume.
Definition: abstractreconstructor.cpp:122
void connectNotifierToMessageHandler(bool includeProgress=false)
Connects this instance's notifier to the CTL's MessageHandler.
Definition: abstractreconstructor.cpp:327
Q_REQUIRED_RESULT VolumeType configureAndReconstruct(const AcquisitionSetup &setup, const ProjectionDataView &projections, const VolumeType &initialVolume, bool *ok=nullptr)
Combines the calls to configure() and reconstruct().