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

_QGAR_GenQgarPolyline.H

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 #ifndef ___QGAR_GENQGARPOLYLINE_H_INCLUDED__
00029 #define ___QGAR_GENQGARPOLYLINE_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   _QGAR_GenQgarPolyline.H
00034  * @brief  Header file of class qgar::GenQgarPolyline.
00035  *
00036  * @warning <b>Not to be used as include file!</b>
00037  * <br>When working with primitives, use file primitives.H.
00038  *
00039  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00040  * @date   December 14, 2004  18:18
00041  * @since  Qgar 2.2
00042  */
00043 
00044 
00045 // For RCS/CVS use: Do not delete
00046 /* $Id: _QGAR_GenQgarPolyline.H,v 1.4 2005/10/14 17:05:48 masini Exp $ */
00047 
00048 
00049 
00050 // STD
00051 #include <deque>
00052 #include <iosfwd>  // Avoid including classes when not necessary
00053 #include <list>
00054 #include <vector>
00055 // QGAR
00056 #include <qgarlib/ISerializable.H>
00057 
00058 
00059 
00060 namespace qgar
00061 {
00062 
00063 
00064 /**
00065  * @class GenQgarPolyline _QGAR_GenQgarPolyline.H "qgarlib/primitives.H"
00066  * @ingroup DS_PRIM_QGAR
00067  * @brief Graphical polyline, so-called <i>Qgar polyline</i>,
00068  * with coordinates of type <b>T</b>.
00069  *
00070  * <ul>
00071  *
00072  * <li>
00073 @verbatim
00074    O
00075     +---------------> X
00076     |\    |
00077     | \ <-'
00078     |  \    angle (in radians, unless specified)
00079     |   \
00080     |
00081     V
00082 
00083     Y
00084 @endverbatim
00085  * The origin of the coordinate system is at top left corner.
00086  * Angles are clockwise from the X axis.
00087  * </li>
00088  *
00089  * <li>
00090  * A Qgar polyline is a series of points, implemented as a STL
00091  * <b>deque</b>): Each point represents a vertex and two
00092  * consecutive points represent a segment.
00093  * </li>
00094  *
00095  * <li>
00096  * A Qgar polyline must always be provided with at least 2 vertices.
00097  * </li>
00098  *
00099  * <li>
00100  * A Qgar polyline is oriented: It is provided with a so-called
00101  * <i>source</i> vertex (first of the series)
00102  * and a so-called <i>target</i> vertex (last of the series).
00103  * </li>
00104  *
00105  * <li>
00106  * A Qgar polyline does not define any closed geometrical shape,
00107  * like a Qgar polygon. In particular, the source and target vertices
00108  * do not define a segment.
00109  * </li>
00110  *
00111  * <li>
00112  * A Qgar polyline is provided with attributes: thickness, color,
00113  * and outline. When such features are useless, see class
00114  * qgar::GenPolyline (for geometrical polylines).
00115  * </li>
00116  *
00117  * <li>
00118  * Predefined types:
00119  * qgar::QgarPolyline,
00120  * qgar::IQgarPolyline,
00121  * qgar::FQgarPolyline,
00122  * qgar::DQgarPolyline.
00123  * </li>
00124  *
00125  * </ul>
00126  *
00127  *
00128  * @warning
00129  *   <b>The coherence of the data structure of a polyline after
00130  *   modifications of its source and/or its target and/or its
00131  *   other vertices is the user's responsibility!</b>
00132  *
00133  *
00134  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00135  * @date   June 24, 2003  15:35
00136  * @since  Qgar 2.1
00137  */
00138 template <class T>
00139 class GenQgarPolyline
00140 
00141   : public AbstractGenQgarPrimitive<T>,
00142     public ISerializable
00143 
00144 {
00145 // -------------------------------------------------------------------
00146 // T Y P E   D E F I N I T I O N S
00147 // -------------------------------------------------------------------
00148 public:
00149 
00150   /** @name Types */
00151   //        =====
00152   //@{
00153 
00154   /**
00155    * @brief Type of the vertices coordinates.
00156    */
00157   typedef T value_type;
00158 
00159   /**
00160    * @brief Reference to qgar::GenQgarPolyline::value_type.
00161    */
00162   typedef value_type& reference;
00163 
00164   /**
00165    * @brief Constant reference to qgar::GenQgarPolyline::value_type.
00166    */
00167   typedef const value_type& const_reference;
00168 
00169   /**
00170    * @brief Pointer to qgar::GenQgarPolyline::value_type.
00171    */
00172   typedef value_type* pointer;
00173 
00174   /**
00175    * @brief Constant pointer to qgar::GenQgarPolyline::value_type.
00176    */
00177   typedef const value_type* const_pointer;
00178 
00179   /**
00180    * @brief Type of the vertices container.
00181    */
00182   typedef std::deque< GenPoint<value_type> > vertices_type;
00183 
00184   /**
00185    * @brief Reference to qgar::GenQgarPolyline::vertices_type.
00186    */
00187   typedef vertices_type& vertices_reference;
00188 
00189   /**
00190    * @brief Constant reference to qgar::GenQgarPolyline::vertices_type.
00191    */
00192   typedef const vertices_type& vertices_const_reference;
00193 
00194   //@}
00195 
00196 
00197 // -------------------------------------------------------------------
00198 // P U B L I C    M E M B E R S
00199 // -------------------------------------------------------------------
00200 public:
00201 
00202   /** @name Constructors */
00203   //        ============
00204   //@{
00205 
00206   /**
00207    * @brief Default constructor: The series of vertices is empty.
00208    *
00209    * @param aThickness  thickness (default <b>1</b>)
00210    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00211    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00212    *
00213    * @todo The created polyline does not conform to the definition
00214    *   of a polyline: The vertices deque is empty whereas it should
00215    *   contain at least 2 elements!
00216    */
00217   GenQgarPolyline(int        aThickness = 1,
00218                   QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00219                   QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00220 
00221   /**
00222    * @brief Copy constructor.
00223    *
00224    * @param aQPoly  a Qgar polyline
00225    */
00226   GenQgarPolyline(const GenQgarPolyline<value_type>& aQPoly);
00227 
00228   /**
00229    * @brief Initialize from a geometrical polyline.
00230    *
00231    * @param aPoly       a (geometrical) polyline
00232    * @param aThickness  thickness (default <b>1</b>)
00233    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00234    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00235    *
00236    * @warning This kind of conversion must be explicitely
00237    *   specified by the client.
00238    */
00239   explicit GenQgarPolyline(const GenPolyline<value_type>& aPoly,
00240                            int        aThickness = 1,
00241                            QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00242                            QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00243 
00244   /**
00245    * @brief Initialize from a Qgar segment.
00246    *
00247    * The created polyline has the same thickness, color and outline
00248    * as the given Qgar segment.
00249    *
00250    * @param aQSeg  a Qgar segment
00251    *
00252    * @warning This kind of conversion must be explicitely
00253    *   specified by the client.
00254    */
00255   explicit GenQgarPolyline(const GenQgarSegment<value_type>& aQSeg);
00256 
00257   /**
00258    * @brief Initialize from a (geometrical) segment.
00259    *
00260    * @param aSeg        a (geometrical) segment
00261    * @param aThickness  thickness (default <b>1</b>)
00262    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00263    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00264    *
00265    * @warning This kind of conversion must be explicitely
00266    *   specified by the client.
00267    */
00268   explicit GenQgarPolyline(const GenSegment<value_type>& aSeg,
00269                            int        aThickness = 1,
00270                            QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00271                            QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00272 
00273   /**
00274    * @brief Initialize from 2 vertices: source and target.
00275    *
00276    * @param aSource     source vertex 
00277    * @param aTarget     target vertex
00278    * @param aThickness  thickness (default <b>1</b>)
00279    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00280    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00281    */
00282   GenQgarPolyline(const GenPoint<value_type>& aSource,
00283                   const GenPoint<value_type>& aTarget,
00284                   int        aThickness = 1,
00285                   QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00286                   QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00287 
00288   /**
00289    * @brief Initialize from a <b>list</b> of at least two points.
00290    *
00291    * @param aPtList     a list of at least two points
00292    * @param aThickness  thickness (default <b>1</b>)
00293    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00294    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00295    *
00296    * @warning This kind of conversion must be explicitely
00297    *   specified by the client.
00298    *
00299    * @exception qgar::QgarErrorUser
00300    * (cannot create a polyline of less than 2 vertices)
00301    */
00302   explicit GenQgarPolyline(const std::list< GenPoint<value_type> >& aPtList,
00303                            int        aThickness = 1,
00304                            QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00305                            QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00306 
00307   //@}
00308 
00309 
00310   /** @name Destructor */
00311   //        ==========
00312   //@{
00313 
00314   /**
00315    * @brief Virtual destructor.
00316    */
00317   virtual ~GenQgarPolyline();
00318 
00319   //@}
00320 
00321 
00322   /**@name Copy */
00323   //       ====
00324   //@{
00325 
00326   virtual GenQgarPolyline<value_type>* clone() const;
00327 
00328   //@}
00329 
00330 
00331   /** @name Operators */
00332   //        =========
00333   //@{
00334 
00335   /**
00336    * @brief Assignment.
00337    *
00338    * @param aQPoly  a Qgar polyline
00339    */
00340   GenQgarPolyline<value_type>&
00341   operator=(const GenQgarPolyline<value_type>& aQPoly);
00342 
00343   //@}
00344 
00345 
00346   /**@name Access to the geometrical structure */
00347   //       ===================================
00348   //@{
00349 
00350   /**
00351    * @brief Get the structure implementing
00352    *        the geometrical aspect of a Qgar polyline.
00353    */
00354   inline const GenPolyline<value_type>& accessGeomStructure() const;
00355 
00356   //@}
00357 
00358 
00359   /** @name Access to vertices */
00360   //        ==================
00361   //@{
00362 
00363   /**
00364    * @brief Get number of vertices.
00365    */
00366   inline int size() const;
00367 
00368   /**
00369    * @brief Get vertices in a <b>deque</b>.
00370    */
00371   inline vertices_const_reference accessVertices() const;
00372 
00373   /**
00374    * @brief Give non-protected access to the vertices.
00375    *
00376    * Vertices may then be directly modified using appropriate
00377    * transformation function members.
00378    */
00379   inline vertices_reference getVertices();
00380 
00381   /**
00382    * @brief Get a copy of the vertices in a <b>deque</b>.
00383    */
00384   inline vertices_type vertices() const;
00385 
00386   //@}
00387 
00388 
00389   /** @name Insert vertices */
00390   //        ===============
00391   //@{
00392 
00393   /**
00394    * @brief Add a point as new source.
00395    *
00396    * @param aPt  a point
00397    */
00398   GenQgarPolyline<value_type>&
00399   appendSource(const GenPoint<value_type>& aPt);
00400 
00401   /**
00402    * @brief Append a point as new target.
00403    *
00404    * @param aPt  a point
00405    */
00406   GenQgarPolyline<value_type>&
00407   appendTarget(const GenPoint<value_type>& aPt);
00408 
00409   /**
00410    * @brief Appends a Qgar polyline.
00411    *
00412    * @param aQPoly the Qgar polyline to be appended
00413    * @return a reference on the current polyline
00414    *
00415    * @warning The thickness, color and outline of the current
00416    *   polyline always remain unchanged.
00417    */
00418   GenQgarPolyline<value_type>&
00419   append(const GenQgarPolyline<value_type>& aQPoly);
00420 
00421   /**
00422    * @brief Appends a polyline.
00423    *
00424    * @param aPoly the polyline to be appended
00425    * @return a reference on the current polyline
00426    */
00427   GenQgarPolyline<value_type>&
00428   append(const GenPolyline<value_type>& aPoly);
00429 
00430   /**
00431    * @brief Appends a set of point to a Qgar polyline.
00432    *
00433    * The last point of the vector becomes the new polyline target.
00434    *
00435    * @param aPtVect the vector of points to be appended
00436    * @return a reference on the current polyline
00437    */
00438   GenQgarPolyline<value_type>&
00439   append(const std::vector< GenPoint<value_type> >& aPtVect);  
00440 
00441   //@}
00442 
00443 
00444   /** @name Remove vertices */
00445   //        ===============
00446   //@{
00447 
00448   /**
00449    * @brief Remove a vertex from the polyline.
00450    *
00451    * @param aPt  a point
00452    *
00453    * @warning The resulting polyline should be provided
00454    *          with at least two vertices.
00455    *
00456    * @exception qgar::QgarErrorUser
00457    * (no removal in a polyline including 2 vertices)
00458    */
00459   GenQgarPolyline<value_type>&
00460   remove(const GenPoint<value_type>& aPt);
00461 
00462   //@}
00463 
00464 
00465   /** @name Conversion of the vertices */
00466   //        ==========================
00467   //@{
00468 
00469   /**
00470    * @brief Get a <b>vector</b> of points from the series of vertices.
00471    */
00472   inline std::vector< GenPoint<value_type> > toPointVector();
00473 
00474   /**
00475    * @brief Get a <b>list</b> of (geometrical) segments from the vertices.
00476    */
00477   inline std::list< GenSegment<value_type> > toSegList();
00478 
00479   /**
00480    * @brief Get a <b>list</b> of Qgar segments from the vertices.
00481    *
00482    * The resulting segments are provided with the same thickness,
00483    * color and outline as the current polyline.
00484    */
00485   inline std::list< GenQgarSegment<value_type> > toQgarSegList();
00486 
00487   //@}
00488 
00489 
00490   /**@name Geometry: Translation */
00491   //       =====================
00492   //@{
00493 
00494   /**
00495    * @brief Translate current polyline along X and Y axis.
00496    * @param aX  X translation factor
00497    * @param aY  Y translation factor
00498    */
00499   virtual void translate(value_type aX, value_type aY);
00500 
00501   //@}
00502 
00503 
00504   /** @name Serialization/Deserialization */
00505   //        =============================
00506   //@{
00507 
00508   /**
00509    * @brief Deserializes the current polyline from an input stream.
00510    *
00511    * A serialized Qgar polyline is represented as:
00512 @verbatim
00513 QgarPolyline(<GEOMETRICAL STRUCTURE>)(<THICKNESS>)(<COLOR>)(<OUTLINE>)
00514 @endverbatim
00515    *
00516    * @param anInStream The input stream
00517    */
00518   inline virtual std::istream& read(std::istream& anInStream);
00519 
00520   /**
00521    * @brief Serializes the current polyline to an input stream.
00522    *
00523    * A serialized Qgar polyline is represented as:
00524 @verbatim
00525 QgarPolyline(<GEOMETRICAL STRUCTURE>)(<THICKNESS>)(<COLOR>)(<OUTLINE>)
00526 @endverbatim
00527    *
00528    * @param anOutStream The output stream
00529    */
00530   inline virtual std::ostream& write(std::ostream& anOutStream) const;
00531 
00532   //@}
00533 
00534 
00535 // -------------------------------------------------------------------
00536 // P R O T E C T E D    M E M B E R S
00537 // -------------------------------------------------------------------
00538 protected:
00539 
00540 
00541   /** @name Geometrical structure of a Qgar polyline */
00542   //        ========================================
00543   //@{
00544 
00545   /**
00546    * @brief Geometrical structure.
00547    */
00548   GenPolyline<value_type> _geomStructure;
00549 
00550   //@}
00551 
00552 
00553   /**@name Non-protected access to the geometrical aspect */
00554   //       ==============================================
00555   //@{
00556 
00557   /**
00558    * @brief Return the geometrical aspect.
00559    *
00560    * It may then be modified using appropriate
00561    * transformation function members.
00562    */
00563   inline AbstractGenPrimitive<value_type>& getGeomStructure();
00564 
00565   //@}
00566 
00567 
00568 // -------------------------------------------------------------------
00569 }; // class Polyline
00570 
00571 
00572 
00573 
00574 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00575 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00576 // P R E D E F I N E D    Q G A R    P O L Y L I N E    T Y P E S
00577 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00578 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00579 
00580 
00581 /** @name Qgar Polyline types */
00582 //        ===================
00583 //@{
00584 
00585 /**
00586  * @ingroup DS_PRIM_QGAR
00587  * @brief Qgar polyline with <b>integer</b> coordinates.
00588  *
00589  * @see qgar::IQgarPolyline
00590  */
00591 typedef GenQgarPolyline<int> QgarPolyline;
00592 
00593 /**
00594  * @ingroup DS_PRIM_QGAR
00595  * @brief Qgar polyline with <b>integer</b> coordinates.
00596  *
00597  * @see qgar::QgarPolyline
00598  */
00599 typedef GenQgarPolyline<int> IQgarPolyline;
00600 
00601 /**
00602  * @ingroup DS_PRIM_QGAR
00603  * @brief Qgar polyline with <b>float</b> coordinates.
00604  */
00605 typedef GenQgarPolyline<float> FQgarPolyline;
00606 
00607 /**
00608  * @ingroup DS_PRIM_QGAR
00609  * @brief Qgar polyline with <b>double</b> coordinates.
00610  */
00611 typedef GenQgarPolyline<double> DQgarPolyline;
00612 
00613 //@}
00614 
00615 
00616 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00617 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00618 
00619 
00620 } // namespace qgar 
00621 
00622 
00623 #endif /* ___QGAR_GENQGARPOLYLINE_H_INCLUDED__ */