Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

_QGAR_GenQgarPolyline.TCC

Go to the documentation of this file.
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   _QGAR_GenQgarPolyline.TCC
00030  * @brief  Implementation of function members
00031  *         of class qgar::GenQgarPolyline.
00032  *
00033  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00034  * @date   December 14, 2004  18:19
00035  * @since  Qgar 2.2
00036  */
00037 
00038 
00039 
00040 // STL
00041 #include <deque>
00042 #include <iostream>
00043 #include <list>
00044 #include <vector>
00045 // QGAR
00046 #include <qgarlib/ISerializable.H>
00047 
00048 
00049 
00050 namespace qgar
00051 {
00052 
00053 
00054 // -------------------------------------------------------------------
00055 // C O N S T R U C T O R S
00056 // -------------------------------------------------------------------
00057 
00058 
00059 // DEFAULT CONSTRUCTOR
00060 
00061 template <class T>
00062 GenQgarPolyline<T>::GenQgarPolyline(int aThickness,
00063                                     QGEcolor aColor,
00064                                     QGEoutline anOutline)
00065 
00066   : AbstractGenQgarPrimitive<T>(aThickness,
00067                                 aColor,
00068                                 anOutline)
00069 
00070 {
00071   // VOID
00072 }
00073 
00074 
00075 // COPY CONSTRUCTOR
00076 
00077 template <class T>
00078 GenQgarPolyline<T>::GenQgarPolyline(const GenQgarPolyline<T>& aQPoly)
00079 
00080   : AbstractGenQgarPrimitive<T>(aQPoly._thickness,
00081                                 aQPoly._color,
00082                                 aQPoly._outline),
00083     _geomStructure(aQPoly._geomStructure)
00084 
00085 {
00086   // VOID
00087 }
00088 
00089 
00090 // INITIALIZE FROM A GEOMETRICAL POLYLINE
00091 
00092 template <class T>
00093 GenQgarPolyline<T>::GenQgarPolyline(const GenPolyline<T>& aPoly,
00094                                     int aThickness,
00095                                     QGEcolor aColor,
00096                                     QGEoutline anOutline)
00097 
00098   : AbstractGenQgarPrimitive<T>(aThickness,
00099                                 aColor,
00100                                 anOutline),
00101     _geomStructure(aPoly)
00102 
00103 {
00104   // VOID
00105 }
00106 
00107 
00108 // INITIALIZE FROM A QGAR SEGMENT
00109 
00110 template <class T>
00111 GenQgarPolyline<T>::GenQgarPolyline(const GenQgarSegment<T>& aQSeg)
00112 
00113   : AbstractGenQgarPrimitive<T>(aQSeg.thickness(),
00114                                 aQSeg.color(),
00115                                 aQSeg.outline())
00116 
00117 {
00118   _geomStructure = GenPolyline<T>(aQSeg.accessGeomStructure());
00119 }
00120 
00121 
00122 // INITIALIZE FROM A (GEOMETRICAL) SEGMENT
00123 
00124 template <class T>
00125 GenQgarPolyline<T>::GenQgarPolyline(const GenSegment<T>& aSeg,
00126                                     int aThickness,
00127                                     QGEcolor aColor,
00128                                     QGEoutline anOutline)
00129 
00130   : AbstractGenQgarPrimitive<T>(aThickness,
00131                                 aColor,
00132                                 anOutline)
00133 
00134 {
00135   _geomStructure = GenPolyline<T>(aSeg);
00136 }
00137 
00138 
00139 // INITIALIZE FROM SOURCE AND TARGET
00140 
00141 template <class T>
00142 GenQgarPolyline<T>::GenQgarPolyline(const GenPoint<T>& aSource,
00143                                     const GenPoint<T>& aTarget,
00144                                     int        aThickness,
00145                                     QGEcolor   aColor,
00146                                     QGEoutline anOutline)
00147 
00148   : AbstractGenQgarPrimitive<T>(aThickness,
00149                                 aColor,
00150                                 anOutline),
00151     _geomStructure(aSource, aTarget)
00152 {
00153   // VOID
00154 }
00155 
00156 
00157 // INITIALIZE FROM A LIST OF AT LEAST 2 POINTS
00158 
00159 template <class T>
00160 GenQgarPolyline<T>::GenQgarPolyline(const std::list< GenPoint<T> >& aPtList,
00161                                     int aThickness,
00162                                     QGEcolor aColor,
00163                                     QGEoutline anOutline)
00164 
00165   : AbstractGenQgarPrimitive<T>(aThickness,
00166                                 aColor,
00167                                 anOutline)
00168 
00169 {
00170   _geomStructure = GenPolyline<T>(aPtList);
00171 }
00172 
00173 
00174 // -------------------------------------------------------------------
00175 // D E S T R U C T O R
00176 // -------------------------------------------------------------------
00177 
00178 
00179 // VIRTUAL DESTRUCTOR
00180 
00181 template <class T>
00182 GenQgarPolyline<T>::~GenQgarPolyline()
00183 {
00184   // VOID
00185 }
00186 
00187 
00188 // -------------------------------------------------------------------
00189 // C O P Y
00190 // -------------------------------------------------------------------
00191 
00192 
00193 // DEEP COPY
00194 
00195 template <class T>
00196 GenQgarPolyline<T>*
00197 GenQgarPolyline<T>::clone() const
00198 {
00199   return new GenQgarPolyline<T>(*this);
00200 }
00201 
00202 
00203 // -------------------------------------------------------------------
00204 // OPERATORS
00205 // -------------------------------------------------------------------
00206 
00207 
00208 // Assignment.
00209 template <class T>
00210 GenQgarPolyline<T>&
00211 GenQgarPolyline<T>::operator=(const GenQgarPolyline<T>& aQPoly)
00212 {
00213   // Are left hand side and right hand side different objects?
00214   if (this != &aQPoly)
00215     {
00216       AbstractGenQgarPrimitive<T>::operator=(aQPoly);
00217       _geomStructure = aQPoly._geomStructure;
00218     }
00219 
00220   return *this;
00221 }
00222 
00223 
00224 // -------------------------------------------------------------------
00225 // ACCESS TO THE GEOMETRICAL STRUCTURE
00226 // -------------------------------------------------------------------
00227 
00228 
00229 // GET THE STRUCTURE IMPLEMENTING
00230 // THE GEOMETRICAL ASPECT OF A QGAR POLYLINE
00231 
00232 template <class T>
00233 inline const GenPolyline<T>&
00234 GenQgarPolyline<T>::accessGeomStructure() const
00235 {
00236   return _geomStructure;
00237 }
00238 
00239 
00240 // -------------------------------------------------------------------
00241 // A C C E S S   T O   V E R T I C E S
00242 // -------------------------------------------------------------------
00243 
00244 
00245 // GET NUMBER OF VERTICES
00246 
00247 template <class T>
00248 inline int
00249 GenQgarPolyline<T>::size() const
00250 {
00251   return _geomStructure.size();
00252 }
00253 
00254 
00255 // GET VERTICES
00256 
00257 template <class T>
00258 inline const std::deque< GenPoint<T> >&
00259 GenQgarPolyline<T>::accessVertices() const
00260 {
00261   return _geomStructure.accessVertices();
00262 }
00263 
00264 
00265 // GIVE NON-PROTECTED ACCESS TO THE VERTICES
00266 
00267 template <class T>
00268 inline std::deque< GenPoint<T> >&
00269 GenQgarPolyline<T>::getVertices()
00270 {
00271   return _geomStructure.getVertices();
00272 }
00273 
00274 
00275 // GET A COPY OF VERTICES
00276 
00277 template <class T>
00278 inline std::deque< GenPoint<T> >
00279 GenQgarPolyline<T>::vertices() const
00280 {
00281   return _geomStructure.vertices();
00282 }
00283 
00284 
00285 // -------------------------------------------------------------------
00286 // I N S E R T   V E R T I C E S
00287 // -------------------------------------------------------------------
00288 
00289 
00290 // ADD A POINT AS NEW SOURCE
00291 
00292 template <class T>
00293 GenQgarPolyline<T>&
00294 GenQgarPolyline<T>::appendSource(const GenPoint<T>& aPt)
00295 {
00296   _geomStructure.appendSource(aPt);
00297   return *this;
00298 }
00299 
00300 
00301 // ADD A POINT AS NEW TARGET
00302 
00303 template <class T>
00304 GenQgarPolyline<T>&
00305 GenQgarPolyline<T>::appendTarget(const GenPoint<T>& aPt)
00306 {
00307   _geomStructure.appendTarget(aPt);
00308   return *this;
00309 }
00310 
00311 
00312 // APPEND A QGAR POLYLINE
00313 
00314 template<class T>
00315 GenQgarPolyline<T>& 
00316 GenQgarPolyline<T>::append(const GenQgarPolyline<T>& aQPoly)
00317 {
00318   _geomStructure.append(aQPoly);
00319   return *this;
00320 }
00321 
00322 
00323 // APPEND A POLYLINE
00324 
00325 template<class T>
00326 GenQgarPolyline<T>& 
00327 GenQgarPolyline<T>::append(const GenPolyline<T>& aPoly)
00328 {
00329   _geomStructure.append(aPoly);
00330   return *this;
00331 }
00332 
00333 
00334 // APPEND A VECTOR OF POINTS
00335 
00336 template<class T>
00337 GenQgarPolyline<T>& 
00338 GenQgarPolyline<T>::append(const std::vector<GenPoint<T> >& aPtVect)
00339 {
00340   _geomStructure.append(aPtVect);
00341   return *this;
00342 }
00343 
00344 
00345 // -------------------------------------------------------------------
00346 // R E M O V E   V E R T I C E S
00347 // -------------------------------------------------------------------
00348 
00349 
00350 // REMOVE A VERTEX
00351 
00352 template <class T>
00353 GenQgarPolyline<T>&
00354 GenQgarPolyline<T>::remove(const GenPoint<T>& aPt)
00355 {
00356   _geomStructure.remove(aPt);
00357   return *this;
00358 }
00359 
00360 
00361 // -------------------------------------------------------------------
00362 // CONVERSIONS OF THE SERIES OF VERTICES
00363 // -------------------------------------------------------------------
00364 
00365 
00366 // GET A VECTOR OF POINTS FROM THE LIST OF VERTICES
00367 
00368 template <class T>
00369 inline std::vector< GenPoint<T> >
00370 GenQgarPolyline<T>::toPointVector()
00371 {
00372   return _geomStructure.toPointVector();
00373 }
00374 
00375 
00376 // GET A STL LIST OF (GEOMETRICAL) SEGMENTS FROM THE VERTICES
00377 
00378 template <class T>
00379 inline std::list<GenSegment<T> >
00380 GenQgarPolyline<T>::toSegList()
00381 {
00382   return _geomStructure.toSegList();
00383 }
00384 
00385 
00386 // GET A STL LIST OF QGAR SEGMENTS FROM THE VERTICES
00387 
00388 template <class T>
00389 inline std::list< GenQgarSegment<T> >
00390 GenQgarPolyline<T>::toQgarSegList()
00391 {
00392   return _geomStructure.toQgarSegList(this->_thickness, 
00393                                       this->_color,
00394                                       this->_outline);
00395 }
00396 
00397 
00398 // -------------------------------------------------------------------
00399 // NON-PROTECTED ACCESS TO THE GEOMETRICAL ASPECT
00400 // -------------------------------------------------------------------
00401 
00402 
00403 // RETURN THE GEOMETRICAL ASPECT
00404 
00405 template <class T>
00406 inline AbstractGenPrimitive<T>&
00407 GenQgarPolyline<T>::getGeomStructure()
00408 {
00409   return _geomStructure;
00410 }
00411 
00412 
00413 // -------------------------------------------------------------------
00414 // S E R I A L I Z A T I O N / D E S E R I A L I Z A T I O N
00415 // -------------------------------------------------------------------
00416 
00417 
00418 template <class T>
00419 inline std::istream& 
00420 GenQgarPolyline<T>::read(std::istream& anInStream)
00421 {
00422   qgReadObjName(anInStream, "QgarPolyline");
00423 
00424   // Geometrical structure
00425 
00426   qgReadObjData(anInStream, _geomStructure);
00427 
00428   // Attributes
00429 
00430   qgReadObjData(anInStream, this->_thickness);
00431 
00432   int color;
00433   qgReadObjData(anInStream, color);
00434   this->_color = static_cast<QGEcolor>(color);
00435 
00436   int outline;
00437   qgReadObjData(anInStream, outline);
00438   this->_outline = static_cast<QGEoutline>(outline);
00439 
00440   return anInStream;
00441 }
00442 
00443 
00444 template <class T>
00445 inline std::ostream& 
00446 GenQgarPolyline<T>::write(std::ostream& anOutStream) const
00447 {
00448   anOutStream << "QgarPolyline("
00449               << this->_geomStructure
00450               << ")("
00451               << this->_thickness
00452               << ")("
00453               << this->_color
00454               << ")("
00455               << this->_outline
00456               << ')';
00457   return anOutStream;  
00458 }
00459 
00460 
00461 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00462 // V                                                                 V
00463 // V            IMPLEMENTATION OF PURE VIRTUAL FUNCTIONS             V
00464 // V            INHERITED FROM AbstractGenQgarPrimitive              V
00465 // V                                                                 V
00466 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00467 
00468 
00469 // -------------------------------------------------------------------
00470 // G E O M E T R Y :   T R A N S L A T I O N 
00471 // -------------------------------------------------------------------
00472 
00473 
00474 template <class T>
00475 inline void
00476 GenQgarPolyline<T>::translate(T aX, T aY)
00477 {
00478   (this->_geomStructure).translate(aX, aY);
00479 }
00480 
00481 
00482 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00483 // V                                                                 V
00484 // VVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVVV
00485 
00486 
00487 } // namespace qgar