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

GenMask2d.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 __GENMASK2D_H_INCLUDED__
00029 #define __GENMASK2D_H_INCLUDED__
00030 
00031 
00032 /**
00033  * @file   GenMask2d.H
00034  * @brief  Header file of class qgar::GenMask2d.
00035  *
00036  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gerald Masini">Gérald Masini</a>
00037  * @date   Apr 11, 2003  15:17
00038  * @since  Qgar 2.1
00039  */
00040 
00041 
00042 // For RCS/CVS use: Do not delete
00043 /* $Id: GenMask2d.H,v 1.16 2005/07/29 16:28:09 gerald Exp $ */
00044 
00045 
00046 
00047 namespace qgar
00048 {
00049 
00050 
00051 /**
00052  * @class GenMask2d GenMask2d.H "qgarlib/GenMask2d.H"
00053  * @ingroup DS_MASK
00054  * @brief Generic 2D mask with coefficients of type <b>T</b>.
00055  * 
00056  * @warning A mask is stored as <b>consecutive rows</b> im memory space.
00057  * The top-left corner of the mask has coordinates <b>(0,0)</b>.
00058  *
00059  * @author <a href="mailto:qgar-develop@loria.fr?subject=Qgar fwd Gerald Masini">Gérald Masini</a>
00060  * @date   Apr 11, 2003  15:17
00061  * @since  Qgar 2.1
00062  */
00063 template <class T> class GenMask2d
00064 {
00065 // -------------------------------------------------------------------
00066 // T Y P E   D E F I N I T I O N S
00067 // -------------------------------------------------------------------
00068 public:
00069 
00070   /** @name Types related to 2D masks */
00071   //        =========================
00072   //@{
00073   /**
00074    * @brief Type of the mask coefficients.
00075    */
00076   typedef T value_type;
00077 
00078   /**
00079    * @brief Reference to qgar::GenMask2d::value_type.
00080    */
00081   typedef value_type& reference;
00082 
00083   /**
00084    * @brief Constant reference to qgar::GenMask2d::value_type.
00085    */
00086   typedef const value_type& const_reference;
00087 
00088   /**
00089    * @brief Pointer to qgar::GenMask2d::value_type.
00090    */
00091   typedef value_type* pointer;
00092 
00093   /**
00094    * @brief Constant pointer to qgar::GenMask2d::value_type.
00095    */
00096   typedef const value_type* const_pointer;
00097 
00098   //@}
00099 
00100 
00101 // -------------------------------------------------------------------
00102 // P U B L I C    M E M B E R S
00103 // -------------------------------------------------------------------
00104 public:
00105 
00106   /** @name Constructors */
00107   //        ============
00108   //@{
00109 
00110   /**
00111    * @brief Default constructor: Set <b>0</b> to mask width and height,
00112    * to pointer to the coefficient map, and to reference counter.
00113    */
00114   GenMask2d();
00115 
00116   /**
00117    * @brief Copy constructor.
00118    *
00119    * See also qgar::GenMask2d::operator=
00120    *      and qgar::GenMask2d::shallowCopy.
00121    *
00122    * @warning Perform a deep copy:
00123    * The coefficent map of the source mask is duplicated.
00124    */
00125   GenMask2d(const GenMask2d<value_type>& aMask);
00126 
00127   /**
00128    * @brief Initialize with given width, height and value.
00129    *
00130    * All the coefficients are set to the given value.
00131    *
00132    * @param aWidth   mask width
00133    * @param aHeight  mask height
00134    * @param aValue   value to fill the mask with (default <b>0</b>)
00135    */
00136   GenMask2d(unsigned int aWidth,
00137             unsigned int aHeight,
00138             value_type aValue = static_cast<value_type>(0));
00139 
00140   /**
00141    * @brief Builds a mask from an array of values.
00142    *
00143    * @param aWidth
00144    * @param aHeight
00145    * @param valArray
00146    */
00147   GenMask2d(unsigned int aWidth,
00148             unsigned int aHeight,
00149             const_pointer const valArray);
00150 
00151   //@}
00152 
00153 
00154   /** @name Destructor */
00155   //        ==========
00156   //@{
00157 
00158   /**
00159    * @brief Non-virtual destructor.
00160    *
00161    * Free space allocated to the coefficient map
00162    * if and only if the reference counter is null.
00163    */
00164   ~GenMask2d();
00165 
00166   //@}
00167 
00168 
00169   /** @name Access to mask characteristics */
00170   //        ==============================
00171   //@{
00172 
00173   /**
00174    * @brief Get mask width.
00175    */
00176   inline int width() const;
00177 
00178   /**
00179    * @brief Get mask height.
00180    */
00181   inline int height() const;
00182 
00183   //@}
00184 
00185 
00186   /** @name Access to coefficient values */
00187   //        ============================
00188   //@{
00189 
00190   /**
00191    * @brief Get a coefficient value.
00192    *
00193    * @param aX  X coordinate (column index) of the coefficient
00194    * @param aY  Y coordinate (row index) of the coefficient
00195    */
00196   value_type coeff(int aX, int aY) const;
00197 
00198   //@}
00199 
00200 
00201  /** @name Access to direct transformations of the coefficient map */
00202   //       =======================================================
00203   //@{
00204 
00205   /**
00206    * @brief Get the pointer to the coefficient map.
00207    */
00208   inline pointer pCoeffMap() const;
00209 
00210   //@}
00211 
00212 
00213   /** @name Transformation */
00214   //        ==============
00215   //@{
00216 
00217   /**
00218    * @brief Set coefficient at given position.
00219    *
00220    * @param aX      X coordinate (column index) of the coefficient
00221    * @param aY      Y coordinate (row index) of the coefficient
00222    * @param aCoeff  coefficient value
00223    */
00224   void setCoeff(int aX, int aY, value_type aCoeff);
00225 
00226   //@}
00227 
00228 
00229   /** @name Copy */
00230   //        ====
00231   //@{
00232 
00233   /**
00234    * @brief Shallow copy: The coefficient map of the source mask
00235    * is <b>not</b> duplicated.
00236    *
00237    * See also qgar::GenMask2d::operator=
00238    *      and qgar::GenMask2d::shallowCopy.
00239    *
00240    * @warning Before the copy is performed, the destination mask
00241    * is not supposed to have the same dimensions as the source mask.
00242    * When the copy is completed, the pixel map of the destination
00243    * mask is the same memory space as the pixel map of the source mask.
00244    */
00245   GenMask2d<value_type> shallowCopy();
00246 
00247   //@}
00248 
00249 
00250   /** @name Operators */
00251   //        =========
00252   //@{
00253 
00254   /**
00255    * @brief Assignment.
00256    * @param aMask mask to assign
00257    *
00258    * See also qgar::GenMask2d::operator=,
00259    *      and qgar::GenMask2d::shallowCopy.
00260    *
00261    * @warning Perform a <b>deep copy</b>: The coefficient map 
00262    * of the source mask is duplicated. Before the copy is performed, 
00263    * the destination mask is not supposed to have the same dimensions
00264    * as the destination mask.
00265    */
00266   GenMask2d<value_type>& operator=(const GenMask2d<value_type>& aMask);
00267 
00268   //@}
00269 
00270 
00271 // -------------------------------------------------------------------
00272 // P R O T E C T E D    M E M B E R S
00273 // -------------------------------------------------------------------
00274 protected:
00275 
00276 
00277   /** @name Shallow copy constructor */
00278   //        ========================
00279   //@{
00280 
00281   /**
00282    * @brief Shallow copy constructor.
00283    *
00284    * This constructor declares an unused <b>integer</b> parameter
00285    * to avoid ambiguous calls to the copy constructor.
00286    * It builds a shallow copy of a mask instance.
00287    *
00288    * @param rhs A mask instance to create a copy from.
00289    */
00290   GenMask2d(const GenMask2d<value_type>& rhs, int);
00291 
00292   //@}
00293 
00294 
00295   /** @name Representation of a mask */
00296   //        ========================
00297   //@{
00298 
00299   /**
00300    * @brief Reference counter.
00301    *
00302    * Its value represent the number of other masks
00303    * with which the current mask shares its coefficient map.
00304    */
00305   int* _pRefCnt;
00306 
00307   /**
00308    * @brief Mask width.
00309    */
00310   int _width;
00311 
00312   /**
00313    * @brief Mask height.
00314    */
00315   int _height;
00316 
00317   /**
00318    * @brief Pointer to the memory space of the mask.
00319    */
00320   pointer _pCoeffMap;
00321 
00322   //@}
00323 
00324 
00325 // -------------------------------------------------------------------
00326 // P R I V A T E    M E M B E R S
00327 // -------------------------------------------------------------------
00328 private:
00329 
00330 
00331   /** @name Auxiliaries */
00332   //        ===========
00333   //@{
00334 
00335   /**
00336    * @brief Store a deep copy of a given mask into the current mask.
00337    *
00338    * @param aMask  mask to be copied
00339    */
00340   void PRIVATEdeepCopy(const GenMask2d<T>& aMask);
00341 
00342   //@}
00343 
00344 
00345 // -------------------------------------------------------------------
00346 }; // class GenMask2d
00347 
00348 
00349 } // namespace qgar
00350 
00351 
00352 
00353 
00354 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00355 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00356 // I M P L E M E N T A T I O N
00357 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00358 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00359 
00360 #include <qgarlib/GenMask2d.TCC>
00361 
00362 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00363 // IIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIIII
00364 
00365 
00366 
00367 
00368 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00369 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00370 // P R E D E F I N E D    M A S K    T Y P E S
00371 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00372 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00373 
00374 
00375 namespace qgar
00376 {
00377 
00378 
00379 /**
00380  * @name 2D Masks
00381  * @ingroup DS_MASK
00382  */
00383 //@{
00384 
00385 /**
00386  * @brief 2D mask with coefficients of type <b>int</b>.
00387  *
00388  * @see qgar::GenMask2d::IMask2d
00389  */
00390 typedef GenMask2d<int> Mask2d;
00391 
00392 /**
00393  * @brief 2D mask with coefficients of type <b>int</b>.
00394  *
00395  * @see qgar::GenMask2d::Mask2d
00396  */
00397 typedef GenMask2d<int> IMask2d;
00398 
00399 /**
00400  * @brief 2D mask with coefficients of type <b>float</b>.
00401  */
00402 typedef GenMask2d<float> FMask2d;
00403 
00404 /**
00405  * @brief 2D mask with coefficients of type <b>double</b>.
00406  */
00407 typedef GenMask2d<double> DMask2d;
00408 
00409 //@}
00410 
00411 
00412 } // namespace qgar
00413 
00414 
00415 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00416 // TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT
00417 
00418 
00419 #endif /* __GENMASK2D_H_INCLUDED__ */