Waterflow
Visualize water in terrain
src/flowSource.cpp
Go to the documentation of this file.
00001 
00002 
00003 
00004 #include "flowSource.h"
00005 
00006 // This functoin expects pressure and time values in two seperates vectors with a N to N corespondence,
00007 // where N is the vector position.
00008 // For example P = [1.5 , 2.1, 1.7] time = [1, 3, 8] gives that the pressure is 2.1 between the time 1 and 3.
00009 // The time vector most be sorted from smalest element to largest.
00010 void FlowSource::setPressure(std::vector<float> P, std::vector<float> time){
00011   pressure = P;
00012   pressureTime = time;
00013 }
00014 
00015 // This function expects a vector filled with vectors that hold 3 values, xyz, and a time vector that specifies when to change the Normal direction. this time vector can be independent from the one used for pressure.
00016 void FlowSource::setNormal(std::vector< std::vector<float> > N, std::vector<int> time){
00017   normal = N;
00018   normalTime = time;
00019 }
00020 
00021 // This function expects three ints symbolizing the 3D space cordinates of the source expressed in voxels
00022 void FlowSource::setPosition(int x, int y, int z){
00023   xpos=x;
00024   ypos=y;
00025   zpos=z;
00026 }
00027 
00028 // This simply sets a float symbolising the total water in a source, no method changing this parameter has been implemented yet.
00029 void FlowSource::setTotalWater(float waterAmount){
00030   totalWater = waterAmount;
00031 }
00032 
00033 
00034 void FlowSource::setRadius(float r){
00035   radius = r;
00036 }
00037 
00038 // This function updates the internal time of the source idealy this should be called att constant intervals e.g. onece evry loop of simulation. It could be expanded with calculating remaining water.
00039 void FlowSource::update(float dt){
00040   currTime = currTime + dt;
00041 }
00042 
00043 // This function returns the curent pressure depending on the internal time set by the update function.
00044 float FlowSource::getPressure(){
00045  unsigned int currItr = 0;
00046   for(auto i = pressureTime.begin(); i !=pressureTime.end(); ++i){
00047     if( *i < currTime) currItr++;
00048     else break;
00049   }
00050   if (currItr < pressureTime.size())
00051     return pressure.at(currItr);
00052   else if (pressureTime.back() == -1)
00053     return pressure.back();
00054   else
00055     return 0;
00056 }
00057 
00058 // This function returns a thee valued vector with xyz defining the Normal direction at the internal time specified by the update function.
00059 std::vector<float> FlowSource::getNormal(){  
00060   unsigned int currItr = 0;
00061   std::vector<float> err = {0, 0, 0};
00062   for(auto i = normalTime.begin(); i !=normalTime.end(); ++i){
00063     if( *i <= currTime) currItr++;
00064     else break;
00065   }
00066   if (currItr < normalTime.size())
00067     return normal.at(currItr);
00068   else if (normalTime.back() == -1)
00069     return normal.back();
00070   else
00071     return err;
00072 }
00073 
00074 // This returns the position as a three valued vector containing xyz.
00075 std::vector<int> FlowSource::getPosition(){
00076   std::vector<int> pos;
00077   pos.push_back(xpos);
00078   pos.push_back(ypos);
00079   pos.push_back(zpos);
00080   return pos;
00081 }
00082 
00083 
00084 float FlowSource::getWaterLeft(){
00085   return totalWater;
00086 }
00087 
00088 float FlowSource::getRadius(){
00089   return radius;
00090 }
00091 
00092 
00093 bool FlowSource::getChange(float dt) {
00094   //currPres = FlowSource::getPressure();
00095   FlowSource::update(dt);
00096   float newPre = FlowSource::getPressure();
00097   if(newPre == currPres){
00098     return false;
00099   }
00100   else {
00101     currPres = newPre;
00102     return true;
00103   }  
00104 }
 All Classes Files Functions Variables Enumerations