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

Maer.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 __MAER_H_INCLUDED__
00029 #define __MAER_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file     Maer.H
00034  * @brief    Header file of template class qgar::Maer.
00035  *
00036  * @author   <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00037  * @date     May 13, 2004  11:30
00038  * @since    Qgar 2.1
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: Maer.H,v 1.13 2005/10/14 17:05:47 masini Exp $ */
00044 
00045 
00046 
00047 // STD
00048 #include <list>
00049 // QGAR
00050 #include <qgarlib/primitives.H>
00051 namespace qgar
00052 {
00053   // Avoid #include's when not necessary
00054   class FreemanChain;
00055 }
00056 
00057 
00058 
00059 namespace qgar
00060 {
00061 
00062 
00063 /**
00064  * @ingroup TOOL_MAER
00065  *
00066  * @class Maer Maer.H "qgarlib/Maer.H"
00067  *
00068  * @brief Minimum-Area Encasing Rectangle (MAER).
00069  *
00070  * Compute a MAER
00071  * from a given list of points, typically supposed
00072  * to determine the contour of an image component.
00073  * See
00074  * [<a href="Bibliography.html#Freeman-and-Shapira-1975">Freeman&nbsp;and&nbsp;Shapira,&nbsp;1975</a>]
00075  *
00076  * <ul>
00077  * <li>
00078  * When only a single point is given, the MAER is a rectangle
00079  * whose 4 corners are this very point.
00080  * </li>
00081  * <li>
00082  * When 2 points or a series of aligned points are given,
00083  * the MAER is a rectangle with 2 pairs of identical corners,
00084  * corresponding to the extremities of the series. For example:
00085 @verbatim
00086    Y
00087     ^
00088     |
00089   1 -  +  +  +     +         MAER = (1,1) (1,1) (5,1) (5,1)
00090     |
00091     +--|--|--|--|--|--->
00092    0   1  2  3  4  5    X
00093 @endverbatim
00094  * </li>
00095  * </ul>
00096  *
00097  * In both cases, the MAER area is equal to <b>0</b>.
00098  *
00099  * The computing is performed using <b>double</b> numbers, and
00100  * the MAER features are also stored as <b>double</b> numbers.
00101  *
00102  * @warning No copy constructor is defined.
00103  *
00104  * @author   <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gérald Masini">Gérald Masini</a>
00105  * @date     May 13, 2004  11:30
00106  * @since    Qgar 2.1
00107  */
00108 class Maer
00109 {
00110 // -------------------------------------------------------------------
00111 // P U B L I C    M E M B E R S
00112 // -------------------------------------------------------------------
00113 public:
00114 
00115   /** @name Constructors */
00116   //        ============
00117   //@{
00118 
00119   ///**
00120   // * @brief Default constructor.
00121   // *
00122   // * @warning No default constructor is defined. 
00123   // */
00124   //Maer();
00125 
00126   /**
00127    * @brief Create from a list of points having <b>double</b> coordinates.
00128    *
00129    * @param aPtList  a list of <b>double</b> points
00130    */
00131   Maer(const std::list<DPoint>& aPtList);
00132 
00133   /**
00134    * @brief Create from a list of points having a coordinate type
00135    *   different from <b>double</b>.
00136    *
00137    * @param aPtList  a list of points
00138    *
00139    * @warning As computing is performed using <b>double</b> numbers,
00140    * the use of this constructor implies the conversion of each given
00141    * point into a point having <b>double</b> coordinates,
00142    * i.e. the duplication of the given list.
00143    */
00144   template <class T>
00145   Maer(const std::list< GenPoint<T> >& aPtList);
00146 
00147   /**
00148    * @brief Create from a Freeman chain
00149    *   (representing the contour of an image component).
00150    *
00151    * @param aCh  a Freeman Chain
00152    */
00153   Maer(const FreemanChain& aCh);
00154 
00155   /**
00156    * @brief Copy constructor.
00157    *
00158    * @param aMaer  a MAER
00159    */
00160   Maer(const Maer& aMaer);
00161 
00162   //@}
00163 
00164 
00165   /** @name Destructor */
00166   //        ==========
00167   //@{
00168 
00169   /**
00170    * @brief Non-virtual destructor:
00171    * The class is not supposed to be derived.
00172    */
00173   ~Maer();
00174 
00175   //@}
00176 
00177 
00178   /** @name Access */
00179   //        ======
00180   //@{
00181 
00182   /**
00183    * @brief Get the list including the 4 corners of the MAER.
00184    */
00185   const std::list<DPoint>& accessVertices() const;
00186   
00187   /**
00188    * @brief Get a copy of the list including the 4 corners of the MAER.
00189    */
00190   std::list<DPoint> vertices() const;
00191   
00192   /**
00193    * @brief Get area.
00194    */
00195   inline double area() const; 
00196  
00197   //@}
00198 
00199 
00200   /** @name Operators */
00201   //        =========
00202   //@{
00203 
00204   /**
00205    * @brief Assignment.
00206    *
00207    * @param aMaer  a Minimum-Area Enclosing Rectangle
00208    */
00209   Maer& operator=(const Maer& aMaer);
00210 
00211   //@}
00212 
00213 // -------------------------------------------------------------------
00214 // P R O T E C T E D    M E M B E R S
00215 // -------------------------------------------------------------------
00216 protected:
00217 
00218   /** @name MAER features */
00219   //        =============
00220   //@{
00221 
00222   /**
00223    * @brief The four corners.
00224    */
00225   std::list<DPoint> _vertices;
00226 
00227   /**
00228    * @brief The area.
00229    */
00230   double _area;
00231 
00232   //@}
00233 
00234 // -------------------------------------------------------------------
00235 // P R I V A T E    M E M B E R S
00236 // -------------------------------------------------------------------
00237 private:
00238 
00239   /** @name MAER computing */
00240   //        ==============
00241 
00242   /**
00243    * @brief Auxiliary function to compute the MAER from a list
00244    *        of points having <b>double</b> coordinates.
00245    *
00246    * @param aPtList  a list of <b>double</b> points
00247    */
00248   void PRIVATEcomputeMaer(const std::list<DPoint>& aPtList);
00249 
00250   //@}
00251 
00252 
00253   /** @name Auxiliaries */
00254   //        ===========
00255   //@{
00256 
00257   /**
00258    * @brief To convert a point having coordinates of any type
00259    * into a point having <b>double</b> coordinates.
00260    *
00261    * To be used as a functor in STL algorithms (see function
00262    * qgar::Maer::Maer(const std::list< GenPoint<T> >&) for example).
00263    *
00264    * @param aPt  a point
00265    */
00266     template <class T>
00267     GenPoint<double>
00268     PRIVATEtoDPoint(const GenPoint<T>& aPt);
00269 
00270   //@}
00271 
00272 // -------------------------------------------------------------------
00273 }; // class Maer
00274 
00275 
00276 
00277 
00278 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00279 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00280 // 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
00281 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00282 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00283 
00284 
00285 // ======
00286 // ACCESS
00287 // ======
00288 
00289 // GET AREA
00290 
00291 inline double
00292 Maer::area() const
00293 {
00294   return _area;
00295 }
00296 
00297 
00298 // ===========
00299 // AUXILIARIES
00300 // ===========
00301 
00302 // To convert a point having coordinates of any type
00303 // into a point having double coordinates.
00304 
00305 template <class T>
00306 GenPoint<double>
00307 Maer::PRIVATEtoDPoint(const GenPoint<T>& aPt)
00308 {
00309   return GenPoint<double>(aPt);
00310 }
00311 
00312 
00313 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00314 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00315 // END OF INLINE FUNCTIONS IMPLEMENTATION
00316 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00317 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00318 
00319 
00320 } // namespace qgar 
00321 
00322 
00323 #endif /* __MAER_H_INCLUDED__ */