last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998 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 /** 00043 * \file cvrConvexHull.h 00044 * Contains the functor convexHull 00045 * \author Pablo Alvarado 00046 * \date 16.11.2002 00047 * 00048 * $Id: cvrConvexHull.h,v 1.5 2006/01/18 12:05:43 doerfler Exp $ 00049 */ 00050 00051 #ifndef _CVR_CONVEX_HULL_H_ 00052 #define _CVR_CONVEX_HULL_H_ 00053 00054 #include "cvrFunctor.h" 00055 #include "cvrPolygonPoints.h" 00056 00057 namespace cvr { 00058 /** 00059 * Computes the convex hull of a set of points. 00060 * 00061 * The algorithm used is similar to the one explained in: 00062 * 00063 * M. de Berg, et. al. Computational Geometry. Algorithms and 00064 * Applications, 2nd. edition. Springer, 2000 00065 */ 00066 class convexHull : public functor { 00067 public: 00068 /** 00069 * the parameters for the class convexHull 00070 */ 00071 class parameters : public functor::parameters { 00072 public: 00073 /** 00074 * default constructor 00075 */ 00076 parameters(); 00077 00078 /** 00079 * copy constructor 00080 * @param other the parameters object to be copied 00081 */ 00082 parameters(const parameters& other); 00083 00084 /** 00085 * destructor 00086 */ 00087 ~parameters(); 00088 00089 /** 00090 * returns name of this type 00091 */ 00092 const std::string& name() const; 00093 00094 /** 00095 * copy the contents of a parameters object 00096 * @param other the parameters object to be copied 00097 * @return a reference to this parameters object 00098 */ 00099 parameters& copy(const parameters& other); 00100 00101 /** 00102 * copy the contents of a parameters object 00103 * @param other the parameters object to be copied 00104 * @return a reference to this parameters object 00105 */ 00106 parameters& operator=(const parameters& other); 00107 00108 00109 /** 00110 * returns a pointer to a clone of the parameters 00111 */ 00112 virtual parameters* clone() const; 00113 00114 /** 00115 * returns a pointer to a new instance of the parameters 00116 */ 00117 virtual parameters* newInstance() const; 00118 00119 /** 00120 * write the parameters in the given ioHandler 00121 * @param handler the ioHandler to be used 00122 * @param complete if true (the default) the enclosing begin/end will 00123 * be also written, otherwise only the data block will be written. 00124 * @return true if write was successful 00125 */ 00126 virtual bool write(ioHandler& handler,const bool complete=true) const; 00127 00128 /** 00129 * read the parameters from the given ioHandler 00130 * @param handler the ioHandler to be used 00131 * @param complete if true (the default) the enclosing begin/end will 00132 * be also written, otherwise only the data block will be written. 00133 * @return true if write was successful 00134 */ 00135 virtual bool read(ioHandler& handler,const bool complete=true); 00136 00137 // ------------------------------------------------ 00138 // the parameters 00139 // ------------------------------------------------ 00140 00141 //TODO: comment the parameters of your functor 00142 // If you add more parameters manually, do not forget to do following: 00143 // 1. indicate in the default constructor the default values 00144 // 2. make sure that the copy member also copy your new parameters 00145 // 3. make sure that the read and write members also read and 00146 // write your parameters 00147 00148 00149 }; 00150 00151 /** 00152 * default constructor 00153 */ 00154 convexHull(); 00155 00156 /** 00157 * Construct a functor using the given parameters 00158 */ 00159 convexHull(const parameters& par); 00160 00161 /** 00162 * copy constructor 00163 * @param other the object to be copied 00164 */ 00165 convexHull(const convexHull& other); 00166 00167 /** 00168 * destructor 00169 */ 00170 virtual ~convexHull(); 00171 00172 /** 00173 * returns the name of this type 00174 */ 00175 virtual const std::string& name() const; 00176 00177 /** 00178 * operates on a copy of the given %parameters. 00179 * @param src pointList with the source data. 00180 * @param dest pointList where the result will be left. 00181 * @return true if apply successful or false otherwise. 00182 */ 00183 bool apply(const ipointList& src,ipolygonPoints& dest) const; 00184 00185 /** 00186 * operates on a copy of the given %parameters. 00187 * @param src pointList with the source data. 00188 * @param dest pointList where the result will be left. 00189 * @return true if apply successful or false otherwise. 00190 */ 00191 bool apply(const ioPoints& src,ipolygonPoints& dest) const; 00192 00193 /** 00194 * operates on a copy of the given %parameters. 00195 * @param src pointList with the source data. 00196 * @param dest pointList where the result will be left. 00197 * @return true if apply successful or false otherwise. 00198 */ 00199 bool apply(const pointList<float>& src,polygonPoints<float>& dest) const; 00200 00201 /** 00202 * operates on a copy of the given %parameters. 00203 * @param src pointList with the source data. 00204 * @param dest pointList where the result will be left. 00205 * @return true if apply successful or false otherwise. 00206 */ 00207 bool apply(const pointList<double>& src, 00208 polygonPoints<double>& dest) const; 00209 00210 /** 00211 * copy data of "other" functor. 00212 * @param other the functor to be copied 00213 * @return a reference to this functor object 00214 */ 00215 convexHull& copy(const convexHull& other); 00216 00217 /** 00218 * alias for copy member 00219 * @param other the functor to be copied 00220 * @return a reference to this functor object 00221 */ 00222 convexHull& operator=(const convexHull& other); 00223 00224 /** 00225 * returns a pointer to a clone of this functor. 00226 */ 00227 virtual convexHull* clone() const; 00228 00229 /** 00230 * returns a pointer to a new instance of this functor. 00231 */ 00232 virtual convexHull* newInstance() const; 00233 00234 /** 00235 * returns used parameters 00236 */ 00237 const parameters& getParameters() const; 00238 00239 //TODO: comment the attributes of your functor 00240 // If you add more attributes manually, do not forget to do following: 00241 // 1. indicate in the default constructor the default values 00242 // 2. make sure that the copy member also copy your new attributes, or 00243 // to ensure there, that these attributes are properly initialized. 00244 00245 /** 00246 * Creates the smallest convex polygon that contains all points 00247 * in the given point list. 00248 * 00249 * The list of points \b must be a set, i.e. the same point is not 00250 * allowed to be twice in the list. (This usually is not the case 00251 * in cvr::ioPoints lists, see castFrom(const ioPoints&)). 00252 * 00253 * For more information on the algorithm used here see: 00254 * 00255 * M. de Berg, et.al. Computational Geometry, Algorithms and Applications. 00256 * 2nd. edition, Springer, 2000, pp. 6ff 00257 * 00258 * @param thePointList a set of points (the same point is not allowed to 00259 * be twice in the list). 00260 * @param thePolygonPoints the resulting polygon 00261 * @return a reference to the result 00262 */ 00263 template<typename T> 00264 polygonPoints<T>& computeConvexHull(const pointList<T>& thePointList, 00265 polygonPoints<T>& thePolygonPoints) const; 00266 00267 }; 00268 } 00269 00270 #endif 00271