jp_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
00030
00031
00032
00033
00034
00035
00036
00037 #include <iostream>
00038 #include "String.h"
00039
00040 #include "ActiveList.h"
00041 #include "BoundingBoxRefine.h"
00042 #include "CrossNeighboursTextFileWriter.h"
00043 #include "CrossNeighboursBinaryFileWriter.h"
00044 #include "DecPlaneSweepFilter.h"
00045 #include "FileReader.h"
00046 #include "FileWriter.h"
00047 #include "Filter.h"
00048 #include "FixedRadiusCrossMatch.h"
00049 #include "IndexedActiveList.h"
00050 #include "Matcher.h"
00051 #include "NestedLoopFilter.h"
00052 #include "Object.h"
00053 #include "ObjectConsumer.h"
00054 #include "ObjectPairConsumer.h"
00055 #include "ObjectPairRefineConsumer.h"
00056 #include "ObjectProducer.h"
00057 #include "SimpleActiveList.h"
00058 #include "Timer.h"
00059 #include "WithinDistanceRefine.h"
00060 #include "JPTextFileReader.h"
00061 #include "WSAReader.h"
00062
00063 static void usage(char const * const prog_name)
00064 {
00065 std::cerr << prog_name
00066 << " [dir] <main_file> <binary|ascii> <large|small>"
00067 << " <external_file> <binary|ascii> <large|small>"
00068 << " <maxDistInArcSecs> <index|list> <filter|nested|sweep>"
00069 << " <outfile_name> <binary|ascii> <swap|noswap>" << std::endl;
00070 }
00071
00072 int main(int argc, char * argv[])
00073 {
00074 #ifdef PLOT_TIMES
00075 Timer::globalTimer()->cont();
00076 #endif
00077
00078 int status = 0;
00079 const int cAllParamCt = 13;
00080 const int cOptParamCt = 1;
00081 const int cSupParamCt = argc-1;
00082
00083 if (cSupParamCt < cAllParamCt - cOptParamCt ||
00084 cSupParamCt > cAllParamCt)
00085 {
00086 usage(argv[0]);
00087 status = 1;
00088 }
00089 else
00090 {
00091
00092 int param = 1;
00093 char *dirStr = (cSupParamCt == cAllParamCt) ? argv[param++]
00094 : 0;
00095 String directory;
00096 if (dirStr)
00097 {
00098 directory = String(dirStr);
00099 if (directory[directory.size()-1] != '/')
00100 {
00101 directory += '/';
00102 }
00103 } else {
00104 directory = "";
00105 }
00106
00107 char *mainNameStr = argv[param++];
00108 String mainFilePath = directory + String(mainNameStr);
00109 String mainFileDtd = mainFilePath;
00110 mainFileDtd.replace(mainFileDtd.find("."), 4, ".dtd");
00111 bool isMainBinary = (strcmp(argv[param++], "binary") == 0);
00112 bool isMainLarge = (strcmp(argv[param++], "large") == 0);
00113
00114 char *externNameStr = argv[param++];
00115 String externFilePath = directory + String(externNameStr);
00116 String externFileDtd = externFilePath;
00117 externFileDtd.replace(externFileDtd.find("."), 4, ".dtd");
00118 bool isExternBinary = (strcmp(argv[param++], "binary") == 0);
00119 bool isExternLarge = (strcmp(argv[param++], "large") == 0);
00120
00121 double maxDist = atof(argv[param++])/3600.0;
00122
00123 bool useIndex = (strcmp(argv[param++], "index") == 0);
00124 bool useFilter = (strcmp(argv[param], "filter") == 0);
00125 bool useNestedLoop = (!useFilter && strcmp(argv[param], "nested") == 0);
00126
00127 char *outFileStr = argv[++param];
00128 bool isOutBinary = (strcmp(argv[++param], "binary") == 0);
00129 bool isOutLarge = true;
00130
00131 bool isSwap = (strcmp(argv[++param], "noswap") != 0);
00132
00133 #ifndef SILENT
00134 if (useFilter)
00135 std::cout << "Using FRCM filter : true" << std::endl;
00136 else if (useNestedLoop)
00137 std::cout << "Using generic nested loop : true" << std::endl;
00138 else
00139 std::cout << "Using generic plane sweep : true" << std::endl;
00140 std::cout << "Using index active list : "
00141 << ((useIndex) ? "true" : "false")
00142 << std::endl;
00143 std::cout << "Max distance (Dec Degs) : " << maxDist << std::endl;
00144 #endif
00145
00146
00147
00148
00149 ObjectProducer* mainProd =
00150 new ObjectProducer(new FileReader(
00151 (isMainBinary) ? (FileObjectReader *) new WSAReader(mainFileDtd)
00152 : (FileObjectReader *) new JPTextFileReader(),
00153 mainFilePath.c_str(),
00154 isMainLarge));
00155
00156 ObjectProducer* externProd =
00157 new ObjectProducer(new FileReader(
00158 (isExternBinary) ? (FileObjectReader *) new WSAReader(externFileDtd)
00159 : (FileObjectReader *) new JPTextFileReader(),
00160 externFilePath.c_str(),
00161 isExternLarge));
00162
00163
00164 ActiveList * aList = (useIndex) ? (ActiveList *) new IndexedActiveList()
00165 : (ActiveList *) new SimpleActiveList();
00166
00167
00168 String outputFilePath = directory + String(outFileStr);
00169
00170 ObjectPairConsumer accWithinDistPairCons
00171 (
00172 WithinDistanceRefine::name() + " accept",
00173 (isOutBinary) ? (ObjectPairWriter*) new
00174 CrossNeighboursBinaryFileWriter(outputFilePath.c_str(),
00175 isOutLarge,
00176 isSwap)
00177 : (ObjectPairWriter*) new
00178 CrossNeighboursTextFileWriter(outputFilePath.c_str(),
00179 isOutLarge)
00180 );
00181
00182 ObjectPairConsumer rejWithinDistPairCons(WithinDistanceRefine::name()
00183 + " reject");
00184
00185
00186 WithinDistanceRefine withinDistRefine(maxDist,
00187 &accWithinDistPairCons,
00188 &rejWithinDistPairCons);
00189 ObjectPairRefineConsumer pairCons
00190 (
00191 (useNestedLoop) ? NestedLoopFilter::name()
00192 : DecPlaneSweepFilter::name(),
00193 &withinDistRefine
00194 );
00195
00196 ObjectConsumer mainRejCons("Main catalogue points reject");
00197 ObjectConsumer externRejCons("External catalogue points reject");
00198
00199 Matcher * matcher = new FixedRadiusCrossMatch(mainProd,
00200 externProd,
00201 aList,
00202 &pairCons,
00203 &mainRejCons,
00204 &externRejCons,
00205 maxDist);
00206
00207
00208 Filter * filter = 0;
00209
00210 if (useFilter)
00211 filter = new Filter(matcher);
00212 else if (useNestedLoop)
00213 filter = new NestedLoopFilter(matcher);
00214 else
00215 filter = new DecPlaneSweepFilter(matcher);
00216
00217 filter->filter();
00218
00219 delete filter;
00220 }
00221
00222 return status;
00223 }
00224