nn_file.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 CSIRO ICT Centre
00003  *
00004  * $Id: nn_file.cpp 587 2004-12-03 15:06:33Z nch $
00005  */
00006 
00007 /*
00008  * This is the program used to perform the nearest neighbour benchmarking.
00009  *
00010  * Command line options are:
00011  *
00012  * <a_dir|0>        The directory path containing the input files, 0 for a single file.
00013  * <a_file>         The common file name prefix, or full filename (including path).
00014  * <binary|ascii>   indicates if the file is binary or ascii.
00015  * [merge]          currently only required for 2MASS.
00016  * <maxDistInArcSecs> as it says.
00017  * <index|list>     Indexed or list for the active list.
00018  * <filter|nested|sweep>
00019  *                  Use CM filter, or generic nested loop, or generic plane sweep.
00020  */
00021 
00022 #include <iostream>
00023 #include "String.h"
00024 
00025 #include "ActiveList.h"
00026 #include "DecPlaneSweepFilter.h"
00027 #include "FileProducerFactory.h"
00028 #include "FilePairWriter.h"
00029 #include "FileWriter.h"
00030 #include "Filter.h"
00031 #include "IndexedActiveList.h"
00032 #include "Matcher.h"
00033 #include "Neighbours.h"
00034 #include "NestedLoopFilter.h"
00035 #include "Object.h"
00036 #include "ObjectConsumer.h"
00037 #include "ObjectPairConsumer.h"
00038 #include "ObjectPairRefineConsumer.h"
00039 #include "ObjectProducer.h"
00040 #include "Refine.h"
00041 #include "SimpleActiveList.h"
00042 #include "TextFileDatumWriter.h"
00043 #include "Timer.h"
00044 #include "WithinDistanceRefine.h"
00045 
00046 
00047 static void usage(char const * const prog_name)
00048 {
00049   std::cerr << prog_name
00050           << " <dir|0> <file> <binary|ascii> [merge]"
00051           << " <maxDistInArcSecs> <index|list> <filter|nested|sweep>" << std::endl;
00052 }
00053 
00054 int main(int argc, char * argv[])
00055 {
00056 #ifdef PLOT_TIMES
00057   Timer::globalTimer()->cont();        // need to start the timer
00058 #endif
00059 
00060   int status = 0;
00061 
00062   if (argc != 7 && argc != 8)
00063   {
00064     usage(argv[0]);
00065     status = 1;
00066   }
00067   else
00068   {
00069     int param = 1;
00070     char * dir = argv[param++];
00071     char * name = argv[param++];
00072     bool binary = (strcmp(argv[param++], "binary") == 0);
00073     bool merge = false;
00074     if (strcmp(argv[param], "merge") == 0)
00075     {
00076       merge = true;
00077       param++;
00078     }
00079 
00080     double maxDist = atof(argv[param++])/3600.0;
00081     bool useIndex = (strcmp(argv[param++], "index") == 0);
00082     bool useFilter =     (strcmp(argv[param], "filter") == 0);
00083     bool useNestedLoop = (!useFilter && strcmp(argv[param++], "nested") == 0);
00084 
00085     if (useFilter)
00086       std::cout << "Using NN filter           : true" << std::endl; 
00087     else if (useNestedLoop)
00088       std::cout << "Using generic nested loop : true" << std::endl;
00089     else
00090       std::cout << "Using generic plane sweep : true" << std::endl;
00091     std::cout << "Using index active list   : " << ((useIndex) ? "true" : "false") << std::endl;
00092     std::cout << "Max distance (Dec Degs)   : " << maxDist << std::endl;
00093 
00094     // example to output the neighbours to a file
00095 //    ObjectPairConsumer accWithinDistPairCons(WithinDistanceRefine::name() + " accept",
00096 //                                            new FilePairWriter(new TextFileDatumWriter(), "ACC"));
00097     ObjectPairConsumer accWithinDistPairCons(WithinDistanceRefine::name() + " accept");
00098     ObjectPairConsumer rejWithinDistPairCons(WithinDistanceRefine::name() + " reject");
00099 
00100     WithinDistanceRefine withinDistRefine(maxDist,
00101                                           &accWithinDistPairCons,
00102                                           &rejWithinDistPairCons);
00103 
00104     ObjectPairRefineConsumer pairCons(((useNestedLoop) ? NestedLoopFilter::name()
00105                                                        : DecPlaneSweepFilter::name()),
00106                                       &withinDistRefine);
00107 
00108     ObjectProducer * prod = FileProducerFactory::instance()->
00109                                 createProducer(dir, name, binary, merge, false);
00110 
00111     // example to output the non matches to a file
00112 //    ObjectConsumer cons("points reject", new FileWriter(new TextFileDatumWriter(), "NM"));
00113     ObjectConsumer cons("points reject");
00114 
00115     ActiveList * aList = (useIndex) ? (ActiveList *) new IndexedActiveList()
00116                                     : (ActiveList *) new SimpleActiveList();
00117     Matcher * matcher = new Neighbours(prod, aList, &pairCons, &cons, maxDist);
00118     Filter * filter = 0;
00119 
00120     if (useFilter)
00121       filter = new Filter(matcher);
00122     else if (useNestedLoop)
00123       filter = new NestedLoopFilter(matcher);
00124     else
00125       filter = new DecPlaneSweepFilter(matcher);
00126 
00127     filter->filter();
00128 
00129     delete filter;
00130   }
00131 
00132   return status;
00133 }
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3