LoPose.C

00001 /**
00002    \file  Robots/LoBot/misc/LoPose.C
00003    \brief This file defines the non-inline member functions of the
00004    lobot::Pose class.
00005 */
00006 
00007 // //////////////////////////////////////////////////////////////////// //
00008 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00009 // by the University of Southern California (USC) and the iLab at USC.  //
00010 // See http://iLab.usc.edu for information about this project.          //
00011 // //////////////////////////////////////////////////////////////////// //
00012 // Major portions of the iLab Neuromorphic Vision Toolkit are protected //
00013 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency //
00014 // in Visual Environments, and Applications'' by Christof Koch and      //
00015 // Laurent Itti, California Institute of Technology, 2001 (patent       //
00016 // pending; application number 09/912,225 filed July 23, 2001; see      //
00017 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status).     //
00018 // //////////////////////////////////////////////////////////////////// //
00019 // This file is part of the iLab Neuromorphic Vision C++ Toolkit.       //
00020 //                                                                      //
00021 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can   //
00022 // redistribute it and/or modify it under the terms of the GNU General  //
00023 // Public License as published by the Free Software Foundation; either  //
00024 // version 2 of the License, or (at your option) any later version.     //
00025 //                                                                      //
00026 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope  //
00027 // that it will be useful, but WITHOUT ANY WARRANTY; without even the   //
00028 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR      //
00029 // PURPOSE.  See the GNU General Public License for more details.       //
00030 //                                                                      //
00031 // You should have received a copy of the GNU General Public License    //
00032 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write   //
00033 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,   //
00034 // Boston, MA 02111-1307 USA.                                           //
00035 // //////////////////////////////////////////////////////////////////// //
00036 //
00037 // Primary maintainer for this file: mviswana usc edu
00038 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Robots/LoBot/slam/LoPose.C $
00039 // $Id: LoPose.C 13620 2010-06-25 05:12:03Z mviswana $
00040 //
00041 
00042 //------------------------------ HEADERS --------------------------------
00043 
00044 // lobot headers
00045 #include "Robots/LoBot/slam/LoPose.H"
00046 #include "Robots/LoBot/util/LoMath.H"
00047 
00048 // Standard C++ headers
00049 #include <iomanip>
00050 
00051 //----------------------------- NAMESPACE -------------------------------
00052 
00053 namespace lobot {
00054 
00055 //-------------------------- INITIALIZATION -----------------------------
00056 
00057 Pose::Pose(float x, float y, float theta)
00058    : m_pose(x, y, clamp_angle(theta))
00059 {}
00060 
00061 Pose::Pose(const triple<float, float, float>& p)
00062    : m_pose(p.first, p.second, clamp_angle(p.third))
00063 {}
00064 
00065 //--------------------------- POSE UPDATES ------------------------------
00066 
00067 void Pose::t(float th)
00068 {
00069    m_pose.third = clamp_angle(th) ;
00070 }
00071 
00072 void Pose::dt(float th)
00073 {
00074    m_pose.third = clamp_angle(m_pose.third + th) ;
00075 }
00076 
00077 //-------------------------- POSE OPERATIONS ----------------------------
00078 
00079 // Add two poses
00080 Pose& Pose::operator+=(const Pose& p)
00081 {
00082    m_pose.first  += p.x() ;
00083    m_pose.second += p.y() ;
00084    m_pose.third  += p.t() ;
00085    return *this ;
00086 }
00087 
00088 // Add two poses
00089 Pose Pose::operator+(const Pose& p) const
00090 {
00091    return Pose(x() + p.x(), y() + p.y(), t() + p.t()) ;
00092 }
00093 
00094 // Return a new Pose weighted by the supplied factor
00095 Pose Pose::operator*(float weight) const
00096 {
00097    return Pose(x() * weight, y() * weight, t() * weight) ;
00098 }
00099 
00100 //----------------------------- POSE I/O --------------------------------
00101 
00102 std::ostream& operator<<(std::ostream& os, const Pose& p)
00103 {
00104    using namespace std ;
00105    os << '('
00106       << setw(8) << left << round(p.x())
00107       << setw(8) << left << round(p.y()) ;
00108 
00109    int th = round(p.theta()) ;
00110    if (th > 180)
00111       th -= 360 ;
00112    if (th == 0)
00113       os << th ;
00114    else
00115       os << showpos << th << noshowpos ;
00116    os << ')' ;
00117 
00118    return os ;
00119 }
00120 
00121 //-----------------------------------------------------------------------
00122 
00123 } // end of namespace encapsulating this file's definitions
00124 
00125 /* So things look consistent in everyone's emacs... */
00126 /* Local Variables: */
00127 /* indent-tabs-mode: nil */
00128 /* End: */
Generated on Sun May 8 08:41:31 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3