cisst-saw
Loading...
Searching...
No Matches
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
14This software is provided "as is" under an open source license, with
15no warranty. The complete license can be found in license.txt and
16http://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
44template <int _instanceLine, class _elementType>
46protected:
47 _elementType *Object;
49 vctDynamicVectorRef<double> &Y, long int &Flag);
51public:
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) {
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) {
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) {
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
101template <int _instanceLine, class _elementType>
102nmrCallBackFunctionF <_instanceLine, _elementType>* nmrCallBackFunctionF<_instanceLine, _elementType>::This = NULL;
103#endif // DOXYGEN
104
105template <int _instanceLine, class _elementType>
107protected:
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 */
119public:
120
121 /* constructor */
122 /* default */
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
164template <int _instanceLine, class _elementType>
165nmrCallBackFunctionJ <_instanceLine, _elementType>* nmrCallBackFunctionJ<_instanceLine, _elementType>::This = NULL;
166#endif // DOXYGEN
167
168template <int _instanceLine, class _elementType>
170protected:
171 _elementType *Object;
172 void (_elementType::*MethodPointer)(vctDynamicVectorRef<double> &X, double *F);
174public:
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
199template <int _instanceLine, class _elementType>
200nmrCallBackFunctionF1 <_instanceLine, _elementType>* nmrCallBackFunctionF1<_instanceLine, _elementType>::This = NULL;
201#endif // DOXYGEN
202
203template <int _instanceLine, class _elementType>
205protected:
206 _elementType *Object;
207 void (_elementType::*MethodPointer)(int Type, vctDynamicVectorRef<int> &ListE,
211public:
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,
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
252template <int _instanceLine, class _elementType>
253nmrCallBackFunctionC <_instanceLine, _elementType>* nmrCallBackFunctionC<_instanceLine, _elementType>::This = NULL;
254#endif // DOXYGEN
255
256#if 0
257template <int _instanceLine, class _elementType>
258class nmrCallBackFunctionCG {
259protected:
260 _elementType *Object;
261 int (_elementType::*MethodPointer)(vctDynamicVectorRef<int> &ListE, long int Shift,
263 CISST_DECLSPEC_THREAD static nmrCallBackFunctionCG* This;
264public:
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};
297template <int _instanceLine, class _elementType>
298nmrCallBackFunctionCG <_instanceLine, _elementType>* nmrCallBackFunctionCG<_instanceLine, _elementType>::This = NULL;
299#endif
300
301#endif // _nmrCallBackLSNonLinSolver_h
static void FunctionFdonlp2(int n, int nonlin, int type, int liste[], double x[], double con[], int err[])
Definition nmrCallBack.h:231
void(_elementType::*) MethodPointer(int Type, vctDynamicVectorRef< int > &ListE, vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Con, vctDynamicVectorRef< int > &Err)
Definition nmrCallBack.h:207
static CISST_DECLSPEC_THREAD nmrCallBackFunctionC * This
Definition nmrCallBack.h:210
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
nmrCallBackFunctionC(_elementType *obj, void(_elementType::*methodPointer)(int Type, vctDynamicVectorRef< int > &ListE, vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Con, vctDynamicVectorRef< int > &Err))
Definition nmrCallBack.h:215
nmrCallBackFunctionC()
Definition nmrCallBack.h:212
_elementType * Object
Definition nmrCallBack.h:206
void Set(_elementType *obj, void(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, double *F))
Definition nmrCallBack.h:183
static CISST_DECLSPEC_THREAD nmrCallBackFunctionF1 * This
Definition nmrCallBack.h:173
_elementType * Object
Definition nmrCallBack.h:171
static void FunctionFdonlp2(int n, double x[], double *fx)
Definition nmrCallBack.h:190
void(_elementType::*) MethodPointer(vctDynamicVectorRef< double > &X, double *F)
Definition nmrCallBack.h:172
nmrCallBackFunctionF1()
Definition nmrCallBack.h:175
nmrCallBackFunctionF1(_elementType *obj, void(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, double *F))
Definition nmrCallBack.h:178
static int FunctionFlmdif(long int *m, long int *n, double *x, double *fvec, long int *iflag)
Definition nmrCallBack.h:69
nmrCallBackFunctionF()
Definition nmrCallBack.h:52
int(_elementType::*) MethodPointer(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Y, long int &Flag)
Definition nmrCallBack.h:48
static CISST_DECLSPEC_THREAD nmrCallBackFunctionF * This
Definition nmrCallBack.h:50
static int FunctionFhybrd(long int *n, double *x, double *fvec, long int *iflag)
Definition nmrCallBack.h:79
static int FunctionFdonlp2(long int *n, double x[], double fgraf[])
Definition nmrCallBack.h:89
void Set(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Y, long int &Flag))
Definition nmrCallBack.h:61
nmrCallBackFunctionF(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &Y, long int &Flag))
Definition nmrCallBack.h:55
_elementType * Object
Definition nmrCallBack.h:47
static CISST_DECLSPEC_THREAD nmrCallBackFunctionJ * This
Definition nmrCallBack.h:118
int(_elementType::*) MethodPointer(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &J, long int &Flag)
Definition nmrCallBack.h:112
_elementType * Object
Definition nmrCallBack.h:109
static int FunctionFhybrj2(long int *n, double *x, double *fdjac, long int *ldfjac, long int *iflag)
Definition nmrCallBack.h:141
nmrCallBackFunctionJ()
Definition nmrCallBack.h:123
void Set(_elementType *obj, int(_elementType::*methodPointer)(vctDynamicVectorRef< double > &X, vctDynamicVectorRef< double > &J, long int &Flag))
Definition nmrCallBack.h:133
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
Dynamic matrix referencing existing memory.
Definition vctDynamicMatrixRef.h:75
Dynamic vector referencing existing memory.
Definition vctDynamicVectorRef.h:78
#define CISST_DECLSPEC_THREAD
Definition nmrCallBack.h:39
nmrCallBackFunctionF< _instanceLine, _elementType > * nmrCallBackFunctionF< _instanceLine, _elementType >::This
Definition nmrCallBack.h:102
const value_type & Y(void) const
Definition vctDynamicConstVectorBase.h:271
const value_type & X(void) const
Definition vctDynamicConstVectorBase.h:263
Declaration of vctDynamicMatrix.
Declaration of vctDynamicMatrixRef.
Declaration of vctDynamicVector.
Declaration of vctDynamicVectorRef.