Ejemplo n.º 1
0
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]);

}
Ejemplo n.º 2
0
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_;
}
Ejemplo n.º 3
0
const ValVec<htmRange> & 
htmInterface::convexHullCmd( char *str ) {

  cmd_ = str;
  if(t_)delete t_;
  t_ = new VarStrToken(cmd_);

  float64 v[3];

  cmdCode code = getCode();
  getDepth();

  polyCorners_.cut(polyCorners_.length());

  // the next positions give the coordinate
  while(  parseVec( code, v ) ) {
    if(code == J2000) {
      SpatialVector tv(v[0],v[1]);
      setPolyCorner(tv);
    } else {
      SpatialVector tv(v[0],v[1],v[2]);
      setPolyCorner(tv);
    }
  }

  return doHull();
}
Ejemplo n.º 4
0
const ValueVector & 
htmInterface::convexHullCmd( char *str ) {

  cmd_ = str;
  if(t_ != NULL) delete t_;
  t_ = new VarStrToken(cmd_);

  float64 v[3];

  cmdCode code = getCode();
  getDepth();
  polyCorners_.clear();

  while(  parseVec( code, v ) ) {
    if(code == J2000) {
      SpatialVector tv(v[0],v[1]);
      setPolyCorner(tv);
    } else {
      SpatialVector tv(v[0],v[1],v[2]);
      setPolyCorner(tv);
    }
  }

  return doHull();
}
Ejemplo n.º 5
0
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);
}
Ejemplo n.º 6
0
bool
BodyTracker::ReadBaseline()
{
	std::ifstream in(const_cast<const char *>(m_baselineFile.c_str()));

	// Parse the header
	std::string header;
	std::getline(in, header);
	std::istringstream buf(header);
	m_baselineFlags = 0;
	std::vector<int> flagVals;
	for (std::string tok ; std::getline(buf, tok, ' ') ; ) {
		if (tok  == "#") continue;
		else if (tok == "POSITION") flagVals.push_back(TRACK_POSITION);
		else if (tok == "ANGLE") flagVals.push_back(TRACK_ANGLE);
		else if (tok == "WORLD_CENTER") flagVals.push_back(TRACK_WORLD_CENTER);
		else if (tok == "LOCAL_CENTER") flagVals.push_back(TRACK_LOCAL_CENTER);
		else if (tok == "LINEAR_VELOCITY") flagVals.push_back(TRACK_LINEAR_VELOCITY);
		else if (tok == "ANGULAR_VELOCITY") flagVals.push_back(TRACK_ANGULAR_VELOCITY);
		else {
			m_errors.push_back("Illegal token '" + tok + "' in header");
			return false;
		}
	}

	// Create mask of all baseline flags and enforce that it matches generated samples.
	m_baselineFlags = 0;
	for (size_t i = 0 ; i < flagVals.size() ; i++ )
		m_baselineFlags |= flagVals[i];
	if (m_baselineFlags != m_flags) {
		m_errors.push_back("Error: baseline data does not match generated data");
		m_errors.push_back("\tBaseline:  " + TrackFlagsToString(m_baselineFlags));
		m_errors.push_back("\tGenerated: " + TrackFlagsToString(m_flags));
		return false;
	}

	// Iterate over all strings in file.
	std::string bodyName;
	SampleVec *samples = 0;
	for (std::string str ; std::getline(in, str) ; ) {
		if (str.length() > 0 && str[0] != '\t') {
			m_baselineSamples[str] = SampleVec();
			samples = &m_baselineSamples[str];
			continue;
		}
        if (!samples) {
            continue;
        }
		Sample sample;
		std::istringstream buf(str);
		int32 field = 0;
		for ( std::string tok ; std::getline(buf, tok, ',') ; ++field ) {
			if (field == 0){
				sample.timeStep = (float)atof(tok.c_str());
				continue;
			}
			const TrackFlags flagVal = static_cast<TrackFlags>(flagVals[field-1]);
			switch (flagVal) {
			case TRACK_POSITION:
				sample.position = parseVec(tok);
			case TRACK_ANGLE:
				sample.angle = (float)atof(tok.c_str());
			case TRACK_WORLD_CENTER:
				sample.worldCenter = parseVec(tok);
			case TRACK_LOCAL_CENTER:
				sample.localCenter = parseVec(tok);
			case TRACK_LINEAR_VELOCITY:
				sample.linearVelocity = parseVec(tok);
			case TRACK_ANGULAR_VELOCITY:
				sample.angularVelocity = (float)atof(tok.c_str());
			}
		}
		samples->push_back(sample);
	}
	m_baselineRead = true;
	return true;
}
Ejemplo n.º 7
0
ofxShape parseShape(ofxXmlSettings &xml) {
    
    ofxShape s;
    
    xml.pushTag("paths");
    
    string str = xml.getAttribute("Path", "data", "");
    
    size_t found = str.find('L');
    if (found!=string::npos) {
        linePath p;
        p.p0 = parseVec(str.substr(1,found)).front(); // eliminate M (for moveTo)
        //ln.p1 = parseVec(str.substr(found+1)).front();
        
        p.bClosed = str.at(str.length()-1) == 'z';
        
        
        
        if (p.bClosed) {
            str = str.substr(found+1,str.npos-1); // eliminate z for closed
        } else {
            str = str.substr(found+1);
        }
        vector<string> svec = ofSplitString(str, "L");
//        cout << "numSegments: " << svec.size() << ", closed: " << p.bClosed<< endl;
        
        for (vector<string>::iterator iter=svec.begin(); iter!=svec.end(); iter++) {
            
            p.segments.push_back(parseVec(*iter).front());  
//            cout << p.segments.back().x << "," << p.segments.back().y << "\t";
        }
//        cout << endl;
        
        
        s.line.push_back(p);
        
//        cout << "rectangle: " << rect.x << " " << rect.y << " " << rect.width << " " << rect.height << " " << endl;
        
    } else {
        found = str.find('C');
        if (found!=string::npos) {
            curvePath p;
            p.p0 = parseVec(str.substr(1,found)).front(); // eliminate M
            
            vector<string> svec = ofSplitString(str.substr(found+1), "C");
            //                        cout << "numCurves: " << svec.size() << endl;
            
            for (vector<string>::iterator iter=svec.begin(); iter!=svec.end(); iter++) {
                vector<ofVec2f> bezier = parseVec(*iter);
                
                //                            cout << bezier.size() << "\t";
                p.segments.push_back(bezier);
            }
            
            s.curve.push_back(p);
            
            
        }
    }
    
    xml.pushTag("Path");
    
    if (xml.tagExists("stroke")) {
        xml.pushTag("stroke");
        xml.pushTag("SolidStroke");
        xml.pushTag("fill");
        
        if (xml.tagExists("SolidColor")) {
            s.solidColorStroke.push_back(ofHexToInt(xml.getAttribute("SolidColor", "color", "").substr(1)));
        }
        xml.popTag();
        xml.popTag();
        xml.popTag();
    }
    
    if (xml.tagExists("fill")) {
        xml.pushTag("fill");
        
        if (xml.tagExists("SolidColor")) {
            s.solidColorFill.push_back(ofHexToInt(xml.getAttribute("SolidColor", "color", "").substr(1)));
        } 
        
        if (xml.tagExists("BitmapFill")) {
            ofxBitmapFill bf;
            bf.bitmapPath = xml.getAttribute("BitmapFill", "bitmapPath", "");
            xml.pushTag("BitmapFill");
            
            if (xml.tagExists("matrix")) {
                xml.pushTag("matrix");
                
                float a = xml.getAttribute("Matrix", "a", 1.0);
                float b = xml.getAttribute("Matrix", "b", 0.0);
                float c = xml.getAttribute("Matrix", "c", 0.0);
                float d = xml.getAttribute("Matrix", "d", 1.0);
                float tx = xml.getAttribute("Matrix", "tx", 0.0);
                float ty = xml.getAttribute("Matrix", "ty", 0.0);
                
                //bi.mat = ofMatrix4x4(a, c, 0, tx, b, d, 0, ty, 0, 0, 1, 0, 0, 0, 0, 1);
                //bi.mat = ofMatrix4x4(sqrt(a*a+b*b)/20, 0, 0, 0, 0,sqrt(c*c+d*d)/20, 0, 0, 0, 0, 1, 0, tx, ty, 0, 1);
                
                //                        bi.width = (float)doc.items[bi.path].frameRight/PIXEL_SCALE;
                //                        bi.height = (float)doc.items[bi.path].frameBottom/PIXEL_SCALE;
                //                        bi.href = doc.items[bi.path].href;
                
                
                //                        cout << bi.path << "\t" << bi.width << "x" << bi.height << endl;
                
                xml.popTag();
                
                bf.mat.scale(sqrt(a*a+b*b)/PIXEL_SCALE, sqrt(c*c+d*d)/PIXEL_SCALE, 1.0);
                bf.mat.rotate(atan2( b, a )*180/PI, 0, 0, 1.0);
                bf.mat.translate(ofVec2f(tx,ty));
            }
            
            
//            cout << bf.mat << endl;
            xml.popTag();
            
                        
            
            
            ofVec2f tl = s.line.front().segments[0];
            ofVec2f br = s.line.front().segments[2];
            
            bf.rect = ofRectangle(tl.x, tl.y, br.x-tl.x, br.y-tl.y); // roikr: what did I forget ? inside rect ?
            
            
            s.bitmapFill.push_back(bf);
        }
        
        xml.popTag();
    }
    
    xml.popTag(); 
    xml.popTag();
    
    return s;
}