//=========================================================================== // 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 _CURVELOOP_H 00016 #define _CURVELOOP_H 00017 00018 #include <boost/smart_ptr.hpp> 00019 #include <vector> 00020 #include "GoTools/utils/config.h" 00021 #include "GoTools/geometry/ParamCurve.h" 00022 00023 00024 namespace Go 00025 { 00033 class GO_API CurveLoop 00034 { 00035 public: 00037 CurveLoop(); 00038 00049 CurveLoop(const std::vector< boost::shared_ptr<ParamCurve> >& curves, 00050 double space_epsilon); 00051 00053 virtual ~CurveLoop(); 00054 00056 void swap(CurveLoop& other); 00057 00067 void setCurves(const std::vector< boost::shared_ptr<ParamCurve> >& curves); 00068 00070 void turnOrientation(); 00071 00075 void setSpaceEpsilon(const double space_epsilon); 00076 00079 double getSpaceEpsilon() const; 00080 00083 int size() const { return curves_.size(); } 00084 00087 std::vector< boost::shared_ptr<ParamCurve> >::const_iterator begin() const 00088 { return curves_.begin(); } 00089 00092 std::vector< boost::shared_ptr<ParamCurve> >::const_iterator end() const 00093 { return curves_.end(); } 00094 00097 std::vector< boost::shared_ptr<ParamCurve> >::iterator begin() 00098 { return curves_.begin(); } 00099 00102 std::vector< boost::shared_ptr<ParamCurve> >::iterator end() 00103 { return curves_.end(); } 00104 00108 boost::shared_ptr<ParamCurve> operator[] (int index) const; 00109 00121 void closestPoint(const Point& pt, int& clo_ind, double& clo_par, 00122 Point& clo_pt, double& clo_dist) const; 00123 00144 void closestParPoint(const Point& pt, int& clo_ind, double& clo_par, 00145 Point& clo_pt, double& clo_dist) const; 00146 00148 std::vector<boost::shared_ptr<ParamCurve> > getCurves() 00149 { 00150 return curves_; 00151 } 00152 00154 std::vector<Point> getCorners() const; 00155 00158 bool isValid() const; 00159 00163 bool fixInvalidLoop(double& max_gap); 00164 00165 // double maxGap(int nmb_seg_samples); 00166 00168 bool simplify(double tol, double ang_tol, double& max_dist); 00169 00170 private: 00171 std::vector< boost::shared_ptr<ParamCurve> > curves_; 00172 double space_epsilon_; 00173 // The curves should form a loop. 00174 int valid_state_; // 0 = not validated. 00175 // 1 = valid 00176 // -1 = not valid 00177 00178 }; 00179 00180 00181 00182 00183 //=========================================================================== 00185 template <class PtrToCurveType> 00186 inline double computeLoopGap(const std::vector< PtrToCurveType >& curves) 00187 //=========================================================================== 00188 { 00189 00190 // Here, we should check that the given curves indeed are forming a 00191 // loop, so every endpoint is within space_epsilon of the start of the 00192 // next curve. 00193 // Also, we make sure that all curves have the same dimension 00194 // and that the curves are of the same type 00195 if ((curves.size() == 0) || (curves[0] == NULL)) 00196 return -1.0; 00197 00198 int dim = curves[0]->dimension(); 00199 // ClassType type = curves[0]->instanceType(); 00200 int n = curves.size(); 00201 int i; 00202 for (i = 1; i < n; ++i) { 00203 if (curves[i] == NULL) 00204 return -1.0; 00205 if (curves[i]->dimension() != dim) { 00206 THROW("Curves do not have the same dimension."); 00207 } 00208 // if (curves[i]->instanceType() != type) { 00209 // THROW("Not all curves are of the same type."); 00210 // } 00211 } 00212 Point startp(dim); 00213 Point endp(dim); 00214 double maxdist = -1.0; 00215 double dist; 00216 for (i = 1; i < n; ++i) { 00217 curves[i-1]->point(endp, curves[i-1]->endparam()); 00218 curves[i]->point(startp, curves[i]->startparam()); 00219 dist = endp.dist(startp); 00220 if (dist > maxdist) maxdist = dist; 00221 } 00222 curves[n-1]->point(endp, curves[n-1]->endparam()); 00223 curves[0]->point(startp, curves[0]->startparam()); 00224 dist = endp.dist(startp); 00225 if (dist > maxdist) maxdist = dist; 00226 return maxdist; 00227 } 00228 00229 00230 } // namespace Go 00231 00232 #endif // _CURVELOOP_H 00233
Generated on Tue Sep 21 15:44:17 2010 for GoTools Core by  doxygen 1.6.3