Rocstar  1.0
Rocstar multiphysics simulation application
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
CImg< T >::_cimg_math_parser Struct Reference

#include <CImg.h>

Collaboration diagram for CImg< T >::_cimg_math_parser:

Public Member Functions

 _cimg_math_parser (const char *const expression, const char *const funcname=0)
 
 ~_cimg_math_parser ()
 
unsigned int opcode (const char op, const unsigned int arg1=0, const unsigned int arg2=0, const unsigned int arg3=0, const unsigned int arg4=0, const unsigned int arg5=0)
 
unsigned int compile (char *const ss, char *const se)
 
template<typename t >
double eval (const CImg< t > &img, const double x, const double y, const double z, const double v)
 
double eval (const double x, const double y, const double z, const double v)
 

Public Attributes

CImgList< uintTcode
 
CImg< doubleTmem
 
unsigned int mempos
 
unsigned int * level
 
unsigned int result
 
const char * calling_function
 
char * expr
 

Detailed Description

template<typename T = float>
struct cimg_library::CImg< T >::_cimg_math_parser

Definition at line 12218 of file CImg.h.

Constructor & Destructor Documentation

_cimg_math_parser ( const char *const  expression,
const char *const  funcname = 0 
)
inline

Definition at line 12232 of file CImg.h.

References CImg< T >::assign(), CImg< T >::_cimg_math_parser::calling_function, CImg< T >::_cimg_math_parser::compile(), d, cimg_library::exp(), CImg< T >::_cimg_math_parser::expr, CImg< T >::_cimg_math_parser::level, CImg< T >::_cimg_math_parser::mem, CImg< T >::_cimg_math_parser::mempos, CImg< T >::pixel_type(), s, cimg_library::cimg::strclean(), cimg_library::cimg::uncase(), and cimg_library::cimg::valuePI.

12232  :level(0),calling_function(funcname),expr(0) {
12233  static const char *const funcname0 = "cimg_math_parser";
12234  if (!funcname) calling_function = funcname0;
12235  if (!expression) return;
12236  unsigned int l0 = std::strlen(expression);
12237  expr = new char[l0+1];
12238  std::strcpy(expr,expression);
12240  if (!*expr) return;
12241  char *d = expr; for (const char *s = expr; *s || (bool)(*d=0); ++s) if (*s!=' ') *(d++) = *s;
12242  const unsigned int l = d - expr;
12243  if (!l) return;
12244  cimg::uncase(expr);
12245  int lv = 0; // Count parenthesis level of expression.
12246  unsigned int *pd = level = new unsigned int[l];
12247  for (const char *ps = expr; *ps && lv>=0; ++ps) *(pd++) = (unsigned int)(*ps=='('?lv++:*ps==')'?--lv:lv);
12248  if (lv!=0) throw CImgArgumentException("CImg<%s>::%s() : Unbalanced parenthesis, in formula '%s'.",
12249  pixel_type(),calling_function,expr);
12250  mem.assign(1024); // Compile formula into serie of opcodes.
12251  mem[8] = cimg::valuePI; mem[9] = std::exp(1.0); mem[10] = 0; mempos = 11;
12252  result = compile(expr,expr+l);
12253  }
CImg< _cimg_Tfloat > exp(const CImg< T > &instance)
Definition: CImg.h:6016
const NT & d
double s
Definition: blastest.C:80
void strclean(char *const s)
Remove useless spaces and symmetric delimiters &#39;, " and ` from a C-string.
Definition: CImg.h:4950
const double valuePI
Definition of the mathematical constant PI.
Definition: CImg.h:2761
static const char * pixel_type()
Return the type of the pixel values.
Definition: CImg.h:11041
CImg< T > & assign()
In-place version of the default constructor/destructor.
Definition: CImg.h:10103
unsigned int compile(char *const ss, char *const se)
Definition: CImg.h:12266
char uncase(const char x)
Remove the &#39;case&#39; of an ASCII character.
Definition: CImg.h:4888

Here is the call graph for this function:

~_cimg_math_parser ( )
inline

Definition at line 12254 of file CImg.h.

References CImg< T >::_cimg_math_parser::expr, and CImg< T >::_cimg_math_parser::level.

12254 { if (level) delete[] level; if (expr) delete[] expr; }

