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

ltiPolygonApproximation.h

00001 /*
00002  * Copyright (C) 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 .......: ltiPolygonApproximation.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 16.11.2002
00030  * revisions ..: $Id: ltiPolygonApproximation.h,v 1.9 2006/02/08 11:39:14 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_POLYGON_APPROXIMATION_H_
00034 #define _LTI_POLYGON_APPROXIMATION_H_
00035 
00036 #include "ltiModifier.h"
00037 #include "ltiContour.h"
00038 #include "ltiPolygonPoints.h"
00039 
00040 namespace lti {
00041   /**
00042    * Computes a polygon approximation for a given border point list.
00043    *
00044    * This is just a wrapper functor for the method \c approximate of the
00045    * lti::polygonPoints class.
00046    */
00047   class polygonApproximation : public modifier {
00048   public:
00049     /**
00050      * the parameters for the class polygonApproximation
00051      */
00052     class parameters : public modifier::parameters {
00053     public:
00054       /**
00055        * default constructor
00056        */
00057       parameters();
00058 
00059       /**
00060        * copy constructor
00061        * @param other the parameters object to be copied
00062        */
00063       parameters(const parameters& other);
00064 
00065       /**
00066        * destructor
00067        */
00068       ~parameters();
00069 
00070       /**
00071        * returns name of this type
00072        */
00073       const char* getTypeName() const;
00074 
00075       /**
00076        * copy the contents of a parameters object
00077        * @param other the parameters object to be copied
00078        * @return a reference to this parameters object
00079        */
00080       parameters& copy(const parameters& other);
00081 
00082       /**
00083        * copy the contents of a parameters object
00084        * @param other the parameters object to be copied
00085        * @return a reference to this parameters object
00086        */
00087       parameters& operator=(const parameters& other);
00088 
00089 
00090       /**
00091        * returns a pointer to a clone of the parameters
00092        */
00093       virtual functor::parameters* clone() const;
00094 
00095       /**
00096        * write the parameters in the given ioHandler
00097        * @param handler the ioHandler to be used
00098        * @param complete if true (the default) the enclosing begin/end will
00099        *        be also written, otherwise only the data block will be written.
00100        * @return true if write was successful
00101        */
00102       virtual bool write(ioHandler& handler,const bool complete=true) const;
00103 
00104       /**
00105        * read the parameters from the given ioHandler
00106        * @param handler the ioHandler to be used
00107        * @param complete if true (the default) the enclosing begin/end will
00108        *        be also written, otherwise only the data block will be written.
00109        * @return true if write was successful
00110        */
00111       virtual bool read(ioHandler& handler,const bool complete=true);
00112 
00113 #     ifdef _LTI_MSC_6
00114       /**
00115        * this function is required by MSVC only, as a workaround for a
00116        * very awful bug, which exists since MSVC V.4.0, and still by
00117        * V.6.0 with all bugfixes (so called "service packs") remains
00118        * there...  This method is also public due to another bug, so please
00119        * NEVER EVER call this method directly: use read() instead
00120        */
00121       bool readMS(ioHandler& handler,const bool complete=true);
00122 
00123       /**
00124        * this function is required by MSVC only, as a workaround for a
00125        * very awful bug, which exists since MSVC V.4.0, and still by
00126        * V.6.0 with all bugfixes (so called "service packs") remains
00127        * there...  This method is also public due to another bug, so please
00128        * NEVER EVER call this method directly: use write() instead
00129        */
00130       bool writeMS(ioHandler& handler,const bool complete=true) const;
00131 #     endif
00132 
00133       // ------------------------------------------------
00134       // the parameters
00135       // ------------------------------------------------
00136 
00137       /**
00138        * Minimal "distance" between vertices of the polygon.
00139        *
00140        * if 0 or negative, only the maxDistance parameter will be
00141        * considered).  The "distance" used here is \b NOT the
00142        * euclidean distance between the vertices but the number of
00143        * elements between both vertices in the border list.  These
00144        * is usually therefore a city-block distance or an
00145        * 8-neighborhood distance depending on the border-points
00146        * description used.
00147        *
00148        * Default value: -1 (i.e. use only maxDistance).
00149        */
00150       int minStep;
00151 
00152       /**
00153        * If \c true, the first two vertices will be computed as the two
00154        * points in the border with the maximal distance.
00155        *
00156        * If \c false, the first point in the list will be a vertex and
00157        * the border point with the maximal distance to it too.  This
00158        * faster method is the default.  It provides usually good
00159        * results.
00160        *
00161        * Default value: false
00162        */
00163       bool searchMaxDistance;
00164 
00165       /**
00166        * Specify the maximal allowed \b euclidean distance between the
00167        * border points and the approximated polygon.  (if negative,
00168        * each "minStep" pixel of the border points will be
00169        * taken).
00170        *
00171        * Default value: 1
00172        */
00173       double maxDistance;
00174 
00175       /**
00176        * If \c true, only the found vertices will be in the list.
00177        * If \c false, the last point of the list will be adjacent to the
00178        * first point in the list.
00179        *
00180        * Default: true
00181        */
00182       bool closed;
00183     };
00184 
00185     /**
00186      * default constructor
00187      */
00188     polygonApproximation();
00189 
00190     /**
00191      * Construct a functor using the given parameters
00192      */
00193     polygonApproximation(const parameters& par);
00194 
00195     /**
00196      * copy constructor
00197      * @param other the object to be copied
00198      */
00199     polygonApproximation(const polygonApproximation& other);
00200 
00201     /**
00202      * destructor
00203      */
00204     virtual ~polygonApproximation();
00205 
00206     /**
00207      * returns the name of this type ("polygonApproximation")
00208      */
00209     virtual const char* getTypeName() const;
00210 
00211     /**
00212      * Approximate the given border points as a polygon.
00213      *
00214      * At the end of the approximation process the polygon-points-list
00215      * contains the coordinates of the vertices.
00216      *
00217      * @param src border points with the contour that must be approximated
00218      * @param dest polygon approximation of the contour.
00219      * @return true if apply successful or false otherwise.
00220      */
00221     bool apply(const borderPoints& src,polygonPoints& dest) const;
00222 
00223     /**
00224      * Approximate the given border points as a polygon, ensuring that
00225      * the points in the given point list are inserted as vertices.
00226      * This point list \b must fulfill followint two conditions:
00227      * -# It must have the same sequence than theBorderPoints.
00228      * -# The points must be contained by the theBorderPoints
00229      *
00230      * At the end of the approximation process the polygon-points-list
00231      * contains the coordinates of the vertices.
00232      *
00233      * @param src border points with the contour to be approximated
00234      * @param forcedVertices list of vertices that must be included in
00235      *                       the polygon representation.  This list must be a 
00236      *                       subset and respect  the same ordering as in
00237      *                       theBorderPoints
00238      * @param dest polygon approximation of the contour.
00239      * @return true if apply successful or false otherwise.
00240      */
00241     bool apply(const borderPoints& src,
00242                const pointList& forcedVertices,
00243                polygonPoints& dest) const;
00244 
00245     /**
00246      * copy data of "other" functor.
00247      * @param other the functor to be copied
00248      * @return a reference to this functor object
00249      */
00250     polygonApproximation& copy(const polygonApproximation& other);
00251 
00252     /**
00253      * alias for copy member
00254      * @param other the functor to be copied
00255      * @return a reference to this functor object
00256      */
00257     polygonApproximation& operator=(const polygonApproximation& other);
00258 
00259     /**
00260      * returns a pointer to a clone of this functor.
00261      */
00262     virtual functor* clone() const;
00263 
00264     /**
00265      * returns used parameters
00266      */
00267     const parameters& getParameters() const;
00268 
00269   };
00270 }
00271 
00272 #endif

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