libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo es el conjunto de objetos y funciones, que permiten ejecutar las operaciones básicas de la plataforma Moldeo, y que compone su núcleo.
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Amigas 'defines' Grupos Páginas
moMathFunction.cpp
Ir a la documentación de este archivo.
1 /*******************************************************************************
2 
3  moMathFunction.cpp
4 
5  ****************************************************************************
6  * *
7  * This source is free software; you can redistribute it and/or modify *
8  * it under the terms of the GNU General Public License as published by *
9  * the Free Software Foundation; either version 2 of the License, or *
10  * (at your option) any later version. *
11  * *
12  * This code is distributed in the hope that it will be useful, but *
13  * WITHOUT ANY WARRANTY; without even the implied warranty of *
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
15  * General Public License for more details. *
16  * *
17  * A copy of the GNU General Public License is available on the World *
18  * Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also *
19  * obtain it by writing to the Free Software Foundation, *
20  * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
21  * *
22  ****************************************************************************
23 
24  Copyright(C) 2006 Fabricio Costa
25 
26  Authors:
27  Fabricio Costa
28  Andrés Colubri
29 
30 *******************************************************************************/
31 
32 #include "moTypes.h"
33 #include "muParser.h"
34 
35 #include <cstdarg>
36 
37 #include "moConfig.h"
38 #include "moMoldeoObject.h"
39 #include "moMathFunction.h"
40 
41 #include "moArray.h"
42 moDefineDynamicArray( moIntArray )
43 moDefineDynamicArray( moBoolArray )
44 moDefineDynamicArray( moFloatArray )
45 moDefineDynamicArray( moMathVariableArray )
46 moDefineDynamicArray( moMathFunctionArray )
47 
48 
50 {
51  if (moText(p_expr) == moText("CubicInterpolant(x)")) return new moCubicInterpolant();
52  if (moText(p_expr) == moText("TautInterpolant(x)")) return new moTautInterpolant();
53  return NULL;
54 }
55 
56 double* AddParserVariableFunction(const char *p_pVarName, void *p_pUserData)
57 {
58  moMathVariableFactory *pFactory = (moMathVariableFactory*)p_pUserData;
59  return pFactory->CreateNewVariable(p_pVarName);
60 }
61 
62 
64 
65  m_pParam = NULL;
66  m_pInlet = NULL;
67 }
68 
69 
70 moMathVariable::moMathVariable( const char* p_name, double p_value0 ) {
71 
72  m_name = (char*)p_name;
73  m_value = p_value0;
74  m_pParam = NULL;
75  m_pInlet = NULL;
76 
77 }
78 
79 
81 
82  SetParam( p_Param );
83 
84 }
85 
87 
88  SetInlet( p_Inlet );
89 
90 }
91 
92 void
94 
95 
96  if (p_Param!=NULL) {
97 
98  m_pParam = p_Param;
99  m_name = m_pParam->GetParamDefinition().GetName();
100  GetValue();
101 
102  }
103 }
104 
105 void
107 
108 
109  if (p_Inlet!=NULL) {
110 
111  m_pInlet = p_Inlet;
112  m_name = m_pInlet->GetConnectorLabelName();
113  GetValue();
114 
115  }
116 }
117 
118 
120 {
121  if (m_pParam) {
122  moData* pData = m_pParam->GetData();
123  if (pData)
124  m_value = pData->Double();
125  } else if (m_pInlet) {
126  moData* pData = m_pInlet->GetData();
127  if (pData)
128  m_value = pData->Double();
129  }
130 
131  return m_value;
132 }
133 
135 
136  GetValue();
137 
138  return &m_value;
139 }
140 
141 
142 /*******************************************************************************
143  Implementación de moMathFunction
144 *******************************************************************************/
145 
147 {
148  m_Expression = moText("");
149  m_EmptyName = moText("");
150  m_pConfig = NULL;
151  m_pMOB = NULL;
152  m_LastEval = 0.0;
153 }
154 
156 {
157  Finish();
158 }
159 #include "moDebugManager.h"
160 MOboolean moMathFunction::Init( const moText& p_Expression, moMoldeoObject* p_pMOB )
161 {
162  SetExpression(p_Expression);
163  BuildParamList();
164  BuildVarList();
165 
167  if (p_pMOB) {
168  m_pMOB = p_pMOB;
170  }
171 
172  if ( m_pConfig ) {
173  moParams& Params( m_pConfig->GetParams() );
174  for( MOuint i=0; i < m_Variables.Count(); i++ ) {
175 
176  moMathVariable* pVariable = m_Variables[i];
177 
178 
180  for( MOuint p=0; p<Params.Count(); p++ ) {
181 
182  moParam& param( Params[p] );
183 
184  if ( param.GetParamDefinition().GetName() == pVariable->GetName() ) {
185 
187  pVariable->SetParam( param.GetPtr() );
188 
189  }
190 
191  }
192 
194  for( MOuint m=0; m<m_pMOB->GetInlets()->Count(); m++ ) {
195 
196  moInlet* pInlet = m_pMOB->GetInlets()->Get(m);
197 
198  if ( pInlet->GetConnectorLabelName() == pVariable->GetName() ) {
200  MODebug2->Log( moText("moMathFunction::Init > assigning variable [") + pVariable->GetName() + moText("] to inlet with the same name. Inlet index is: " + IntToStr(m)) );
201  pVariable->SetInlet( pInlet );
202  }
203 
204 
205  }
206 
207  }
208 
209  }
210 
211  return true;
212 }
213 
215 {
216  return true;
217 }
218 
219 void moMathFunction::SetParameters(double s, ...)
220 {
221  int num = m_Parameters.Count(); // Number of parameters. Must be equal to the number of arguments.
222 
223  if (num>0) {
224  va_list arguments; // A place to store the list of arguments
225 
226  if (m_Parameters[0])
227  m_Parameters[0]->SetValue(s);
228 
229  va_start(arguments, s); // Initializing arguments to store all values after s
230  for (int i = 1; i < num; i++)
231  if (m_Parameters[i] != NULL)
232  m_Parameters[i]->SetValue(va_arg(arguments, double));
233  va_end (arguments); // Cleans up the list
234  }
235  OnParamUpdate();
236 }
237 
239 
240  int num = m_Variables.Count();
241 
242  if (num>0) {
243  for (int i = 0; i < num; i++) {
244  if (m_Variables[i] != NULL) {
246  m_Variables[i]->GetValue();
247  }
248  }
249  }
250 
251 
252  return OnFuncEval();
253 }
254 
255 
257  return m_LastEval;
258 }
259 
260 double moMathFunction::Eval(double x, ...)
261 {
262  int num = m_Variables.Count(); // Number of variables. Must be equal to the number of arguments.
263 
264  if (num>0) {
265  if (m_Variables[0])
266  m_Variables[0]->SetValue(x);
267 
268  va_list arguments; // A place to store the list of arguments
269  va_start(arguments, x); // Initializing arguments to store all values after x.
270  for (int i = 1; i < num; i++)
271  if (m_Variables[i] != NULL)
272  m_Variables[i]->SetValue(va_arg(arguments, double));
273  va_end (arguments); // Cleans up the list
274  }
275  return OnFuncEval();
276 }
277 
278 double moMathFunction::DEval(int n, ...)
279 {
280  int num = m_Variables.Count(); // Number of variables. Must be equal to the number of arguments.
281 
282  if (num>0) {
283  va_list arguments; // A place to store the list of arguments
284 
285  va_start(arguments, n); // Initializing arguments to store all values after n.
286  for (int i = 0; i < num; i++)
287  if (m_Variables[i] != NULL)
288  m_Variables[i]->SetValue(va_arg(arguments, double));
289  va_end (arguments); // Cleans up the list
290  }
291  return OnDerivEval(n);
292 }
293 
295 {
296  return m_Parameters.Count();
297 }
298 
300 {
301  if (m_Parameters[i] != NULL) return m_Parameters[i]->GetName();
302  else return m_EmptyName;
303 }
304 
306 {
307  if (m_Parameters[i] != NULL) return m_Parameters[i]->GetValue();
308  else return 0;
309 }
310 
312 {
313  return m_Variables.Count();
314 }
315 
317 {
318  if (m_Variables[i] != NULL) return m_Variables[i]->GetName();
319  else return m_EmptyName;
320 }
321 
323 {
324  if (m_Variables[i] != NULL) return m_Variables[i]->GetValue();
325  else return 0;
326 }
327 
328 double moMathFunction::operator () (double x, ...)
329 {
330  int num = m_Variables.Count(); // Number of variables. Must be equal to the number of arguments.
331  if (num>0) {
332  va_list arguments; // A place to store the list of arguments
333 
334  m_Variables[0]->SetValue(x);
335 
336  va_start(arguments, x); // Initializing arguments to store all values after x.
337  for (int i = 1; i < num; i++)
338  if (m_Variables[i] != NULL)
339  m_Variables[i]->SetValue(va_arg(arguments, double));
340  va_end (arguments); // Cleans up the list
341  }
342  return OnFuncEval();
343 }
344 
345 /*******************************************************************************
346  Implementación de moCubicInterpolant
347 *******************************************************************************/
348 
350 {
351  if (p_Expression == moText("CubicInterpolant(x)"))
352  {
353  moMathFunction::Init(p_Expression);
354 
355  // Asignando parámetros por defecto:
356  // x0 = 0.0, y0 = 1.0, d0 = 0.0
357  // x1 = 1.0, y1 = 1.0, d1 = 1.0
358  SetParameters(0.0, 0.0, 0.0, 1.0, 1.0, 1.0);
359 
360  return true;
361  }
362  else return false;
363 }
364 
365 void moCubicInterpolant::OnParamUpdate()
366 {
367  double x0 = m_Parameters[0]->GetValue();
368  double y0 = m_Parameters[1]->GetValue();
369  double d0 = m_Parameters[2]->GetValue();
370 
371  double x1 = m_Parameters[3]->GetValue();
372  double y1 = m_Parameters[4]->GetValue();
373  double d1 = m_Parameters[5]->GetValue();
374 
375  double delta = x1 - x0;
376  double deriv = (y0 - y1) /(x0 - x1);
377 
378  C4 = (d0 + d1 - 2 * deriv) /(delta * delta);
379  C3 = (deriv - d0) / delta - C4 * delta;
380  C2 = d0;
381  C1 = y0;
382 }
383 
384 double moCubicInterpolant::OnFuncEval()
385 {
386  // Aqui calculamos delta = x - x0:
387  double delta = m_Variables[0]->GetValue() - m_Parameters[0]->GetValue();
388  double sqr_delta = delta * delta;
389 
390  return C1 + C2 * delta + C3 * sqr_delta + C4 * sqr_delta * delta;
391 }
392 
393 double moCubicInterpolant::OnDerivEval(int n)
394 {
395  if (n == 0) return OnFuncEval();
396  else if (n < 4)
397  {
398  double delta;
399 
400  // Aqui calculamos delta = x - x0:
401  if (n < 3) delta = m_Variables[0]->GetValue() - m_Parameters[0]->GetValue();
402  else delta = 0; // La derivada de orden 3 es constante, por lo que no necesitamos 'delta'.
403 
404  if (n == 1) return C2 + 2 * C3 * delta + 3 * C4 * delta * delta;
405  else if (n == 2) return 2 * C3 + 6 * C4 * delta;
406  else return 6 * C4;
407  }
408  else return 0;
409 }
410 
411 void moCubicInterpolant::BuildParamList()
412 {
413  m_Parameters.Add(new moMathVariable("_x0"));
414  m_Parameters.Add(new moMathVariable("_y0"));
415  m_Parameters.Add(new moMathVariable("_d0"));
416  m_Parameters.Add(new moMathVariable("_x1"));
417  m_Parameters.Add(new moMathVariable("_y1"));
418  m_Parameters.Add(new moMathVariable("_d1"));
419 }
420 
421 void moCubicInterpolant::BuildVarList()
422 {
423  m_Variables.Add(new moMathVariable("x"));
424 }
425 
426 /*******************************************************************************
427  Implementación de moTautInterpolant
428 *******************************************************************************/
429 
431 {
432  if (p_Expression == moText("TautInterpolant(x)"))
433  {
434  moMathFunction::Init(p_Expression);
435 
436  // Asignando parámetros por defecto:
437  // x0 = 0.0, y0 = 1.0, d0 = 0.0
438  // x1 = 1.0, y1 = 1.0, d1 = 1.0
439  // gamma = 1.5
440  SetParameters(0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 1.5);
441 
442  return true;
443  }
444  else return false;
445 }
446 
447 double moTautInterpolant::PhiFunc1(double u)
448 {
449  double v = max(one_minus_knot_inv *(u - knot), 0.0);
450  return alpha * u * u * u + (1 - alpha) * v * v * v;
451 }
452 
453 double moTautInterpolant::DPhiFunc1(double u)
454 {
455  double s, v, dv;
456  s = one_minus_knot_inv *(u - knot);
457  v = max(s, 0.0);
458  if (0 <= s) dv = one_minus_knot_inv; else dv = 0;
459  return 3 * (alpha * u * u + (1 - alpha) * v * v * dv);
460 }
461 
462 double moTautInterpolant::PhiFunc2(double u)
463 {
464  double v = max(one_minus_knot_inv2 *(u - knot2), 0.0);
465  return alpha2 * u * u * u + (1 - alpha2) * v * v * v;
466 }
467 
468 double moTautInterpolant::DPhiFunc2(double u)
469 {
470  double s, v, dv;
471  s = one_minus_knot_inv2 *(u - knot2);
472  v = max(s, 0.0);
473  if (0 <= s) dv = one_minus_knot_inv2; else dv = 0;
474  return 3 * (alpha2 * u * u + (1 - alpha2) * v * v * dv);
475 }
476 
477 void moTautInterpolant::OnParamUpdate()
478 {
479  double x0 = m_Parameters[0]->GetValue();
480  double y0 = m_Parameters[1]->GetValue();
481  double Dy0 = m_Parameters[2]->GetValue();
482 
483  double x1 = m_Parameters[3]->GetValue();
484  double y1 = m_Parameters[4]->GetValue();
485  double Dy1 = m_Parameters[5]->GetValue();
486 
487  double gamma = m_Parameters[6]->GetValue();
488 
489  double diff, s0, s1;
490  double zeta2;
491  double d1, d2, a, b;
492 
493  delta = x1 - x0; delta_inv = 1.0 / delta;
494 
495  diff = y1 - y0;
496 
497  s0 = Dy0 * delta - diff;
498  s1 = Dy1 * delta - diff;
499 
500  // Parameters of Phi 1 function.
501  zeta = s1 / (s1 - s0);
502  knot = 1.0 - gamma * min(1.0 - zeta, 1.0 / 3.0);
503  knot = max(1e-10, knot); knot = min(1.0 - 1e-10, knot); // Keeping the knot in(0, 1).
504  one_minus_knot_inv = 1.0 /(1.0 - knot);
505  alpha = (1.0 - gamma / 3.0) / knot;
506  d1 = DPhiFunc1(1);
507 
508  // Parameters of Phi 2 function.
509  zeta2 = 1.0 - zeta;
510  knot2 = 1.0 - gamma * min(1.0 - zeta2, 1.0 / 3.0);
511  knot2 = max(1e-10, knot2); knot2 = min(1.0 - 1e-10, knot2); // Keeping the knot in(0, 1).
512  one_minus_knot_inv2 = 1.0 /(1.0 - knot2);
513  alpha2 = (1.0 - gamma / 3.0) / knot2;
514  d2 = DPhiFunc2(1);
515 
516  a = d1 - 1.0;
517  b = 1.0 - d2;
518 
519  // Coefficients of the taut spline.
520  if (a * b == -1)
521  {
522  // The coefficient D is indetermined. A interpolating spline exists only
523  // if -a * s0 == s1.
524  D = 0.0;
525  }
526  else D = (s1 + a * s0) / (a * b + 1);
527  C = b * D - s0;
528  B = diff + D - C;
529  A = y0 - D;
530 }
531 
532 double moTautInterpolant::OnFuncEval()
533 {
534  double u = delta_inv *(m_Variables[0]->GetValue() - m_Parameters[0]->GetValue());
535  return A + B * u + C * PhiFunc1(u) + D * PhiFunc2(1 - u);
536 }
537 
538 double moTautInterpolant::OnDerivEval(int n)
539 {
540  if (n == 0) return OnFuncEval();
541  else if (n < 2)
542  {
543  double u = delta_inv *(m_Variables[0]->GetValue() - m_Parameters[0]->GetValue());
544  return (B + C * DPhiFunc1(u) - D * DPhiFunc2(1 - u)) * delta_inv;
545  }
546  else
547  // Calculation of derivatives of order 2 and 3 is not implemented.
548  return 0;
549 }
550 
551 void moTautInterpolant::BuildParamList()
552 {
553  m_Parameters.Add(new moMathVariable("_x0"));
554  m_Parameters.Add(new moMathVariable("_y0"));
555  m_Parameters.Add(new moMathVariable("_d0"));
556  m_Parameters.Add(new moMathVariable("_x1"));
557  m_Parameters.Add(new moMathVariable("_y1"));
558  m_Parameters.Add(new moMathVariable("_d1"));
559  m_Parameters.Add(new moMathVariable("_gamma"));
560 }
561 
562 void moTautInterpolant::BuildVarList()
563 {
564  m_Variables.Add(new moMathVariable("x"));
565 }
566 
567 /*******************************************************************************
568  Implementación de moParserFunction
569 *******************************************************************************/
570 
572 
573  m_pConfig = NULL;
574  m_pMOB = NULL;
575 
576 }
577 
578 
580 {
581  mu::Parser* pParser = new mu::Parser();
582  m_pParser = (moParser*) pParser;
583  m_pMOB = p_pMOB;
584  if (m_pMOB) m_pConfig = m_pMOB->GetConfig();
585 
587 
588  if (pParser) {
589  pParser->SetVarFactory(AddParserVariableFunction, pVarFactory);
590 
593 
594  m_Expression = p_Expression;
595  char* expr = (char*)(m_Expression);
596 
597  try {
598  pParser->SetExpr(expr);
599  pParser->Eval();
600  }
601  catch ( mu::ParserError Exc) {
602  moText msgexpr = (char*)Exc.GetExpr().c_str();
603  moText msgerror = (char*)Exc.GetMsg().c_str();
604  moText mobname = "undefined MOB";
605  if (p_pMOB) mobname = p_pMOB->GetLabelName();
606  MODebug2->Error( mobname + moText(" > ") + (moText)msgexpr + moText(":") + (moText)msgerror );
607  delete pVarFactory;
608  return false;
609  }
610 
611  delete pVarFactory;
612 
613  }
614 
616 
617  if ( m_pConfig ) {
618  moParams& Params( m_pConfig->GetParams() );
619  for( MOuint i=0; i < m_Variables.Count(); i++ ) {
620 
621  moMathVariable* pVariable = m_Variables[i];
622 
624  for( MOuint p=0; p<Params.Count(); p++ ) {
625 
626  moParam& param( Params[p] );
627 
628  if ( param.GetParamDefinition().GetName() == pVariable->GetName() ) {
629 
631  MODebug2->Log( moText("moParserFunction::Init > assigning variable [") + pVariable->GetName() + moText(" to parameter with the same name.") );
632  pVariable->SetParam( param.GetPtr() );
633 
634  }
635 
636  }
637 
639  for( MOuint m=0; m<m_pMOB->GetInlets()->Count(); m++ ) {
640 
641  moInlet* pInlet = m_pMOB->GetInlets()->Get(m);
642 
643  if ( pInlet->GetConnectorLabelName() == pVariable->GetName() ) {
644  MODebug2->Log( moText("moParserFunction::Init > assigning variable [") + pVariable->GetName() + moText("] to inlet with the same name. Inlet index is: " + IntToStr(m)) );
645  pVariable->SetInlet( pInlet );
646  }
647 
648 
649  }
650 
651  }
652 
653  }
654 
655  return CheckVariables();
656 }
657 
659 {
660  if (m_pParser) {
661  mu::Parser* pParser = (mu::Parser*) m_pParser;
662  delete pParser;
663  m_pParser = NULL;
664  }
665  return true;
666 }
667 
669 {
670  mu::Parser* pParser = (mu::Parser*) m_pParser;
671  if (pParser) {
672  pParser->DefineFun( "UnitRandom", (mu::fun_type1) moMathd::UnitRandom, false);
673  pParser->DefineFun("SymmetricRandom", (mu::fun_type1) moMathd::SymmetricRandom, false);
674  pParser->DefineFun("IntervalRandom", (mu::fun_type3) moMathd::IntervalRandom, false);
675 
676  pParser->DefineFun("FastSin0", moMathd::FastSin0, false);
677  pParser->DefineFun("FastSin1", moMathd::FastSin1, false);
678 
679  pParser->DefineFun("FastCos0", moMathd::FastCos0, false);
680  pParser->DefineFun("FastCos1", moMathd::FastCos1, false);
681 
682  pParser->DefineFun("FastTan0", moMathd::FastTan0, false);
683  pParser->DefineFun("FastTan1", moMathd::FastTan1, false);
684 
685  pParser->DefineFun("FastInvSin0", moMathd::FastInvSin0, false);
686  pParser->DefineFun("FastInvSin1", moMathd::FastInvSin1, false);
687 
688  pParser->DefineFun("FastInvCos0", moMathd::FastInvCos0, false);
689  pParser->DefineFun("FastInvCos1", moMathd::FastInvCos1, false);
690 
691  pParser->DefineFun("FastInvTan0", moMathd::FastInvTan0, false);
692  pParser->DefineFun("FastInvTan1", moMathd::FastInvTan1, false);
693 
694  pParser->DefineFun("FastInvSqrt", moMathd::FastInvSqrt, false);
695 
696  pParser->DefineFun("FastNegExp0", moMathd::FastNegExp0, false);
697  pParser->DefineFun("FastNegExp1", moMathd::FastNegExp1, false);
698  pParser->DefineFun("FastNegExp2", moMathd::FastNegExp2, false);
699  pParser->DefineFun("FastNegExp3", moMathd::FastNegExp3, false);
700 
701  pParser->DefineFun("DegToRad", moMathd::DegToRad, false);
702  pParser->DefineFun("RadToDeg", moMathd::RadToDeg, false);
703  }
704 }
705 
707 {
708  mu::Parser* pParser = (mu::Parser*) m_pParser;
709  if (pParser) {
710  pParser->DefineConst("EPSILON", moMathd::EPSILON);
711  pParser->DefineConst("ZERO_TOLERANCE", moMathd::ZERO_TOLERANCE);
712  pParser->DefineConst("MAX_REAL", moMathd::MAX_REAL);
713  pParser->DefineConst("PI", moMathd::PI);
714  pParser->DefineConst("TWO_PI", moMathd::TWO_PI);
715  pParser->DefineConst("HALF_PI", moMathd::HALF_PI);
716  pParser->DefineConst("INV_PI", moMathd::INV_PI);
717  pParser->DefineConst("INV_TWO_PI", moMathd::INV_TWO_PI);
718  pParser->DefineConst("DEG_TO_RAD", moMathd::DEG_TO_RAD);
719  pParser->DefineConst("RAD_TO_DEG", moMathd::RAD_TO_DEG);
720  pParser->DefineConst("LN_2", moMathd::LN_2);
721  pParser->DefineConst("LN_10", moMathd::LN_10);
722  pParser->DefineConst("INV_LN_2", moMathd::INV_LN_2);
723  pParser->DefineConst("INV_LN_10", moMathd::INV_LN_10);
724  }
725 }
726 
728 {
729  int iNumVar;
730  int nvar, npar;
731  nvar = npar = 0;
732 
733  mu::Parser* pParser = (mu::Parser*) m_pParser;
734 
735  if (pParser) {
736 
737  mu::varmap_type variables = pParser->GetVar();
738 
739  iNumVar = (int)variables.size();
740 
741  mu::varmap_type::const_iterator item = variables.begin();
742 
743  for (; item!=variables.end(); ++item)
744  {
745  if (item->first[0] == '_')
746  {
747  npar++;
748  }
749  else
750  {
751  nvar++;
752  }
753  }
754 
755  if (nvar != (MOint)m_Variables.Count())
756  {
757  MODebug2->Push("Error in number of parser variables.");
758  return false;
759  }
760 
761  if (npar != (MOint)m_Parameters.Count())
762  {
763  MODebug2->Push("Error in number of parser parameters.");
764  return false;
765  }
766  return true;
767  }
768  return false;
769 }
770 
771 
773 
774  mu::Parser* pParser = (mu::Parser*) m_pParser;
775  if (pParser) {
776 
777  try {
778  m_LastEval = pParser->Eval();
779  }
780  catch ( mu::ParserError Exc) {
781  moText msgexpr = (char*)Exc.GetExpr().c_str();
782  moText msgerror = (char*)Exc.GetMsg().c_str();
783  moText mobname = "undefined MOB";
784  if (m_pMOB) mobname = m_pMOB->GetLabelName();
785  MODebug2->Error( mobname + moText(" > ") + (moText)msgexpr + moText(":") + (moText)msgerror );
786  m_LastEval = 0.0;
787  }
788 
789  }
790 
791  return m_LastEval;
792 
793 }
794 
moMathVariableArray m_Variables
MOuint GetVariableCount()
static double FastInvTan1(doublefValue)
Definition: moMath.h:682
MOuint GetParameterCount()
var b
Definition: jquery.js:16
const moText & GetLabelName() const
static const double HALF_PI
Definition: moMath.h:828
moDefineDynamicArray(moIntArray) moDefineDynamicArray(moBoolArray) moDefineDynamicArray(moFloatArray) moDefineDynamicArray(moMathVariableArray) moDefineDynamicArray(moMathFunctionArray) moMathFunction *BuiltInMathFunctionFactory(const moText &p_expr)
virtual MOboolean Finish()
void Error(moText p_text)
Anuncia y registra un error.
Definition: moAbstract.cpp:79
static double FastCos1(doublefAngle)
Definition: moMath.h:513
double GetParameterValue(int i)
static double FastTan1(doublefAngle)
Definition: moMath.h:550
static double FastTan0(doublefAngle)
Definition: moMath.h:534
virtual void SetExpression(const moText &p_Expression)
moParams & GetParams()
Devuelve el puntero al arreglo de parámetros.
Definition: moConfig.cpp:977
Conector Inlet, conector que recibe datos.
Definition: moConnectors.h:374
function p(by, bw, bv)
Definition: jquery.js:28
static double FastInvSin1(doublefValue)
Definition: moMath.h:592
static double FastNegExp2(doublefValue)
Definition: moMath.h:757
virtual double DEval(int n,...)
static const double RAD_TO_DEG
Definition: moMath.h:832
moParser * m_pParser
static const double INV_TWO_PI
Definition: moMath.h:830
#define MOboolean
Definition: moTypes.h:385
static double FastInvCos1(doublefValue)
Definition: moMath.h:636
moText & GetName()
function a
Definition: jquery.js:41
virtual void OnParamUpdate()=0
function x(bx)
Definition: jquery.js:30
moInlets * GetInlets()
static const double TWO_PI
Definition: moMath.h:827
moParam * GetPtr()
Definition: moParam.cpp:1275
moText & GetParameterName(int i)
double * GetValuePointer()
virtual MOboolean Init()
Inicializa el objeto.
Definition: moAbstract.cpp:141
static double FastNegExp0(doublefValue)
Definition: moMath.h:717
static const double ZERO_TOLERANCE
Definition: moMath.h:824
static double SymmetricRandom(unsigned int uiSeed=0)
Definition: moMath.h:396
moMathFunction * BuiltInMathFunctionFactory(const moText &p_expr)
const moText & GetName() const
Definition: moParam.h:266
void moParser
static const double EPSILON
Definition: moMath.h:823
clase de para manejar textos
Definition: moText.h:75
void SetParam(moParam *p_Param)
moMathVariable
static const double LN_2
Definition: moMath.h:833
double * CreateNewVariable(const char *p_pNewName)
double GetVariableValue(int i)
moTypes MOint moText moParamIndex moParamReference int iRow int int i int i
Definition: all_f.js:18
static double DegToRad(doubleiDeg)
Definition: moMath.h:805
void Log(moText p_text)
Escribe un mensaje en el archivo de registro (log)
Definition: moAbstract.cpp:123
static const double MAX_REAL
Definition: moMath.h:825
moText0 moText
Definition: moText.h:291
moConfig * m_pConfig
static double FastNegExp3(doublefValue)
Definition: moMath.h:780
#define MOint
Definition: moTypes.h:388
virtual void BuildVarList()=0
virtual void SetParameters(double s,...)
a max
Definition: jquery.js:72
Clase Base para Objetos Moldeo ( moEffect, moIODevice, moResource, moConsole )
static double FastCos0(doublefAngle)
Definition: moMath.h:498
static const double INV_LN_10
Definition: moMath.h:836
static double FastSin0(doublefAngle)
Definition: moMath.h:460
moMathVariableArray m_Parameters
static const double LN_10
Definition: moMath.h:834
static double FastInvTan0(doublefValue)
Definition: moMath.h:662
void SetInlet(moInlet *p_Inlet)
virtual ~moMathFunction()
static double RadToDeg(doubleiRad)
Definition: moMath.h:815
MOboolean CheckVariables()
double * AddParserVariableFunction(const char *p_pVarName, void *p_pUserData)
function e
Definition: jquery.js:71
MOdouble Double() const
Definition: moValue.cpp:859
static moDebug * MODebug2
Clase de impresión de errores para depuración.
Definition: moAbstract.h:225
moConfig * GetConfig()
virtual const moText & GetConnectorLabelName() const
virtual double OnFuncEval()=0
static double FastInvSqrt(doublefValue)
moMoldeoObject * m_pMOB
virtual double Eval()
void Push(moText p_text)
Apila el mensaje dentro de la pila de mensajes.
Definition: moAbstract.h:115
moParamDefinition & GetParamDefinition()
Definition: moParam.cpp:1268
static double FastInvSin0(doublefValue)
Definition: moMath.h:574
static double FastInvCos0(doublefValue)
Definition: moMath.h:618
static const double INV_LN_2
Definition: moMath.h:835
#define MOuint
Definition: moTypes.h:387
LIBMOLDEO_API moText0 IntToStr(int a)
Definition: moText.cpp:1070
static const double PI
Definition: moMath.h:826
static double FastNegExp1(doublefValue)
Definition: moMath.h:736
static double IntervalRandom(doublefMin, doublefMax, unsigned int uiSeed=0)
Definition: moMath.h:414
moData * GetData()
Definition: moParam.cpp:1286
moText & GetVariableName(int i)
static const double DEG_TO_RAD
Definition: moMath.h:831
moData * GetData()
virtual double OnDerivEval(int n)=0
double operator()(double x,...)
moMathFunction
virtual void BuildParamList()=0
static double UnitRandom(unsigned int uiSeed=0)
Definition: moMath.h:380
moPort const
Definition: all_14.js:19
static double FastSin1(doublefAngle)
Definition: moMath.h:476
static const double INV_PI
Definition: moMath.h:829