Member Function Documentation

unsigned int compile ( char *const  ss,
char *const  se 
)
inline

Definition at line 12266 of file CImg.h.

References _cimg_fopcode0, _cimg_fopcode1, _cimg_fopcode2, _cimg_fopcode3, _cimg_fopcode5, _cimg_freturn, CImg< T >::_cimg_math_parser::calling_function, CImg< T >::_cimg_math_parser::code, CImg< T >::end(), CImg< T >::_cimg_math_parser::expr, i, CImg< T >::_cimg_math_parser::level, CImg< T >::_cimg_math_parser::mem, CImg< T >::_cimg_math_parser::mempos, CImg< T >::_cimg_math_parser::opcode(), CImg< T >::pixel_type(), CImg< T >::resize(), s, CImg< T >::size(), CImg< T >::transfer_to(), and CImg< T >::vector().

Referenced by CImg< T >::_cimg_math_parser::_cimg_math_parser().

12266  {
12267  if (!ss || se<=ss || !*ss) throw CImgArgumentException("CImg<%s>::%s() : Missing item, in formula '%s'.",
12269  char
12270  *const se1 = se-1, *const se2 = se-2, *const se3 = se-3, *const se4 = se-4,
12271  *const ss1 = ss+1, *const ss2 = ss+2, *const ss3 = ss+3, *const ss4 = ss+4, *const ss5 = ss+5, *const ss6 = ss+6;
12272  const char saved_char = *se; *se = 0;
12273  const unsigned int clevel = level[ss-expr], clevel1 = clevel+1;
12274 
12275  // Look for a single value, variable or reccurent expression.
12276  char end = 0; double val = 0;
12277  if (std::sscanf(ss,"%lf%c",&val,&end)==1) {
12278  const unsigned int i = mempos++;
12279  mem[i] = val;
12280  _cimg_freturn(i);
12281  }
12282  if (ss1==se) switch (*ss) {
12283  case 'x' : _cimg_freturn(0); case 'y' : _cimg_freturn(1); case 'z' : _cimg_freturn(2); case 'v' : _cimg_freturn(3);
12284  case 'w' : _cimg_freturn(4); case 'h' : _cimg_freturn(5); case 'd' : _cimg_freturn(6); case 'c' : _cimg_freturn(7);
12285  case 'e' : _cimg_freturn(9);
12286  case 'u' : _cimg_fopcode0('U');
12287  case 'g' : _cimg_fopcode0('G');
12288  case 'i' : _cimg_fopcode0('I');
12289  }
12290  if (ss1==se1 && *ss=='p' && *ss1=='i') _cimg_freturn(8); // pi-value
12291  if (ss3==se) {
12292  if (*ss=='x' && *ss1=='/' && *ss2=='w') _cimg_fopcode0('0');
12293  if (*ss=='y' && *ss1=='/' && *ss2=='h') _cimg_fopcode0('1');
12294  if (*ss=='z' && *ss1=='/' && *ss2=='d') _cimg_fopcode0('2');
12295  if (*ss=='v' && *ss1=='/' && *ss2=='c') _cimg_fopcode0('3');
12296  }
12297 
12298  // Look for a unary of binary operators.
12299  for (char *s = ss1, *ns = 0; s<se3 && (ns=std::strstr(s,"and")) && ns<se3; s=ns+3)
12300  if (level[ns-expr]==clevel) _cimg_fopcode2('A',compile(ss,ns),compile(ns+3,se));
12301  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,"&&")) && ns<se2; s=ns+2)
12302  if (level[ns-expr]==clevel) _cimg_fopcode2('A',compile(ss,ns),compile(ns+2,se));
12303  for (char *s = ss1, *ns = 0; s<se3 && (ns=std::strstr(s,"xor")) && ns<se3; s=ns+3)
12304  if (level[ns-expr]==clevel) _cimg_fopcode2('X',compile(ss,ns),compile(ns+3,se));
12305  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,"or")) && ns<se2; s=ns+2)
12306  if (level[ns-expr]==clevel) _cimg_fopcode2('O',compile(ss,ns),compile(ns+2,se));
12307  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,"||")) && ns<se2; s=ns+2)
12308  if (level[ns-expr]==clevel) _cimg_fopcode2('O',compile(ss,ns),compile(ns+2,se));
12309  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,"<=")) && ns<se2; s=ns+2)
12310  if (level[ns-expr]==clevel) _cimg_fopcode2('l',compile(ss,ns),compile(ns+2,se));
12311  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,">=")) && ns<se2; s=ns+2)
12312  if (level[ns-expr]==clevel) _cimg_fopcode2('g',compile(ss,ns),compile(ns+2,se));
12313  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,"!=")) && ns<se2; s=ns+2)
12314  if (level[ns-expr]==clevel) _cimg_fopcode2('!',compile(ss,ns),compile(ns+2,se));
12315  for (char *s = ss1, *ns = 0; s<se2 && (ns=std::strstr(s,"==")) && ns<se2; s=ns+2)
12316  if (level[ns-expr]==clevel) _cimg_fopcode2('=',compile(ss,ns),compile(ns+2,se));
12317  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,">")) && ns<se1; s=ns+1)
12318  if (level[ns-expr]==clevel) _cimg_fopcode2('>',compile(ss,ns),compile(ns+1,se));
12319  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"<")) && ns<se1; s=ns+1)
12320  if (level[ns-expr]==clevel) _cimg_fopcode2('<',compile(ss,ns),compile(ns+1,se));
12321  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"+")) && ns<se1; s=ns+1)
12322  if (level[ns-expr]==clevel) _cimg_fopcode2('+',compile(ss,ns),compile(ns+1,se));
12323  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"-")) && ns<se1; s=ns+1) {
12324  const char ps = *(ns-1);
12325  if (ps!='*' && ps!='/' && ps!='%' && ps!='^' && ps!='&' && ps!='|' && ps!='^' &&
12326  level[ns-expr]==clevel) _cimg_fopcode2('-',compile(ss,ns),compile(ns+1,se));
12327  }
12328  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"*")) && ns<se1; s=ns+1)
12329  if (level[ns-expr]==clevel) _cimg_fopcode2('*',compile(ss,ns),compile(ns+1,se));
12330  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"/")) && ns<se1; s=ns+1)
12331  if (level[ns-expr]==clevel) _cimg_fopcode2('/',compile(ss,ns),compile(ns+1,se));
12332  if (ss<se1) {
12333  if (*ss=='-') _cimg_fopcode1('o',compile(ss1,se));
12334  if (*ss=='+') _cimg_fopcode1('p',compile(ss1,se));
12335  if (*ss=='!') _cimg_fopcode1('n',compile(ss1,se));
12336  if (*ss=='~') _cimg_fopcode1('~',compile(ss1,se));
12337  }
12338  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"%")) && ns<se1; s=ns+1)
12339  if (level[ns-expr]==clevel) _cimg_fopcode2('%',compile(ss,ns),compile(ns+1,se));
12340  for (char *s = ss1, *ns = 0; s<se3 && (ns=std::strstr(s,"mod")) && ns<se3; s=ns+3)
12341  if (level[ns-expr]==clevel) _cimg_fopcode2('%',compile(ss,ns),compile(ns+3,se));
12342  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"&")) && ns<se1; s=ns+1)
12343  if (level[ns-expr]==clevel) _cimg_fopcode2('&',compile(ss,ns),compile(ns+1,se));
12344  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"|")) && ns<se1; s=ns+1)
12345  if (level[ns-expr]==clevel) _cimg_fopcode2('|',compile(ss,ns),compile(ns+1,se));
12346  for (char *s = ss1, *ns = 0; s<se1 && (ns=std::strstr(s,"^")) && ns<se1; s=ns+1)
12347  if (level[ns-expr]==clevel) _cimg_fopcode2('^',compile(ss,ns),compile(ns+1,se));
12348 
12349  // Look for a function call or a parenthesis.
12350  if (*se1==')') {
12351  if (*ss=='(') _cimg_freturn(compile(ss1,se1));
12352  if (!std::strncmp(ss,"sin(",4)) _cimg_fopcode1('s',compile(ss4,se1));
12353  if (!std::strncmp(ss,"cos(",4)) _cimg_fopcode1('c',compile(ss4,se1));
12354  if (!std::strncmp(ss,"tan(",4)) _cimg_fopcode1('t',compile(ss4,se1));
12355  if (!std::strncmp(ss,"asin(",5)) _cimg_fopcode1('S',compile(ss5,se1));
12356  if (!std::strncmp(ss,"acos(",5)) _cimg_fopcode1('C',compile(ss5,se1));
12357  if (!std::strncmp(ss,"atan(",5)) _cimg_fopcode1('T',compile(ss5,se1));
12358  if (!std::strncmp(ss,"sinh(",5)) _cimg_fopcode1('.',compile(ss5,se1));
12359  if (!std::strncmp(ss,"cosh(",5)) _cimg_fopcode1(',',compile(ss5,se1));
12360  if (!std::strncmp(ss,"tanh(",5)) _cimg_fopcode1(';',compile(ss5,se1));
12361  if (!std::strncmp(ss,"log10(",6)) _cimg_fopcode1('Q',compile(ss6,se1));
12362  if (!std::strncmp(ss,"log(",4)) _cimg_fopcode1('q',compile(ss4,se1));
12363  if (!std::strncmp(ss,"ln(",3)) _cimg_fopcode1('q',compile(ss3,se1));
12364  if (!std::strncmp(ss,"exp(",4)) _cimg_fopcode1('e',compile(ss4,se1));
12365  if (!std::strncmp(ss,"sqrt(",5)) _cimg_fopcode1('r',compile(ss5,se1));
12366  if (!std::strncmp(ss,"sign(",5)) _cimg_fopcode1('\\',compile(ss5,se1));
12367  if (!std::strncmp(ss,"rint(",5)) _cimg_fopcode1('i',compile(ss5,se1));
12368  if (!std::strncmp(ss,"abs(",4)) _cimg_fopcode1(':',compile(ss4,se1));
12369  if (!std::strncmp(ss,"atan2(",6)) {
12370  char *s1 = ss6; while (s1<se2 && (*s1!=',' || level[s1-expr]!=clevel1)) ++s1;
12371  _cimg_fopcode2('#',compile(ss6,s1),compile(s1+1,se1));
12372  }
12373  if (!std::strncmp(ss,"if(",3)) {
12374  char *s1 = ss3; while (s1<se4 && (*s1!=',' || level[s1-expr]!=clevel1)) ++s1;
12375  char *s2 = s1+1; while (s2<se2 && (*s2!=',' || level[s2-expr]!=clevel1)) ++s2;
12376  _cimg_fopcode3('?',compile(ss3,s1),compile(s1+1,s2),compile(s2+1,se1));
12377  }
12378  if (!std::strncmp(ss,"i(",2)) {
12379  unsigned int indx = 0, indy = 1, indz = 2, indv = 3, borders = 10;
12380  if (ss2!=se1) {
12381  char *s1 = ss2; while (s1<se2 && (*s1!=',' || level[s1-expr]!=clevel1)) ++s1;
12382  indx = compile(ss2,s1==se2?++s1:s1);
12383  if (s1<se1) {
12384  char *s2 = s1+1; while (s2<se2 && (*s2!=',' || level[s2-expr]!=clevel1)) ++s2;
12385  indy = compile(s1+1,s2==se2?++s2:s2);
12386  if (s2<se1) {
12387  char *s3 = s2+1; while (s3<se2 && (*s3!=',' || level[s3-expr]!=clevel1)) ++s3;
12388  indz = compile(s2+1,s3==se2?++s3:s3);
12389  if (s3<se1) {
12390  char *s4 = s3+1; while (s4<se2 && (*s4!=',' || level[s4-expr]!=clevel1)) ++s4;
12391  indv = compile(s3+1,s4==se2?++s4:s4);
12392  if (s4<se1) borders = compile(s4+1,se1);
12393  }
12394  }
12395  }
12396  }
12397  _cimg_fopcode5('(',indx,indy,indz,indv,borders);
12398  }
12399  if (!std::strncmp(ss,"min(",4) || !std::strncmp(ss,"max(",4)) {
12400  CImgList<uintT> opcode;
12401  if (mempos>=mem.size()) mem.resize(-200,1,1,1,0); const unsigned int pos = mempos++;
12402  CImg<uintT>::vector(ss[1]=='i'?'m':'M',pos).transfer_to(opcode);
12403  for (char *s = ss4; s<se; ++s) {
12404  char *ns = s; while (ns<se && (*ns!=',' || level[ns-expr]!=clevel1) && (*ns!=')' || level[ns-expr]!=clevel)) ++ns;
12405  CImg<uintT>::vector(compile(s,ns)).transfer_to(opcode);
12406  s = ns;
12407  }
12408  (opcode>'y').transfer_to(code);
12409  _cimg_freturn(pos);
12410  }
12411  }
12412  // No known item found.
12413  char *item = new char[std::strlen(ss)];
12414  std::strcpy(item,ss);
12415  *se = saved_char;
12416  throw CImgArgumentException("CImg<%s>::%s() : Invalid item '%s', in expression '%s'.",
12418  return 0;
12419  }
#define _cimg_freturn(x)
Definition: CImg.h:12224
#define _cimg_fopcode1(op, i1)
Definition: CImg.h:12226
#define _cimg_fopcode5(op, i1, i2, i3, i4, i5)
Definition: CImg.h:12229
double s
Definition: blastest.C:80
unsigned int opcode(const char op, const unsigned int arg1=0, const unsigned int arg2=0, const unsigned int arg3=0, const unsigned int arg4=0, const unsigned int arg5=0)
Definition: CImg.h:12257
iterator end()
Return an iterator pointing after the last image pixel (STL-compliant name).
Definition: CImg.h:11161
#define _cimg_fopcode3(op, i1, i2, i3)
Definition: CImg.h:12228
static const char * pixel_type()
Return the type of the pixel values.
Definition: CImg.h:11041
unsigned int size() const
Return the number of image buffer elements.
Definition: CImg.h:11075
CImg< T > & vector()
Unroll all images values into a one-column vector.
Definition: CImg.h:13334
CImg< t > & transfer_to(CImg< t > &img)
Transfer the content of the instance image into another one in a way that memory copies are avoided i...
Definition: CImg.h:10332
CImg< T > & resize(const int pdx, const int pdy=-100, const int pdz=-100, const int pdv=-100, const int interpolation_type=1, const int border_condition=-1, const bool center=false)
Resize an image.
Definition: CImg.h:16630
blockLoc i
Definition: read.cpp:79
unsigned int compile(char *const ss, char *const se)
Definition: CImg.h:12266
#define _cimg_fopcode2(op, i1, i2)
Definition: CImg.h:12227
#define _cimg_fopcode0(op)
Definition: CImg.h:12225

