00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 #include "ArithmeticPrimFunc.h"
00018 #include "Primitive.h"
00019 #include "SceneGraph.h"
00020 
00021 using namespace Fluxus;
00022 
00023 ArithmeticPrimFunc::ArithmeticPrimFunc()
00024 {
00025 }
00026 
00027 ArithmeticPrimFunc::~ArithmeticPrimFunc()
00028 {
00029 }
00030 
00031 void ArithmeticPrimFunc::Run(Primitive &prim, const SceneGraph &world)
00032 {
00033     string op = GetArg<string>("operator",string("add"));
00034     PData *src = prim.GetDataRaw(GetArg<string>("src",string("p")));
00035     PData *other = NULL;
00036     if (ArgExists<string>("other"))
00037     {
00038         other = prim.GetDataRaw(GetArg<string>("other",string("p")));
00039     }
00040 
00041     
00042     if (src!=NULL)
00043     {
00044         if (other!=NULL) 
00045         {
00046             if (src->Size()==other->Size()) 
00047             {
00048                 prim.SetDataRaw(GetArg<string>("dst",string("p")),
00049                     OperatorFirst(op,src,other));
00050             }
00051         }
00052         else if (ArgExists<float>("constant"))  
00053         {
00054             prim.SetDataRaw(GetArg<string>("dst",string("p")),
00055                 OperatorFloatFirst(op,src,GetArg<float>("constant",1)));
00056         }
00057     }
00058 }
00059 
00060 PData *ArithmeticPrimFunc::OperatorFirst(const string &op, PData* first, PData *second)
00061 {
00062     TypedPData<dVector> *data = dynamic_cast<TypedPData<dVector>*>(first);  
00063     if (data) return OperatorSecond<dVector>(op,data,second);
00064     else
00065     {
00066         TypedPData<dColour> *data = dynamic_cast<TypedPData<dColour>*>(first);
00067         if (data) return OperatorSecond<dColour>(op,data,second);
00068         else 
00069         {
00070             TypedPData<float> *data = dynamic_cast<TypedPData<float>*>(first);
00071             if (data) return OperatorSecond<float>(op,data,second);
00072             else 
00073             {
00074                 TypedPData<dMatrix> *data = dynamic_cast<TypedPData<dMatrix>*>(first);
00075                 if (data) return OperatorSecond<dMatrix>(op,data,second);
00076             }
00077         }
00078     }
00079     return NULL;
00080 }
00081 
00082 PData *ArithmeticPrimFunc::OperatorFloatFirst(const string &op, PData* first, float second)
00083 {
00084     TypedPData<dVector> *data = dynamic_cast<TypedPData<dVector>*>(first);  
00085     if (data) return OperatorFloatSecond<dVector>(op,data,second);
00086     else
00087     {
00088         TypedPData<dColour> *data = dynamic_cast<TypedPData<dColour>*>(first);
00089         if (data) return OperatorFloatSecond<dColour>(op,data,second);
00090         else 
00091         {
00092             TypedPData<float> *data = dynamic_cast<TypedPData<float>*>(first);
00093             if (data) return OperatorFloatSecond<float>(op,data,second);
00094             else 
00095             {
00096                 TypedPData<dMatrix> *data = dynamic_cast<TypedPData<dMatrix>*>(first);
00097                 if (data) return OperatorFloatSecond<dMatrix>(op,data,second);
00098             }
00099         }
00100     }
00101     return NULL;
00102 }
00103