00001 /*---------------------------------------------------------------------+ 00002 | Library QgarLib, graphics analysis and recognition | 00003 | Copyright (C) 2002 Qgar Project, LORIA | 00004 | | 00005 | This library is free software; you can redistribute it and/or | 00006 | modify it under the terms of the GNU Lesser General Public | 00007 | License version 2.1, as published by the Free Software Foundation. | 00008 | | 00009 | This library is distributed in the hope that it will be useful, | 00010 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 00011 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | 00012 | See the GNU Lesser General Public License for more details. | 00013 | | 00014 | The GNU Lesser General Public License is included in the file | 00015 | LICENSE.LGPL, in the root directory of the Qgar packaging. See | 00016 | http://www.gnu.org/licenses/lgpl.html for the terms of the licence. | 00017 | To receive a paper copy, write to the Free Software Foundation, | 00018 | Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. | 00019 | | 00020 | Contact Project Qgar for any information: | 00021 | LORIA - équipe Qgar | 00022 | B.P. 239, 54506 Vandoeuvre-lès-Nancy Cedex, France | 00023 | email: qgar-contact@loria.fr | 00024 | http://www.qgar.org/ | 00025 *---------------------------------------------------------------------*/ 00026 00027 00028 /** 00029 * @file GenPointChain.TCC 00030 * @brief Implementation of function members of class qgar::GenPointChain. 00031 * 00032 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a> 00033 * @date January 27, 2005 22:22 00034 * @since Qgar 2.2 00035 */ 00036 00037 00038 00039 // STD 00040 #include <list> 00041 // QGAR 00042 #include <qgarlib/primitives.H> 00043 00044 00045 00046 namespace qgar 00047 { 00048 00049 00050 // ------------------------------------------------------------------- 00051 // C O N S T R U C T O R S 00052 // ------------------------------------------------------------------- 00053 00054 00055 // DEFAULT CONSTRUCTOR 00056 00057 template <class T> 00058 GenPointChain<T>::GenPointChain() : _chain() 00059 { 00060 // Set iterator to end of chain 00061 _iter = _chain.end(); 00062 } 00063 00064 00065 // COPY CONSTRUCTOR 00066 00067 template <class T> 00068 GenPointChain<T>::GenPointChain(const GenPointChain<T>& aPtChain) 00069 00070 : _chain(aPtChain._chain) 00071 00072 { 00073 // Set the iterator to the beginning of the chain 00074 _iter = _chain.begin(); 00075 } 00076 00077 00078 // CONSTRUCT FROM A GIVEN POINT 00079 00080 template <class T> 00081 GenPointChain<T>::GenPointChain(const GenPoint<T>& aPoint) 00082 00083 : _chain() 00084 00085 { 00086 _chain.push_back(aPoint); 00087 // Set iterator to the beginning of the chain 00088 _iter = _chain.begin(); 00089 } 00090 00091 00092 // ------------------------------------------------------------------- 00093 // D E S T R U C T O R 00094 // ------------------------------------------------------------------- 00095 00096 00097 template <class T> 00098 GenPointChain<T>::~GenPointChain() 00099 { 00100 // VOID 00101 } 00102 00103 00104 // ------------------------------------------------------------------- 00105 // A C C E S S T O C H A I N C H A R A C T E R I S T I C S 00106 // ------------------------------------------------------------------- 00107 00108 00109 // IS CURRENT CHAIN EMPTY? 00110 00111 template <class T> 00112 bool 00113 GenPointChain<T>::empty() const 00114 { 00115 return _chain.empty(); 00116 } 00117 00118 00119 // GET CHAIN SIZE (number of points) 00120 00121 template <class T> 00122 int 00123 GenPointChain<T>::size() const 00124 { 00125 return _chain.size(); 00126 } 00127 00128 00129 // ------------------------------------------------------------------- 00130 // I T E R A T O R 00131 // ------------------------------------------------------------------- 00132 00133 00134 // SET ITERATOR TO THE FIRST POINT IN CHAIN 00135 00136 template <class T> 00137 void GenPointChain<T>::setToBegin() 00138 { 00139 _iter = _chain.begin(); 00140 } 00141 00142 00143 // SET ITERATOR TO THE LAST POINT IN CHAIN 00144 00145 template <class T> 00146 void GenPointChain<T>::setToEnd() 00147 { 00148 _iter = _chain.end(); 00149 --_iter; 00150 } 00151 00152 00153 // IS THERE A POINT AFTER THE CURRENT POINT? 00154 00155 template <class T> 00156 bool 00157 GenPointChain<T>::hasNext() const 00158 { 00159 typename std::list< GenPoint<T> >::iterator itAux = _iter; 00160 return (++itAux != _chain.end()); 00161 } 00162 00163 00164 // IS THERE A POINT BEFORE THE CURRENT POINT? 00165 00166 template <class T> 00167 bool 00168 GenPointChain<T>::hasPrevious() const 00169 { 00170 return (_iter != _chain.begin()); 00171 } 00172 00173 00174 // DOES INTERNAL ITERATOR POINTS TO THE BEGINNING OF THE CHAIN? 00175 00176 template <class T> 00177 bool 00178 GenPointChain<T>::isAtBegin() const 00179 { 00180 return _iter == _chain.begin(); 00181 } 00182 00183 00184 // DOES INTERNAL ITERATOR POINTS TO THE END OF THE CHAIN? 00185 00186 template <class T> 00187 bool 00188 GenPointChain<T>::isAtEnd() const 00189 { 00190 return _iter == _chain.end(); 00191 } 00192 00193 00194 // INCREMENT ITERATOR 00195 00196 template <class T> 00197 void GenPointChain<T>::moveNext() 00198 { 00199 ++_iter; 00200 } 00201 00202 00203 // DECREMENT ITERATOR 00204 00205 template <class T> 00206 void GenPointChain<T>::movePrevious() 00207 { 00208 --_iter; 00209 } 00210 00211 00212 // ------------------------------------------------------------------- 00213 // A C C E S S T O P O I N T S 00214 // ------------------------------------------------------------------- 00215 00216 00217 // GET FIRST POINT 00218 00219 template <class T> 00220 const GenPoint<T>& 00221 GenPointChain<T>::accessFront() const 00222 { 00223 return _chain.front(); 00224 } 00225 00226 // GET A COPY OF THE FIRST POINT 00227 00228 template <class T> 00229 GenPoint<T> 00230 GenPointChain<T>::front() const 00231 { 00232 return _chain.front(); 00233 } 00234 00235 // GET LAST POINT 00236 00237 template <class T> 00238 const GenPoint<T>& 00239 GenPointChain<T>::accessBack() const 00240 { 00241 return _chain.back(); 00242 } 00243 00244 // GET A COPY OF THE LAST POINT 00245 00246 template <class T> 00247 GenPoint<T> GenPointChain<T>::back() const 00248 { 00249 return _chain.back(); 00250 } 00251 00252 00253 // GET THE CURRENT POINT 00254 00255 template <class T> 00256 const GenPoint<T>& 00257 GenPointChain<T>::accessCurrent() const 00258 { 00259 return *_iter; 00260 } 00261 00262 00263 // GET A COPY OF THE CURRENT POINT 00264 00265 template <class T> 00266 GenPoint<T> GenPointChain<T>::current() const 00267 { 00268 return *_iter; 00269 } 00270 00271 00272 // GET THE SUCCESSOR OF THE CURRENT POINT 00273 00274 template <class T> 00275 const GenPoint<T>& 00276 GenPointChain<T>::accessNext() 00277 { 00278 _iter++; 00279 return *_iter; 00280 } 00281 00282 // GET A COPY OF THE SUCCESSOR OF THE CURRENT POINT 00283 00284 template <class T> 00285 GenPoint<T> 00286 GenPointChain<T>::next() 00287 { 00288 _iter++; 00289 return *_iter; 00290 } 00291 00292 00293 // GET THE PREDECESSOR OF THE CURRENT POINT 00294 00295 template <class T> 00296 const GenPoint<T>& 00297 GenPointChain<T>::accessPrevious() 00298 { 00299 _iter--; 00300 return *_iter; 00301 } 00302 00303 00304 // GET A COPY OF THE PREDECESSOR OF THE CURRENT POINT 00305 00306 template <class T> 00307 GenPoint<T> GenPointChain<T>::previous() 00308 { 00309 _iter--; 00310 return *_iter; 00311 } 00312 00313 00314 // ------------------------------------------------------------------- 00315 // A C C E S S T O T H E L I S T O F P O I N T S 00316 // ------------------------------------------------------------------- 00317 00318 00319 // GET THE STL LIST IMPLEMENTING THE CHAIN OF POINTS 00320 00321 template <class T> 00322 inline const std::list< GenPoint<T> >& 00323 GenPointChain<T>::accessPointList() const 00324 { 00325 return _chain; 00326 } 00327 00328 00329 // GET THE STL LIST IMPLEMENTING THE CHAIN OF POINTS 00330 // The result is not const 00331 00332 template <class T> 00333 inline std::list< GenPoint<T> >& 00334 GenPointChain<T>::pointList() 00335 { 00336 return _chain; 00337 } 00338 00339 00340 // ------------------------------------------------------------------- 00341 // I N S E R T I O N 00342 // ------------------------------------------------------------------- 00343 00344 00345 // INSERT A POINT AT THE BEGINNING OF THE CHAIN 00346 00347 template <class T> 00348 void GenPointChain<T>::push_front(const GenPoint<T>& aPt) 00349 { 00350 _chain.push_front(aPt); 00351 } 00352 00353 00354 // INSERT A POINT AT THE END OF THE CHAIN 00355 00356 template <class T> 00357 void GenPointChain<T>::push_back(const GenPoint<T>& aPt) 00358 { 00359 _chain.push_back(aPt); 00360 } 00361 00362 00363 // ------------------------------------------------------------------- 00364 // T R A N S F O R M A T I O N S 00365 // ------------------------------------------------------------------- 00366 00367 00368 // REVERSE THE ORDER OF THE POINTS IN THE LIST 00369 00370 template <class T> 00371 void GenPointChain<T>::reverse() 00372 { 00373 _chain.reverse(); 00374 } 00375 00376 00377 // ------------------------------------------------------------------- 00378 // C O N V E R S I O N S 00379 // ------------------------------------------------------------------- 00380 00381 00382 // CONVERT INTO A STL LIST OF POINTS 00383 00384 template <class T> 00385 std::list< GenPoint<T> > 00386 GenPointChain<T>::toPointList() const 00387 { 00388 return _chain; 00389 } 00390 00391 00392 // ------------------------------------------------------------------- 00393 // O P E R A T O R S 00394 // ------------------------------------------------------------------- 00395 00396 00397 // ASSIGNMENT 00398 00399 template <class T> 00400 GenPointChain<T>& 00401 GenPointChain<T>::operator=(const GenPointChain<T>& aPtChain) 00402 { 00403 // Are left hand side and right hand side different objects? 00404 if (this != &aPtChain) 00405 { 00406 _chain = aPtChain._chain; 00407 00408 // Set the iterator to the beginning of the chain 00409 _iter = _chain.begin(); 00410 } 00411 00412 return *this; 00413 } 00414 00415 00416 // ------------------------------------------------------------------- 00417 00418 00419 } // namespace qgar