LTI-Lib latest version v1.9 - last update 10 Apr 2010

ltiLocation.h

00001 /*
00002  * Copyright (C) 2002, 2003, 2004, 2005, 2006
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  * This file is part of the LTI-Computer Vision Library (LTI-Lib)
00006  *
00007  * The LTI-Lib is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License (LGPL)
00009  * as published by the Free Software Foundation; either version 2.1 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * The LTI-Lib is distributed in the hope that it will be
00013  * useful, but WITHOUT ANY WARRANTY; without even the implied warranty
00014  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU Lesser General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with the LTI-Lib; see the file LICENSE.  If
00019  * not, write to the Free Software Foundation, Inc., 59 Temple Place -
00020  * Suite 330, Boston, MA 02111-1307, USA.
00021  */
00022 
00023 
00024 /*--------------------------------------------------------------------
00025  * project ....: LTI-Lib: Image Processing and Computer Vision Library
00026  * file .......: ltiLocation.h
00027  * authors ....: Pablo Alvarado
00028  * organization: LTI, RWTH Aachen
00029  * creation ...: 7.1.2002
00030  * revisions ..: $Id: ltiLocation.h,v 1.3 2006/02/08 11:25:18 ltilib Exp $
00031  */
00032 
00033 #ifndef _LTI_LOCATION_H_
00034 #define _LTI_LOCATION_H_
00035 
00036 #include "ltiPoint.h"
00037 
00038 namespace lti {
00039   /**
00040    * The location class specifies a small region in an image or channel.
00041    * It is mainly used in the extraction of local features.   There
00042    * are some functors to extract the important or salient locations in an
00043    * image, for example lti::axLocalRegions.
00044    *
00045    * The locations are represented by its position in an image or channel,
00046    * an orientation and a radius.
00047    *
00048    */
00049   class location {
00050   public:
00051     /**
00052      * default constructor
00053      */
00054     location();
00055 
00056     /**
00057      * Constructor
00058      * @param pos position of the middle point of the location
00059      * @param ang angle of the location (in radians)
00060      * @param rad radius or size of the location
00061      */
00062     location(const point& pos,const float& ang,const float& rad);
00063 
00064     /**
00065      * Constructor
00066      * @param pos position of the middle point of the location
00067      * @param ang angle of the location (in radians)
00068      * @param rad radius or size of the location
00069      */
00070     location(const tpoint<float>& pos,const float& ang,const float& rad);
00071 
00072     /**
00073      * copy constructor
00074      */
00075     location(const location& other);
00076 
00077     /**
00078      * copy operator
00079      */
00080     location& copy(const location& other);
00081 
00082     /**
00083      * alias for copy operator
00084      */
00085     location& operator=(const location& other);
00086 
00087     /**
00088      * operator ==
00089      */
00090     bool operator==(const location& p) const;
00091 
00092     /**
00093      * operator !=
00094      */
00095     bool operator!=(const location& p) const;
00096 
00097     /**
00098      * Comparition operator.
00099      *
00100      * A location is smaller than another one if its radius is smaller, or
00101      * in case of equal radii, if the position is smaller, i.e. if it has
00102      * smaller y-coordinate, or in case of equal y-position, if it has
00103      * smaller x-coordinate.
00104      */
00105     bool operator<(const location& other);
00106 
00107     /**
00108      * Comparition operator.
00109      *
00110      * A location is greater than another one if its radius is greater, or
00111      * in case of equal radii, if the position is greater, i.e. if it has
00112      * greater y-coordinate, or in case of equal y-position, if it has
00113      * greater x-coordinate.
00114      */
00115     bool operator>(const location& other);
00116 
00117     /**
00118      * Multiply the radius and position with the given factor
00119      */
00120     location& scale(const float& factor);
00121 
00122     /**
00123      * Multiply the other location's radius and position with the
00124      * given factor and leave the result here.
00125      */
00126     location& scale(const location& other,const float& factor);
00127 
00128     /**
00129      * Shift the location by the given point
00130      */
00131     location& shift(const point& shft);
00132 
00133     /**
00134      * Shift the location by the given point
00135      */
00136     location& shift(const tpoint<float>& shft);
00137 
00138     /**
00139      * Shift the other location by the given point and leave the result here
00140      */
00141     location& shift(const location& other,const point& shft);
00142 
00143     /**
00144      * Shift the other location by the given point and leave the result here
00145      */
00146     location& shift(const location& other,const tpoint<float>& shft);
00147 
00148     /**
00149      * Add the given angle in radius to the actual angle
00150      */
00151     location& rotate(const float& factor);
00152 
00153     /**
00154      * Add the given angle in radius to the angle of the other location and
00155      * leave the result here.
00156      */
00157     location& rotate(const location& other,const float& factor);
00158 
00159     /**
00160      * Check if the given point can be considered within the location, i.e.
00161      * if ||p-position|| < radius
00162      */
00163     bool contains(const point& p) const;
00164 
00165     /**
00166      * Check if the given point can be considered within the location, i.e.
00167      * if ||p-position|| < radius
00168      */
00169     bool contains(const tpoint<float>& p) const;
00170 
00171     /**
00172      * returns the distance between the borders of two
00173      * locations or zero if they overlap or if one of the locations
00174      * lies inside the other one.
00175      */
00176     float distance(const location& other);
00177 
00178     /**
00179      * Position of the location
00180      */
00181     tpoint<float> position;
00182 
00183     /**
00184      * Angle in radius of the location.  It is usually given for
00185      * the image coordinates, i.e. for a left coordinate system, in which
00186      * positive angles are given clock-wise.
00187      */
00188     float angle;
00189 
00190     /**
00191      * Radius or size of the location
00192      */
00193     float radius;
00194   };
00195 
00196   /**
00197    * The rectLocation class specifies a small region in an image or channel.
00198    * The rectangular locations are represented by its position in an
00199    * image or channel, an orientation, the length at the orientation
00200    * direction (maxLenght), and the length at the perpendicular
00201    * direction (minLength).
00202    *
00203    * The difference to lti::location is that the regions are considered
00204    * rectangular.  Two lengths are needed, where the orientation angle is
00205    * always given for the maxLength.
00206    *
00207    * You can get rectangular %locations with the lti::boundingBox %functor, and
00208    * used them to check if objects overlap or not.
00209    */
00210   class rectLocation {
00211   public:
00212     /**
00213      * default constructor
00214      */
00215     rectLocation();
00216 
00217     /**
00218      * Constructor
00219      * @param pos position of the middle point of the rectLocation
00220      * @param ang angle of the rectLocation (in radians)
00221      * @param maxLength length in pixels of the principal axis
00222      * @param minLength length in pixels of the second axis
00223      */
00224     rectLocation(const point& pos,
00225                  const float& ang,
00226                  const float& maxLength,
00227                  const float& minLength);
00228 
00229     /**
00230      * Constructor
00231      * @param pos position of the middle point of the rectLocation
00232      * @param ang angle of the rectLocation (in radians)
00233      * @param maxLength length in pixels of the principal axis
00234      * @param minLength length in pixels of the second axis
00235      */
00236     rectLocation(const tpoint<float>& pos,
00237                  const float& ang,
00238                  const float& maxLength,
00239                  const float& minLength);
00240 
00241     /**
00242      * copy constructor from a normal location
00243      */
00244     rectLocation(const location& loc);
00245 
00246     /**
00247      * copy constructor
00248      */
00249     rectLocation(const rectLocation& other);
00250 
00251     /**
00252      * copy operator
00253      */
00254     rectLocation& copy(const rectLocation& other);
00255 
00256     /**
00257      * copy the other location into this rectLocation.  The radius of
00258      * the location will be assumed as the maxLength and minLength.
00259      */
00260     rectLocation& castFrom(const location& other);
00261 
00262 
00263     /**
00264      * alias for copy operator
00265      */
00266     rectLocation& operator=(const rectLocation& other);
00267 
00268     /**
00269      * operator ==
00270      */
00271     bool operator==(const rectLocation& p) const;
00272 
00273     /**
00274      * operator !=
00275      */
00276     bool operator!=(const rectLocation& p) const;
00277 
00278     /**
00279      * Comparition operator.
00280      *
00281      * A rectLocation is smaller than another one if its area is smaller, or
00282      * in case of equal areas, if the position is smaller, i.e. if it has
00283      * smaller y-coordinate, or in case of equal y-position, if it has
00284      * smaller x-coordinate.
00285      */
00286     bool operator<(const rectLocation& other);
00287 
00288     /**
00289      * Comparition operator.
00290      *
00291      * A rectLocation is greater than another one if its area is greater, or
00292      * in case of equal radii, if the position is greater, i.e. if it has
00293      * greater y-coordinate, or in case of equal y-position, if it has
00294      * greater x-coordinate.
00295      */
00296     bool operator>(const rectLocation& other);
00297 
00298     /**
00299      * Multiply the lengths and position with the given factor
00300      */
00301     rectLocation& scale(const float& factor);
00302 
00303     /**
00304      * Multiply the other rectLocation's lengths and position with the
00305      * given factor and leave the result here.
00306      */
00307     rectLocation& scale(const rectLocation& other,
00308                         const float& factor);
00309 
00310     /**
00311      * Shift the rectLocation by the given point
00312      */
00313     rectLocation& shift(const point& shft);
00314 
00315     /**
00316      * Shift the rectLocation by the given point
00317      */
00318     rectLocation& shift(const tpoint<float>& shft);
00319 
00320     /**
00321      * Shift the other rectLocation by the given point and leave the
00322      * result here
00323      */
00324     rectLocation& shift(const rectLocation& other,const point& shft);
00325 
00326     /**
00327      * Shift the other rectLocation by the given point and leave the
00328      * result here
00329      */
00330     rectLocation& shift(const rectLocation& other,const tpoint<float>& shft);
00331 
00332     /**
00333      * Add the given angle in radius to the actual angle
00334      */
00335     rectLocation& rotate(const float& factor);
00336 
00337     /**
00338      * Add the given angle in radius to the angle of the other rectLocation and
00339      * leave the result here.
00340      */
00341     rectLocation& rotate(const rectLocation& other,const float& factor);
00342 
00343     /**
00344      * Check if the given point can be considered within the rectLocation.
00345      */
00346     bool contains(const point& p) const;
00347 
00348     /**
00349      * Check if the given point can be considered within the rectLocation.
00350      */
00351     bool contains(const tpoint<float>& p) const;
00352 
00353     /**
00354      * returns the square of the distance between the borders of two
00355      * locations or zero if they overlap or if one of the locations
00356      * lies inside the other one.
00357      *
00358      * @param other the other rectLocation to be compared with
00359      * @return minimal distance to other location
00360      */
00361     float distanceSqr(const rectLocation& other);
00362 
00363     /**
00364      * returns the square of the distance between the borders of two
00365      * locations or zero if they overlap or if one of the locations
00366      * lies inside the other one.
00367      *
00368      * @param other the other rectLocation to be compared with
00369      * @param pt point in the border of this location with the
00370      *           smallest distance.
00371      * @param po point in the border of the other location with the
00372      *           smallest distance.
00373      * @return minimal distance to other location
00374      */
00375     float distanceSqr(const rectLocation& other,
00376                     tpoint<float>& pt,
00377                     tpoint<float>& po);
00378 
00379     /**
00380      * Get the area of this location (maxLength*minLength)
00381      */
00382     float getArea() const;
00383 
00384     /**
00385      * Position of the rectLocation
00386      */
00387     tpoint<float> position;
00388 
00389     /**
00390      * Angle in radius of the rectLocation.  It is usually given for
00391      * the image coordinates, i.e. for a left coordinate system, in which
00392      * positive angles are given clock-wise.
00393      */
00394     float angle;
00395 
00396     /**
00397      * maximum length.  The angle corresponds to the axis with the maxLength
00398      */
00399     float maxLength;
00400 
00401     /**
00402      * minimum length.  Should be smaller than maximum length
00403      */
00404     float minLength;
00405   };
00406 
00407 
00408   bool read(ioHandler& handler,
00409             location& mat,
00410             const bool complete=true);
00411 
00412   bool write(ioHandler& handler,
00413              const location& mat,
00414              const bool complete=true);
00415 
00416   bool read(ioHandler& handler,
00417             rectLocation& mat,
00418             const bool complete=true);
00419 
00420   bool write(ioHandler& handler,
00421              const rectLocation& mat,
00422              const bool complete=true);
00423 }
00424 
00425 namespace std {
00426   ostream& operator<<(ostream& s,
00427                       const lti::location& loc);
00428 
00429   ostream& operator<<(ostream& s,
00430                       const lti::rectLocation& loc);
00431 
00432 }
00433 
00434 #endif

Generated on Sat Apr 10 15:25:47 2010 for LTI-Lib by Doxygen 1.6.1