Point3D.H

Go to the documentation of this file.
00001 /*!@file BeoSub/BeeBrain/Point3D.H A basic 3D point class */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2001 by the //
00005 // University of Southern California (USC) and the iLab at USC.         //
00006 // See http://iLab.usc.edu for information about this project.          //
00007 // //////////////////////////////////////////////////////////////////// //
00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00010 // in Visual Environments, and Applications'' by Christof Koch and      //
00011 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00012 // pending; application number 09/912,225 filed July 23, 2001; see      //
00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00014 // //////////////////////////////////////////////////////////////////// //
00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00016 //                                                                      //
00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00018 // redistribute it and/or modify it under the terms of the GNU General  //
00019 // Public License as published by the Free Software Foundation; either  //
00020 // version 2 of the License, or (at your option) any later version.     //
00021 //                                                                      //
00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00025 // PURPOSE.  See the GNU General Public License for more details.       //
00026 //                                                                      //
00027 // You should have received a copy of the GNU General Public License    //
00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00030 // Boston, MA 02111-1307 USA.                                           //
00031 // //////////////////////////////////////////////////////////////////// //
00032 //
00033 // Primary maintainer for this file: Michael Montalbo <montalbo@usc.edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/BeoSub/BeeBrain/Point3D.H $
00035 // $Id: Point3D.H 9412 2008-03-10 23:10:15Z farhan $
00036 //
00037 
00038 #ifndef POINT3D_H_DEFINED
00039 #define POINT3D_H_DEFINED
00040 
00041 #include <cmath>
00042 #include <string> // for string conversions
00043 
00044 //! This is a basic class to encode 3D integer coordinates
00045 /*! This is a completely public class whose goal is just to provide a
00046  shorthand notation for 3D integer coordinates.
00047  All methods are inlined, so there is no .C file, just a .H file.
00048 */
00049 
00050 class Point3D
00051 {
00052 public:
00053   //! The default constructor initializes the coordinates to (0,0)
00054   inline Point3D();
00055 
00056   //! Initialize the Point2D<int> from horizontal & vertical coordinates
00057   inline Point3D(const int xx, const int yy, const int zz);
00058 
00059   //! += operator
00060   inline Point3D& operator+=(const Point3D &p);
00061   //! -= operator
00062   inline Point3D& operator-=(const Point3D &p);
00063   //! *= operator
00064   inline Point3D& operator*=(const Point3D &p);
00065   //! /= operator
00066   inline Point3D& operator/=(const Point3D &p);
00067 
00068   //! + operator
00069   inline Point3D operator+(const Point3D &p) const;
00070   //! - operator
00071   inline Point3D operator-(const Point3D &p) const;
00072   //! * operator
00073   inline Point3D operator*(const Point3D &p) const;
00074   //! / operator
00075   inline Point3D operator/(const Point3D &p) const;
00076 
00077   //! += operator
00078   inline Point3D& operator+=(const int val);
00079   //! -= operator
00080   inline Point3D& operator-=(const int val);
00081   //! *= operator
00082   inline Point3D& operator*=(const int val);
00083   //! /= operator
00084   inline Point3D& operator/=(const int val);
00085 
00086   //! + operator
00087   inline Point3D operator+(const int val) const;
00088   //! - operator
00089   inline Point3D operator-(const int val) const;
00090   //! * operator
00091   inline Point3D operator*(const int val) const;
00092   //! / operator
00093   inline Point3D operator/(const int val) const;
00094 
00095   //! test whether x is positive
00096   inline bool isValidX() const;
00097 
00098   //! test whether y is positive
00099   inline bool isValidY() const;
00100 
00101   //! test whether z is positive
00102   inline bool isValidZ() const;
00103 
00104   //! the square euclidean distance from p
00105   inline float squdist(const Point3D& p) const;
00106 
00107   //! the euclidean distance from p
00108   inline float distance(const Point3D& p) const;
00109 
00110   //! 3D coordinates
00111   int x, y, z;
00112 };
00113 
00114 
00115 //! == operator
00116 inline bool operator==(const Point3D& p1, const Point3D& p2);
00117 
00118 //! != operator
00119 inline bool operator!=(const Point3D& p1, const Point3D& p2);
00120 
00121 //! Point3D overload: format is "<int>,<int>,<int>"
00122 std::string convertToString(const Point3D& val);
00123 
00124 //! Point3D overload: format is "<int>,<int>,<int>"
00125 void convertFromString(const std::string& str, Point3D& val);
00126 
00127 
00128 
00129 
00130 
00131 
00132 // ######################################################################
00133 inline Point3D::Point3D()
00134 { x = 0; y = 0; z = 0;}
00135 
00136 // ######################################################################
00137 inline Point3D::Point3D(const int xx, const int yy, const int zz)
00138 { x = xx; y = yy; z = zz;}
00139 
00140 // ######################################################################
00141 inline Point3D& Point3D::operator+=(const Point3D &p)
00142 { x += p.x; y += p.y; z += p.z; return *this; }
00143 
00144 // ######################################################################
00145 inline Point3D& Point3D::operator-=(const Point3D &p)
00146 { x -= p.x; y -= p.y; z -= p.z; return *this; }
00147 
00148 // ######################################################################
00149 inline Point3D& Point3D::operator*=(const Point3D &p)
00150 { x *= p.x; y *= p.y;  z *= p.z; return *this; }
00151 
00152 // ######################################################################
00153 inline Point3D& Point3D::operator/=(const Point3D &p)
00154 { x /= p.x; y /= p.y;  z /= p.z; return *this; }
00155 
00156 // ######################################################################
00157 inline Point3D Point3D::operator+(const Point3D &p) const
00158 { return Point3D(x + p.x, y + p.y, z + p.z); }
00159 
00160 // ######################################################################
00161 inline Point3D Point3D::operator-(const Point3D &p) const
00162 { return Point3D(x - p.x, y - p.y, z - p.z); }
00163 
00164 // ######################################################################
00165 inline Point3D Point3D::operator*(const Point3D &p) const
00166 { return Point3D(x * p.x, y * p.y, z * p.z); }
00167 
00168 // ######################################################################
00169 inline Point3D Point3D::operator/(const Point3D &p) const
00170 { return Point3D(x / p.x, y / p.y, z / p.z); }
00171 
00172 // ######################################################################
00173 inline Point3D& Point3D::operator+=(const int val)
00174 { x += val; y += val; z += val; return *this; }
00175 
00176 // ######################################################################
00177 inline Point3D& Point3D::operator-=(const int val)
00178 { x -= val; y -= val; z -= val; return *this; }
00179 
00180 // ######################################################################
00181 inline Point3D& Point3D::operator*=(const int val)
00182 { x *= val; y *= val;  z *= val; return *this; }
00183 
00184 // ######################################################################
00185 inline Point3D& Point3D::operator/=(const int val)
00186 { x /= val; y /= val;  z /= val; return *this; }
00187 
00188 // ######################################################################
00189 inline Point3D Point3D::operator+(const int val) const
00190 { return Point3D(x + val, y + val,  z + val); }
00191 
00192 // ######################################################################
00193 inline Point3D Point3D::operator-(const int val) const
00194 { return Point3D(x - val, y - val, z - val); }
00195 
00196 // ######################################################################
00197 inline Point3D Point3D::operator*(const int val) const
00198 { return Point3D(x * val, y * val, z * val); }
00199 
00200 // ######################################################################
00201 inline Point3D Point3D::operator/(const int val) const
00202 { return Point3D(x / val, y / val, z / val); }
00203 
00204 // ######################################################################
00205 inline bool operator==(const Point3D& p1, const Point3D& p2)
00206 { return p1.x == p2.x && p1.y == p2.y && p1.z == p2.z; }
00207 
00208 // ######################################################################
00209 inline bool operator!=(const Point3D& p1, const Point3D& p2)
00210 { return p1.x != p2.x || p1.y != p2.y  || p1.z != p2.z; }
00211 
00212 // ######################################################################
00213 inline bool Point3D::isValidX() const
00214 { return (x >= 0); }
00215 
00216 // ######################################################################
00217 inline bool Point3D::isValidY() const
00218 { return (y >= 0); }
00219 
00220 // ######################################################################
00221 inline bool Point3D::isValidZ() const
00222 { return (z >= 0); }
00223 
00224 // ######################################################################
00225 inline float Point3D::squdist(const Point3D& p) const
00226 {
00227   int d1 = p.x - x, d2 = p.y - y, d3 = p.z - z;
00228   return (d1 * d1 + d2 * d2 + d3 * d3);
00229 }
00230 
00231 // ######################################################################
00232 inline float Point3D::distance(const Point3D& p) const
00233 { return sqrt(squdist(p)); }
00234 
00235 
00236 // ######################################################################
00237 /* So things look consistent in everyone's emacs... */
00238 /* Local Variables: */
00239 /* indent-tabs-mode: nil */
00240 /* End: */
00241 
00242 #endif
Generated on Sun May 8 08:40:19 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3