InterpolationData2D.cpp

Go to the documentation of this file.
00001 // InterpolationData2D.cpp: implementation of the InterpolationData2D class.
00002 //
00004 #ifdef WIN32 
00005 #pragma warning(disable:4786)
00006 #endif
00007 
00008 #include "InterpolationData2D.h"
00009 #include <iostream>
00011 // Construction/Destruction
00013 namespace Interpolator
00014 {
00016 InterpolationData2D::InterpolationData2D()
00017 {
00018 
00019 }
00020 
00022 InterpolationData2D::~InterpolationData2D()
00023 {
00024         delete [] _mXValues;
00025         delete [] _mYValues;
00026         delete [] _mZValues;
00027         _mXValues = 0;
00028         _mYValues = 0;
00029         _mZValues = 0;
00030 }
00031 
00041 InterpolationData2D::InterpolationData2D(       std::string sXName, std::string sYName, std::string sZName,
00042                                                                                         long lNbXData,long lNbYData,
00043                                                                                         double* mXValues, double* mYValues, double* mZValues) : 
00044 _sXName(sXName),_sYName(sYName),_sZName(sZName),
00045 _lNbXData(lNbXData),_lNbYData(lNbYData),_lNbZData(lNbXData*lNbYData)
00046 {
00047 
00048         _mXValues = new double[_lNbXData];
00049         _mYValues = new double[_lNbYData];
00050         _mZValues = new double[_lNbZData];
00051 
00052         setValues(_lNbXData,_lNbYData,mXValues,mYValues,mZValues);
00053 }
00054 
00056 std::string InterpolationData2D::getXName() const
00057 {
00058         return _sXName;
00059 }
00060 
00062 std::string InterpolationData2D::getYName() const
00063 {
00064         return _sYName;
00065 }
00066 
00068 std::string InterpolationData2D::getZName() const
00069 {
00070         return _sZName;
00071 }
00072 
00073 
00077 double InterpolationData2D::getXValue(int i) const // throw (IndexOutOfBoundException,NullPointerException)
00078 {
00079         if ((i < 0) || (i >= getNbXData())) throw IndexOutOfBoundException("index",i,0,getNbXData(),"InterpolationData2D::getXValue(int i)",__FILE__,__LINE__); 
00080         if (_mXValues == 0) throw NullPointerException("_mXValues","InterpolationData2D::getXValue(int i)",__FILE__,__LINE__);
00081         return _mXValues[i];
00082 }
00083 
00087 double InterpolationData2D::getYValue(int i) const // throw (IndexOutOfBoundException,NullPointerException)
00088 {
00089         if ((i < 0) || (i >= getNbYData())) throw IndexOutOfBoundException("index",i,0,getNbYData(),"InterpolationData2D::getYValue(int i)",__FILE__,__LINE__); 
00090         if (_mYValues == 0) throw NullPointerException("_mYValues","InterpolationData2D::getYValue(int i)",__FILE__,__LINE__);
00091         return _mYValues[i];
00092 }
00093 
00097 double InterpolationData2D::getZValue(int i,int j) const // throw (IndexOutOfBoundException,NullPointerException)
00098 {
00099         if ((i < 0) || (i >= getNbXData())) throw IndexOutOfBoundException("index",i,0,getNbXData(),"InterpolationData2D::getZValue(int i,int j)",__FILE__,__LINE__); 
00100         if ((j < 0) || (j >= getNbYData())) throw IndexOutOfBoundException("index",j,0,getNbYData(),"InterpolationData2D::getZValue(int i,int j)",__FILE__,__LINE__); 
00101         if (_mZValues == 0) throw NullPointerException("_mZValues","InterpolationData2D::getZValue(int i,int j)",__FILE__,__LINE__);
00102         return _mZValues[i*_lNbYData + j];
00103 }
00104 
00105 
00107 long InterpolationData2D::getNbXData() const
00108 {
00109         return _lNbXData;
00110 }
00111 
00113 long InterpolationData2D::getNbYData() const
00114 {
00115         return _lNbYData;
00116 }
00117 
00119 long InterpolationData2D::getNbZData() const
00120 {
00121         return _lNbZData;
00122 }
00123 
00124 
00125 
00126 
00127 
00131 void InterpolationData2D::setXValue(int i,double dNewValue) // throw (IndexOutOfBoundException,NullPointerException)
00132 {
00133         if ((i < 0) || (i >= getNbXData())) throw IndexOutOfBoundException("index",i,0,getNbXData(),"InterpolationData2D::setXValue(int i,double dNewValue)",__FILE__,__LINE__); 
00134         if (_mXValues == 0) throw NullPointerException("_mXValues","InterpolationData2D::setXValue(int i,double dNewValue)",__FILE__,__LINE__);
00135         _mXValues[i] = dNewValue;
00136 }
00137 
00141 void InterpolationData2D::setYValue(int i,double dNewValue) // throw (IndexOutOfBoundException,NullPointerException)
00142 {
00143         if ((i < 0) || (i >= getNbYData())) throw IndexOutOfBoundException("index",i,0,getNbYData(),"InterpolationData2D::setYValue(int i,double dNewValue)",__FILE__,__LINE__); 
00144         if (_mYValues == 0) throw NullPointerException("_mYValues","InterpolationData2D::setYValue(int i,double dNewValue)",__FILE__,__LINE__);
00145         _mYValues[i] = dNewValue;
00146 }
00147 
00148 
00152 void InterpolationData2D::setZValue(int i,int j,double dNewValue) // throw (IndexOutOfBoundException,NullPointerException)
00153 {
00154         if ((i < 0) || (i >= getNbXData())) throw IndexOutOfBoundException("index",i,0,getNbXData(),"InterpolationData2D::setZValue(int i,int j,double dNewValue)",__FILE__,__LINE__); 
00155         if ((j < 0) || (j >= getNbYData())) throw IndexOutOfBoundException("index",j,0,getNbYData(),"InterpolationData2D::setZValue(int i,int j,double dNewValue)",__FILE__,__LINE__); 
00156         if (_mZValues == 0) throw NullPointerException("_mZValues","InterpolationData2D::setZValue(int i,int j,double dNewValue)",__FILE__,__LINE__);
00157         _mZValues[i*_lNbYData + j] = dNewValue;
00158 }
00159 
00162 double* InterpolationData2D::getXValues() const // throw (NullPointerException)
00163 {
00164         if (_mXValues == 0) throw NullPointerException("_mXValues","InterpolationData2D::getXValues()",__FILE__,__LINE__);
00165         return _mXValues;
00166 }
00167 
00170 double* InterpolationData2D::getYValues() const // throw (NullPointerException)
00171 {
00172         if (_mYValues == 0) throw NullPointerException("_mYValues","InterpolationData2D::getYValues()",__FILE__,__LINE__);
00173         return _mYValues;
00174 }
00175 
00178 double* InterpolationData2D::getZValues() const // throw (NullPointerException)
00179 {
00180         if (_mZValues == 0) throw NullPointerException("_mZValues","InterpolationData2D::getZValues()",__FILE__,__LINE__);
00181         return _mZValues;
00182 }
00183 
00184 
00187 void InterpolationData2D::setXValues(double* dNewValues)
00188 {
00189     for (int i=0;i<_lNbXData;i++)
00190         {
00191           setXValue(i,*(dNewValues+i));
00192         }
00193 }
00194 
00197 void InterpolationData2D::setYValues(double* dNewValues)
00198 {   
00199     for (int i=0;i<_lNbYData;i++)
00200         {
00201           setYValue(i,*(dNewValues+i));
00202         }
00203 }
00204 
00205 
00208 void InterpolationData2D::setZValues(double* dNewValues)
00209 {   
00210  for (int i=0;i<_lNbXData;i++)
00211  {
00212         for (int j=0;j<_lNbYData;j++)
00213         {
00214                 setZValue(i,j,*(dNewValues+(i*_lNbYData + j)));
00215         }
00216  }
00217 }
00218 
00219 
00222 void InterpolationData2D::setValues(long lNbXData,long lNbYData,double* dNewXValues,double* dNewYValues,double* dNewZValues)
00223 {
00224 
00225   if (lNbXData != getNbXData() || lNbYData != getNbYData()) //It is necessary to reallocate the X and Z array
00226   { 
00227         delete [] _mXValues;
00228         delete [] _mYValues;
00229         delete [] _mZValues;
00230         
00231         _lNbXData = lNbXData;
00232         _lNbYData = lNbYData;
00233         _lNbZData = lNbXData * lNbYData;
00234 
00235         _mXValues = new double[_lNbXData];
00236         _mYValues = new double[_lNbYData];
00237         _mZValues = new double[_lNbZData];
00238    }
00239         
00240   setXValues(dNewXValues);
00241   setYValues(dNewYValues);
00242   setZValues(dNewZValues);
00243 }
00244 
00245 
00248 void InterpolationData2D::printInfos()
00249 {
00250         int i,j;
00251 
00252         if(Interpolator::_verb == true) cout << "\n##### INTERPOLATION DATA 2D #####" << endl;
00253         if(Interpolator::_verb == true) cout << "X Name=" << getXName() << " | Y Name=" << getYName() << " | Z Name=" << getZName() << endl;
00254         if(Interpolator::_verb == true) cout << "\t";
00255 
00256         for (i=0;i < getNbYData();i++) 
00257         {
00258                 if(Interpolator::_verb == true) cout << getYValue(i) << "\t";
00259         }
00260         if(Interpolator::_verb == true) cout << endl;
00261 
00262         for (i=0;i< getNbXData();i++)
00263         {
00264                 for (j=-1;j < getNbYData();j++)
00265                 {
00266                         if (j==-1) if(Interpolator::_verb == true) cout << getXValue(i) << "\t";
00267                         else if(Interpolator::_verb == true) cout << getZValue(i,j) << "\t";
00268                 }
00269                 if(Interpolator::_verb == true) cout << endl;
00270         }
00271 
00272 }
00273 
00274 }
00275 

Generated on Tue Apr 14 09:50:27 2009 for Interpolator Library by  doxygen 1.4.5