CASToR  3.0
Tomographic Reconstruction (PET/SPECT/CT)
iPenaltyTemplate.cc
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 #include "iPenaltyTemplate.hh"
31 
32 // =====================================================================
33 // ---------------------------------------------------------------------
34 // ---------------------------------------------------------------------
35 // =====================================================================
36 
38 {
39  // ---------------------------
40  // Mandatory member parameters
41  // (inherited from vPenalty)
42  // ---------------------------
43 
44  // Specify here the derivative order of the penalty.
45  // Most algorithms able to handle penalties require 1 derivative,
46  // and some 2 derivatives. If infinite, then set INT_MAX.
47  m_penaltyDerivativesOrder = INT_MAX;
48 
49  // --------------------------
50  // Specific member parameters
51  // --------------------------
52 
53  // Set here the default values of the parameters specific to this optimizer
54 
55 }
56 
57 // =====================================================================
58 // ---------------------------------------------------------------------
59 // ---------------------------------------------------------------------
60 // =====================================================================
61 
63 {
64  // Delete or free ONLY things that were built into this class
65 }
66 
67 // =====================================================================
68 // ---------------------------------------------------------------------
69 // ---------------------------------------------------------------------
70 // =====================================================================
71 
73 {
74  cout << "This penalty is only a squeleton template to explain how to add a penalty into CASToR. If you" << endl;
75  cout << "want to implement your own penalty, start from here and look at the specific documentation." << endl;
76 }
77 
78 // =====================================================================
79 // ---------------------------------------------------------------------
80 // ---------------------------------------------------------------------
81 // =====================================================================
82 
83 int iPenaltyTemplate::ReadConfigurationFile(const string& a_configurationFile)
84 {
85  // This function is designed to read parameters specific to the optimizer through a configuration file.
86  // To do that, use the ReadDataASCIIFile() function, and take a look at other optimizers to see how it is done.
87  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
88  // Return 1 if any problem. See other penalties' implementation to get guidance.
89 
90  // Normal end
91  return 0;
92 }
93 
94 // =====================================================================
95 // ---------------------------------------------------------------------
96 // ---------------------------------------------------------------------
97 // =====================================================================
98 
99 int iPenaltyTemplate::ReadOptionsList(const string& a_optionsList)
100 {
101  // This function is designed to read parameters specific to the optimizer through a list of options in a string.
102  // To do that, use the ReadStringOption() function, and take a look at other optimizers to see how it is done.
103  // Do not check the parameters' values, the CheckSpecificParameters() function is designed to do that.
104  // Return 1 if any problem. See other penalties' implementation to get guidance.
105 
106  // Normal end
107  return 0;
108 }
109 
110 // =====================================================================
111 // ---------------------------------------------------------------------
112 // ---------------------------------------------------------------------
113 // =====================================================================
114 
116 {
117  // This function is designed to check that all parameters specific to the optimizer have been set properly.
118  // Return 1 if any problem.
119 
120  // Normal end
121  return 0;
122 }
123 
124 // =====================================================================
125 // ---------------------------------------------------------------------
126 // ---------------------------------------------------------------------
127 // =====================================================================
128 
130 {
131  // Verbose
132  if (m_verbose>=2) Cout("iOptimizerTemplate::InitializeSpecific() -> Use the template optimizer" << endl);
133 
134  // This function is designed to initialize everything that should be initialized before being able to launch the iteration.
135  // Return 1 if any problem.
136 
137  // Normal end
138  return 0;
139 }
140 
141 // =====================================================================
142 // ---------------------------------------------------------------------
143 // ---------------------------------------------------------------------
144 // =====================================================================
145 
146 FLTNB iPenaltyTemplate::ComputePenaltyValue(int a_tbf, int a_rbf, int a_cbf, INTNB a_voxel, int a_th)
147 {
148  // This is where you must implement the computation of the penalty value, for the provided parameters.
149  // It is used to compute the overall cost function.
150  // This function is called inside a parallel loop. The index of the thread is provided.
151  // See other penalties' implementation to get guidance.
152  FLTNB penalty = 0.;
153  return penalty;
154 }
155 
156 // =====================================================================
157 // ---------------------------------------------------------------------
158 // ---------------------------------------------------------------------
159 // =====================================================================
160 
161 FLTNB iPenaltyTemplate::ComputeFirstDerivative(int a_tbf, int a_rbf, int a_cbf, INTNB a_voxel, int a_th)
162 {
163  // This is where you must implement the computation of the penalty's first derivative value, for the
164  // provided parameters. It is used by the optimizer to compute the next update.
165  // This function is called inside a parallel loop. The index of the thread is provided.
166  // See other penalties' implementation to get guidance.
167  FLTNB first_derivative = 0.;
168  return first_derivative;
169 }
170 
171 
172 // =====================================================================
173 // ---------------------------------------------------------------------
174 // ---------------------------------------------------------------------
175 // =====================================================================
176 
177 FLTNB iPenaltyTemplate::ComputeSecondDerivative(int a_tbf, int a_rbf, int a_cbf, INTNB a_voxel, int a_th)
178 {
179  // This is where you must implement the computation of the penalty's second derivative value, for the
180  // provided parameters. It may be used by the optimizer to compute the next update.
181  // If the penalty does not admit a second derivative, then just let the function as is.
182  // This function is called inside a parallel loop. The index of the thread is provided.
183  // See other penalties' implementation to get guidance.
184  FLTNB second_derivative = 0.;
185  return second_derivative;
186 }
int ReadOptionsList(const string &a_optionsList)
A function used to read options from a list of options.
int m_penaltyDerivativesOrder
Definition: vPenalty.hh:293
#define FLTNB
Definition: gVariables.hh:81
int ReadConfigurationFile(const string &a_configurationFile)
A function used to read options from a configuration file.
FLTNB ComputePenaltyValue(int a_tbf, int a_rbf, int a_cbf, INTNB a_voxel, int a_th)
Implementation of the pure virtual vPenalty::ComputePenaltyValue()
void ShowHelpSpecific()
A function used to show help about the child penalty.
int InitializeSpecific()
This function is used to initialize specific stuff to the child penalty.
int m_verbose
Definition: vPenalty.hh:291
int CheckSpecificParameters()
A private function used to check the parameters settings specific to the child penalty.
~iPenaltyTemplate()
The destructor of iPenaltyTemplate.
FLTNB ComputeFirstDerivative(int a_tbf, int a_rbf, int a_cbf, INTNB a_voxel, int a_th)
Implementation of the pure virtual vPenalty::ComputeFirstDerivative()
This class is designed to generically described any penalty applied to MAP algorithms.
Definition: vPenalty.hh:48
Declaration of class iPenaltyTemplate.
FLTNB ComputeSecondDerivative(int a_tbf, int a_rbf, int a_cbf, INTNB a_voxel, int a_th)
Implementation of the pure virtual vPenalty::ComputeSecondDerivative()
#define INTNB
Definition: gVariables.hh:92
iPenaltyTemplate()
The constructor of iPenaltyTemplate.
#define Cout(MESSAGE)