find_neighbours.cpp

Go to the documentation of this file.
00001 
00002 
00003 //-----------------------------------------------------------------------------
00004 // CVS: $Revision: 2866 $, $Date: 2006-09-15 12:04:57 +0100 (Fri, 15 Sep 2006) $, $Author: rsc $
00005 //-----------------------------------------------------------------------------
00006 /*                                                         Based on nn_file.cpp
00007  * Command line options are:
00008  *
00009  * <a_dir> [optional - default is ./]
00010  *   The common directory prefix for all file I/O
00011  * <a_file>
00012  *   The common file name prefix, or full filename (including path).
00013  * <binary|ascii>
00014  *   indicates if the file is binary or ascii.
00015  * <large|small>
00016  *   both input and output files are larger than 2 Gb
00017  * <maxDistInArcSecs>
00018  *   as it says.
00019  * <index|list>
00020  *   Indexed or list for the active list.
00021  * <filter|nested|sweep>
00022  *   Use CM filter, or generic nested loop, or generic plane sweep.
00023  * <outfile_name>
00024  *   Name of the output file for the final matches.
00025  * <binary|ascii>
00026  *   indicates if the file is binary or ascii.
00027  */
00028 //-----------------------------------------------------------------------------
00029 #include <iostream>
00030 #include "String.h"
00031 
00032 #include "ActiveList.h"
00033 #include "DecPlaneSweepFilter.h"
00034 #include "FileReader.h"
00035 #include "FileWriter.h"
00036 #include "Filter.h"
00037 #include "IndexedActiveList.h"
00038 #include "Matcher.h"
00039 #include "Neighbours.h"
00040 #include "NeighboursTextFileWriter.h"
00041 #include "NeighboursBinaryFileWriter.h"
00042 #include "NestedLoopFilter.h"
00043 #include "Object.h"
00044 #include "ObjectConsumer.h"
00045 #include "ObjectPairConsumer.h"
00046 #include "ObjectPairRefineConsumer.h"
00047 #include "ObjectProducer.h"
00048 #include "Refine.h"
00049 #include "SimpleActiveList.h"
00050 #include "Timer.h"
00051 #include "WithinDistanceRefine.h"
00052 #include "WSATextFileReader.h"
00053 #include "WSAReader.h"
00054 //-----------------------------------------------------------------------------
00055 static void usage(char const * const prog_name)
00056 {
00057   std::cerr << prog_name
00058           << " [dir] <file> <binary|ascii> <large|small>"
00059           << " <maxDistInArcSecs> <index|list> <filter|nested|sweep>"
00060           << " <outfile_name> <binary|ascii>"
00061           << std::endl;
00062 }
00063 //-----------------------------------------------------------------------------
00064 int main(int argc, char * argv[])
00065 {
00066 #ifdef PLOT_TIMES
00067   Timer::globalTimer()->cont();        // need to start the timer
00068 #endif
00069 
00070   int status = 0;
00071   const int cAllParamTotal = 10;
00072 
00073   if (argc != cAllParamTotal && argc != cAllParamTotal-1)
00074   {
00075     usage(argv[0]);
00076     status = 1;
00077   }
00078   else
00079   {
00080 // ******** Read in Arguments ***********
00081     int param = 1;
00082     char *dirStr = (argc == cAllParamTotal) ? argv[param++]
00083                                             : 0;
00084     String directory;
00085     if (dirStr)
00086     {
00087       directory = String(dirStr);
00088       if (directory[directory.size()-1] != '/')
00089       {
00090         directory += '/';
00091       }
00092     } else {
00093       directory = "";
00094     }
00095     char *nameStr = argv[param++];
00096     String inputFilePath = directory + String(nameStr);
00097     String inputFileDtd = inputFilePath;
00098     inputFileDtd.replace(inputFileDtd.find("."), 4, ".dtd");
00099     bool isBinary = (strcmp(argv[param++], "binary") == 0);
00100     bool isLarge = (strcmp(argv[param++], "large") == 0);
00101     double maxDist = atof(argv[param++])/3600.0;
00102     bool useIndex = (strcmp(argv[param++], "index") == 0);
00103     bool useFilter =     (strcmp(argv[param], "filter") == 0);
00104     bool useNestedLoop = (!useFilter && strcmp(argv[param], "nested") == 0);
00105     char *outNameStr = argv[++param];
00106     String outputFilePath = directory + String(outNameStr);
00107     bool isOutBinary = (strcmp(argv[++param], "binary") == 0);
00108 
00109 #ifndef SILENT
00110     if (useFilter)
00111       std::cout << "Using NN filter           : true" << std::endl; 
00112     else if (useNestedLoop)
00113       std::cout << "Using generic nested loop : true" << std::endl;
00114     else
00115       std::cout << "Using generic plane sweep : true" << std::endl;
00116     std::cout << "Using index active list   : "
00117               << ((useIndex) ? "true" : "false")
00118               << std::endl;
00119     std::cout << "Max distance (Dec Degs)   : " << maxDist << std::endl;
00120 #endif
00121 
00122 // ******** Create Matcher ***********
00123 
00124     // Read in objects with an object producer
00125     ObjectProducer* prod = new
00126       ObjectProducer(new
00127         FileReader(isBinary ? (FileObjectReader *) new WSAReader(inputFileDtd)
00128                             : (FileObjectReader *) new WSATextFileReader(),
00129                    inputFilePath.c_str(),
00130                    isLarge));
00131 
00132     // Create the active list
00133     ActiveList* aList = (useIndex) ? (ActiveList*) new IndexedActiveList()
00134                                    : (ActiveList*) new SimpleActiveList();
00135 
00136     // Write out matched pairs to a file, output always large file just in case
00137     bool isOutLarge = true;
00138     ObjectPairConsumer accWithinDistPairCons
00139     (
00140       WithinDistanceRefine::name() + " accept",
00141       (isOutBinary) ? (ObjectPairWriter*) 
00142                        new NeighboursBinaryFileWriter(outputFilePath.c_str(),
00143                                                       isOutLarge)
00144                     : (ObjectPairWriter*)
00145                        new NeighboursTextFileWriter(outputFilePath.c_str(),
00146                                                     isOutLarge)
00147     );
00148     // Ignore rejected pairs
00149     ObjectPairConsumer rejWithinDistPairCons(WithinDistanceRefine::name()
00150                                              + " reject");
00151 
00152     // Refine matched pairs using WithinDistance
00153     WithinDistanceRefine withinDistRefine(maxDist,
00154                                           &accWithinDistPairCons,
00155                                           &rejWithinDistPairCons);
00156     ObjectPairRefineConsumer pairCons
00157     (
00158       (useNestedLoop) ? NestedLoopFilter::name()
00159                       : DecPlaneSweepFilter::name(),
00160       &withinDistRefine
00161     );
00162 
00163     ObjectConsumer cons("points reject");
00164 
00165     Matcher *matcher = new Neighbours(prod, aList, &pairCons, &cons, maxDist);
00166 
00167 // ******** Filter ***********
00168 
00169     Filter *filter = 0;
00170 
00171     if (useFilter)
00172       filter = new Filter(matcher);
00173     else if (useNestedLoop)
00174       filter = new NestedLoopFilter(matcher);
00175     else
00176       filter = new DecPlaneSweepFilter(matcher);
00177 
00178     filter->filter();
00179 
00180     delete filter;
00181   }
00182 
00183   return status;
00184 }
00185 //-----------------------------------------------------------------------------
Generated on Mon Oct 4 10:39:55 2010 for Matching.kdevelop by  doxygen 1.6.3