00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
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
00183
00184
00185
00186
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 }
00219
00220 #endif // _GOCURVELOOP_H
00221
00222