SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svkMRSZeroOrderPhaseCostFunction.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2009-2014 The Regents of the University of California.
3  * All Rights Reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * • Redistributions of source code must retain the above copyright notice,
8  * this list of conditions and the following disclaimer.
9  * • Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * • None of the names of any campus of the University of California, the name
13  * "The Regents of the University of California," or the names of any of its
14  * contributors may be used to endorse or promote products derived from this
15  * software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  * IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
21  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
23  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
24  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
26  * OF SUCH DAMAGE.
27  */
28 
29 
30 
31 /*
32  * $URL$
33  * $Rev$
34  * $Author$
35  * $Date$
36  *
37  * Authors:
38  * Jason C. Crane, Ph.D.
39  * Beck Olson,
40  */
41 
42 #ifndef SVK_MRS_ZERO_ORDER_PHASE_COST_FUNCTION_H
43 #define SVK_MRS_ZERO_ORDER_PHASE_COST_FUNCTION_H
44 
45 
46 #include <svkPhaseCostFunction.h>
47 #include <svkMRSPeakPick.h>
48 #include <svkMetaboliteMap.h>
49 
50 
51 using namespace svk;
52 
53 
54 /*
55  * Cost function for ITK optimizer:
56  */
58 {
59 
60  public:
61 
64  typedef itk::SmartPointer<Self> Pointer;
65  typedef itk::SmartPointer<const Self> ConstPointer;
66 
67 
69 
70  itkNewMacro( Self );
71 
72 
74  this->zeroOrderPhasePeak = 0;
75  }
76 
77 
83  {
84 
85  double phi0 = parameters[0];
86 
87  double intensity = 0;
88  float cmplxPt[2];
89  double tmp;
90 
91  // Get the sum of the peak hits for picked peaks:
92  // maximize positive peak height (minimize negative peak ht)
93  for ( int peakNum = 0; peakNum < this->peaks->GetNumPeaks(); peakNum++ ) {
94 
95  int startPt;
96  int endPt;
97  int peakPt;
98  this->peaks->GetPeakDefinition( peakNum, &startPt, &peakPt, &endPt );
99 
100  // apply zero order phase to data in window, then get peak ht:
101  for ( int freq = startPt; freq <= endPt; freq++) {
102  this->copySpectrum->GetTupleValue(freq, cmplxPt);
103  svk::svkPhaseSpec::ZeroOrderPhase(phi0, cmplxPt);
104  this->copySpectrum->SetTuple(freq, cmplxPt);
105  }
106  float peakHt = svkMetaboliteMap::GetPeakHt(
107  static_cast<float*>(this->copySpectrum->GetVoidPointer(4)),
108  startPt,
109  endPt
110  );
111  cout << "PEAK HT: " << peakHt << " @ " << phi0 * 180. / vtkMath::Pi() << endl;
112  intensity += (-1 * peakHt);
113  }
114 
115  MeasureType measure = intensity;
116  return measure;
117  }
118 
119 
120  /*
121  * returns the cost function for the current param values:
122  * typedef double MeasureType
123  */
124  virtual MeasureType GetValue( const ParametersType & parameters ) const
125  {
126 
127  double cost;
128 
129  // make a member variable (copy)
130  //cout << "copy spectrum" << endl;
131  this->copySpectrum->DeepCopy(this->spectrum);
132  cost = GetZeroOrderPhaseCost_2( parameters );
133 
134  MeasureType measure = cost;
135  //cout << " cost: " << measure << endl;
136  return measure;
137  }
138 
139 
140  /*
141  *
142  */
143  virtual unsigned int GetNumberOfParameters(void) const
144  {
145  return 1;
146  }
147 
148 
150  {
151  this->peaks = peaks;
152  }
153 
154 
155  /*
156  *
157  */
158  void SetZeroOrderPhasePeak( int peakNum)
159  {
160  this->zeroOrderPhasePeak = peakNum;
161  }
162 
163 
164  /*
165  *
166  */
168  {
169  return this->zeroOrderPhasePeak;
170  }
171 
172 
173 
174 
175 
176  private:
177  svkMRSPeakPick* peaks;
178  int zeroOrderPhasePeak;
179 
180 };
181 
182 
183 
184 #endif// SVK_MRS_ZERO_ORDER_PHASE_COST_FUNCTION_H
virtual MeasureType GetValue(const ParametersType &parameters) const
Definition: svkMRSZeroOrderPhaseCostFunction.h:124
static double GetPeakHt(float *specPtr, int startPt, int endPt)
Definition: svkMetaboliteMap.cc:360
Definition: svkPhaseCostFunction.h:64
itk::SmartPointer< Self > Pointer
Definition: svkMRSZeroOrderPhaseCostFunction.h:64
MeasureType GetZeroOrderPhaseCost_2(const ParametersType &parameters) const
Definition: svkMRSZeroOrderPhaseCostFunction.h:82
Superclass::MeasureType MeasureType
Definition: svkPhaseCostFunction.h:79
void SetZeroOrderPhasePeak(int peakNum)
Definition: svkMRSZeroOrderPhaseCostFunction.h:158
Definition: svkMRSZeroOrderPhaseCostFunction.h:57
Definition: svkMRSPeakPick.h:69
svkMRSZeroOrderPhaseCostFunction()
Definition: svkMRSZeroOrderPhaseCostFunction.h:73
void SetPeakPicker(svkMRSPeakPick *peaks)
Definition: svkMRSZeroOrderPhaseCostFunction.h:149
svkPhaseCostFunction Superclass
Definition: svkMRSZeroOrderPhaseCostFunction.h:63
int GetZeroOrderPhasePeak()
Definition: svkMRSZeroOrderPhaseCostFunction.h:167
static void ZeroOrderPhase(float phi0, float *cmplxPt)
Definition: svkPhaseSpec.cc:339
Superclass::ParametersType ParametersType
Definition: svkPhaseCostFunction.h:77
itk::SmartPointer< const Self > ConstPointer
Definition: svkMRSZeroOrderPhaseCostFunction.h:65
virtual unsigned int GetNumberOfParameters(void) const
Definition: svkMRSZeroOrderPhaseCostFunction.h:143
svkMRSZeroOrderPhaseCostFunction Self
Definition: svkMRSZeroOrderPhaseCostFunction.h:62