test.cpp
Go to the documentation of this file.
00001 
00002 #include <iostream>
00003 #include <fstream>
00004 #include <vector>
00005 #include <stdlib.h>
00006 #include <utility>
00007 #include <math.h>
00008 #include <numeric>
00009 #include <sstream>
00010 
00011 #include <lama_common/point.h>
00012 #include <lama_common/polygon_utils.h> // for resamplePolygon()
00013 #include <pm_fourier/fourier.h>
00014 #include "utils.h"
00015 
00016 #define intro if (id==-1) { cerr << myId << " : " << __FUNCTION__ << "\n"; return; } else if (id!=myId) return;
00017 
00018 using namespace std;
00019 using lama_common::Point2;
00020 
00021 static void loadPolygon(const char *file, vector<Point2> &polygon) {
00022   ifstream ifs(file);
00023   polygon.clear();
00024   double x,y;
00025   while(ifs) {
00026     if (ifs >> x >> y) {
00027       polygon.push_back(Point2(x,y));
00028     }
00029   }
00030   ifs.close();
00031 }
00032 
00033 void getDissimilarity_fourier(int argc, char **argv, const int id, const int myId) {
00034   intro;
00035   if (argc < 3) {
00036     cerr << "usage: " << argv[0] << " <polygonFile1> <polygonFile2> <samples>\n";
00037     cerr << "numOfSamples .. for resampling polygons";
00038     cerr << "polygonFile* .. one point per line\n";
00039     exit(0);
00040   }
00041 
00042   const char *mapFile1 = argv[1];
00043   const char *mapFile2 = argv[2];
00044   //nst int numOfSamples = atoi(argv[3]);
00045 
00046   struct rusage t1,t2;
00047   getTime(&t1);
00048   vector<Point2> polygon1;
00049   vector<Point2> polygon2;
00050   loadPolygon(mapFile1,polygon1);
00051   loadPolygon(mapFile2,polygon2);
00052 
00053   double delta1;
00054   const int numOfSamples = 200;
00055   const int fftSize = 20;
00056 
00057   vector<Point2> rpol1(lama_common::resamplePolygon(polygon1,numOfSamples,delta1));
00058   vector<Point2> rpol2(lama_common::resamplePolygon(polygon2,numOfSamples,delta1));
00059 
00060   const double sim = getDissimilarityFourier(rpol1, rpol2,fftSize);
00061   getTime(&t2);
00062   getTime(t1,t2);
00063   rpol1.clear(); rpol2.clear(); polygon1.clear(); polygon2.clear();
00064 
00065   cout << sim << " " << getTime(t1,t2) << "\n";
00066 }
00067 
00068 void getDissimilarity_fourier_from_filelist(int argc, char **argv, const int id, const int myId) {
00069   intro;
00070   if (argc < 4) {
00071     cerr << "usage: " << argv[0] << " <fileList> <fftSize> <prefix>\n";
00072     cerr << "fileList  list of file pairs, each per pair line, these pair will be loaded and processed\n";
00073     exit(0);
00074   }
00075   const char *filelist = argv[1];
00076   const int fftSize = atoi(argv[2]);
00077   const char *prefix = argv[3];
00078 
00079   vector<std::pair<string,string> > files;
00080   ifstream ifs(filelist);
00081   while(ifs) {
00082     string a,b;
00083     if (ifs >> a >> b) {
00084       files.push_back(pair<string,string>(a,b));
00085     }
00086   }
00087   cerr << "Loaded " << files.size() << " file pairs from " << filelist << "\n";
00088 
00089   char name[2000];
00090   sprintf(name,"%s.fullresults",prefix);
00091   ofstream ofs(name);
00092 
00093   const int numOfSamples = 200;
00094   //    const int fftSize = 50;
00095 
00096   for(int i=0;i<(int)files.size();i++) {
00097     struct rusage t1,t2;
00098     getTime(&t1);
00099     vector<Point2> polygon1;
00100     vector<Point2> polygon2;
00101     loadPolygon(files[i].first.c_str(),polygon1);
00102     loadPolygon(files[i].second.c_str(),polygon2);
00103 
00104     double delta1;
00105 
00106     vector<Point2> rpol1(resamplePolygon(polygon1,numOfSamples,delta1));
00107     vector<Point2> rpol2(resamplePolygon(polygon2,numOfSamples,delta1));
00108 
00109     const double sim = getDissimilarityFourier(rpol1, rpol2,fftSize);
00110     getTime(&t2);
00111     getTime(t1,t2);
00112     rpol1.clear(); rpol2.clear(); polygon1.clear(); polygon2.clear();
00113 
00114     string f1a(files[i].first);
00115     string f2a(files[i].second);
00116 
00117     string f1( f1a.substr( f1a.rfind('/')+1)); 
00118     string f2( f2a.substr( f2a.rfind('/')+1)); 
00119 
00120     ofs << f1 << " " << f2 << " " << sim << " " << getTime(t1,t2) << "\n";
00121     ofs << f2 << " " << f1 << " " << sim << " " << getTime(t1,t2) << "\n";
00122 
00123     if (! (i % 1000)) {
00124       cerr <<  "Finished " << (100.0*i/files.size()) << "% \r";
00125     }
00126   }
00127   ofs.close();
00128 }
00129 
00130 
00131 int main(int argc, char **argv) {
00132 
00133   int k = -1;
00134   if (argc < 2) {
00135     cerr << "choose one of following:\n";
00136   } else {
00137     k = atoi(argv[1]);
00138     argc--;
00139     argv++;
00140   }
00141   getDissimilarity_fourier(argc,argv,k,1);
00142   getDissimilarity_fourier_from_filelist(argc,argv,k,2);
00143 }
00144 
00145 #undef intro
00146 
00147 


place_matcher_fourier
Author(s): Gaël Ecorchard , Karel Košnar , Vojtěch Vonásek
autogenerated on Sat Jun 8 2019 19:53:01