CTL  0.6.1
Computed Tomography Library
artreconstructor.h
1 #ifndef CTL_ARTRECONSTRUCTOR_H
2 #define CTL_ARTRECONSTRUCTOR_H
3 
5 #include "abstractsubsetgenerator.h"
6 #include "acquisition/acquisitionsetup.h"
7 #include "processing/abstractvolumefilter.h"
9 #include "defaultsubsetgenerator.h"
10 
11 #include <memory>
12 
13 namespace CTL {
14 
77 {
79  Q_GADGET
80 
81 public:
83  {
85 
87  MaximumTime = 1 << 1,
92 
94  MaximumTime |
99  };
100  Q_DECLARE_FLAGS(StoppingCriteria, StoppingCriterion)
101  Q_FLAG(StoppingCriteria)
102 
104  ARTReconstructor(std::unique_ptr<AbstractProjector> forwardProjector,
105  std::unique_ptr<AbstractReconstructor> backprojector);
106  ARTReconstructor(AbstractProjector* forwardProjector,
107  AbstractReconstructor* backprojector);
108 
109  public: void configure(const AcquisitionSetup& setup) override;
110  public: bool reconstructToPlain(const ProjectionDataView& projections,
111  VoxelVolume<float>& targetVolume) override;
112  public: bool reconstructToSpectral(const ProjectionDataView& projections,
113  SpectralVolumeData& targetVolume) override;
114 public:
115  // SerializationInterface interface
116  QVariant parameter() const override;
117  void setParameter(const QVariant& parameter) override;
118  QVariant toVariant() const override;
119 
120  static float computeRelaxationEstimate(const AcquisitionSetup& setup,
121  const VoxelVolume<float>& targetVolume,
122  std::shared_ptr<AbstractProjector> forwardProjector,
123  std::shared_ptr<AbstractReconstructor> backprojector,
124  uint nbPowerIter = 1u);
125  static float computeRelaxationEstimate(const AcquisitionSetup& setup,
126  const VoxelVolume<float>& targetVolume,
127  AbstractProjector* forwardProjector = nullptr,
128  AbstractReconstructor* backprojector = nullptr,
129  uint nbPowerIter = 1u);
130 
131  // setter
132  void setPositivityConstraintEnabled(bool enabled);
133  void setRegularizationEnabled(bool enabled);
134  void setRelaxationEstimationEnabled(bool enabled);
135 
136  // relaxation setters -> deactivate automatic estimation when used
137  void setRelaxation(float relax);
138  void setRelaxationByEstimation(const VoxelVolume<float>& targetVolume,
139  uint nbPowerIter = 1u);
141  const VoxelVolume<float>& targetVolume,
142  uint nbPowerIter = 1u);
143 
144  void setRegularizer(AbstractVolumeFilter* regularizer, bool enableRegularization = true);
145  void setRegularizer(std::unique_ptr<AbstractVolumeFilter> regularizer,
146  bool enableRegularization = true);
148  void setSubsetGenerator(std::unique_ptr<AbstractSubsetGenerator> generator);
149  void setForwardProjector(std::unique_ptr<AbstractProjector> projector);
150  void setBackprojector(std::unique_ptr<AbstractReconstructor> projector);
151  void setForwardProjector(AbstractProjector* projector);
152  void setBackprojector(AbstractReconstructor* projector);
155 
156  // stopping criteria
157  void setMaxNbIterations(uint nbIt, bool enableCriterion = true);
158  void setMaxTime(float seconds, bool enableCriterion = true);
159  void setMinChangeInVolumeDomain(float minRelativeChange, bool enableCriterion = true);
160  void setMinChangeInProjectionError(float minRelativeChange, bool enableCriterion = true);
161  void setMinRelativeProjectionError(float minRelativeError, bool enableCriterion = true);
162  void setNormalEqTolerance(float relativeTol, bool enableCriterion = true);
163  void setStoppingCriteria(int criteria);
164  void setStoppingCriterionEnabled(StoppingCriterion criterion, bool enabled = true);
165 
166 
167  // getter
168  bool isCustomSubsetGeneratorInUse() const;
169  bool isDefaultSubsetGeneratorInUse() const;
170  bool isPositivityConstraintEnabled() const;
171  bool isRelaxationEstimationEnabled() const;
172  bool isRegularizationEnabled() const;
173  bool isStoppingCriterionEnabled(int criteria) const;
174  float relaxation() const;
175  int stoppingCriteria() const;
180 
181 private:
182  AcquisitionSetup _setup;
183  std::unique_ptr<AbstractProjector> _fp;
184  std::unique_ptr<AbstractReconstructor> _bp;
185  std::unique_ptr<AbstractVolumeFilter> _regularizer;
186  std::unique_ptr<AbstractSubsetGenerator> _customSubsetGen;
187  std::unique_ptr<DefaultSubsetGenerator> _defaultSubsetGen;
188  AbstractSubsetGenerator* _activeSubsetGen;
189 
190  // parameters
191  uint _maxNbIterations = 5;
192  bool _usePositivityConstraint = true;
193  bool _useRegularization = false;
194  bool _useRelaxationEstimation = true;
195  float _relax = 1.0e-6f;
196  float _terminateNormalEqTol = 0.001f;
197  float _terminateVolChange = 0.001f;
198  float _terminateProjErrChange = 0.01f;
199  float _terminateProjErrRel = 0.01f;
201  int _stoppingCriteria = MaximumNbIterations;
202 
203  bool consistencyChecks(const ProjectionDataView& projections) const;
204 
205  // stopping criteria methods
206  bool hasAnyStoppingCriterion() const;
207  bool stoppingCriterionReached(const VoxelVolume<float>& oldVol,
208  const VoxelVolume<float>& newVol,
209  float oldProjError,
210  float newProjError,
211  float inputProjNorm,
212  float normalEqNormalization,
213  int msSpent,
214  uint iteration) const;
215  bool terminateByComputationTime(int msSpent) const;
216  bool terminateByIterationCount(uint iteration) const;
217  bool terminateByProjError(float projError, float inputProjNorm) const;
218  bool terminateByProjErrorChange(float oldProjError, float newProjError) const;
219  bool terminateByVolumeChange(const VoxelVolume<float>& oldVol,
220  const VoxelVolume<float>& newVol) const;
221  bool terminateByNormalEqTol(const VoxelVolume<float>& oldVol,
222  const VoxelVolume<float>& newVol,
223  float normalization) const;
224 
225  bool reconstructData(const ProjectionDataView& projections,
226  SpectralVolumeData& targetVolume,
227  AbstractProjector& fp,
229 
230  static float computeRelaxationEstimate(const AcquisitionSetup& setup,
231  const VoxelVolume<float>& targetVolume,
232  AbstractProjector& fp,
234  uint nbPowerIter);
235  static QMetaEnum metaEnum();
236 };
237 
238 Q_DECLARE_OPERATORS_FOR_FLAGS(ARTReconstructor::StoppingCriteria)
239 
240 
246 {
247 public:
248  enum FootprintType { TR, TT, TT_Generic };
249  explicit ARTReconstructorSFP(FootprintType footprintType = TR);
250  ARTReconstructorSFP(FootprintType footprintTypeFP, FootprintType footprintTypeBP);
251 };
252 
253 namespace assist {
254 void enforcePositivity(VoxelVolume<float>& volume);
255 } // namespace assist
256 } // namespace CTL
257 
258 #endif // CTL_ARTRECONSTRUCTOR_H
void setStoppingCriterionEnabled(StoppingCriterion criterion, bool enabled=true)
Sets the use of the stopping criterion criterion to enabled.
Definition: artreconstructor.cpp:478
AbstractSubsetGenerator & customSubsetGenerator() const
Returns a reference to the current custom subset generator of this instance.
Definition: artreconstructor.cpp:696
uint _terminateMaxTime
in ms
Definition: artreconstructor.h:200
Definition: artreconstructor.h:90
void setRelaxation(float relax)
Sets the relaxation parameter to relax.
Definition: artreconstructor.cpp:384
void setForwardProjector(std::unique_ptr< AbstractProjector > projector)
Sets the forward projector to be used to projector.
Definition: artreconstructor.cpp:548
bool reconstructToPlain(const ProjectionDataView &projections, VoxelVolume< float > &targetVolume) override
Reconstructs projection data projections into targetVolume and returns true on success.
Definition: artreconstructor.cpp:85
bool terminateByProjError(float projError, float inputProjNorm) const
Returns true if the ratio between projError and inputProjNorm is less than the corresponding stopping...
Definition: artreconstructor.cpp:1030
void useDefaultSubsetGenerator()
(Re-)Enables the use of the default subset generator.
Definition: artreconstructor.cpp:613
bool isDefaultSubsetGeneratorInUse() const
Returns true if the default subset generator is in use.
Definition: artreconstructor.cpp:458
bool consistencyChecks(const ProjectionDataView &projections) const
Returns true if projections are consistent with the AcquisitionSetup previously passed to configure()...
Definition: artreconstructor.cpp:856
void setMaxNbIterations(uint nbIt, bool enableCriterion=true)
Sets the maximum number of iterations to nbIt and enables the corresponding stopping criterion if ena...
Definition: artreconstructor.cpp:283
void setPositivityConstraintEnabled(bool enabled)
Sets the use of the positivity constraint to enabled.
Definition: artreconstructor.cpp:351
bool terminateByProjErrorChange(float oldProjError, float newProjError) const
Returns true if the relative difference between oldProjError and newProjError is less than the corres...
Definition: artreconstructor.cpp:968
bool isPositivityConstraintEnabled() const
Returns true if the positivity constraint is enabled.
Definition: artreconstructor.cpp:621
static float computeRelaxationEstimate(const AcquisitionSetup &setup, const VoxelVolume< float > &targetVolume, std::shared_ptr< AbstractProjector > forwardProjector, std::shared_ptr< AbstractReconstructor > backprojector, uint nbPowerIter=1u)
Computes an estimation for a suitable relaxation parameter using the power method.
Definition: artreconstructor.cpp:722
Definition: artreconstructor.h:89
void setRelaxationEstimationEnabled(bool enabled)
Sets the use of an estimation for the relaxation parameter to enabled.
Definition: artreconstructor.cpp:373
bool terminateByComputationTime(int msSpent) const
Returns true if msSpent is greater than the corresponding stopping criterion value.
Definition: artreconstructor.cpp:989
AbstractSubsetGenerator & subsetGenerator() const
Returns a reference to the subset generator that is currently enabled.
Definition: artreconstructor.cpp:711
void setMaxTime(float seconds, bool enableCriterion=true)
Sets the maximum runtime for the reconstruction to seconds and enables the corresponding stopping cri...
Definition: artreconstructor.cpp:294
void setRegularizer(AbstractVolumeFilter *regularizer, bool enableRegularization=true)
Sets the regularizer to regularizer and enables regularization if enableRegularization = true.
Definition: artreconstructor.cpp:434
Holds a CTSystem together with the information about the system settings for all views from which pro...
Definition: acquisitionsetup.h:175
Definition: artreconstructor.h:87
The ProjectionDataView class is a read-only wrapper for a reference to ProjectionData.
Definition: projectiondataview.h:51
Definition: abstractvolumefilter.h:11
bool reconstructToSpectral(const ProjectionDataView &projections, SpectralVolumeData &targetVolume) override
Reconstructs projection data projections into targetVolume and returns true on success.
Definition: artreconstructor.cpp:120
bool isRegularizationEnabled() const
Returns true if use of the regularizer is enabled.
Definition: artreconstructor.cpp:637
static QMetaEnum metaEnum()
QMetaEnum object used to decode/encode subset order enum values.
Definition: artreconstructor.cpp:831
The AbstractProjector class is the abstract base class defining the interfaces for forward projectors...
Definition: abstractprojector.h:68
ARTReconstructor()
Constructs an ARTReconstructor that uses the default forward and backprojector.
Definition: artreconstructor.cpp:56
bool hasAnyStoppingCriterion() const
Returns true if any of the available stopping criteria is enabled.
Definition: artreconstructor.cpp:898
DefaultSubsetGenerator & defaultSubsetGenerator() const
Returns a reference to the default subset generator of this instance.
Definition: artreconstructor.cpp:498
float relaxation() const
Returns the relaxation parameter.
Definition: artreconstructor.cpp:658
void setMinRelativeProjectionError(float minRelativeError, bool enableCriterion=true)
Sets the minimum (relative) projection error to minRelativeError and enables the corresponding stoppi...
Definition: artreconstructor.cpp:327
void setParameter(const QVariant &parameter) override
Sets the parameters of this instance based on the passed QVariant parameter.
Definition: artreconstructor.cpp:1179
bool isStoppingCriterionEnabled(int criteria) const
Returns true if the stopping criterion criteria is enabled.
Definition: artreconstructor.cpp:648
The AbstractReconstructor class defined the interface for reconstruction types.
Definition: abstractreconstructor.h:163
void configure(const AcquisitionSetup &setup) override
Passes the AcquisitionSetup that describes the setting in which projections that shall be reconstruct...
Definition: artreconstructor.cpp:1094
bool reconstructData(const ProjectionDataView &projections, SpectralVolumeData &targetVolume, AbstractProjector &fp, AbstractReconstructor &bp)
Performs the iterative reconstruction of projections into targetVolume using fp and bp as forward and...
Definition: artreconstructor.cpp:192
void setBackprojector(std::unique_ptr< AbstractReconstructor > projector)
Sets the backprojector to be used to projector.
Definition: artreconstructor.cpp:559
The DefaultSubsetGenerator class is a convenience class combining the capabilities of multiple CTL su...
Definition: defaultsubsetgenerator.h:147
Definition: artreconstructor.h:93
void setMinChangeInVolumeDomain(float minRelativeChange, bool enableCriterion=true)
Sets the minimum (relative) change in volume domain to minRelativeChange and enables the correspondin...
Definition: artreconstructor.cpp:305
Definition: artreconstructor.h:84
float _terminateVolChange
relative change
Definition: artreconstructor.h:197
bool terminateByIterationCount(uint iteration) const
Returns true if iteration is greater or equal to the corresponding stopping criterion value.
Definition: artreconstructor.cpp:1010
void useCustomSubsetGenerator()
Enables the use of the (previously set) custom subset generator.
Definition: artreconstructor.cpp:598
void setMinChangeInProjectionError(float minRelativeChange, bool enableCriterion=true)
Sets the minimum (relative) change in projection domain to minRelativeChange and enables the correspo...
Definition: artreconstructor.cpp:316
The ARTReconstructor class is an implementation of the algebraic reconstruction technique that can ut...
Definition: artreconstructor.h:76
bool terminateByVolumeChange(const VoxelVolume< float > &oldVol, const VoxelVolume< float > &newVol) const
Returns true if newVol and oldVol differ by less than the corresponding stopping criterion value.
Definition: artreconstructor.cpp:910
#define CTL_TYPE_ID(newIndex)
Definition: serializationinterface.h:189
unsigned int uint
Qt style alias for unsigned int.
Definition: modulelayout.h:6
void setNormalEqTolerance(float relativeTol, bool enableCriterion=true)
Sets the minimum (relative) tolerance w.r.t the normal equation to relativeTol and enables the corres...
Definition: artreconstructor.cpp:338
bool stoppingCriterionReached(const VoxelVolume< float > &oldVol, const VoxelVolume< float > &newVol, float oldProjError, float newProjError, float inputProjNorm, float normalEqNormalization, int msSpent, uint iteration) const
Returns true if any of the enabled stopping criteria is hit.
Definition: artreconstructor.cpp:1049
The AbstractSubsetGenerator class is the abstract base class for subset generators.
Definition: abstractsubsetgenerator.h:57
float _terminateProjErrChange
relative change
Definition: artreconstructor.h:198
The SpectralVolumeData class holds voxelized data (for a single material) along with information on i...
Definition: spectralvolumedata.h:40
The ARTReconstructorSFP class is a convenience class that creates an instance of ARTReconstructor wit...
Definition: artreconstructor.h:245
QVariant toVariant() const override
Stores the contents of this instance in a QVariant.
Definition: artreconstructor.cpp:1285
int stoppingCriteria() const
Returns the combination of stopping criteria flags that are currently enabled.
Definition: artreconstructor.cpp:666
void setStoppingCriteria(int criteria)
Sets the stopping criteria to be checked after each iteration to criteria.
Definition: artreconstructor.cpp:468
void setSubsetGenerator(AbstractSubsetGenerator *generator)
Sets the subset generator to be used for subset creation to generator.
Definition: artreconstructor.cpp:519
StoppingCriterion
Definition: artreconstructor.h:82
float _terminateProjErrRel
relative error (wrt. input data)
Definition: artreconstructor.h:199
float _relax
relaxation times number of views in setup (will be divided by subset size)
Definition: artreconstructor.h:195
AbstractVolumeFilter & regularizer() const
Returns a reference to the currently set regularizer.
Definition: artreconstructor.cpp:677
bool terminateByNormalEqTol(const VoxelVolume< float > &oldVol, const VoxelVolume< float > &newVol, float normalization) const
Definition: artreconstructor.cpp:943
void setRelaxationByEstimation(const VoxelVolume< float > &targetVolume, uint nbPowerIter=1u)
Computes an estimation for the relaxation parameter and sets it for this instance.
Definition: artreconstructor.cpp:397
Definition: artreconstructor.h:88
float _terminateNormalEqTol
relative change
Definition: artreconstructor.h:196
void setRegularizationEnabled(bool enabled)
Sets the use of the regularizer to enabled.
Definition: artreconstructor.cpp:362
bool isRelaxationEstimationEnabled() const
Returns true if automatic estimation of a suitable relaxation parameter is enabled.
Definition: artreconstructor.cpp:629
QVariant parameter() const override
Returns the parameters of this instance as a QVariant.
Definition: artreconstructor.cpp:1122
Definition: artreconstructor.h:86
bool isCustomSubsetGeneratorInUse() const
Returns true if a custom subset generator is currently used to create subsets.
Definition: artreconstructor.cpp:506
Definition: artreconstructor.h:91