Fluid3D.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #ifndef SOFA_COMPONENT_BEHAVIORMODEL_EULERIANFLUID_FLUID3D_H
00026 #define SOFA_COMPONENT_BEHAVIORMODEL_EULERIANFLUID_FLUID3D_H
00027
00028 #include <sofa/component/behaviormodel/eulerianfluid/Grid3D.h>
00029 #include <sofa/core/BehaviorModel.h>
00030 #include <sofa/core/VisualModel.h>
00031 #include <sofa/core/objectmodel/DataPtr.h>
00032 #include <sofa/core/objectmodel/Data.h>
00033 #include <sofa/helper/MarchingCubeUtility.h>
00034
00035 namespace sofa
00036 {
00037
00038 namespace component
00039 {
00040
00041 namespace behaviormodel
00042 {
00043
00044 namespace eulerianfluid
00045 {
00046
00047 class Fluid3D : public sofa::core::BehaviorModel, public sofa::core::VisualModel
00048 {
00049 public:
00050 typedef Grid3D::real real;
00051 typedef Grid3D::vec3 vec3;
00052 protected:
00053 int nx,ny,nz;
00054 real cellwidth;
00055
00056 Grid3D* fluid;
00057 Grid3D* fnext;
00058 Grid3D* ftemp;
00059
00060 public:
00061 sofa::core::objectmodel::DataPtr<int> f_nx;
00062 sofa::core::objectmodel::DataPtr<int> f_ny;
00063 sofa::core::objectmodel::DataPtr<int> f_nz;
00064 sofa::core::objectmodel::DataPtr<real> f_cellwidth;
00065 sofa::core::objectmodel::Data<vec3> f_center;
00066 sofa::core::objectmodel::Data<real> f_height;
00067 sofa::core::objectmodel::Data<vec3> f_dir;
00068 sofa::core::objectmodel::Data<real> f_tstart;
00069 sofa::core::objectmodel::Data<real> f_tstop;
00070
00071 Fluid3D();
00072 virtual ~Fluid3D();
00073
00074 int getNx() const { return f_nx.getValue(); }
00075 void setNx(int v) { f_nx.setValue(v); }
00076
00077 int getNy() const { return f_ny.getValue(); }
00078 void setNy(int v) { f_ny.setValue(v); }
00079
00080 int getNz() const { return f_nz.getValue(); }
00081 void setNz(int v) { f_nz.setValue(v); }
00082
00083 virtual void init();
00084
00085 virtual void reset();
00086
00087 virtual void updatePosition(double dt);
00088
00089 virtual void drawVisual();
00090
00091 virtual void exportOBJ(std::string name, std::ostream* out, std::ostream* mtl, int& vindex, int& nindex, int& tindex);
00092
00093 virtual void initVisual() {}
00094
00095 virtual void updateVisual();
00096
00097 virtual bool addBBox(double* minBBox, double* maxBBox);
00098
00099 protected:
00100
00101
00102 struct Vertex
00103 {
00104 vec3 p;
00105 vec3 n;
00106 };
00107
00108 struct Face
00109 {
00110 int p[3];
00111 };
00112
00113 sofa::helper::vector<Vertex> points;
00114 sofa::helper::vector<Face> facets;
00115
00117 struct CubeData
00118 {
00119 int p[3];
00120 };
00121
00122
00123 sofa::helper::vector<CubeData> planes;
00124
00125
00126
00127 template<int C>
00128 int addPoint(int x,int y,int z, real v0, real v1, real iso)
00129 {
00130 int p = points.size();
00131 vec3 pos((real)x,(real)y,(real)z);
00132 pos[C] -= (iso-v0)/(v1-v0);
00133 points.resize(p+1);
00134 points[p].p = pos;
00135 return p;
00136 }
00137
00138 int addFace(int p1, int p2, int p3)
00139 {
00140 int nbp = points.size();
00141 if ((unsigned)p1<(unsigned)nbp &&
00142 (unsigned)p2<(unsigned)nbp &&
00143 (unsigned)p3<(unsigned)nbp)
00144 {
00145 int f = facets.size();
00146 facets.resize(f+1);
00147 facets[f].p[0] = p1;
00148 facets[f].p[1] = p2;
00149 facets[f].p[2] = p3;
00150 return f;
00151 }
00152 else
00153 {
00154 std::cerr << "ERROR: Invalid face "<<p1<<" "<<p2<<" "<<p3<<std::endl;
00155 return -1;
00156 }
00157 }
00158
00159 };
00160
00161 }
00162
00163 }
00164
00165 }
00166
00167 }
00168
00169 #endif