last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2005 00003 * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany 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 cvrBresenhamLine.h 00043 * Contains the functor bresenhamLine. 00044 * \author Gustavo Quiros 00045 * \date 18.3.2005 00046 * 00047 * revisions ..: $Id: cvrBresenhamLine.h,v 1.4 2005/08/09 14:34:34 arndh Exp $ 00048 */ 00049 00050 #ifndef _CVR_BRESENHAM_LINE_H_ 00051 #define _CVR_BRESENHAM_LINE_H_ 00052 00053 #include "cvrFunctor.h" 00054 #include "cvrGenericMatrix.h" 00055 #include "cvrPointList.h" 00056 00057 namespace cvr { 00058 00059 /** 00060 * Functor for rendering line segments with the Bresenham line 00061 * drawing algorithm. 00062 * 00063 * The apply methods take the first and last points of the line 00064 * segment, and an object where to store the points. Currently two 00065 * types of point stores are supported: 00066 * 00067 * - genericMatrix<T>, in which points are drawn with a given value of T 00068 * - ipointList, in which points are stored in the list 00069 * 00070 * Additional point stores may be added, see the addPoint() method. 00071 * 00072 */ 00073 class bresenhamLine : public functor { 00074 public: 00075 /** 00076 * The parameters for the class bresenhamLine 00077 */ 00078 class parameters : public functor::parameters { 00079 public: 00080 /** 00081 * Default constructor 00082 */ 00083 parameters(); 00084 00085 /** 00086 * Copy constructor 00087 * \param other the parameters object to be copied 00088 */ 00089 parameters(const parameters& other); 00090 00091 /** 00092 * Destructor 00093 */ 00094 ~parameters(); 00095 00096 /** 00097 * Copy the contents of a parameters object 00098 * \param other the parameters object to be copied 00099 * \return a reference to this parameters object 00100 */ 00101 parameters& copy(const parameters& other); 00102 00103 /** 00104 * Copy the contents of a parameters object 00105 * \param other the parameters object to be copied 00106 * \return a reference to this parameters object 00107 */ 00108 parameters& operator=(const parameters& other); 00109 00110 /** 00111 * Returns the complete name of the parameters class. 00112 */ 00113 virtual const std::string& name() const; 00114 00115 /** 00116 * Returns a pointer to a clone of the parameters. 00117 */ 00118 virtual parameters* clone() const; 00119 00120 /** 00121 * Returns a pointer to a new instance of the parameters. 00122 */ 00123 virtual parameters* newInstance() const; 00124 00125 /** 00126 * Write the parameters in the given ioHandler 00127 * \param handler the ioHandler to be used 00128 * \param complete if true (the default) the enclosing begin/end will 00129 * be also written, otherwise only the data block will be written. 00130 * \return true if write was successful 00131 */ 00132 virtual bool write(ioHandler& handler,const bool complete=true) const; 00133 00134 /** 00135 * Read the parameters from the given ioHandler 00136 * \param handler the ioHandler to be used 00137 * \param complete if true (the default) the enclosing begin/end will 00138 * be also written, otherwise only the data block will be written. 00139 * \return true if write was successful 00140 */ 00141 virtual bool read(ioHandler& handler,const bool complete=true); 00142 00143 // ------------------------------------------------ 00144 // the parameters 00145 // ------------------------------------------------ 00146 00147 //TODO: comment the parameters of your functor 00148 // If you add more parameters manually, do not forget to do following: 00149 // 1. indicate in the default constructor the default values 00150 // 2. make sure that the copy member also copy your new parameters 00151 // 3. make sure that the read and write members also read and 00152 // write your parameters 00153 00154 00155 }; 00156 00157 /** 00158 * Default constructor 00159 */ 00160 bresenhamLine(); 00161 00162 /** 00163 * Construct a functor using the given parameters 00164 */ 00165 bresenhamLine(const parameters& par); 00166 00167 /** 00168 * Copy constructor 00169 * \param other the object to be copied 00170 */ 00171 bresenhamLine(const bresenhamLine& other); 00172 00173 /** 00174 * Destructor 00175 */ 00176 virtual ~bresenhamLine(); 00177 00178 /** 00179 * Render a line from the point (fx,fy) to point (tx,ty). 00180 * The line will be drawn to the given genericMatrix<T> instance, 00181 * using the given color. 00182 */ 00183 template<typename T> 00184 inline bool apply(const int fx, const int fy, 00185 const int tx, const int ty, 00186 genericMatrix<T>& m, T color) const; 00187 00188 /** 00189 * Render a line from the point (fx,fy) to point (tx,ty). 00190 * The points in the line will be added to the given list. 00191 */ 00192 inline bool apply(const int fx, const int fy, 00193 const int tx, const int ty, 00194 ipointList& l) const; 00195 00196 /** 00197 * Render a line from the point f to point t. 00198 * The line will be drawn to the given genericMatrix<T> instance, 00199 * using the given color. 00200 */ 00201 template<typename T> 00202 inline bool apply(const ipoint& from, const ipoint& to, 00203 genericMatrix<T>& m, T color) const; 00204 00205 /** 00206 * Render a line from the point f to point t. 00207 * The points in the line will be added to the given list. 00208 */ 00209 inline bool apply(const ipoint& from, const ipoint& to, ipointList& l) const; 00210 00211 /** 00212 * Copy data of "other" functor. 00213 * \param other the functor to be copied 00214 * \return a reference to this functor object 00215 */ 00216 bresenhamLine& copy(const bresenhamLine& other); 00217 00218 /** 00219 * Alias for copy member 00220 * \param other the functor to be copied 00221 * \return a reference to this functor object 00222 */ 00223 bresenhamLine& operator=(const bresenhamLine& other); 00224 00225 /** 00226 * Returns the complete name of the functor class 00227 */ 00228 virtual const std::string& name() const; 00229 00230 /** 00231 * Returns a pointer to a clone of this functor. 00232 */ 00233 virtual bresenhamLine* clone() const; 00234 00235 /** 00236 * Returns a pointer to a new instance of this functor. 00237 */ 00238 virtual bresenhamLine* newInstance() const; 00239 00240 /** 00241 * Returns used parameters 00242 */ 00243 const parameters& getParameters() const; 00244 00245 //TODO: comment the attributes of your functor 00246 // If you add more attributes manually, do not forget to do following: 00247 // 1. indicate in the default constructor the default values 00248 // 2. make sure that the copy member also copy your new attributes, or 00249 // ensure there, that these attributes are properly initialized. 00250 00251 private: 00252 00253 /** 00254 * Implementation of the Bresenham line rendering algorithm. 00255 * This method uses addPoint to store the produced points 00256 * in the given point store. 00257 */ 00258 template<typename POINT_STORE, typename T> 00259 bool renderLine(const int fx, const int fy, 00260 const int tx, const int ty, 00261 POINT_STORE& store, T color) const; 00262 00263 /** 00264 * Adds the given point to the given point list. 00265 */ 00266 template<typename T> 00267 inline void addPoint(const int x, const int y, ipointList& l, T unused) const; 00268 00269 /** 00270 * Draws the given point to the given matrix with the given color. 00271 */ 00272 template<typename T> 00273 inline void addPoint(const int x, const int y, genericMatrix<T>& m, T color) const; 00274 00275 }; 00276 } 00277 00278 #include "cvrBresenhamLine_inline.h" 00279 00280 /* The following include is necesary, so that the renderLine method gets 00281 instantiated for every instantiation of genericMatrix<T> as a point store. Otherwise, 00282 we would need to manually instantiate each apply for every T in genericMatrix<T>. 00283 */ 00284 #include "cvrBresenhamLine_template.h" 00285 00286 #endif 00287