00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "stdafx.h"
00021
00022 #include <iostream>
00023
00024 #include "gul_types.h"
00025 #include "gunu_mba_approximate.h"
00026 #include "guma_transform.h"
00027
00028 #if defined(__MINGW32__) || defined(_MSC_VER)
00029 #define GULDECL __declspec(dllexport)
00030 #define GULCALL __cdecl
00031 #define CCALL __cdecl
00032 #else
00033 #define GULDECL
00034 #define GULCALL
00035 #define CCALL
00036 #endif
00037
00038 using gul::Ptr;
00039 using gul::point;
00040 using gul::point2;
00041
00042 extern "C" {
00043
00044
00045
00046
00047
00048 typedef struct
00049 {
00050 double x,y,z;
00051 }
00052 GULpoint;
00053
00054 typedef struct
00055 {
00056 double x,y;
00057 }
00058 GULpoint2;
00059
00060 }
00061
00062
00063
00064
00065
00066 inline void set( double *out, const double& in )
00067 {
00068 *out = in;
00069 }
00070
00071 inline void set( point<double> *out, const GULpoint& in )
00072 {
00073 out->x = in.x;
00074 out->y = in.y;
00075 out->z = in.z;
00076 }
00077
00078 inline void set( point2<double> *out, const GULpoint2& in )
00079 {
00080 out->x = in.x;
00081 out->y = in.y;
00082 }
00083
00084 inline void set( GULpoint *out, const point<double>& in )
00085 {
00086 out->x = in.x;
00087 out->y = in.y;
00088 out->z = in.z;
00089 }
00090
00091 inline void set( GULpoint2 *out, const point2<double>& in )
00092 {
00093 out->x = in.x;
00094 out->y = in.y;
00095 }
00096
00097
00098
00099 template< class T1, class T2 >
00100 void copy( int n, const T1 *inP, Ptr<T2>& outP )
00101 {
00102 int i;
00103 outP.reserve_pool(n);
00104 for( i = 0; i < n; i++ )
00105 set( &outP[i], inP[i] );
00106 }
00107
00108 template< class T1, class T2 >
00109 void copy( int n, const Ptr<T1>& inP, T2 **outP )
00110 {
00111 int i;
00112 *outP = (T2 *)galloc( sizeof(T2) * n );
00113 for( i = 0; i < n; i++ )
00114 set( &(*outP)[i], inP[i] );
00115 }
00116
00117
00118
00119 template< class T1, class T2 >
00120 void copy( int m, int n, const T1 **inP, Ptr< Ptr<T2> >& outP )
00121 {
00122 int i;
00123 outP.reserve_pool(m);
00124 for( i = 0; i < m; i++ )
00125 {
00126 outP[i].reserve_pool(n);
00127 for( j = 0; j < n; j++ )
00128 set( &outP[i][j], inP[i][j] );
00129 }
00130 }
00131
00132 template< class T1, class T2 >
00133 void copy( int m, int n, const Ptr< Ptr<T1> >& inP, T2 ***outP )
00134 {
00135 int i,j;
00136 *outP = (T2**)galloc( sizeof(T2*) * m );
00137 for( i = 0; i < m; i++ )
00138 {
00139 (*outP)[i] = (T2*)galloc( sizeof(T2) * n );
00140 for( j = 0; j < n; j++ )
00141 set( &(*outP)[i][j], inP[i][j] );
00142 }
00143 }
00144
00145
00146
00147
00148
00149 extern "C" {
00150
00151
00152
00153
00154
00155
00156
00157 static void *(CCALL *GUL_malloc_func)( size_t size ) = 0;
00158 static void (CCALL *GUL_free_func)( void * ) = 0;
00159
00160 GULDECL void GULCALL GUL_set_malloc_func( void *(CCALL *func)(size_t) )
00161 {
00162 GUL_malloc_func = func;
00163 }
00164
00165 GULDECL void GULCALL GUL_set_free_func( void (CCALL *func)(void *) )
00166 {
00167 GUL_free_func = func;
00168 }
00169
00170 void *galloc( size_t size )
00171 {
00172 if( GUL_malloc_func )
00173 return GUL_malloc_func(size);
00174
00175 return malloc(size);
00176 }
00177
00178 void gree( void *p )
00179 {
00180 if( GUL_free_func )
00181 {
00182 GUL_free_func(p);
00183 return;
00184 }
00185 free(p);
00186 }
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209 GULDECL void GULCALL GUL_SurfaceOverXYPlane(
00210 int nDatPoints, GULpoint *datPoints,
00211 int useStdDevs, double *StdDevs,
00212 int minimize, int nIter,
00213 int pu, int pv,
00214 int *ret_nu, double **retU,
00215 int *ret_nv, double **retV,
00216 GULpoint ***retPw )
00217 {
00218 Ptr< point<double> > datP;
00219 Ptr<double> stdD, U, V;
00220 Ptr< Ptr< point<double> > > Pw;
00221
00222 copy( nDatPoints, datPoints, datP );
00223 if( useStdDevs ) copy( nDatPoints, StdDevs, stdD );
00224
00225 gunu::SurfaceOverXYPlane< double,point<double> >(
00226 nDatPoints, datP, (useStdDevs!=0), stdD, (minimize!=0), nIter, pu, pv,
00227 ret_nu, &U, ret_nv, &V, &Pw );
00228
00229 copy( U.nElems(), U, retU );
00230 copy( V.nElems(), V, retV );
00231 copy( Pw.nElems(), Pw[0].nElems(), Pw, retPw );
00232 }
00233
00234
00235
00236
00237
00238
00239
00240 GULDECL void GULCALL GUL_MBASurface(
00241 int nDatPoints, GULpoint *datPoints, GULpoint2 *domPoints,
00242 int nIter, int pu, int pv,
00243 int *ret_nu, double **retU,
00244 int *ret_nv, double **retV,
00245 GULpoint ***retPw )
00246 {
00247 Ptr< point<double> > dat;
00248 Ptr< point2<double> > dom;
00249 Ptr<double> U,V;
00250 Ptr< Ptr< point<double> > > Pw;
00251
00252 copy( nDatPoints, datPoints, dat );
00253 copy( nDatPoints, domPoints, dom );
00254
00255 gunu::MBASurface( nDatPoints, dat, dom, nIter, pu, pv,
00256 ret_nu, &U, ret_nv, &V, &Pw );
00257
00258 copy( U.nElems(), U, retU );
00259 copy( V.nElems(), V, retV );
00260 copy( Pw.nElems(), Pw[0].nElems(), Pw, retPw );
00261 }
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274 GULDECL void GULCALL GUL_CommonCoordinateSystem(
00275 GULpoint B, GULpoint P, GULpoint Ab, GULpoint Pb,
00276 double **T )
00277 {
00278 point<double> b,p,ab,pb;
00279 Ptr< Ptr<double> > t;
00280 int i,j;
00281
00282 b.x = B.x; b.y = B.y; b.z = B.z;
00283 p.x = P.x; p.y = P.y; p.z = P.z;
00284 ab.x = Pb.x; ab.y = Pb.y; ab.z = Pb.z;
00285 pb.x = Pb.x; pb.y = Pb.y; pb.z = Pb.z;
00286
00287 t.reserve_pool(4);
00288 for( i = 0; i < 4; i++ )
00289 t[i].reserve_pool(4);
00290
00291 guma::CommonCoordinateSystem( b, p, ab, pb, t );
00292
00293 for( i = 0; i < 4; i++ )
00294 for( j = 0; j < 4; j++ )
00295 T[i][j] = t[i][j];
00296 }
00297
00298 }
00299