Here is the call graph for this function:

Here is the caller graph for this function:

double eval ( const CImg< t > &  img,
const double  x,
const double  y,
const double  z,
const double  v 
)
inline

Definition at line 12423 of file CImg.h.

References cimg_library::cimg::abs(), cimg_library::acos(), cimg_library::asin(), cimg_library::atan(), CImg< T >::_cimg_math_parser::calling_function, cimglist_for, CImg< T >::_cimg_math_parser::code, cos, cimg_library::cosh(), cimg_library::exp(), cimg_library::cimg::grand(), CImg< T >::height, i, cimg_library::log(), cimg_library::log10(), cimg_library::cimg::max(), CImg< T >::_cimg_math_parser::mem, cimg_library::cimg::min(), cimg_library::cimg::mod(), CImg< T >::_cimg_math_parser::opcode(), CImg< T >::pixel_type(), Mesquite::pow(), cimg_library::cimg::rand(), CImg< T >::_cimg_math_parser::result, cimg_library::cimg::round(), cimg_library::cimg::sign(), sin, cimg_library::sinh(), sqrt(), cimg_library::tan(), cimg_library::tanh(), v, x, y, and z.

Referenced by CImg< T >::_cimg_math_parser::eval(), CImg< T >::_marching2d_func_expr::operator()(), and CImg< T >::_marching3d_func_expr::operator()().

