Main Page   Modules   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages  

Interpolate.h

Go to the documentation of this file.
00001 /* SimData: Data Infrastructure for Simulations
00002  * Copyright (C) 2002 Mark Rose <tm2@stm.lbl.gov>
00003  * 
00004  * This file is part of SimData.
00005  * 
00006  * This program is free software; you can redistribute it and/or
00007  * modify it under the terms of the GNU General Public License
00008  * as published by the Free Software Foundation; either version 2
00009  * of the License, or (at your option) any later version.
00010  * 
00011  * This program is distributed in the hope that it will be useful,
00012  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  * GNU General Public License for more details.
00015  * 
00016  * You should have received a copy of the GNU General Public License
00017  * along with this program; if not, write to the Free Software
00018  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019  */
00020 
00021 
00038 #ifndef __SIMDATA_INTERPOLATE_H__
00039 #define __SIMDATA_INTERPOLATE_H__
00040 
00041 #include <string>
00042 #include <vector>
00043 #include <cstdio>
00044 
00045 #include <SimData/Enum.h>
00046 #include <SimData/Export.h>
00047 
00048 
00049 
00050 
00051 NAMESPACE_SIMDATA
00052 
00053 class Archive;
00054 
00059 template <typename T>
00060 class SIMDATA_EXPORT InterpolatedData: public BaseType {
00061 
00062         /*
00063         
00064         Base class for lookup tables.
00065         
00066         Derived classes must implement the following methods:
00067                 precess_second_derivatives()
00068                 getValue()
00069                 getPrecise()
00070         
00071         */
00072 
00073 public:
00074 
00075         typedef T value_t;
00076         typedef typename std::vector<value_t> vector_t;
00077         typedef typename std::vector<value_t>::iterator vector_it;
00078         typedef typename std::vector<value_t>::const_iterator vector_cit;
00079 
00080         static const Enumeration Method;
00081         Enum<InterpolatedData<T>::Method> method;
00082 
00083         InterpolatedData();
00084         virtual ~InterpolatedData();
00085 
00088         virtual void serialize(Archive&);
00089         
00090         virtual value_t getValue(value_t, value_t) const;
00091         virtual value_t getPrecise(value_t, value_t) const;
00092         int find(vector_t b, value_t v) const;
00093 
00094 protected:
00095         vector_t _compute_second_derivatives(const vector_t& breaks, const vector_t& data);
00096         virtual void _compute_second_derivatives() = 0;
00097 };
00098 
00099 
00100 #ifdef SWIG
00101 %template(InterpolatedFloat) InterpolatedData<float>;
00102 #endif
00103 
00104 
00118 class SIMDATA_EXPORT Curve: public InterpolatedData<float> {
00119 
00120         vector_t _breaks, _data, _table, _sd;
00121         value_t _range, _spacing, _min;
00122         int _i_n;
00123 
00124         // A one dimensional bicubic-interpolated LUT.
00125         
00126 public:
00127 
00130         Curve();
00131         
00134         Curve(const Curve &);
00135 
00138         virtual ~Curve();
00139 
00140 #ifndef SWIG
00141 
00143         const Curve &operator=(const Curve &);
00144 #endif // SWIG
00145 
00148         virtual void serialize(Archive&);
00149 
00152         vector_t getBreaks();
00153 
00156         void setBreaks(const vector_t& breaks);
00157 
00160         void setData(const vector_t& data);
00161 
00167         void interpolate(value_t spacing);
00168         
00171         value_t getPrecise(value_t x) const;
00172 
00176         value_t getValue(value_t x) const;
00177 
00180         void dumpCurve(FILE* f) const;
00181 
00184         virtual std::string asString() const;
00185 
00188         virtual std::string typeString() const;
00189 
00190 protected:
00193         virtual void _compute_second_derivatives();
00194 };
00195 
00196 
00197 
00204 class SIMDATA_EXPORT Table: public InterpolatedData<float> {
00205 
00206 public:
00207         std::string _x_label, _y_label;
00208         vector_t _x_breaks, _y_breaks, _data, _table, _dcols, _drows;
00209         value_t _x_spacing, _y_spacing;
00210         value_t _x_min, _y_min, _x_range, _y_range;
00211         int _x_in, _y_in, _x_n, _y_n;
00212         int _valid;
00213         
00214 public:
00215         Table();
00216         Table(const Table &);
00217         virtual ~Table();
00218 #ifndef SWIG
00219         const Table &operator=(const Table &);
00220 #endif // SWIG
00221         void invalidate();
00222         int isValid() const;
00223 
00226         virtual void serialize(Archive&);
00227 
00228         vector_t getXBreaks() const;
00229         vector_t getYBreaks() const;
00230         void setXBreaks(const vector_t& breaks);
00231         void setYBreaks(const vector_t& breaks);
00232         void setBreaks(const vector_t& x_breaks, const vector_t& y_breaks);
00233         void setXSpacing(value_t spacing);
00234         void setYSpacing(value_t spacing);
00235         void setSpacing(value_t x_spacing, value_t y_spacing);
00236         value_t getXSpacing() const;
00237         value_t getYSpacing() const;
00238         void setData(const vector_t& data);
00239         void interpolate();
00240         value_t getPrecise(value_t x, value_t y) const;
00241         value_t getValue(value_t x, value_t y) const;
00242         void toPGM(FILE *fp) const;
00243         void dumpTable(FILE *fp) const;
00244         void dumpDRows(FILE *fp) const;
00245         void dumpDCols(FILE *fp) const;
00246         virtual std::string asString() const;
00247 
00250         virtual std::string typeString() const;
00251 
00252 protected:
00253         virtual void _compute_second_derivatives();
00254 
00255 };
00256 
00257 
00258 NAMESPACE_SIMDATA_END
00259 
00260 
00261 #endif // __SIMDATA_INTERPOLATE_H__
00262 

SimData version pre-0.4.0. For more information on SimData, visit the SimData Homepage.

Generated on Tue Oct 14 12:06:38 2003, using Doxygen 1.2.18.

[SF.net]