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_ABSTRACTGENQGARPRIMITIVE_H_INCLUDED__ 00029 #define ___QGAR_ABSTRACTGENQGARPRIMITIVE_H_INCLUDED__ 00030 00031 00032 /** 00033 * @file _QGAR_AbstractGenQgarPrimitive.H 00034 * @brief Header file of class qgar::AbstractGenQgarPrimitive. 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 December 14, 2004 15:15 00041 * @since Qgar 2.2 00042 */ 00043 00044 00045 // For RCS/CVS use: Do not delete 00046 /* $Id: _QGAR_AbstractGenQgarPrimitive.H,v 1.3 2005/07/13 16:29:02 masini Exp $ */ 00047 00048 00049 00050 namespace qgar 00051 { 00052 00053 00054 /** 00055 * @class AbstractGenQgarPrimitive _QGAR_AbstractGenQgarPrimitive.H "qgarlib/primitives.H" 00056 * @ingroup DS_PRIM_QGAR 00057 * @brief Graphical primitives, typically resulting from vectorization, 00058 * with coordinates of type <b>T</b>. 00059 * 00060 * Such a primitive is provided with: 00061 * <ul> 00062 * <li>Attributes: color, thickness, and outline.</li> 00063 * <li>A geometrical primitive as implementation, to be defined 00064 * in derived classes: Functions giving access to this implementation, 00065 * qgar::accessGeomStructure and qgar::geomStructure, are pure virtual.</li> 00066 * <li>A so-called source point (head) and 00067 * a so-called target point (tail), that are the source and target 00068 * points of the geometrical primitive.</li> 00069 * </ul> 00070 * 00071 * Predefined types: 00072 * qgar::QgarPrimitive, 00073 * qgar::IQgarPrimitive, 00074 * qgar::FQgarPrimitive, 00075 * qgar::DQgarPrimitive. 00076 * 00077 * @warning 00078 * <ul> 00079 * <li> 00080 * This is an abstract class: It cannot be instantiated. 00081 * Pure virtual functions are 00082 * qgar::AbstractGenQgarPrimitive::accessGeomStructure, 00083 * qgar::AbstractGenQgarPrimitive::getGeomStructure, 00084 * qgar::AbstractGenQgarPrimitive::clone. 00085 * </li> 00086 * <li> 00087 * When the coordinates of its source and/or target are modified using 00088 * specified functions, the complete data structure of a primitive is 00089 * supposed to be subsequently updated. 00090 * See class qgar::AbstractGenPrimitive. 00091 * </li> 00092 * </ul> 00093 * 00094 * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a> 00095 * @date June 20, 2003 15:15 00096 * @since Qgar 2.1 00097 */ 00098 template <class T> class AbstractGenQgarPrimitive 00099 { 00100 // ------------------------------------------------------------------- 00101 // T Y P E D E F I N I T I O N S 00102 // ------------------------------------------------------------------- 00103 public: 00104 00105 00106 /** @name Types */ 00107 // ===== 00108 //@{ 00109 00110 /** 00111 * @brief Type of a point of a primitive. 00112 */ 00113 typedef T value_type; 00114 00115 /** 00116 * @brief Reference to qgar::AbstractGenQgarPrimitive::value_type. 00117 */ 00118 typedef value_type& reference; 00119 00120 /** 00121 * @brief Constant reference to qgar::AbstractGenQgarPrimitive::value_type. 00122 */ 00123 typedef const value_type& const_reference; 00124 00125 /** 00126 * @brief Pointer to qgar::AbstractGenQgarPrimitive::value_type. 00127 */ 00128 typedef value_type* pointer; 00129 00130 /** 00131 * @brief Constant pointer to qgar::AbstractGenQgarPrimitive::value_type. 00132 */ 00133 typedef const value_type* const_pointer; 00134 00135 //@} 00136 00137 00138 // ------------------------------------------------------------------- 00139 // P U B L I C M E M B E R S 00140 // ------------------------------------------------------------------- 00141 public: 00142 00143 00144 /** @name Constructors */ 00145 // ============ 00146 //@{ 00147 00148 /** 00149 * @brief Default constructor. 00150 * 00151 * @param aThickness thickness (default <b>1</b>) 00152 * @param aColor color (default qgar::QGE_COLOR_BLACK) 00153 * @param anOutline outline (default qgar::QGE_OUTLINE_SOLID) 00154 */ 00155 AbstractGenQgarPrimitive(int aThickness = 1, 00156 QGEcolor aColor = QGE_COLOR_BLACK, 00157 QGEoutline anOutline = QGE_OUTLINE_SOLID); 00158 00159 /** 00160 * @brief Copy constructor. 00161 * 00162 * @param aQPrim Qgar primitive to be copied 00163 */ 00164 AbstractGenQgarPrimitive(const AbstractGenQgarPrimitive<T>& aQPrim); 00165 00166 //@} 00167 00168 00169 /**@name Destructor */ 00170 // ========== 00171 //@{ 00172 00173 /** 00174 * @brief Virtual destructor. 00175 */ 00176 virtual ~AbstractGenQgarPrimitive(); 00177 00178 //@} 00179 00180 00181 /**@name Copy */ 00182 // ==== 00183 //@{ 00184 /** 00185 * @brief Create a dynamically allocated deep copy of the 00186 * primitive. 00187 */ 00188 virtual AbstractGenQgarPrimitive<value_type>* clone() const = 0; 00189 //@} 00190 00191 00192 /**@name Geometrical aspect */ 00193 // ================== 00194 //@{ 00195 /** 00196 00197 * @brief Get the structure implementing 00198 * the geometrical aspect of the primitive. 00199 */ 00200 virtual const AbstractGenPrimitive<value_type>& 00201 accessGeomStructure() const = 0; 00202 00203 //@} 00204 00205 00206 /**@name Access to attributes */ 00207 // ==================== 00208 //@{ 00209 00210 /** 00211 * @brief Get thickness. 00212 */ 00213 inline int thickness() const; 00214 00215 /** 00216 * @brief Get color. 00217 */ 00218 inline QGEcolor color() const; 00219 00220 /** 00221 * @brief Get outline. 00222 */ 00223 inline QGEoutline outline() const; 00224 00225 //@} 00226 00227 00228 /**@name Access to source and target */ 00229 // =========================== 00230 //@{ 00231 00232 /** 00233 * @brief Get source point. 00234 */ 00235 inline const GenPoint<value_type>& accessSource() const; 00236 00237 /** 00238 * @brief Get a copy of the source point. 00239 */ 00240 inline GenPoint<value_type> source() const; 00241 00242 /** 00243 * @brief Get target point. 00244 */ 00245 inline const GenPoint<value_type>& accessTarget() const; 00246 00247 /** 00248 * @brief Get a copy of the target point. 00249 */ 00250 inline GenPoint<value_type> target() const; 00251 00252 //@} 00253 00254 00255 /**@name Access to separate coordinates */ 00256 // ============================== 00257 //@{ 00258 00259 /** 00260 * @brief Get X coordinate of the source point. 00261 */ 00262 inline value_type xSource() const; 00263 00264 /** 00265 * @brief Get X coordinate of the target point. 00266 */ 00267 inline value_type xTarget() const; 00268 00269 /** 00270 * @brief Get Y coordinate of the source point. 00271 */ 00272 inline value_type ySource() const; 00273 00274 /** 00275 * @brief Get Y coordinate of the target point. 00276 */ 00277 inline value_type yTarget() const; 00278 00279 //@} 00280 00281 00282 /** @name Access to geometrical characteristics */ 00283 // ===================================== 00284 //@{ 00285 00286 /** 00287 * @brief Difference between target and source X coordinates. 00288 */ 00289 inline value_type dx() const; 00290 00291 /** 00292 * @brief Difference between target and source Y coordinates. 00293 */ 00294 inline value_type dy() const; 00295 00296 //@} 00297 00298 00299 /**@name Set attributes */ 00300 // ============== 00301 //@{ 00302 00303 /** 00304 * @brief Set thickness. 00305 * 00306 * @param aThickness a thickness 00307 */ 00308 inline void setThickness(int aThickness); 00309 00310 /** 00311 * @brief Set color. 00312 * 00313 * @param aColor a color 00314 */ 00315 inline void setColor(QGEcolor aColor); 00316 00317 /** 00318 * @brief Set outline. 00319 * 00320 * @param anOutline an outline 00321 */ 00322 inline void setOutline(QGEoutline anOutline); 00323 00324 //@} 00325 00326 00327 /**@name Set source and/or target without update */ 00328 // ======================================= 00329 //@{ 00330 00331 /** 00332 * @brief Set source point. 00333 * 00334 * @param aX new X coordinate of the source point 00335 * @param aY new Y coordinate of the source point 00336 * 00337 * @warning <b>The data structure of the primitive 00338 * is not subsequently updated</b>. 00339 */ 00340 inline void setSource(value_type aX, value_type aY); 00341 00342 /** 00343 * @brief Set source point. 00344 * 00345 * @param aPt a point 00346 * 00347 * @warning <b>The data structure of the primitive 00348 * is not subsequently updated</b>. 00349 */ 00350 inline void setSource(const GenPoint<value_type>& aPt); 00351 00352 /** 00353 * @brief Set target point. 00354 * 00355 * @param aX new X coordinate of the target point 00356 * @param aY new Y coordinate of the target point 00357 * 00358 * @warning <b>The data structure of the primitive 00359 * is not subsequently updated</b>. 00360 */ 00361 inline void setTarget(value_type aX, value_type aY); 00362 00363 /** 00364 * @brief Set target point. 00365 * 00366 * @param aPt a point 00367 * 00368 * @warning <b>The data structure of the primitive 00369 * is not subsequently updated</b>. 00370 */ 00371 inline void setTarget(const GenPoint<value_type>& aPt); 00372 00373 /** 00374 * @brief Set both source and target points. 00375 * 00376 * @param aXSource new X coordinate of the source point 00377 * @param aYSource new Y coordinate of the source point 00378 * @param aXTarget new X coordinate of the target point 00379 * @param aYTarget new Y coordinate of the target point 00380 * 00381 * @warning <b>The data structure of the primitive 00382 * is not subsequently updated</b>. 00383 */ 00384 inline void setSourceTarget(value_type aXSource, 00385 value_type aYSource, 00386 value_type aXTarget, 00387 value_type aYTarget); 00388 00389 /** 00390 * @brief Set both source and target points. 00391 * 00392 * @param aSource source point 00393 * @param aTarget target point 00394 * 00395 * @warning <b>The data structure of the primitive 00396 * is not subsequently updated</b>. 00397 */ 00398 inline void setSourceTarget(const GenPoint<value_type>& aSource, 00399 const GenPoint<value_type>& aTarget); 00400 00401 //@} 00402 00403 00404 /**@name Set source and/or target with update */ 00405 // ==================================== 00406 //@{ 00407 00408 /** 00409 * @brief Set source point. 00410 * 00411 * @param aX new X coordinate of the source point 00412 * @param aY new Y coordinate of the source point 00413 * 00414 * @warning <b>Function qgar::AbstractGenPrimitive::updateSource 00415 * is called after the modification of the source point.</b> 00416 */ 00417 inline void fixSource(value_type aX, value_type aY); 00418 00419 /** 00420 * @brief Set source point. 00421 * 00422 * @param aPt a point 00423 * 00424 * @warning <b>Function qgar::AbstractGenPrimitive::updateSource 00425 * is called after the modification of the source point.</b> 00426 */ 00427 inline void fixSource(const GenPoint<value_type>& aPt); 00428 00429 /** 00430 * @brief Set target point. 00431 * 00432 * @param aX new X coordinate of the target point 00433 * @param aY new Y coordinate of the target point 00434 * 00435 * @warning <b>Function qgar::AbstractGenPrimitive::updateTarget 00436 * is called after the modification of the target point.</b> 00437 */ 00438 inline void fixTarget(value_type aX, value_type aY); 00439 00440 /** 00441 * @brief Set target point. 00442 * 00443 * @param aPt a point 00444 * 00445 * @warning <b>Function qgar::AbstractGenPrimitive::updateTarget 00446 * is called after the modification of the target point.</b> 00447 */ 00448 inline void fixTarget(const GenPoint<value_type>& aPt); 00449 00450 /** 00451 * @brief Set both source and target points. 00452 * 00453 * @param aXSource new X coordinate of the source point 00454 * @param aYSource new Y coordinate of the source point 00455 * @param aXTarget new X coordinate of the target point 00456 * @param aYTarget new Y coordinate of the target point 00457 * 00458 * @warning <b>Function qgar::AbstractGenPrimitive::updateTarget 00459 * is called after the modification of the source target.</b> 00460 */ 00461 inline void fixSourceTarget(value_type aXSource, 00462 value_type aYSource, 00463 value_type aXTarget, 00464 value_type aYTarget); 00465 00466 /** 00467 * @brief Set both source and target points. 00468 * 00469 * @param aSource source point 00470 * @param aTarget target point 00471 * 00472 * @warning <b>Function qgar::AbstractGenPrimitive::updateTarget 00473 * is called after the modification of the source target.</b> 00474 */ 00475 inline void fixSourceTarget(const GenPoint<value_type>& aSource, 00476 const GenPoint<value_type>& aTarget); 00477 00478 //@} 00479 00480 00481 /**@name Set separate (source and target) coordinates without update */ 00482 // =========================================================== 00483 //@{ 00484 00485 /** 00486 * @brief Set X coordinate of the source point. 00487 * 00488 * @param aX new X coordinate of the source point 00489 * 00490 * @warning <b>The data structure of the primitive 00491 * is not subsequently updated</b>. 00492 */ 00493 inline void setXSource(value_type aX); 00494 00495 /** 00496 * @brief Set X coordinate of the target point. 00497 * 00498 * @param aX new X coordinate of the target point 00499 * 00500 * @warning <b>The data structure of the primitive 00501 * is not subsequently updated</b>. 00502 */ 00503 inline void setXTarget(value_type aX); 00504 00505 /** 00506 * @brief Set Y coordinate of the source point. 00507 * 00508 * @param aY new Y coordinate of the source point 00509 * 00510 * @warning <b>The data structure of the primitive 00511 * is not subsequently updated</b>. 00512 */ 00513 inline void setYSource(value_type aY); 00514 00515 /** 00516 * @brief Set Y coordinate of the target point. 00517 * 00518 * @param aY new Y coordinate of the target point 00519 * 00520 * @warning <b>The data structure of the primitive 00521 * is not subsequently updated</b>. 00522 */ 00523 inline void setYTarget(value_type aY); 00524 00525 //@} 00526 00527 00528 /**@name Set separate (source and target) coordinates with update */ 00529 // ======================================================== 00530 //@{ 00531 00532 /** 00533 * @brief Set X coordinate of the source point. 00534 * 00535 * @param aX new X coordinate of the source point 00536 * 00537 * @warning <b>Function qgar::AbstractGenPrimitive::updateSource 00538 * is called after the modification of the source point.</b> 00539 */ 00540 void fixXSource(value_type aX); 00541 00542 /** 00543 * @brief Set X coordinate of the target point. 00544 * 00545 * @param aX new X coordinate of the target point 00546 * 00547 * @warning <b>Function qgar::AbstractGenPrimitive::updateTarget 00548 * is called after the modification of the target point.</b> 00549 */ 00550 void fixXTarget(value_type aX); 00551 00552 /** 00553 * @brief Set Y coordinate of the source point. 00554 * 00555 * @param aY new Y coordinate of the source point 00556 * 00557 * @warning <b>Function qgar::AbstractGenPrimitive::updateSource 00558 * is called after the modification of the source point.</b> 00559 */ 00560 void fixYSource(value_type aY); 00561 00562 /** 00563 * @brief Set Y coordinate of the target point. 00564 * 00565 * @param aY new Y coordinate of the target point 00566 * 00567 * @warning <b>Function qgar::AbstractGenPrimitive::updateTarget 00568 * is called after the modification of the target point.</b> 00569 */ 00570 void fixYTarget(value_type aY); 00571 00572 //@} 00573 00574 00575 /** @name Operators */ 00576 // ========= 00577 //@{ 00578 /** 00579 * @brief Assignment. 00580 * 00581 * @param aQPrim a Qgar primitive 00582 */ 00583 AbstractGenQgarPrimitive<value_type>& 00584 operator=(const AbstractGenQgarPrimitive<value_type>& aQPrim); 00585 //@} 00586 00587 00588 /** @name Geometry: Translation */ 00589 // ===================== 00590 //@{ 00591 00592 /** 00593 * @brief Translate along X and Y axis. 00594 * 00595 * @param aTransX X translation factor 00596 * @param aTransY Y translation factor 00597 */ 00598 inline void translate(value_type aTransX, value_type aTransY); 00599 00600 //@} 00601 00602 00603 // /** @name Geometry: Symmetry */ 00604 // // ================== 00605 // //@{ 00606 00607 // /** 00608 // * @brief Apply a central symmetry to the current primitive, using 00609 // * the point of given coordinates as the symmetry center. 00610 // * @param aX X coordinate of the symmetry center 00611 // * @param aY Y coordinate of the symmetry center 00612 // * 00613 // */ 00614 // inline void symmetry(value_type aX, value_type aY); 00615 00616 // /** 00617 // * @brief Apply a central symmetry to the current primitive, using 00618 // * the given point as the symmetry center. 00619 // * @param aCenter a point representing the center of the symmetry 00620 // */ 00621 // inline void symmetry(const GenPoint<value_type>& aCenter); 00622 00623 // /** 00624 // * @brief Apply a mirror symmetry to the current primitive, using 00625 // * the line passing through the two given points for the symmetry. 00626 // * @param aPt1 a point 00627 // * @param aPt2 a point 00628 // * 00629 // * @warning This function applies to primitives 00630 // * having coordinates of type <b>double</b> only. 00631 // */ 00632 // inline void symmetry(const GenPoint<double>& aPt1, 00633 // const GenPoint<double>& aPt2); 00634 00635 // /** 00636 // * @brief Apply a mirror symmetry to the current primitive, using 00637 // * the line supporting the given segment for the symmetry. 00638 // * @param aSeg a segment 00639 // * 00640 // * @warning This function applies to primitives 00641 // * having coordinates of type <b>double</b> only. 00642 // */ 00643 // inline void symmetry(const GenSegment<double>& aSeg); 00644 00645 // //@} 00646 00647 00648 // ------------------------------------------------------------------- 00649 // P R O T E C T E D M E M B E R S 00650 // ------------------------------------------------------------------- 00651 protected: 00652 00653 00654 /** @name Attributes */ 00655 // ========== 00656 //@{ 00657 00658 /** 00659 * @brief Thickness of the outline. 00660 */ 00661 int _thickness; 00662 00663 /** 00664 * @brief Color of the outline. 00665 */ 00666 QGEcolor _color; 00667 00668 /** 00669 * @brief Type of outline. 00670 * 00671 * @see Enum type qgar::QGEoutline 00672 */ 00673 QGEoutline _outline; 00674 00675 //@} 00676 00677 00678 /**@name Non-protected access to the geometrical aspect */ 00679 // ============================================== 00680 //@{ 00681 00682 /** 00683 * @brief Return the geometrical aspect. 00684 * 00685 * It may then be modified using appropriate 00686 * transformation function members. 00687 */ 00688 virtual AbstractGenPrimitive<value_type>& getGeomStructure() = 0; 00689 00690 //@} 00691 00692 00693 // ------------------------------------------------------------------- 00694 }; // class AbstractGenQgarPrimitive 00695 00696 00697 00698 00699 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00700 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00701 // P R E D E F I N E D P R I M I T I V E T Y P E S 00702 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00703 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00704 00705 00706 /** 00707 * @name Qgar Abstract Primitives 00708 * @ingroup DS_PRIM_QGAR 00709 */ 00710 // @{ 00711 00712 /** 00713 * @brief Qgar primitive with <b>integer</b> coordinates. 00714 * 00715 * @see qgar::IQgarPrimitive 00716 */ 00717 typedef AbstractGenQgarPrimitive<int> QgarPrimitive; 00718 00719 /** 00720 * @brief Qgar primitive with <b>integer</b> coordinates. 00721 * 00722 * @see qgar::QgarPrimitive 00723 */ 00724 typedef AbstractGenQgarPrimitive<int> IQgarPrimitive; 00725 00726 /** 00727 * @brief Qgar primitive with <b>float</b> coordinates. 00728 */ 00729 typedef AbstractGenQgarPrimitive<float> FQgarPrimitive; 00730 00731 /** 00732 * @brief Qgar primitive with <b>double</b> coordinates. 00733 */ 00734 typedef AbstractGenQgarPrimitive<double> DQgarPrimitive; 00735 00736 // @} 00737 00738 00739 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00740 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT 00741 00742 00743 } // namespace qgar 00744 00745 00746 #endif /* ___QGAR_ABSTRACTGENQGARPRIMITIVE_H_INCLUDED__ */