Table1D.cpp

Go to the documentation of this file.
00001 // Table1D.cpp: implementation of the Table1D class.
00002 //
00004 
00005 #ifdef WIN32 
00006 #pragma warning(disable:4786)
00007 #endif
00008 #include "Table1D.h"
00009 //#include "Monochromator.h"
00010 #include "LinearInterpolator1D.h"
00011 #include "AkimaInterpolator1D.h"
00012 #include "PeriodicAkimaInterpolator1D.h"
00013 #include "CubicSplineInterpolator1D.h"
00014 #include "PeriodicCubicSplineInterpolator1D.h"
00015 #include "PolynomialInterpolator1D.h"
00016 
00017 
00018 namespace Interpolator
00019 {
00020 
00022 // Construction/Destruction
00024 
00026 /*Table1D::Table1D()
00027 {
00028 
00029 }*/
00030 
00032 Table1D::~Table1D()
00033 {       
00034         DESTRUCTION(_mInterpolator);
00035         DESTRUCTION(_mData);
00036 }
00037 
00047 Table1D::Table1D(       std::string                     sName,
00048                                         std::string                     sDescription,   
00049                                         std::string                     sEntryPoint, 
00050                                         std::string                     sOutputPoint,
00051                                         Variable*                       mEntryPoint,
00052                                         Interpolator1D*         mInterpolator/*,
00053                                         Interpolator*   mInverseInterpolator*/) : 
00054 Table(sName,sDescription,""),
00055 _sEntryPoint(sEntryPoint),_sOutputPoint(sOutputPoint),
00056 _mEntryPoint(mEntryPoint),_mInterpolator(mInterpolator)
00057 {
00059 }
00060 
00061 
00074 Table1D::Table1D(       std::string                     sName,
00075                                         std::string                     sDescription,   
00076                                         std::string                     sEntryPoint, 
00077                                         std::string                     sOutputPoint,
00078                                         Variable*                       mEntryPoint,
00079                                         std::string                     sInterpolationType,
00080                                         long                            lNbData,
00081                                         double*                         mX,
00082                                         double*                         mY) :
00083 Table(sName,sDescription,sInterpolationType),
00084 _sEntryPoint(sEntryPoint),_sOutputPoint(sOutputPoint),_mEntryPoint(mEntryPoint)
00085 
00086 {
00087 _mData                  = new InterpolationData1D(sEntryPoint,sOutputPoint,lNbData,mX,mY);
00088         
00089 
00090 if (sInterpolationType == "Akima") 
00091 {
00092         std::string sInterpolationName = sEntryPoint;
00093         sInterpolationName+= "-->";
00094         sInterpolationName+= sOutputPoint;
00095         _mInterpolator = new AkimaInterpolator1D(sDescription,sInterpolationName,_mData);
00096 }
00097 
00098 else if (sInterpolationType == "Periodic Akima") 
00099 {
00100         std::string sInterpolationName = sEntryPoint;
00101         sInterpolationName+= "-->";
00102         sInterpolationName+= sOutputPoint;
00103         _mInterpolator = new PeriodicAkimaInterpolator1D(sDescription,sInterpolationName,_mData);
00104 }
00105 
00107 else if (sInterpolationType == "Linear") 
00108 {
00109         std::string sInterpolationName = sEntryPoint;
00110         sInterpolationName+= "-->";
00111         sInterpolationName+= sOutputPoint;
00112         _mInterpolator = new LinearInterpolator1D(sDescription,sInterpolationName,_mData);
00113 }
00114 
00115 else if (sInterpolationType == "Cubic Spline") 
00116 {
00117         std::string sInterpolationName = sEntryPoint;
00118         sInterpolationName+= "-->";
00119         sInterpolationName+= sOutputPoint;
00120         _mInterpolator = new CubicSplineInterpolator1D(sDescription,sInterpolationName,_mData);
00121 }
00122 
00123 else if (sInterpolationType == "Periodic Cubic Spline") 
00124 {
00125         std::string sInterpolationName = sEntryPoint;
00126         sInterpolationName+= "-->";
00127         sInterpolationName+= sOutputPoint;
00128         _mInterpolator = new PeriodicCubicSplineInterpolator1D(sDescription,sInterpolationName,_mData);
00129 }
00130 
00131 else if (sInterpolationType == "Polynomial") 
00132 {
00133         std::string sInterpolationName = sEntryPoint;
00134         sInterpolationName+= "-->";
00135         sInterpolationName+= sOutputPoint;
00136         _mInterpolator = new PolynomialInterpolator1D(sDescription,sInterpolationName,_mData);
00137 }
00138 
00139 else //Error
00140 {
00141         _mInterpolator = 0;
00142 
00143 }
00144 
00145 }
00146 
00155 Table1D::Table1D(       std::string                     sName,
00156                                         std::string                     sDescription,   
00157                                         std::string                     sInterpolationType,
00158                                         std::string                     sFilePath,
00159                                         int                                     iFirstColumn,
00160                                         int                                     iSecondColumn) :
00161 Table(sName,sDescription,sInterpolationType,sFilePath)
00162 {
00163         GenericFileReader1D* _mFileReader = new GenericFileReader1D(sFilePath);
00164         
00165         double* mX = _mFileReader->getColumn(iFirstColumn);
00166         double* mY = _mFileReader->getColumn(iSecondColumn);
00167 
00168         _sEntryPoint = _mFileReader->getColumnName(iFirstColumn);
00169         _sOutputPoint = _mFileReader->getColumnName(iSecondColumn);
00170         
00171         _mEntryPoint = (Variable*)0; //Or mMono->getVariable(_sEntryPoint);
00172 
00173         long lNbData = _mFileReader->getNbData();
00174 
00175         _mData                  = new InterpolationData1D(_sEntryPoint,_sOutputPoint,lNbData,mX,mY);
00176         
00177         if (sInterpolationType == "Akima") 
00178         {
00179                 std::string sInterpolationName = _sEntryPoint;
00180                 sInterpolationName+= "-->";
00181                 sInterpolationName+= _sOutputPoint;
00182                 _mInterpolator = new AkimaInterpolator1D(sDescription,sInterpolationName,_mData);
00183         }
00184 
00185         else if (sInterpolationType == "Periodic Akima") 
00186         {
00187                 std::string sInterpolationName = _sEntryPoint;
00188                 sInterpolationName+= "-->";
00189                 sInterpolationName+= _sOutputPoint;
00190                 _mInterpolator = new PeriodicAkimaInterpolator1D(sDescription,sInterpolationName,_mData);
00191         }
00192 
00194         else if (sInterpolationType == "Linear") 
00195         {
00196                 std::string sInterpolationName = _sEntryPoint;
00197                 sInterpolationName+= "-->";
00198                 sInterpolationName+= _sOutputPoint;
00199                 _mInterpolator = new LinearInterpolator1D(sDescription,sInterpolationName,_mData);
00200         }
00201 
00202         else if (sInterpolationType == "Cubic Spline") 
00203         {
00204                 std::string sInterpolationName = _sEntryPoint;
00205                 sInterpolationName+= "-->";
00206                 sInterpolationName+= _sOutputPoint;
00207                 _mInterpolator = new CubicSplineInterpolator1D(sDescription,sInterpolationName,_mData);
00208         }
00209 
00210         else if (sInterpolationType == "Periodic Cubic Spline") 
00211         {
00212                 std::string sInterpolationName = _sEntryPoint;
00213                 sInterpolationName+= "-->";
00214                 sInterpolationName+= _sOutputPoint;
00215                 _mInterpolator = new PeriodicCubicSplineInterpolator1D(sDescription,sInterpolationName,_mData);
00216         }
00217 
00218         else if (sInterpolationType == "Polynomial") 
00219         {
00220                 std::string sInterpolationName = _sEntryPoint;
00221                 sInterpolationName+= "-->";
00222                 sInterpolationName+= _sOutputPoint;
00223                 _mInterpolator = new PolynomialInterpolator1D(sDescription,sInterpolationName,_mData);
00224         }
00225 
00226         else //Error
00227         {
00228                 _mInterpolator = 0;
00229 
00230         }
00231 
00232         delete (_mFileReader);
00233 }
00234 
00236 double Table1D::computeValue(double dValue)
00237 {
00238         return _mInterpolator->getInterpolatedValue(dValue);
00239 }
00240 
00242 double Table1D::computeValue()
00243 {
00244         /*/------------ !!!!! ATTENTION: F. LANGLOIS:
00245         La partie ci dessous est commentée pour permettre a la lib Interpolator de ne plus faire reference a la librairie Monochromator
00246         Ceci peut avoir des consequences sur les devices deja existants.
00247         a ma connaissance, aucun device a ce jour n'utilise cette methode
00248         */
00249 
00250 
00251         /*Monochromator* mMonochromator = Monochromator::GetMonochromatorInstance();
00252         //std::string sEntryPointCorrection     = _mInterpolator->getInterpolatedData()->getXName();
00253         Variable* mVariable                             = mMonochromator->getVariable(_sEntryPoint);
00254         double dValue                                   = mVariable->getValue(); 
00255         return _mInterpolator->getInterpolatedValue(dValue);*/
00256 
00257         return 0.0;
00258 }
00259 
00261 std::string Table1D::getEntryPoint() const
00262 {
00263         return _sEntryPoint;
00264 }
00265 
00267 std::string Table1D::getOutputPoint() const
00268 {
00269         return _sOutputPoint;
00270 }
00271         
00273 InterpolationData1D* Table1D::getInterpolationData() const
00274 {
00275         return _mData;
00276 }
00277 
00279 Interpolator1D* Table1D::getInterpolator() const
00280 {
00281         return _mInterpolator;
00282 }
00283 
00285 void Table1D::printInfos()
00286 {
00287         if(Interpolator::_verb == true) cout << "\n############ Table1D : " << getName() << " ############\n" << endl;
00288         if(Interpolator::_verb == true) cout << "Interpolation Type   : " << getInterpolationType() << endl;
00289         if(Interpolator::_verb == true) cout << "Description          : " << getDescription() << endl;
00290         if(Interpolator::_verb == true) cout << "Columns Names        : " << getEntryPoint() << " --> " << getOutputPoint() << endl;
00291         if(Interpolator::_verb == true) cout << "Values\n" << endl;
00292         _mData->DisplayData();
00293 }
00294 
00295 
00296 
00298 void Table1D::setXValue(int i,double dNewValue)
00299 {
00300         //First we update the interpolation data structure values
00301         _mInterpolator->getInterpolatedData()->setXValue(i,dNewValue);
00302         //And after update of the gsl object according the new InterpolationData values
00303         _mInterpolator->updateInterpolator();
00304 }
00305 
00307 void Table1D::setYValue(int i,double dNewValue)
00308 {
00309         //First we update the interpolation data structure values
00310         _mInterpolator->getInterpolatedData()->setYValue(i,dNewValue);
00311         //And after update of the gsl object according the new InterpolationData values
00312         _mInterpolator->updateInterpolator();
00313 }
00314 
00316 void Table1D::setValues(long lNbData,double* dNewXValues,double* dNewYValues)
00317 {
00318         //First we update the interpolation data structure values
00319         _mInterpolator->getInterpolatedData()->setValues(lNbData,dNewXValues,dNewYValues);
00320         //And after update of the gsl object according the new InterpolationData values
00321         _mInterpolator->updateInterpolator();
00322 }
00323 
00324 
00325 
00329 double Table1D::getXValue(int i) const
00330 {
00331         return _mInterpolator->getInterpolatedData()->getXValue(i);
00332 }
00333         
00337 double Table1D::getYValue(int i) const
00338 {
00339         return _mInterpolator->getInterpolatedData()->getYValue(i);
00340 }
00341 
00344 double* Table1D::getXValues() const
00345 {
00346         return _mInterpolator->getInterpolatedData()->getXValues();
00347 }
00348 
00351 double* Table1D::getYValues() const
00352 {
00353         return _mInterpolator->getInterpolatedData()->getYValues();
00354 }
00355 
00357 long Table1D::getNbData() const
00358 {
00359         return _mInterpolator->getInterpolatedData()->getNbData();
00360 }
00361 
00362 
00363 
00364 
00365 
00366 }
00367 
00368 

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