Blender  V2.59
particletracer.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  * Particle Viewer/Tracer
00010  *
00011  *****************************************************************************/
00012 #ifndef NTL_PARTICLETRACER_H
00013 
00014 #include "ntl_geometryobject.h"
00015 template<class Scalar> class ntlMatrix4x4;
00016 
00017 // particle types
00018 #define PART_BUBBLE (1<< 1)
00019 #define PART_DROP   (1<< 2)
00020 #define PART_INTER  (1<< 3)
00021 #define PART_FLOAT  (1<< 4)
00022 #define PART_TRACER (1<< 5)
00023 
00024 // particle state
00025 #define PART_IN     (1<< 8)
00026 #define PART_OUT    (1<< 9)
00027 #define PART_INACTIVE (1<<10)
00028 #define PART_OUTFLUID  (1<<11)
00029 
00030 // defines for particle movement
00031 #define MOVE_FLOATS 1
00032 #define FLOAT_JITTER 0.03
00033 //#define FLOAT_JITTER 0.0
00034 
00035 extern int ParticleObjectIdCnt;
00036 
00038 class ParticleObject
00039 {
00040         public:
00042         inline ParticleObject(ntlVec3Gfx mp) :
00043                         mPos(mp),mVel(0.0), mSize(1.0), mStatus(0),mLifeTime(0),mpNext(NULL) 
00044                                 { mId = ParticleObjectIdCnt++; };
00046         inline ParticleObject(const ParticleObject &a) :
00047                         mPos(a.mPos), mVel(a.mVel), mSize(a.mSize), 
00048                         mStatus(a.mStatus),
00049                         mLifeTime(a.mLifeTime), mpNext(NULL) 
00050                                 { mId = ParticleObjectIdCnt++; };
00052         inline ~ParticleObject() { /* empty */ };
00053 
00055                 inline void advance(float vx, float vy, float vz) {
00056                         mPos[0] += vx; mPos[1] += vy; mPos[2] += vz; }
00057                 inline void advanceVec(ntlVec3Gfx v) {
00058                         mPos[0] += v[0]; mPos[1] += v[1]; mPos[2] += v[2]; }
00060                 inline void advanceVel() { mPos += mVel; }
00062                 inline void addToVel(ntlVec3Gfx acc) { mVel += acc; }
00063 
00065                 inline ntlVec3Gfx getPos() { return mPos; }
00066                 inline void setPos(ntlVec3Gfx set) { mPos=set; }
00068                 inline void setVel(ntlVec3Gfx set) { mVel = set; }
00070                 inline void setVel(gfxReal x, gfxReal y, gfxReal z) { mVel = ntlVec3Gfx(x,y,z); }
00072                 inline ntlVec3Gfx getVel() { return mVel; }
00073 
00075                 inline gfxReal getSize() { return mSize; }
00076                 inline void setSize(gfxReal set) { mSize=set; }
00077 
00079                 inline ParticleObject* getNext() { return mpNext; }
00080                 inline void setNext(ParticleObject* set) { mpNext=set; }
00081 
00083                 inline int getFlags() const { return mStatus; }
00085                 inline int getStatus() const { return (mStatus&0xFF00); }
00087                 inline void setStatus(int set) { mStatus = set|(mStatus&0x00FF); }
00089                 inline int getType() const { return (mStatus&0x00FF); }
00091                 inline void setType(int set) { mStatus = set|(mStatus&0xFF00); }
00093                 inline bool getActive() const { return ((mStatus&PART_INACTIVE)==0); }
00095                 inline void setActive(bool set) { 
00096                         if(set) mStatus &= (~PART_INACTIVE);    
00097                         else mStatus |= PART_INACTIVE;
00098                 }
00100                 inline bool getInFluid() const { return ((mStatus&PART_OUTFLUID)==0); }
00102                 inline void setInFluid(bool set) { 
00103                         if(set) mStatus &= (~PART_OUTFLUID);    
00104                         else mStatus |= PART_OUTFLUID;
00105                 }
00107                 inline float getLifeTime() const { return mLifeTime; }
00109                 inline void setLifeTime(float set) { mLifeTime = set; }
00110                 
00111                 inline int getId() const { return mId; }
00112 
00113                 static inline float getMass(float size) { 
00114                         return 4.0/3.0 * M_PI* (size)*(size)*(size); // mass: 4/3 pi r^3 rho
00115                 }
00116 
00117         protected:
00118 
00120                 int mId;
00122                 ntlVec3Gfx mPos;
00124                 ntlVec3Gfx mVel;
00126                 gfxReal mSize;
00128                 int mStatus;
00130                 float mLifeTime;
00131 
00132                 /* for list constructions */
00133                 ParticleObject *mpNext;
00134 };
00135 
00136 
00138 class ParticleTracer :
00139         public ntlGeometryObject
00140 {
00141         public:
00143         ParticleTracer();
00145         ~ParticleTracer();
00146 
00148                 void addParticle(float x, float y, float z);
00150                 void addFullParticle(ParticleObject &np);
00151 
00153                 void draw();
00154                 
00156                 void parseAttrList( AttributeList *att );
00157 
00159                 void adaptPartTimestep(float factor);
00160 
00161                 // access funcs
00162                 
00164                 inline int  getNumParticles()                           { return mParts.size(); }
00166                 inline void setNumInitialParticles(int set) { mNumInitialParts=set; }
00167                 inline int  getNumInitialParticles()          { return mNumInitialParts; }
00168 
00170                 inline vector<ParticleObject>::iterator getParticlesBegin() { return mParts.begin(); }
00172                 inline vector<ParticleObject>::iterator getParticlesEnd() { return mParts.end(); }
00174                 inline ParticleObject* getLast() { return &(mParts[ mParts.size()-1 ]); }
00175                 
00177                 inline void setStart(ntlVec3Gfx set) { mStart = set; initTrafoMatrix(); }
00179                 inline void setEnd(ntlVec3Gfx set) { mEnd = set; initTrafoMatrix(); }
00181                 inline ntlVec3Gfx getStart() { return mStart; }
00183                 inline ntlVec3Gfx getEnd() { return mEnd; }
00184                 
00186                 inline void setSimStart(ntlVec3Gfx set) { mSimStart = set; initTrafoMatrix(); }
00188                 inline void setSimEnd(ntlVec3Gfx set) { mSimEnd = set; initTrafoMatrix(); }
00189                 
00191                 inline void setDumpParts(bool set) { mDumpParts = set; }
00192                 inline bool getDumpParts()         { return mDumpParts; }
00194                 inline void setDumpTextFile(string set) { mDumpTextFile = set; }
00195                 inline string getDumpTextFile()         { return mDumpTextFile; }
00197                 inline void setDumpTextInterval(float set) { mDumpTextInterval = set; }
00198                 inline float getDumpTextInterval()         { return mDumpTextInterval; }
00200                 inline void setInitStart(float set) { mInitStart = set; }
00201                 inline float getInitStart()         { return mInitStart; }
00202                 inline void setInitEnd(float set)   { mInitEnd = set; }
00203                 inline float getInitEnd()           { return mInitEnd; }
00204                 
00206                 inline void setPartScale(float set) { mPartScale = set; }
00207 
00209                 void checkDumpTextPositions(double simtime);
00210 
00211                 // NTL geometry implementation
00213                 virtual void getTriangles(double t, vector<ntlTriangle> *triangles, 
00214                                 vector<ntlVec3Gfx> *vertices, 
00215                                 vector<ntlVec3Gfx> *normals, int objectId );
00216 
00217                 virtual void notifyOfDump(int dumptype, int frameNr,char *frameNrStr,string outfilename,double simtime);
00218 
00219                 // notify of next step for trails
00220                 void checkTrails(double time);
00221                 // free deleted particles
00222                 void cleanup();
00223 
00224         protected:
00225 
00227                 vector<ParticleObject> mParts;
00228 
00230                 float mPartSize;
00231 
00233                 ntlVec3Gfx mStart, mEnd;
00234 
00236                 ntlVec3Gfx mSimStart, mSimEnd;
00237 
00239                 float mPartScale;
00241                 float mPartHeadDist, mPartTailDist;
00243                 int mPartSegments;
00245                 int mValueScale;
00247                 float mValueCutoffTop;
00249                 float mValueCutoffBottom;
00250 
00252                 int mDumpParts;
00254                 string mDumpTextFile;
00256                 float mDumpTextInterval;
00257                 float mDumpTextLastTime;
00258                 int mDumpTextCount;
00260                 int mShowOnly;
00262                 int mNumInitialParts;
00263 
00265                 ntlMatrix4x4<gfxReal> *mpTrafo;
00267                 void initTrafoMatrix();
00268 
00270                 float mInitStart, mInitEnd;
00271 
00273                 vector< vector<ParticleObject> > mPrevs;
00274                 /* prev pos save interval */
00275                 float mTrailTimeLast, mTrailInterval;
00276                 int mTrailLength;
00277 };
00278 
00279 #define NTL_PARTICLETRACER_H
00280 #endif
00281