Blender  V2.59
attributes.cpp
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 #include "attributes.h"
00014 #include "ntl_matrices.h"
00015 #include "elbeem.h"
00016 
00017 
00018 
00019 /******************************************************************************
00020  * attribute conversion functions
00021  *****************************************************************************/
00022 
00023 bool Attribute::initChannel(int elemSize) {
00024         elemSize=0; // remove warning
00025         return false;
00026 }
00027 string Attribute::getAsString(bool debug) {
00028         debug=false; // remove warning
00029         return string("");
00030 }
00031 int Attribute::getAsInt() {
00032         return 0;
00033 }
00034 bool Attribute::getAsBool() {
00035         return false;
00036 }
00037 double Attribute::getAsFloat() {
00038         return 0.;
00039 }
00040 ntlVec3d Attribute::getAsVec3d() {
00041         return ntlVec3d(0.);
00042 }
00043 void Attribute::getAsMat4Gfx(ntlMat4Gfx *mat) {
00044         mat=NULL; // remove warning
00045 }
00046 string Attribute::getCompleteString() {
00047         return string("");
00048 }
00049 
00050 
00051 /******************************************************************************
00052  * channel returns
00053  *****************************************************************************/
00054 
00055 AnimChannel<double> Attribute::getChannelFloat() {
00056         return AnimChannel<double>();
00057 }
00058 AnimChannel<int> Attribute::getChannelInt() { 
00059         return AnimChannel<int>();
00060 }
00061 AnimChannel<ntlVec3d> Attribute::getChannelVec3d() { 
00062         return AnimChannel<ntlVec3d>();
00063 }
00064 AnimChannel<ntlSetVec3f> 
00065 Attribute::getChannelSetVec3f() {
00066         return AnimChannel<ntlSetVec3f>();
00067 }
00068 
00069 /******************************************************************************
00070  * check if there were unknown params
00071  *****************************************************************************/
00072 bool AttributeList::checkUnusedParams() {
00073         return false;
00074 }
00075 void AttributeList::setAllUsed() {
00076 }
00077 
00078 /******************************************************************************
00079  * Attribute list read functions
00080  *****************************************************************************/
00081 int AttributeList::readInt(string name, int defaultValue, string source,string target, bool needed) {
00082         name=source=target=string(""); needed=false; // remove warning
00083         return defaultValue;
00084 }
00085 bool AttributeList::readBool(string name, bool defaultValue, string source,string target, bool needed) {
00086         name=source=target=string(""); needed=false; // remove warning
00087         return defaultValue;
00088 }
00089 double AttributeList::readFloat(string name, double defaultValue, string source,string target, bool needed) {
00090         name=source=target=string(""); needed=false; // remove warning
00091         return defaultValue;
00092 }
00093 string AttributeList::readString(string name, string defaultValue, string source,string target, bool needed) {
00094         name=source=target=string(""); needed=false; // remove warning
00095         return defaultValue;
00096 }
00097 ntlVec3d AttributeList::readVec3d(string name, ntlVec3d defaultValue, string source,string target, bool needed) {
00098         name=source=target=string(""); needed=false; // remove warning
00099         return defaultValue;
00100 }
00101 
00102 void AttributeList::readMat4Gfx(string name, ntlMat4Gfx defaultValue, string source,string target, bool needed, ntlMat4Gfx *mat) {
00103         *mat = defaultValue;
00104         name=source=target=string(""); needed=false; mat=NULL; // remove warning
00105 }
00106 
00107 // set that a parameter can be given, and will be ignored...
00108 bool AttributeList::ignoreParameter(string name, string source) {
00109         name = source = ("");
00110         return false;
00111 }
00112                 
00113 // read channels
00114 AnimChannel<int> AttributeList::readChannelInt(string name, int defaultValue, string source, string target, bool needed) {
00115         name=source=target=string(""); needed=false; // remove warning
00116         return AnimChannel<int>(defaultValue);
00117 }
00118 AnimChannel<double> AttributeList::readChannelFloat(string name, double defaultValue, string source, string target, bool needed ) {
00119         name=source=target=string(""); needed=false; // remove warning
00120         return AnimChannel<double>(defaultValue);
00121 }
00122 AnimChannel<ntlVec3d> AttributeList::readChannelVec3d(string name, ntlVec3d defaultValue, string source, string target, bool needed ) {
00123         name=source=target=string(""); needed=false; // remove warning
00124         return AnimChannel<ntlVec3d>(defaultValue);
00125 }
00126 AnimChannel<ntlSetVec3f> AttributeList::readChannelSetVec3f(string name, ntlSetVec3f defaultValue, string source, string target, bool needed) {
00127         name=source=target=string(""); needed=false; // remove warning
00128         return AnimChannel<ntlSetVec3f>(defaultValue);
00129 }
00130 AnimChannel<float> AttributeList::readChannelSinglePrecFloat(string name, float defaultValue, string source, string target, bool needed ) {
00131         name=source=target=string(""); needed=false; // remove warning
00132         return AnimChannel<float>(defaultValue);
00133 }
00134 AnimChannel<ntlVec3f> AttributeList::readChannelVec3f(string name, ntlVec3f defaultValue, string source, string target, bool needed) {
00135         name=source=target=string(""); needed=false; // remove warning
00136         return AnimChannel<ntlVec3f>(defaultValue);
00137 }
00138 
00139 /******************************************************************************
00140  * destructor
00141  *****************************************************************************/
00142 AttributeList::~AttributeList() { 
00143 };
00144 
00145 
00146 /******************************************************************************
00147  * debugging
00148  *****************************************************************************/
00149 
00151 void Attribute::print() {
00152 }
00153                 
00155 void AttributeList::print() {
00156 }
00157 
00158 
00159 /******************************************************************************
00160  * import attributes from other attribute list
00161  *****************************************************************************/
00162 void AttributeList::import(AttributeList *oal) {
00163         oal=NULL; // remove warning
00164 }
00165 
00166 
00167 /******************************************************************************
00168  * channel max finding
00169  *****************************************************************************/
00170 ntlVec3f channelFindMaxVf (AnimChannel<ntlVec3f> channel) {
00171         ntlVec3f ret(0.0);
00172         float maxLen = 0.0;
00173         for(size_t i=0; i<channel.accessValues().size(); i++) {
00174                 float nlen = normNoSqrt(channel.accessValues()[i]);
00175                 if(nlen>maxLen) { ret=channel.accessValues()[i]; maxLen=nlen; }
00176         }
00177         return ret;
00178 }
00179 ntlVec3d channelFindMaxVd (AnimChannel<ntlVec3d> channel) {
00180         ntlVec3d ret(0.0);
00181         float maxLen = 0.0;
00182         for(size_t i=0; i<channel.accessValues().size(); i++) {
00183                 float nlen = normNoSqrt(channel.accessValues()[i]);
00184                 if(nlen>maxLen) { ret=channel.accessValues()[i]; maxLen=nlen; }
00185         }
00186         return ret;
00187 }
00188 int      channelFindMaxi  (AnimChannel<float   > channel) {
00189         int ret = 0;
00190         float maxLen = 0.0;
00191         for(size_t i=0; i<channel.accessValues().size(); i++) {
00192                 float nlen = ABS(channel.accessValues()[i]);
00193                 if(nlen>maxLen) { ret= (int)channel.accessValues()[i]; maxLen=nlen; }
00194         }
00195         return ret;
00196 }
00197 float    channelFindMaxf  (AnimChannel<float   > channel) {
00198         float ret = 0.0;
00199         float maxLen = 0.0;
00200         for(size_t i=0; i<channel.accessValues().size(); i++) {
00201                 float nlen = ABS(channel.accessValues()[i]);
00202                 if(nlen>maxLen) { ret=channel.accessValues()[i]; maxLen=nlen; }
00203         }
00204         return ret;
00205 }
00206 double   channelFindMaxd  (AnimChannel<double  > channel) {
00207         double ret = 0.0;
00208         float maxLen = 0.0;
00209         for(size_t i=0; i<channel.accessValues().size(); i++) {
00210                 float nlen = ABS(channel.accessValues()[i]);
00211                 if(nlen>maxLen) { ret=channel.accessValues()[i]; maxLen=nlen; }
00212         }
00213         return ret;
00214 }
00215 
00216 /******************************************************************************
00217  // unoptimized channel simplification functions, use elbeem.cpp functions
00218  // warning - currently only with single precision
00219  *****************************************************************************/
00220 
00221 template<class SCALAR>
00222 static bool channelSimplifyScalarT(AnimChannel<SCALAR> &channel) {
00223         int   size = channel.getSize();
00224         if(size<=1) return false;
00225         float *nchannel = new float[2*size];
00226         // convert to array
00227         for(size_t i=0; i<channel.accessValues().size(); i++) {
00228                 nchannel[i*2 + 0] = (float)channel.accessValues()[i];
00229                 nchannel[i*2 + 1] = (float)channel.accessTimes()[i];
00230         }
00231         bool ret = elbeemSimplifyChannelFloat(nchannel, &size);
00232         if(ret) {
00233                 vector<SCALAR> vals;
00234                 vector<double> times;
00235                 for(int i=0; i<size; i++) {
00236                         vals.push_back(  (SCALAR)(nchannel[i*2 + 0]) );
00237                         times.push_back( (double)(nchannel[i*2 + 1]) );
00238                 }
00239                 channel = AnimChannel<SCALAR>(vals, times);
00240         }
00241         delete [] nchannel;
00242         return ret;
00243 }
00244 bool channelSimplifyi  (AnimChannel<int   > &channel) { return channelSimplifyScalarT<int>(channel); }
00245 bool channelSimplifyf  (AnimChannel<float> &channel) { return channelSimplifyScalarT<float>(channel); }
00246 bool channelSimplifyd  (AnimChannel<double  > &channel) { return channelSimplifyScalarT<double>(channel); }
00247 template<class VEC>
00248 static bool channelSimplifyVecT(AnimChannel<VEC> &channel) {
00249         int   size = channel.getSize();
00250         if(size<=1) return false;
00251         float *nchannel = new float[4*size];
00252         // convert to array
00253         for(size_t i=0; i<channel.accessValues().size(); i++) {
00254                 nchannel[i*4 + 0] = (float)channel.accessValues()[i][0];
00255                 nchannel[i*4 + 1] = (float)channel.accessValues()[i][1];
00256                 nchannel[i*4 + 2] = (float)channel.accessValues()[i][2];
00257                 nchannel[i*4 + 3] = (float)channel.accessTimes()[i];
00258         }
00259         bool ret = elbeemSimplifyChannelVec3(nchannel, &size);
00260         if(ret) {
00261                 vector<VEC> vals;
00262                 vector<double> times;
00263                 for(int i=0; i<size; i++) {
00264                         vals.push_back(  VEC(nchannel[i*4 + 0], nchannel[i*4 + 1], nchannel[i*4 + 2] ) );
00265                         times.push_back( (double)(nchannel[i*4 + 3]) );
00266                 }
00267                 channel = AnimChannel<VEC>(vals, times);
00268         }
00269         delete [] nchannel;
00270         return ret;
00271 }
00272 bool channelSimplifyVf (AnimChannel<ntlVec3f> &channel) {
00273         return channelSimplifyVecT<ntlVec3f>(channel);
00274 }
00275 bool channelSimplifyVd (AnimChannel<ntlVec3d> &channel) {
00276         return channelSimplifyVecT<ntlVec3d>(channel);
00277 }
00278 
00280 template<class Scalar>
00281 string AnimChannel<Scalar>::printChannel() {
00282         std::ostringstream ostr;
00283         ostr << " CHANNEL #"<<  mValue.size() <<" = { ";
00284         for(size_t i=0;i<mValue.size();i++) {
00285                 ostr <<"'"<< mValue[i]<<"' ";
00286                 ostr << "@"<<mTimes[i]<<"; ";
00287         }
00288         ostr << " } ";
00289         return ostr.str();
00290 } // */
00291 
00292 // is now in header file: debugPrintChannel() 
00293 // hack to force instantiation
00294 void __forceAnimChannelInstantiation() {
00295         AnimChannel< float > tmp1;
00296         AnimChannel< double > tmp2;
00297         AnimChannel< string > tmp3;
00298         AnimChannel< ntlVector3Dim<float> > tmp4;
00299         AnimChannel< ntlVector3Dim<double> > tmp5;
00300         tmp1.debugPrintChannel();
00301         tmp2.debugPrintChannel();
00302         tmp3.debugPrintChannel();
00303         tmp4.debugPrintChannel();
00304         tmp5.debugPrintChannel();
00305 }
00306 
00307 
00308 ntlSetVec3f::ntlSetVec3f(double v ) {
00309         mVerts.clear();
00310         mVerts.push_back( ntlVec3f(v) );
00311 }
00312 const ntlSetVec3f& 
00313 ntlSetVec3f::operator=(double v ) {
00314         mVerts.clear();
00315         mVerts.push_back( ntlVec3f(v) );
00316         return *this;
00317 }
00318 
00319 std::ostream& operator<<( std::ostream& os, const ntlSetVec3f& vs ) {
00320         os<< "{";
00321         for(int j=0;j<(int)vs.mVerts.size();j++)  os<<vs.mVerts[j];
00322         os<< "}";
00323   return os;
00324 }
00325 
00326 ntlSetVec3f& 
00327 ntlSetVec3f::operator+=( double v )
00328 {
00329         for(int j=0;j<(int)(mVerts.size()) ;j++) {
00330                 mVerts[j] += v;
00331         }
00332         return *this;
00333 }
00334 
00335 ntlSetVec3f& 
00336 ntlSetVec3f::operator+=( const ntlSetVec3f &v )
00337 {
00338         for(int j=0;j<(int)MIN(mVerts.size(),v.mVerts.size()) ;j++) {
00339                 mVerts[j] += v.mVerts[j];
00340         }
00341         return *this;
00342 }
00343 
00344 ntlSetVec3f& 
00345 ntlSetVec3f::operator*=( double v )
00346 {
00347         for(int j=0;j<(int)(mVerts.size()) ;j++) {
00348                 mVerts[j] *= v;
00349         }
00350         return *this;
00351 }
00352 
00353 ntlSetVec3f& 
00354 ntlSetVec3f::operator*=( const ntlSetVec3f &v )
00355 {
00356         for(int j=0;j<(int)MIN(mVerts.size(),v.mVerts.size()) ;j++) {
00357                 mVerts[j] *= v.mVerts[j];
00358         }
00359         return *this;
00360 }
00361 
00362