00001 /** 00002 \file Robots/LoBot/misc/LoVector.H 00003 00004 \brief Some utility types and functions related to vectors and images 00005 of vectors. 00006 */ 00007 00008 // //////////////////////////////////////////////////////////////////// // 00009 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005 // 00010 // by the University of Southern California (USC) and the iLab at USC. // 00011 // See http://iLab.usc.edu for information about this project. // 00012 // //////////////////////////////////////////////////////////////////// // 00013 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00014 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00015 // in Visual Environments, and Applications'' by Christof Koch and // 00016 // Laurent Itti, California Institute of Technology, 2001 (patent // 00017 // pending; application number 09/912,225 filed July 23, 2001; see // 00018 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00019 // //////////////////////////////////////////////////////////////////// // 00020 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00023 // redistribute it and/or modify it under the terms of the GNU General // 00024 // Public License as published by the Free Software Foundation; either // 00025 // version 2 of the License, or (at your option) any later version. // 00026 // // 00027 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00028 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00029 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00030 // PURPOSE. See the GNU General Public License for more details. // 00031 // // 00032 // You should have received a copy of the GNU General Public License // 00033 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00034 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00035 // Boston, MA 02111-1307 USA. // 00036 // //////////////////////////////////////////////////////////////////// // 00037 // 00038 // Primary maintainer for this file: mviswana usc edu 00039 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/misc/LoVector.H $ 00040 // $Id: LoVector.H 13811 2010-08-21 02:00:08Z mviswana $ 00041 // 00042 00043 #ifndef LOBOT_VECTOR_DOT_H 00044 #define LOBOT_VECTOR_DOT_H 00045 00046 //------------------------------ HEADERS -------------------------------- 00047 00048 // lobot headers 00049 #include "Robots/LoBot/util/LoMath.H" 00050 00051 // INVT image support 00052 #include "Image/Image.H" 00053 #include "Image/Point2D.H" 00054 00055 // Standard C headers 00056 #include <math.h> 00057 00058 //----------------------------- NAMESPACE ------------------------------- 00059 00060 namespace lobot { 00061 00062 //----------------------------- TYPEDEFS -------------------------------- 00063 00064 /// Some parts of Robolocust rely on the notion of a vector (here, we are 00065 /// talking about the mathematical variety, not the container type). 00066 /// Although vectors and points are quite distinct concepts, we simply 00067 /// piggyback off the INVT Point2D implementation for our vectors. 00068 typedef Point2D<float> Vector ; 00069 00070 /// Some quick operators for vectors 00071 //@{ 00072 inline Vector operator*(float k, const Vector& V) 00073 { 00074 return Vector(k * V.i, k * V.j) ; 00075 } 00076 00077 inline Vector operator*(const Vector& V, float k) 00078 { 00079 return operator*(k, V) ; 00080 } 00081 00082 inline Vector operator/(const Vector& V, float k) 00083 { 00084 return is_zero(k) ? Vector() : operator*(1.0f/k, V) ; 00085 } 00086 //@} 00087 00088 /// Return the radial direction of the supplied vector. 00089 inline float direction(const Vector& v) 00090 { 00091 return atan(v.j, v.i) ; 00092 } 00093 00094 /// Return the unit vector associated with the given radial direction. 00095 inline Vector unit_vector(float dir) 00096 { 00097 return Vector(cos(dir), sin(dir)) ; 00098 } 00099 00100 /// Return the magnitude of the supplied vector. 00101 inline float magnitude(const Vector& v) 00102 { 00103 return sqrtf((v.i * v.i) + (v.j * v.j)) ; 00104 } 00105 00106 /// Normalize the supplied vector and return the result. 00107 inline Vector normalized(const Vector& v) 00108 { 00109 return v/magnitude(v) ; 00110 } 00111 00112 /// Return the dot product of two 2D vectors. 00113 inline float dot(const Vector& a, const Vector& b) 00114 { 00115 return a.i * b.i + a.j * b.j ; 00116 } 00117 00118 /// Some parts of Robolocust need the notion of a collection of vectors 00119 /// arranged in a 2D grid, i.e., an image of vectors. 00120 typedef Image<Vector> VectorImage ; 00121 00122 /// From an image of vectors, extract the vector at pixel location (x,y). 00123 inline const Vector& get_vector(const VectorImage& I, int x, int y) 00124 { 00125 return I.getVal(x, y) ; 00126 } 00127 00128 //----------------------------------------------------------------------- 00129 00130 } // end of namespace encapsulating this file's definitions 00131 00132 #endif 00133 00134 /* So things look consistent in everyone's emacs... */ 00135 /* Local Variables: */ 00136 /* indent-tabs-mode: nil */ 00137 /* End: */