CVR-Lib last update 20 Sep 2009

cvrBresenhamCircle.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998-2005
00003  * Peter Doerfler
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   cvrBresenhamCircle.h
00043  *         Contains the functor bresenhamCircle.
00044  * \author Peter Doerfler
00045  * \date   30.07.2005
00046  *
00047  * revisions ..: $Id: cvrBresenhamCircle.h,v 1.2 2005/08/09 14:34:33 arndh Exp $
00048  */
00049 
00050 #ifndef _CVR_BRESENHAM_CIRCLE_H_
00051 #define _CVR_BRESENHAM_CIRCLE_H_
00052 
00053 #include "cvrFunctor.h"
00054 #include "cvrGenericMatrix.h"
00055 #include "cvrPointList.h"
00056 #include "cvrLattice1D.h"
00057 
00058 namespace cvr {
00059 
00060   /**
00061    * Functor for rendering circle segments with the Bresenham circle
00062    * drawing algorithm.
00063    *
00064    * The apply methods take the first and last points of the circle
00065    * segment, and an object where to store the points. Currently two
00066    * types of point stores are supported:
00067    *
00068    * - genericMatrix<T>, in which points are drawn with a given value of T
00069    * - ipointList, in which points are stored in the list
00070    *
00071    * Additional point stores may be added, see the addPoint() method.
00072    *
00073    */
00074   class bresenhamCircle : public functor {
00075   public:
00076     /**
00077      * The parameters for the class bresenhamCircle
00078      */
00079     class parameters : public functor::parameters {
00080     public:
00081       /**
00082        * Default constructor
00083        */
00084       parameters();
00085 
00086       /**
00087        * Copy constructor
00088        * \param other the parameters object to be copied
00089        */
00090       parameters(const parameters& other);
00091 
00092       /**
00093        * Destructor
00094        */
00095       ~parameters();
00096 
00097       /**
00098        * Copy the contents of a parameters object
00099        * \param other the parameters object to be copied
00100        * \return a reference to this parameters object
00101        */
00102       parameters& copy(const parameters& other);
00103 
00104       /**
00105        * Copy the contents of a parameters object
00106        * \param other the parameters object to be copied
00107        * \return a reference to this parameters object
00108        */
00109       parameters& operator=(const parameters& other);
00110 
00111       /**
00112        * Returns the complete name of the parameters class.
00113        */
00114       virtual const std::string& name() const;
00115 
00116       /**
00117        * Returns a pointer to a clone of the parameters.
00118        */
00119       virtual parameters* clone() const;
00120 
00121       /**
00122        * Returns a pointer to a new instance of the parameters.
00123        */
00124       virtual parameters* newInstance() const;
00125 
00126       /**
00127        * Write the parameters in the given ioHandler
00128        * \param handler the ioHandler to be used
00129        * \param complete if true (the default) the enclosing begin/end will
00130        *        be also written, otherwise only the data block will be written.
00131        * \return true if write was successful
00132        */
00133       virtual bool write(ioHandler& handler,const bool complete=true) const;
00134 
00135       /**
00136        * Read the parameters from the given ioHandler
00137        * \param handler the ioHandler to be used
00138        * \param complete if true (the default) the enclosing begin/end will
00139        *        be also written, otherwise only the data block will be written.
00140        * \return true if write was successful
00141        */
00142       virtual bool read(ioHandler& handler,const bool complete=true);
00143 
00144       // ------------------------------------------------
00145       // the parameters
00146       // ------------------------------------------------
00147 
00148       //TODO: comment the parameters of your functor
00149       // If you add more parameters manually, do not forget to do following:
00150       // 1. indicate in the default constructor the default values
00151       // 2. make sure that the copy member also copy your new parameters
00152       // 3. make sure that the read and write members also read and
00153       //    write your parameters
00154 
00155 
00156     };
00157 
00158     /**
00159      * Default constructor
00160      */
00161     bresenhamCircle();
00162 
00163     /**
00164      * Construct a functor using the given parameters
00165      */
00166     bresenhamCircle(const parameters& par);
00167 
00168     /**
00169      * Copy constructor
00170      * \param other the object to be copied
00171      */
00172     bresenhamCircle(const bresenhamCircle& other);
00173 
00174     /**
00175      * Destructor
00176      */
00177     virtual ~bresenhamCircle();
00178 
00179     /**
00180      * Render a circle with center \a (cx,cy) and radius \a radius.
00181      *
00182      * The circle will be drawn to the given genericMatrix<T> instance,
00183      * using the given color.
00184      *
00185      * @param cx x-coord of center
00186      * @param cy y-coord of center
00187      * @param radius radius of the circle
00188      * @param m matrix the circle is drawn into
00189      * @param color color the circle is drawn in
00190      */
00191     template<typename T>
00192     inline bool apply(const int cx, const int cy,
00193                       const int radius,
00194                       genericMatrix<T>& m, T color) const;
00195 
00196     /**
00197      * Render a circle with center \a (cx,cy) and radius \a radius.
00198      *
00199      * The point will be added to the given pointlist \a l.
00200      *
00201      * @param cx x-coord of center
00202      * @param cy y-coord of center
00203      * @param radius radius of the circle
00204      * @param l pointlist the points are added to
00205      */
00206     inline bool apply(const int cx, const int cy,
00207                       const int radius,
00208                       ipointList& l) const;
00209 
00210     /**
00211      * Render a circle with center \a center and radius \a radius.
00212      *
00213      * The circle will be drawn to the given genericMatrix<T> instance,
00214      * using the given color.
00215      *
00216      * @param center center of the circle
00217      * @param radius radius of the circle
00218      * @param m matrix the circle is drawn into
00219      * @param color color the circle is drawn in
00220      */
00221     template<typename T>
00222     inline bool apply(const ipoint& center, const int radius,
00223                       genericMatrix<T>& m, T color) const;
00224 
00225     /**
00226      * Render a circle with center \a center and radius \a radius.
00227      *
00228      * The point will be added to the given pointlist \a l.
00229      *
00230      * @param center center of the circle
00231      * @param radius radius of the circle
00232      * @param l pointlist the points are added to
00233      */
00234     inline bool apply(const ipoint& center, const int radius,
00235                       ipointList& l) const;
00236 
00237     /**
00238      * Render a circle with radius \a radius.
00239      *
00240      * The outmost x-coordinates of each y-coordinate will be added to
00241      * the given lattice1D \a ioPts. This lattice1D can then be used as io
00242      * points for sampling a circle area.
00243      *
00244      * @param radius radius of the circle
00245      * @param ioPts lattice1D containing io coordinates
00246      */
00247     inline bool apply(const int radius, lattice1D<int>& ioPts) const;
00248 
00249     /**
00250      * Copy data of "other" functor.
00251      * \param other the functor to be copied
00252      * \return a reference to this functor object
00253      */
00254     bresenhamCircle& copy(const bresenhamCircle& other);
00255 
00256     /**
00257      * Alias for copy member
00258      * \param other the functor to be copied
00259      * \return a reference to this functor object
00260      */
00261     bresenhamCircle& operator=(const bresenhamCircle& other);
00262 
00263     /**
00264      * Returns the complete name of the functor class
00265      */
00266     virtual const std::string& name() const;
00267 
00268     /**
00269      * Returns a pointer to a clone of this functor.
00270      */
00271     virtual bresenhamCircle* clone() const;
00272 
00273     /**
00274      * Returns a pointer to a new instance of this functor.
00275      */
00276     virtual bresenhamCircle* newInstance() const;
00277 
00278     /**
00279      * Returns used parameters
00280      */
00281     const parameters& getParameters() const;
00282 
00283     //TODO: comment the attributes of your functor
00284     // If you add more attributes manually, do not forget to do following:
00285     // 1. indicate in the default constructor the default values
00286     // 2. make sure that the copy member also copy your new attributes, or
00287     //    ensure there, that these attributes are properly initialized.
00288 
00289   private:
00290 
00291     /**
00292      * Implementation of the Bresenham circle rendering algorithm.
00293      * This method uses addPoint to store the produced points
00294      * in the given point store.
00295      */
00296     template<typename POINT_STORE, typename T>
00297     bool renderCircle(const int cx, const int cy, const int rad,
00298                       POINT_STORE& store, T color) const;
00299 
00300     /**
00301      * Adds the given point plus symmetric points to the given point
00302      * list.
00303      */
00304     template<typename T>
00305     inline void addPoints(const int cx, const int cy,
00306                           const int x, const int y,
00307                           ipointList& l, T unused) const;
00308 
00309     /**
00310      * Adds the given point plus symmetric points to the given ilattice1D.
00311      */
00312     template<typename T>
00313     inline void addPoints(const int cx, const int cy,
00314                           const int x, const int y,
00315                           lattice1D<int>& arr, T unused) const;
00316 
00317     /**
00318      * Draws the given point plus symmetric points to the given matrix
00319      * with the given color.
00320      */
00321     template<typename T>
00322     inline void addPoints(const int cx, const int cy,
00323                           const int x, const int y,
00324                           genericMatrix<T>& m, T color) const;
00325 
00326     /**
00327      * Sets the point \a (x,y) in \a m to \a color if 0<=x<mx
00328      * and 0<=y<m<.
00329      */
00330     template<typename T>
00331     inline void setPoint(const int x, const int y,
00332                          const int mx, const int my,
00333                          genericMatrix<T>& m, T color) const;
00334 
00335   };
00336 }
00337 
00338 #include "cvrBresenhamCircle_inline.h"
00339 
00340 /* The following include is necesary, so that the renderCircle method
00341    gets instantiated for every instantiation of genericMatrix<T> as a
00342    point store. Otherwise, we would need to manually instantiate each
00343    apply for every T in genericMatrix<T>.
00344 */
00345 #include "cvrBresenhamCircle_template.h"
00346 
00347 #endif
00348 

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8