00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00028 #ifndef GIRLPATH_HPP
00029 #define GIRLPATH_HPP
00030
00031 #include <girl/girlFreemanCodePath.hpp>
00032 #include <girl/girlContour.hpp>
00033
00034 namespace girl {
00035
00041 class GIRL_API path : public freemanCodePath
00042 {
00043
00044 public:
00045
00051 inline path(const girl::point &startPt = girl::point(0, 0));
00052
00059 path(const girl::point &startPt,
00060 const std::deque<girl::direction> &dirs);
00061
00072 inline path(const girl::point &startPt, const girl::point &endPt,
00073 const std::deque<girl::direction> &dirs);
00074
00075
00081 inline path(const girl::contour &c);
00082
00087 void set(const girl::point &startPt,
00088 const std::deque<girl::direction> &dirs);
00089
00098 inline void set(const girl::point &startPt, const girl::point &endPt,
00099 const std::deque<girl::direction> &dirs);
00100
00101
00102
00107 inline bool isClosed() const;
00108
00109
00113 inline girl::point startPt() const;
00114
00115
00119 inline girl::point endPt() const;
00120
00126 inline size_t length() const;
00127
00132 inline bool isValid() const;
00133
00137 inline bool operator==(const path &o);
00138
00142 inline bool operator!=(const path &o);
00143
00153 void invertOrientation();
00154
00160 void add(girl::direction d);
00161
00166 void append(const girl::path &p);
00167
00168
00174 void move(const girl::point &newStartPt);
00175
00182 void crop(size_t startIndex, size_t length);
00183
00184
00185 private:
00186
00201 path(const girl::point &start,
00202 const girl::point &end,
00203 const std::vector<char> &packedDirections,
00204 size_t nbDirections);
00205
00206 void set_aux(const std::deque<girl::direction> &dirs);
00207
00208 private:
00209
00210 girl::point m_end;
00211
00212 };
00213
00214
00215
00216
00217
00218
00219 path::path(const girl::point &pStartPt)
00220 : freemanCodePath(pStartPt), m_end(pStartPt)
00221 {
00222 assert(isValid());
00223 }
00224
00225 path::path(const girl::point &pStartPt, const girl::point &pEndPt,
00226 const std::deque<girl::direction> &dirs)
00227 : freemanCodePath(pStartPt, dirs), m_end(pEndPt)
00228 {
00229 assert(m_end == freemanCodePath::endPt());
00230 }
00231
00232 path::path(const girl::contour &c)
00233 : freemanCodePath(c), m_end(m_start)
00234 {
00235
00236 }
00237
00238
00239 void
00240 path::set(const girl::point &pStartPt, const girl::point &pEndPt,
00241 const std::deque<girl::direction> &dirs)
00242 {
00243 freemanCodePath::set(pStartPt, dirs);
00244 m_end = pEndPt;
00245
00246 assert(isValid());
00247 }
00248
00249 bool
00250 path::isClosed() const
00251 {
00252 return m_start == m_end;
00253 }
00254
00255 girl::point
00256 path::endPt() const
00257 {
00258 return m_end;
00259 }
00260
00261 girl::point
00262 path::startPt() const
00263 {
00264 return freemanCodePath::startPt();
00265 }
00266
00267 size_t
00268 path::length() const
00269 {
00270 return freemanCodePath::length();
00271 }
00272
00273 bool
00274 path::isValid() const
00275 {
00276 return freemanCodePath::isValid() && (m_end == freemanCodePath::endPt());
00277 }
00278
00279 bool
00280 path::operator==(const path &o)
00281 {
00282 return freemanCodePath::operator==(o) && m_end == o.m_end;
00283 }
00284
00285 bool
00286 path::operator!=(const path &o)
00287 {
00288 return !operator==(o);
00289 }
00290
00291 }
00292
00293
00294 #endif