PDataArithmetic.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 "PDataArithmetic.h"
00018 
00019 using namespace Fluxus;
00020 
00021 template <>
00022 PData *AddOperator::Operate(TypedPData<float> *a, float b)
00023 {
00024     for (vector<float>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00025     {
00026         *i+=b;
00027     }
00028     
00029     return NULL;
00030 }
00031 
00032 template <>
00033 PData *AddOperator::Operate(TypedPData<dVector> *a, float b)
00034 {
00035     for (vector<dVector>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00036     {
00037         i->x+=b;
00038         i->y+=b;
00039         i->z+=b;
00040     }
00041     return NULL;
00042 }
00043 
00044 template <>
00045 PData *AddOperator::Operate(TypedPData<dVector> *a, dVector b)
00046 {
00047     for (vector<dVector>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00048     {
00049         i->x+=b.x;
00050         i->y+=b.y;
00051         i->z+=b.z;
00052     }
00053     return NULL;
00054 }
00055 
00056 template <>
00057 PData *AddOperator::Operate(TypedPData<float> *a, TypedPData<float> *b)
00058 {
00059     for (unsigned int i=0; i<a->Size(); i++) a->m_Data[i]+=b->m_Data[i];
00060     return NULL;
00061 }
00062 
00063 template <>
00064 PData *AddOperator::Operate(TypedPData<dVector> *a, TypedPData<float> *b)
00065 {
00066     for (unsigned int i=0; i<a->Size(); i++) 
00067     {
00068         a->m_Data[i].x+=b->m_Data[i];
00069         a->m_Data[i].y+=b->m_Data[i];
00070         a->m_Data[i].z+=b->m_Data[i];
00071     }
00072     return NULL;
00073 }
00074 
00075 template <>
00076 PData *AddOperator::Operate(TypedPData<dVector> *a, TypedPData<dVector> *b)
00077 {
00078     for (unsigned int i=0; i<a->Size(); i++) a->m_Data[i]+=b->m_Data[i];
00079     return NULL;
00080 }
00081 
00083 
00084 template <>
00085 PData *MultOperator::Operate(TypedPData<float> *a, float b)
00086 {
00087     for (vector<float>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00088     {
00089         (*i)*=b;
00090     }
00091     return NULL;
00092 }
00093 
00094 template <>
00095 PData *MultOperator::Operate(TypedPData<dVector> *a, float b)
00096 {
00097     for (vector<dVector>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00098     {
00099         (*i)*=b;
00100     }
00101     return NULL;
00102 }
00103 
00104 template <>
00105 PData *MultOperator::Operate(TypedPData<dColour> *a, float b)
00106 {
00107     for (vector<dColour>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00108     {
00109         (*i)*=b;
00110     }
00111     return NULL;
00112 }
00113 
00114 template <>
00115 PData *MultOperator::Operate(TypedPData<dVector> *a, dVector b)
00116 {
00117     for (vector<dVector>::iterator i=a->m_Data.begin(); i!=a->m_Data.end(); i++)
00118     {
00119         (*i).x*=b.x;
00120         (*i).y*=b.y;
00121         (*i).z*=b.z;
00122     }
00123     return NULL;
00124 }
00125 
00126 template <>
00127 PData *MultOperator::Operate(TypedPData<float> *a, TypedPData<float> *b)
00128 {
00129     for (unsigned int i=0; i<a->Size(); i++) a->m_Data[i]*=b->m_Data[i];
00130     return NULL;
00131 }
00132 
00133 template <>
00134 PData *MultOperator::Operate(TypedPData<dVector> *a, TypedPData<float> *b)
00135 {
00136     for (unsigned int i=0; i<a->Size(); i++) 
00137     {
00138         a->m_Data[i]*=b->m_Data[i];
00139     }
00140     return NULL;
00141 }
00142 
00143 template <>
00144 PData *MultOperator::Operate(TypedPData<dVector> *a, TypedPData<dVector> *b)
00145 {
00146     for (unsigned int i=0; i<a->Size(); i++)
00147     {
00148         a->m_Data[i].x*=b->m_Data[i].x;
00149         a->m_Data[i].y*=b->m_Data[i].y;
00150         a->m_Data[i].z*=b->m_Data[i].z;
00151     }
00152     return NULL;
00153 }
00154 
00156 
00157 template <>
00158 PData *SineOperator::Operate(TypedPData<float> *a, TypedPData<float> *b)
00159 {
00160     for (unsigned int i=0; i<a->Size(); i++)
00161     {
00162         a->m_Data[i]=sin(b->m_Data[i]);
00163     }
00164     return NULL;
00165 }
00166 
00168 
00169 template <>
00170 PData *CosineOperator::Operate(TypedPData<float> *a, TypedPData<float> *b)
00171 {
00172     for (unsigned int i=0; i<a->Size(); i++)
00173     {   
00174         a->m_Data[i]=cos(b->m_Data[i]); 
00175     }
00176     return NULL;
00177 }
00178 
00180 
00181 template <>
00182 PData *ClosestOperator::Operate(TypedPData<dVector> *a, dVector b)
00183 {
00184     float closestdist=999999;
00185     dVector closest;
00186     for (unsigned int i=0; i<a->Size(); i++)
00187     {   
00188         float dist = a->m_Data[i].dist(b);  
00189         if (dist<closestdist)
00190         {
00191             closestdist=dist;
00192             closest=a->m_Data[i];
00193         }
00194         
00195     }
00196     
00197     TypedPData<dVector> *ret = new TypedPData<dVector>;
00198     ret->m_Data.push_back(closest);
00199     return ret;
00200 }
00201 
00202 template <>
00203 PData *ClosestOperator::Operate(TypedPData<dVector> *a, float b)
00204 {
00205     // use the float as the index
00206     unsigned int index=(unsigned int)b;
00207     float closestdist=999999;
00208     dVector closest;
00209     for (unsigned int i=0; i<a->Size(); i++)
00210     {   
00211         if (i!=index)
00212         {
00213             float dist = a->m_Data[i].dist(a->m_Data[index]);   
00214             if (dist<closestdist)
00215             {
00216                 closestdist=dist;
00217                 closest=a->m_Data[i];
00218             }
00219         }
00220     }
00221     
00222     TypedPData<dVector> *ret = new TypedPData<dVector>;
00223     ret->m_Data.push_back(closest);
00224     return ret;
00225 }
00226 

Generated on Mon Feb 11 06:54:25 2008 for The Fluxus Renderer (libfluxus) by  doxygen 1.5.1