1 /*************************************************************************** 2 * abstract.h is part of Math Graphic Library 3 * Copyright (C) 2007-2016 Alexey Balakin <mathgl.abalakin@gmail.ru> * 4 * * 5 * This program is free software; you can redistribute it and/or modify * 6 * it under the terms of the GNU Lesser General Public License as * 7 * published by the Free Software Foundation; either version 3 of the * 8 * License, or (at your option) any later version. * 9 * * 10 * This program is distributed in the hope that it will be useful, * 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 13 * GNU General Public License for more details. * 14 * * 15 * You should have received a copy of the GNU Lesser General Public * 16 * License along with this program; if not, write to the * 17 * Free Software Foundation, Inc., * 18 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * 19 ***************************************************************************/ 20 #ifndef _MGL_ABSTRACT_H_ 21 #define _MGL_ABSTRACT_H_ 22 23 #include "mgl2/define.h" 24 //----------------------------------------------------------------------------- 25 #ifdef __cplusplus 26 #include "mgl2/type.h" 27 #define MGL_TO_WCS(str,code) if(str && *str){size_t s=mbstowcs(0,str,0); wchar_t *wcs=new wchar_t[s+1]; mbstowcs(wcs,str,s); wcs[s]=0; code; delete []wcs;}else{const wchar_t *wcs=L""; code;} 28 //----------------------------------------------------------------------------- 29 class mglBase; 30 class mglData; 31 class mglDataA; 32 class mglDataC; 33 class mglParser; 34 class mglFormula; 35 class mglFormulaC; 36 class mglFont; 37 typedef mglBase* HMGL; 38 typedef mglData* HMDT; 39 typedef mglDataC* HADT; 40 typedef mglParser* HMPR; 41 typedef mglFormula* HMEX; 42 typedef mglFormulaC* HAEX; 43 typedef const mglDataA* HCDT; 44 //----------------------------------------------------------------------------- 45 std::string MGL_EXPORT mgl_data_to_string(HCDT d, long ns); 46 std::string MGL_EXPORT mgl_datac_to_string(HCDT d, long ns); 47 /// Get section separated by symbol ch. This is analog of QString::section(). 48 std::string MGL_EXPORT mgl_str_arg(const std::string &str, char ch, int n1, int n2=-1); 49 std::wstring MGL_EXPORT mgl_wcs_arg(const std::wstring &str, wchar_t ch, int n1, int n2); 50 /// Get sections separated by symbol ch 51 std::vector<std::string> MGL_EXPORT mgl_str_args(const std::string &str, char ch); 52 std::vector<std::wstring> MGL_EXPORT mgl_wcs_args(const std::wstring &str, wchar_t ch); 53 /// Get string from real number 54 std::string MGL_EXPORT mgl_str_num(double val); 55 /// Get string from complex number 56 std::string MGL_EXPORT mgl_str_num(dual val); 57 //----------------------------------------------------------------------------- 58 59 extern "C" { 60 61 #else 62 #define mglDataA void 63 #define mglNum void 64 typedef void *HMGL; 65 typedef void *HMDT; 66 typedef void *HADT; 67 typedef void *HMEX; 68 typedef void *HAEX; 69 typedef void *HMPR; 70 typedef const void *HCDT; 71 #endif 72 73 /// Set buffer size for number of primitives as (1<<bsize)^2. 74 /** I.e. as 10^12 for bsize=20 or 4*10^9 for bsize=16 (default). NOTE: you set it only once. The current value is returned. */ 75 unsigned MGL_EXPORT mgl_bsize(unsigned bsize); 76 unsigned MGL_EXPORT mgl_bsize_(unsigned *bsize); 77 78 /// Set seed for random numbers 79 void MGL_EXPORT mgl_srnd(long seed); 80 void MGL_EXPORT mgl_srnd_(int *seed); 81 /// Get random number 82 double MGL_EXPORT mgl_rnd(); 83 double MGL_EXPORT mgl_rnd_(); 84 85 /// Set name for data variable (can be used in mgl_formula_calc() or in MGL scripts) 86 void MGL_EXPORT mgl_data_set_name(mglDataA *dat, const char *name); 87 void MGL_EXPORT mgl_data_set_name_(uintptr_t *dat, const char *name,int); 88 void MGL_EXPORT mgl_data_set_name_w(mglDataA *dat, const wchar_t *name); 89 /// Get name of data variable 90 MGL_EXPORT_PURE const wchar_t *mgl_data_get_name_w(HCDT dat); 91 /// Set callback function which is called at deleting variable 92 void MGL_EXPORT mgl_data_set_func(mglDataA *dat, void (*func)(void *), void *par); 93 94 #define mgl_datac_set_id mgl_data_set_id 95 #define mgl_datac_set_id_ mgl_data_set_id_ 96 /// Set names for columns (slices) 97 void MGL_EXPORT mgl_data_set_id(mglDataA *d, const char *ids); 98 void MGL_EXPORT mgl_datac_set_id_(uintptr_t *d, const char *eq,int ); 99 /// Get names for columns (slices) 100 MGL_EXPORT_PURE const char *mgl_data_get_id(HCDT d); 101 102 /// Save whole data array (for ns=-1) or only ns-th slice to text file 103 void MGL_EXPORT mgl_data_save(HCDT dat, const char *fname,long ns); 104 void MGL_EXPORT mgl_data_save_(uintptr_t *dat, const char *fname,int *ns,int); 105 /// Export data array (for ns=-1) or only ns-th slice to PNG file according color scheme 106 void MGL_EXPORT mgl_data_export(HCDT dat, const char *fname, const char *scheme, double v1, double v2, long ns); 107 void MGL_EXPORT mgl_data_export_(uintptr_t *dat, const char *fname, const char *scheme, mreal *v1, mreal *v2, int *ns,int,int); 108 /// Save data to HDF file 109 void MGL_EXPORT mgl_data_save_hdf(HCDT d,const char *fname,const char *data,int rewrite); 110 void MGL_EXPORT mgl_data_save_hdf_(uintptr_t *d, const char *fname, const char *data, int *rewrite,int l,int n); 111 /// Save value to HDF file 112 void MGL_EXPORT mgl_dual_save_hdf(mdual val,const char *fname,const char *data,int rewrite); 113 void MGL_EXPORT mgl_real_save_hdf(double val,const char *fname,const char *data,int rewrite); 114 void MGL_EXPORT mgl_int_save_hdf(long val,const char *fname,const char *data,int rewrite); 115 void MGL_EXPORT mgl_real_save_hdf_(double *val,const char *fname,const char *data,int *rewrite,int,int); 116 void MGL_EXPORT mgl_int_save_hdf_(long *val, const char *fname, const char *data, int *rewrite, int, int); 117 /// Get information about the data (sizes and momentum) to string 118 MGL_EXPORT const char *mgl_data_info(HCDT dat); 119 int MGL_EXPORT mgl_data_info_(uintptr_t *dat, char *out, int len); 120 /// Put HDF data names into buf as '\t' separated. 121 long MGL_EXPORT mgl_datas_hdf(const char *fname, char *buf, long size); 122 long MGL_EXPORT mgl_datas_hdf_(const char *fname, char *buf, int l, int size); 123 /// Put HDF data names as list of strings (last one is ""). 124 MGL_EXPORT const char * const * mgl_datas_hdf_str(const char *fname); 125 126 /// Get maximal value of the data 127 mreal MGL_EXPORT mgl_data_max(HCDT dat); 128 mreal MGL_EXPORT mgl_data_max_(uintptr_t *dat); 129 /// Get maximal value of the data which is less than 0 130 mreal MGL_EXPORT mgl_data_neg_max(HCDT dat); 131 mreal MGL_EXPORT mgl_data_neg_max_(uintptr_t *dat); 132 /// Get minimal value of the data 133 mreal MGL_EXPORT mgl_data_min(HCDT dat); 134 mreal MGL_EXPORT mgl_data_min_(uintptr_t *dat); 135 /// Get minimal value of the data which is larger than 0 136 mreal MGL_EXPORT mgl_data_pos_min(HCDT dat); 137 mreal MGL_EXPORT mgl_data_pos_min_(uintptr_t *dat); 138 /// Find position (after specified in i,j,k) of first nonzero value of formula 139 mreal MGL_EXPORT mgl_data_first(HCDT dat, const char *cond, long *i, long *j, long *k); 140 mreal MGL_EXPORT mgl_data_first_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); 141 /// Find position (before specified in i,j,k) of last nonzero value of formula 142 mreal MGL_EXPORT mgl_data_last(HCDT dat, const char *cond, long *i, long *j, long *k); 143 mreal MGL_EXPORT mgl_data_last_(uintptr_t *dat, const char *cond, int *i, int *j, int *k, int); 144 /// Find position of first in direction 'dir' nonzero value of formula 145 long MGL_EXPORT mgl_data_find(HCDT dat, const char *cond, char dir, long i, long j, long k); 146 int MGL_EXPORT mgl_data_find_(uintptr_t *dat, const char *cond, char *dir, int *i, int *j, int *k, int,int); 147 /// Find if any nonzero value of formula 148 int MGL_EXPORT mgl_data_find_any(HCDT dat, const char *cond); 149 int MGL_EXPORT mgl_data_find_any_(uintptr_t *dat, const char *cond, int); 150 /// Get maximal value of the data and its position 151 mreal MGL_EXPORT mgl_data_max_int(HCDT dat, long *i, long *j, long *k); 152 mreal MGL_EXPORT mgl_data_max_int_(uintptr_t *dat, int *i, int *j, int *k); 153 /// Get maximal value of the data and its approximated position 154 mreal MGL_EXPORT mgl_data_max_real(HCDT dat, mreal *x, mreal *y, mreal *z); 155 mreal MGL_EXPORT mgl_data_max_real_(uintptr_t *dat, mreal *x, mreal *y, mreal *z); 156 /// Get minimal value of the data and its position 157 mreal MGL_EXPORT mgl_data_min_int(HCDT dat, long *i, long *j, long *k); 158 mreal MGL_EXPORT mgl_data_min_int_(uintptr_t *dat, int *i, int *j, int *k); 159 /// Get minimal value of the data and its approximated position 160 mreal MGL_EXPORT mgl_data_min_real(HCDT dat, mreal *x, mreal *y, mreal *z); 161 mreal MGL_EXPORT mgl_data_min_real_(uintptr_t *dat, mreal *x, mreal *y, mreal *z); 162 /// Get "energy and find 4 momenta of data: median, width, skewness, kurtosis 163 mreal MGL_EXPORT mgl_data_momentum_val(HCDT d, char dir, mreal *m, mreal *w, mreal *s, mreal *k); 164 mreal MGL_EXPORT mgl_data_momentum_val_(uintptr_t *dat, char *dir, mreal *m, mreal *w, mreal *s, mreal *k,int); 165 /// Get first (last if from<0) maximum along direction dir, and save its orthogonal coordinates in p1, p2 166 long MGL_EXPORT mgl_data_max_first(HCDT d, char dir, long from, long *p1, long *p2); 167 long MGL_EXPORT mgl_data_max_first_(uintptr_t *d, const char *dir, long *from, long *p1, long *p2,int); 168 169 /// Interpolate by linear function the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] 170 mreal MGL_EXPORT mgl_data_linear(HCDT dat, mreal x,mreal y,mreal z); 171 mreal MGL_EXPORT mgl_data_linear_(uintptr_t *dat, mreal *x,mreal *y,mreal *z); 172 /// Interpolate by linear function the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] 173 mreal MGL_EXPORT mgl_data_linear_ext(HCDT dat, mreal x,mreal y,mreal z, mreal *dx,mreal *dy,mreal *dz); 174 mreal MGL_EXPORT mgl_data_linear_ext_(uintptr_t *dat, mreal *x,mreal *y,mreal *z, mreal *dx,mreal *dy,mreal *dz); 175 176 /// Internal function for (un-)locking mutex in mglStack 177 void MGL_EXPORT mgl_mutex_lock(void *); 178 void MGL_EXPORT mgl_mutex_unlock(void *); 179 180 //----------------------------------------------------------------------------- 181 /// Create HMEX object for expression evaluating 182 HMEX MGL_EXPORT mgl_create_expr(const char *expr); 183 uintptr_t MGL_EXPORT mgl_create_expr_(const char *expr, int); 184 /// Delete HMEX object 185 void MGL_EXPORT mgl_delete_expr(HMEX ex); 186 void MGL_EXPORT mgl_delete_expr_(uintptr_t *ex); 187 /// Return value of expression for given x,y,z variables 188 double MGL_EXPORT_PURE mgl_expr_eval(HMEX ex, double x, double y,double z); 189 double MGL_EXPORT_PURE mgl_expr_eval_(uintptr_t *ex, mreal *x, mreal *y, mreal *z); 190 /// Return value of expression for given variables 191 double MGL_EXPORT_PURE mgl_expr_eval_v(HMEX ex, mreal *vars); 192 /// Return value of expression differentiation over variable dir for given x,y,z variables 193 double MGL_EXPORT_PURE mgl_expr_diff(HMEX ex, char dir, double x, double y,double z); 194 double MGL_EXPORT_PURE mgl_expr_diff_(uintptr_t *ex, const char *dir, mreal *x, mreal *y, mreal *z, int); 195 /// Return value of expression differentiation over variable dir for given variables 196 double MGL_EXPORT_PURE mgl_expr_diff_v(HMEX ex, char dir, mreal *vars); 197 //----------------------------------------------------------------------------- 198 /// Create HAEX object for expression evaluating 199 HAEX MGL_EXPORT mgl_create_cexpr(const char *expr); 200 uintptr_t MGL_EXPORT mgl_create_cexpr_(const char *expr, int); 201 /// Delete HAEX object 202 void MGL_EXPORT mgl_delete_cexpr(HAEX ex); 203 void MGL_EXPORT mgl_delete_cexpr_(uintptr_t *ex); 204 /// Return value of expression for given x,y,z variables 205 cmdual MGL_EXPORT mgl_cexpr_eval(HAEX ex, mdual x, mdual y, mdual z); 206 cmdual MGL_EXPORT mgl_cexpr_eval_(uintptr_t *ex, mdual *x, mdual *y, mdual *z); 207 /// Return value of expression for given variables 208 cmdual MGL_EXPORT mgl_cexpr_eval_v(HAEX ex, mdual *vars); 209 210 //----------------------------------------------------------------------------- 211 /// Callback function for asking user a question. Result shouldn't exceed 1024. 212 extern MGL_EXPORT void (*mgl_ask_func)(const wchar_t *quest, wchar_t *res); 213 /// Console function for asking user a question. Result shouldn't exceed 1024. 214 void MGL_EXPORT mgl_ask_gets(const wchar_t *quest, wchar_t *res); 215 /// Callback function for displaying progress of something. 216 extern MGL_EXPORT void (*mgl_progress_func)(int value, int maximal, HMGL gr); 217 /// Console function for displaying progress of something. 218 void MGL_EXPORT mgl_progress_txt(int value, int maximal, HMGL gr); 219 /// Display progress of something. 220 void MGL_EXPORT mgl_progress(int value, int maximal, HMGL gr); 221 //----------------------------------------------------------------------------- 222 #ifdef __cplusplus 223 } 224 //----------------------------------------------------------------------------- 225 /// Structure for the number handling (see mglParse class). 226 struct MGL_EXPORT mglNum 227 { 228 mreal d; ///< Number itself 229 dual c; 230 mglString s; ///< Number name dmglNum231 mglNum(mreal val=0):d(val),c(val) {} mglNummglNum232 mglNum(const mglNum &n):d(n.d),c(n.c),s(n.s) {} 233 const mglNum &operator=(const mglNum &n) 234 { d=n.d; c=n.c; s=n.s; return n; } 235 }; 236 //----------------------------------------------------------------------------- 237 /// List of user-defined data arrays 238 MGL_EXPORT extern std::vector<mglDataA*> mglDataList; 239 //----------------------------------------------------------------------------- 240 /// Abstract class for data array 241 class MGL_EXPORT mglDataA 242 { 243 public: 244 mglString s; ///< Data name 245 mglString id; ///< column (or slice) names 246 247 bool temp; ///< This is temporary variable 248 void (*func)(void *); ///< Callback function for destroying 249 void *o; ///< Pointer to external object 250 mglDataA()251 mglDataA() { mgl_init(); mglDataList.push_back(this); temp=false; func=0; o=0; } ~mglDataA()252 virtual ~mglDataA() 253 { 254 for(long i = mglDataList.size()-1; i>=0; i--) 255 if(mglDataList[i] == this) 256 { mglDataList.erase(mglDataList.begin()+i); break; } 257 if(func) func(o); 258 } 259 /// Set name for data variable (can be used in mgl_formula_calc() or in MGL scripts) Name(const char * name)260 inline void Name(const char *name) { s = name; } Name(const wchar_t * name)261 inline void Name(const wchar_t *name) { s = name; } 262 /// Get name of data variable Name()263 inline const wchar_t *Name() const { return s.w; } 264 265 /// Set names for columns (slices) SetColumnId(const char * ids)266 inline void SetColumnId(const char *ids) { id = ids; } 267 /// Make new id NewId()268 inline void NewId() { id = ""; } 269 /// Get names for columns (slices) GetColumnId()270 inline const char *GetColumnId() const { return id.s; } 271 272 virtual void set_v(mreal /*val*/, long /*i*/,long /*j*/=0,long /*k*/=0) {} 273 /// Get the interpolated value and its derivatives in given data cell without border checking 274 virtual mreal valueD(mreal x,mreal y=0,mreal z=0,mreal *dx=0,mreal *dy=0,mreal *dz=0) const =0; 275 /// Get the interpolated value in given data cell without border checking 276 virtual mreal value(mreal x,mreal y=0,mreal z=0) const =0; 277 /// Interpolate by linear function the data to given point 278 inline mreal linear(mreal x,mreal y=0,mreal z=0) const 279 { return mgl_data_linear_ext(this,x,y,z,0,0,0); } 280 /// Interpolate by linear function the data to given point and get the gradient 281 inline mreal linearD(mreal x,mreal y=0,mreal z=0,mreal *dx=0,mreal *dy=0,mreal *dz=0) const 282 { return mgl_data_linear_ext(this,x,y,z,dx,dy,dz); } 283 virtual mreal v(long i,long j=0,long k=0) const = 0; vthr(long i)284 virtual mreal vthr(long i) const 285 { return v(i%GetNx(), (i/GetNx())%GetNy(), i/(GetNx()*GetNy())); } 286 virtual dual vc(long i,long j=0,long k=0) const { return v(i,j,k); } vcthr(long i)287 virtual dual vcthr(long i) const { return vthr(i); } 288 virtual long GetNx() const = 0; 289 virtual long GetNy() const = 0; 290 virtual long GetNz() const = 0; GetNN()291 inline long GetNN() const { return GetNx()*GetNy()*GetNz(); } 292 virtual mreal dvx(long i,long j=0,long k=0) const = 0; 293 // { return i>0 ? (i<GetNx()-1 ? (v(i+1,j,k)-v(i-1,j,k))/2 : v(i,j,k)-v(i-1,j,k)) : v(1,j,k)-v(0,j,k); } 294 virtual mreal dvy(long i,long j=0,long k=0) const = 0; 295 // { return j>0 ? (j<GetNy()-1 ? (v(i,j+1,k)-v(i,j-1,k))/2 : v(i,j,k)-v(i,j-1,k)) : v(i,1,k)-v(i,0,k); } 296 virtual mreal dvz(long i,long j=0,long k=0) const = 0; 297 // { return k>0 ? (k<GetNz()-1 ? (v(i,j,k+1)-v(i,j,k-1))/2 : v(i,j,k)-v(i,j,k-1)) : v(i,j,1)-v(i,j,0); } 298 299 // Now some common function which applicable for most of data types 300 /// Save whole data array (for ns=-1) or only ns-th slice to text file 301 virtual void Save(const char *fname,long ns=-1) const 302 { mgl_data_save(this,fname,ns); } 303 /// Get whole data array (for ns=-1) or only ns-th slice to string 304 virtual std::string Get(long ns=-1) const 305 { return mgl_data_to_string(this,ns); } 306 /// Export data array (for ns=-1) or only ns-th slice to PNG file according color scheme 307 inline void Export(const char *fname,const char *scheme,mreal v1=0,mreal v2=0,long ns=-1) const 308 { mgl_data_export(this,fname,scheme,v1,v2,ns); } 309 /// Save data to HDF file 310 virtual void SaveHDF(const char *fname,const char *data,bool rewrite=false) const 311 { mgl_data_save_hdf(this,fname,data,rewrite); } 312 /// Put HDF data names into buf as '\t' separated. DatasHDF(const char * fname,char * buf,long size)313 inline static int DatasHDF(const char *fname, char *buf, long size) 314 { return mgl_datas_hdf(fname,buf,size); } 315 /// Put HDF data names as list of strings (last one is ""). DatasHDF(const char * fname)316 inline static const char * const * DatasHDF(const char *fname) 317 { return mgl_datas_hdf_str(fname); } 318 319 /// Get information about the data (sizes and momentum) to string PrintInfo()320 inline const char *PrintInfo() const { return mgl_data_info(this); } 321 /// Print information about the data (sizes and momentum) to FILE (for example, stdout) PrintInfo(FILE * fp)322 inline void PrintInfo(FILE *fp) const 323 { if(fp) { fprintf(fp,"%s",mgl_data_info(this)); fflush(fp); } } 324 /// Get maximal value of the data Maximal()325 virtual mreal Maximal() const { return mgl_data_max(this); } 326 /// Get minimal value of the data Minimal()327 virtual mreal Minimal() const { return mgl_data_min(this); } 328 /// Get maximal value of the data which is less than 0 MaximalNeg()329 inline mreal MaximalNeg() const { return mgl_data_neg_max(this); } 330 /// Get minimal value of the data which is larger than 0 MinimalPos()331 inline mreal MinimalPos() const { return mgl_data_pos_min(this); } 332 /// Get maximal value of the data and its position Maximal(long & i,long & j,long & k)333 inline mreal Maximal(long &i,long &j,long &k) const 334 { return mgl_data_max_int(this,&i,&j,&k); } 335 /// Get minimal value of the data and its position Minimal(long & i,long & j,long & k)336 inline mreal Minimal(long &i,long &j,long &k) const 337 { return mgl_data_min_int(this,&i,&j,&k); } 338 /// Get maximal value of the data and its approximated position Maximal(mreal & x,mreal & y,mreal & z)339 inline mreal Maximal(mreal &x,mreal &y,mreal &z) const 340 { return mgl_data_max_real(this,&x,&y,&z); } 341 /// Get minimal value of the data and its approximated position Minimal(mreal & x,mreal & y,mreal & z)342 inline mreal Minimal(mreal &x,mreal &y,mreal &z) const 343 { return mgl_data_min_real(this,&x,&y,&z); } 344 /// Get first (last if from<0) maximum along direction dir, and save its orthogonal coordinates in p1, p2 Maximal(char dir,long from,long & p1,long & p2)345 inline long Maximal(char dir, long from, long &p1, long &p2) const 346 { return mgl_data_max_first(this,dir,from,&p1,&p2); } Maximal(char dir,long from)347 inline long Maximal(char dir, long from) const 348 { return mgl_data_max_first(this,dir,from,0,0); } 349 /// Get "energy" and find first (median) and second (width) momenta of data Momentum(char dir,mreal & m,mreal & w)350 inline mreal Momentum(char dir,mreal &m,mreal &w) const 351 { return mgl_data_momentum_val(this,dir,&m,&w,0,0); } 352 /// Get "energy and find 4 momenta of data: median, width, skewness, kurtosis Momentum(char dir,mreal & m,mreal & w,mreal & s,mreal & k)353 inline mreal Momentum(char dir,mreal &m,mreal &w,mreal &s,mreal &k) const 354 { return mgl_data_momentum_val(this,dir,&m,&w,&s,&k); } 355 /// Find position (after specified in i,j,k) of first nonzero value of formula Find(const char * cond,long & i,long & j,long & k)356 inline mreal Find(const char *cond, long &i, long &j, long &k) const 357 { return mgl_data_first(this,cond,&i,&j,&k); } 358 /// Find position (before specified in i,j,k) of last nonzero value of formula Last(const char * cond,long & i,long & j,long & k)359 inline mreal Last(const char *cond, long &i, long &j, long &k) const 360 { return mgl_data_last(this,cond,&i,&j,&k); } 361 /// Find position of first in direction 'dir' nonzero value of formula 362 inline long Find(const char *cond, char dir, long i=0, long j=0, long k=0) const 363 { return mgl_data_find(this,cond,dir,i,j,k); } 364 /// Find if any nonzero value of formula FindAny(const char * cond)365 inline bool FindAny(const char *cond) const 366 { return mgl_data_find_any(this,cond); } 367 368 /// Interpolate by cubic spline the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] 369 inline mreal Spline(mreal x,mreal y=0,mreal z=0) const 370 { return value(x,y,z); } 371 /// Interpolate by cubic spline the data to given point x,\a y,\a z which normalized in range [0, 1] 372 inline mreal Spline1(mreal x,mreal y=0,mreal z=0) const 373 { return value(x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1)); } 374 /// Interpolate by cubic spline the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] 375 inline mreal Spline(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const 376 { return valueD(x,y,z, &(dif.x),&(dif.y), &(dif.z)); } 377 /// Interpolate by cubic spline the data and return its derivatives at given point x,\a y,\a z which normalized in range [0, 1] 378 inline mreal Spline1(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const 379 { mreal res=valueD(x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1), &(dif.x),&(dif.y), &(dif.z)); 380 dif.x*=GetNx()>1?GetNx()-1:1; dif.y*=GetNy()>1?GetNy()-1:1; dif.z*=GetNz()>1?GetNz()-1:1; return res; } 381 382 /// Interpolate by linear function the data to given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] 383 inline mreal Linear(mreal x,mreal y=0,mreal z=0) const 384 { return mgl_data_linear_ext(this,x,y,z,0,0,0); } 385 /// Interpolate by line the data to given point x,\a y,\a z which normalized in range [0, 1] 386 inline mreal Linear1(mreal x,mreal y=0,mreal z=0) const 387 { return mgl_data_linear_ext(this,x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1),0,0,0); } 388 /// Interpolate by linear function the data and return its derivatives at given point x=[0...nx-1], y=[0...ny-1], z=[0...nz-1] 389 inline mreal Linear(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const 390 { return mgl_data_linear_ext(this,x,y,z, &(dif.x),&(dif.y), &(dif.z)); } 391 /// Interpolate by line the data and return its derivatives at given point x,\a y,\a z which normalized in range [0, 1] 392 inline mreal Linear1(mglPoint &dif, mreal x,mreal y=0,mreal z=0) const 393 { mreal res=mgl_data_linear_ext(this,x*(GetNx()-1),y*(GetNy()-1),z*(GetNz()-1), &(dif.x),&(dif.y), &(dif.z)); 394 dif.x*=GetNx()>1?GetNx()-1:1; dif.y*=GetNy()>1?GetNy()-1:1; dif.z*=GetNz()>1?GetNz()-1:1; return res; } 395 }; 396 //----------------------------------------------------------------------------- 397 /// Structure for color ID 398 struct MGL_EXPORT mglColorID 399 { 400 char id; 401 mglColor col; 402 }; 403 MGL_EXPORT extern mglColorID mglColorIds[31]; 404 // MGL_EXPORT extern std::string mglGlobalMess; ///< Buffer for receiving global messages 405 //----------------------------------------------------------------------------- 406 #endif 407 408 #ifdef MGL_SRC 409 #define _Da_(d) (*((const mglDataA *)(d))) 410 #define _DA_(a) ((const mglDataA *)*(a)) 411 #define _GR_ ((mglBase *)(*gr)) 412 //#define _D_(d) *((mglData *)*(d)) 413 #define _DM_(a) ((mglData *)*(a)) 414 #define _DT_ ((mglData *)*d) 415 #endif 416 417 #endif 418