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
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include <string.h>
00038 #include <stdio.h>
00039 #include <math.h>
00040
00041 #include "PSSources.h"
00042
00043
00044
00045 plumesim::PSMeadering::PSMeadering()
00046 {
00047 this->changesOverTime = false;
00048
00049 this->startPoint.px = 0.0;
00050 this->startPoint.py = 0.0;
00051 this->startPoint.pz = 0.0;
00052
00053 this->arenaRect.startPoint.px = 0.0;
00054 this->arenaRect.startPoint.py = 0.0;
00055 this->arenaRect.endPoint.px = 0.0;
00056 this->arenaRect.endPoint.py = 0.0;
00057
00058 this->numOfPlumePoints = 200;
00059 this->releaseRate = 10.0;
00060 this->dispersionCoeficient = 0.1;
00061 this->radius = 0.1;
00062 }
00063
00064
00065
00066 plumesim::PSMeadering::~PSMeadering()
00067 {
00068
00069 }
00070
00071
00072
00073 int plumesim::PSMeadering::setup()
00074 {
00075 if(!plumePoints.empty()) plumePoints.clear();
00076 this->isPlaying = true;
00077 return 0;
00078 }
00079
00080
00081
00082 int plumesim::PSMeadering::cleanup()
00083 {
00084 plumePoints.clear();
00085 return 0;
00086 }
00087
00088
00089
00090 int plumesim::PSMeadering::generatePoints()
00091 {
00092 int i;
00093
00094 if(!plumePoints.empty()) plumePoints.clear();
00095
00096 PSPoint3d startupPoints[MIN_NUM_OF_POINTS];
00097
00098 double step = (arenaRect.endPoint.px - startPoint.px)/MIN_NUM_OF_POINTS;
00099
00100 for(i=0 ; i<MIN_NUM_OF_POINTS ; i++) startupPoints[i].px = startPoint.px + i * step;
00101
00102 double sigma = 0.2*step;
00103
00104 startupPoints[0].py = startPoint.py;
00105
00106 double ay[MIN_NUM_OF_POINTS];
00107
00108 for(i=0 ; i<MIN_NUM_OF_POINTS ; i++) ay[i] = sigma*randomNormal();
00109
00110 double vy[MIN_NUM_OF_POINTS];
00111
00112 vy[0] = sigma*randomNormal();
00113
00114 for(i=1 ; i<MIN_NUM_OF_POINTS ; i++)
00115 {
00116
00117 vy[i] = vy[i-1] + ay[i-1];
00118
00119 startupPoints[i].py = startupPoints[i-1].py + vy[i-1];
00120 }
00121
00122 linearInterpolation(startupPoints, MIN_NUM_OF_POINTS);
00123
00124 PSPoint3d * plumePoint;
00125 for(i=0 ; i<plumePoints.size() ; i++)
00126 {
00127 plumePoint = &plumePoints[i];
00128
00129 plumePoint->py = plumePoint->py + ( dispersionCoeficient * (plumePoint->px - startPoint.px) * (releaseRate * randomNormal()));
00130 }
00131
00132 PSPoint3d center;
00133 center.px = startPoint.px + radius;
00134 center.py = startPoint.py;
00135 center.pz = 0.0;
00136
00137 maxPoints = this->countPoints(¢er, radius);
00138
00139 this->isPlaying = false;
00140
00141 return(0);
00142 }
00143
00144
00145
00146 int plumesim::PSMeadering::getChemicalReading(PSPoint3d * point, PSOdorData * odor_data)
00147 {
00148 int pointCount = this->countPoints(point, radius);
00149
00150 odor_data->chemical = fmin(100.0, 100.0*pointCount/maxPoints);
00151
00152
00153 odor_data->windDirection = 0.0;
00154 odor_data->windSpeed = 0.5;
00155
00156 return(0);
00157 }
00158
00159
00160
00161 void plumesim::PSMeadering::linearInterpolation(PSPoint3d * points, int numOfPoints)
00162 {
00163 double b, m;
00164 int i, j;
00165 PSPoint3d point;
00166
00167 int pointsOnThisSection;
00168
00169 double x_step = (points[numOfPoints-1].px - points[0].px) / numOfPlumePoints;
00170
00171 for(i=0 ; i<numOfPoints-1 ; i++)
00172 {
00173 point.px = points[i].px;
00174 point.py = points[i].py;
00175 point.pz = 0.0;
00176 plumePoints.push_back(point);
00177
00178 m = (points[i+1].py - points[i].py)/(points[i+1].px - points[i].px);
00179 b = points[i].py - m * points[i].px;
00180
00181 pointsOnThisSection = (points[i+1].px - points[i].px) / x_step;
00182
00183 for(j=0 ; j<pointsOnThisSection ; j++)
00184 {
00185 point.px = points[i].px + (j+1)*x_step;
00186 point.py = m * point.px + b;
00187 point.pz = 0.0;
00188 plumePoints.push_back(point);
00189 }
00190 }
00191 point.px = points[numOfPoints-1].px;
00192 point.py = points[numOfPoints-1].py;
00193 point.pz = 0.0;
00194 plumePoints.push_back(point);
00195 }
00196
00197
00198