示例#1
0
    // 
    // Hoist quantifier from rule (universal) or query (existential)
    // 
    unsigned rule_manager::hoist_quantifier(bool is_forall, expr_ref& fml, svector<symbol>* names) {   

        unsigned index = var_counter().get_next_var(fml);
        while (is_quantifier(fml) && (is_forall == to_quantifier(fml)->is_forall())) {
            quantifier* q = to_quantifier(fml);
            index += q->get_num_decls();
            if (names) {
                names->append(q->get_num_decls(), q->get_decl_names());
            }
            fml = q->get_expr();
        }
        if (!has_quantifiers(fml)) {
            return index;
        }
        app_ref_vector vars(m);
        quantifier_hoister qh(m);
        qh.pull_quantifier(is_forall, fml, vars);
        if (vars.empty()) {
            return index;
        }
        // replace vars by de-bruijn indices
        expr_substitution sub(m);
        for (unsigned i = 0; i < vars.size(); ++i) {
            app* v = vars[i].get();
            if (names) {
                names->push_back(v->get_decl()->get_name());
            }                
            sub.insert(v, m.mk_var(index++,m.get_sort(v)));
        }
        scoped_ptr<expr_replacer> rep = mk_default_expr_replacer(m); 
        rep->set_substitution(&sub);
        (*rep)(fml);
        return index;
    }
