CVR-Lib last update 20 Sep 2009

cvrIoPoints.h

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

Generated on Sun Sep 20 22:07:59 2009 for CVR-Lib by Doxygen 1.5.8