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

_QGAR_GenQgarArc.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_GENQGARARC_H_INCLUDED__
00029 #define ___QGAR_GENQGARARC_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   _QGAR_GenQgarArc.H
00034  * @brief  Header file of class qgar::GenQgarArc.
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  17:17
00041  * @since  Qgar 2.2
00042  */
00043 
00044 // For RCS/CVS use: Do not delete
00045 /* $Id: _QGAR_GenQgarArc.H,v 1.5 2005/10/14 17:05:48 masini Exp $ */
00046 
00047 
00048 
00049 // STL
00050 #include <iosfwd>  // Avoid including classes when not necessary
00051 // QGAR
00052 #include <qgarlib/ISerializable.H>
00053 
00054 
00055 
00056 namespace qgar
00057  {
00058 
00059 
00060 /**
00061  * @class GenQgarArc _QGAR_GenQgarArc.H "qgarlib/primitives.H"
00062  * @ingroup DS_PRIM_QGAR
00063  * @brief Arc of circle, so-called <i>Qgar arc</i>,
00064  *   with coordinates of type <b>T</b>.
00065  *
00066  * <ul>
00067  *
00068  * <li>
00069 @verbatim
00070    O
00071     +---------------> X
00072     |\    |
00073     | \ <-'
00074     |  \    angle (in radians, unless specified)
00075     |   \
00076     |
00077     V
00078 
00079     Y
00080 @endverbatim
00081  * The origin of the coordinate system is at top left corner and
00082  * angles are clockwise from the X axis.
00083  * </li>
00084  *
00085  * <li>
00086 @verbatim
00087    O                                 O
00088     +----------------------> X        +----------------------> X
00089     | center                          | 
00090     |      +       +  source          |           -----
00091     |              |                  |     arc /       \
00092     |             / arc               |         |   +    v
00093     | target  +<-                     |         \        + target
00094     |                                 |          +
00095     V                                 V        source
00096 
00097     Y                                 Y
00098 @endverbatim
00099  * A Qgar arc is oriented: It is provided with a so-called
00100  * <i>source point</i> and a so-called <i>target point</i>,
00101  * which determine the part of the circle supporting the arc.
00102  *</li>
00103  *
00104  * <li>
00105  * Predefined types:
00106  * qgar::QgarArc,
00107  * qgar::IQgarArc,
00108  * qgar::FQgarArc,
00109  * qgar::DQgarArc.
00110  * </li>
00111  *
00112  * <li>
00113  * A Qgar arc is provided with attributes: thickness, color, 
00114  * and outline. When such features are useless, see class
00115  * qgar::GenArc (for geometrical arcs).
00116  * </li>
00117  *
00118  * </ul>
00119  * 
00120  *
00121  * @warning
00122  *   <b>The coherence of the data structure of a Qgar arc
00123  *   after modifications of its source and/or its target
00124  *   and/or its center is the user's responsibility!</b>
00125  *
00126  *
00127  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00128  * @date   June 20, 2003  17:35
00129  * @since  Qgar 2.1
00130  */
00131 template <class T> class GenQgarArc
00132 
00133   : public AbstractGenQgarPrimitive<T>,
00134     public ISerializable
00135 
00136 {
00137 // -------------------------------------------------------------------
00138 // T Y P E   D E F I N I T I O N S
00139 // -------------------------------------------------------------------
00140 public:
00141 
00142   /** @name Types related to Qgar arcs */
00143   //        ==========================
00144   //@{
00145 
00146   /**
00147    * @brief Type of the coordinates of the source, target and center.
00148    */
00149   typedef T value_type;
00150 
00151   /**
00152    * @brief Reference to qgar::GenQgarArc::value_type.
00153    */
00154   typedef value_type& reference;
00155 
00156   /**
00157    * @brief Constant reference to qgar::GenQgarArc::value_type.
00158    */
00159   typedef const value_type& const_reference;
00160 
00161   /**
00162    * @brief Pointer to qgar::GenQgarArc::value_type.
00163    */
00164   typedef value_type* pointer;
00165 
00166   /**
00167    * @brief Constant pointer to qgar::GenQgarArc::value_type.
00168    */
00169   typedef const value_type* const_pointer;
00170 
00171   //@}
00172 
00173 
00174 // -------------------------------------------------------------------
00175 // P U B L I C    M E M B E R S
00176 // -------------------------------------------------------------------
00177 public:
00178 
00179 
00180   /**@name Constructors */
00181   //       ============
00182   //@{
00183 
00184   /**
00185    * @brief Default constructor.
00186    *
00187    * Zero-length arc located at the origin of the coordinate system.
00188    *
00189    * @param aThickness  thickness (default <b>1</b>)
00190    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00191    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00192    *
00193    * @todo The created arc does not conform
00194    *   to the definition of an arc!
00195    */
00196   GenQgarArc(int        aThickness = 1,
00197              QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00198              QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00199 
00200   /**
00201    * @brief Copy constructor.
00202    */
00203   GenQgarArc(const GenQgarArc<value_type>& aQArc);
00204 
00205   /**
00206    * @brief Initialize from a geometrical arc.
00207    *
00208    * @param anArc      a geometrical arc
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   GenQgarArc(const GenArc<value_type>& anArc,
00214              int        aThickness = 1,
00215              QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00216              QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00217 
00218   /**
00219    * @brief Initialize from three points.
00220    *
00221    * @param aSource     source point
00222    * @param aTarget     target point
00223    * @param aCenter     center point
00224    * @param aThickness  thickness (default <b>1</b>)
00225    * @param aColor      color     (default qgar::QGE_COLOR_DEFAULT)
00226    * @param anOutline   outline   (default qgar::QGE_OUTLINE_DEFAULT) 
00227    */
00228   GenQgarArc(const GenPoint<value_type>& aSource,
00229              const GenPoint<value_type>& aTarget,
00230              const GenPoint<value_type>& aCenter,
00231              int        aThickness = 1,
00232              QGEcolor   aColor     = QGE_COLOR_DEFAULT,
00233              QGEoutline anOutline  = QGE_OUTLINE_DEFAULT);
00234 
00235   //@}
00236 
00237 
00238   /**@name Destructor */
00239   //       ==========
00240   //@{
00241 
00242   /**
00243    * @brief Virtual destructor.
00244    */
00245   virtual ~GenQgarArc();
00246 
00247   //@}
00248 
00249 
00250   /**@name Copy */
00251   //       ====
00252   //@{
00253 
00254   virtual GenQgarArc<value_type>* clone() const;
00255 
00256   //@}
00257 
00258 
00259   /** @name Access to geometrical features */
00260   //        ==============================
00261   //@{
00262 
00263   /**
00264    * @brief Get the structure implementing
00265    *        the geometrical aspect of a Qgar arc.
00266    */
00267   inline const GenArc<value_type>& accessGeomStructure() const;
00268 
00269   /**
00270    * @brief Get the radius.
00271    */
00272   inline double radius() const;
00273 
00274   /**
00275    * @brief Get length of the arc.
00276    */
00277   inline double length() const;
00278 
00279   /**
00280    * @brief Get the angle of the arc, in [0, 2PI] radians.
00281    *
00282    * Always positive.
00283    */
00284   inline double angle() const;
00285 
00286   /**
00287    * @brief Get the angle of the arc, in [0, 360] degrees.
00288    *
00289    * Always positive.
00290    */
00291   inline double angleDegrees() const;
00292 
00293   /**
00294    * @brief Get the so-called source angle.
00295    *
00296    * It is the angle between the vector joining the center to
00297    * the source point and the X axis, in [0, 2PI] radians.
00298    */
00299   inline double sourceAngle() const;
00300 
00301   /**
00302    * @brief Get the source angle, in [0, 360] degrees.
00303    */
00304   inline double sourceAngleDegrees() const;
00305 
00306   /**
00307    * @brief Get the so-called target angle.
00308    *
00309    * Its is the angle between the vector joining the center to
00310    * the target point and the X axis, in [0, 2PI] radians.
00311    */
00312   inline double targetAngle() const;
00313 
00314    /**
00315    * @brief Get the target angle, in [0, 360] degrees.
00316    */
00317   inline double targetAngleDegrees() const;
00318 
00319   //@}
00320 
00321 
00322   /** @name Center */
00323   //        ======
00324   //@{
00325 
00326   /**
00327    * @brief Get the center point.
00328    */
00329   inline const GenPoint<value_type>& accessCenter() const;
00330 
00331   /**
00332    * @brief Get a copy of the center point.
00333    */
00334   inline GenPoint<value_type> center() const;
00335 
00336   /**
00337    * @brief Get X coordinate of center point.
00338    */
00339   value_type xCenter() const;
00340 
00341   /**
00342    * @brief Get Y coordinate of center point.
00343    */
00344   value_type yCenter() const;
00345 
00346   /**
00347    * @brief Set X coordinate of the center point.
00348    *
00349    * @param aX  new X coordinate
00350    */
00351   inline void setXCenter(value_type aX);
00352 
00353   /**
00354    * @brief Set Y coordinate of the center point.
00355    *
00356    * @param aY  new Y coordinate
00357    */
00358   inline void setYCenter(value_type aY);
00359 
00360   /**
00361    * @brief Set the center point.
00362    *
00363    * @param aX  X coordinate of the new center
00364    * @param aY  Y coordinate of the new center
00365    */
00366   void setCenter(value_type aX, value_type aY);
00367 
00368   /**
00369    * @brief Set the center point.
00370    *
00371    * @param aCenter  point representing the new center
00372    */
00373   void setCenter(const GenPoint<value_type>& aCenter);
00374 
00375   //@}
00376 
00377 
00378   /** @name Operators */
00379   //        =========
00380   //@{
00381 
00382   /**
00383    * @brief Assignment.
00384    *
00385    * @param aQArc  a Qgar arc
00386    */
00387   GenQgarArc<value_type>&
00388   operator=(const GenQgarArc<value_type>& aQArc);
00389 
00390   /**
00391    * @brief Same as function qgar::GenQgarArc::eq
00392    */
00393   inline bool
00394   operator==(const GenQgarArc<value_type>& aQArc) const;
00395 
00396   /**
00397    * @brief Same as function qgar::GenQgarArc::notEq.
00398    */
00399   inline bool
00400   operator!=(const GenQgarArc<value_type>& aQArc) const;
00401 
00402   //@}
00403 
00404 
00405   /**@name Functional operators */
00406   //       ====================
00407   //@{
00408 
00409   /**
00410    * @brief Equality.
00411    *
00412    * @param aQArc  a Qgar arc
00413    *
00414    * @return <b>true</b> if the current arc
00415    * and the given arc have the same coordinates,
00416    * regardless other features.
00417    */
00418   inline bool eq(const GenQgarArc<value_type>& aQArc) const;
00419 
00420    /**
00421    * @brief Equality.
00422    *
00423    * @param aQArc  a Qgar arc
00424    *
00425    * @return <b>true</b> if the current arc
00426    * and the given arc have the same coordinates and attributes.
00427    */
00428   bool equal(const GenQgarArc<value_type>& aQArc) const;
00429 
00430   /**
00431    * @brief Inequality.
00432    *
00433    * @param aQArc a Qgar arc
00434    *
00435    * @return <b>true</b> if the coordinates
00436    * of the current arc and of the given arc are different,
00437    * regardless other features.
00438    */
00439   inline bool notEq(const GenQgarArc<value_type>& aQArc) const;
00440 
00441   /**
00442    * @brief Inequality.
00443    *
00444    * @param aQArc a Qgar arc
00445    *
00446    * @return <b>true</b> if the coordinates or attributes
00447    * of the current arc and of the given arc are different.
00448    */
00449   bool notEqual(const GenQgarArc<value_type>& aQArc) const;
00450 
00451   //@}
00452 
00453 
00454   /** @name Serialization/deserialization */
00455   //        =============================
00456   //@{
00457 
00458   /**
00459    * @brief Deserializes the current arc from an input stream.
00460    *
00461    * A serialized Qgar arc is represented as:
00462 @verbatim
00463 QgarArc(<GEOMETRICAL STRUCTURE>)(<THICKNESS>)(<COLOR>)(<OUTLINE>)
00464 @endverbatim
00465    *
00466    * @param anInStream The input stream
00467    */
00468   virtual std::istream& read(std::istream& anInStream);
00469 
00470 
00471   /**
00472    * @brief Serializes the current arc to an input stream.
00473    *
00474    * A serialized Qgar arc is represented as:
00475 @verbatim
00476 QgarArc(<GEOMETRICAL STRUCTURE>)(<THICKNESS>)(<COLOR>)(<OUTLINE>)
00477 @endverbatim
00478    *
00479    * @param anOutStream The output stream
00480    */
00481   virtual std::ostream& write(std::ostream& anOutStream) const;
00482 
00483   //@}
00484 
00485 
00486 // -------------------------------------------------------------------
00487 // P R O T E C T E D    M E M B E R S
00488 // -------------------------------------------------------------------
00489 protected:
00490 
00491 
00492   /** @name Geometrical structure of a Qgar arc */
00493   //        ===================================
00494   //@{
00495 
00496   /**
00497    * @brief Geometrical structure.
00498    */
00499   GenArc<value_type> _geomStructure;
00500 
00501   //@}
00502 
00503 
00504   /**@name Non-protected access to the geometrical aspect */
00505   //       ==============================================
00506   //@{
00507 
00508   /**
00509    * @brief Return the geometrical aspect.
00510    *
00511    * It may then be modified using appropriate
00512    * transformation function members.
00513    */
00514   virtual AbstractGenPrimitive<value_type>& getGeomStructure();
00515 
00516   //@}
00517 
00518 
00519 // -------------------------------------------------------------------
00520 }; // class GenQgarArc
00521 
00522 
00523 
00524 
00525 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00526 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00527 // P R E D E F I N E D    Q G A R    A R C    T Y P E S
00528 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00529 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00530 
00531 
00532 /** 
00533  * @name Qgar Arcs
00534  * @ingroup DS_PRIM_QGAR
00535  */
00536 //@{
00537 
00538 /**
00539  * @brief Qgar arc with <b>integer</b> coordinates.
00540  *
00541  * @see qgar::IQgarArc
00542  */
00543 typedef GenQgarArc<int> QgarArc;
00544 
00545 /**
00546  * @brief Qgar arc with <b>integer</b> coordinates.
00547  *
00548  * @see qgar::QgarArc
00549  */
00550 typedef GenQgarArc<int> IQgarArc;
00551 
00552 /**
00553  * @brief Qgar arc with <b>float</b> coordinates.
00554  */
00555 typedef GenQgarArc<float> FQgarArc;
00556 
00557 /**
00558  * @brief Qgar arc with <b>double</b> coordinates.
00559  */
00560 typedef GenQgarArc<double> DQgarArc;
00561 
00562 //@}
00563 
00564 
00565 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00566 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00567 
00568 
00569 } // namespace qgar
00570 
00571 
00572 #endif /* ___QGAR_GENQGARARC_H_INCLUDED__ */