LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiDraw.h

00001 /*
00002  * Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /* -----------------------------------------------------------------------
00025  * project ....: LTI-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiDraw.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 25.5.1998
00030  * revisions ..: $Id: ltiDraw.h,v 1.12 2006/02/07 18:46:12 ltilib Exp $
00031  */
00032 #ifndef _LTI_DRAW_H
00033 #define _LTI_DRAW_H
00034 
00035 
00036 #include <vector>
00037 
00038 #include "ltiTypes.h"
00039 #include "ltiHTypes.h"
00040 #include "ltiImage.h"
00041 #include "ltiContour.h"
00042 #include "ltiIoHandler.h"
00043 #include "ltiPoint.h"
00044 #include "ltiLine.h"
00045 #include "ltiRectangle.h"
00046 #include "ltiLocation.h"
00047 #include "ltiLinearKernels.h"
00048 
00049 #include "ltiDrawBase.h"
00050 
00051 namespace lti {
00052 
00053   /**
00054    * Object for drawing a number of geometric figures and lists
00055    * thereof, simple texts and a few other types with graphic
00056    * representation in a lti::matrix. There are also methods to draw
00057    * Matlab-style markers instead of single pixels for points (see
00058    * marker()).
00059    *
00060    * The type T of this template class corresponds to the type T of the matrix.
00061    *
00062    * Example:
00063    *
00064    * if you want to draw on a channel, you can create an instance of
00065    * the draw-object this way:
00066    *
00067    * \code
00068    * lti::draw<lti::channel::value_type> drawer;  // drawer for channels
00069    * lti::channel canvas(256,256,0.0f);   // a channel to draw on
00070    *
00071    * drawer.use(canvas);                  // draw on canvas
00072    * drawer.setColor(0.5f);               // use gray
00073    * drawer.line(0,0,255,255);            // draw a line from to upper-left
00074    *                                      // to the bottom-right corner.
00075    * \endcode
00076    *
00077    */
00078   template<class T>
00079   class draw : public drawBase<T> {
00080   public:
00081 
00082     /**
00083      * default constructor
00084      */
00085     draw();
00086     /**
00087      * destructor
00088      */
00089     ~draw();
00090 
00091     /**
00092      * get name of this type
00093      */
00094     const char* getTypeName() const;
00095 
00096     /**
00097      * @name Canvas
00098      */
00099     //@{
00100 
00101     /**
00102      * Indicates in which image will be drawn
00103      */
00104     virtual void use(matrix<T>& img);
00105 
00106     /**
00107      * get a reference to the image currently being used.
00108      * \warning if you haven't set any image yet (see use()), an lti::exception
00109      *          will be thrown
00110      */
00111     virtual matrix<T>& getCanvas();
00112 
00113     /**
00114      * get a read-only reference to the image currently being used.
00115      * \warning if you haven't set any image yet (see use()), an lti::exception
00116      *          will be thrown
00117      */
00118     virtual const matrix<T>& getCanvas() const;
00119 
00120     /**
00121      * returns the size of the canvas
00122      */
00123     point getCanvasSize();
00124 
00125     //@}
00126 
00127     /**
00128      * @name Color and Pen-Style Tool selection
00129      */
00130     //@{
00131     
00132     /**
00133      * Specifies color to be used. If the template type is rgbPixel
00134      * this means an actual color. For other template types, this sets
00135      * a gray-level.
00136      */
00137     void setColor(const T& px);
00138 
00139     /**
00140      * Specifies color to be used. If the template type is rgbPixel
00141      * this means an actual color. For other template types, this sets
00142      * a gray-level. Here, MATLAB style specifiers are used. See
00143      * setStyle(const char*) for details.
00144      */
00145     void setColor(const char* color);
00146 
00147     /**
00148      * Specifies gray-level to be used.
00149      */
00150     void setGray(const float k);
00151 
00152 
00153     /**
00154      * Get color being used
00155      */
00156     const T& getColor() const;
00157 
00158     //@}
00159 
00160     /**
00161      * @name Whole canvas operators
00162      */
00163     //@{
00164     /**
00165      * scale each pixel value with the given constant
00166      */
00167     void scale(const double factor);
00168     
00169     /**
00170      * fills the canvas with the actual color
00171      */
00172     void clear();
00173 
00174     /**
00175      * fill the canvas with the current color, starting at the given
00176      * seed until a color different to the original one at the seed is
00177      * found.  This is similar to the fill tools usually found in
00178      * paint programs.
00179      */
00180     void fill(const point& seed);
00181 
00182     /**
00183      * fill the canvas with the current color, starting at the given
00184      * seed until a color different to the original one at the seed is
00185      * found.  This is similar to the fill tools usually found in
00186      * paint programs.
00187      */
00188     inline void fill(const int x,const int y) {
00189       fill(point(x,y));
00190     }
00191 
00192     /**
00193      * fillUntil fills the canvas with the current color, 
00194      * starting at the given seed until the stop color is reached.
00195      */
00196     void fillUntil(const point& seed,const T& stopColor);
00197 
00198     /**
00199      * fillUntil fill the canvas with the current color, 
00200      * starting at the given seed until the stop color is reached.
00201      */
00202     inline void fillUntil(const int x,const int y,const T& stopColor) {
00203       fillUntil(point(x,y),stopColor);
00204     }
00205 
00206     //@}
00207 
00208     /**
00209      * @name Points and Lines
00210      */
00211     //@{
00212 
00213     /**
00214      * Set pixel at x,y in the color set by setColor().
00215      * @param x x-coordinate of the pixel to be set.
00216      * @param y y-coordinate of the pixel to be set.
00217      */
00218     void set(const int x, const int y);
00219 
00220     /**
00221      * Set pixel at p in the color set by setColor().
00222      * @param p coordinates of the pixel to be set
00223      */
00224     void set(const point& p) {set(p.x,p.y);};
00225 
00226     /**
00227      * Set pixel at p in the color set by setColor().
00228      * @param p coordinates of the pixel to be set
00229      */
00230     template<class U>
00231     void set(const hPoint2D<U>& p) {
00232       set(p.x/p.h,p.y/p.h);
00233     };
00234 
00235     /**
00236      * Draw a line from the point (fx,fy) to point (tx,ty).
00237      * The "last point" will be defined with the last "set", "line" or
00238      * "lineTo" method.
00239      */
00240     void line(const int fx, const int fy,
00241               const int tx, const int ty);
00242 
00243     /**
00244      * Draw a line from the point p to point p2.
00245      * @see line(int,int,int,int)
00246      */
00247     void line(const point& p1,const point& p2) {
00248       line(p1.x,p1.y,p2.x,p2.y);
00249     }
00250 
00251     /**
00252      * Draw a line 
00253      * @see line(int,int,int,int)
00254      */
00255     void line(const tline<int>& l) {
00256       line(l.getStart(),l.getEnd());
00257     }
00258 
00259     /**
00260      * the homogeneus point p represents also a line, which equation is
00261      * given by p.x*x + p.y*y + p.h*1 = 0.  This line is drawn with this
00262      * member
00263      */
00264     template <class U>
00265     void line(const hPoint2D<U>& p) {
00266       if (isNull(img)) {
00267         return;
00268       }
00269       if (p.x != U(0)) {
00270         line(-p.h/p.x,0,(-p.y*(img->lastRow())-p.h)/p.x,img->lastRow());
00271       } else if (p.y != U(0)) {
00272         line(0,-p.h/p.y,img->lastColumn(),(-p.x*(img->lastColumn())-p.h)/p.y);
00273       }
00274     }
00275 
00276     /**
00277      * Draw a line from the last point to (x,y).
00278      * The "last point" will be defined with the last "set", "point", "line" or
00279      * "lineTo" method.
00280      */
00281     void lineTo(const int x, const int y);
00282 
00283     /**
00284      * Draw a line from the last point to the point p.
00285      * The "last point" will be defined with the last "set", "point", "line" or
00286      * "lineTo" method.
00287      */
00288     void lineTo(const point& p) {
00289       lineTo(p.x,p.y);
00290     }
00291 
00292     /**
00293      * Draws a vertical line from (x,y1) to (x,y2).
00294      */
00295     void verticalLine(const int x, const int y1, const int y2);
00296 
00297     /**
00298      * Draws a vertical line from (p1.x,p1.y) to (p1.x,p2.y).
00299      */
00300     void verticalLine(const point& p1, const point& p2);
00301 
00302     /**
00303      * Draws a horizontal line from (x1,y) to (x2,y).
00304      */
00305     void horizontalLine(const int x1, const int x2, const int y);
00306 
00307     /**
00308      * Draws a horizontal line from (p1.x,p1.y) to (p2.x,p1.y).
00309      */
00310     void horizontalLine(const point& p1, const point& p2);
00311     //@}
00312 
00313     /**
00314      * @name Simple polygons and other geometric primitives
00315      */
00316     //@{
00317 
00318     /**
00319      * draw an arrow. arrow tip will be at (tx,ty).
00320      * If size<1.0 then tipsize will be the relative portion of arrow length.
00321      * If size>1.0 then tipsize will be (int)size, independent of arrow length.
00322      */
00323     void arrow(const int fx, const int fy,
00324                const int tx, const int ty,
00325                const float& size=0.2f);
00326 
00327 
00328     /**
00329      * draw an arrow from point p1 to point p2
00330      */
00331     void arrow(const point& p1,const point& p2,const float& size=0.2f){
00332       arrow(p1.x,p1.y,p2.x,p2.y,size);
00333     };
00334 
00335     /**
00336      * draw a box
00337      *
00338      * \deprecated use rectangle(const rectangle&, const bool&) instead!
00339      *
00340      * @param r rectangle (with orientation 0)
00341      * @param filled true if the box must be filled, false if only the
00342      *               border needs to be drawn.
00343      */
00344     void box(const trectangle<int>& r, const bool& filled=false) {
00345       box(r.ul.x,r.ul.y,r.br.x,r.br.y,filled);
00346     }
00347 
00348     /**
00349      * draw a rotated box
00350      *
00351      * \deprecated use rectangle(const rectangle&, const float, const bool&)
00352      * instead!
00353      *
00354      * @param r rectangle (with orientation 0)
00355      * @param angle rotation angle at the middle point of the box
00356      * @param filled true if the box must be filled, false if only the
00357      *               border needs to be drawn.
00358      */
00359     void box(const trectangle<int>& r, const float angle, const bool& filled) {
00360       box(r.ul.x,r.ul.y,r.br.x,r.br.y,angle,filled);
00361     }
00362 
00363     /**
00364      * draw a box
00365      *
00366      * \deprecated use rectangle(const point&, const point&, const bool&)
00367      * instead!
00368      * 
00369      * @param upperLeft upper left corner of the rectangle with orientation 0
00370      * @param bottomRight bottom right corner of the rectangle with orientation
00371      *                    0
00372      * @param filled true if the box must be filled, false if only the
00373      *               border needs to be drawn.
00374      * @see box(int,int,int,int,const bool&)
00375      */
00376     void box(const point& upperLeft, const point& bottomRight,
00377              const bool& filled=false) {
00378       box(upperLeft.x,upperLeft.y,bottomRight.x,bottomRight.y,filled);
00379     }
00380 
00381     /**
00382      * draw a box
00383      *
00384      * \deprecated use rectangle(const point&, const point&, float, const bool&) instead!
00385      * 
00386      * @param upperLeft upper left corner of the rectangle with orientation 0
00387      * @param bottomRight bottom right corner of the rectangle with orientation
00388      *                    0
00389      * @param angle rotation angle at the middle point of the box
00390      * @param filled true if the box must be filled, false if only the
00391      *               border needs to be drawn.
00392      * @see box(int,int,int,int,const bool&)
00393      */
00394     void box(const point& upperLeft, const point& bottomRight,
00395              const float angle,
00396              const bool& filled=false) {
00397       box(upperLeft.x,upperLeft.y,bottomRight.x,bottomRight.y,angle,filled);
00398     }
00399 
00400     /**
00401      * draw a box.
00402      *
00403      * \deprecated use rectangle(int, int, int, int, const bool&) instead!
00404      *
00405      * @param xl left x-coordinate.
00406      * @param yu upper y-coordinate.
00407      * @param xr right x-coordinate.
00408      * @param yb bottom y-coordinate.
00409      * @param filled if true box is filled
00410      */
00411     void box(const int xl,const  int yu,
00412              const int xr,const int yb, const bool& filled=false) {
00413       rectangle(xl,yu,xr,yb,filled);
00414     }
00415 
00416     /**
00417      * draw a rotated box.
00418      *
00419      * \deprecated use rectangle(int, int, int, int, float, const bool&)
00420      * instead!
00421      *
00422      * @param xl left x-coordinate.
00423      * @param yu upper y-coordinate.
00424      * @param xr right x-coordinate.
00425      * @param yb bottom y-coordinate.
00426      * @param angle rotation angle at the middle point of the box
00427      * @param filled if true box is filled
00428      */
00429     void box(const int xl,const  int yu,
00430              const int xr,const int yb,
00431              const float angle,
00432              const bool& filled=false) {
00433       rectangle(xl,yu,xr,yb,angle,filled);
00434     }
00435 
00436     /**
00437      * draw a rectangle
00438      * @param r rectangle (with orientation 0)
00439      * @param filled true if the rectangle must be filled, false if only the
00440      *               border needs to be drawn.
00441      */
00442     void rectangle(const trectangle<int>& r, const bool& filled=false) {
00443       rectangle(r.ul.x,r.ul.y,r.br.x,r.br.y,filled);
00444     }
00445 
00446     /**
00447      * draw a rotated rectangle
00448      * @param r rectangle (with orientation 0)
00449      * @param angle rotation angle at the middle point of the rectangle
00450      * @param filled true if the rectangle must be filled, false if only the
00451      *               border needs to be drawn.
00452      */
00453     void rectangle(const trectangle<int>& r, const float angle,
00454                    const bool& filled) {
00455       rectangle(r.ul.x,r.ul.y,r.br.x,r.br.y,angle,filled);
00456     }
00457 
00458     /**
00459      * draw a rectangle
00460      * @param upperLeft upper left corner of the rectangle with orientation 0
00461      * @param bottomRight bottom right corner of the rectangle with orientation
00462      *                    0
00463      * @param filled true if the rectangle must be filled, false if only the
00464      *               border needs to be drawn.
00465      * @see rectangle(int,int,int,int,const bool&)
00466      */
00467     void rectangle(const point& upperLeft, const point& bottomRight,
00468              const bool& filled=false) {
00469       rectangle(upperLeft.x,upperLeft.y,bottomRight.x,bottomRight.y,filled);
00470     }
00471 
00472     /**
00473      * draw a rectangle
00474      * @param upperLeft upper left corner of the rectangle with orientation 0
00475      * @param bottomRight bottom right corner of the rectangle with orientation
00476      *                    0
00477      * @param angle rotation angle at the middle point of the rectangle
00478      * @param filled true if the rectangle must be filled, false if only the
00479      *               border needs to be drawn.
00480      * @see rectangle(int,int,int,int,const bool&)
00481      */
00482     void rectangle(const point& upperLeft, const point& bottomRight,
00483              const float angle,
00484              const bool& filled=false) {
00485       rectangle(upperLeft.x,upperLeft.y,bottomRight.x,bottomRight.y,angle,filled);
00486     }
00487 
00488     /**
00489      * draw a rectangle.
00490      * @param xl left x-coordinate.
00491      * @param yu upper y-coordinate.
00492      * @param xr right x-coordinate.
00493      * @param yb bottom y-coordinate.
00494      * @param filled if true rectangle is filled
00495      */
00496     void rectangle(const int xl,const  int yu,
00497              const int xr,const int yb, const bool& filled=false);
00498 
00499     /**
00500      * draw a rectangle.
00501      * @param xl left x-coordinate.
00502      * @param yu upper y-coordinate.
00503      * @param xr right x-coordinate.
00504      * @param yb bottom y-coordinate.
00505      * @param angle rotation angle at the middle point of the rectangle
00506      * @param filled if true rectangle is filled
00507      */
00508     void rectangle(const int xl,const  int yu,
00509                    const int xr,const int yb,
00510                    const float angle,
00511                    const bool& filled=false);
00512 
00513     /**
00514      * draw a polygon represented by the given polygonPoints list
00515      * optionally, it can be rotated by the given angle and shifted
00516      * @param poly the polygon vertices
00517      * @param filled true if the polygon must be filled, false otherwise
00518      * @param angle rotation angle on the mean point of the vertices
00519      * @param shift shift amount to the polygon points.
00520      */
00521     void polygon(const polygonPoints& poly,
00522                  const bool filled=false,
00523                  const float angle=0.0f,
00524                  const point& shift=point(0,0));
00525 
00526 
00527     /**
00528      * draw a circle with circle center 'p1' and radius 'r'
00529      */
00530     void circle(const point& p1,const int r, const bool& filled=false);
00531 
00532     /**
00533      * draw a circle with circle center (x,y) and radius 'r'
00534      */
00535     inline void circle(const int x,const int y,
00536                 const int r, 
00537                 const bool& filled=false) {
00538       circle(point(x,y),r,filled);
00539     }
00540 
00541     /**
00542      * draw an ellipse with center 'p1' and main axes 'aX' and 'aY'
00543      */
00544     void ellipse(const point& p1,const int aX, const int aY,
00545                  const bool& filled=false);
00546 
00547     /**
00548      * draw an ellipse with center 'p1' and main axes 'aX' and 'aY'
00549      */
00550     void ellipse(const point& p1,const int aX, const int aY,
00551                  const float& angle, const bool& filled=false);
00552 
00553     /**
00554      * draw an arc from 'pA' to 'pB', clockwise around center 'p1'.
00555      */
00556     void arc(const point& p1, const point& pA, const point& pB);
00557     //@}
00558 
00559     /**
00560      * @name Tools for other lti::objects
00561      */
00562     //@{
00563     
00564     /**
00565      * Sets pixels at all points in c, moved by he given offset.
00566      */
00567     void set(const pointList& c, const point& offset=point(0,0)) {
00568       drawBase<T>::set(c,offset);    
00569     }
00570 
00571     /**
00572      * draw a location.
00573      *
00574      * @param loc location with position, angle and radius
00575      * @param showAngleLine if true, a line from the middle point of the
00576      *        location (given by loc.position) with the angle given by
00577      *        loc.angle will be drawn.
00578      */
00579     void set(const location& loc,const bool showAngleLine = false) {
00580       drawBase<T>::set(loc,showAngleLine);
00581     }
00582 
00583     /**
00584      * draw a rectLocation
00585      *
00586      * @param loc location with position, angle and radius
00587      * @param showAngleLine if true, a line from the middle point of the
00588      *        location (given by loc.position) with the angle given by
00589      *        loc.angle will be drawn.
00590      */
00591     void set(const rectLocation& loc,const bool showAngleLine = false) {
00592       drawBase<T>::set(loc,showAngleLine);
00593     }
00594 
00595     /**
00596      * draw a list of locations
00597      */
00598     void set(const std::list<location>& locs,
00599              const bool showAngleLine = false) {
00600       drawBase<T>::set(locs,showAngleLine);
00601     }
00602 
00603     /**
00604      * draw the contents of the vector using the whole image
00605      * @param vct the vector to be shown
00606      * @param axisColor color for the axis.  The vector will be drawn in the
00607      *                  default color (see setColor())
00608      * @param forceAxis0 if true, both axis will be shown, i.e. the value 0 for
00609      *                  the vector will be always shown.  If false, only the
00610      *                  required value-range will be shown
00611      */
00612     void set(const dvector& vct,
00613              const T& axisColor,
00614              const bool& forceAxis0 = true);
00615 
00616     /**
00617      * draw the contents of the vector using the whole image
00618      * @param vct the vector to be shown
00619      * @param axisColor color for the axis.  The vector will be drawn in the
00620      *                  default color (see setColor())
00621      * @param forceAxis0 if true, both axis will be shown, i.e. the value 0 for
00622      *                  the vector will be always shown.  If false, only the
00623      *                  required value-range will be shown
00624      */
00625     void set(const fvector& vct,
00626              const T& axisColor,
00627              const bool& forceAxis0 = true);
00628 
00629     /**
00630      * draw the contents of the vector using the whole image
00631      * @param vct the vector to be shown
00632      * @param axisColor color for the axis.  The vector will be drawn in the
00633      *                  default color (see setColor())
00634      * @param forceAxis0 if true, both axis will be shown, i.e. the value 0 for
00635      *                  the vector will be always shown.  If false, only the
00636      *                  required value-range will be shown     
00637      */
00638     void set(const ivector& vct,
00639              const T& axisColor,
00640              const bool& forceAxis0 = true);
00641 
00642     /**
00643      * Draws a grid in the image.
00644      * The interpretation of delta depends on the value of interval.
00645      * if interval is true, the values are taken as number of pixels
00646      * between two grid lines in x and y direction. Otherwise, it
00647      * is used as number of grid lines.
00648      */
00649     void grid(const point& delta, const bool interval=true);
00650 
00651     /**
00652      * overlay the given channel using the actual color
00653      * The new pixel color is calculated as (1-c)*old_pixel_color+c*used_color,
00654      * where c is the channel color and used_color is the color set with
00655      * setColor().
00656      * The given channel will be overlayed at the given position
00657      * (default 0,0)
00658      * @param overlay channel to be overlayed
00659      * @param x position at x (the column)
00660      * @param y position at y (the row)
00661      */
00662     void overlay(const channel& overlay,const int x = 0, const int y = 0);
00663 
00664     /**
00665      * overlay the given channel using the actual color
00666      * The new pixel color is calculated as (1-c)*old_pixel_color+c*used_color,
00667      * where c is the channel color and used_color is the color set with
00668      * setColor().
00669      * The given channel will be overlayed at the given position
00670      * (default 0,0)
00671      * @param overlay channel to be overlayed
00672      * @param p position where <code>overlay</code> will be placed
00673      */
00674     void overlay(const channel& overlay,const point& p);
00675 
00676     /**
00677      * overlay the given channel8 using the actual color
00678      * The new pixel color is calculated as
00679      * ((255-c)*old_pixel_color+c*used_color)/255,
00680      * where c is the channel color and used_color is the color set with
00681      * setColor()
00682      * @param overlay channel8 to be overlayed
00683      * @param x position at x (the column)
00684      * @param y position at y (the row)
00685      */
00686     void overlay(const channel8& overlay,const int x = 0, const int y = 0);
00687 
00688     /**
00689      * overlay the given channel8 using the actual color
00690      * The new pixel color is calculated as
00691      * ((255-c)*old_pixel_color+c*used_color)/255,
00692      * where c is the channel color and used_color is the color set with
00693      * setColor()
00694      * @param overlay channel to be overlayed
00695      * @param p position where <code>overlay</code> will be placed
00696      */
00697     void overlay(const channel8& overlay,const point& p);
00698     //@}
00699 
00700     /**
00701      * @name Simple text drawing tools
00702      */
00703     //@{
00704 
00705 
00706     /**
00707      * draw an integer <code>num</code> at position 'p1' with size 's'.
00708      * 's' must be given as quota of image height (0.0 to 1.0).
00709      *
00710      * @see text()
00711      *
00712      * @param num the number to be written
00713      * @param p1 the position where the number will be drawn
00714      * @param s scale factor as quota of image height
00715      */
00716     void number(const int num,
00717                 const point& p1 = point(0,0),
00718                 const float& s = 0.03125f);
00719 
00720     /**
00721      * draw an integer <code>num</code> at position 'x'/'y' with size 's'.
00722      * 's' must be given as quota of image height (0.0 to 1.0).
00723      * @see text()
00724      * @param num the number to be written
00725      * @param x the column where the number will be drawn
00726      * @param y the row where the number will be drawn
00727      * @param s scale factor as quota of image height
00728      */
00729     void number(const int num,
00730                 const int x,
00731                 const int y,
00732                 const float& s);
00733 
00734     /**
00735      * draw an integer <code>num</code> at position 'x'/'y' with size 's'.
00736      * 's' must be given as quota of image height (0.0 to 1.0).
00737      * @see text()
00738      * @param num the number to be written
00739      * @param x the column where the number will be drawn
00740      * @param y the row where the number will be drawn
00741      */
00742     void number(const int num,
00743                 const int x,
00744                 const int y) {
00745       number(num,x,y,0.03125f);
00746     }
00747 
00748     /**
00749      * Draw the given text at the position <code>upperleft</code> with
00750      * a specified scale.
00751      * scale.x and scale.y must have values greater than zero.
00752      * The original size of one character is 8x8.
00753      * With the parameter opaqueness you can make transparent text.
00754      * Opaqueness = 1.0f means no transparency.
00755      * If <code>horizontal</code> is true the text is writen from left
00756      * to right.
00757      * @param txt the output text
00758      * @param upperleft the coordinates in the image where the text will be
00759      *                  written
00760      * @param scale a point with the (integer) scaling factor greater or equal
00761      *              one for each coordinate.  Note that you can use different
00762      *              scales for the width and height of the caracters
00763      * @param opaqueness value in percent (between 0.0f and 1.0f)
00764      * @param horizontal true left to rigth, false top to bottom
00765      */
00766     void text(const std::string txt,
00767               const point& upperleft = point(0,0),
00768               const point& scale = point(1,1),
00769               const float opaqueness = 1.0f,
00770               const bool horizontal = true);
00771 
00772 
00773     /**
00774      * Draw the given text at the position <code>upperleft</code> with
00775      * a specified scale.
00776      * scale.x and scale.y must have values greater than zero.
00777      * The original size of one character is 8x8.
00778      * With the parameter opaqueness you can make transparent text.
00779      * Opaqueness = 1.0f means no transparency.
00780      * If <code>horizontal</code> is true the text is writen from left
00781      * to right.
00782      * @param txt the output text
00783      * @param x the x coordinate in the image where the text will be
00784      *                written
00785      * @param y the y coordinate in the image where the text will be
00786      *                written
00787      * @param scale a point with the (integer) scaling factor greater or equal
00788      *              one for each coordinate.  Note that you can use different
00789      *              scales for the width and height of the caracters
00790      * @param opaqueness value in percent (between 0.0f and 1.0f)
00791      * @param horizontal true left to rigth, false top to bottom
00792      */
00793     void text(const std::string txt,
00794               const int x,
00795               const int y,
00796               const point& scale,
00797               const float opaqueness,
00798               const bool horizontal);
00799 
00800     /**
00801      * Draw the text string txt at position x,y.
00802      * @see text(const std::string,const int,const int,const point&,
00803      *           const float,const bool)
00804      */
00805     void text(const std::string txt,const int x, const int y) {
00806       text(txt,x,y,point(1,1),1.0f,true);
00807     };
00808 
00809     //@}
00810 
00811   protected:
00812     /**
00813      * the "actual" image
00814      */
00815     matrix<T> *img;
00816 
00817     /**
00818      * Color in use
00819      */
00820     T actColor;
00821 
00822     /**
00823      * Returns "true" if the point is within the image
00824      */
00825     inline bool inCanvas(const point& p) const;
00826 
00827     /**
00828      * Returns "true" if the point is within the image
00829      */
00830     inline bool inCanvas(const int x,const int y) const;
00831 
00832     /**
00833      * Checks if the line-segment between (x,y) and (x2,y2) lies
00834      * within the image.  If (x,y) lays out of the image boudaries
00835      * it will be "transformed" to a point in the image
00836      */
00837     bool correctLine (int &x,int &y,const int x2, const int y2);
00838 
00839     /**
00840      * This is need for drawing filled rotated ellipses
00841      */
00842     inline static point turnPoint(const float x, const float y, float angle) {
00843       float sa,ca;
00844       sincos(angle, sa, ca);
00845       return lti::point(iround(x*ca-y*sa),
00846                         iround(x*sa+y*ca));
00847     };
00848 
00849     /**
00850      * This is need for drawing filled rotated ellipses
00851      * this enters a point into the point list, the first one into x1
00852      * the second one into x2
00853      * if any more come, they are merged into the closest one.
00854      *
00855      * The vectors x1 and x2 can be seen as input- or output point lists, while
00856      * miny and maxy contain the range of y values used until now.
00857      *
00858      * You must ensure that the x1 and x2 arrays are bigger than the
00859      * value contained in p.y.
00860      */
00861     inline void enterPX(const point& p,
00862                         int* x1, int* x2, int& miny, int& maxy) {
00863       if ((p.y >= 0) && (p.y < img->rows())) {
00864         x1[p.y]=lti::min(x1[p.y],p.x);
00865         x2[p.y]=lti::max(x2[p.y],p.x);
00866         if (p.y < miny) {
00867           miny=p.y;
00868         }
00869         if (p.y > maxy) {
00870           maxy=p.y;
00871         }
00872       }
00873     };
00874 
00875     /**
00876      * Draws a symbol set with the method setStyle() at the given
00877      * position. Used by the marker() methods.
00878      */
00879     void drawSymbol(const int x,const int y);
00880 
00881     /**
00882      * Draws a symbol at the given location.  Used by the marker()
00883      * methods.
00884      */
00885     void drawSymbol(const int x, const int y,const int w,
00886                     const typename drawBase<T>::eMarkerType t);
00887 
00888     /**
00889      * Draws a symbol at the given location.  Used by the marker() methods.
00890      */
00891     void drawSymbol(const int x,const int y,const int w,const char* style);
00892 
00893   };
00894 
00895 
00896   template<class T>
00897   inline bool draw<T>::inCanvas(const int x,const int y) const {
00898     assert(img != 0);
00899     return ((static_cast<unsigned int>(x) <
00900              static_cast<unsigned int>(img->columns())) &&
00901             (static_cast<unsigned int>(y) <
00902              static_cast<unsigned int>(img->rows())));
00903   }
00904 
00905   template<class T>
00906   inline bool draw<T>::inCanvas(const point& p) const {
00907     assert(img != 0);
00908     return ((static_cast<unsigned int>(p.x) <
00909              static_cast<unsigned int>(img->columns())) &&
00910             (static_cast<unsigned int>(p.y) <
00911              static_cast<unsigned int>(img->rows())));
00912   }
00913 
00914 }
00915 
00916 #endif

Generated on Sat Apr 10 15:25:23 2010 for LTI-Lib by Doxygen 1.6.1