Cleanup: remove redundant doxygen \file argument
[blender.git] / intern / elbeem / intern / attributes.h
1 /** \file \ingroup elbeem
2  */
3 /******************************************************************************
4  *
5  * El'Beem - Free Surface Fluid Simulation with the Lattice Boltzmann Method
6  * Copyright 2003-2006 Nils Thuerey
7  *
8  * DEPRECATED - replaced by elbeem API, only channels are still used
9  *
10  *****************************************************************************/
11
12
13 #ifndef NTL_ATTRIBUTES_H
14
15 #include "utilities.h"
16
17 #ifdef WITH_CXX_GUARDEDALLOC
18 #  include "MEM_guardedalloc.h"
19 #endif
20
21 template<class T> class ntlMatrix4x4;
22 class ntlSetVec3f;
23 std::ostream& operator<<( std::ostream& os, const ntlSetVec3f& i );
24
25
26
27 //! An animated attribute channel
28 template<class Scalar>
29 class AnimChannel
30 {
31         public:
32                 // default constructor
33                 AnimChannel() : 
34                         mValue(), mTimes() { mInited = false; debugPrintChannel(); }
35
36                 // null init constructor
37                 AnimChannel(Scalar null) : 
38                         mValue(1), mTimes(1) { mValue[0]=null; mTimes[0]=0.0; mInited = true; debugPrintChannel(); }
39
40                 // proper init
41                 AnimChannel(vector<Scalar> &v, vector<double> &t) : 
42                         mValue(v), mTimes(t) { mInited = true; debugPrintChannel(); }
43
44                 // desctructor, nothing to do
45                 ~AnimChannel() { };
46
47                 // get interpolated value at time t
48                 Scalar get(double t) const {
49                         if(!mInited) { Scalar null; null=(Scalar)(0.0); return null; }
50                         if(t<=mTimes[0])               { return mValue[0]; }
51                         if(t>=mTimes[mTimes.size()-1]) { return mValue[mTimes.size()-1]; }
52                         for(size_t i=0; i<mTimes.size()-1; i++) {
53                                 // find first time thats in between
54                                 if((mTimes[i]<=t)&&(mTimes[i+1]>t)) { 
55                                         // interpolate
56                                         double d = mTimes[i+1]-mTimes[i];
57                                         double f = (t-mTimes[i])/d;
58                                         //return (Scalar)(mValue[i] * (1.0-f) + mValue[i+1] * f);
59                                         Scalar ret,tmp;
60                                         ret = mValue[i];
61                                         ret *= 1.-f;
62                                         tmp = mValue[i+1];
63                                         tmp *= f;
64                                         ret += tmp;
65                                         return ret;
66                                 }
67                         }
68                         // whats this...?
69                         return mValue[0];
70                 };
71
72                 // get uninterpolated value at time t
73                 Scalar getConstant(double t) const {
74                         //errMsg("DEBB","getc"<<t<<" ");
75                         if(!mInited) { Scalar null; null=(Scalar)0.0; return null; }
76                         if(t<=mTimes[0])               { return mValue[0]; }
77                         if(t>=mTimes[mTimes.size()-1]) { return mValue[mTimes.size()-1]; }
78                         for(size_t i=0; i<mTimes.size()-1; i++) {
79                                 //errMsg("DEBB","getc i"<<i<<" "<<mTimes[i]);
80                                 // find first time thats in between
81                                 if((mTimes[i]<=t)&&(mTimes[i+1]>t)) { return mValue[i]; }
82                         }
83                         // whats this...?
84                         return mValue[0];
85                 };
86
87                 // reset to null value
88                 void reset(Scalar null) {
89                         mValue.clear();
90                         mTimes.clear();
91                         mValue.push_back(null);
92                         mTimes.push_back(0.0);
93                 }
94
95                 //! debug function, prints channel as string
96                 string printChannel();
97                 //! debug function, prints to stdout if DEBUG_CHANNELS flag is enabled, used in constructors
98                 void debugPrintChannel();
99                 //! valid init?
100                 bool isInited() const { return mInited; }
101
102                 //! get number of entries (value and time sizes have to be equal)
103                 int getSize() const { return mValue.size(); };
104                 //! raw access of value vector
105                 vector<Scalar> &accessValues() { return mValue; }
106                 //! raw access of time vector
107                 vector<double> &accessTimes() { return mTimes; }
108                 
109         protected:
110
111                 /*! inited at least once? */
112                 bool mInited;
113                 /*! anim channel attribute values */
114                 vector<Scalar> mValue;
115                 /*! anim channel attr times */
116                 vector<double> mTimes;
117
118 private:
119 #ifdef WITH_CXX_GUARDEDALLOC
120         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:AnimChannel")
121 #endif
122 };
123
124
125 // helper class (not templated) for animated meshes
126 class ntlSetVec3f {
127         public:
128                 ntlSetVec3f(): mVerts() {};
129                 ntlSetVec3f(double v);
130                 ntlSetVec3f(vector<ntlVec3f> &v) { mVerts = v; };
131
132                 const ntlSetVec3f& operator=(double v );
133                 ntlSetVec3f& operator+=( double v );
134                 ntlSetVec3f& operator+=( const ntlSetVec3f &v );
135                 ntlSetVec3f& operator*=( double v );
136                 ntlSetVec3f& operator*=( const ntlSetVec3f &v );
137
138                 vector<ntlVec3f> mVerts;
139
140 private:
141 #ifdef WITH_CXX_GUARDEDALLOC
142         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:ntlSetVec3f")
143 #endif
144 };
145
146
147 // warning: DEPRECATED - replaced by elbeem API
148 class Attribute
149 {
150         public:
151         Attribute(string mn, vector<string> &value, int setline,bool channel) { 
152                         mn = string(""); setline=0; channel=false; value.clear(); // remove warnings
153                 };
154         Attribute(Attribute &a) { a.getCompleteString(); };
155         ~Attribute() { };
156
157                 void setUsed(bool set){ set=false; }
158                 bool getUsed() { return true; }
159                 void setIsChannel(bool set){ set=false;  }
160                 bool getIsChannel() { return false; }
161
162                 string getAsString(bool debug=false);
163                 int getAsInt();
164                 bool getAsBool();
165                 double getAsFloat();
166                 ntlVec3d getAsVec3d();
167                 void getAsMat4Gfx(ntlMatrix4x4<gfxReal> *mat);
168
169                 AnimChannel<int> getChannelInt();
170                 AnimChannel<double> getChannelFloat();
171                 AnimChannel<ntlVec3d> getChannelVec3d();
172                 AnimChannel<ntlSetVec3f> getChannelSetVec3f();
173
174                 string getCompleteString();
175                 void print();
176                 
177         protected:
178
179                 bool initChannel(int elemSize);
180
181 private:
182 #ifdef WITH_CXX_GUARDEDALLOC
183         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:Attribute")
184 #endif
185 };
186
187
188 // warning: DEPRECATED - replaced by elbeem API
189 //! The list of configuration attributes
190 class AttributeList
191 {
192         public:
193         AttributeList(string name) { name=string(""); };
194         ~AttributeList();
195                 void addAttr(string name, vector<string> &value, int line, bool isChannel) { 
196                         name=string(""); value.clear(); line=0; isChannel=false; // remove warnings
197                 };
198                 bool exists(string name) { name=string(""); return false; }
199                 void setAllUsed();
200                 bool checkUnusedParams();
201                 void import(AttributeList *oal);
202                 int      readInt(string name, int defaultValue,         string source,string target, bool needed);
203                 bool     readBool(string name, bool defaultValue,       string source,string target, bool needed);
204                 double   readFloat(string name, double defaultValue,   string source,string target, bool needed);
205                 string   readString(string name, string defaultValue,   string source,string target, bool needed);
206                 ntlVec3d readVec3d(string name, ntlVec3d defaultValue,  string source,string target, bool needed);
207                 void readMat4Gfx(string name, ntlMatrix4x4<gfxReal> defaultValue,  string source,string target, bool needed, ntlMatrix4x4<gfxReal> *mat);
208                 AnimChannel<int>     readChannelInt(         string name, int defaultValue=0, string source=string("src"), string target=string("dst"), bool needed=false );
209                 AnimChannel<double>  readChannelFloat(       string name, double defaultValue=0, string source=string("src"), string target=string("dst"), bool needed=false );
210                 AnimChannel<ntlVec3d> readChannelVec3d(      string name, ntlVec3d defaultValue=ntlVec3d(0.), string source=string("src"), string target=string("dst"), bool needed=false );
211                 AnimChannel<ntlSetVec3f> readChannelSetVec3f(string name, ntlSetVec3f defaultValue=ntlSetVec3f(0.), string source=string("src"), string target=string("dst"), bool needed=false );
212                 AnimChannel<ntlVec3f> readChannelVec3f(           string name, ntlVec3f defaultValue=ntlVec3f(0.), string source=string("src"), string target=string("dst"), bool needed=false );
213                 AnimChannel<float>    readChannelSinglePrecFloat( string name, float defaultValue=0., string source=string("src"), string target=string("dst"), bool needed=false );
214                 bool ignoreParameter(string name, string source);
215                 void print();
216         protected:
217
218 private:
219 #ifdef WITH_CXX_GUARDEDALLOC
220         MEM_CXX_CLASS_ALLOC_FUNCS("ELBEEM:AttributeList")
221 #endif
222 };
223
224 ntlVec3f channelFindMaxVf (AnimChannel<ntlVec3f> channel);
225 ntlVec3d channelFindMaxVd (AnimChannel<ntlVec3d> channel);
226 int      channelFindMaxi  (AnimChannel<int     > channel);
227 float    channelFindMaxf  (AnimChannel<float   > channel);
228 double   channelFindMaxd  (AnimChannel<double  > channel);
229
230 // unoptimized channel simplification functions, use elbeem.cpp functions
231 bool channelSimplifyVf (AnimChannel<ntlVec3f> &channel);
232 bool channelSimplifyVd (AnimChannel<ntlVec3d> &channel);
233 bool channelSimplifyi  (AnimChannel<int     > &channel);
234 bool channelSimplifyf  (AnimChannel<float   > &channel);
235 bool channelSimplifyd  (AnimChannel<double  > &channel);
236
237 //! output channel values? on=1/off=0
238 #define DEBUG_PCHANNELS 0
239
240 //! debug function, prints to stdout if DEBUG_PCHANNELS flag is enabled, used in constructors
241 template<class Scalar>
242 void AnimChannel<Scalar>::debugPrintChannel() { }
243
244
245 #define NTL_ATTRIBUTES_H
246 #endif
247