find_neighbours.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
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();
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
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
00123
00124
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
00133 ActiveList* aList = (useIndex) ? (ActiveList*) new IndexedActiveList()
00134 : (ActiveList*) new SimpleActiveList();
00135
00136
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
00149 ObjectPairConsumer rejWithinDistPairCons(WithinDistanceRefine::name()
00150 + " reject");
00151
00152
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
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