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