Interpolator::NearestNeighbourInterpolator2D Class Reference

This class performs a nearest neighbour interpolation. More...

#include <NearestNeighbourInterpolator2D.h>

Inherits Interpolator::Interpolator2D.

Inherited by Interpolator::FourNearestNeighboursMeanInterpolator2D.

Inheritance diagram for Interpolator::NearestNeighbourInterpolator2D:

Inheritance graph
[legend]
Collaboration diagram for Interpolator::NearestNeighbourInterpolator2D:

Collaboration graph
[legend]
List of all members.

Public Member Functions

 NearestNeighbourInterpolator2D ()
 Default constructor.
virtual ~NearestNeighbourInterpolator2D ()
 Destructor.
 NearestNeighbourInterpolator2D (std::string sName, std::string sDescription, std::string sInterpolationType, InterpolationData2D *mInterpolationData)
 This constructor requires 3 parameters :
  • the name of the interpolator
  • the description of the interpolator
  • the interpolation type (must be "Nearest")
  • the interpolation data.

virtual double getInterpolatedValue (double dXValue, double dYValue)
 Return the interpolated value for the wanted couple (dXValue,dYvalue).

Private Member Functions

virtual double compute (double dXValue, double dYValue)
 Compute the interpolated value.

Detailed Description

This class performs a nearest neighbour interpolation.

Definition at line 16 of file NearestNeighbourInterpolator2D.h.


Constructor & Destructor Documentation

Interpolator::NearestNeighbourInterpolator2D::NearestNeighbourInterpolator2D  ) 
 

Default constructor.

Definition at line 18 of file NearestNeighbourInterpolator2D.cpp.

00019 {
00020 
00021 }

Interpolator::NearestNeighbourInterpolator2D::~NearestNeighbourInterpolator2D  )  [virtual]
 

Destructor.

Definition at line 24 of file NearestNeighbourInterpolator2D.cpp.

00025 {
00026 
00027 }

Interpolator::NearestNeighbourInterpolator2D::NearestNeighbourInterpolator2D std::string  sName,
std::string  sDescription,
std::string  sInterpolationType,
InterpolationData2D mInterpolationData
 

This constructor requires 3 parameters :

  • the name of the interpolator
  • the description of the interpolator
  • the interpolation type (must be "Nearest")
  • the interpolation data.

Definition at line 34 of file NearestNeighbourInterpolator2D.cpp.

00037                                                                                                                                                                          : 
00038 Interpolator2D(sName,sDescription,sInterpolationType,mInterpolationData)
00039 {
00040 }


Member Function Documentation

double Interpolator::NearestNeighbourInterpolator2D::compute double  dXValue,
double  dYValue
[private, virtual]
 

Compute the interpolated value.

Implements Interpolator::Interpolator2D.

Reimplemented in Interpolator::FourNearestNeighboursMeanInterpolator2D.

Definition at line 51 of file NearestNeighbourInterpolator2D.cpp.

References Interpolator::Interpolator2D::_mInterpolationData, Interpolator::Interpolator::_verb, Interpolator::Interpolator2D::findXIndex(), Interpolator::Interpolator2D::findYIndex(), Interpolator::InterpolationData2D::getNbXData(), Interpolator::InterpolationData2D::getNbYData(), and Interpolator::InterpolationData2D::getZValue().

Referenced by getInterpolatedValue().

