frcm_file.cpp

Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2004 CSIRO ICT Centre
00003  *
00004  * $Id: frcm_file.cpp 1193 2005-09-20 15:23:10Z rsc $
00005  */
00006 
00007 /*
00008  * This is the program used to perform fixed radius cross match benchmarking.
00009  *
00010  * Note - this file is an alteration of cm_file.cpp, without the threshold
00011  * refine option and using the WithinDistanceRefine in place of AngularSeparationRefine.
00012  *
00013  * At first it may seem an overwhelming number of parameters, but there
00014  * aren't really that many:
00015  *
00016  * The first 4 describe the input file(s):
00017  *
00018  * <a_dir|0>        The directory path containing the input files, 0 for a single file.
00019  * <a_file>         The common file name prefix, or full filename (including path).
00020  * <binary|ascii>   Indicates if the file is in binary or ascii format
00021  * [merge]          currently only required for 2MASS.
00022  *
00023  * The next 3 (or 4 if "merge" used) are for the other catalogue.
00024  *
00025  * <maxDistInArcSecs> Match fixed radius, in arc seconds.
00026  * <index|list>     Indexed or list for the active list.
00027  * <bb|as>          Bounding Box test with Angular Separation, or just Angular Separation 
00028  * <filter|nested|sweep>
00029  *                  Use CM filter, or generic nested loop, or generic plane sweep.
00030  * <outfile_name>   Name of the output file for the final matches.
00031  *
00032  * The output currently reports the number of matches (and non-matches) found.
00033  *
00034  * To write the output to a file, will need to modify the ObjectConsumers
00035  * (uaCons and ubCons) for the unmatched objects, or the various
00036  * ObjectPairConsumers used by the ObjectPairRefineConsumers.
00037  * Examples are included in comments below.
00038  */
00039 
00040 #include <iostream>
00041 #include "String.h"
00042 
00043 #include "ActiveList.h"
00044 #include "BinaryFileObjectWriter.h"
00045 #include "BoundingBoxRefine.h"
00046 #include "DecPlaneSweepFilter.h"
00047 #include "FileProducerFactory.h"
00048 #include "FileWriter.h"
00049 #include "FilePairWriter.h"
00050 #include "Filter.h"
00051 #include "FixedRadiusCrossMatch.h"
00052 #include "IndexedActiveList.h"
00053 #include "Matcher.h"
00054 #include "NestedLoopFilter.h"
00055 #include "Object.h"
00056 #include "ObjectConsumer.h"
00057 #include "ObjectPairConsumer.h"
00058 #include "ObjectPairRefineConsumer.h"
00059 #include "ObjectProducer.h"
00060 #include "ObjectPairRefine.h"
00061 #include "SimpleActiveList.h"
00062 #include "TextFileObjectWriter.h"
00063 #include "Timer.h"
00064 #include "WithinDistanceRefine.h"
00065 
00066 
00067 static void usage(char const * const prog_name)
00068 {
00069   std::cerr << prog_name
00070             << " <a_dir|0> <a_file> <binary|ascii> [merge]"
00071             << " <b_dir|0> <b_file> <binary|ascii> [merge]"
00072             << " <maxDistInArcSecs> <index|list> <bb|as> <filter|nested|sweep>"
00073             << " <outfile_name>" << std::endl;
00074 }
00075 
00076 int main(int argc, char * argv[])
00077 {
00078 #ifdef PLOT_TIMES
00079   Timer::globalTimer()->cont();        // need to start the timer
00080 #endif
00081 
00082   int status = 0;
00083 
00084   if (argc < 12 || argc > 14)
00085   {
00086     usage(argv[0]);
00087     status = 1;
00088   }
00089   else
00090   {
00091     int param = 1;
00092     char * aDir = argv[param++];
00093     char * aName = argv[param++];
00094     bool aBinary = true;
00095     if (strcmp(argv[param++], "ascii") == 0)
00096       aBinary = false;
00097     bool aMerge = false;
00098     if (strcmp(argv[param], "merge") == 0)
00099     {
00100       aMerge = true;
00101       param++;
00102     }
00103 
00104     char * bDir = argv[param++];
00105     char * bName = argv[param++];
00106     bool bBinary = true;
00107     if (strcmp(argv[param++], "ascii") == 0)
00108       bBinary = false;
00109     bool bMerge = false;
00110     if (strcmp(argv[param], "merge") == 0)
00111     {
00112       bMerge = true;
00113       param++;
00114     }
00115 
00116     double maxDist = atof(argv[param++])/3600.0;
00117 
00118     bool useIndex =      (strcmp(argv[param++], "index") == 0);
00119     bool useBB =         (strcmp(argv[param++], "bb") == 0);
00120     bool useFilter =     (strcmp(argv[param], "filter") == 0);
00121     bool useNestedLoop = (!useFilter && strcmp(argv[param], "nested") == 0);
00122 
00123     char * outFile = argv[++param];
00124 
00125     if (useFilter)
00126       std::cout << "Using FRCM filter         : true" << std::endl; 
00127     else if (useNestedLoop)
00128       std::cout << "Using generic nested loop : true" << std::endl;
00129     else
00130       std::cout << "Using generic plane sweep : true" << std::endl;
00131     std::cout << "Using index active list   : " << ((useIndex) ? "true" : "false") << std::endl;
00132     std::cout << "Using full BB refine      : " << ((useBB) ? "true" : "false") << std::endl;
00133     std::cout << "Max distance (Dec Degs)   : " << maxDist << std::endl;
00134 
00135     /* Consume successful angular separation refine candidates to a file */
00136     ObjectPairConsumer accWithinDistPairCons(WithinDistanceRefine::name() + " accept",
00137                          new FilePairWriter(new TextFileObjectWriter(), outFile, true));
00138 //                         new FilePairWriter(new BinaryFileObjectWriter(), outFile, true));
00139     ObjectPairConsumer rejWithinDistPairCons(WithinDistanceRefine::name() + " reject");
00140 
00141     WithinDistanceRefine distanceRefine(maxDist, &accWithinDistPairCons,
00142                                                  &rejWithinDistPairCons);
00143 
00144     ObjectPairRefineConsumer bbCons(BoundingBoxRefine::name(), &distanceRefine);
00145 
00146     ObjectPairConsumer rejBBPairCons(BoundingBoxRefine::name() + " reject");
00147 
00148     BoundingBoxRefine bbRefine(&bbCons, &rejBBPairCons);
00149 
00150     // depending on value of useBB and useThreshold, set the appropriate refine
00151     ObjectPairRefineConsumer pairCons(useNestedLoop ? NestedLoopFilter::name()
00152                                                     : DecPlaneSweepFilter::name(),
00153                                       useBB ? (ObjectPairRefine*) &bbRefine
00154                                             : (ObjectPairRefine*) &distanceRefine);
00155 
00156 
00157     ObjectConsumer uaCons("A points reject");
00158     ObjectConsumer ubCons("B points reject");
00159 
00160     ObjectProducer * aProd = FileProducerFactory::instance()->createProducer(
00161                                         aDir, aName, aBinary, aMerge, true, false);
00162     ObjectProducer * bProd = FileProducerFactory::instance()->createProducer(
00163                                         bDir, bName, bBinary, bMerge, true, false);
00164 
00165     ActiveList * aList = (useIndex) ? (ActiveList *) new IndexedActiveList()
00166                                     : (ActiveList *) new SimpleActiveList();
00167     Matcher * matcher = new FixedRadiusCrossMatch(aProd, bProd, aList , &pairCons, &uaCons, &ubCons, maxDist);
00168     Filter * filter = 0;
00169 
00170     if (useFilter)
00171       filter = new Filter(matcher);
00172     else if (useNestedLoop)
00173       filter = new NestedLoopFilter(matcher);
00174     else
00175       filter = new DecPlaneSweepFilter(matcher);
00176 
00177     filter->filter();
00178 
00179     delete filter;
00180   }
00181 
00182   return status;
00183 }
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3