last update 20 Sep 2009 |
00001 /* 00002 * Copyright (C) 1998-2004 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 cvrBorderPoints.h 00044 * Declares borderPoints 00045 * \author LTI 00046 * \date 19.08.1998 00047 * 00048 * $Id: cvrBorderPoints.h,v 1.5 2007/09/24 04:01:11 alvarado Exp $ 00049 */ 00050 00051 #ifndef _CVR_BORDER_POINTS_H_ 00052 #define _CVR_BORDER_POINTS_H_ 00053 00054 #include "cvrIoHandler.h" 00055 #include "cvrPointList.h" 00056 #include "cvrAreaPoints.h" 00057 #include "cvrIoPoints.h" 00058 #include "cvrPolygonPoints.h" 00059 #include "cvrMatrix.h" 00060 00061 namespace cvr { 00062 00063 class areaPoints; 00064 class ioPoints; 00065 00066 /** 00067 * Direct border point representation of a contour. 00068 * 00069 * borderPoints is a ipointList that contains all points that belong to 00070 * a specified border. 00071 * 00072 * For the explanation of the contour description in this class, see 00073 * following image: 00074 * 00075 * \code 00076 * -- 00000000001111111111222222222233 00077 * -- 01234567890123456789012345678901 00078 * 00 -------------------------------- 00079 * 01 -------------------------------- 00080 * 02 -------------------------------- 00081 * 03 --------BBBB------BBBB---------- 00082 * 04 -------B****BBB----B**B--------- 00083 * 05 -------B*******B---B***B-------- 00084 * 06 ------B*******B-----B*B--------- 00085 * 07 -------B*******BBBBB**B--------- 00086 * 08 ---------B*************B-------- 00087 * 09 --------B**----*********B------- 00088 * 10 --------B**-----********B------- 00089 * 11 -------B**-----*******BB-------- 00090 * 12 ------B**-----*******B---------- 00091 * 13 ------B**-------******BB-------- 00092 * 14 -----B**---------*******B------- 00093 * 15 -----B**--------*********B------ 00094 * 16 ----B**-------**********BB------ 00095 * 17 ---B***----*******----BB-------- 00096 * 18 ----BBBBBBBBB*** --*B---------- 00097 * 19 -------------BBBBBBBB----------- 00098 * 20 -------------------------------- 00099 * 21 -------------------------------- 00100 * 22 -------------------------------- 00101 * 23 -------------------------------- 00102 * 00103 * "-" means background and the rest is part of the object. 00104 * "B" indicates a borderpoint. 00105 * \endcode 00106 * 00107 * This contour class allows three representations of a contour: 00108 * - ioPoints. It contains all input and output points for 00109 * each line. For example, for the previous image: 00110 * (8,3)(11,3)(18,3)(21,3)(7,4)(14,4)(19,4)(22,4)... 00111 * Note that every IO-point is a border point, but not all border 00112 * points are IO-points. 00113 * - borderPoints. It contains a list of the points at the border. 00114 * Beginning with the point at (8,3) the chain code for our example 00115 * image is: 00116 * (8,3)(9,3)(10,3)(11,3)(12,4)(13,4)(14,4)(15,5)(14,6)... 00117 * - areaPoints. It contains all points in the object. 00118 * 00119 * @see cvr::ioPoints, cvr::areaPoints 00120 * 00121 * @ingroup gAggregate 00122 * @ingroup gShape 00123 */ 00124 class borderPoints : public ipointList { 00125 00126 public: 00127 /** 00128 * Default constructor. empty borderPoints 00129 */ 00130 borderPoints(); 00131 00132 /** 00133 * Copy constructor 00134 */ 00135 borderPoints(const borderPoints& other); 00136 00137 /** 00138 * Destructor 00139 */ 00140 virtual ~borderPoints(); 00141 00142 /** 00143 * Extracts borderPoints from ioPoints 00144 */ 00145 borderPoints& castFrom(const ioPoints& theIoPoints); 00146 00147 /** 00148 * Extracts borderPoints from areaPoints 00149 */ 00150 borderPoints& castFrom(const areaPoints& theAreaPoints); 00151 00152 /** 00153 * Extracts borderPoints from the given polygonPoints 00154 */ 00155 borderPoints& castFrom(const ipolygonPoints& polyPoints); 00156 00157 /** 00158 * Copy \c other borderPoints into these. 00159 */ 00160 borderPoints& copy(const borderPoints& other); 00161 00162 /** 00163 * Assigment operator (alias for copy(other)). 00164 * @param other the pointList to be copied 00165 * @return a reference to the actual pointList 00166 */ 00167 inline borderPoints& operator=(const borderPoints& other); 00168 00169 /** 00170 * Returns the name of this type. 00171 */ 00172 virtual const std::string& name() const; 00173 00174 /** 00175 * Create a clone of the borderPoints 00176 * 00177 * @return a pointer to a copy of the borderPoints. 00178 */ 00179 virtual borderPoints* clone() const; 00180 00181 /** 00182 * Create a clone of the borderPoints. 00183 * 00184 * @return a pointer to a copy of the borderPoints 00185 */ 00186 virtual borderPoints* newInstance() const; 00187 00188 /** 00189 * Extract borderPoints from the given mask image. 00190 * 00191 * This function assumes that the mask contains JUST ONE connected 00192 * object. To get the biggest object on the mask see 00193 * cvr::objectsFromMask or cvr::fastRelabeling. 00194 */ 00195 bool extractFromMask(const matrix<ubyte>& mask); 00196 00197 /** 00198 * Generate mask from the borderPoints. 00199 * 00200 * The dimensions of the resulting mask are the smallest rectangle to 00201 * contain the point (0,0) (optional) and all points in this list, plus 00202 * 1 pixel in both width and heigth. If the given mask is bigger than 00203 * this size, its dimensions will be kept. 00204 * 00205 * If the boundary of the point list is not up to date, it can 00206 * be calculated if specified by the arguments: 00207 * @param mask The calculated mask will be stored here 00208 * @param computeBoundary If false, the internal boundary of the 00209 * point list will be used, otherwise the boundary 00210 * will be calculated (but NOT updated!!!). 00211 * @param exactBoundaryDimensions If true, the dimensions of the resulting 00212 * mask will be the smallest rectangle to contain only the points in 00213 * this list. The origin (0,0) may not be included, therefore a 1:1 00214 * correspondence of coordinates will generally not be given. 00215 * @param keepMaskData if false, the mask will be initialized with 00216 * zero before getting the area mask. If true, 00217 * the previous mask data is not deleted, but 00218 * the mask will be resized if necessary. 00219 * @return true if successful, false otherwise. 00220 */ 00221 bool generateMask(matrix<ubyte>& mask, 00222 const bool computeBoundary=true, 00223 const bool exactBoundaryDimensions=false, 00224 const bool keepMaskData=false) const; 00225 00226 /** 00227 * Invert the direction of the border points 00228 */ 00229 void invert(); 00230 00231 /** 00232 * Check consistency of border points. Border points are 00233 * consistent if the D8 distance between any two subsequent points 00234 * (with the first point being subsequent to the last) is exactly 00235 * 1, i.e. if every border point is "next to" its predecessor, 00236 * with "next to" meaning "one of the 8 neighbouring pixels in the 00237 * grid". 00238 */ 00239 bool isConsistent() const; 00240 00241 protected: 00242 /** 00243 * Check if the given coordinates point lies inside the mask. 00244 */ 00245 inline bool inside(const ipoint& p,const matrix<ubyte>& mask); 00246 }; 00247 } 00248 00249 #include "cvrBorderPoints_inline.h" 00250 00251 #endif 00252 00253 00254