SplineCurve.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 _GOSPLINECURVE_H
00034 #define _GOSPLINECURVE_H
00035 
00036 
00037 #include "DirectionCone.h"
00038 #include "ParamCurve.h"
00039 #include "BsplineBasis.h"
00040 
00041 
00042 namespace Go
00043 {
00046 
00047 
00048 class Interpolator;
00049 
00052 class SplineCurve : public ParamCurve
00053 {
00054 public:
00055 
00058     SplineCurve() : dim_(-1), rational_(false) { }
00059 
00075     template <typename RandomIterator1, typename RandomIterator2>
00076     SplineCurve(int number,
00077                   int order,
00078                   RandomIterator1 knotstart,
00079                   RandomIterator2 coefsstart,
00080                   int dim,
00081                   bool rational = false)
00082         : dim_(dim), rational_(rational),
00083           basis_(number, order, knotstart)
00084     {
00085         if (rational) {
00086             rcoefs_.resize((dim+1)*number);
00087             std::copy(coefsstart, coefsstart+(dim+1)*number, 
00088                       rcoefs_.begin());
00089             coefs_.resize(dim*number);
00090             updateCoefsFromRcoefs();
00091         } else {
00092             coefs_.resize(dim*number);
00093             std::copy(coefsstart, coefsstart + dim*number, 
00094                       coefs_.begin());
00095         }
00096     }
00097 
00105     SplineCurve(const Point& pnt1, const Point& pnt2);
00106 
00115     SplineCurve(const Point& pnt1, double startpar, 
00116                 const Point& pnt2, double endpar);
00117 
00119     virtual ~SplineCurve();
00120 
00121     // Inherited from Streamable
00122     virtual void read (std::istream& is);
00123 
00124     // Inherited from Streamable
00125     virtual void write (std::ostream& os) const;
00126 
00127     // Inherited from GeomObject
00128     virtual BoundingBox boundingBox() const;
00129 
00130     // Inherited from GeomObject
00131     virtual int dimension() const;
00132 
00133     // Inherited from GeomObject
00134     virtual ClassType instanceType() const;
00135 
00136     // Inherited from GeomObject
00137     static ClassType classType()
00138     { return Class_SplineCurve; }
00139     // Inherited from GeomObject
00140 // #if ((_MSC_VER > 0) && (_MSC_VER < 1300))
00141 //     virtual GeomObject* clone() const
00142 //     { return new SplineCurve(*this); }
00143 // #else
00144     virtual SplineCurve* clone() const
00145     { return new SplineCurve(*this); }
00146 // #endif
00147 
00148     // Inherited from ParamCurve
00149     virtual void point(Point& pt, double tpar) const;
00150 
00151     // Inherited from ParamCurve
00152     virtual void point(std::vector<Point>& pts, 
00153                        double tpar,
00154                        int derivs,
00155                        bool from_right = true) const;
00156 
00157     // Inherited from ParamCurve
00158     virtual double startparam() const;
00159 
00160     // Inherited from ParamCurve
00161     virtual double endparam() const;
00162 
00163     // Inherited from ParamCurve
00164     virtual void reverseParameterDirection(bool switchparam = false);
00165 
00166     // Inherited from ParamCurve
00167     virtual SplineCurve* geometryCurve();
00168 
00169     // Inherited from ParamCurve
00170     virtual DirectionCone directionCone() const;
00171 
00172     // Inherited from ParamCurve
00173     virtual CompositeBox compositeBox() const;
00174 
00175     // Inherited from ParamCurve
00176     virtual bool isDegenerate(double degenerate_epsilon);
00177 
00184 
00185     SplineCurve* derivCurve(int ider) const;
00186 
00187     // Inherited from ParamCurve
00188 #if ((_MSC_VER > 0) && (_MSC_VER < 1300))
00189     virtual ParamCurve* subCurve(double from_par, double to_par,
00190                                  double fuzzy 
00191                                  = DEFAULT_PARAMETER_EPSILON) const;
00192 #else
00193     virtual SplineCurve* subCurve(double from_par, double to_par,
00194                                   double fuzzy 
00195                                   = DEFAULT_PARAMETER_EPSILON) const;
00196 #endif
00197 
00198     // Inherited from ParamCurve
00199     virtual void closestPoint(const Point& pt,
00200                               double         tmin,
00201                               double         tmax,
00202                               double&        clo_t,
00203                               Point&         clo_pt,
00204                               double&        clo_dist,
00205                               double const   *seed = 0) const;
00206 
00229     virtual void appendCurve(ParamCurve* other_curve,
00230                              int continuity, 
00231                              double& dist, 
00232                              bool repar=true);
00233     
00243     virtual void appendCurve(ParamCurve* cv, bool repar=true);
00244 
00247     const BsplineBasis& basis() const
00248     { return basis_; }
00249 
00252     BsplineBasis& basis()
00253     { return basis_; }
00254 
00257     int numCoefs() const
00258     { return basis_.numCoefs(); }
00259 
00262     int order() const
00263     { return basis_.order(); }
00264 
00267     bool rational() const
00268     { return rational_; }
00269 
00272     std::vector<double>::iterator knotsBegin()
00273     { return basis_.begin(); }
00276     std::vector<double>::iterator knotsEnd()
00277     { return basis_.end(); }
00280     std::vector<double>::const_iterator knotsBegin() const
00281     { return basis_.begin(); }
00284     std::vector<double>::const_iterator knotsEnd() const
00285     { return basis_.end(); }
00286 
00287 
00292     std::vector<double>::iterator coefs_begin() 
00293     { return coefs_.begin(); }
00298     std::vector<double>::iterator coefs_end() 
00299     { return coefs_.end(); }
00304     std::vector<double>::const_iterator coefs_begin() const 
00305     { return coefs_.begin(); }
00310     std::vector<double>::const_iterator coefs_end() const 
00311     { return coefs_.end(); }
00316     std::vector<double>::iterator rcoefs_begin() 
00317     { return rcoefs_.begin(); }
00322     std::vector<double>::iterator rcoefs_end() 
00323     { return rcoefs_.end(); }
00328     std::vector<double>::const_iterator rcoefs_begin() const 
00329     { return rcoefs_.begin(); }
00334     std::vector<double>::const_iterator rcoefs_end() const 
00335     { return rcoefs_.end(); }
00336 
00349     void interpolate(Interpolator& interpolator,
00350                      int num_points,
00351                      int dim,
00352                      const double* param_start,
00353                      const double* data_start);
00354 
00357     void insertKnot(double apar);
00358 
00362     void insertKnot(const std::vector<double>& new_knots);
00363 
00366     void makeBernsteinKnots();
00367 
00372     void setParameterInterval(double t1, double t2);
00373 
00376     void removeKnot(double tpar);
00377 
00381     void raiseOrder(int i = 1);
00382 
00385     void makeKnotStartRegular();
00386 
00389     void makeKnotEndRegular();
00390 
00393     void swap(SplineCurve& other);
00394 
00403     virtual double nextSegmentVal(double par, bool forward, 
00404                                   double tol) const;
00405 
00406 
00407 private:
00408     // Canonical data
00409     int dim_;
00410     bool rational_;
00411     BsplineBasis basis_;
00412     std::vector<double> coefs_;   
00413     std::vector<double> rcoefs_;  
00414 
00415 
00416     // Helper functions
00417     void updateCoefsFromRcoefs();
00428     void appendSelfPeriodic();
00429 
00430 };
00431 
00432 
00434 } // namespace Go
00435 
00436 
00437 
00438 #endif // _GOSPLINECURVE_H
00439 
00440 

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