CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
vOptimizer.hh
Go to the documentation of this file.
1 /*
2 This file is part of CASToR.
3 
4  CASToR is free software: you can redistribute it and/or modify it under the
5  terms of the GNU General Public License as published by the Free Software
6  Foundation, either version 3 of the License, or (at your option) any later
7  version.
8 
9  CASToR is distributed in the hope that it will be useful, but WITHOUT ANY
10  WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11  FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
12  details.
13 
14  You should have received a copy of the GNU General Public License along with
15  CASToR (in file GNU_GPL.TXT). If not, see <http://www.gnu.org/licenses/>.
16 
17 Copyright 2017-2019 all CASToR contributors listed below:
18 
19  --> Didier BENOIT, Claude COMTAT, Marina FILIPOVIC, Thibaut MERLIN, Mael MILLARDET, Simon STUTE, Valentin VIELZEUF
20 
21 This is CASToR version 3.0.
22 */
23 
30 #ifndef VOPTIMIZER_HH
31 #define VOPTIMIZER_HH 1
32 
33 #include "gVariables.hh"
35 #include "oImageSpace.hh"
36 #include "vDataFile.hh"
37 #include "oProjectionLine.hh"
38 #include "vPenalty.hh"
39 
60 {
61  // -------------------------------------------------------------------
62  // Constructor & Destructor
63  public:
70  vOptimizer();
78  virtual ~vOptimizer();
79 
80 
81  // -------------------------------------------------------------------
82  // Public member functions
83  public:
89  void ShowHelp();
98  int CheckParameters();
107  int Initialize();
118  int UpdateVisitedVoxels();
128  int PreDataUpdateStep();
138  int PreImageUpdateStep();
139 
140 
141  // -------------------------------------------------------------------
142  // Virtual public member functions that may be overloaded by specific child optimizers
143  public:
163  virtual int DataStep1ForwardProjectModel( oProjectionLine* ap_Line, vEvent* ap_Event,
164  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
165  int a_thread );
180  virtual int DataStep2Optional( oProjectionLine* ap_Line, vEvent* ap_Event,
181  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
182  int a_thread );
200  virtual int DataStep3BackwardProjectSensitivity( oProjectionLine* ap_Line, vEvent* ap_Event,
201  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
202  int a_thread );
217  virtual int DataStep4Optional( oProjectionLine* ap_Line, vEvent* ap_Event,
218  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
219  int a_thread );
237  virtual int DataStep5ComputeCorrections( oProjectionLine* ap_Line, vEvent* ap_Event,
238  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
239  int a_thread );
254  virtual int DataStep6Optional( oProjectionLine* ap_Line, vEvent* ap_Event,
255  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
256  int a_thread );
275  virtual int DataStep7BackwardProjectCorrections( oProjectionLine* ap_Line, vEvent* ap_Event,
276  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
277  int a_thread );
292  virtual int DataStep8ComputeFOM( oProjectionLine* ap_Line, vEvent* ap_Event,
293  int a_timeFrame, int a_respGate, int a_cardGate,
294  int a_thread );
305  virtual int ImageUpdateStep();
306 
307 
308  // -----------------------------------------------------------------------------------------
309  // Virtual private member functions that may be overloaded by specific child optimizers
310  private:
319  virtual int PreDataUpdateSpecificStep();
328  virtual int PreImageUpdateSpecificStep();
329 
330  // -----------------------------------------------------------------------------------------
331  // Pure virtual public member functions that need to be implemented by child optimizers
332  public:
343  virtual int ReadConfigurationFile( const string& a_configurationFile ) = 0;
354  virtual int ReadOptionsList( const string& a_optionsList ) = 0;
355 
356 
357  // -----------------------------------------------------------------------------------------
358  // Pure virtual private member functions that need to be implemented by child optimizers
359  private:
368  virtual void ShowHelpSpecific() = 0;
377  virtual int CheckSpecificParameters() = 0;
387  virtual int InitializeSpecific() = 0;
406  virtual int SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
407  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
408  FLTNB a_quantificationFactor, oProjectionLine* ap_Line ) = 0;
428  virtual int DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
429  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
430  FLTNB a_quantificationFactor, oProjectionLine* ap_Line ) = 0;
449  virtual int ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
450  FLTNB a_sensitivity, FLTNB* ap_correctionValues, INTNB a_voxel,
451  int tbf = -1, int rbf = -1, int cbf = -1 ) = 0;
452 
453 
454  // -------------------------------------------------------------------
455  // Public Get & Set functions
456  public:
462  inline void SetVerbose(int a_verbose)
463  {m_verbose = a_verbose;}
469  inline void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification* ap_ImageDimensionsAndQuantification)
470  {mp_ImageDimensionsAndQuantification = ap_ImageDimensionsAndQuantification;}
476  inline void SetImageSpace(oImageSpace* ap_ImageSpace)
477  {mp_ImageSpace = ap_ImageSpace;}
483  inline void SetNbTOFBins(int a_nbTOFBins)
484  {m_nbTOFBins = a_nbTOFBins;}
490  inline void SetDataMode(int a_dataMode)
491  {m_dataMode = a_dataMode;}
497  inline void SetDataType(int a_dataType)
498  {m_dataType = a_dataType;}
504  inline void SetDataSpec(int a_dataSpec)
505  {m_dataSpec = a_dataSpec;}
512  inline void SetAttenuationImage(FLTNB* ap_attenuationImage, int a_thread)
513  {m2p_attenuationImage[a_thread] = ap_attenuationImage;}
519  inline void SetFOMFlag(bool a_optimizerFOMFlag)
520  {m_optimizerFOMFlag = a_optimizerFOMFlag;}
526  inline void SetImageStatFlag(bool a_optimizerImageStatFlag)
527  {m_optimizerImageStatFlag = a_optimizerImageStatFlag;}
534  inline void SetNumbersOfIterationsAndSubsets(int a_nbIterations, int* ap_nbSubsets)
535  {m_nbIterations = a_nbIterations; mp_nbSubsets = ap_nbSubsets;}
541  inline void SetCurrentIteration(int a_currentIteration)
542  {m_currentIteration = a_currentIteration;}
548  inline void SetCurrentSubset(int a_currentSubset)
549  {m_currentSubset = a_currentSubset;}
555  inline int GetNbBackwardImages()
556  {return m_nbBackwardImages;}
563  {return m_initialValue;}
569  inline void SetOptimizerID(const string& a_optimizerID)
570  {m_optimizerID = a_optimizerID;}
577  inline const string& GetOptimizerID()
578  {return m_optimizerID;}
591  inline bool GetAcceptPenalty()
598  inline void SetPenalty(vPenalty* ap_penalty)
599  {mp_Penalty = ap_penalty;}
607  {return m_needGlobalSensitivity;}
608 
609 
610  // -------------------------------------------------------------------
611  // Private member functions
612  protected:
628  FLTNB ComputeSensitivity( FLTNB**** a4p_sensitivityImage,
629  int a_timeBasisFunction, int a_respBasisFunction, int a_cardBasisFunction,
630  int a_voxel );
640  FLTNB ForwardProject( oProjectionLine* ap_Line, FLTNB* ap_image = NULL );
651  void BackwardProject( oProjectionLine* ap_Line, FLTNB* ap_image, FLTNB a_value );
652 
653  // -------------------------------------------------------------------
654  // Data members
655  protected:
656 
657  string m_optimizerID;
658  int m_verbose;
675  // Iterations/subsets
680  // Optimizer figures-of-merit computation
684  uint64_t**** m4p_FOMNbBins;
687  // Image update statistics
696  // Penalty
700 };
701 
702 
703 // ----------------------------------------------------------------------
704 // Part of code that manages the auto declaration of children classes
705 // ----------------------------------------------------------------------
706 
707 // Macro for the function that creates the object
708 #define FUNCTION_OPTIMIZER(CLASS) \
709  static vOptimizer *make_optimizer() { return new CLASS(); };
710 
711 // Macro for the class that links the appropriate function to the map of objects
712 #define CLASS_OPTIMIZER(NAME,CLASS) \
713  class NAME##OptimizerCreator \
714  { \
715  public: \
716  NAME##OptimizerCreator() \
717  { sAddonManager::GetInstance()->mp_listOfOptimizers[#NAME] = CLASS::make_optimizer; } \
718  }; \
719  static NAME##OptimizerCreator OptimizerCreator##NAME;
720 
721 #endif
void SetOptimizerID(const string &a_optimizerID)
Set the optimizer ID.
Definition: vOptimizer.hh:569
FLTNB * mp_imageStatMax
Definition: vOptimizer.hh:691
This header file is mainly used to declare some macro definitions and all includes needed from the st...
int m_requiredPenaltyDerivativesOrder
Definition: vOptimizer.hh:697
Declaration of class oImageDimensionsAndQuantification.
bool GetNeedGlobalSensitivity()
Get the boolean saying if the sensitivity has to be computed globally for all data channels and not p...
Definition: vOptimizer.hh:606
#define FLTNB
Definition: gVariables.hh:81
FLTNB m_initialValue
Definition: vOptimizer.hh:663
bool m_listmodeCompatibility
Definition: vOptimizer.hh:664
virtual int DataStep2Optional(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function which does nothing but being virtual.
Definition: vOptimizer.cc:721
void SetFOMFlag(bool a_optimizerFOMFlag)
Set the FOM flag specifying if figures-of-merit will be computed or not.
Definition: vOptimizer.hh:519
FLTNB * mp_imageStatMin
Definition: vOptimizer.hh:690
#define HPFLTNB
Definition: gVariables.hh:83
HPFLTNB **** m4p_FOMNbData
Definition: vOptimizer.hh:685
virtual int ReadConfigurationFile(const string &a_configurationFile)=0
A function used to read options from a configuration file.
oImageDimensionsAndQuantification * mp_ImageDimensionsAndQuantification
Definition: vOptimizer.hh:669
FLTNB ComputeSensitivity(FLTNB ****a4p_sensitivityImage, int a_timeBasisFunction, int a_respBasisFunction, int a_cardBasisFunction, int a_voxel)
A function used to compute the sensitivity of a given voxel and a given set of dynamic basis function...
Definition: vOptimizer.cc:1150
virtual int ImageUpdateStep()
A public function used to perform the image update step of the optimizer.
Definition: vOptimizer.cc:954
void SetCurrentIteration(int a_currentIteration)
Set the current iteration.
Definition: vOptimizer.hh:541
virtual int CheckSpecificParameters()=0
A private function used to check the parameters settings specific to the child optimizer.
vOptimizer()
The constructor of vOptimizer.
Definition: vOptimizer.cc:37
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
Set the pointer to the image dimensions in use.
Definition: vOptimizer.hh:469
FLTNB ForwardProject(oProjectionLine *ap_Line, FLTNB *ap_image=NULL)
A function used to forward project the provided image (or 1 if NULL), based on the provided oProjecti...
Definition: vOptimizer.cc:1120
uint64_t **** m4p_FOMNbBins
Definition: vOptimizer.hh:684
HPFLTNB * mp_correctionStatMean
Definition: vOptimizer.hh:694
virtual int ReadOptionsList(const string &a_optionsList)=0
A function used to read options from a list of options.
int PreDataUpdateStep()
A public function used to do stuff that need to be done at the beginning of a subset (before the data...
Definition: vOptimizer.cc:431
int m_dataMode
Definition: vOptimizer.hh:671
virtual int DataSpaceSpecificOperations(FLTNB a_data, FLTNB a_forwardModel, FLTNB *ap_backwardValues, FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue, FLTNB a_quantificationFactor, oProjectionLine *ap_Line)=0
A private function used to compute the correction term in the data space from the provided data...
int m_dataSpec
Definition: vOptimizer.hh:673
bool m_optimizerFOMFlag
Definition: vOptimizer.hh:681
void SetNbTOFBins(int a_nbTOFBins)
Set the number of TOF bins in use.
Definition: vOptimizer.hh:483
void SetDataType(int a_dataType)
Set the data type in use.
Definition: vOptimizer.hh:497
virtual int DataStep6Optional(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function which does nothing but being virtual.
Definition: vOptimizer.cc:823
INTNB * mp_imageStatNbVox
Definition: vOptimizer.hh:689
Declaration of class oProjectionLine.
int GetRequiredPenaltyDerivativesOrder()
Get the penalty derivative order needed for this algorithm.
Definition: vOptimizer.hh:584
bool m_needGlobalSensitivity
Definition: vOptimizer.hh:699
bool GetAcceptPenalty()
Get the boolean saying if the optimizer accepts penalties.
Definition: vOptimizer.hh:591
bool m_emissionCompatibility
Definition: vOptimizer.hh:666
void SetNumbersOfIterationsAndSubsets(int a_nbIterations, int *ap_nbSubsets)
Set these numbers of iterations and subsets.
Definition: vOptimizer.hh:534
int m_nbIterations
Definition: vOptimizer.hh:676
int m_nbBackwardImages
Definition: vOptimizer.hh:659
virtual int DataStep3BackwardProjectSensitivity(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function used to back-project the sensitivity terms for the provided event.
Definition: vOptimizer.cc:734
Declaration of class vDataFile.
virtual int InitializeSpecific()=0
A private function used to initialize everything specific to the child optimizer. ...
void BackwardProject(oProjectionLine *ap_Line, FLTNB *ap_image, FLTNB a_value)
A function used to backward project the provided value into the provided image, based on the provided...
Definition: vOptimizer.cc:1135
virtual int ImageSpaceSpecificOperations(FLTNB a_currentImageValue, FLTNB *ap_newImageValue, FLTNB a_sensitivity, FLTNB *ap_correctionValues, INTNB a_voxel, int tbf=-1, int rbf=-1, int cbf=-1)=0
A private function used to update the image value from the provided data.
virtual int DataStep1ForwardProjectModel(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function used to compute the model: forward projection of the provided event.
Definition: vOptimizer.cc:642
FLTNB ** m2p_attenuationImage
Definition: vOptimizer.hh:674
bool m_histogramCompatibility
Definition: vOptimizer.hh:665
bool m_optimizerImageStatFlag
Definition: vOptimizer.hh:688
Declaration of class vPenalty.
This class is designed to generically described any penalty applied to MAP algorithms.
Definition: vPenalty.hh:48
virtual int DataStep8ComputeFOM(oProjectionLine *ap_Line, vEvent *ap_Event, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function used to update the computation of figures-of-merit in the data space.
Definition: vOptimizer.cc:891
HPFLTNB **** m4p_FOMPenalty
Definition: vOptimizer.hh:686
void SetImageStatFlag(bool a_optimizerImageStatFlag)
Set the image stat flag specifying if basic statistics about image udpate will be computed or not...
Definition: vOptimizer.hh:526
void SetPenalty(vPenalty *ap_penalty)
Set the penalty of the optimizer.
Definition: vOptimizer.hh:598
HPFLTNB **** m4p_FOMRMSE
Definition: vOptimizer.hh:683
FLTNB GetInitialValue()
Get the initial image value (for initialization)
Definition: vOptimizer.hh:562
int m_currentSubset
Definition: vOptimizer.hh:679
HPFLTNB * mp_imageStatVariance
Definition: vOptimizer.hh:693
virtual ~vOptimizer()
The destructor of vOptimizer.
Definition: vOptimizer.cc:83
virtual int PreImageUpdateSpecificStep()
A private function used to perform any step required by the child optimizer, between the loop on even...
Definition: vOptimizer.cc:631
void SetDataSpec(int a_dataSpec)
Set the data physical specificity in use.
Definition: vOptimizer.hh:504
int PreImageUpdateStep()
A public function used to do stuff that need to be done between the loop over events and the image up...
Definition: vOptimizer.cc:479
#define INTNB
Definition: gVariables.hh:92
bool m_transmissionCompatibility
Definition: vOptimizer.hh:667
This class is designed to generically described any iterative optimizer.
Definition: vOptimizer.hh:59
void SetAttenuationImage(FLTNB *ap_attenuationImage, int a_thread)
Set the attenuation image corresponding to the current thread and current event.
Definition: vOptimizer.hh:512
int m_nbTOFBins
Definition: vOptimizer.hh:660
This class is designed to manage and store system matrix elements associated to a vEvent...
vPenalty * mp_Penalty
Definition: vOptimizer.hh:698
Declaration of class oImageSpace.
int m_currentIteration
Definition: vOptimizer.hh:678
void SetCurrentSubset(int a_currentSubset)
Set the current subset.
Definition: vOptimizer.hh:548
int Initialize()
A public function used to initialize the optimizer.
Definition: vOptimizer.cc:349
virtual int DataStep4Optional(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function which does nothing but being virtual.
Definition: vOptimizer.cc:774
This class holds all the matrices in the image domain that can be used in the algorithm: image...
Definition: oImageSpace.hh:60
oImageSpace * mp_ImageSpace
Definition: vOptimizer.hh:670
int m_dataType
Definition: vOptimizer.hh:672
Mother class for the Event objects.
Definition: vEvent.hh:42
virtual int DataStep5ComputeCorrections(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function used to compute the correction terms in the data space, for the provided event...
Definition: vOptimizer.cc:787
HPFLTNB * mp_imageStatMean
Definition: vOptimizer.hh:692
This class is designed to manage all dimensions and quantification related stuff. ...
int GetNbBackwardImages()
Get the number of backward images used by the specific optimizer.
Definition: vOptimizer.hh:555
int UpdateVisitedVoxels()
A public function used to update the &#39;visited&#39; voxels after each subset.
Definition: vOptimizer.cc:919
int * mp_nbSubsets
Definition: vOptimizer.hh:677
void SetVerbose(int a_verbose)
Set the verbose level.
Definition: vOptimizer.hh:462
virtual void ShowHelpSpecific()=0
A function used to show help about the child module.
virtual int SensitivitySpecificOperations(FLTNB a_data, FLTNB a_forwardModel, FLTNB *ap_weight, FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue, FLTNB a_quantificationFactor, oProjectionLine *ap_Line)=0
A private function used to compute the sensitivity weight associated to the provided data...
virtual int DataStep7BackwardProjectCorrections(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
A public function used to back-project the correction terms into the backward correction image...
Definition: vOptimizer.cc:836
void SetDataMode(int a_dataMode)
Set the data mode in use.
Definition: vOptimizer.hh:490
void ShowHelp()
A function used to show help about the optimizer.
Definition: vOptimizer.cc:233
HPFLTNB * mp_correctionStatVariance
Definition: vOptimizer.hh:695
const string & GetOptimizerID()
Definition: vOptimizer.hh:577
FLTNB ** m2p_forwardValues
Definition: vOptimizer.hh:661
HPFLTNB **** m4p_FOMLogLikelihood
Definition: vOptimizer.hh:682
FLTNB *** m3p_backwardValues
Definition: vOptimizer.hh:662
int CheckParameters()
A public function used to check the parameters settings.
Definition: vOptimizer.cc:254
virtual int PreDataUpdateSpecificStep()
A private function used to perform any step required by the child optimizer, before the loop on event...
Definition: vOptimizer.cc:468
void SetImageSpace(oImageSpace *ap_ImageSpace)
Set the pointer to the image space in use.
Definition: vOptimizer.hh:476
string m_optimizerID
Definition: vOptimizer.hh:657