libmoldeo (Moldeo 1.0 Core)  1.0
libmoldeo is the group of objects and functions that executes the basic operations of Moldeo 1.0 Platform.
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
moMathFunction.h
Go to the documentation of this file.
1 /*******************************************************************************
2 
3  moMathFunction.h
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 copyright(C) 2006 Fabricio Costa
25 
26  \author Fabricio Costa
27  \author Andrés Colubri
28 
29 *******************************************************************************/
30 
246 #ifndef __MO_MATH_FUNCTION_H__
247 #define __MO_MATH_FUNCTION_H__
248 
249 #include "moTypes.h"
250 #include "moArray.h"
251 #include "moAbstract.h"
252 #include "moMath.h"
253 
254 class moParam;
255 class moConfig;
256 class moMoldeoObject;
257 class moInlet;
258 
259 typedef void moParser;
260 
262 moDeclareExportedDynamicArray( bool, moBoolArray );
263 moDeclareExportedDynamicArray( float, moFloatArray );
264 
266 
295 {
296 public:
302  moMathVariable();
303  moMathVariable(const char* p_name, double p_value0 = 0.0);
304  moMathVariable( moParam* p_Param );
305  moMathVariable( moInlet* p_Inlet );
306 
307  void SetParam( moParam* p_Param );
308  void SetInlet( moInlet* p_Inlet );
309 
314  void SetName(moText& p_name) { m_name = p_name; }
319  moText& GetName() { return m_name; }
320 
325  void SetValue(double p_value) { m_value = p_value; }
330  double GetValue();
331 
332 
333 
334 
340  double* GetValuePointer();
341 
342 private:
346  moText m_name;
350  double m_value;
351 
355  moParam* m_pParam;
356 
360  moInlet* m_pInlet;
361 };
362 
364 moDeclareExportedDynamicArray( moMathVariablePtr, moMathVariableArray );
365 
367 
376 {
377 public:
381  moMathFunction();
385  virtual ~moMathFunction();
386 
393  virtual MOboolean Init(const moText& p_Expression, moMoldeoObject* p_pMOB = NULL );
398  virtual MOboolean Finish();
399 
404  virtual void SetExpression(const moText& p_Expression) { m_Expression = p_Expression; }
409  virtual moText& GetExpression() { return m_Expression; }
414  virtual void SetParameters(double s, ...);
415 
420  virtual double Eval();
421 
426  double LastEval();
427 
433  virtual double Eval(double x, ...);
434 
440  virtual double DEval(int n, ...);
441 
446  MOuint GetParameterCount();
452  moText& GetParameterName(int i);
458  double GetParameterValue(int i);
459 
464  MOuint GetVariableCount();
470  moText& GetVariableName(int i);
476  double GetVariableValue(int i);
477 
483  double operator () (double x, ...);
484 protected:
497  moMathVariableArray m_Parameters;
501  moMathVariableArray m_Variables;
502 
503  double m_LastEval;
504 
510  virtual void OnParamUpdate() = 0;
517  virtual double OnFuncEval() = 0;
524  virtual double OnDerivEval(int n) = 0;
525 
531  virtual void BuildParamList() = 0;
537  virtual void BuildVarList() = 0;
538 
541 };
542 
544 moDeclareExportedDynamicArray( MathFunctionPtr, moMathFunctionArray );
545 
546 /*******************************************************************************
547  Algunas funciones matemáticas pre-defindas
548 *******************************************************************************/
549 
557 {
558 public:
565  MOboolean Init(moText& p_Expression);
566 private:
567  double C1, C2, C3, C4;
568 
569  void OnParamUpdate();
570  double OnFuncEval();
571  double OnDerivEval(int n);
572 
573  void BuildParamList();
574  void BuildVarList();
575 };
576 
587 {
588 public:
595  MOboolean Init(moText& p_Expression);
596 private:
597  double A, B, C, D;
598  double delta, alpha, zeta, knot;
599  double delta_inv, one_minus_knot_inv;
600  double alpha2, knot2, one_minus_knot_inv2;
601 
602  double PhiFunc1(double u);
603  double DPhiFunc1(double u);
604 
605  double PhiFunc2(double u);
606  double DPhiFunc2(double u);
607 
608  void OnParamUpdate();
609  double OnFuncEval();
610  double OnDerivEval(int n);
611 
612  void BuildParamList();
613  void BuildVarList();
614 };
615 
617 
627 {
628 public:
634  moMathVariableFactory(moMathVariableArray* p_pParArray, moMathVariableArray* p_pVarArray)
635  {
636  m_pParArray = p_pParArray;
637  m_pVarArray = p_pVarArray;
638  }
639 
646  double* CreateNewVariable(const char *p_pNewName)
647  {
648  moMathVariable* pvar = new moMathVariable(p_pNewName, 0.0);
649 
650  if (p_pNewName != NULL) {
651  if (p_pNewName[0] == '_') m_pParArray->Add(pvar); // Agregando parámetro.
652  else m_pVarArray->Add(pvar); // Agregando variable.
653  }
654  return pvar->GetValuePointer();
655  }
656 private:
657  moMathVariableArray* m_pParArray;
658  moMathVariableArray* m_pVarArray;
659 };
660 
664 double* AddParserVariableFunction(const char *p_pVarName, void *p_pUserData);
665 
670 {
671 public:
672 
674 
675 
682  virtual MOboolean Init(const moText& p_Expression, moMoldeoObject* p_pMOB = NULL );
687  MOboolean Finish();
688 protected:
689 
690  double x;
691 
693 
694  void AddMathFunctions();
695  void AddMathConstants();
696  MOboolean CheckVariables();
697 
698  void OnParamUpdate() {}
699  double OnFuncEval();
700  double OnDerivEval(int n) { return n; }
701 
702  void BuildParamList() {}
703  void BuildVarList() {}
704 };
705 
706 
707 
708 #endif
709 
moMathVariableArray m_Variables
The Blue component of a color.
Definition: moOGLFT.h:88
moMathFunction * MathFunctionPtr
moMathVariable * moMathVariablePtr
virtual MOboolean Finish()
virtual void SetExpression(const moText &p_Expression)
Conector Inlet, conector que recibe datos.
Definition: moConnectors.h:374
virtual MOboolean Finish()
Finaliza el objeto, libera recursos.
Definition: moAbstract.cpp:147
double OnDerivEval(int n)
moParser * m_pParser
#define MOboolean
Definition: moTypes.h:385
moText & GetName()
virtual void OnParamUpdate()=0
void SetValue(double p_value)
double * GetValuePointer()
Clase base abstracta de donde deben derivar los objetos [virtual pura].
Definition: moAbstract.h:191
virtual MOboolean Init()
Inicializa el objeto.
Definition: moAbstract.cpp:141
#define LIBMOLDEO_API
Definition: moTypes.h:180
moMathFunction * BuiltInMathFunctionFactory(const moText &p_expr)
void moParser
clase de para manejar textos
Definition: moText.h:75
void SetParam(moParam *p_Param)
moMathVariable
double * CreateNewVariable(const char *p_pNewName)
moConfig * m_pConfig
void SetName(moText &p_name)
virtual void BuildVarList()=0
Clase Base para Objetos Moldeo ( moEffect, moIODevice, moResource, moConsole )
The Alpha (or transparency) of a color.
Definition: moOGLFT.h:89
moMathVariableArray m_Parameters
void SetInlet(moInlet *p_Inlet)
virtual double OnFuncEval()=0
moMoldeoObject * m_pMOB
moMathVariableFactory(moMathVariableArray *p_pParArray, moMathVariableArray *p_pVarArray)
#define MOuint
Definition: moTypes.h:387
Real operator()(int iRow, int iCol) const
double * AddParserVariableFunction(const char *p_pVarName, void *p_pUserData)
virtual double OnDerivEval(int n)=0
moMathFunction
virtual void BuildParamList()=0
virtual moText & GetExpression()
moDeclareExportedDynamicArray(MOuint, moIntArray)
almacena la configuración de los parámetros de un objeto en un archivo XML
Definition: moConfig.h:193