12423  {
12424  if (!mem) return 0;
12425  mem[0] = x; mem[1] = y; mem[2] = z; mem[3] = v;
12426  mem[4] = img.dimx(); mem[5] = img.dimy(); mem[6] = img.dimz(); mem[7] = img.dimv();
12427  cimglist_for(code,l) {
12428  const CImg<uintT> &opcode = code[l];
12429  double &res = mem[opcode(1)];
12430  switch (opcode(0)) {
12431  case 'U' : res = cimg::rand(); break;
12432  case 'G' : res = cimg::grand(); break;
12433  case 'I' : res = (double)img.atXYZV((int)x,(int)y,(int)z,(int)v,0); break;
12434  case '0' : res = x/img.dimx(); break;
12435  case '1' : res = y/img.dimy(); break;
12436  case '2' : res = z/img.dimz(); break;
12437  case '3' : res = v/img.dimv(); break;
12438  case 'A' : res = (bool)mem[opcode(2)] && (bool)mem[opcode(3)]; break;
12439  case 'X' : res = (bool)mem[opcode(2)] ^ (bool)mem[opcode(3)]; break;
12440  case 'O' : res = (bool)mem[opcode(2)] || (bool)mem[opcode(3)]; break;
12441  case 'l' : res = (mem[opcode(2)] <= mem[opcode(3)]); break;
12442  case 'g' : res = (mem[opcode(2)] >= mem[opcode(3)]); break;
12443  case '!' : res = (mem[opcode(2)] != mem[opcode(3)]); break;
12444  case '=' : res = (mem[opcode(2)] == mem[opcode(3)]); break;
12445  case '>' : res = (mem[opcode(2)] > mem[opcode(3)]); break;
12446  case '<' : res = (mem[opcode(2)] < mem[opcode(3)]); break;
12447  case '+' : res = (mem[opcode(2)] + mem[opcode(3)]); break;
12448  case '-' : res = (mem[opcode(2)] - mem[opcode(3)]); break;
12449  case '*' : res = (mem[opcode(2)] * mem[opcode(3)]); break;
12450  case '/' : res = (mem[opcode(2)] / mem[opcode(3)]); break;
12451  case 'o' : res = -mem[opcode(2)]; break;
12452  case 'p' : res = mem[opcode(2)]; break;
12453  case 'n' : res = !mem[opcode(2)]; break;
12454  case '~' : res = ~(unsigned long)mem[opcode(2)]; break;
12455  case '%' : res = cimg::mod(mem[opcode(2)],mem[opcode(3)]); break;
12456  case '&' : res = ((unsigned long)mem[opcode(2)] & (unsigned long)mem[opcode(3)]); break;
12457  case '|' : res = ((unsigned long)mem[opcode(2)] | (unsigned long)mem[opcode(3)]); break;
12458  case '^' : res = std::pow(mem[opcode(2)],mem[opcode(3)]); break;
12459  case 's' : res = std::sin(mem[opcode(2)]); break;
12460  case 'c' : res = std::cos(mem[opcode(2)]); break;
12461  case 't' : res = std::tan(mem[opcode(2)]); break;
12462  case 'S' : res = std::asin(mem[opcode(2)]); break;
12463  case 'C' : res = std::acos(mem[opcode(2)]); break;
12464  case 'T' : res = std::atan(mem[opcode(2)]); break;
12465  case '.' : res = std::sinh(mem[opcode(2)]); break;
12466  case ',' : res = std::cosh(mem[opcode(2)]); break;
12467  case ';' : res = std::tanh(mem[opcode(2)]); break;
12468  case 'Q' : res = std::log10(mem[opcode(2)]); break;
12469  case 'q' : res = std::log(mem[opcode(2)]); break;
12470  case 'e' : res = std::exp(mem[opcode(2)]); break;
12471  case 'r' : res = std::sqrt(mem[opcode(2)]); break;
12472  case '\\' : res = cimg::sign(mem[opcode(2)]); break;
12473  case 'i' : res = cimg::round(mem[opcode(2)],1); break;
12474  case '(' : {
12475  const int v = (int)mem[opcode(5)];
12476  switch ((int)mem[opcode(6)]) {
12477  case 0 : res = (double)img.linear_atXYZ((float)mem[opcode(2)],
12478  (float)mem[opcode(3)],
12479  (float)mem[opcode(4)],
12480  v<0?0:v>=img.dimv()?img.dimv()-1:v,0); break;
12481  case 1 : res = (double)img.linear_atXYZ((float)mem[opcode(2)],
12482  (float)mem[opcode(3)],
12483  (float)mem[opcode(4)],
12484  v<0?0:v>=img.dimv()?img.dimv()-1:v); break;
12485  default : res = (double)img.linear_atXYZ((float)cimg::mod(mem[opcode(2)],(double)img.dimx()),
12486  (float)cimg::mod(mem[opcode(3)],(double)img.dimy()),
12487  (float)cimg::mod(mem[opcode(4)],(double)img.dimz()),
12488  v<0?0:v>=img.dimv()?img.dimv()-1:v); break;
12489  }
12490  } break;
12491  case ':' : res = cimg::abs(mem[opcode(2)]); break;
12492  case '#' : res = std::atan2(mem[opcode(2)],mem[opcode(3)]); break;
12493  case '?' : res = mem[opcode(2)]?mem[opcode(3)]:mem[opcode(4)]; break;
12494  case 'm' : {
12495  double val = mem[opcode(2)];
12496  for (unsigned int i = 3; i<opcode.height; ++i) val = cimg::min(val,mem[opcode(i)]);
12497  res = val;
12498  } break;
12499  case 'M' : {
12500  double val = mem[opcode(2)];
12501  for (unsigned int i = 3; i<opcode.height; ++i) val = cimg::max(val,mem[opcode(i)]);
12502  res = val;
12503  } break;
12504  default :
12505  throw CImgArgumentException("CImg<%s>::%s() : Invalid opcode %d.",pixel_type(),calling_function,opcode(0));
12506  }
12507  }
12508  return mem[result];
12509  }
CImg< _cimg_Tfloat > exp(const CImg< T > &instance)
Definition: CImg.h:6016
cimg::superset< t1, t2 >::type min(const t1 &a, const t2 &b)
Return the minimum value between two numbers.
Definition: CImg.h:4728
double grand()
Return a random variable following a gaussian distribution and a standard deviation of 1...
Definition: CImg.h:4845
T mod(const T &x, const T &m)
Return the modulo of a number.
Definition: CImg.h:4788
void int int REAL REAL * y
Definition: read.cpp:74
double round(const double x, const double y, const int rounding_type=0)
Return a rounded number.
Definition: CImg.h:4871
unsigned int opcode(const char op, const unsigned int arg1=0, const unsigned int arg2=0, const unsigned int arg3=0, const unsigned int arg4=0, const unsigned int arg5=0)
Definition: CImg.h:12257
double sqrt(double d)
Definition: double.h:73
int dimy() const
Return the number of rows of the instance image (size along the Y-axis, i.e image height)...
Definition: CImg.h:11051
CImg< _cimg_Tfloat > tan(const CImg< T > &instance)
Definition: CImg.h:6046
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
CImg< _cimg_Tfloat > cosh(const CImg< T > &instance)
Definition: CImg.h:6066
static const char * pixel_type()
Return the type of the pixel values.
Definition: CImg.h:11041
CImg< _cimg_Tfloat > log(const CImg< T > &instance)
Definition: CImg.h:6021
CImg< _cimg_Tfloat > asin(const CImg< T > &instance)
Definition: CImg.h:6056
CImg< _cimg_Tfloat > sinh(const CImg< T > &instance)
Definition: CImg.h:6071
void int int int REAL REAL REAL * z
Definition: write.cpp:76
NT & sin
int dimz() const
Return the number of slices of the instance image (size along the Z-axis).
Definition: CImg.h:11056
int dimx() const
Return the number of columns of the instance image (size along the X-axis, i.e image width)...
Definition: CImg.h:11046
blockLoc i
Definition: read.cpp:79
cimg::superset< t1, t2 >::type max(const t1 &a, const t2 &b)
Return the maximum value between two numbers.
Definition: CImg.h:4749
CImg< _cimg_Tfloat > log10(const CImg< T > &instance)
Definition: CImg.h:6026
void int int REAL * x
Definition: read.cpp:74
CImg< T > & abs()
Compute the absolute value of each pixel value.
Definition: CImg.h:12570
CImg< _cimg_Tfloat > atan(const CImg< T > &instance)
Definition: CImg.h:6061
T sign(const T x)
Return the sign of a number.
Definition: CImg.h:4770
#define cimglist_for(list, l)
Definition: CImg.h:1877
Tfloat linear_atXYZ(const float fx, const float fy, const float fz, const int v, const T out_val) const
Read a pixel value using linear interpolation and Dirichlet boundary conditions (first three coordina...
Definition: CImg.h:11451
double rand()
Return a random variable between [0,1] with respect to an uniform distribution.
Definition: CImg.h:4833
CImg< _cimg_Tfloat > acos(const CImg< T > &instance)
Definition: CImg.h:6051
CImg< _cimg_Tfloat > tanh(const CImg< T > &instance)
Definition: CImg.h:6076
double pow(double value, const Exponent &exp)
NT & cos
int dimv() const
Return the number of vector channels of the instance image (size along the V-axis).
Definition: CImg.h:11061

Here is the call graph for this function:

Here is the caller graph for this function:

double eval ( const double  x,
const double  y,
const double  z,
const double  v 
)
inline

Definition at line 12512 of file CImg.h.

References CImg< T >::empty(), and CImg< T >::_cimg_math_parser::eval().

12512  {
12513  static const CImg<T> empty;
12514  return eval(empty,x,y,z,v);
12515  }
void int int REAL REAL * y
Definition: read.cpp:74
static CImg< T > & empty()
Return a reference to an empty image.
Definition: CImg.h:10351
*********************************************************************Illinois Open Source License ****University of Illinois NCSA **Open Source License University of Illinois All rights reserved ****Developed free of to any person **obtaining a copy of this software and associated documentation to deal with the Software without including without limitation the rights to and or **sell copies of the and to permit persons to whom the **Software is furnished to do subject to the following this list of conditions and the following disclaimers ****Redistributions in binary form must reproduce the above **copyright this list of conditions and the following **disclaimers in the documentation and or other materials **provided with the distribution ****Neither the names of the Center for Simulation of Advanced the University of nor the names of its **contributors may be used to endorse or promote products derived **from this Software without specific prior written permission ****THE SOFTWARE IS PROVIDED AS WITHOUT WARRANTY OF ANY **EXPRESS OR INCLUDING BUT NOT LIMITED TO THE WARRANTIES **OF FITNESS FOR A PARTICULAR PURPOSE AND **NONINFRINGEMENT IN NO EVENT SHALL THE CONTRIBUTORS OR **COPYRIGHT HOLDERS BE LIABLE FOR ANY DAMAGES OR OTHER WHETHER IN AN ACTION OF TORT OR **ARISING OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE **USE OR OTHER DEALINGS WITH THE SOFTWARE v
Definition: roccomf90.h:20
void int int int REAL REAL REAL * z
Definition: write.cpp:76
void int int REAL * x
Definition: read.cpp:74
double eval(const CImg< t > &img, const double x, const double y, const double z, const double v)
Definition: CImg.h:12423

Here is the call graph for this function:

unsigned int opcode ( const char  op,
const unsigned int  arg1 = 0,
const unsigned int  arg2 = 0,
const unsigned int  arg3 = 0,
const unsigned int  arg4 = 0,
const unsigned int  arg5 = 0 
)
inline

Definition at line 12257 of file CImg.h.

References CImg< T >::_cimg_math_parser::code, CImg< T >::_cimg_math_parser::mem, CImg< T >::_cimg_math_parser::mempos, CImg< T >::resize(), CImg< T >::size(), and CImg< T >::vector().

Referenced by CImg< T >::_cimg_math_parser::compile(), and CImg< T >::_cimg_math_parser::eval().

12258  {
12259  if (mempos>=mem.size()) mem.resize(-200,1,1,1,0);
12260  const unsigned int pos = mempos++;
12261  CImg<uintT>::vector(op,pos,arg1,arg2,arg3,arg4,arg5).transfer_to(code);
12262  return pos;
12263  }
unsigned int size() const
Return the number of image buffer elements.
Definition: CImg.h:11075
CImg< T > & vector()
Unroll all images values into a one-column vector.
Definition: CImg.h:13334
CImg< T > & resize(const int pdx, const int pdy=-100, const int pdz=-100, const int pdv=-100, const int interpolation_type=1, const int border_condition=-1, const bool center=false)
Resize an image.
Definition: CImg.h:16630

Here is the call graph for this function:

Here is the caller graph for this function:

Member Data Documentation

unsigned int result

Definition at line 12221 of file CImg.h.

Referenced by CImg< T >::_cimg_math_parser::eval().


The documentation for this struct was generated from the following file: