HtmIndex.hxx
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007 #ifndef HTMINDEX_H
00008 #define HTMINDEX_H
00009
00010 #include "htm.h"
00011 #include <limits>
00012
00013 #include "Constants.h"
00014 #include "Converter.h"
00015 #include "DataMethod.hxx"
00016 #include "Logger.h"
00017 #include "StringOps.h"
00018
00020 template<typename DataType>
00021 class HtmIndex : public DataMethod<DataType>
00022 {
00023 public:
00026 HtmIndex(int htmLevel)
00027 {
00028 DataMethod<DataType>::methodName = "HtmIndex";
00029 Logger log;
00030 log.addMessage("Making HTM indicies with level = "
00031 + StringOps::NumToString(htmLevel));
00032 mHtmPtr = new SpatialIndex(htmLevel);
00033 }
00034
00036 virtual ~HtmIndex() { delete mHtmPtr; }
00037
00039 void setSource(IntMap& tbls, IntMap& cols, StringMap units)
00040 {
00041 raColno = cols[0];
00042 decColno = cols[1];
00043 Converter converter;
00044 mDecFact = converter.getFactor(units[0], "Degrees");
00045 mRAFact = converter.getFactor(units[1], "Degrees");
00046 }
00047
00049 void setTarget(IntMap& cols, StringMap units)
00050 {
00051 htmColno = cols[0];
00052 }
00053
00055 void doit(TableData<DataType>& data, int row1, int row2)
00056 {
00057 Logger log;
00058
00059 for (int rowNo = row1; rowNo < row2; ++rowNo)
00060 {
00061 double ra, dec;
00062 data.value(raColno, rowNo, ra);
00063 data.value(decColno, rowNo, dec);
00064
00065
00066 if (ra != ra or std::isinf(ra) or
00067 dec != dec or std::isinf(dec))
00068 {
00069 string mess = "WCS error in htmID ";
00070 mess += StringOps::NumToString(htmColno) + " ";
00071 mess += StringOps::NumToString(rowNo) + " : ";
00072 mess += "value replaced with dbl_max";
00073 log.addError(mess);
00074 data.assign(htmColno, rowNo, 0.0);
00075 } else {
00076 data.assign(htmColno, rowNo, static_cast<double>(
00077 mHtmPtr->idByPoint(ra * mRAFact, dec * mDecFact)));
00078 }
00079 }
00080 }
00081
00082
00083 void doit2(TableData<DataType>& rawData, TableData<DataType>& data, int row1, int row2) { }
00084
00085 private:
00086 int htmColno;
00087 int raColno;
00088 int decColno;
00089 double mDecFact;
00090 double mRAFact;
00091 SpatialIndex* mHtmPtr;
00092 };
00093
00094 #endif
00095
00096
00097
00098
00099
00100
00101