Image Component Library (ICL)
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RDPApproximation.h
Go to the documentation of this file.
00001 /********************************************************************
00002 **                Image Component Library (ICL)                    **
00003 **                                                                 **
00004 ** Copyright (C) 2006-2013 CITEC, University of Bielefeld          **
00005 **                         Neuroinformatics Group                  **
00006 ** Website: www.iclcv.org and                                      **
00007 **          http://opensource.cit-ec.de/projects/icl               **
00008 **                                                                 **
00009 ** File   : ICLCV/src/ICLCV/RDPApproximation.h                     **
00010 ** Module : ICLCV                                                  **
00011 ** Authors: Sergius Gaulik                                         **
00012 **                                                                 **
00013 **                                                                 **
00014 ** GNU LESSER GENERAL PUBLIC LICENSE                               **
00015 ** This file may be used under the terms of the GNU Lesser General **
00016 ** Public License version 3.0 as published by the                  **
00017 **                                                                 **
00018 ** Free Software Foundation and appearing in the file LICENSE.LGPL **
00019 ** included in the packaging of this file.  Please review the      **
00020 ** following information to ensure the license requirements will   **
00021 ** be met: http://www.gnu.org/licenses/lgpl-3.0.txt                **
00022 **                                                                 **
00023 ** The development of this software was supported by the           **
00024 ** Excellence Cluster EXC 277 Cognitive Interaction Technology.    **
00025 ** The Excellence Cluster EXC 277 is a grant of the Deutsche       **
00026 ** Forschungsgemeinschaft (DFG) in the context of the German       **
00027 ** Excellence Initiative.                                          **
00028 **                                                                 **
00029 ********************************************************************/
00030 
00031 #pragma once
00032 
00033 #include <ICLUtils/CompatMacros.h>
00034 #include <ICLUtils/Point.h>
00035 #include <ICLUtils/Point32f.h>
00036 #include <ICLCore/Img.h>
00037 #include <ICLCore/Types.h>
00038 #include <vector>
00039 
00040 namespace icl{
00041   namespace cv{
00042 
00044 
00064     class ICLCV_API RDPApproximation {
00065 
00066       struct ChainPoint : utils::Point32f {
00067         ChainPoint *prev;
00068         ChainPoint *next;
00069       };
00070 
00071     public:
00073       RDPApproximation(float epsilon = 0.1f, int max_corners = 0, int search_iters = 3) :
00074         epsilon(epsilon), max_corners(max_corners), search_iters(search_iters) {};
00075 
00077 
00080       const std::vector<utils::Point32f> &approximate(const std::vector<utils::Point> &poly, bool polygon = true);
00081       const std::vector<utils::Point32f> &approximate(const std::vector<utils::Point32f> &poly, bool polygon = true);
00082       const std::vector<utils::Point32f> &approximate(const utils::Point *begin, const utils::Point *end, const int size, bool polygon = true);
00083 
00085       void drawAllPoints(core::ImgBase *img, const icl64f &value);
00086 
00088       inline const std::vector<utils::Point32f> &getLastApproximation() const {
00089         return approximation;
00090       }
00091 
00092       inline void setEpsilon(float value){ epsilon = value; }
00093       inline void setMaxCorners(float value){ max_corners = value; }
00094       inline void setSearchIterations(float value){ search_iters = value; }
00095       inline float getEpsilon() const { return epsilon; }
00096       inline float getMaxCorners() const { return max_corners; }
00097       inline float getSearchIterations() const { return search_iters; }
00098 
00099     private:
00101       float epsilon;
00102       int max_corners;
00103       int search_iters;
00104 
00106       void approximateCurve(const ChainPoint *first, const ChainPoint *last);
00107 
00109 
00112       int approximateCurveWithCap(const ChainPoint *first, const ChainPoint *last, int cap);
00113 
00115       void approximatePolygon(const ChainPoint *cps, const int size, bool polygon);
00116 
00118       void approximateWithCap(const ChainPoint *cps, const int size, bool polygon);
00119 
00121       std::vector<utils::Point32f> approximation;
00122     };
00123   } // namespace cv
00124 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines