SmoothSurfSet.h

00001 //===========================================================================
00002 // GoTools - SINTEF Geometry Tools version 1.1
00003 //
00004 // GoTools module: CORE
00005 //
00006 // Copyright (C) 2000-2007 SINTEF ICT, Applied Mathematics, Norway.
00007 //
00008 // This program is free software; you can redistribute it and/or          
00009 // modify it under the terms of the GNU General Public License            
00010 // as published by the Free Software Foundation version 2 of the License. 
00011 //
00012 // This program is distributed in the hope that it will be useful,        
00013 // but WITHOUT ANY WARRANTY; without even the implied warranty of         
00014 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the          
00015 // GNU General Public License for more details.                           
00016 //
00017 // You should have received a copy of the GNU General Public License      
00018 // along with this program; if not, write to the Free Software            
00019 // Foundation, Inc.,                                                      
00020 // 59 Temple Place - Suite 330,                                           
00021 // Boston, MA  02111-1307, USA.                                           
00022 //
00023 // Contact information: E-mail: tor.dokken@sintef.no                      
00024 // SINTEF ICT, Department of Applied Mathematics,                         
00025 // P.O. Box 124 Blindern,                                                 
00026 // 0314 Oslo, Norway.                                                     
00027 //
00028 // Other licenses are also available for this software, notably licenses
00029 // for:
00030 // - Building commercial software.                                        
00031 // - Building software whose source code you wish to keep private.        
00032 //===========================================================================
00033 #ifndef _GOSMOOTHSURFSET_H_
00034 #define _GOSMOOTHSURFSET_H_
00035 
00036 
00037 //   -----------------------------------------------------------------------
00038 //      Interface file for class SmoothSurfSET
00039 //   -----------------------------------------------------------------------
00040 //
00041 //       Used to modify a tensor product B-spline surface with respect
00042 //       to conditions on smoothness, editing constraints and boundary
00043 //       conditions.
00044 //
00045 //       Implementation of the member functions are given in the
00046 //       following files:
00047 //
00048 //          1. SmoothSurfSet.C
00049 //
00050 //   -----------------------------------------------------------------------
00051 //    Written by: Vibeke Skytt                            04.2002.
00052 //   -----------------------------------------------------------------------
00053 
00054 #include "SplineSurface.h"
00055 #include "ConstraintDefinitions.h"
00056 #include <vector>
00057 
00058 namespace Go
00059 {
00062 
00063 
00066 class SmoothSurfSet
00067 {
00068 
00069 
00070 public:
00072     SmoothSurfSet();
00073 
00076     SmoothSurfSet(bool copy_coefs);
00077 
00079     virtual
00080     ~SmoothSurfSet();
00081 
00092     void attach(std::vector<boost::shared_ptr<SplineSurface> >& insf, 
00093                 std::vector<std::vector<int> >& coef_known,
00094                 int num_side_constraints = 0, 
00095                 int has_normal_cond = 0);
00096 
00097     // @@@ VSK. Can it be relevant to use different weights for 
00098     // different surfaces, and how to define the weights in that case?
00104     virtual
00105     void setOptimize(double weight1, double weight2, double weight3);
00106 
00117     void setLeastSquares(std::vector<std::vector<double> >& pnts,
00118                          std::vector<std::vector<double> >& param_pnts,
00119                          std::vector<std::vector<double> >& pnt_weights,
00120                          double weight);
00121 
00132     int setNormalCond(std::vector<std::vector<double> >& pnts,
00133                       std::vector<std::vector<double> >& param_pnts,
00134                       std::vector<std::vector<double> >& pnt_weights,
00135                       double weight);
00136 
00141     void approxOrig(double weight);
00142 
00145     void setSideConstraints(std::vector<sideConstraintSet>& constraints);
00146 
00147     // We may have side constraints which are not suitable for exact equality as
00148     // spline solution space may not be large enough. We therefore allow using least
00149     // squares to minimize the error.
00150     // This applies in particular to constraint involving higher order derivatives.
00151     // @@ Currently function uses newmat. As matrix is sparce we may do it another way.
00153     void setApproxSideConstraints(std::vector<sideConstraintSet>& constraints,
00154                                   double weight);
00155 
00160     int equationSolve(std::vector<boost::shared_ptr<SplineSurface> >& surfaces);
00161 
00162 
00163 protected:
00164     int kdim_;             // 3 if normal conditions are included, otherwise 1.
00165     int idim_;             // Dimension of geometry space. 
00166     int idim1_;            // Dimension of projective space.
00167     int ider_;             // Maximum derivative involved in the computations. 
00168 
00169     int kncond_;           // Number of unknown coefficents + number of constraints.
00170     int knconstraint_;     // Number of side constraints.
00171 
00172     std::vector<std::vector<int>::iterator> coef_known_;
00173     // Array indicating the status of coefficients, i.e.
00174     // free, fixed, not involved, equal to a given
00175     // coefficients.
00176     std::vector<std::vector<int> > pivot_; // Array giving the position of the
00177     // free coefficients in the equation system.
00178 
00179     // Parameters defining the spline space.
00180     std::vector<boost::shared_ptr<SplineSurface> > srfs_;   // Pointer to input surfaces.
00181 
00182     const int copy_coefs_; // Whether we are to copy the coefs from input surfaces
00183                            // (or work directly on coefficients in input surfaces).
00184 
00185     // Parameters used to define the specific input spline surfaces.
00186     std::vector<std::vector<double> > coef_array_;
00187 
00188     //    std::vector<double>::iterator  scoef;   // Pointer to surface coefficients.      
00189 
00190     // Storage of the equation system.
00191     std::vector<double> gmat_;       // Matrix at left side of equation system.
00192     std::vector<double> gright_;     // Right side of equation system.      
00193 
00207     virtual
00208     void getBasis(double *sb1, double *sb2, int kk1, int kk2, 
00209                   int kleft1, int kleft2, int ider, double *sbasis);
00210 
00211 
00212 private:
00213 
00215     typedef struct integralInfo
00216     {
00217         // Parameters used in integration
00218         std::vector<double> vec1, vec2;
00219         double ***integral1;  // Array used to store integrals of inner product
00220         // of derivatives of B-splines in 1. par. dir.
00221         // The 1st index runs over the derivatives, the 2nd & 3rd in u- and v-dir.
00222         double ***integral2;  // Array used to store integrals of inner product
00223         // of derivatives of B-splines in 2. par. dir.
00224         // The 1st index runs over the derivatives, the 2nd & 3rd in u- and v-dir.
00225         bool integralset; // Whether integral1 & integral2 have been computed.
00226         int der; // The number of derivatives to compute.
00227       
00229         integralInfo() 
00230         { integral1 = 0; integral2 = 0; integralset = false; der = -1; }
00231 
00233         ~integralInfo()
00234         { erase(); }
00235 
00240         void resize(int ider, int in1, int in2)
00241         {
00242             int ki, kj;
00243             vec1.resize((ider+1)*in1*in1);
00244             vec2.resize((ider+1)*in2*in2);
00245             std::fill(vec1.begin(), vec1.end(), 0.0);
00246             std::fill(vec2.begin(), vec2.end(), 0.0);
00247 
00248             integral1 = new double**[ider+1];
00249             integral2 = new double**[ider+1];
00250 
00251             for (ki=0; ki<=ider; ki++)
00252                 {
00253                     integral1[ki] = new double*[in1];
00254                     integral2[ki] = new double*[in2];
00255 
00256                     for (kj=0; kj<in1; kj++)
00257                         integral1[ki][kj] = &vec1[(ki*in1+kj)*in1];
00258 
00259                     for (kj=0; kj<in2; kj++)
00260                         integral2[ki][kj] = &vec2[(ki*in2+kj)*in2];
00261                 }
00262 
00263             integralset = 0;
00264             der = ider;
00265         }
00266 
00268         void erase()
00269         {
00270             int ki;
00271             for (ki=0; ki<=der; ki++)
00272                 {
00273                     delete [] integral1[ki];
00274                     delete [] integral2[ki];
00275                 }
00276             delete [] integral1;
00277             delete [] integral2;
00278             integralset = false;
00279         }
00280     } integralInfo;
00281 
00282     std::vector<integralInfo> surf_integral_; // Integral calculations for the surfaces.
00283 
00288     void removeKnownCoefs(std::vector<sideConstraintSet>& constraints) const;
00289 
00290 };
00291 
00293 }
00294 
00295 #endif //
00296 

Generated on Mon Jun 11 14:48:18 2007 for GoTools Core Library by  doxygen 1.5.1