//=========================================================================== // GoTools Core - SINTEF Geometry Tools Core library, version 2.0.1 // // Copyright (C) 2000-2007, 2010 SINTEF ICT, Applied Mathematics, Norway. // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation version 2 of the License. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software // Foundation, Inc., // 59 Temple Place - Suite 330, // Boston, MA 02111-1307, USA. // // Contact information: E-mail: tor.dokken@sintef.no // SINTEF ICT, Department of Applied Mathematics, // P.O. Box 124 Blindern, // 0314 Oslo, Norway. // // Other licenses are also available for this software, notably licenses // for: // - Building commercial software. // - Building software whose source code you wish to keep private. //=========================================================================== 00015 #ifndef _SMOOTHCURVESET_H 00016 #define _SMOOTHCURVESET_H 00017 00018 #include "GoTools/creators/ConstraintDefinitions.h" 00019 #include "GoTools/geometry/SplineCurve.h" 00020 00021 namespace Go 00022 { 00023 00024 struct cvSetConstraint 00025 { 00026 // Let pos1 be the evaluation of the first cv wrt to the cv1_der_'th 00027 // derivative, pos2 evaluation of the 2nd wrt to the cv2_der_'th derivative. 00028 // Let furthermore sign = (opp_) ? -1 : 1. 00029 // Then we should have: pos1 = sign*pos2. 00030 00031 cvSetConstraint(int cv1_id, double cv1_par, int cv1_der, 00032 int cv2_id, double cv2_par, int cv2_der, bool opp) 00033 : cv1_id_(cv1_id), cv1_par_(cv1_par), cv1_der_(cv1_der), 00034 cv2_id_(cv2_id), cv2_par_(cv2_par), cv2_der_(cv2_der), opp_(opp) 00035 {;} 00036 00037 int cv1_id_; // Index of first curve. 00038 double cv1_par_; // Parameter in first curve. 00039 int cv1_der_; // The derivative of first curve involved in the constraint. 00040 int cv2_id_; 00041 double cv2_par_; 00042 int cv2_der_; 00043 bool opp_; // If true the evaluation of the second curve should be negated. 00044 00045 }; 00046 00047 00048 class SmoothCurveSet 00049 { 00050 private: 00051 typedef struct integralInfo 00052 { 00053 // Parameters used in integration 00054 std::vector<double> vec_; 00055 double ***integral_; // Array used to store integrals of inner product 00056 // of derivatives of B-splines 00057 // The 1st index runs over the derivatives, the 2nd & 3rd in 00058 // the B-spline parameters 00059 bool integralset_; // Whether integral1 & integral2 have been computed. 00060 int der_; // The number of derivatives to compute. 00061 00063 integralInfo() 00064 { integral_ = 0; integralset_ = false; der_ = -1; } 00065 00067 ~integralInfo() 00068 { erase(); } 00069 00074 void resize(int ider, int in) 00075 { 00076 int ki, kj; 00077 vec_.resize((ider+1)*in*in); 00078 std::fill(vec_.begin(), vec_.end(), 0.0); 00079 00080 integral_ = new double**[ider+1]; 00081 00082 for (ki=0; ki<=ider; ki++) 00083 { 00084 integral_[ki] = new double*[in]; 00085 00086 for (kj=0; kj<in; kj++) 00087 integral_[ki][kj] = &vec_[(ki*in+kj)*in]; 00088 00089 } 00090 00091 integralset_ = 0; 00092 der_ = ider; 00093 } 00094 00096 void erase() 00097 { 00098 int ki; 00099 for (ki=0; ki<=der_; ki++) 00100 { 00101 delete [] integral_[ki]; 00102 } 00103 delete [] integral_; 00104 integralset_ = false; 00105 } 00106 } integralInfo; 00107 00108 public: 00109 00110 SmoothCurveSet(); // Default constructor to the class 00111 // SmoothCurveSet. Initializes class variable. 00112 00113 ~SmoothCurveSet(); // Destructor. 00114 00115 // Initializes data given by an intermediate surface. 00116 // For each sf there exists a vector coef_known (of size kn1*kn2) 00117 // Input is array of iterators to first element. 00118 int attach(std::vector<boost::shared_ptr<SplineCurve> >& incvs, 00119 std::vector<int>& seem, 00120 std::vector<std::vector<int> >& coef_known, 00121 int numSideConstraints = 0); 00122 00123 // @@@ VSK. Can it be relevant to use different weights for 00124 // different curves, and how to define the weights in that case? 00125 // Compute the smoothing part of the equation system. 00126 int setOptimize(double weight1, double weight2, double weight3); 00127 00128 // Compute matrices for least squares approximation. 00129 int setLeastSquares(const std::vector<std::vector<double> >& pnts, 00130 const std::vector<std::vector<double> >& param_pnts, 00131 const std::vector<std::vector<double> >& pnt_weights, 00132 double weight); 00133 00134 // int setApproxSideConstraints(sideConstraintSetPntrArray& 00135 // constraints, 00136 // double weight); 00137 00138 void setApproxOrig(double weight); 00139 00140 /* // Compute matrices for approximation of normal directions. */ 00141 /* // The number of std::vectors corresponds to number of sfs in set. */ 00142 /* int setNormalCond(const std::vector<std::vector<double> >& pnts, */ 00143 /* const std::vector<std::vector<double> >& param_pnts, */ 00144 /* const std::vector<std::vector<double> >& pnt_weights, */ 00145 /* double weight); */ 00146 00147 // We add the interpolation conditions as linear side constraints. 00148 // Assuming the degrees of freedom are sufficient (i.e. that the input 00149 // curve provided by the user has enough knots). 00150 // Well, if the user wants to approximate the interpolation pts 00151 // there is a setLeastSquares routine which does just that (and it even 00152 // allows separate weights). 00153 void setInterpolationConditions(const std::vector<std::vector<double> >& pnts, 00154 const std::vector<std::vector<double> >& param_pnts, 00155 const std::vector<std::vector<int> >& der, 00156 bool appr_constraints, double appr_wgt, 00157 int* jstat); 00158 00159 // Set linear side constraints between the coefs in (possibly different) 00160 // input cvs. 00161 int 00162 setCvSetConstraints(const std::vector<boost::shared_ptr<cvSetConstraint> >& cv_set_constraints, 00163 bool appr_constraints, double appr_wgt); 00164 00165 // We may have side constraints which are not suitable for exact equality as 00166 // spline solution space may not be large enough. We therefore allow using 00167 // least squares to minimize the error. 00168 // This applies in particular to constraint involving higher order 00169 // derivatives. 00170 // Assuming input is preprocessed (all coefs in constraints are free). 00171 int setApproxSideConstraints(std::vector<boost::shared_ptr<sideConstraintSet> >& constraints, 00172 double weight); 00173 00174 // Solve equation system, and produce output curves. 00175 int equationSolve(std::vector<boost::shared_ptr<SplineCurve> >& curves); 00176 00177 int setOrthCond(const std::vector<std::vector<double> >& pnts, 00178 const std::vector<std::vector<double> >& param_pnts, 00179 double weight); 00180 00181 // Add side constraints to the functional (Lagrange multiplier). 00182 // Assuming input is preprocessed (all coefs in constraints are free). 00183 // If replace_constraints==true the old constraints are removed prior 00184 // to adding new constraints. 00185 void setSideConstraints(std::vector<boost::shared_ptr<sideConstraintSet> >& constraints, 00186 bool replace_constraints); 00187 00188 00189 private: 00190 00191 00192 std::vector<boost::shared_ptr<integralInfo> > cv_integral_; // size nmb_cvs 00193 00194 int idim_; // Dimension of geometry space. 00195 int kdim_; // Normal conditions. 00196 int ider_; // Maximum derivative involved in the computations. 00197 std::vector<int> cont_seem_; // Number of rows affected by continuity 00198 // at the seem. 00199 00200 // The input curves 00201 std::vector<boost::shared_ptr<SplineCurve> > cvs_; 00202 00203 const int copyCoef_; 00204 00205 00206 // Parameters used to define the specific input curve. 00207 std::vector<std::vector<double> > coef_array_; // Array with curve coefficients. 00208 00209 std::vector<std::vector<int> > coefknown_; 00210 std::vector<std::vector<int> > pivot_; 00211 00212 // No coefs are assumed to be known. 00213 int kncond_; 00214 int knconstraint_; // Number of side constraints. 00215 00216 int kpointer_; // Used to differ corresponding coefs + whether coef is known. 00217 00218 // Storage of the equation system. 00219 std::vector<double> gmat_; // Matrix at left side of equation system. 00220 std::vector<double> gright_; // Right side of equation system. 00221 00222 // Set pointers between identical coefficients at a periodic seem 00223 // (i.e. c0 cont). 00224 // If possible, update fixed coefficients at the seem. 00225 void preparePeriodicity(int cvidx, int seem); 00226 00227 // Set periodicity constraints for cvs with seem[cvidx] > 1. 00228 // Expects that the gmat and gright have been initialized. 00229 int setPeriodicity(); 00230 00231 // // Set constraints on approximative C1-continuity at a seem 00232 // void setC1AtSeem(int cvidx, double weight); 00233 00234 // // Set constraints on approximative C2-continuity at a seem 00235 // void setC2AtSeem(int cvidx, double weight); 00236 00237 // Update constraints by adding known coefs to the right hand side 00238 // of constraint expression. 00239 int updateSideConstraints(std::vector<boost::shared_ptr<sideConstraintSet> >& constraints, 00240 const std::vector<std::vector<int> >& coef_known); 00241 00242 00243 00244 // Extract the linear side contraints expression in der in cv in tpar. 00245 std::vector<std::pair<std::pair<int,int>, double > > 00246 getSideConstraint(int cv_id, 00247 double tpar, 00248 int der, 00249 int sign, 00250 int* jstat); 00251 00252 int get_min_deriv(boost::shared_ptr<SplineCurve> cv, double support_mult); 00253 00254 00255 // We update weights according to spline space of curves. 00256 // Size of weights should be 4 (i.e. smoothing & appr terms). 00257 int setWeights(double weights[], double new_weights[]); 00258 00259 int set_weights(boost::shared_ptr<SplineCurve> cv, double support_mult, 00260 double weights[], double new_weights[]); 00261 void spline_space_cont(boost::shared_ptr<SplineCurve> cv, int& nmbc); 00262 00263 }; 00264 00265 } // end namespace Go 00266 00267 #endif // _SMOOTHCURVESET_H 00268
Generated on Tue Sep 21 15:44:16 2010 for GoTools Core by  doxygen 1.6.3