00052 {
00053         //Faire algo quicksort pour plus de rapidité et faire les verifs sur les index calculés et sur le z si possible 
00054         int iXIndex = findXIndex(dXValue);
00055         int iYIndex = findYIndex(dYValue);
00056         
00057         double z,z1,z2,z3,z4,x1,x3,y1,y2;
00058 
00059         z = 0;
00060         //The 4 cases where the indexes for X and Y are outside the arrays (four corners cases)
00061         if ((iXIndex >= _mInterpolationData->getNbXData()) && (iYIndex >= _mInterpolationData->getNbYData()))
00062         {
00063                 if(Interpolator::_verb == true) cout << "case 1" << endl;
00064                 z = _mInterpolationData->getZValue(iXIndex-1,iYIndex-1);
00065         }
00066         
00067         else if ((iXIndex == -1) && (iYIndex == -1))
00068         {       
00069                 if(Interpolator::_verb == true) cout << "case 2" << endl;
00070                 z = _mInterpolationData->getZValue(0,0);
00071         }
00072 
00073         else if ((iXIndex == -1) && (iYIndex >= _mInterpolationData->getNbYData()))
00074         {
00075                 if(Interpolator::_verb == true) cout << "case 3" << endl;
00076                 z = _mInterpolationData->getZValue(0,iYIndex-1);
00077         }
00078 
00079         else if ((iXIndex >= _mInterpolationData->getNbXData()) && (iYIndex == -1))
00080         {
00081                 if(Interpolator::_verb == true) cout << "case 4" << endl;
00082                 z = _mInterpolationData->getZValue(iXIndex-1,0);
00083         }
00084 
00085 
00086         //The case when the X index is outside (bigger than the last index) of the array
00087         else if (iXIndex >= _mInterpolationData->getNbXData()) 
00088         {
00089                 if(Interpolator::_verb == true) cout << "case 5" << endl;
00090                 x1      =  _mInterpolationData->getXValue(iXIndex-1);
00091                  
00092                 y1 =  _mInterpolationData->getYValue(iYIndex);
00093                 y2 =  _mInterpolationData->getYValue(iYIndex+1);
00094 
00095                 z1      = _mInterpolationData->getZValue(iXIndex-1,iYIndex);
00096                 z2      = _mInterpolationData->getZValue(iXIndex-1,iYIndex+1);          
00097         
00098                 double dDistance1 = x1*x1 + y1*y1;
00099                 double dDistance2 = x1*x1 + y2*y2;
00100                 
00101                 if (isLessThan(dDistance1,dDistance2)) z =  z1;
00102                 else z =  z2;
00103         }
00104         
00105         //The case when the X index is outside (lower than the first index) of the array
00106         else if (iXIndex == -1) 
00107         {
00108                 if(Interpolator::_verb == true) cout << "case 6" << endl;
00109                  x1     =  _mInterpolationData->getXValue(iXIndex+1);
00110                  
00111                  y1 =  _mInterpolationData->getYValue(iYIndex);
00112                  y2 =  _mInterpolationData->getYValue(iYIndex+1);
00113 
00114                  z1     = _mInterpolationData->getZValue(iXIndex+1,iYIndex);
00115                  z2     = _mInterpolationData->getZValue(iXIndex+1,iYIndex+1);          
00116                 
00117                 double dDistance1 = x1*x1 + y1*y1;
00118                 double dDistance2 = x1*x1 + y2*y2;
00119                 
00120                 if (isLessThan(dDistance1,dDistance2)) z =  z1;
00121                 else z =  z2;
00122         }
00123 
00124         //The case when the Y index is outside (bigger than the last index) of the array
00125         else if (iYIndex >= _mInterpolationData->getNbYData())
00126         {
00127                 if(Interpolator::_verb == true) cout << "case 7" << endl;
00128                  y1 =  _mInterpolationData->getYValue(iYIndex-1);
00129 
00130                  z1     = _mInterpolationData->getZValue(iXIndex,iYIndex-1);
00131                  z3     = _mInterpolationData->getZValue(iXIndex+1,iYIndex-1);          
00132         
00133                  x1     =  _mInterpolationData->getXValue(iXIndex);
00134                  x3     =  _mInterpolationData->getXValue(iXIndex+1);
00135                 
00136                 double dDistance1 = x1*x1 + y1*y1;
00137                 double dDistance2 = x3*x3 + y1*y1;
00138                 
00139                 if (isLessThan(dDistance1,dDistance2)) z =  z1;
00140                 else z =  z3;
00141         }
00142         
00143                 
00144         //The case when the Y index is outside (lower than the first index) of the array
00145         else if (iYIndex == -1 )
00146         {
00147                 if(Interpolator::_verb == true) cout << "case 8" << endl;
00148                  y1 =  _mInterpolationData->getYValue(iYIndex+1);
00149 
00150                  z1     = _mInterpolationData->getZValue(iXIndex,iYIndex+1);
00151                  z3     = _mInterpolationData->getZValue(iXIndex+1,iYIndex+1);          
00152         
00153                  x1     =  _mInterpolationData->getXValue(iXIndex);
00154                  x3     =  _mInterpolationData->getXValue(iXIndex+1);
00155                 
00156                 double dDistance1 = x1*x1 + y1*y1;
00157                 double dDistance2 = x3*x3 + y1*y1;
00158                 
00159                 if (isLessThan(dDistance1,dDistance2)) z = z1;
00160                 else z =  z3;
00161         }
00162 
00163 
00164         //Normal case
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                 double dDistance1 = x1*x1 + y1*y1;
00179                 double dDistance2 = x1*x1 + y2*y2;
00180                 double dDistance3 = x3*x3 + y2*y2;
00181                 double dDistance4 = x3*x3 + y1*y1;
00182 
00183                 std::vector<double> distanceVector;
00184                 distanceVector.push_back(dDistance1);
00185                 distanceVector.push_back(dDistance2);
00186                 distanceVector.push_back(dDistance3);
00187                 distanceVector.push_back(dDistance4);
00188                 sort(distanceVector.begin(), distanceVector.end());
00189                 
00190                 if (distanceVector[0] == dDistance1) z = z1;
00191                 else if (distanceVector[0] == dDistance2) z = z2;
00192                 else if (distanceVector[0] == dDistance3) z = z3;
00193                 else if (distanceVector[0] == dDistance4) z = z4;
00194 
00195         }
00196         if(Interpolator::_verb == true) cout << _mInterpolationData->getZName() << "=f(" << _mInterpolationData->getXName() << "," << _mInterpolationData->getYName() << ")=f("<< dXValue << "," << dYValue<< ")=" <<  z << endl;
00197         //if(Interpolator::_verb == true) cout << "z=f("<< dXValue << "," << dYValue<< ")=" <<  z << endl;
00198         return z;
00199 }

Here is the call graph for this function:

double Interpolator::NearestNeighbourInterpolator2D::getInterpolatedValue double  dXValue,
double  dYValue
[virtual]
 

Return the interpolated value for the wanted couple (dXValue,dYvalue).

Implements Interpolator::Interpolator2D.

Reimplemented in Interpolator::FourNearestNeighboursMeanInterpolator2D.

Definition at line 44 of file NearestNeighbourInterpolator2D.cpp.

References compute().

00045 {
00046         double z = compute(dXValue,dYValue);
00047         return z;
00048 }

Here is the call graph for this function:


The documentation for this class was generated from the following files:
Generated on Tue Apr 14 09:51:39 2009 for Interpolator Library by  doxygen 1.4.5