uint64 htmInterface::lookupIDCmd(char *str) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; cmdCode code = getCode(); if(code == NAME) { VarStr token = t_->next(); if(token.empty()) throw SpatialInterfaceError("htmInterface:lookupIDCmd: expected Name"); return index_->idByName(token.data()); } getDepth(); if(! parseVec(code, v) ) throw SpatialInterfaceError("htmInterface:lookupIDCmd: Expect vector in Command. ", cmd_.data()); if( code == J2000 ) return lookupID(v[0], v[1]); return lookupID(v[0], v[1], v[2]); }
// parse the string, returning the number of floats // that have been in the string. bool htmInterface::parseVec( cmdCode code, float64 *v) { VarStr token; size_t i = 0, len; if(code == J2000) len = 2; else if(code == CARTESIAN) len = 3; else throw SpatialInterfaceError("htmInterface:parseVec: Expected code J2000 or CARTESIAN."); // parse the next len positions while( i < len ) { token = t_->next(); if(token.empty())break; if(!isFloat(token)) throw SpatialInterfaceError("htmInterface:parse: Expected float at this position of Command. ",cmd_.data()); if(i == len) throw SpatialInterfaceError("htmInterface:parse: Expect less floats in Command. ", cmd_.data()); v[i++] = atof(token.data()); } if(i < len) return false; return true; }
const char * htmInterface::lookupNameCmd(char *str) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; cmdCode code = getCode(); if(code == ID) { uint64 id = getInt64(); index_->nameById(id, name_); } else { getDepth(); if(! parseVec(code, v) ) throw SpatialInterfaceError("htmInterface:lookupNameCmd: Expect vector in Command. ", cmd_.data()); if( code == J2000 ) index_->nameByPoint(v[0], v[1], name_); else { SpatialVector tv(v[0], v[1], v[2]); index_->nameByPoint(tv, name_); } } return name_; }
const ValVec<htmRange> & htmInterface::domainCmd( char *str ) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); cmdCode code = getCode(); if(code != HTMDOMAIN) throw SpatialInterfaceError("htmInterface:domainCmd: missing keyword HTMDOMAIN"); getDepth(); int32 nx,nc; nx = getInteger(); SpatialDomain dom; for(int32 i = 0 ; i < nx; i++ ) { SpatialConvex convex; nc = getInteger(); for(int32 j = 0; j < nc; j++ ) { float64 x = getFloat(); float64 y = getFloat(); float64 z = getFloat(); float64 d = getFloat(); SpatialConstraint c(SpatialVector(x,y,z),d); convex.add(c); } dom.add(convex); } return domain(dom); }
const ValVec<htmRange> & htmInterface::doHull() { if(polyCorners_.length() < 3) throw SpatialInterfaceError("htmInterface:convexHull: empty hull: points on one line"); SpatialVector v; SpatialConvex x; SpatialDomain d; // The constraint we have for each side is a 0-constraint (great circle) // passing through the 2 corners. Since we are in counterclockwise order, // the vector product of the two successive corners just gives the correct // constraint. size_t i, len = polyCorners_.length(); for(i = 0; i < len; i++) { v = polyCorners_[i].c_ ^ polyCorners_[ i == len-1 ? 0 : i + 1].c_; #ifdef DIAG cerr << v << " " << i << "," << i+1 << "\n"; #endif v.normalize(); SpatialConstraint c(v,0); x.add(c); } d.add(x); d.intersect(index_, idList_); range_.cut(range_.length()); makeRange(); return range_; }
cmdCode #else htmInterface::cmdCode #endif htmInterface::getCode() { cmdCode code; // parse incoming string. expect to have an integer indicating the // depth at first position. VarStr token = t_->next(); if ( token == "J2000" ) code = J2000; else if( token == "CARTESIAN" ) code = CARTESIAN; else if( token == "NAME" ) code = NAME; else if( token == "ID" ) code = ID; else if( token == "DOMAIN" ) code = HTMDOMAIN; else throw SpatialInterfaceError("htmInterface:getCode: Unexpected command",token); return code; }
const ValueVector & htmInterface::doHull() { if(polyCorners_.size() < 3) throw SpatialInterfaceError("htmInterface:convexHull: empty hull: points on one line"); SpatialVector v; RangeConvex cvx; SpatialDomain dom; // The constraint we have for each side is a 0-constraint (great circle) // passing through the 2 corners. Since we are in counterclockwise order, // the vector product of the two successive corners just gives the correct // constraint. size_t i, len = polyCorners_.size(); for(i = 0; i < len; i++) { v = polyCorners_[i].c_ ^ polyCorners_[ i == len-1 ? 0 : i + 1].c_; #ifdef DIAG cerr << "doHull:: " << v << " " << i << "," << i+1 << endl; #endif v.normalize(); SpatialConstraint c(v,0); cvx.add(c); // [ed:RangeConvex::add] } dom.add(cvx); //%%%%%%%%%%%%%%%%%%%%%%%%%%% // dom.convexes_[0].boundingCircle_.write(cout); // dom.write(cout); //%%%%%%%%%%%%%%%%%%%%%%%%%%% return domain(dom); }
void htmInterface::getDepth() { size_t depth = getInteger(); if(depth > HTMMAXDEPTH) throw SpatialInterfaceError("htmInterface:getDepth: Depth too large: Max is HTMMAXDEPTH"); changeDepth(depth); }
// get an integer out of the command string float64 htmInterface::getFloat() { if(!t_) throw SpatialFailure("htmInterface:getFloat: No command to parse"); // parse incoming string. expect to have an integer. const VarStr &token = t_->next(); if(!isFloat(token)) throw SpatialInterfaceError("htmInterface:getFloat: Expected float at first position of Command. ",cmd_.data()); return atof(token.data()); }
// get an integer out of the command string int32 htmInterface::getInteger() { if(t_ == NULL) throw SpatialFailure("htmInterface:getInteger: No command to parse"); // parse incoming string. expect to have an integer. const StdStr &token = t_->next(); if(!isInteger(token)) throw SpatialInterfaceError("htmInterface:getInteger: Expected integer at first position of Command. ",cmd_.data()); return atoi(token.data()); }
// get an integer out of the command string uint64 htmInterface::getInt64() { if(!t_) throw SpatialFailure("htmInterface:getInt64: No command to parse"); // parse incoming string. expect to have an integer. const VarStr &token = t_->next(); if(!isInteger(token)) throw SpatialInterfaceError("htmInterface:getInt64: Expected integer at first position of Command. ",cmd_.data()); #ifdef SpatialWinNT return _atoi64(token.data()); #elif defined(SpatialDigitalUnix) return atol(token.data()); #else return atoll(token.data()); #endif }
const ValVec<htmRange> & htmInterface::circleRegionCmd( char *str ) { cmd_ = str; if(t_)delete t_; t_ = new VarStrToken(cmd_); float64 v[3]; float64 d; cmdCode code = getCode(); getDepth(); if(! parseVec(code, v) ) throw SpatialInterfaceError("htmInterface:circleRegionCmd: Expect vector in Command. ", cmd_.data()); d = getFloat(); if( code == J2000 ) return circleRegion(v[0], v[1], d); return circleRegion(v[0], v[1], v[2], d); }