ArithmeticPrimFunc.cpp

Go to the documentation of this file.
00001 // Copyright (C) 2005 Dave Griffiths
00002 //
00003 // This program is free software; you can redistribute it and/or modify
00004 // it under the terms of the GNU General Public License as published by
00005 // the Free Software Foundation; either version 2 of the License, or
00006 // (at your option) any later version.
00007 //
00008 // This program is distributed in the hope that it will be useful,
00009 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00010 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00011 // GNU General Public License for more details.
00012 //
00013 // You should have received a copy of the GNU General Public License
00014 // along with this program; if not, write to the Free Software
00015 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
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     // need at least a source
00042     if (src!=NULL)
00043     {
00044         if (other!=NULL) // pdata array as second argument
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"))  // float as the second argument
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 

Generated on Tue Sep 4 23:22:18 2007 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1