00001
00002
00004 #ifdef WIN32
00005 #pragma warning(disable:4786)
00006 #endif
00007
00008 #include "FourNearestNeighboursMeanInterpolator2D.h"
00009 #include <iostream>
00011
00013 namespace Interpolator
00014 {
00016 FourNearestNeighboursMeanInterpolator2D::FourNearestNeighboursMeanInterpolator2D()
00017 {
00018
00019 }
00020
00022 FourNearestNeighboursMeanInterpolator2D::~FourNearestNeighboursMeanInterpolator2D()
00023 {
00024
00025 }
00026
00031 FourNearestNeighboursMeanInterpolator2D::FourNearestNeighboursMeanInterpolator2D(
00032 std::string sName,
00033 std::string sDescription,
00034 InterpolationData2D* mInterpolationData) :
00035 NearestNeighbourInterpolator2D(sName,sDescription,"4 Nearest Neighbours Mean",mInterpolationData)
00036 {
00037 }
00038
00040 double FourNearestNeighboursMeanInterpolator2D::getInterpolatedValue(double dXValue,double dYValue)
00041 {
00042 double z = compute(dXValue,dYValue);
00043 return z;
00044 }
00045
00047 double FourNearestNeighboursMeanInterpolator2D::compute(double dXValue,double dYValue)
00048 {
00049
00050 int iXIndex = findXIndex(dXValue);
00051 int iYIndex = findYIndex(dYValue);
00052
00053 double z,z1,z2,z3,z4,x1,x3,y1,y2;
00054
00055
00056 if ((iXIndex >= _mInterpolationData->getNbXData()) && (iYIndex >= _mInterpolationData->getNbYData()))
00057 {
00058 if(Interpolator::_verb == true) cout << "case 1" << endl;
00059 z = _mInterpolationData->getZValue(iXIndex-1,iYIndex-1);
00060 }
00061
00062 else if ((iXIndex == -1) && (iYIndex == -1))
00063 {
00064 if(Interpolator::_verb == true) cout << "case 2" << endl;
00065 z = _mInterpolationData->getZValue(0,0);
00066 }
00067
00068 else if ((iXIndex == -1) && (iYIndex >= _mInterpolationData->getNbYData()))
00069 {
00070 if(Interpolator::_verb == true) cout << "case 3" << endl;
00071 z = _mInterpolationData->getZValue(0,iYIndex-1);
00072 }
00073
00074 else if ((iXIndex >= _mInterpolationData->getNbXData()) && (iYIndex == -1))
00075 {
00076 if(Interpolator::_verb == true) cout << "case 4" << endl;
00077 z = _mInterpolationData->getZValue(iXIndex-1,0);
00078 }
00079
00080
00081
00082 else if (iXIndex >= _mInterpolationData->getNbXData())
00083 {
00084 if(Interpolator::_verb == true) cout << "case 5" << endl;
00085 x1 = _mInterpolationData->getXValue(iXIndex-1);
00086
00087 y1 = _mInterpolationData->getYValue(iYIndex);
00088 y2 = _mInterpolationData->getYValue(iYIndex+1);
00089
00090 z1 = _mInterpolationData->getZValue(iXIndex-1,iYIndex);
00091 z2 = _mInterpolationData->getZValue(iXIndex-1,iYIndex+1);
00092
00093 if(Interpolator::_verb == true) cout << "(iX-1=" << iXIndex-1 << "|iY=" << iYIndex << ") --> (" << x1 << "," << y1 << "," << z1 << ")" << endl;
00094 if(Interpolator::_verb == true) cout << "(iX=" << iXIndex << "|iY+1=" << iYIndex+1 << ") --> (" << x1 << "," << y2 << "," << z2 << ")" << endl;
00095
00096 double zMean = (z1 + z2)/2.0;
00097
00098 z = zMean;
00099 }
00100
00101
00102 else if (iXIndex == -1)
00103 {
00104 if(Interpolator::_verb == true) cout << "case 6" << endl;
00105 x1 = _mInterpolationData->getXValue(iXIndex+1);
00106
00107 y1 = _mInterpolationData->getYValue(iYIndex);
00108 y2 = _mInterpolationData->getYValue(iYIndex+1);
00109
00110 z1 = _mInterpolationData->getZValue(iXIndex+1,iYIndex);
00111 z2 = _mInterpolationData->getZValue(iXIndex+1,iYIndex+1);
00112
00113 if(Interpolator::_verb == true) cout << "(iX=" << iXIndex << "|iY=" << iYIndex << ") --> (" << x1 << "," << y1 << "," << z1 << ")" << endl;
00114 if(Interpolator::_verb == true) cout << "(iX+1=" << iXIndex+1 << "|iY+1=" << iYIndex+1 << ") --> (" << x1 << "," << y2 << "," << z2 << ")" << endl;
00115
00116 double zMean = (z1 + z2)/2.0;
00117
00118 z = zMean;
00119 }
00120
00121
00122 else if (iYIndex >= _mInterpolationData->getNbYData())
00123 {
00124 if(Interpolator::_verb == true) cout << "case 7" << endl;
00125 y1 = _mInterpolationData->getYValue(iYIndex-1);
00126
00127 z1 = _mInterpolationData->getZValue(iXIndex,iYIndex-1);
00128 z3 = _mInterpolationData->getZValue(iXIndex+1,iYIndex-1);
00129
00130 x1 = _mInterpolationData->getXValue(iXIndex);
00131 x3 = _mInterpolationData->getXValue(iXIndex+1);
00132
00133 if(Interpolator::_verb == true) cout << "(iX=" << iXIndex << "|iY-1=" << iYIndex-1 << ") --> (" << x1 << "," << y1 << "," << z1 << ")" << endl;
00134 if(Interpolator::_verb == true) cout << "(iX+1=" << iXIndex+1 << "|iY=" << iYIndex << ") --> (" << x3 << "," << y1 << "," << z3 << ")" << endl;
00135
00136 double zMean = (z1 + z3)/2.0;
00137
00138 z = zMean;
00139 }
00140
00141
00142
00143 else if (iYIndex == -1 )
00144 {
00145 if(Interpolator::_verb == true) cout << "case 8" << endl;
00146 y1 = _mInterpolationData->getYValue(iYIndex+1);
00147
00148 z1 = _mInterpolationData->getZValue(iXIndex,iYIndex+1);
00149 z3 = _mInterpolationData->getZValue(iXIndex+1,iYIndex+1);
00150
00151 x1 = _mInterpolationData->getXValue(iXIndex);
00152 x3 = _mInterpolationData->getXValue(iXIndex+1);
00153
00154 if(Interpolator::_verb == true) cout << "(iX=" << iXIndex << "|iY=" << iYIndex << ") --> (" << x1 << "," << y1 << "," << z1 << ")" << endl;
00155 if(Interpolator::_verb == true) cout << "(iX+1=" << iXIndex+1 << "|iY+1=" << iYIndex+1 << ") --> (" << x3 << "," << y1 << "," << z3 << ")" << endl;
00156
00157
00158 double zMean = (z1 + z3)/2.0;
00159
00160 z = zMean;
00161 }
00162
00163
00164
00165 else
00166 {
00167 if(Interpolator::_verb == true) cout << "case 9" << endl;
00168 z1 = _mInterpolationData->getZValue(iXIndex,iYIndex);
00169 z2 = _mInterpolationData->getZValue(iXIndex,iYIndex+1);
00170 z3 = _mInterpolationData->getZValue(iXIndex+1,iYIndex+1);
00171 z4 = _mInterpolationData->getZValue(iXIndex+1,iYIndex);
00172
00173 x1 = _mInterpolationData->getXValue(iXIndex);
00174 x3 = _mInterpolationData->getXValue(iXIndex+1);
00175 y1 = _mInterpolationData->getYValue(iYIndex);
00176 y2 = _mInterpolationData->getYValue(iYIndex+1);
00177
00178 if(Interpolator::_verb == true) cout << "(iX=" << iXIndex << "|iY=" << iYIndex << ") --> (" << x1 << "," << y1 << "," << z1 << ")" << endl;
00179 if(Interpolator::_verb == true) cout << "(iX+1=" << iXIndex+1 << "|iY=" << iYIndex << ") --> (" << x3 << "," << y1 << "," << z2 << ")" << endl;
00180 if(Interpolator::_verb == true) cout << "(iX+1=" << iXIndex+1 << "|iY+1=" << iYIndex+1 << ") --> (" << x3 << "," << y2 << "," << z3 << ")" << endl;
00181 if(Interpolator::_verb == true) cout << "(iX=" << iXIndex << "|iY+1=" << iYIndex+1 << ") --> (" << x1 << "," << y2 << "," << z4 << ")" << endl;
00182
00183 double zMean = (z1 + z2 + z3 + z4)/4.0;
00184 z = zMean;
00185 }
00186 if(Interpolator::_verb == true) cout << _mInterpolationData->getZName() << "=f(" << _mInterpolationData->getXName() << "," << _mInterpolationData->getYName() << ")=f("<< dXValue << "," << dYValue<< ")=" << z << endl;
00187
00188 return z;
00189 }
00190 }
00191