cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nmrCallBack.h
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ex: set filetype=cpp softtabstop=4 shiftwidth=4 tabstop=4 cindent expandtab: */
3 
4 /*
5 
6  Author(s): Ankur Kapoor
7  Created on: 2004-10-26
8 
9  (C) Copyright 2004-2007 Johns Hopkins University (JHU), All Rights
10  Reserved.
11 
12 --- begin cisst license - do not edit ---
13 
14 This software is provided "as is" under an open source license, with
15 no warranty. The complete license can be found in license.txt and
16 http://www.cisst.org/cisst/license.txt.
17 
18 --- end cisst license ---
19 */
20 
21 
26 #ifndef _nmrCallBackLSNonLinSolver_h
27 #define _nmrCallBackLSNonLinSolver_h
28 
29 
34 
36 
37 #define nmrUNIQUE_IDENTIFIER_LINE ( __LINE__ + 0x0000 )
38 #if CISST_OS == CISST_WINDOWS
39 #define CISST_DECLSPEC_THREAD __declspec( thread )
40 #else
41 #define CISST_DECLSPEC_THREAD
42 #endif
43 
44 template <int _instanceLine, class _elementType>
46 protected:
47  _elementType *Object;
48  int (_elementType::*MethodPointer)(vctDynamicVectorRef<double> &X,
49  vctDynamicVectorRef<double> &Y, long int &Flag);
51 public:
54  }
55  nmrCallBackFunctionF(_elementType *obj, int (_elementType::*methodPointer)
57  vctDynamicVectorRef<double> &Y, long int &Flag)):Object(obj),
58  MethodPointer(methodPointer) {
60  }
61  void Set(_elementType *obj, int (_elementType::*methodPointer)
63  vctDynamicVectorRef<double> &Y, long int &Flag)) {
64  Object = obj;
65  MethodPointer = methodPointer;
67  }
68  /* static function to be passed to lmdif */
69  static int FunctionFlmdif (long int *m, long int *n, double *x, double *fvec,
70  long int *iflag) {
71  if (nmrCallBackFunctionF::This != NULL) {
72  vctDynamicVectorRef<double> XRef(*n, x);
73  vctDynamicVectorRef<double> FRef(*m, fvec);
74  return (This->Object->*This->MethodPointer)(XRef, FRef, *iflag);
75  }
76  return -1;
77  }
78  /* static function to be passed to hybrd */
79  static int FunctionFhybrd (long int *n, double *x, double *fvec,
80  long int *iflag) {
81  if (nmrCallBackFunctionF::This != NULL) {
82  vctDynamicVectorRef<double> XRef(*n, x);
83  vctDynamicVectorRef<double> FRef(*n, fvec);
84  return (This->Object->*This->MethodPointer)(XRef, FRef, *iflag);
85  }
86  return -1;
87  }
88  /* static function to be passed to donlp2 */
89  static int FunctionFdonlp2 (long int *n, double x[], double fgraf[]) {
90  static long int iflag = 0;
91  if (nmrCallBackFunctionF::This != NULL) {
92  vctDynamicVectorRef<double> XRef(*n, x);
93  vctDynamicVectorRef<double> FRef(*n, fgraf);
94  return (This->Object->*This->MethodPointer)(XRef, FRef, iflag);
95  }
96  return -1;
97  }
98 };
99 
100 #ifndef DOXYGEN
101 template <int _instanceLine, class _elementType>
103 #endif // DOXYGEN
104 
105 template <int _instanceLine, class _elementType>
107 protected:
108  /* pointer to object that contains the method to be called */
109  _elementType* Object;
110 
111  /* pointer to method that needs to be called */
113  vctDynamicVectorRef<double> &J, long int &Flag);
114 
115  /* a static pointer to this object. Note only one type of this can be created.
116  uniqueness is ensured by modifying the template parameter
117  */
119 public:
120 
121  /* constructor */
122  /* default */
125  }
126  nmrCallBackFunctionJ (_elementType* obj, int (_elementType::*methodPointer)(vctDynamicVectorRef<double> &X,
127  vctDynamicVectorRef<double> &J, long int &Flag)):
128  Object(obj), MethodPointer(methodPointer) {
130  }
131 
132  /* set value other than constructor */
133  void Set(_elementType* obj, int (_elementType::*methodPointer)(vctDynamicVectorRef<double> &X,
134  vctDynamicVectorRef<double> &J, long int &Flag)) {
135  Object = obj;
136  MethodPointer = methodPointer;
138  }
139 
140  /* static function to be passed to hybrj2 */
141  static int FunctionFhybrj2 (long int *n, double *x, double *fdjac,
142  long int *ldfjac, long int *iflag) {
143  if (nmrCallBackFunctionJ::This != NULL) {
144  vctDynamicVectorRef<double> XRef(*n, x);
145  vctDynamicVectorRef<double> JRef((*ldfjac)*(*n), fdjac);
146  return (This->Object->*This->MethodPointer)(XRef, JRef, *iflag);
147  }
148  return -1;
149  }
150 
151  /* static function to be passed to hybrj2 */
152  static int FunctionFlmder2 (long int *m, long int *n, double *x, double *fdjac,
153  long int *ldfjac, long int *iflag) {
154  if (nmrCallBackFunctionJ::This != NULL) {
155  vctDynamicVectorRef<double> XRef(*n, x);
156  vctDynamicVectorRef<double> JRef((*ldfjac)*(*n), fdjac);
157  return (This->Object->*This->MethodPointer)(XRef, JRef, *iflag);
158  }
159  return -1;
160  }
161 };
162 
163 #ifndef DOXYGEN
164 template <int _instanceLine, class _elementType>
166 #endif // DOXYGEN
167 
168 template <int _instanceLine, class _elementType>
170 protected:
171  _elementType *Object;
172  void (_elementType::*MethodPointer)(vctDynamicVectorRef<double> &X, double *F);
174 public:
177  }
178  nmrCallBackFunctionF1(_elementType *obj, void (_elementType::*methodPointer)
179  (vctDynamicVectorRef<double> &X, double *F)):Object(obj),
180  MethodPointer(methodPointer) {
182  }
183  void Set(_elementType *obj, void (_elementType::*methodPointer)
184  (vctDynamicVectorRef<double> &X, double *F)) {
185  Object = obj;
186  MethodPointer = methodPointer;
188  }
189  /* static function to be passed to donlp2 */
190  static void FunctionFdonlp2 (int n, double x[], double *fx) {
191  if (nmrCallBackFunctionF1::This != NULL) {
192  vctDynamicVectorRef<double> XRef(n+1, x);
193  (This->Object->*This->MethodPointer)(XRef, fx);
194  }
195  }
196 };
197 
198 #ifndef DOXYGEN
199 template <int _instanceLine, class _elementType>
201 #endif // DOXYGEN
202 
203 template <int _instanceLine, class _elementType>
205 protected:
206  _elementType *Object;
207  void (_elementType::*MethodPointer)(int Type, vctDynamicVectorRef<int> &ListE,
211 public:
214  }
215  nmrCallBackFunctionC(_elementType *obj, void (_elementType::*methodPointer)
216  (int Type, vctDynamicVectorRef<int> &ListE,
218  vctDynamicVectorRef<int> &Err)):Object(obj),
219  MethodPointer(methodPointer) {
221  }
222  void Set(_elementType *obj, void (_elementType::*methodPointer)
223  (int Type, vctDynamicVectorRef<int> &ListE,
225  vctDynamicVectorRef<int> &Err)) {
226  Object = obj;
227  MethodPointer = methodPointer;
229  }
230  /* static function to be passed to donlp2 */
231  static void FunctionFdonlp2 (int n, int nonlin, int type ,int liste[],
232  double x[],double con[], int err[]) {
233  if (nmrCallBackFunctionC::This != NULL) {
234  vctDynamicVectorRef<double> XRef(n+1, x);
235  vctDynamicVectorRef<double> ConRef(nonlin+1, con);
236  vctDynamicVectorRef<int> ListERef(liste[0]+1, liste);
237  vctDynamicVectorRef<int> ErrRef(nonlin+1, err);
238  (This->Object->*This->MethodPointer)(type, ListERef, XRef, ConRef, ErrRef);
239 #if 0
240  fprintf(stderr, "%d, %d, %d", n, nonlin, type);
241  for (int l = 1; l <= liste[0]; l++) fprintf(stderr, "%d, ", liste[l]);
242  for (int bb = 1; bb <= n; bb++) fprintf(stderr, "%f, ", x[bb]);
243  for (int cc = 1; cc <= nonlin; cc++) fprintf(stderr, "%f, ", con[cc]);
244  for (int dd = 1; dd <= nonlin; dd++) fprintf(stderr, "%d, ", err[dd]);
245  fprintf(stderr, "\n");
246 #endif
247  }
248  }
249 };
250 
251 #ifndef DOXYGEN
252 template <int _instanceLine, class _elementType>
254 #endif // DOXYGEN
255 
256 #if 0
257 template <int _instanceLine, class _elementType>
258 class nmrCallBackFunctionCG {
259 protected:
260  _elementType *Object;
261  int (_elementType::*MethodPointer)(vctDynamicVectorRef<int> &ListE, long int Shift,
263  CISST_DECLSPEC_THREAD static nmrCallBackFunctionCG* This;
264 public:
265  nmrCallBackFunctionCG():Object(0), MethodPointer(0) {
266  nmrCallBackFunctionCG::This = NULL;
267  }
268  nmrCallBackFunctionCG(_elementType *obj, int (_elementType::*methodPointer)
269  (vctDynamicVectorRef<int> &ListE, long int Shift,
271  Object(obj),
272  MethodPointer(methodPointer) {
273  nmrCallBackFunctionCG::This = this;
274  }
275  void Set(_elementType *obj, int (_elementType::*methodPointer)
276  (vctDynamicVectorRef<int> &ListE, long int Shift,
278  {
279  Object = obj;
280  MethodPointer = methodPointer;
281  nmrCallBackFunctionCG::This = this;
282  }
283  /* static function to be passed to donlp2 */
284  static int FunctionFdonlp2 (long int n, long int nonlin, long int liste[] ,long int shift , double x[],
285  double **grad) {
286  static int iflag = 0;
287  if (nmrCallBackFunctionCG::This != NULL) {
288  vctDynamicVectorRef<double> XRef(n+1, x);
289  vctDynamicMatrixRef<double> GradRef(*n, x);
290  vctDynamicVectorRef<double> XRef(*n, x);
291  vctDynamicVectorRef<double> XRef(*n, x);
292  return (This->Object->*This->MethodPointer)(XRef, *fx, iflag);
293  }
294  return -1;
295  }
296 };
297 template <int _instanceLine, class _elementType>
298 nmrCallBackFunctionCG <_instanceLine, _elementType>* nmrCallBackFunctionCG<_instanceLine, _elementType>::This = NULL;
299 #endif
300 
301 #endif // _nmrCallBackLSNonLinSolver_h
void Set(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Y, long int &Flag))
Definition: nmrCallBack.h:61
Declaration of vctDynamicMatrix.
void Set(_elementType *obj, void(_elementType::*methodPointer)(int Type, vctDynamicVectorRef< int > &ListE, vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Con, vctDynamicVectorRef< int > &Err))
Definition: nmrCallBack.h:222
_elementType * Object
Definition: nmrCallBack.h:109
static int FunctionFdonlp2(long int *n, double x[], double fgraf[])
Definition: nmrCallBack.h:89
nmrCallBackFunctionF1()
Definition: nmrCallBack.h:175
static CISST_DECLSPEC_THREAD nmrCallBackFunctionJ * This
Definition: nmrCallBack.h:118
nmrCallBackFunctionC(_elementType *obj, void(_elementType::*methodPointer)(int Type, vctDynamicVectorRef< int > &ListE, vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Con, vctDynamicVectorRef< int > &Err))
Definition: nmrCallBack.h:215
Definition: nmrCallBack.h:169
static CISST_DECLSPEC_THREAD nmrCallBackFunctionF1 * This
Definition: nmrCallBack.h:173
Definition: nmrCallBack.h:204
int(_elementType::* MethodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Y, long int &Flag)
Definition: nmrCallBack.h:48
nmrCallBackFunctionF1(_elementType *obj, void(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, double *F))
Definition: nmrCallBack.h:178
int(_elementType::* MethodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &J, long int &Flag)
Definition: nmrCallBack.h:112
static void FunctionFdonlp2(int n, int nonlin, int type, int liste[], double x[], double con[], int err[])
Definition: nmrCallBack.h:231
void Set(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &J, long int &Flag))
Definition: nmrCallBack.h:133
Declaration of vctDynamicVector.
static void FunctionFdonlp2(int n, double x[], double *fx)
Definition: nmrCallBack.h:190
Definition: nmrCallBack.h:45
static int FunctionFhybrd(long int *n, double *x, double *fvec, long int *iflag)
Definition: nmrCallBack.h:79
nmrCallBackFunctionF(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Y, long int &Flag))
Definition: nmrCallBack.h:55
static int FunctionFlmdif(long int *m, long int *n, double *x, double *fvec, long int *iflag)
Definition: nmrCallBack.h:69
void(_elementType::* MethodPointer)(int Type, vctDynamicVectorRef< int > &ListE, vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Con, vctDynamicVectorRef< int > &Err)
Definition: nmrCallBack.h:207
Definition: nmrCallBack.h:106
Declaration of vctDynamicMatrixRef.
static int FunctionFhybrj2(long int *n, double *x, double *fdjac, long int *ldfjac, long int *iflag)
Definition: nmrCallBack.h:141
#define CISST_DECLSPEC_THREAD
Definition: nmrCallBack.h:39
void(_elementType::* MethodPointer)(vctDynamicVectorRef< double > &X, double *F)
Definition: nmrCallBack.h:172
_elementType * Object
Definition: nmrCallBack.h:206
Declaration of vctDynamicVectorRef.
nmrCallBackFunctionC()
Definition: nmrCallBack.h:212
nmrCallBackFunctionJ()
Definition: nmrCallBack.h:123
static CISST_DECLSPEC_THREAD nmrCallBackFunctionF * This
Definition: nmrCallBack.h:50
_elementType * Object
Definition: nmrCallBack.h:171
nmrCallBackFunctionJ(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &J, long int &Flag))
Definition: nmrCallBack.h:126
static int FunctionFlmder2(long int *m, long int *n, double *x, double *fdjac, long int *ldfjac, long int *iflag)
Definition: nmrCallBack.h:152
nmrCallBackFunctionF()
Definition: nmrCallBack.h:52
_elementType * Object
Definition: nmrCallBack.h:47
void Set(_elementType *obj, void(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, double *F))
Definition: nmrCallBack.h:183
static CISST_DECLSPEC_THREAD nmrCallBackFunctionC * This
Definition: nmrCallBack.h:210