CASToR  3.2
Tomographic Reconstruction (PET/SPECT/CT)
include/optimizer/vOptimizer.hh
Go to the documentation of this file.
1 
8 #ifndef VOPTIMIZER_HH
9 #define VOPTIMIZER_HH 1
10 
11 #include "gVariables.hh"
12 #include "oImageDimensionsAndQuantification.hh"
13 #include "oImageSpace.hh"
14 #include "vDataFile.hh"
15 #include "oProjectionLine.hh"
16 #include "vPenalty.hh"
17 #include "oImageConvolverManager.hh"
18 
38 class vOptimizer
39 {
40  // -------------------------------------------------------------------
41  // Constructor & Destructor
42  public:
49  vOptimizer();
57  virtual ~vOptimizer();
58 
59 
60  // -------------------------------------------------------------------
61  // Public member functions
62  public:
68  void ShowHelp();
77  int CheckParameters();
86  int Initialize();
97  int UpdateVisitedVoxels();
107  int PreDataUpdateStep();
117  int PreImageUpdateStep();
118 
119 
120  // -------------------------------------------------------------------
121  // Virtual public member functions that may be overloaded by specific child optimizers
122  public:
142  virtual int DataStep1ForwardProjectModel( oProjectionLine* ap_Line, vEvent* ap_Event,
143  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
144  int a_thread );
159  virtual int DataStep2Optional( oProjectionLine* ap_Line, vEvent* ap_Event,
160  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
161  int a_thread );
179  virtual int DataStep3BackwardProjectSensitivity( oProjectionLine* ap_Line, vEvent* ap_Event,
180  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
181  int a_thread );
196  virtual int DataStep4Optional( oProjectionLine* ap_Line, vEvent* ap_Event,
197  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
198  int a_thread );
216  virtual int DataStep5ComputeCorrections( oProjectionLine* ap_Line, vEvent* ap_Event,
217  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
218  int a_thread );
233  virtual int DataStep6Optional( oProjectionLine* ap_Line, vEvent* ap_Event,
234  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
235  int a_thread );
254  virtual int DataStep7BackwardProjectCorrections( oProjectionLine* ap_Line, vEvent* ap_Event,
255  int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
256  int a_thread );
271  virtual int DataStep8ComputeFOM( oProjectionLine* ap_Line, vEvent* ap_Event,
272  int a_timeFrame, int a_respGate, int a_cardGate,
273  int a_thread );
284  virtual int ImageUpdateStep();
285 
286 
287  // -----------------------------------------------------------------------------------------
288  // Virtual private member functions that may be overloaded by specific child optimizers
289  private:
298  virtual int PreDataUpdateSpecificStep();
307  virtual int PreImageUpdateSpecificStep();
308 
309  // -----------------------------------------------------------------------------------------
310  // Pure virtual public member functions that need to be implemented by child optimizers
311  public:
322  virtual int ReadConfigurationFile( const string& a_configurationFile ) = 0;
333  virtual int ReadOptionsList( const string& a_optionsList ) = 0;
334 
335 
336  // -----------------------------------------------------------------------------------------
337  // Pure virtual private member functions that need to be implemented by child optimizers
338  private:
347  virtual void ShowHelpSpecific() = 0;
356  virtual int CheckSpecificParameters() = 0;
366  virtual int InitializeSpecific() = 0;
385  virtual int SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
386  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
387  FLTNB a_quantificationFactor, oProjectionLine* ap_Line ) = 0;
407  virtual int DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
408  FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections, FLTNB a_blankValue,
409  FLTNB a_quantificationFactor, oProjectionLine* ap_Line ) = 0;
428  virtual int ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
429  FLTNB a_sensitivity, FLTNB* ap_correctionValues, INTNB a_voxel,
430  int tbf = -1, int rbf = -1, int cbf = -1 ) = 0;
431 
432 
433  // -------------------------------------------------------------------
434  // Public Get & Set functions
435  public:
441  inline void SetVerbose(int a_verbose)
442  {m_verbose = a_verbose;}
448  inline void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification* ap_ImageDimensionsAndQuantification)
449  {mp_ImageDimensionsAndQuantification = ap_ImageDimensionsAndQuantification;}
455  inline void SetImageSpace(oImageSpace* ap_ImageSpace)
456  {mp_ImageSpace = ap_ImageSpace;}
462  inline void SetDataFile(vDataFile* ap_DataFile)
463  {mp_DataFile = ap_DataFile;}
469  inline void SetNbTOFBins(int a_nbTOFBins)
470  {m_nbTOFBins = a_nbTOFBins;}
476  inline void SetDataMode(int a_dataMode)
477  {m_dataMode = a_dataMode;}
483  inline void SetDataType(int a_dataType)
484  {m_dataType = a_dataType;}
490  inline void SetDataSpec(int a_dataSpec)
491  {m_dataSpec = a_dataSpec;}
498  inline void SetAttenuationImage(FLTNB* ap_attenuationImage, int a_thread)
499  {m2p_attenuationImage[a_thread] = ap_attenuationImage;}
505  inline void SetFOMFlag(bool a_optimizerFOMFlag)
506  {m_optimizerFOMFlag = a_optimizerFOMFlag;}
512  inline void SetImageStatFlag(bool a_optimizerImageStatFlag)
513  {m_optimizerImageStatFlag = a_optimizerImageStatFlag;}
520  inline void SetNumbersOfIterationsAndSubsets(int a_nbSubIterationsTotal, int* ap_nbSubsets)
521  {m_nbSubIterationsTotal = a_nbSubIterationsTotal; mp_nbSubsets = ap_nbSubsets;}
527  inline void SetOutputIterations(bool* ap_outputIterations)
528  {mp_outputIterations = ap_outputIterations;}
534  void SetCurrentIteration(int a_currentTotalSubIteration);
548  inline void SetImageConvolverManager(oImageConvolverManager* ap_ImageConvolverManager)
549  {mp_ImageConvolverManager = ap_ImageConvolverManager;}
555  inline void SetCurrentSubset(int a_currentSubset)
556  {m_currentSubset = a_currentSubset;}
562  inline int GetNbBackwardImages()
563  {return m_nbBackwardImages;}
570  {return m_initialValue;}
576  inline void SetOptimizerID(const string& a_optimizerID)
577  {m_optimizerID = a_optimizerID;}
584  inline const string& GetOptimizerID()
585  {return m_optimizerID;}
598  inline bool GetAcceptPenalty()
605  inline void SetPenalty(vPenalty* ap_penalty)
606  {mp_Penalty = ap_penalty;}
614  {return m_needGlobalSensitivity;}
619  inline void EnterPreIteration()
620  {m_isInPreIteration = true;}
625  inline void ExitPreIteration()
626  {m_isInPreIteration = false;}
632  inline bool NeedPreIteration()
633  {return m_needPreIteration;}
638  inline void EnterPostIteration()
639  {m_isInPostIteration = true;}
644  inline void ExitPostIteration()
645  {m_isInPostIteration = false;}
651  inline bool NeedPostIteration()
652  {return m_needPostIteration;}
653 
654 
655 
656  // -------------------------------------------------------------------
657  // Private member functions
658  protected:
674  FLTNB ComputeSensitivity( FLTNB**** a4p_sensitivityImage,
675  int a_timeBasisFunction, int a_respBasisFunction, int a_cardBasisFunction,
676  int a_voxel );
686  FLTNB ForwardProject( oProjectionLine* ap_Line, FLTNB* ap_image = NULL );
697  void BackwardProject( oProjectionLine* ap_Line, FLTNB* ap_image, FLTNB a_value );
698 
699  // -------------------------------------------------------------------
700  // Data members
701  protected:
702 
703  string m_optimizerID;
704  int m_verbose;
705  int m_nbBackwardImages;
706  int m_nbTOFBins;
719  int m_dataMode;
720  int m_dataType;
721  int m_dataSpec;
723  // Iterations/subsets
724  int m_nbIterations;
729  int* mp_nbSubsets;
731  int m_currentIteration;
735  int m_currentSubset;
736  // Processing pre- and post-iteration loop
741  // Optimizer figures-of-merit computation
742  bool m_optimizerFOMFlag;
744  HPFLTNB**** m4p_FOMRMSE;
745  uint64_t**** m4p_FOMNbBins;
746  HPFLTNB**** m4p_FOMNbData;
747  HPFLTNB**** m4p_FOMPenalty;
748  // Image update statistics
757  // Penalty
761 };
762 
763 
764 // ----------------------------------------------------------------------
765 // Part of code that manages the auto declaration of children classes
766 // ----------------------------------------------------------------------
767 
768 // Macro for the function that creates the object
769 #define FUNCTION_OPTIMIZER(CLASS) \
770  static vOptimizer *make_optimizer() { return new CLASS(); };
771 
772 // Macro for the class that links the appropriate function to the map of objects
773 #define CLASS_OPTIMIZER(NAME,CLASS) \
774  class NAME##OptimizerCreator \
775  { \
776  public: \
777  NAME##OptimizerCreator() \
778  { sAddonManager::GetInstance()->mp_listOfOptimizers[#NAME] = CLASS::make_optimizer; } \
779  }; \
780  static NAME##OptimizerCreator OptimizerCreator##NAME;
781 
782 #endif
virtual int ReadConfigurationFile(const string &a_configurationFile)=0
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
This class is designed to be a mother virtual class for DataFile.
void ExitPostIteration()
Set post-process flag to false.
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
void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification *ap_ImageDimensionsAndQuantification)
virtual int DataStep2Optional(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void EnterPostIteration()
Set post-process flag to true.
void ExitPreIteration()
Set pre-process flag to false.
oImageDimensionsAndQuantification * mp_ImageDimensionsAndQuantification
FLTNB ComputeSensitivity(FLTNB ****a4p_sensitivityImage, int a_timeBasisFunction, int a_respBasisFunction, int a_cardBasisFunction, int a_voxel)
virtual int ImageUpdateStep()
A public function used to perform the image update step of the optimizer.
void SetImageConvolverManager(oImageConvolverManager *ap_ImageConvolverManager)
Set the Image Convolver Manager Object.
virtual int CheckSpecificParameters()=0
A private function used to check the parameters settings specific to the child optimizer.
vOptimizer()
The constructor of vOptimizer.
void SetDataType(int a_dataType)
FLTNB ForwardProject(oProjectionLine *ap_Line, FLTNB *ap_image=NULL)
int PreDataUpdateStep()
A public function used to do stuff that need to be done at the beginning of a subset (before the data...
void SetFOMFlag(bool a_optimizerFOMFlag)
void SetImageSpace(oImageSpace *ap_ImageSpace)
virtual int DataStep6Optional(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void SetAttenuationImage(FLTNB *ap_attenuationImage, int a_thread)
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
virtual int DataStep3BackwardProjectSensitivity(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
virtual int InitializeSpecific()=0
A private function used to initialize everything specific to the child optimizer. ...
void SetOutputIterations(bool *ap_outputIterations)
Set the selected output iterations.
void BackwardProject(oProjectionLine *ap_Line, FLTNB *ap_image, FLTNB a_value)
int GetNbSubIterationsInOneIteration()
Get the number of sub iterations in one iteration.
void SetOptimizerID(const string &a_optimizerID)
virtual int DataStep1ForwardProjectModel(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void SetDataMode(int a_dataMode)
This class is designed to manage the different image convolvers and to apply them.
This class is designed to generically described any penalty applied to MAP algorithms.
virtual int DataStep8ComputeFOM(oProjectionLine *ap_Line, vEvent *ap_Event, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void SetNbTOFBins(int a_nbTOFBins)
bool NeedPostIteration()
Say if the optimizer needs a post-process loop after iterations are done.
void SetDataFile(vDataFile *ap_DataFile)
Set the data file in use.
void SetVerbose(int a_verbose)
virtual ~vOptimizer()
The destructor of vOptimizer.
virtual int PreImageUpdateSpecificStep()
A private function used to perform any step required by the child optimizer, between the loop on even...
int PreImageUpdateStep()
A public function used to do stuff that need to be done between the loop over events and the image up...
This class is designed to generically described any iterative optimizer.
void EnterPreIteration()
Set pre-process flag to true.
This class is designed to manage and store system matrix elements associated to a vEvent...
void SetImageStatFlag(bool a_optimizerImageStatFlag)
Declaration of class vPenalty.
int Initialize()
A public function used to initialize the optimizer.
virtual int DataStep4Optional(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
This class holds all the matrices in the image domain that can be used in the algorithm: image...
Mother class for the Event objects.
virtual int DataStep5ComputeCorrections(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void SetCurrentIteration(int a_currentIteration)
void SetCurrentSubset(int a_currentSubset)
This class is designed to manage all dimensions and quantification related stuff. ...
int UpdateVisitedVoxels()
A public function used to update the 'visited' voxels after each subset.
void SetDataSpec(int a_dataSpec)
virtual void ShowHelpSpecific()=0
A function used to show help about the child module.
virtual int DataStep7BackwardProjectCorrections(oProjectionLine *ap_Line, vEvent *ap_Event, int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_thread)
void ShowHelp()
A function used to show help about the optimizer.
void SetPenalty(vPenalty *ap_penalty)
const string & GetOptimizerID()
bool NeedPreIteration()
Say if the optimizer needs a pre-process loop before iterations are done.
int CheckParameters()
A public function used to check the parameters settings.
oImageConvolverManager * mp_ImageConvolverManager
virtual int PreDataUpdateSpecificStep()
A private function used to perform any step required by the child optimizer, before the loop on event...
void SetNumbersOfIterationsAndSubsets(int a_nbSubIterationsTotal, int *ap_nbSubsets)
virtual int ReadOptionsList(const string &a_optionsList)=0