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

WDSegmentList.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 __WDSEGMENTLIST_H_INCLUDED__
00029 #define __WDSEGMENTLIST_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   WDSegmentList.H
00034  * @brief  Header file of class qgar::WDSegmentList.
00035  *
00036  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00037  * @date   July 3, 2001  09:56
00038  * @since  Qgar 1.0
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: WDSegmentList.H,v 1.6 2005/11/02 17:30:48 masini Exp $ */
00044 
00045 
00046 
00047 // STL
00048 #include <list>
00049 // QGAR
00050 #include <qgarlib/image.H>
00051 #include <qgarlib/primitives.H>
00052 namespace qgar
00053 {
00054   // Avoid #include's when not necessary
00055   template <class T> class AbstractGenPointChain;
00056   template <class T> class GenPoint;
00057 }
00058 
00059 
00060 
00061 namespace qgar
00062 {
00063 
00064 /*---------------------------------------------------------------------*
00065  |                                                                     |
00066  |             C  L  A  S  S      W  D  S  E  G  M  E  N  T            |
00067  |                                                                     |
00068  *---------------------------------------------------------------------*/
00069 
00070 /**
00071  * @ingroup GRAPHPROC_POLYAPPROX
00072  *
00073  * @class WDSegment WDSegmentList.H
00074  *
00075  * @brief A segment resulting from a polygonal approximation
00076  *   performed according to Wall and Danielsson's method.
00077  *
00078  * @todo Dirty: Take a look at functions qgar::WDSegmentList::set(),
00079  * and conversions from WDSegments to Segments.
00080  * Find a way to remove this class!
00081  *
00082  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00083  * @date   July 3, 2001  09:56
00084  * @since  Qgar 1.0
00085  */
00086 class WDSegment
00087 
00088   : public GenSegment<int>
00089 
00090 {
00091 // -------------------------------------------------------------------
00092 // P U B L I C    M E M B E R S
00093 // -------------------------------------------------------------------
00094 public:
00095 
00096   /** @name Constructors */
00097   //        ============
00098   //@{
00099 
00100   /**
00101    * @brief Default constructor: Creation of a null segment.
00102    */
00103   WDSegment();
00104 
00105   /**
00106    * @brief Construct from full data (used during approximation).
00107    *
00108    * @param orig   origin point
00109    * @param deltaX displacement to end point (\f$\Delta_x\f$)
00110    * @param deltaY displacement to end point (\f$\Delta_y\f$)
00111    * @param d      direction of segment
00112    */
00113   WDSegment(GenPoint<int>& orig,
00114             int deltaX,
00115             int deltaY,
00116             QGEdirection d);
00117 
00118   /**
00119    * @brief Copy constructor.
00120    */
00121   WDSegment(const WDSegment& aSeg);
00122 
00123   //@}
00124 
00125 
00126   /** @name Access */
00127   //        ======
00128   //@{
00129 
00130   /**
00131    * @brief Get approximation factor.
00132    */
00133   inline int approxFactor() const;
00134 
00135   /**
00136    * @brief Get square length.
00137    */
00138   inline int sqrLength() const;
00139 
00140   /**
00141    * @brief Get general direction.
00142    */
00143   inline QGEdirection direction() const;
00144 
00145   /**
00146    * @brief Get length of segment.
00147    */
00148   inline double length() const;
00149 
00150   //@}
00151 
00152 
00153   /** @name Transformation */
00154   //        ==============
00155   //@{
00156 
00157   /**
00158    * @brief Set approximation factor.
00159    */
00160   inline void setApproxFactor(int af);
00161 
00162   /**
00163    * @brief Set square length.
00164    */
00165   inline void setSqrLength(int sl);
00166 
00167   /**
00168    * @brief Set general direction.
00169    */
00170   inline void setDirection(QGEdirection d);
00171 
00172   /**
00173    * @brief Translate extremum point with given point.
00174    */
00175   void translateTarget(GenPoint<int>&);
00176 
00177   /**
00178    * @brief Set segment from an other segment (member-to-member copy).
00179    */
00180   void set(const WDSegment& aSeg);
00181 
00182   /**
00183    * Set segment from given data.
00184    *
00185    * @param orig    origin point
00186    * @param deltaX  displacement to end point (\f$\Delta_{x}\f$)
00187    * @param deltaY  displacement to end point (\f$\Delta_{y}\f$)
00188    * @param d       direction of segment
00189    */
00190   void set(GenPoint<int>& orig, int deltaX, int deltaY, QGEdirection d);
00191 
00192   //@}
00193 
00194 
00195   /** @name Operators */
00196   //        =========
00197   //@{
00198 
00199   /**
00200    * @brief Assignment.
00201    */
00202   WDSegment& operator=(const WDSegment& w);
00203 
00204   /**
00205    * @brief Equality.
00206    */
00207   inline int operator==(const WDSegment s) const;
00208 
00209   /**
00210    * @brief Inequality.
00211    */
00212   inline int operator!=(const WDSegment s) const;
00213 
00214   //@}
00215 
00216 // -------------------------------------------------------------------
00217 // P R O T E C T E D    M E M B E R S
00218 // -------------------------------------------------------------------
00219 protected:
00220 
00221   /** @name Representation of a segment */
00222   //        ===========================
00223   //@{
00224 
00225   /**
00226    * @brief Square length.
00227    */
00228   int _sqrLength;
00229 
00230   /**
00231    * @brief Approximation factor.
00232    *
00233    * In the Wall & Danielsson's method, it is a measure of the
00234    * algebraic area between the segment and the approximated curve.
00235    */
00236   int _approxFactor;
00237 
00238   /**
00239    * @brief Direction of the segment.
00240    */
00241   QGEdirection _direction;
00242 
00243   //@}
00244 
00245 // -------------------------------------------------------------------
00246 }; // class WDSegment
00247 
00248 
00249 
00250 
00251 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00252 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00253 // I N L I N E   F U N C T I O N S   I M P L E M E N T A T I O N 
00254 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00255 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00256 
00257 
00258 //  ======
00259 //  ACCESS
00260 //  ======
00261 
00262 
00263 // GET APPROXIMATION FACTOR
00264 
00265 inline int
00266 WDSegment::approxFactor() const
00267 {
00268   return _approxFactor;
00269 }
00270 
00271 
00272 // GET SQUARE LENGTH
00273 
00274 inline int
00275 WDSegment::sqrLength() const
00276 {
00277   return _sqrLength;
00278 }
00279 
00280 
00281 // GET GENERAL DIRECTION
00282 
00283 inline QGEdirection
00284 WDSegment::direction() const
00285 {
00286   return _direction;
00287 }
00288 
00289 
00290 // GET SEGMENT LENGTH
00291 
00292 inline double
00293 WDSegment::length() const
00294 {
00295   return sqrt((double) _sqrLength);
00296 }
00297 
00298 
00299 // ==============
00300 // TRANSFORMATION
00301 // ==============
00302 
00303 
00304 // SET APPROXIMATION FACTOR
00305 
00306 inline void
00307 WDSegment::setApproxFactor(int af)
00308 {
00309   _approxFactor = af;
00310 }
00311 
00312 
00313 // SET SQUARE LENGTH
00314 
00315 inline void
00316 WDSegment::setSqrLength(int sl)
00317 {
00318   _sqrLength = sl;
00319 }
00320 
00321 
00322 // SET DIRECTION
00323 
00324 inline void
00325 WDSegment::setDirection(QGEdirection d)
00326 {
00327   _direction = d;
00328 }
00329 
00330 
00331 // =========
00332 // OPERATORS
00333 // =========
00334 
00335 
00336 // EQUALITY
00337 
00338 inline int
00339 WDSegment::operator==(const WDSegment s) const
00340 {
00341   return (Segment) (*this) == (Segment) s;
00342 }
00343 
00344 
00345 // INEQUALITY
00346 
00347 inline int
00348 WDSegment::operator!=(const WDSegment s) const
00349 {
00350   return (Segment) (*this) != (Segment) s;
00351 }
00352 
00353 
00354 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00355 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00356 
00357 
00358 
00359 
00360 
00361 
00362 /*---------------------------------------------------------------------*
00363  |                                                                     |
00364  |       C  L  A  S  S      W  D  S  E  G  M  E  N  T  L  I  S  T      |
00365  |                                                                     |
00366  *---------------------------------------------------------------------*/
00367 
00368 /** 
00369  * @ingroup GRAPHPROC_POLYAPPROX
00370  *
00371  * @class WDSegmentList WDSegmentList.H "qgarlib/WDSegmentList.H"
00372  *
00373  * @brief Polygonal approximation of a chain of points,
00374  *   using Wall & Danielsson's method.
00375  *
00376  * The method is described in
00377  * [<a href="Bibliography.html#Wall-and-Danielsson-1984">Wall&nbsp;and&nbsp;Danielsson,&nbsp;1984</a>].
00378  *
00379  * @todo The class should be a client of STL class list, instead of
00380  * deriving from it!
00381  *
00382  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Karl Tombre">Karl Tombre</a>
00383  * @date   July 3, 2001  09:56
00384  * @since  Qgar 1.0
00385  */
00386 class WDSegmentList
00387 
00388   : public std::list<WDSegment>
00389 
00390 {
00391 // -------------------------------------------------------------------
00392 // P U B L I C    M E M B E R S
00393 // -------------------------------------------------------------------
00394 public:
00395 
00396   /** @name Constructors */
00397   //        ============
00398   //@{
00399 
00400   /**
00401    * @brief Construct from given chain, using given threshold.
00402    */
00403   WDSegmentList(AbstractGenPointChain<int>& chain, int wdThreshold);
00404 
00405   //@}
00406 
00407 
00408   /** @name Destructor */
00409   //        ==========
00410   //@{
00411 
00412   /**
00413    * @brief Virtual destructor.
00414    */
00415   virtual ~WDSegmentList();
00416 
00417   //@}
00418 
00419 // -------------------------------------------------------------------
00420 // P R I V A T E    M E M B E R S
00421 // -------------------------------------------------------------------
00422 private:
00423 
00424   /** @name Auxiliary functions */
00425   //        ===================
00426   //@{
00427 
00428   /**
00429    * @brief Perform polygonal approximation.
00430    */
00431   void PRIVATEperform(AbstractGenPointChain<int>&, int);
00432 
00433   //@}
00434 
00435 
00436   /** @name Auxiliary data */
00437   //        ==============
00438   //@{
00439 
00440   /**
00441    * @brief Used for angular points processing.
00442    */
00443   WDSegment _cutSeg;
00444 
00445   /**
00446    * @brief Used for angular points processing.
00447    */
00448   WDSegment _newSeg;
00449 
00450   //@}
00451 
00452 // -------------------------------------------------------------------
00453 }; // class WDSegmentList
00454 
00455 
00456 } // namespace qgar
00457 
00458 
00459 #endif /* __WDSEGMENTLIST_H_INCLUDED__ */