Polygon.C

00001 /*!@file FeatureMatching/Line.C Line segments algs */
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: Lior Elazary <elazary@usc.edu>
00034 // $HeadURL: $
00035 // $Id: $
00036 //
00037 
00038 #ifndef POLYGON_C_DEFINED
00039 #define POLYGON_C_DEFINED
00040 
00041 #include "FeatureMatching/Polygon.H"
00042 #include "Image/DrawOps.H"
00043 #include "GUI/DebugWin.H"
00044 #include "Util/FastMathFunctions.H"
00045 
00046 void Polygon::addLine(const Line& line)
00047 {
00048   itsLines.push_back(line);
00049 }
00050 
00051 // ######################################################################
00052 void Polygon::quantize(int nDirections)
00053 {
00054   itsNumDirections = nDirections;
00055   for(uint i=0; i<itsLines.size(); i++)
00056     itsLines[i].quantize(nDirections);
00057 }
00058 
00059 // ######################################################################
00060 void Polygon::rotate(double theta)
00061 {
00062   for(uint i=0; i<itsLines.size(); i++)
00063     itsLines[i].rotate(theta);
00064 }
00065 
00066 // ######################################################################
00067 void Polygon::shear(double k1, double k2)
00068 {
00069   for(uint i=0; i<itsLines.size(); i++)
00070     itsLines[i].shear(k1,k2);
00071 }
00072 
00073 // ######################################################################
00074 void Polygon::scale(float s)
00075 {
00076   itsLength = 0;
00077   for(uint i=0; i<itsLines.size(); i++)
00078   {
00079     itsLines[i].scale(s);
00080     itsLines[i].setQuantizedDir(itsNumDirections);
00081     itsLength += itsLines[i].getLength();
00082   }
00083 
00084 }
00085 
00086 // ######################################################################
00087 void Polygon::scale(float sx, float sy)
00088 {
00089   itsLength = 0;
00090   for(uint i=0; i<itsLines.size(); i++)
00091   {
00092     itsLines[i].scale(sx, sy);
00093     itsLines[i].setQuantizedDir(itsNumDirections);
00094     itsLength += itsLines[i].getLength();
00095   }
00096 }
00097 
00098 // ######################################################################
00099 void Polygon::setCOM()
00100 {
00101   Point2D<float> center(0,0);
00102   for (uint i=0 ; i<itsLines.size(); i++)
00103     center += itsLines[i].getCenter();
00104   center /= itsLines.size();
00105 
00106   center *= -1; //Shift by center
00107 
00108   trans(center);
00109 }
00110 
00111 // ######################################################################
00112 void Polygon::trans(Point2D<float> p)
00113 {
00114   for(uint i=0; i<itsLines.size(); i++)
00115     itsLines[i].trans(p);
00116 }
00117 
00118 // ######################################################################
00119 void Polygon::setWeights()
00120 {
00121   for(uint i=0; i<itsLines.size(); i++)
00122     itsLines[i].setWeight(itsLines[i].getLength()/itsLength);
00123 }
00124 
00125 // ######################################################################
00126 void Polygon::getBoundary(double &minx, double &miny, double &maxx, double &maxy)
00127 {
00128   minx = miny = 1e+10;
00129   maxx = maxy = -1e+10;
00130 
00131   for (uint i=0 ; i<itsLines.size() ; i++)
00132   {
00133     Point2D<float> p1 = itsLines[i].getP1();
00134     Point2D<float> p2 = itsLines[i].getP2();
00135 
00136     if (minx > p1.i) minx = p1.i;
00137     if (minx > p2.i) minx = p2.i;
00138 
00139     if (maxx < p1.i) maxx = p1.i;
00140     if (maxx < p2.i) maxx = p2.i;
00141 
00142     if (miny > p1.j) miny = p1.j;
00143     if (miny > p2.j) miny = p2.j;
00144 
00145     if (maxy < p1.j) maxy = p1.j;
00146     if (maxy < p2.j) maxy = p2.j;
00147   }     
00148 }
00149 
00150 
00151 // ######################################################################
00152 double Polygon::getRadius()
00153 {
00154   double radius = 0;
00155   Point2D<float> center(0,0);
00156   for(uint i=0; i<itsLines.size(); i++)
00157   {
00158     double dist = center.distance(itsLines[i].getP1());
00159     if (dist > radius)
00160       radius = dist;
00161 
00162     dist = center.distance(itsLines[i].getP2());
00163     if (dist > radius)
00164       radius = dist;
00165   }
00166   return radius;
00167 }
00168 
00169 
00170 
00171 // ######################################################################
00172 /* So things look consistent in everyone's emacs... */
00173 /* Local Variables: */
00174 /* indent-tabs-mode: nil */
00175 /* End: */
00176 
00177 #endif
00178 
Generated on Sun May 8 08:40:39 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3