SpatialMetrics.C

Go to the documentation of this file.
00001 /*!@file Neuro/SpatialMetrics.C */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
00005 // by the 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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Neuro/SpatialMetrics.C $
00035 // $Id: SpatialMetrics.C 14593 2011-03-13 00:57:50Z dberg $
00036 //
00037 
00038 #ifndef NEURO_SPATIALMETRICS_C_DEFINED
00039 #define NEURO_SPATIALMETRICS_C_DEFINED
00040 
00041 #include "Neuro/SpatialMetrics.H"
00042 
00043 #include "Component/GlobalOpts.H"
00044 #include "Component/ModelOptionDef.H"
00045 #include "Component/OptionManager.H"
00046 #include "Image/Point2D.H"
00047 #include "Media/MediaOpts.H"
00048 #include "Neuro/NeuroOpts.H"
00049 #include "Util/TextLog.H"
00050 #include "Util/log.H"
00051 #include "Util/sformat.H"
00052 
00053 #include <algorithm>
00054 
00055 // ######################################################################
00056 SpatialMetrics::SpatialMetrics(OptionManager& mgr,
00057                                const std::string& descrName,
00058                                const std::string& tagName)
00059   :
00060   ModelComponent(mgr, descrName, tagName),
00061   itsLogFile(&OPT_TextLogFile, this),
00062   itsInputFrameDims(&OPT_InputFrameDims, this),
00063   itsFoveaRadius(&OPT_FoveaRadius, this),
00064   itsFOAradius(&OPT_FOAradius, this),
00065   itsPPD(&OPT_PixelsPerDegree, this)
00066 {}
00067 
00068 // ######################################################################
00069 SpatialMetrics::~SpatialMetrics()
00070 {}
00071 
00072 // ######################################################################
00073 int SpatialMetrics::getFoveaRadius() const
00074 { return itsFoveaRadius.getVal(); }
00075 
00076 // ######################################################################
00077 int SpatialMetrics::getFOAradius() const
00078 { return itsFOAradius.getVal(); }
00079 
00080 // ######################################################################
00081 double SpatialMetrics::getPPD() const
00082 { return itsPPD.getVal().ppd(); }
00083 
00084 // ######################################################################
00085 double SpatialMetrics::getPPDX() const
00086 { return itsPPD.getVal().ppdx(); }
00087 
00088 // ######################################################################
00089 double SpatialMetrics::getPPDY() const
00090 { return itsPPD.getVal().ppdy(); }
00091 
00092 // ######################################################################
00093 void SpatialMetrics::paramChanged(ModelParamBase* param,
00094                                   const bool valueChanged,
00095                                   ParamClient::ChangeStatus* status)
00096 {
00097   ModelComponent::paramChanged(param, valueChanged, status);
00098 
00099   OptionManager& mgr = this->getManager();
00100 
00101   if (param == &itsInputFrameDims && itsInputFrameDims.getVal().isNonEmpty())
00102     {
00103       const Dims indims = itsInputFrameDims.getVal();
00104 
00105       {
00106         // set the FOA radius if someone wants it but it is not set:
00107         int foaRadius = 0;
00108         convertFromString(mgr.getOptionValString(&OPT_FOAradius),
00109                           foaRadius);
00110         if (foaRadius == 0) {
00111           foaRadius = std::min(indims.w(), indims.h()) / 12;
00112           mgr.setOptionValString(&OPT_FOAradius,
00113                                  convertToString(foaRadius));
00114           LINFO("Using FOA radius = %d pixels", foaRadius);
00115           textLog(itsLogFile.getVal(),
00116                   "FOAradius", sformat("%d", foaRadius));
00117         }
00118       }
00119 
00120       {
00121         // set the fovea radius if someone wants it but it is not set:
00122         int foveaRadius = 0;
00123         convertFromString(mgr.getOptionValString(&OPT_FoveaRadius),
00124                           foveaRadius);
00125         if (foveaRadius == 0) {
00126           foveaRadius = std::min(indims.w(), indims.h()) / 12;
00127           mgr.setOptionValString(&OPT_FoveaRadius,
00128                                  convertToString(foveaRadius));
00129           LINFO("Using fovea radius = %d pixels", foveaRadius);
00130           textLog(itsLogFile.getVal(),
00131                   "FoveaRadius", sformat("%d", foveaRadius));
00132         }
00133       }
00134 
00135     }
00136 }
00137 
00138 // ######################################################################
00139 void SpatialMetrics::setFoveaRadius(int val)
00140 {
00141   getManager().setOptionValString(&OPT_FoveaRadius, convertToString(val));
00142 }
00143 
00144 // ######################################################################
00145 void SpatialMetrics::setFOAradius(int val)
00146 {
00147   getManager().setOptionValString(&OPT_FOAradius, convertToString(val));
00148 }
00149 
00150 // ######################################################################
00151 void SpatialMetrics::pix2deg(const Point2D<int>& pixloc,
00152                              double& xdeg, double& ydeg) const
00153 {
00154   const double width = double(itsInputFrameDims.getVal().w());
00155   const double height = double(itsInputFrameDims.getVal().h());
00156   const double ppdx = itsPPD.getVal().ppdx();
00157   const double ppdy = itsPPD.getVal().ppdy();
00158 
00159   xdeg = atan((2.0 * pixloc.i / width - 1.0) *
00160               tan(width / ppdx * M_PI / 360.0)) * 180.0 / M_PI;
00161   ydeg = atan((1.0 - 2.0 * pixloc.j / height) *
00162               tan(height / ppdy * M_PI / 360.0)) * 180.0 / M_PI;
00163 }
00164 
00165 // ######################################################################
00166 void SpatialMetrics::deg2pix(const double xdeg, const double ydeg,
00167                              Point2D<int>& pixloc) const
00168 {
00169   const double width = double(itsInputFrameDims.getVal().w());
00170   const double height = double(itsInputFrameDims.getVal().h());
00171   const double ppdx = itsPPD.getVal().ppdx();
00172   const double ppdy = itsPPD.getVal().ppdy();
00173 
00174   pixloc.i = int(0.5 * width * (1.0 + tan(xdeg * M_PI / 180.0) /
00175                                 tan(width / ppdx * M_PI / 360.0)));
00176   pixloc.j = int(0.5 * height * (1.0 - tan(ydeg * M_PI / 180.0) /
00177                                  tan(height / ppdy * M_PI / 360.0)));
00178 }
00179 
00180 // ######################################################################
00181 Dims SpatialMetrics::getInputFrameDims() const
00182 { return itsInputFrameDims.getVal(); }
00183 
00184 
00185 
00186 // ######################################################################
00187 /* So things look consistent in everyone's emacs... */
00188 /* Local Variables: */
00189 /* mode: c++ */
00190 /* indent-tabs-mode: nil */
00191 /* End: */
00192 
00193 #endif // NEURO_SPATIALMETRICS_C_DEFINED
Generated on Sun May 8 08:41:04 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3