SIVIC API  0.9.26
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
svkHSVD.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  * Bjoern Menze, Ph.D.
39  * Jason C. Crane, Ph.D.
40  * Beck Olson
41  */
42 
43 #pragma once
44 
45 #ifndef SVK_HSVD_H
46 #define SVK_HSVD_H
47 
48 
49 #include <vtkObject.h>
50 #include <vtkObjectFactory.h>
51 #include <vtkInformation.h>
52 #include <vtkStreamingDemandDrivenPipeline.h>
54 #ifdef WIN32
55 #define _USE_MATH_DEFINES
56 #include <math.h>
57 #endif
58 
59 extern "C" { // C interface
60  #include "f2c.h"
61  #undef max
62  #undef min
63  #undef small
64  #undef large
65  #undef abs
66  //#include "clapack.h"
67 }
68 
69 #include <complex>
70 
71 // For some reason including the clapack.h inside the above extern"C" block
72 // doesn't work as expected.
73 extern "C" {
74 // Here too, OsX seems to have header defs for these already which causes a definition
75 // conflict when building the OsiriX plugin
76 #ifndef SYS_F2C_OSIRIX
77  int zheev_(char *jobz, char *uplo, integer *n, doublecomplex
78  *a, integer *lda, doublereal *w, doublecomplex *work, integer *lwork,
79  doublereal *rwork, integer *info);
80  int zheevd_(char *jobz, char *uplo, integer *n,
81  doublecomplex *a, integer *lda, doublereal *w, doublecomplex *work,
82  integer *lwork, doublereal *rwork, integer *lrwork, integer *iwork,
83  integer *liwork, integer *info);
84  int zgeqp3_(integer *m, integer *n, doublecomplex *a,
85  integer *lda, integer *jpvt, doublecomplex *tau, doublecomplex *work,
86  integer *lwork, doublereal *rwork, integer *info);
87  int zungqr_(integer *m, integer *n, integer *k,
88  doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *
89  work, integer *lwork, integer *info);
90  int ztrtrs_(char *uplo, char *trans, char *diag, integer *n,
91  integer *nrhs, doublecomplex *a, integer *lda, doublecomplex *b,
92  integer *ldb, integer *info);
93  int zgeev_(char *jobvl, char *jobvr, integer *n,
94  doublecomplex *a, integer *lda, doublecomplex *w, doublecomplex *vl,
95  integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work,
96  integer *lwork, doublereal *rwork, integer *info);
97 #endif
98 }
99 
100 
101 namespace svk {
102 
103 
104 using namespace std;
105 
106 
107 
129 {
130 
131  public:
132 
134  SET_FILTER_TO_ZERO = 0, // leave input signal unchanged
135  SET_SIGNAL_TO_ZERO = 1,
136  IGNORE_ERROR = 2 // output filter image on error
137  };
138 
139  static svkHSVD* New();
140  vtkTypeMacro( svkHSVD, svkThreadedImageAlgorithm);
141 
142  void RemoveH20On();
143  void RemoveLipidOn();
144 
145  void AddPPMFrequencyFilterRule(
146  float frequencyLimit1PPM,
147  float frequencyLimit2PPM
148  );
149 
150  void AddFrequencyAndDampingFilterRule(
151  float frequencyLimit1PPM,
152  float frequencyLimit2PPM,
153  float dampingThreshold
154  );
155 
156  void AddDampingFilterRule(
157  float dampingThreshold
158  );
159  bool GetFitSuccessStatus();
160  void ExportFilterImage();
161  svkMrsImageData* GetFilterImage();
162  svkMriImageData* GetFitSuccessImage();
163  void OnlyFitSpectraInVolumeLocalization();
164  void SetModelOrder( int modelOrder );
165 
166  void SetErrorHandlingBehavior( HSVDBehaviorOnError errBehavior );
167  void SetErrorHandlingSignalToZeroOn();
168  void SetErrorHandlingFilterToZeroOn();
169  void SetErrorHandlingIgnoreError();
170 
171  void SetThresholdModelDifference( float percentDifferenceUp, float percentDifferenceDown );
172 
173  void SetSingleThreaded();
174 
175  protected:
176 
177  svkHSVD();
178  ~svkHSVD();
179 
180  virtual int FillInputPortInformation(int port, vtkInformation* info);
181 
182 
183  // Methods:
184  virtual int RequestInformation(
185  vtkInformation* request,
186  vtkInformationVector** inputVector,
187  vtkInformationVector* outputVector
188  );
189 
190 
191  virtual int RequestData(
192  vtkInformation* request,
193  vtkInformationVector** inputVector,
194  vtkInformationVector* outputVector
195  );
196 
197 
198  virtual void ThreadedRequestData(
199  vtkInformation* request,
200  vtkInformationVector** inputVector,
201  vtkInformationVector* outputVector,
202  vtkImageData*** inData,
203  vtkImageData** outData,
204  int extent[6],
205  int threadId
206  );
207  static int* progress;
208 
209 
210 
211  private:
212 
213  typedef std::complex<float> complexf;
214  typedef std::complex<double> complexd;
215  typedef std::complex<long double> complexld;
216 
217  void svkHSVDExecute(int ext[6], int id);
218  void HSVDFitCellSpectrum( int cellID );
219  bool HSVD( int cellID, vector< vector <double> >* hsvdModel );
220  void GenerateHSVDFilterModel( int cellID, vector< vector<double> >* hsvdModel, bool cellFit);
221  void SubtractFilter();
222  void CheckInputSpectralDomain();
223  void CheckOutputSpectralDomain();
224  bool CanFitSignal( const doublecomplex* signal, int numPts );
225  bool GetFilterFailStatus(
226  int cellID,
227  vtkFloatArray* filterSpec,
228  float* qfactor
229  );
230 
231  void MatMat(
232  const doublecomplex* matrix1,
233  const doublecomplex* matrix2,
234  int m,
235  int n,
236  doublecomplex* result
237  );
238 
239  void MatSq(
240  const doublecomplex* matrix,
241  int m,
242  int n,
243  doublecomplex* result
244  );
245 
246  void MatVec(
247  const doublecomplex* matrix,
248  const doublecomplex* vector,
249  int m,
250  int n,
251  doublecomplex* result
252  );
253 
254 
255  vector< vector< float > > filterRules;
256  svkMrsImageData* filterImage;
257  bool isInputInTimeDomain;
258  bool exportFilterImage;
259  bool onlyFitInVolumeLocalization;
260  int modelOrder;
261  short* selectionBoxMask;
262 
263  int numTimePoints;
264  double spectralWidth;
265  //vtkFloatArray* apodizationWindow;
266  double thresholdRMSRatioDown;
267  double thresholdRMSRatioUp;
268  int numberPtsToCheckQuality;
269  HSVDBehaviorOnError errorHandlingFlag;
270  svkMriImageData* fitSuccessMap;
271 
272 
273 };
274 
275 
276 } //svk
277 
278 
279 #endif //SVK_HSVD_H
280 
281 
282 
283 
284 
int zgeqp3_(integer *m, integer *n, doublecomplex *a, integer *lda, integer *jpvt, doublecomplex *tau, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info)
Definition: svkMrsImageData.h:66
int zheev_(char *jobz, char *uplo, integer *n, doublecomplex *a, integer *lda, doublereal *w, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info)
int ztrtrs_(char *uplo, char *trans, char *diag, integer *n, integer *nrhs, doublecomplex *a, integer *lda, doublecomplex *b, integer *ldb, integer *info)
HSVDBehaviorOnError
Definition: svkHSVD.h:133
int zheevd_(char *jobz, char *uplo, integer *n, doublecomplex *a, integer *lda, doublereal *w, doublecomplex *work, integer *lwork, doublereal *rwork, integer *lrwork, integer *iwork, integer *liwork, integer *info)
Definition: svkThreadedImageAlgorithm.h:71
Definition: svkHSVD.h:128
int zungqr_(integer *m, integer *n, integer *k, doublecomplex *a, integer *lda, doublecomplex *tau, doublecomplex *work, integer *lwork, integer *info)
Definition: svkMriImageData.h:72
static int * progress
Definition: svkHSVD.h:207
int zgeev_(char *jobvl, char *jobvr, integer *n, doublecomplex *a, integer *lda, doublecomplex *w, doublecomplex *vl, integer *ldvl, doublecomplex *vr, integer *ldvr, doublecomplex *work, integer *lwork, doublereal *rwork, integer *info)