readMatrix.C

Go to the documentation of this file.
00001 /*! @file VFAT/readMatrix.C [put description here] */
00002 
00003 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/VFAT/readMatrix.C $
00004 // $Id: readMatrix.C 6182 2006-01-31 18:41:41Z rjpeters $
00005 
00006 #include "VFAT/readMatrix.H"
00007 
00008 #include "Util/log.H"
00009 #include "Util/readConfig.H"
00010 
00011 #include <iostream>
00012 #include <fstream>
00013 #include <string>
00014 
00015 readMatrix::readMatrix(const char* fileName)
00016 {
00017   int row = 0;
00018   bool firstLine = false;
00019   bool comment = false;
00020   std::vector<std::vector<double> >::iterator rowIter;
00021   std::vector<double>::iterator columnIter;
00022   std::ifstream inFile(fileName,std::ios::in);
00023   std::string in;
00024   LINFO("LOAD MATRIX %s",fileName);
00025   while (inFile >> in)
00026   {
00027     if(!in.compare("#")) //comment code # found
00028     {
00029       if(!comment)
00030       {
00031         comment = true;
00032       }
00033       else              //end of comment
00034       {
00035         comment = false;
00036       }
00037     }
00038     if((!comment) && in.compare("#")) //real line found
00039     {
00040       // the first line contains the diminsions
00041       // resize the vector
00042       if(firstLine == false)
00043       {
00044         sizeX = (int)atof(in.c_str());
00045         inFile >> in;
00046         sizeY = (int)atof(in.c_str());
00047         firstLine = true;
00048         std::vector<double> tvec(sizeX,0.0F);
00049         vectorIn.resize(sizeY,tvec);
00050         rowIter = vectorIn.begin();
00051         columnIter = rowIter->begin();
00052       }
00053       else
00054       {
00055         *columnIter = atof(in.c_str());
00056         ++columnIter;
00057         // if end of column reached, return
00058         if(columnIter == rowIter->end())
00059         {
00060           row++;
00061           ++rowIter;
00062           if(row < sizeY)
00063             columnIter = rowIter->begin();
00064           //ASSERT(sizeY > row);
00065         }
00066       }
00067     }
00068   }
00069 }
00070 
00071 readMatrix::~readMatrix()
00072 {}
00073 
00074 std::vector<std::vector<double> >  readMatrix::returnMatrix()
00075 {
00076   return vectorIn;
00077 }
00078 
00079 Image<float> readMatrix::returnMatrixAsImage()
00080 {
00081   std::vector<std::vector<double> >::iterator rowIter;
00082   std::vector<double>::iterator columnIter;
00083   Image<float> intermed;
00084   intermed.resize(sizeY,sizeX);
00085   int x = 0;
00086   for(rowIter = vectorIn.begin(); rowIter != vectorIn.end(); ++rowIter, x++)
00087   {
00088     int y = 0;
00089     for(columnIter = rowIter->begin(); columnIter != rowIter->end();
00090         ++columnIter, y++)
00091     {
00092       float whatthefuck;
00093       whatthefuck = *columnIter;
00094       intermed.setVal(x,y,whatthefuck);
00095     }
00096   }
00097   outImage = intermed;
00098   return outImage;
00099 }
00100 
00101 void readMatrix::echoMatrix()
00102 {
00103   std::vector<std::vector<double> >::iterator rowIter;
00104   std::vector<double>::iterator columnIter;
00105   for(rowIter = vectorIn.begin(); rowIter != vectorIn.end(); ++rowIter)
00106   {
00107     for(columnIter = rowIter->begin(); columnIter != rowIter->end();
00108         ++columnIter)
00109     {
00110       std::cerr << *columnIter << " ";
00111     }
00112     std::cerr << "\n";
00113   }
00114 }
00115 
Generated on Sun May 8 08:42:34 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3