CVR-Lib last update 20 Sep 2009

cvrRectLocation.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   cvrRectLocation.h
00044  *         Definition of cvr::rectLocation which is a rectangular local region
00045  *         around an interest point.
00046  *
00047  *         Global read/write methods to iostream and ostream operators are
00048  *         provided as well.
00049  * \author Pablo Alvarado
00050  * \date   07.01.2002
00051  *
00052  * $Id: cvrRectLocation.h,v 1.3 2005/01/03 16:09:05 alvarado Exp $
00053  */
00054 
00055 #ifndef _CVR_RECT_LOCATION_H_
00056 #define _CVR_RECT_LOCATION_H_
00057 
00058 #include "cvrPoint.h"
00059 #include "cvrLocation.h"
00060 
00061 namespace cvr {
00062   /**
00063    * The rectLocation class specifies a small region in an image or
00064    * channel around an interest point.
00065    * The rectangular location is represented by its position in an
00066    * image or channel, an orientation, the length at the orientation
00067    * direction (maxLenght), and the length at the perpendicular
00068    * direction (minLength).
00069    *
00070    * The difference to cvr::location is that the regions are considered
00071    * rectangular.  Two lengths are needed, where the orientation angle is
00072    * always given for the maxLength.
00073    *
00074    * You can get rectangular %locations with the cvr::boundingBox %functor, and
00075    * use them to check if objects overlap or not.
00076    */
00077   class rectLocation {
00078   public:
00079     /**
00080      * Default constructor
00081      */
00082     rectLocation();
00083 
00084     /**
00085      * Constructor
00086      * @param pos position of the center point of the rectLocation
00087      * @param ang angle of the rectLocation (in radians)
00088      * @param maxLength length in pixels of the principal axis
00089      * @param minLength length in pixels of the second axis
00090      */
00091     rectLocation(const ipoint& pos,
00092                  const float& ang,
00093                  const float& maxLength,
00094                  const float& minLength);
00095 
00096     /**
00097      * Constructor
00098      * @param pos position of the center point of the rectLocation
00099      * @param ang angle of the rectLocation (in radians)
00100      * @param maxLength length in pixels of the principal axis
00101      * @param minLength length in pixels of the second axis
00102      */
00103     rectLocation(const fpoint& pos,
00104                  const float& ang,
00105                  const float& maxLength,
00106                  const float& minLength);
00107 
00108     /**
00109      * Copy constructor from a normal location
00110      */
00111     rectLocation(const location& loc);
00112 
00113     /**
00114      * Copy constructor
00115      */
00116     rectLocation(const rectLocation& other);
00117 
00118     /**
00119      * Copy operator
00120      */
00121     rectLocation& copy(const rectLocation& other);
00122 
00123     /**
00124      * Copy the other location into this rectLocation.  The radius of
00125      * the location will be assumed as the maxLength and minLength.
00126      */
00127     rectLocation& castFrom(const location& other);
00128 
00129 
00130     /**
00131      * Alias for copy operator
00132      */
00133     rectLocation& operator=(const rectLocation& other);
00134 
00135     /**
00136      * Operator ==
00137      */
00138     bool operator==(const rectLocation& p) const;
00139 
00140     /**
00141      * Operator !=
00142      */
00143     bool operator!=(const rectLocation& p) const;
00144 
00145     /**
00146      * Comparition operator.
00147      *
00148      * A rectLocation is smaller than another one if its area is smaller, or
00149      * in case of equal areas, if the position is smaller, i.e. if it has
00150      * smaller y-coordinate, or in case of equal y-position, if it has
00151      * smaller x-coordinate.
00152      */
00153     bool operator<(const rectLocation& other);
00154 
00155     /**
00156      * Comparition operator.
00157      *
00158      * A rectLocation is greater than another one if its area is greater, or
00159      * in case of equal radii, if the position is greater, i.e. if it has
00160      * greater y-coordinate, or in case of equal y-position, if it has
00161      * greater x-coordinate.
00162      */
00163     bool operator>(const rectLocation& other);
00164 
00165     /**
00166      * Multiply the lengths and position with the given factor
00167      */
00168     rectLocation& scale(const float& factor);
00169 
00170     /**
00171      * Multiply the other rectLocation's lengths and position with the
00172      * given factor and leave the result here.
00173      */
00174     rectLocation& scale(const rectLocation& other,
00175                         const float& factor);
00176 
00177     /**
00178      * Shift the rectLocation by the given point
00179      */
00180     rectLocation& shift(const ipoint& shft);
00181 
00182     /**
00183      * Shift the rectLocation by the given point
00184      */
00185     rectLocation& shift(const fpoint& shft);
00186 
00187     /**
00188      * Shift the other rectLocation by the given point and leave the
00189      * result here
00190      */
00191     rectLocation& shift(const rectLocation& other,const ipoint& shft);
00192 
00193     /**
00194      * Shift the other rectLocation by the given point and leave the
00195      * result here
00196      */
00197     rectLocation& shift(const rectLocation& other,const fpoint& shft);
00198 
00199     /**
00200      * Add the given angle in radians to the actual angle
00201      */
00202     rectLocation& rotate(const float& factor);
00203 
00204     /**
00205      * Add the given angle in radians to the angle of the other rectLocation and
00206      * leave the result here.
00207      */
00208     rectLocation& rotate(const rectLocation& other,const float& factor);
00209 
00210     /**
00211      * Check if the given point can be considered within the rectLocation.
00212      */
00213     bool contains(const ipoint& p) const;
00214 
00215     /**
00216      * Check if the given point can be considered within the rectLocation.
00217      */
00218     bool contains(const fpoint& p) const;
00219 
00220     /**
00221      * Returns the square of the distance between the borders of two
00222      * locations or zero if they overlap or if one of the locations
00223      * lies inside the other one.
00224      *
00225      * @param other the other rectLocation to be compared with
00226      * @return minimal distance to other location
00227      */
00228     float distanceSqr(const rectLocation& other);
00229 
00230     /**
00231      * Returns the square of the distance between the borders of two
00232      * locations or zero if they overlap or if one of the locations
00233      * lies inside the other one.
00234      *
00235      * @param other the other rectLocation to be compared with
00236      * @param pt point in the border of this location with the
00237      *           smallest distance.
00238      * @param po point in the border of the other location with the
00239      *           smallest distance.
00240      * @return minimal distance to other location
00241      */
00242     float distanceSqr(const rectLocation& other,
00243                       fpoint& pt,
00244                       fpoint& po);
00245 
00246     /**
00247      * Get the area of this location (maxLength*minLength)
00248      */
00249     float calculateArea() const;
00250 
00251     /**
00252      * Position of the rectLocation
00253      */
00254     fpoint position;
00255 
00256     /**
00257      * Angle in radians of the rectLocation.  It is usually given for
00258      * the image coordinates, i.e. for a left coordinate system, in which
00259      * positive angles are given clock-wise.
00260      */
00261     float angle;
00262 
00263     /**
00264      * Major length.
00265      *
00266      * The angle corresponds to the axis with the maxLength
00267      */
00268     float maxLength;
00269 
00270     /**
00271      * Minor length.
00272      *
00273      * Should be smaller than maximum length
00274      */
00275     float minLength;
00276   };
00277 
00278   /**
00279    * Global function to read a cvr::rectLocation from an ioHandler.
00280    */
00281   bool read(ioHandler& handler,
00282             rectLocation& mat,
00283             const bool complete=true);
00284 
00285   /**
00286    * Global function to write a cvr::rectLocation into an ioHandler.
00287    */
00288   bool write(ioHandler& handler,
00289              const rectLocation& mat,
00290              const bool complete=true);
00291 }
00292 
00293 namespace std {
00294 
00295   ostream& operator<<(ostream& s,
00296                       const cvr::rectLocation& loc);
00297 
00298 }
00299 
00300 #endif
00301 
00302 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8