CASToR  1.0
Tomographic Reconstruction (PET/SPECT)
vOptimizer.hh
Go to the documentation of this file.
00001 
00008 #ifndef VOPTIMIZER_HH
00009 #define VOPTIMIZER_HH 1
00010 
00011 #include "gVariables.hh"
00012 #include "oImageDimensionsAndQuantification.hh"
00013 #include "oImageSpace.hh"
00014 #include "vDataFile.hh"
00015 #include "oProjectionLine.hh"
00016 
00036 class vOptimizer
00037 {
00038   // -------------------------------------------------------------------
00039   // Constructor & Destructor
00040   public:
00047     vOptimizer();
00055     virtual ~vOptimizer();
00056 
00057 
00058   // -------------------------------------------------------------------
00059   // Public member functions
00060   public:
00066     void ShowHelp();
00075     int CheckParameters();
00084     int Initialize();
00096     int UpdateVisitedVoxels(oImageSpace* ap_Image);
00110     int PreDataUpdateStep(int a_iteration, int a_nbIterations, int a_subset, int a_nbSubsets);
00124     int PostDataUpdateStep(int a_iteration, int a_nbIterations, int a_subset, int a_nbSubsets);
00125 
00126 
00127   // -------------------------------------------------------------------
00128   // Virtual public member functions that may be overloaded by specific child optimizers
00129   public:
00150     virtual int DataStep1ForwardProjectModel( oProjectionLine* ap_Line, oImageSpace* ap_Image, vEvent* ap_Event,
00151                                               int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
00152                                               int a_thread );
00169     virtual int DataStep2Optional( oProjectionLine* ap_Line, oImageSpace* ap_Image, vEvent* ap_Event,
00170                                    int a_bed, int a_timeFrame, int a_respGate, int a_cardGate, int a_iteration,
00171                                    int a_thread );
00190     virtual int DataStep3BackwardProjectSensitivity( oProjectionLine* ap_Line, oImageSpace* ap_Image, vEvent* ap_Event,
00191                                                      int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
00192                                                      int a_thread );
00209     virtual int DataStep4Optional( oProjectionLine* ap_Line, oImageSpace* ap_Image, vEvent* ap_Event,
00210                                    int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
00211                                    int a_iteration, int a_thread );
00229     virtual int DataStep5ComputeCorrections( oProjectionLine* ap_Line, vEvent* ap_Event,
00230                                              int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
00231                                              int a_thread );
00248     virtual int DataStep6Optional( oProjectionLine* ap_Line, oImageSpace* ap_Image, vEvent* ap_Event,
00249                                    int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
00250                                    int a_iteration, int a_thread );
00270     virtual int DataStep7BackwardProjectCorrections( oProjectionLine* ap_Line, oImageSpace* ap_Image, vEvent* ap_Event,
00271                                                      int a_bed, int a_timeFrame, int a_respGate, int a_cardGate,
00272                                                      int a_thread );
00287     virtual int DataStep8ComputeFOM( oProjectionLine* ap_Line, vEvent* ap_Event,
00288                                      int a_timeFrame, int a_respGate, int a_cardGate,
00289                                      int a_thread );
00301     virtual int ImageUpdateStep( oImageSpace* ap_Image, int a_iteration, int a_nbSubsets );
00302 
00303 
00304   // -----------------------------------------------------------------------------------------
00305   // Virtual private member functions that may be overloaded by specific child optimizers
00306   private:
00319     virtual int PreDataUpdateSpecificStep(int a_iteration, int a_nbIterations, int a_subset, int a_nbSubsets);
00332     virtual int PostDataUpdateSpecificStep(int a_iteration, int a_nbIterations, int a_subset, int a_nbSubsets);
00333 
00334   // -----------------------------------------------------------------------------------------
00335   // Pure virtual public member functions that need to be implemented by child optimizers
00336   public:
00347     virtual int ReadConfigurationFile( const string& a_configurationFile ) = 0;
00358     virtual int ReadOptionsList( const string& a_optionsList ) = 0;
00359 
00360 
00361   // -----------------------------------------------------------------------------------------
00362   // Pure virtual private member functions that need to be implemented by child optimizers
00363   private:
00372     virtual void ShowHelpSpecific() = 0;
00381     virtual int CheckSpecificParameters() = 0;
00391     virtual int InitializeSpecific() = 0;
00409     virtual int SensitivitySpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_weight,
00410                                                FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections,
00411                                                FLTNB a_quantificationFactor, oProjectionLine* ap_Line ) = 0;
00430     virtual int DataSpaceSpecificOperations( FLTNB a_data, FLTNB a_forwardModel, FLTNB* ap_backwardValues,
00431                                              FLTNB a_multiplicativeCorrections, FLTNB a_additiveCorrections,
00432                                              FLTNB a_quantificationFactor, oProjectionLine* ap_Line ) = 0;
00450     virtual int ImageSpaceSpecificOperations( FLTNB a_currentImageValue, FLTNB* ap_newImageValue,
00451                                               FLTNB a_sensitivity, FLTNB* ap_correctionValues ) = 0;
00452 
00453 
00454   // -------------------------------------------------------------------
00455   // Public Get & Set functions
00456   public:
00462     inline void SetVerbose(int a_verbose)
00463            {m_verbose = a_verbose;}
00469     inline void SetImageDimensionsAndQuantification(oImageDimensionsAndQuantification* ap_ImageDimensionsAndQuantification)
00470            {mp_ImageDimensionsAndQuantification = ap_ImageDimensionsAndQuantification;}
00476     inline void SetNbTOFBins(int a_nbTOFBins)
00477            {m_nbTOFBins = a_nbTOFBins;}
00483     inline void SetDataMode(int a_dataMode)
00484            {m_dataMode = a_dataMode;}
00490     inline void SetDataType(int a_dataType)
00491            {m_dataType = a_dataType;}
00498     inline void SetAttenuationImage(FLTNB* ap_attenuationImage, int a_thread)
00499            {m2p_attenuationImage[a_thread] = ap_attenuationImage;}
00505     inline void SetFOMFlag(bool a_optimizerFOMFlag)
00506            {m_optimizerFOMFlag = a_optimizerFOMFlag;}
00512     inline void SetImageStatFlag(bool a_optimizerImageStatFlag)
00513            {m_optimizerImageStatFlag = a_optimizerImageStatFlag;}
00519     inline int GetNbBackwardImages()
00520            {return m_nbBackwardImages;}
00526     inline FLTNB GetInitialValue()
00527            {return m_initialValue;}
00528     /*
00529     inline bool GetAcceptPenalty()
00530            {return m_penaltyEnergyFunctionDerivativesOrder>0;}
00531     inline int GetPenaltyEnergyFunctionDerivativesOrder()
00532            {return m_penaltyEnergyFunctionDerivativesOrder;}
00533     */
00534 
00535 
00536   // -------------------------------------------------------------------
00537   // Private member functions
00538   protected:
00554     FLTNB ComputeSensitivity( FLTNB**** a4p_sensitivityImage,
00555                               int a_timeBasisFunction, int a_respBasisFunction, int a_cardBasisFunction,
00556                               int a_voxel, int a_nbSubsets );
00566     FLTNB ForwardProject( oProjectionLine* ap_Line, FLTNB* ap_image = NULL );
00577     void BackwardProject( oProjectionLine* ap_Line, FLTNB* ap_image, FLTNB a_value );
00578 
00579   // -------------------------------------------------------------------
00580   // Data members
00581   protected:
00582     int m_verbose;                         
00583     int m_nbBackwardImages;                
00584     int m_nbTOFBins;                       
00585     FLTNB** m2p_forwardValues;             
00586     FLTNB*** m3p_backwardValues;           
00587     FLTNB m_initialValue;                  
00588     bool m_listmodeCompatibility;          
00589     bool m_histogramCompatibility;         
00590     oImageDimensionsAndQuantification* 
00591       mp_ImageDimensionsAndQuantification; 
00592     int m_dataMode;                        
00593     int m_dataType;                        
00594     FLTNB** m2p_attenuationImage;          
00595     // Optimizer figures-of-merit computation
00596     bool m_optimizerFOMFlag;               
00597     FLTNB**** m4p_FOMLogLikelihood;        
00598     FLTNB**** m4p_FOMRMSE;                 
00599     uint64_t**** m4p_FOMNbBins;            
00600     double**** m4p_FOMNbData;              
00601     // Image update statistics
00602     bool m_optimizerImageStatFlag;         
00603     INTNB* mp_imageStatNbVox;              
00604     FLTNB* mp_imageStatMin;                
00605     FLTNB* mp_imageStatMax;                
00606     double* mp_imageStatMean;              
00607     double* mp_imageStatVariance;          
00608     double* mp_correctionStatMean;         
00609     double* mp_correctionStatVariance;     
00610     //int m_penaltyEnergyFunctionDerivativesOrder; /*!< The penalty derivatives order accepted by the specific optimizer (0 if none) */
00611 };
00612 
00613 
00614 // ----------------------------------------------------------------------
00615 // Part of code that manages the auto declaration of children classes
00616 // ----------------------------------------------------------------------
00617 
00618 // Macro for the function that creates the object
00619 #define FUNCTION_OPTIMIZER(CLASS) \
00620   static vOptimizer *make_optimizer() { return new CLASS(); };
00621 
00622 // Macro for the class that links the appropriate function to the map of objects
00623 #define CLASS_OPTIMIZER(NAME,CLASS)                                                           \
00624   class NAME##OptimizerCreator                                                                \
00625   {                                                                                           \
00626     public:                                                                                   \
00627       NAME##OptimizerCreator()                                                                \
00628         { sAddonManager::GetInstance()->mp_listOfOptimizers[#NAME] = CLASS::make_optimizer; } \
00629   };                                                                                          \
00630   static NAME##OptimizerCreator OptimizerCreator##NAME;
00631 
00632 #endif
 All Classes Files Functions Variables Typedefs Defines