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

_QGAR_GenArc.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_GENARC_H_INCLUDED__
00029 #define ___QGAR_GENARC_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   _QGAR_GenArc.H
00034  * @brief  Header file of class qgar::GenArc.
00035  *
00036  * @warning <b>Not to be used as include file!</b>
00037  * <br>When working with primitives, use header 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    January 28, 20045  15:51
00041  * @since   Qgar 2.2
00042  */
00043 
00044 
00045 // For RCS/CVS use: Do not delete
00046 /* $Id: _QGAR_GenArc.H,v 1.5 2005/10/14 17:05:48 masini Exp $ */
00047 
00048 
00049 
00050 // STD
00051 #include <iosfwd>  // Avoid including classes when not necessary
00052 // QGAR
00053 #include <qgarlib/ISerializable.H>
00054 
00055 
00056 
00057 namespace qgar
00058 {
00059 
00060 
00061 /**
00062  * @class GenArc _QGAR_GenArc.H "qgarlib/primitives.H"
00063  * @ingroup DS_PRIM_GEOM
00064  * @brief Arc of circle, 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  * An arc is oriented: It is provided with a so-called <i>source point</i>
00100  * and a so-called <i>target point</i>, which determine the part of the
00101  * circle supporting the arc.
00102  *</li>
00103  *
00104  * <li>
00105  * Predefined types:
00106  * - qgar::Arc
00107  * - qgar::IArc
00108  * - qgar::FArc
00109  * - qgar::DArc
00110  * </li>
00111  *
00112  * <li>
00113  * An arc has no attribute. For <i>graphical</i> arcs, typically
00114  * resulting from vectorization and provided with attributes
00115  * (thickness, color, outline), see class qgar::GenQgarArc.
00116  * </li>
00117  *
00118  * </ul>
00119  *
00120  *
00121  * @warning
00122  *   <b>The coherence of the data structure of an arc after
00123  *   modifications of its source and/or its target and/or its
00124  *   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  19:23
00129  * @since  Qgar 2.1
00130  */
00131 template <class T> class GenArc
00132 
00133   : public AbstractGenPrimitive<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 
00143   /** @name Types */
00144   //        =====
00145   //@{
00146 
00147   /**
00148    * @brief Type of the coordinates of the source, target and center.
00149    */
00150   typedef T value_type;
00151 
00152   /**
00153    * @brief Reference to qgar::GenArc::value_type.
00154    */
00155   typedef value_type& reference;
00156 
00157   /**
00158    * @brief Constant reference to qgar::GenArc::value_type.
00159    */
00160   typedef const value_type& const_reference;
00161 
00162   /**
00163    * @brief Pointer to qgar::GenArc::value_type.
00164    */
00165   typedef value_type* pointer;
00166 
00167   /**
00168    * @brief Constant pointer to qgar::GenArc::value_type.
00169    */
00170   typedef const value_type* const_pointer;
00171 
00172   //@}
00173 
00174 
00175 // -------------------------------------------------------------------
00176 // P U B L I C    M E M B E R S
00177 // -------------------------------------------------------------------
00178 public:
00179 
00180 
00181   /**@name Constructors */
00182   //       ============
00183   //@{
00184 
00185   /**
00186    * @brief Default constructor.
00187    *
00188    * Zero-length arc located at the origin of the coordinate system.
00189    *
00190    * @todo Such an arc does not conform the definition of an arc!
00191    */
00192   GenArc();
00193 
00194   /**
00195    * @brief Copy constructor.
00196    */
00197   GenArc(const GenArc<value_type>& anArc);
00198 
00199   /**
00200    * @brief Initialize from a Qgar arc.
00201    *
00202    * @param aQArc  a Qgar arc
00203    *
00204    * @warning This kind of conversion must be explicitely
00205    *   specified by the client.
00206    */
00207   explicit GenArc(const GenQgarArc<value_type>& aQArc);
00208 
00209   /**
00210    * @brief Initialize from three points.
00211    *
00212    * @param aSource     source point
00213    * @param aTarget     target point
00214    * @param aCenter     center point
00215    */
00216   GenArc(const GenPoint<value_type>& aSource,
00217          const GenPoint<value_type>& aTarget,
00218          const GenPoint<value_type>& aCenter);
00219 
00220   //@}
00221   
00222   
00223   /**@name Destructor */
00224   //       ==========
00225   //@{
00226 
00227   /**
00228    * @brief Virtual destructor.
00229    */
00230   virtual ~GenArc();
00231 
00232   //@}
00233 
00234 
00235   /**@name Copy */
00236   //       ====
00237   //@{
00238 
00239   /**
00240    * @brief Return a deep copy of the current arc.
00241    */  
00242   virtual GenArc<value_type>* clone() const;
00243 
00244   //@}  
00245   
00246 
00247   /** @name Access to geometrical features */
00248   //        ==============================
00249   //@{
00250 
00251   /**
00252    * @brief Get radius.
00253    */
00254   inline double radius() const;
00255 
00256   /**
00257    * @brief Get arc length.
00258    */
00259   double length() const;
00260 
00261   /**
00262    * @brief Get arc angle, in [0, 2PI] radians.
00263    *
00264    * Always positive.
00265    */
00266   double angle() const;
00267 
00268   /**
00269    * @brief Get arc angle, in [0, 360] degrees.
00270    *
00271    * Always positive.
00272    */
00273   inline double angleDegrees() const;
00274 
00275   /**
00276    * @brief Get the so-called source angle.
00277    *
00278    * It is the angle between the vector joining the center to
00279    * the source point and the X axis, in <b>[0, 2PI]</b> radians.
00280    */
00281   inline double sourceAngle() const;
00282 
00283   /**
00284    * @brief Get the source angle, in <b>[0, 360]</b> degrees.
00285    */
00286   inline double sourceAngleDegrees() const;
00287 
00288   /**
00289    * @brief Get the so-called target angle.
00290    *
00291    * It is the angle between the vector joining the center to
00292    * the target point and the X axis, in <b>[0, 2PI]</b> radians.
00293    */
00294   inline double targetAngle() const;
00295 
00296    /**
00297    * @brief Get the target angle, in <b>[0, 360]</b> degrees.
00298    */
00299   inline double targetAngleDegrees() const;
00300 
00301   //@}
00302 
00303 
00304   /** @name Center */
00305   //        ======
00306   //@{
00307 
00308   /**
00309    * @brief Get the center point.
00310    */
00311   inline const GenPoint<value_type>& accessCenter() const;
00312 
00313   /**
00314    * @brief Get a copy of the center point.
00315    */
00316   inline GenPoint<value_type> center() const;
00317 
00318   /**
00319    * @brief Get X coordinate of center point.
00320    */
00321   inline value_type xCenter() const;
00322 
00323   /**
00324    * @brief Get Y coordinate of center point.
00325    */
00326   inline value_type yCenter() const;
00327 
00328   /**
00329    * @brief Set X coordinate of the center point.
00330    *
00331    * @param aX  new X coordinate
00332    */
00333   inline void setXCenter(value_type aX);
00334 
00335   /**
00336    * @brief Set Y coordinate of the center point.
00337    *
00338    * @param aY  new Y coordinate
00339    */
00340   inline void setYCenter(value_type aY);
00341 
00342   /**
00343    * @brief Set the center point.
00344    *
00345    * @param aX  X coordinate of the new center
00346    * @param aY  Y coordinate of the new center
00347    */
00348   inline void setCenter(value_type aX, value_type aY);
00349 
00350   /**
00351    * @brief Set the center point.
00352    *
00353    * @param aCenter  point representing the new center
00354    */
00355   inline void setCenter(const GenPoint<value_type>& aCenter);
00356 
00357   //@}
00358 
00359 
00360   /** @name Operators */
00361   //        =========
00362   //@{
00363 
00364   /**
00365    * @brief Assignment.
00366    *
00367    * @param anArc  an arc
00368    */
00369   GenArc<value_type>& operator=(const GenArc<value_type>& anArc);
00370 
00371   /**
00372    * @brief Same as function qgar::GenArc::eq
00373    */
00374   inline bool operator==(const GenArc<value_type>& anArc) const;
00375 
00376   /**
00377    * @brief Same as function qgar::GenArc::notEq.
00378    */
00379   inline bool operator!=(const GenArc<value_type>& anArc) const;
00380 
00381   //@}
00382   
00383   
00384   /**@name Functional operators */
00385   //       ====================
00386   //@{
00387 
00388    /**
00389    * @brief Equality.
00390    *
00391    * Return <b>true</b> if the current arc
00392    * and the given arc have the same coordinates.
00393    *
00394    * @param anArc  an arc
00395    */
00396   bool eq(const GenArc<value_type>& anArc) const;
00397 
00398   /**
00399    * @brief Inequality.
00400    *
00401    * Return <b>true</b> if the coordinates of the current
00402    * and given arcs are different.
00403    *
00404    * @param anArc an arc
00405    */
00406   bool notEq(const GenArc<value_type>& anArc) const;
00407 
00408   //@}
00409 
00410 
00411   /**@name Geometry: Translation */
00412   //       =====================
00413   //@{
00414 
00415   /**
00416    * @brief Translate current arc along X and Y axis.
00417    *
00418    * @param aTransX  X translation factor
00419    * @param aTransY  Y translation factor
00420    */
00421   virtual void translate(value_type aTransX, value_type aTransY);
00422 
00423   //@}
00424 
00425 
00426   /** @name Serialization/deserialization */
00427   //        =============================
00428   //@{
00429 
00430   /**
00431    * @brief Deserializes the current arc from an input stream.
00432    *
00433    * A serialized arc is represented as:
00434 @verbatim
00435 Arc(<SOURCE>)(<TARGET>)(<CENTER>)
00436 @endverbatim
00437    *
00438    * @param anInStream The input stream
00439    */
00440   virtual std::istream& read(std::istream& anInStream);
00441 
00442   /**
00443    * @brief Serializes the current arc to an input stream.
00444    *
00445    * A serialized arc is represented as:
00446 @verbatim
00447 Arc(<SOURCE>)(<TARGET>)(<CENTER>)
00448 @endverbatim
00449    *
00450    * @param anOutStream The output stream
00451    */
00452   virtual std::ostream& write(std::ostream& anOutStream) const;
00453 
00454   //@}
00455 
00456 
00457 // -------------------------------------------------------------------
00458 // P R O T E C T E D    M E M B E R S
00459 // -------------------------------------------------------------------
00460 protected:
00461 
00462 
00463   /** @name Structure of an arc */
00464   //        ===================
00465   //@{
00466 
00467   /**
00468    * @brief Center of the circle supporting the arc.
00469    */
00470   GenPoint<value_type> _center;
00471 
00472   //@}
00473 
00474 
00475   /** @name Implementation of pure virtual functions */
00476   //        ========================================
00477   //@{
00478 
00479   /**
00480    * @brief Update the geometrical structure
00481    *   when the source has been changed.
00482    *
00483    * Inherited from qgar::AbstractGenPrimitive.
00484    */
00485   virtual void updateSource();
00486 
00487   /**
00488    * @brief Update the geometrical structure
00489    *   when the target has been changed.
00490    *
00491    * Inherited from qgar::AbstractGenPrimitive.
00492    */
00493   virtual void updateTarget();
00494 
00495   /**
00496    * @brief Update the geometrical structure
00497    *   when both source and target have been changed.
00498    *
00499    * Inherited from qgar::AbstractGenPrimitive.
00500    */
00501   virtual void updateSourceTarget();
00502 
00503   //@}
00504 
00505 
00506 // -------------------------------------------------------------------
00507 }; // class GenArc
00508 
00509 
00510 
00511 
00512 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00513 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00514 // P R E D E F I N E D    A R C    T Y P E S
00515 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00516 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00517 
00518 
00519 /** @name Arc types */
00520 //        =========
00521 //@{
00522 
00523 /**
00524  * @brief Arc with <b>integer</b> coordinates.
00525  * @ingroup DS_PRIM_GEOM
00526  *
00527  * @see qgar::IArc
00528  */
00529 typedef GenArc<int> Arc;
00530 
00531 /**
00532  * @brief Arc with <b>integer</b> coordinates.
00533  * @ingroup DS_PRIM_GEOM
00534  *
00535  * @see qgar::Arc
00536  */
00537 typedef GenArc<int> IArc;
00538 
00539 /**
00540  * @brief Arc with <b>float</b> coordinates.
00541  * @ingroup DS_PRIM_GEOM
00542  */
00543 typedef GenArc<float> FArc;
00544 
00545 /**
00546  * @brief Arc with <b>double</b> coordinates.
00547  * @ingroup DS_PRIM_GEOM
00548  */
00549 typedef GenArc<double> DArc;
00550 
00551 //@}
00552 
00553 
00554 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00555 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00556 
00557 
00558 } // namespace qgar
00559 
00560 
00561 #endif /* ___QGAR_GENARC_H_INCLUDED__ */