last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 2007 00003 * ITCR, Pablo Alvarado 00004 * 00005 * 00006 * This file is part of the Computer Vision and Robotics Library (CVR-Lib) 00007 * 00008 * The CVR-Lib is free software; you can redistribute it and/or 00009 * modify it under the terms of the BSD License. 00010 * 00011 * All rights reserved. 00012 * 00013 * Redistribution and use in source and binary forms, with or without 00014 * modification, are permitted provided that the following conditions are met: 00015 * 00016 * 1. Redistributions of source code must retain the above copyright notice, 00017 * this list of conditions and the following disclaimer. 00018 * 00019 * 2. Redistributions in binary form must reproduce the above copyright notice, 00020 * this list of conditions and the following disclaimer in the documentation 00021 * and/or other materials provided with the distribution. 00022 * 00023 * 3. Neither the name of the authors nor the names of its contributors may be 00024 * used to endorse or promote products derived from this software without 00025 * specific prior written permission. 00026 * 00027 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00028 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00029 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00030 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00031 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00032 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00033 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00034 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00035 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00036 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00037 * POSSIBILITY OF SUCH DAMAGE. 00038 */ 00039 00040 00041 /** 00042 * \file cvrBoundaryExpansion.h 00043 * Contains the class cvr::boundaryExpansion, 00044 * which is used to expand an image with a border defined through the 00045 * boundaryType parameter 00046 * 00047 * \author Pablo Alvarado 00048 * \date 03.10.2007 00049 * 00050 * revisions ..: $Id: cvrBoundaryExpansion.h,v 1.1 2007/10/05 00:46:15 alvarado Exp $ 00051 */ 00052 00053 #ifndef _CVR_BOUNDARY_EXPANSION_H_ 00054 #define _CVR_BOUNDARY_EXPANSION_H_ 00055 00056 #include "cvrMatrix.h" 00057 #include "cvrVector.h" 00058 #include "cvrFunctor.h" 00059 #include "cvrTypeInfo.h" 00060 #include "cvrBoundaryType.h" 00061 00062 namespace cvr { 00063 00064 /** 00065 * Class boundaryExpansion 00066 * 00067 * This class is used to expand the border of an image and fill it according 00068 * to the boundary type specified in the parameters. It is employed by 00069 * several functors to work using "internal" pixels only, without worring 00070 * about the specific border type to be used. 00071 * 00072 * If negative values of border are given in the parameters, the image will 00073 * be clipped. 00074 * 00075 * @see boundaryExpansion::parameters. 00076 * 00077 * @ingroup gGeometricTrans 00078 */ 00079 class boundaryExpansion : public functor { 00080 public: 00081 /** 00082 * The parameters for the class boundaryExpansion 00083 */ 00084 class parameters : public functor::parameters { 00085 public: 00086 /** 00087 * Default constructor 00088 */ 00089 parameters(); 00090 00091 /** 00092 * Copy constructor 00093 * @param other the parameters object to be copied 00094 */ 00095 parameters(const parameters& other); 00096 00097 /** 00098 * Destructor 00099 */ 00100 ~parameters(); 00101 00102 /** 00103 * Copy the contents of a parameters object 00104 * @param other the parameters object to be copied 00105 * @return a reference to this parameters object 00106 */ 00107 parameters& copy(const parameters& other); 00108 00109 /** 00110 * Copy the contents of a parameters object 00111 * @param other the parameters object to be copied 00112 * @return a reference to this parameters object 00113 */ 00114 parameters& operator=(const parameters& other); 00115 00116 /** 00117 * Returns the complete name of the parameters class. 00118 */ 00119 virtual const std::string& name() const; 00120 00121 /** 00122 * Returns a pointer to a clone of the parameters. 00123 */ 00124 virtual parameters* clone() const; 00125 00126 /** 00127 * Returns a pointer to a new instance of the parameters. 00128 */ 00129 virtual parameters* newInstance() const; 00130 00131 /** 00132 * Write the parameters in the given ioHandler 00133 * @param handler the ioHandler to be used 00134 * @param complete if true (the default) the enclosing begin/end will 00135 * be also written, otherwise only the data block will be written. 00136 * @return true if write was successful 00137 */ 00138 virtual bool write(ioHandler& handler,const bool complete=true) const; 00139 00140 /** 00141 * Read the parameters from the given ioHandler 00142 * @param handler the ioHandler to be used 00143 * @param complete if true (the default) the enclosing begin/end will 00144 * be also written, otherwise only the data block will be written. 00145 * @return true if write was successful 00146 */ 00147 virtual bool read(ioHandler& handler,const bool complete=true); 00148 00149 // ------------------------------------------------ 00150 // the parameters 00151 // ------------------------------------------------ 00152 00153 /** 00154 * Number of pixels in the bottom border. 00155 * 00156 * Default value: 5 00157 */ 00158 int bottomBorder; 00159 00160 /** 00161 * Number of pixels in the left border. 00162 * 00163 * Default value: 5 00164 */ 00165 int leftBorder; 00166 00167 /** 00168 * Number of pixels in the right border. 00169 * 00170 * Default value: 5 00171 */ 00172 int rightBorder; 00173 00174 /** 00175 * Number of pixels in the top border. 00176 * 00177 * Default value: 5 00178 */ 00179 int topBorder; 00180 00181 /** 00182 * Type of boundary expansion 00183 */ 00184 eBoundaryType boundaryType; 00185 00186 /** 00187 * Normalization. 00188 * 00189 * If set to \c true, then the values will be normalized and denormalized 00190 * when transfering the data from one matrix of one type to a matrix of 00191 * another type, so that the values preserve their nature. For instance, 00192 * when converting ubyte to float, the values will be divided by 255 to 00193 * produce values between 0.0f and 1.0f, or the other way around. The 00194 * normalization constants are given by 00195 * cvr::typeInfo<T>::suggestedNorm(). 00196 * 00197 * If set to \c false then the values are simply casted. 00198 * 00199 * Default value: false 00200 */ 00201 bool normalize; 00202 00203 }; 00204 00205 /** 00206 * Default constructor 00207 */ 00208 boundaryExpansion(); 00209 00210 /** 00211 * Construct a functor with a border of homogeneous width all around, and 00212 * the given boundary type. 00213 * 00214 * @param width width of the border 00215 * @param type boundary type 00216 * @param normalize indicate if normalization by the type conversion has 00217 * to be made. 00218 */ 00219 boundaryExpansion(const int width, 00220 const eBoundaryType type = Zero, 00221 const bool normalize = false); 00222 00223 /** 00224 * Construct a functor using the given parameters 00225 */ 00226 boundaryExpansion(const parameters& par); 00227 00228 /** 00229 * Copy constructor 00230 * @param other the object to be copied 00231 */ 00232 boundaryExpansion(const boundaryExpansion& other); 00233 00234 /** 00235 * Destructor 00236 */ 00237 virtual ~boundaryExpansion(); 00238 00239 /** 00240 * Expand the boundary of the given matrix and leave the result on the 00241 * same matrix. 00242 * 00243 * @param srcdest matrix<T> with the source data. The result 00244 * will be left here too. 00245 * @return true if apply successful or false otherwise. 00246 */ 00247 template<typename T> 00248 bool apply(matrix<T>& srcdest) const; 00249 00250 /** 00251 * Operates on a copy of the given arguments. 00252 * 00253 * @param src matrix<T> with the source data. 00254 * @param dest matrix<T> where the result will be left. 00255 * @return true if apply successful or false otherwise. 00256 */ 00257 template<typename T,typename U> 00258 bool apply(const matrix<T>& src, matrix<U>& dest) const; 00259 00260 /** 00261 * Copy data of "other" functor. 00262 * @param other the functor to be copied 00263 * @return a reference to this functor object 00264 */ 00265 boundaryExpansion& copy(const boundaryExpansion& other); 00266 00267 /** 00268 * Alias for copy member 00269 * @param other the functor to be copied 00270 * @return a reference to this functor object 00271 */ 00272 boundaryExpansion& operator=(const boundaryExpansion& other); 00273 00274 /** 00275 * Returns the complete name of the functor class 00276 */ 00277 virtual const std::string& name() const; 00278 00279 /** 00280 * Returns a pointer to a clone of this functor. 00281 */ 00282 virtual boundaryExpansion* clone() const; 00283 00284 /** 00285 * Returns a pointer to a new instance of this functor. 00286 */ 00287 virtual boundaryExpansion* newInstance() const; 00288 00289 /** 00290 * Returns used parameters 00291 */ 00292 const parameters& getParameters() const; 00293 00294 private: 00295 /** 00296 * The class doing the real job 00297 */ 00298 template<typename T,typename U,bool N> 00299 class helperBase; 00300 00301 /** 00302 * The class doing the real job 00303 */ 00304 template<typename T,typename U,bool N> 00305 class helper; 00306 }; 00307 } 00308 00309 #include "cvrBoundaryExpansion_template.h" 00310 00311 #endif 00312