00001 #include "Streamlines.h"
00002
00016 Streamlines::Streamlines (FlowData* dataset, int distance, float stepSize, int maxSteps, float width)
00017 {
00018 dist = distance;
00019 step = stepSize;
00020 max = maxSteps;
00021 data = dataset;
00022 w = width;
00023 }
00024
00035 void Streamlines::createGrid(int formula)
00036 {
00037 float pointX;
00038 float pointY;
00039 float diffX = (float)data->getChannel(0)->geom->getDimX()/w;
00040
00041 for(int i=dist; i < data->getChannel(0)->geom->getDimX(); i=i+dist)
00042 {
00043 for(int j=dist; j < data->getChannel(0)->geom->getDimY(); j=j+dist)
00044 {
00045 pointX = ((((float)i/data->getChannel(0)->geom->getDimX())*2)-1)*diffX;
00046 pointY = ((((float)j/data->getChannel(0)->geom->getDimY())*2)-1);
00047
00048
00049 if(formula == 1)
00050 getEulerPoints((pointX/diffX+1)*0.5, (pointY+1)*0.5);
00051 else if(formula == 2)
00052 getRungeKuttaPoints((pointX/diffX+1)*0.5, (pointY+1)*0.5);
00053 }
00054 }
00055 }
00056
00064 void Streamlines::getEulerPoints(float x, float y)
00065 {
00066 float poX, poY, pkX, pkY; int j; float dx, dy, vel;
00067 float* points = new float[max*2];
00068
00069
00070
00071
00072 poX = x;
00073 poY = y;
00074
00075
00076 j = 0;
00077 for (int i = 0; i < max; i++)
00078 {
00079 dx = data->getChannel(0)->getValueNormPos(poX, poY);
00080 dy = data->getChannel(1)->getValueNormPos(poX, poY);
00081 vel = data->getChannel(7)->getValueNormPos(poX, poY);
00082
00083 dx = dx/vel; dy = dy/vel;
00084
00085 pkX = poX+dx*step;
00086 pkY = poY+dy*step;
00087 points[j] = poX; j++;
00088 points[j] = poY; j++;
00089
00090 if (pkX < 0 || pkY < 0 || pkX > 1 || pkY > 1)
00091 {
00092 points[j] = -1; j++;
00093 points[j] = -1;
00094 break;
00095 }
00096
00097 poX = pkX; poY = pkY;
00098 }
00099 lines.push_back(points);
00100 points = new float[max*2];
00101
00102 poX = x;
00103 poY = y;
00104
00105
00106 j = 0;
00107 for (int i = 0; i < max; i++)
00108 {
00109 dx = data->getChannel(0)->getValueNormPos(poX, poY);
00110 dy = data->getChannel(1)->getValueNormPos(poX, poY);
00111 vel = data->getChannel(7)->getValueNormPos(poX, poY);
00112
00113 dx = dx/vel; dy = dy/vel;
00114
00115 pkX = poX-dx*step;
00116 pkY = poY-dy*step;
00117 points[j] = poX; j++;
00118 points[j] = poY; j++;
00119
00120 if (pkX < 0 || pkY < 0 || pkX > 1 || pkY > 1)
00121 {
00122 points[j] = -1; j++;
00123 points[j] = -1;
00124 break;
00125 }
00126
00127 poX = pkX; poY = pkY;
00128 }
00129 lines.push_back(points);
00130 }
00131
00139 void Streamlines::getRungeKuttaPoints(float x, float y)
00140 {
00141 float poX, poY, pkX, pkY; int j; float dx, dy, vel;
00142 float* points = new float[max*2];
00143
00144
00145
00146
00147 poX = x;
00148 poY = y;
00149
00150
00151 j = 0;
00152 for (int i = 0; i < max; i++)
00153 {
00154 dx = data->getChannel(0)->getValueNormPos(poX, poY);
00155 dy = data->getChannel(1)->getValueNormPos(poX, poY);
00156 vel = data->getChannel(7)->getValueNormPos(poX, poY);
00157
00158 dx = dx/vel; dy = dy/vel;
00159
00160 pkX = poX+dx*step*0.5f;
00161 pkY = poY+dy*step*0.5f;
00162
00163 points[j] = poX; j++;
00164 points[j] = poY; j++;
00165
00166 if (pkX < 0 || pkY < 0 || pkX > 1 || pkY > 1)
00167 {
00168 points[j] = -1; j++;
00169 points[j] = -1;
00170 break;
00171 }
00172
00173 dx = data->getChannel(0)->getValueNormPos(pkX, pkY);
00174 dy = data->getChannel(1)->getValueNormPos(pkX, pkY);
00175 vel = data->getChannel(7)->getValueNormPos(pkX, pkY);
00176
00177 dx = dx/vel; dy = dy/vel;
00178
00179 pkX = poX+dx*step;
00180 pkY = poY+dy*step;
00181
00182 if (pkX < 0 || pkY < 0 || pkX > 1 || pkY > 1)
00183 {
00184 points[j] = -1; j++;
00185 points[j] = -1;
00186 break;
00187 }
00188
00189 poX = pkX; poY = pkY;
00190 }
00191 lines.push_back(points);
00192
00193 points = new float[max*2];
00194
00195 poX = x;
00196 poY = y;
00197
00198
00199 j = 0;
00200 for (int i = 0; i < max; i++)
00201 {
00202 dx = data->getChannel(0)->getValueNormPos(poX, poY);
00203 dy = data->getChannel(1)->getValueNormPos(poX, poY);
00204 vel = data->getChannel(7)->getValueNormPos(poX, poY);
00205
00206 dx = dx/vel; dy = dy/vel;
00207
00208 pkX = poX-dx*step*0.5f;
00209 pkY = poY-dy*step*0.5f;
00210
00211 points[j] = poX; j++;
00212 points[j] = poY; j++;
00213
00214 if (pkX < 0 || pkY < 0 || pkX > 1 || pkY > 1)
00215 {
00216 points[j] = -1; j++;
00217 points[j] = -1;
00218 break;
00219 }
00220
00221 dx = data->getChannel(0)->getValueNormPos(pkX, pkY);
00222 dy = data->getChannel(1)->getValueNormPos(pkX, pkY);
00223 vel = data->getChannel(7)->getValueNormPos(pkX, pkY);
00224
00225 dx = dx/vel; dy = dy/vel;
00226
00227 pkX = poX-dx*step;
00228 pkY = poY-dy*step;
00229
00230 if (pkX < 0 || pkY < 0 || pkX > 1 || pkY > 1)
00231 {
00232 points[j] = -1; j++;
00233 points[j] = -1;
00234 break;
00235 }
00236
00237 poX = pkX; poY = pkY;
00238 }
00239 lines.push_back(points);
00240 }
00241
00252 std::vector<float*> Streamlines::getStreamLines(int formula)
00253 {
00254 createGrid(formula);
00255 return lines;
00256 }