Blender V2.61 - r43446

attributes.h

Go to the documentation of this file.
00001 
00004 /******************************************************************************
00005  *
00006  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
00007  * Copyright 2003-2006 Nils Thuerey
00008  *
00009  * DEPRECATED - replaced by elbeem API, only channels are still used
00010  *
00011  *****************************************************************************/
00012 
00013 
00014 #ifndef NTL_ATTRIBUTES_H
00015 
00016 #include "utilities.h"
00017 template<class T> class ntlMatrix4x4;
00018 class ntlSetVec3f;
00019 std::ostream& operator<<( std::ostream& os, const ntlSetVec3f& i );
00020 
00021 
00022 
00024 template<class Scalar>
00025 class AnimChannel
00026 {
00027     public:
00028         // default constructor
00029         AnimChannel() : 
00030             mValue(), mTimes() { mInited = false; debugPrintChannel(); }
00031 
00032         // null init constructor
00033         AnimChannel(Scalar null) : 
00034             mValue(1), mTimes(1) { mValue[0]=null; mTimes[0]=0.0; mInited = true; debugPrintChannel(); }
00035 
00036         // proper init
00037         AnimChannel(vector<Scalar> &v, vector<double> &t) : 
00038             mValue(v), mTimes(t) { mInited = true; debugPrintChannel(); }
00039 
00040         // desctructor, nothing to do
00041         ~AnimChannel() { };
00042 
00043         // get interpolated value at time t
00044         Scalar get(double t) const {
00045             if(!mInited) { Scalar null; null=(Scalar)(0.0); return null; }
00046             if(t<=mTimes[0])               { return mValue[0]; }
00047             if(t>=mTimes[mTimes.size()-1]) { return mValue[mTimes.size()-1]; }
00048             for(size_t i=0; i<mTimes.size()-1; i++) {
00049                 // find first time thats in between
00050                 if((mTimes[i]<=t)&&(mTimes[i+1]>t)) { 
00051                     // interpolate
00052                     double d = mTimes[i+1]-mTimes[i];
00053                     double f = (t-mTimes[i])/d;
00054                     //return (Scalar)(mValue[i] * (1.0-f) + mValue[i+1] * f);
00055                     Scalar ret,tmp;
00056                     ret = mValue[i];
00057                     ret *= 1.-f;
00058                     tmp = mValue[i+1];
00059                     tmp *= f;
00060                     ret += tmp;
00061                     return ret;
00062                 }
00063             }
00064             // whats this...?
00065             return mValue[0];
00066         };
00067 
00068         // get uninterpolated value at time t
00069         Scalar getConstant(double t) const {
00070             //errMsg("DEBB","getc"<<t<<" ");
00071             if(!mInited) { Scalar null; null=(Scalar)0.0; return null; }
00072             if(t<=mTimes[0])               { return mValue[0]; }
00073             if(t>=mTimes[mTimes.size()-1]) { return mValue[mTimes.size()-1]; }
00074             for(size_t i=0; i<mTimes.size()-1; i++) {
00075                 //errMsg("DEBB","getc i"<<i<<" "<<mTimes[i]);
00076                 // find first time thats in between
00077                 if((mTimes[i]<=t)&&(mTimes[i+1]>t)) { return mValue[i]; }
00078             }
00079             // whats this...?
00080             return mValue[0];
00081         };
00082 
00083         // reset to null value
00084         void reset(Scalar null) {
00085             mValue.clear();
00086             mTimes.clear();
00087             mValue.push_back(null);
00088             mTimes.push_back(0.0);
00089         }
00090 
00092         string printChannel();
00094         void debugPrintChannel();
00096         bool isInited() const { return mInited; }
00097 
00099         int getSize() const { return mValue.size(); };
00101         vector<Scalar> &accessValues() { return mValue; }
00103         vector<double> &accessTimes() { return mTimes; }
00104         
00105     protected:
00106 
00108         bool mInited;
00110         vector<Scalar> mValue;
00112         vector<double> mTimes;
00113 };
00114 
00115 
00116 // helper class (not templated) for animated meshes
00117 class ntlSetVec3f {
00118     public:
00119         ntlSetVec3f(): mVerts() {};
00120         ntlSetVec3f(double v);
00121         ntlSetVec3f(vector<ntlVec3f> &v) { mVerts = v; };
00122 
00123         const ntlSetVec3f& operator=(double v );
00124         ntlSetVec3f& operator+=( double v );
00125         ntlSetVec3f& operator+=( const ntlSetVec3f &v );
00126         ntlSetVec3f& operator*=( double v );
00127         ntlSetVec3f& operator*=( const ntlSetVec3f &v );
00128 
00129         vector<ntlVec3f> mVerts;
00130 };
00131 
00132 
00133 // warning: DEPRECATED - replaced by elbeem API
00134 class Attribute
00135 {
00136     public:
00137     Attribute(string mn, vector<string> &value, int setline,bool channel) { 
00138             mn = string(""); setline=0; channel=false; value.clear(); // remove warnings
00139         };
00140     Attribute(Attribute &a) { a.getCompleteString(); };
00141     ~Attribute() { };
00142 
00143         void setUsed(bool set){ set=false; }
00144         bool getUsed() { return true; }
00145         void setIsChannel(bool set){ set=false;  }
00146         bool getIsChannel() { return false; }
00147 
00148         string getAsString(bool debug=false);
00149         int getAsInt();
00150         bool getAsBool();
00151         double getAsFloat();
00152         ntlVec3d getAsVec3d();
00153         void getAsMat4Gfx(ntlMatrix4x4<gfxReal> *mat);
00154 
00155         AnimChannel<int> getChannelInt();
00156         AnimChannel<double> getChannelFloat();
00157         AnimChannel<ntlVec3d> getChannelVec3d();
00158         AnimChannel<ntlSetVec3f> getChannelSetVec3f();
00159 
00160         string getCompleteString();
00161         void print();
00162         
00163     protected:
00164 
00165         bool initChannel(int elemSize);
00166 };
00167 
00168 
00169 // warning: DEPRECATED - replaced by elbeem API
00171 class AttributeList
00172 {
00173     public:
00174     AttributeList(string name) { name=string(""); };
00175     ~AttributeList();
00176         void addAttr(string name, vector<string> &value, int line, bool isChannel) { 
00177             name=string(""); value.clear(); line=0; isChannel=false; // remove warnings
00178         };
00179         bool exists(string name) { name=string(""); return false; }
00180         void setAllUsed();
00181         bool checkUnusedParams();
00182         void import(AttributeList *oal);
00183         int      readInt(string name, int defaultValue,         string source,string target, bool needed);
00184         bool     readBool(string name, bool defaultValue,       string source,string target, bool needed);
00185         double   readFloat(string name, double defaultValue,   string source,string target, bool needed);
00186         string   readString(string name, string defaultValue,   string source,string target, bool needed);
00187         ntlVec3d readVec3d(string name, ntlVec3d defaultValue,  string source,string target, bool needed);
00188         void readMat4Gfx(string name, ntlMatrix4x4<gfxReal> defaultValue,  string source,string target, bool needed, ntlMatrix4x4<gfxReal> *mat);
00189         AnimChannel<int>     readChannelInt(         string name, int defaultValue=0, string source=string("src"), string target=string("dst"), bool needed=false );
00190         AnimChannel<double>  readChannelFloat(       string name, double defaultValue=0, string source=string("src"), string target=string("dst"), bool needed=false );
00191         AnimChannel<ntlVec3d> readChannelVec3d(      string name, ntlVec3d defaultValue=ntlVec3d(0.), string source=string("src"), string target=string("dst"), bool needed=false );
00192         AnimChannel<ntlSetVec3f> readChannelSetVec3f(string name, ntlSetVec3f defaultValue=ntlSetVec3f(0.), string source=string("src"), string target=string("dst"), bool needed=false );
00193         AnimChannel<ntlVec3f> readChannelVec3f(           string name, ntlVec3f defaultValue=ntlVec3f(0.), string source=string("src"), string target=string("dst"), bool needed=false );
00194         AnimChannel<float>    readChannelSinglePrecFloat( string name, float defaultValue=0., string source=string("src"), string target=string("dst"), bool needed=false );
00195         bool ignoreParameter(string name, string source);
00196         void print();
00197     protected:
00198 };
00199 
00200 ntlVec3f channelFindMaxVf (AnimChannel<ntlVec3f> channel);
00201 ntlVec3d channelFindMaxVd (AnimChannel<ntlVec3d> channel);
00202 int      channelFindMaxi  (AnimChannel<int     > channel);
00203 float    channelFindMaxf  (AnimChannel<float   > channel);
00204 double   channelFindMaxd  (AnimChannel<double  > channel);
00205 
00206 // unoptimized channel simplification functions, use elbeem.cpp functions
00207 bool channelSimplifyVf (AnimChannel<ntlVec3f> &channel);
00208 bool channelSimplifyVd (AnimChannel<ntlVec3d> &channel);
00209 bool channelSimplifyi  (AnimChannel<int     > &channel);
00210 bool channelSimplifyf  (AnimChannel<float   > &channel);
00211 bool channelSimplifyd  (AnimChannel<double  > &channel);
00212 
00214 #define DEBUG_PCHANNELS 0
00215 
00217 template<class Scalar>
00218 void AnimChannel<Scalar>::debugPrintChannel() { }
00219 
00220 
00221 #define NTL_ATTRIBUTES_H
00222 #endif
00223