CurveLoop.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 _GOCURVELOOP_H
00034 #define _GOCURVELOOP_H
00035 
00036 #include <boost/smart_ptr.hpp>
00037 #include <vector>
00038 #include "ParamCurve.h"
00039 
00040 
00041 namespace Go
00042 {
00045 
00053 class CurveLoop
00054 {
00055 public:
00057     CurveLoop();
00058 
00069     CurveLoop(const std::vector< boost::shared_ptr<ParamCurve> >& curves,
00070               double space_epsilon);
00071 
00073     virtual ~CurveLoop();
00074 
00076     void swap(CurveLoop& other);
00077     
00087     void setCurves(const std::vector< boost::shared_ptr<ParamCurve> >& curves);
00088 
00090     void turnOrientation();
00091 
00095     void setSpaceEpsilon(const double space_epsilon);
00096 
00099     double getSpaceEpsilon() const;
00100 
00103     int size() const { return curves_.size(); }
00104 
00107     std::vector< boost::shared_ptr<ParamCurve> >::const_iterator begin() const
00108     { return curves_.begin(); }
00109     
00112     std::vector< boost::shared_ptr<ParamCurve> >::const_iterator end() const
00113     { return curves_.end(); }
00114 
00117     std::vector< boost::shared_ptr<ParamCurve> >::iterator begin()
00118     { return curves_.begin(); }
00119 
00122     std::vector< boost::shared_ptr<ParamCurve> >::iterator end()
00123     { return curves_.end(); }
00124 
00128     boost::shared_ptr<ParamCurve> operator[] (int index) const;
00129 
00141     void closestPoint(const Point& pt, int& clo_ind, double& clo_par, 
00142                       Point& clo_pt, double& clo_dist) const;
00143 
00164     void closestParPoint(const Point& pt, int& clo_ind, double& clo_par, 
00165                          Point& clo_pt, double& clo_dist) const;
00166 
00167 private:
00168     std::vector< boost::shared_ptr<ParamCurve> > curves_;
00169     double space_epsilon_;
00170 };
00171 
00172 
00173 
00174 
00175 //===========================================================================
00177 template <class PtrToCurveType>
00178 inline double computeLoopGap(const std::vector< PtrToCurveType >& curves)
00179 //===========================================================================
00180 {
00181 
00182     // Here, we should check that the given curves indeed are forming a
00183     // loop, so every endpoint is within space_epsilon of the start of the
00184     // next curve.
00185     // Also, we make sure that all curves have the same dimension
00186     // and that the curves are of the same type
00187 
00188     int dim = curves[0]->dimension();
00189     ClassType type = curves[0]->instanceType();
00190     int n = curves.size();
00191     int i;
00192     for (i = 1; i < n; ++i) {
00193         if (curves[i]->dimension() != dim) {
00194             THROW("Curves do not have the same dimension.");
00195         }
00196         if (curves[i]->instanceType() != type) {
00197             THROW("Not all curves are of the same type.");
00198         }
00199     }
00200     Point startp(dim);
00201     Point endp(dim);
00202     double maxdist = 0.0;
00203     double dist;
00204     for (i = 1; i < n; ++i) {
00205         curves[i-1]->point(endp, curves[i-1]->endparam());
00206         curves[i]->point(startp, curves[i]->startparam());
00207         dist = endp.dist(startp);
00208         if (dist > maxdist) maxdist = dist;
00209     }
00210     curves[n-1]->point(endp, curves[n-1]->endparam());
00211     curves[0]->point(startp, curves[0]->startparam());
00212     dist = endp.dist(startp);
00213     if (dist > maxdist) maxdist = dist;
00214     return maxdist;
00215 }
00216 
00218 } // namespace Go
00219 
00220 #endif // _GOCURVELOOP_H
00221 
00222 

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