MBA.h

00001 //===========================================================================
00002 // SINTEF Multilevel B-spline Approximation library - version 1.1
00003 //
00004 // Copyright (C) 2000-2005 SINTEF ICT, Applied Mathematics, Norway.
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 version 2 of the License. 
00009 //
00010 // This program is distributed in the hope that it will be useful,        
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00013 // GNU General Public License for more details.                           
00014 //
00015 // You should have received a copy of the GNU General Public License      
00016 // along with this program; if not, write to the Free Software            
00017 // Foundation, Inc.,                                                      
00018 // 59 Temple Place - Suite 330,                                           
00019 // Boston, MA  02111-1307, USA.                                           
00020 //
00021 // Contact information: e-mail: tor.dokken@sintef.no                      
00022 // SINTEF ICT, Department of Applied Mathematics,                         
00023 // P.O. Box 124 Blindern,                                                 
00024 // 0314 Oslo, Norway.                                                     
00025 //
00026 // Other licenses are also available for this software, notably licenses
00027 // for:
00028 // - Building commercial software.                                        
00029 // - Building software whose source code you wish to keep private.        
00030 //===========================================================================
00031 #ifndef _MBA_H_
00032 #define _MBA_H_
00033 
00034 #include <MBAtypedef.h>
00035 #include <UCBtypedef.h>
00036 #include <GenMatrix.h>
00037 #include <MBAdata.h>
00038 
00039 #include <vector>
00040 #include <boost/shared_ptr.hpp>
00041 
00042 #include <UCBsplineSurface.h>
00043 //===========================================================================
00072 //===========================================================================
00073 class MBA {
00074   
00075   MBAdata data_;
00076   int m_,n_; // the lattice is from -1,0,...,m_+1  -1,0,...,n_+1
00077   boost::shared_ptr<GenMatrixType> PHI_;
00078 
00079   static const std::vector<UCBspl_real> smoothing_filter_;
00080 
00081   GenMatrix<UCBspl_real> delta_; // temporary array for BA/MBA algorithm
00082   GenMatrix<UCBspl_real> omega_; // temporary array for BA/MBA algorithm
00083   
00084   void BAalg();
00085   double f_pure(double u, double v) const; // without base surface, used in MBAalg
00086 
00087   // Smoothing
00088   void flagZeros(GenMatrix<bool>& qwe_) const;
00089 
00090   /* Update spline coefficients by adding the base surface over which the surface is defined.
00091    * This ensures that PHI() returns the correct coefficients of the spline surface.
00092    * This is always run after MBAalg.
00093    */
00094   bool adjustForBaseSurface();
00095 
00096 public:
00097 
00098   MBA(){};
00099 
00102   MBA(boost::shared_ptr<dVec> U, boost::shared_ptr<dVec> V, boost::shared_ptr<dVec> Z)
00103      {data_.init(U, V, Z);}
00104     
00105  ~MBA(){}
00106 
00110   void init(boost::shared_ptr<dVec> U, boost::shared_ptr<dVec> V, boost::shared_ptr<dVec> Z)
00111      {data_.init(U, V, Z);}
00112 
00115   void init(UCBspl::SplineSurface& surf);
00116 
00117 
00118   /* Expand the rectangular domain of the surface beyond the domain of the given 
00119    *  scattered data.
00120    *  The given arguments must be grater than or equal to zero;
00121    *  e.g. \a Dumin is the increment in the negative u-direction.
00122    *  (If used, this must be done before creating the surface.)
00123    */
00124   //void expandDomain(double Dumin, double Dvmin, double Dumax, double Dvmax)
00125   //                  {data_.expandDomain(Dumin, Dvmin, Dumax, Dvmax);}
00126 
00135   void setDomain(double umin, double vmin, double umax, double vmax)
00136                  {data_.setDomain(umin,vmin,umax,vmax);}
00137 
00146   void setBaseType(MBAbaseType baseType) {data_.baseType_ = baseType;}
00147   
00149   void setBaseValue(double base) {data_.offset_ = base; data_.baseType_ = MBA_CONSTVAL;}
00150   
00170   void MBAalg(int m0, int n0, int h = 0, int smoothing_steps = 0);    
00171   
00173         const MBAdata& getData() const {return data_;}
00174 
00176   void readScatteredData(char filename[]) {data_.readScatteredData(filename);}
00177 
00179   void smoothZeros(int no_iter);
00180 
00183   UCBspl::SplineSurface getSplineSurface() const {return UCBspl::SplineSurface(PHI_, data_.umin(), data_.vmin(),
00184                                                   data_.umax(), data_.vmax());}
00185 
00193   void getIndexDomain(int& m, int& n) const {m = m_; n = n_;}
00194 
00203   void cleanup(int type = 0);
00204 
00207   boost::shared_ptr<GenMatrixType> PHI() const {return PHI_;}
00208 
00209   // (Temporary) utilities
00210   void checkSparsity() const;
00211   //void printSplineSurface(char filename[]) const;
00212   void checkError() const;
00213 
00214   static void smoothMatrix(GenMatrixType& matrix, int no_iter);
00215 
00216 };
00217 
00218 #endif

Generated on Wed Nov 28 12:27:19 2007 for MBA by  doxygen 1.5.1