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