void testApp :: draw()
{
	
	//ofQuaternion constructor: angle, ofVec3f axis
	
	ofQuaternion qr (roll, Znormal);	// quat roll.
	ofQuaternion qp (pitch, Xnormal);	// quat pitch.
	ofQuaternion qh (heading, Ynormal);	// quat heading or yaw.
	ofQuaternion qt;					// quat total.

	
	
	// The order IS IMPORTANT. Apply roll first, then pitch, then heading.
	qt = qr * qp * qh;
	
	
		
	ofPushMatrix();
		ofTranslate( ofGetWidth() * 0.5, ofGetHeight() * 0.5, 0 );
		
		/******************************/
		
		/*
		//GYMBAL LOCK!!
		EulerRot = qt.getEuler();
		ofRotateX(EulerRot.x);
		ofRotateY(EulerRot.y);
		ofRotateZ(EulerRot.z);
		 */
		 

		ofVec3f qaxis; float qangle;
		qt.getRotate(qangle, qaxis);
	
		ofRotate(qangle, qaxis.x, qaxis.y, qaxis.z);
 
	
		ofScale( 200, 200, 200 );
		/******************************/

		
		drawCube();
		
	ofPopMatrix();
	
	
	
	
	ofSetColor( 0x000000 );
	ofDrawBitmapString
	(
	 "fps :: " + ofToString(ofGetFrameRate(), 2) + "\n\n"
	 "incDir  :: press i to change :: " + ofToString( incDir ) + "\n\n"
	 "roll    :: press 1 to change :: " + ofToString( roll ) + "\n\n"
	 "pitch   :: press 2 to change :: " + ofToString( pitch ) + "\n\n"
	 "heading :: press 3 to change :: " + ofToString( heading ) + "\n\n",
	 20,
	 20
	 );
}
void CSharedFile::Serialize(QSqlDatabase* pDatabase)
{
    // get directory id if needed
    if(m_nDirectoryID == 0)
    {
        QSqlQuery query(*pDatabase);

        query.prepare("SELECT id FROM dirs WHERE path LIKE '?'");
        query.bindValue(0, m_sDirectory);
        if(!query.exec())
        {
            systemLog.postLog(LogSeverity::Debug, QString("SQL Query failed: %1").arg(query.lastError().text()));
            //qDebug() << "Cannot fetch directory id: " << query.lastError().text();
            return;
        }

        if(query.size() != 1)
        {
            systemLog.postLog(LogSeverity::Debug, QString("Bad record number: %1").arg(query.size()));
            //qDebug() << "Bad record number: " << query.size();
            return;
        }

        query.next();

        m_nDirectoryID = query.value(0).toLongLong();
    }

    // now insert or update file record
    if(m_nFileID == 0)
    {
        // insert

        pDatabase->transaction();

        QSqlQuery query(*pDatabase);
        query.prepare("INSERT INTO files (dir_id, name, size, last_modified, shared) VALUES (?,?,?,?,?)");
        query.bindValue(0, m_nDirectoryID);
        query.bindValue(1, m_sFileName);
        query.bindValue(2, m_nSize);
        query.bindValue(3, m_nLastModified);
        query.bindValue(4, m_bShared);
        if(!query.exec())
        {
            systemLog.postLog(LogSeverity::Debug, QString("Cannot insert new record: %1").arg(query.lastError().text()));
            //qDebug() << "Cannot insert new record: " << query.lastError().text();
            return;
        }

        qint64 nFileID = query.lastInsertId().toLongLong();
        qDebug() << "New file ID: " << nFileID;

        QSqlQuery q2(*pDatabase);
        q2.exec(QString("DELETE FROM hashes WHERE file_id = %1").arg(nFileID));

        QMap<QString, QVariant> mapValues;
        mapValues.insert("file_id", QVariant(nFileID));

        foreach(CHash * oHash, m_lHashes)
        {
            if(pDatabase->record("hashes").contains(oHash->GetFamilyName()))
            {
                mapValues.insert(oHash->GetFamilyName(), oHash->RawValue());
            }
        }

        if(mapValues.count() > 1)
        {
            QSqlQuery qh(*pDatabase);

            QString sFields, sValues;

            for(QMap<QString, QVariant>::iterator itValues = mapValues.begin(); itValues != mapValues.end(); itValues++)
            {
                sFields.append(itValues.key()).append(",");
            }
            sFields.truncate(sFields.size() - 1);

            for(int i = 0; i < mapValues.count(); i++)
            {
                sValues += "?,";
            }
            sValues.truncate(sValues.size() - 1);

            qh.prepare(QString("INSERT INTO hashes (" + sFields + ") VALUES (" + sValues + ")"));

            int nCurrPos = 0;
            for(QMap<QString, QVariant>::iterator itValues = mapValues.begin(); itValues != mapValues.end(); itValues++)
            {
                qh.bindValue(nCurrPos, QVariant(itValues.value()));
                nCurrPos++;
            }

            if(!qh.exec())
            {
                systemLog.postLog(LogSeverity::Debug, QString("Cannot insert hashes: %1 %2").arg(qh.lastError().text()).arg(qh.executedQuery()));
                //qDebug() << "Cannot insert hashes: " << qh.lastError().text() << qh.executedQuery();
            }
        }

        QStringList lKeywords;
        CQueryHashTable::MakeKeywords(m_sFileName, lKeywords);

        QSqlQuery qkw(*pDatabase);
        qkw.prepare("INSERT OR IGNORE INTO keywords (keyword) VALUES (?)");
        foreach(QString sKey, lKeywords)
        {
            qkw.bindValue(0, QVariant(sKey));
            qkw.exec();
        }
示例#4
0
bool FPSManipulator::calcMovement()
{
    // return if less then two events have been added.
    if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;

    float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
    float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();

   // float distance = sqrtf(dx*dx + dy*dy);
   
    
    // return if there is no movement.
   /* if (distance==0.0f)
    {
        return false;
    }*/

  //  unsigned int buttonMask = _ga_t1->getButtonMask();
  //  if (buttonMask==osgGA::GUIEventAdapter::LEFT_MOUSE_BUTTON)//pk for test, to be removed after
    {

        // rotate camera.

        float px0 = _ga_t0->getXnormalized();
        float py0 = _ga_t0->getYnormalized();
											
        float px1 = _ga_t1->getXnormalized();
        float py1 = _ga_t1->getYnormalized();
        
		//test the border to reset the position
		if(px0>0.9 || px0<-0.9 || py0>0.9 || py0<-0.9)
		{
			_gw->requestWarpPointer((_ga_t0->getXmax() - _ga_t0->getXmin())/2,(_ga_t0->getYmax() - _ga_t0->getYmin())/2);
			flushMouseEventStack(); //rest to avoid big move
		}

		double speed = _mouseScale; //default 50.0


		//horizontal rotation
		osg::Quat qh(osg::DegreesToRadians((px1-px0)*speed), osg::Z_AXIS);


		//vertical rotation
			//rotation axis //here axis is more complex

		osg::Vec3d geteye, getcenter, getup;
		getInverseMatrix().getLookAt(geteye, getcenter, getup);

		osg::Vec3d front = getcenter - geteye;
		front.normalize();
		osg::Vec3d axis = front ^ osg::Z_AXIS;
		axis.normalize();

		//test and stop the vertical rotation
		double scalar = front * osg::Z_AXIS;
		osg::Quat qv;

		qv = osg::Quat(osg::DegreesToRadians((py0-py1)*speed+computeAnimation()), axis);

		if((scalar > 0.9 && py0 > py1 ) || (scalar < -0.9 && py0 < py1 )) //going up or down near vertical axis
		{
			qv = osg::Quat(-osg::DegreesToRadians((py0-py1)*speed), axis); //inverse rotation
		}
		
		//then apply the rotations
        _rotation = _rotation*qv*qh;


        return true;

    }
  /*  else if (buttonMask==GUIEventAdapter::MIDDLE_MOUSE_BUTTON ||
        buttonMask==(GUIEventAdapter::LEFT_MOUSE_BUTTON|GUIEventAdapter::RIGHT_MOUSE_BUTTON))
    {

        // pan model.

        float scale = -0.3f*_distance;

        osg::Matrix rotation_matrix;
        rotation_matrix.makeRotate(_rotation);

        osg::Vec3 dv(dx*scale,dy*scale,0.0f);

        _center += dv*rotation_matrix;
        
        return true;

    }
    else if (buttonMask==GUIEventAdapter::RIGHT_MOUSE_BUTTON)
    {

        // zoom model.

        float fd = _distance;
        float scale = 1.0f+dy;
        if (fd*scale>_modelScale*_minimumZoomScale)
        {

            _distance *= scale;

        }
        else
        {

            // notify(DEBUG_INFO) << "Pushing forward"<<std::endl;
            // push the camera forward.
            float scale = -fd;

            osg::Matrix rotation_matrix(_rotation);

            osg::Vec3 dv = (osg::Vec3(0.0f,0.0f,-1.0f)*rotation_matrix)*(dy*scale);

            _center += dv;

        }

        return true;

    }*/

    return false;
}
示例#5
0
int main(int argc, char** argv) {
    // Initialize control plain using mpi
    graphlab::mpi_tools::init(argc, argv);
    graphlab::distributed_control dc;
    global_logger().set_log_level(LOG_FATAL);

    // Parse command line options -------------------------------------
    graphlab::command_line_options 
        clopts("Distributed Path Finding Algorithm.");
    std::string graph_dir;
    std::string format = "tsv";
    std::string exec_type = "synchronous";
    clopts.attach_option("graph", graph_dir,
            "The graph file.  If none is provided "
            "then a toy graph will be created");
    clopts.add_positional("graph");

    clopts.attach_option("engine", exec_type, 
            "The engine type synchronous or asynchronous");

    std::string saveprefix;
    clopts.attach_option("saveprefix", saveprefix,
            "If set, will save the resultant pagerank to a "
            "sequence of files with prefix saveprefix");
    
    size_t n_tree = 1;
    clopts.attach_option("num_tree", n_tree,
            "Number of trees.");
   
    size_t n_query = 0;
    clopts.attach_option("num_query", n_query,
            "Preset number of experiments.");
    
    bool stepy = false;
    clopts.attach_option("stepy", stepy,
            "Regular mode or stepy mode.");

    std::string input_file = "";
    clopts.attach_option("input_file", input_file,
            "Read from file or randomly generate (default).");

    if(!clopts.parse(argc, argv)) {
        dc.cout() << 
            "Error in parsing command line arguments." << std::endl;
        return EXIT_FAILURE;
    }

    // Build the graph ---------------------------------------------
    dc.cout() << "\n0 Loading graph..." << std::endl;
    graph_type graph(dc, clopts);
    dc.cout() << "\tLoading graph in format: "<< format << std::endl;
    graph.load_format(graph_dir, format);
    // must call finalize before querying the graph
    graph.finalize();
    dc.cout() << "\t#vertices:  " << graph.num_vertices() << 
        "\t#edges:     " << graph.num_edges() << std::endl;

    // start the handler here
#ifdef TIE_FULL
#ifdef TIE_HEUR
    size_t n_query_batch = 10000;
#else
    size_t n_query_batch = 1000;
#endif
#else
    //size_t n_query_batch = n_query * 2;
    size_t n_query_batch = 50000;
#endif
#ifdef BIDIRECTIONAL_SEARCH
    n_query_batch /= 2;
#endif
    query_handler qh(n_tree, stepy, n_query,
            &dc, &clopts, &graph, 
            input_file, exec_type, 
            saveprefix, graph_dir,
            n_query_batch);

#ifndef CALC_REAL
    qh.ds_query_batch();
#else
    qh.real_query_serial();
#endif

    // Tear-down communication layer and quit ----------------------
    graphlab::mpi_tools::finalize();
    return EXIT_SUCCESS;
} // End of main