LR-splines  0.5
LRSplineSurface.h
Go to the documentation of this file.
00001 #ifndef LRSPLINESURFACE_H
00002 #define LRSPLINESURFACE_H
00003 
00004 #include <vector>
00005 #ifdef HAS_GOTOOLS
00006         #include <GoTools/utils/Point.h>
00007         #include <GoTools/geometry/SplineSurface.h>
00008 #endif
00009 #include <boost/rational.hpp>
00010 #include "LRSpline.h"
00011 #include "Basisfunction.h"
00012 #include "Meshline.h"
00013 #include "Element.h"
00014 #include "HashSet.h"
00015 
00016 
00017 namespace LR {
00018 
00019 
00020 class LRSplineSurface : public LRSpline {
00021 
00022 public:
00023         // constructors and destructors
00024         LRSplineSurface();
00025 #ifdef HAS_GOTOOLS
00026         LRSplineSurface(Go::SplineSurface *surf);
00027 #endif
00028         LRSplineSurface(int n1, int n2, int order_u, int order_v);
00029         LRSplineSurface(int n1, int n2, int order_u, int order_v, double *knot_u, double *knot_v);
00030         LRSplineSurface(int n1, int n2, int order_u, int order_v, double *knot_u, double *knot_v, double *coef, int dim, bool rational=false);
00031         ~LRSplineSurface();
00032         LRSplineSurface* copy() const;
00033                 
00034         // surface evaluation
00035 #ifdef HAS_GOTOOLS
00036         virtual void point(Go::Point &pt, double u, double v, int iEl=-1) const;
00037         virtual void point(Go::Point &pt, double u, double v, int iEl, bool u_from_right, bool v_from_right) const;
00038         virtual void point(std::vector<Go::Point> &pts, double upar, double vpar, int derivs, int iEl=-1) const;
00039         void computeBasis (double param_u, double param_v, Go::BasisPtsSf     & result, int iEl=-1 ) const;
00040         void computeBasis (double param_u, double param_v, Go::BasisDerivsSf  & result, int iEl=-1 ) const;
00041         void computeBasis (double param_u, double param_v, Go::BasisDerivsSf2 & result, int iEl=-1 ) const;
00042 #endif
00043         virtual void point(std::vector<double> &pt, double u, double v, int iEl=-1) const;
00044         virtual void point(std::vector<double> &pt, double u, double v, int iEl, bool u_from_right, bool v_from_right) const;
00045         virtual void point(std::vector<std::vector<double> > &pts, double upar, double vpar, int derivs, int iEl=-1) const;
00046         virtual void point(std::vector<std::vector<double> > &pts, double upar, double vpar, int derivs, bool u_from_right, bool v_from_right, int iEl=-1) const;
00047         void computeBasis (double param_u,
00048                            double param_v,
00049                            std::vector<std::vector<double> >& result,
00050                            int derivs=0,
00051                            int iEl=-1 ) const;
00052         int getElementContaining(double u, double v) const;
00053         // TODO: get rid of the iEl argument in evaluation signatures - it's too easy to mess it up (especially with derivatives at multiple-knot boundaries). 
00054         //       Try and sort the Elements after all refinements and binary search for the containing point in logarithmic time
00055 
00056         // refinement functions
00057         void refineBasisFunction(int index);
00058         void refineBasisFunction(const std::vector<int> &indices);
00059         void refineElement(int index);
00060         void refineElement(const std::vector<int> &indices);
00061         void refineByDimensionIncrease(const std::vector<double> &error, double beta);
00062 
00063         // (private) refinement functions
00064         Meshline* insert_const_u_edge(double u, double start_v, double stop_v, int multiplicity=1);
00065         Meshline* insert_const_v_edge(double v, double start_u, double stop_u, int multiplicity=1);
00066         void getFullspanLines(  int iEl,          std::vector<Meshline*>& lines);
00067         void getMinspanLines(   int iEl,          std::vector<Meshline*>& lines);
00068         void getStructMeshLines(Basisfunction *b, std::vector<Meshline*>& lines);
00069         void aPosterioriFixes() ;
00070         void closeGaps(            std::vector<Meshline*>* newLines=NULL);
00071         void enforceMaxTjoints(    std::vector<Meshline*>* newLines=NULL);
00072         void enforceMaxAspectRatio(std::vector<Meshline*>* newLines=NULL);
00073 
00074         // linear independence methods
00075         bool isLinearIndepByOverloading(bool verbose) ;
00076         bool isLinearIndepByMappingMatrix(bool verbose) const ;
00077         bool isLinearIndepByFloatingPointMappingMatrix(bool verbose) const ;
00078         void getNullSpace(std::vector<std::vector<boost::rational<long long> > >& nullspace) const ;
00079 
00080         void updateSupport(Basisfunction *f) ;
00081         void updateSupport(Basisfunction *f,
00082                            std::vector<Element*>::iterator start,
00083                            std::vector<Element*>::iterator end ) ;
00084         
00085         // common get methods
00086         void getGlobalKnotVector      (std::vector<double> &knot_u, std::vector<double> &knot_v) const;
00087         void getGlobalUniqueKnotVector(std::vector<double> &knot_u, std::vector<double> &knot_v) const;
00088         void getBezierElement         (int iEl, std::vector<double> &controlPoints)              const;
00089         void getBezierExtraction      (int iEl, std::vector<double> &extractMatrix)              const;
00090         int nMeshlines()              const                { return meshline_.size(); };
00091 
00092         // more get-methods
00093         std::vector<Meshline*>::iterator       meshlineBegin()         { return meshline_.begin(); };
00094         std::vector<Meshline*>::iterator       meshlineEnd()           { return meshline_.end(); };
00095         Meshline* getMeshline(int i)                                   { return meshline_[i]; };
00096         const Meshline* getMeshline(int i) const                       { return meshline_[i]; };
00097         std::vector<Meshline*> getAllMeshlines()                       { return meshline_;    };
00098         const std::vector<Meshline*> getAllMeshlines() const           { return meshline_;    };
00099 
00100         // assorted specialized functions
00101         double makeIntegerKnots();
00102         void getSupportElements(       std::vector<int> &result, const std::vector<int> &basisfunctions) const ;
00103         void getDiagonalElements(      std::vector<int> &result) const ;
00104         void getDiagonalBasisfunctions(std::vector<int> &result) const ;
00105         void printElements(std::ostream &out) const;
00106         LRSplineSurface* getRaiseOrderSpace(int raiseOrderU, int raiseOrderV) const;
00107         std::vector<LRSplineSurface*> getDerivativeSpace() const ;
00108         bool setGlobalContinuity(int contU, int contV);
00109         bool decreaseContinuity( int du,    int dv);
00110 
00111         // input output methods
00112         virtual void read(std::istream &is);
00113         virtual void write(std::ostream &os) const;
00114 
00115         // print LR splines as eps-files
00116         void setElementColor(double r, double g, double b) ;
00117         void setBasisColor(double r, double g, double b) ;
00118         void setSelectedBasisColor(double r, double g, double b) ;
00119         void writePostscriptMesh(std::ostream &out, bool close=true, std::vector<int> *colorElements=NULL) const;
00120         void writePostscriptElements(std::ostream &out, int nu=2, int nv=2, bool close=true, std::vector<int> *colorElements=NULL) const;
00121         void writePostscriptFunctionSpace(std::ostream &out, std::vector<int> *colorBasis=NULL, bool drawAll=true, bool close=true) const;
00122         void writePostscriptMeshWithControlPoints(std::ostream &out, int nu=2, int nv=2) const ;
00123 
00124 private:
00125         // initializeation methods (called from constructors)
00126         void initMeta();
00127         template <typename RandomIterator1,
00128                   typename RandomIterator2,
00129                   typename RandomIterator3>
00130         void initCore(int n1, int n2, int order_u, int order_v, RandomIterator1 knot_u, RandomIterator2 knot_v, RandomIterator3 coef, int dim, bool rational=false) {
00131                 order_.resize(2);
00132                 start_.resize(2);
00133                 end_.resize(2);
00134                 rational_ = rational;
00135                 dim_      = dim;
00136                 order_[0]  = order_u;
00137                 order_[1]  = order_v;
00138                 start_[0]  = knot_u[0];
00139                 start_[1]  = knot_v[0];
00140                 end_[0]    = knot_u[n1];
00141                 end_[1]    = knot_v[n2];
00142         
00143                 for(int j=0; j<n2; j++)
00144                         for(int i=0; i<n1; i++)
00145                                 basis_.insert(new Basisfunction(knot_u+i, knot_v+j, coef+(j*n1+i)*(dim+rational), dim, order_u, order_v));
00146                 int unique_u=0;
00147                 int unique_v=0;
00148                 for(int i=0; i<n1+order_u; i++) {// const u, spanning v
00149                         int mult = 1;
00150                         while(i<n1+order_u && knot_u[i]==knot_u[i+1]) {
00151                                 i++;
00152                                 mult++;
00153                         }
00154                         unique_u++;
00155                         meshline_.push_back(new Meshline(false, knot_u[i], knot_v[0], knot_v[n2], mult) );
00156                 }
00157                 for(int i=0; i<n2+order_v; i++) {// const v, spanning u
00158                         int mult = 1;
00159                         while(i<n2+order_v && knot_v[i]==knot_v[i+1]) {
00160                                 i++;
00161                                 mult++;
00162                         }
00163                         unique_v++;
00164                         meshline_.push_back(new Meshline(true, knot_v[i], knot_u[0], knot_u[n1], mult) );
00165                 }
00166                 for(int j=0; j<unique_v-1; j++) {
00167                         for(int i=0; i<unique_u-1; i++) {
00168                                 double umin = meshline_[i]->const_par_;
00169                                 double vmin = meshline_[unique_u + j]->const_par_;
00170                                 double umax = meshline_[i+1]->const_par_;
00171                                 double vmax = meshline_[unique_u + j+1]->const_par_;
00172                                 element_.push_back(new Element(umin, vmin, umax, vmax));
00173                         }
00174                 }
00175 
00176                 HashSet_iterator<Basisfunction*> it;
00177                 for(it=basis_.begin(); it!=basis_.end(); ++it)
00178                         updateSupport(*it);
00179         }
00180 
00181         void split(bool insert_in_u, Basisfunction* b, double new_knot, int multiplicity, HashSet<Basisfunction*> &newFunctions);
00182         Meshline* insert_line(bool const_u, double const_par, double start, double stop, int multiplicity);
00183         
00184         std::vector<Meshline*> meshline_;
00185 
00186         // plotting parameters
00187         double element_red;
00188         double element_green;
00189         double element_blue;
00190         double basis_red;
00191         double basis_green;
00192         double basis_blue;
00193         double selected_basis_red;
00194         double selected_basis_green;
00195         double selected_basis_blue;
00196 
00197 };
00198 
00199 } // end namespace LR
00200 
00201 #endif
00202