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

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