Exemplo n.º 1
0
MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent)
{
    m_log = new Log(this);
    m_pragmaDialog = new PragmaDialog(this);
    m_memoryDialog = new MemoryDialog(this);

    m_dbWidget = new DatabaseWidget();
    connect(m_dbWidget, SIGNAL(logMsg(QString)), m_log, SLOT(addMsg(QString)));
    connect(m_dbWidget, SIGNAL(active(QSharedPointer<SQLite>)), m_pragmaDialog, SLOT(active(QSharedPointer<SQLite>)));
    connect(m_dbWidget, SIGNAL(inactive()), m_pragmaDialog, SLOT(inactive()));

    connect(m_dbWidget, SIGNAL(active(QSharedPointer<SQLite>)), m_memoryDialog, SLOT(active(QSharedPointer<SQLite>)));
    connect(m_dbWidget, SIGNAL(inactive()), m_memoryDialog, SLOT(inactive()));

    setCentralWidget(m_dbWidget);

    createActions();
    createMenus();
    createToolBars();

    statusBar();

    QSettings settings("Research In Motion", "sbuilder");
    restoreGeometry(settings.value("geometry").toByteArray());
    m_recentFiles = settings.value("recentFiles").toStringList();
    updateRecentFileActions();

    sqlite3_initialize();
}
Exemplo n.º 2
0
void ChatSession::slotReconnect() {
    delete mng;
    m_chatpage->users_box->clear();
    emit inactive();
    createTelnetManager();
    emit active();
}
Exemplo n.º 3
0
void make_progressbar(float value, video::IImage *image)
{
	if(image == NULL)
		return;
	
	core::dimension2d<u32> size = image->getDimension();

	u32 barheight = size.Height/16;
	u32 barpad_x = size.Width/16;
	u32 barpad_y = size.Height/16;
	u32 barwidth = size.Width - barpad_x*2;
	v2u32 barpos(barpad_x, size.Height - barheight - barpad_y);

	u32 barvalue_i = (u32)(((float)barwidth * value) + 0.5);

	video::SColor active(255,255,0,0);
	video::SColor inactive(255,0,0,0);
	for(u32 x0=0; x0<barwidth; x0++)
	{
		video::SColor *c;
		if(x0 < barvalue_i)
			c = &active;
		else
			c = &inactive;
		u32 x = x0 + barpos.X;
		for(u32 y=barpos.Y; y<barpos.Y+barheight; y++)
		{
			image->setPixel(x,y, *c);
		}
	}
}
Exemplo n.º 4
0
//Checks if this chain is currently providing angles so that external
//classes can check the status of this one
void ScriptedProvider::setActive(){
    if(isDone())
    {
        inactive();
    }
    else
        active();
}
Exemplo n.º 5
0
double stex::Reac::rate(void) const
{
    if (inactive()) return 0.0;

    // Prefetch some variables.
    ssolver::Compdef * cdef = pTet->compdef();
    uint nspecs = cdef->countSpecs();
    uint * lhs_vec = cdef->reac_lhs_bgn(cdef->reacG2L(pReacdef->gidx()));
    uint * cnt_vec = pTet->pools();

    // Compute combinatorial part.
    double h_mu = 1.0;
    for (uint pool = 0; pool < nspecs; ++pool)
    {
        uint lhs = lhs_vec[pool];
        if (lhs == 0) continue;
        uint cnt = cnt_vec[pool];
        if (lhs > cnt)
        {
            h_mu = 0.0;
            break;
        }
        switch (lhs)
        {
            case 4:
            {
                h_mu *= static_cast<double>(cnt - 3);
            }
            case 3:
            {
                h_mu *= static_cast<double>(cnt - 2);
            }
            case 2:
            {
                h_mu *= static_cast<double>(cnt - 1);
            }
            case 1:
            {
                h_mu *= static_cast<double>(cnt);
                break;
            }
            default:
            {
                assert(0);
                return 0.0;
            }
        }
    }

    // Multiply with scaled reaction constant.
    return h_mu * pCcst;
}
Exemplo n.º 6
0
 inline void set_force_inactive()
 {
    utils::byte active(THREAD_ACTIVE);
    utils::byte inactive(THREAD_INACTIVE);
    while(true) {
       utils::byte old_val(tstate);
       if(old_val == inactive)
          return;
       else if(old_val == active) {
          if(cmpxchg(&tstate, old_val, inactive) == old_val) {
             term_barrier->is_inactive();
             return;
          }
       } else if(old_val == (active | THREAD_NEW_WORK)) {
          if(cmpxchg(&tstate, old_val, inactive) == old_val)
             return;
       }
       cpu_relax();
    }
 }
Exemplo n.º 7
0
 inline bool set_inactive_if_no_work()
 {
    utils::byte active(THREAD_ACTIVE);
    utils::byte inactive(THREAD_INACTIVE);
    // return true if there is new work
    while(true) {
       utils::byte old_val(tstate);
       if(old_val == inactive)
          return false;
       else if(old_val == THREAD_ACTIVE) {
          if(cmpxchg(&tstate, old_val, inactive) == old_val) {
             term_barrier->is_inactive();
             return false;
          }
       } else if(old_val == (THREAD_ACTIVE | THREAD_NEW_WORK)) {
          if(cmpxchg(&tstate, old_val, active) == old_val)
             return true;
       }
       cpu_relax();
    }
 }
  // add training images for a person
  void addTrainingImagesCb(const sensor_msgs::ImageConstPtr& msg) {
    // cout << "addTrainingImagesCb" << endl;

    if (_as.isPreemptRequested() || !ros::ok()) {
      // std::cout << "preempt req or not ok" << std::endl;
      ROS_INFO("%s: Preempted", _action_name.c_str());
      // set the action state to preempted
      _as.setPreempted();
      // success = false;
      // break;
      // cout << "shutting down _image_sub" << endl;
      _image_sub.shutdown();
      return;
    }

    if (!_as.isActive()) {
      // std::cout << "not active" << std::endl;
      // cout << "shutting down _image_sub" << endl;
      _image_sub.shutdown();
      return;
    }

    cv_bridge::CvImagePtr cv_ptr;
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("%s: cv_bridge exception: %s", _action_name.c_str(), e.what());
      return;
    }

    if (_window_rows == 0) {
      _window_rows = cv_ptr->image.rows;
      _window_cols = cv_ptr->image.cols;
    }

    std::vector<cv::Rect> faces;
    // _fd.detectFaces(cv_ptr->image, faces, true);

    std::vector<cv::Mat> faceImgs = _fd.getFaceImgs(cv_ptr->image, faces, true);
    
    if (faceImgs.size() > 0)
      _fc->capture(faceImgs[0]);

    // call images capturing function
    _result.names.push_back(_goal_argument);
    // _result.confidence.push_back(2.0);
    
    int no_images_to_click;
    _ph.getParam("no_training_images", no_images_to_click);
    
    if (_fc->getNoImgsClicked() >= no_images_to_click) {
      // Mat inactive = cv::Mat::zeros(cv_ptr->image.rows, cv_ptr->image.cols, CV_32F);
      Mat inactive(_window_rows, _window_cols, CV_8UC3, CV_RGB(20,20,20));
      appendStatusBar(inactive, "INACTIVE", "Images added. Please train.");
      cv::imshow(_windowName, inactive);  
      // cv::displayOverlay(_windowName, "Images added", 3000); 
      _as.setSucceeded(_result);
    } else {
      // update GUI window
      // check GUI parameter
      appendStatusBar(cv_ptr->image, "ADDING IMAGES.", "Images added");
      cv::imshow(_windowName, cv_ptr->image);  
    }

    cv::waitKey(3);
  }
  // run face recognition on the recieved image 
  void recognizeCb(const sensor_msgs::ImageConstPtr& msg) {
    // cout << "entering.. recognizeCb" << endl;

    _ph.getParam("algorithm", _recognitionAlgo);

    if (_as.isPreemptRequested() || !ros::ok()) {
      // std::cout << "preempt req or not ok" << std::endl;
      ROS_INFO("%s: Preempted", _action_name.c_str());
      // set the action state to preempted
      _as.setPreempted();
      // success = false;
      // break;
      // cout << "shutting down _image_sub" << endl;
      _image_sub.shutdown();
      Mat inactive(_window_rows, _window_cols, CV_8UC3, CV_RGB(20,20,20));
      appendStatusBar(inactive, "INACTIVE", "");
      cv::imshow(_windowName, inactive);
      cv::waitKey(3);
      return;
    }

    if (!_as.isActive()) {
      // std::cout << "not active" << std::endl;
      // cout << "shutting down _image_sub" << endl;
      _image_sub.shutdown();
      Mat inactive(_window_rows, _window_cols, CV_8UC3, CV_RGB(20,20,20));
      appendStatusBar(inactive, "INACTIVE", "");
      cv::imshow(_windowName, inactive);
      cv::waitKey(3);
      return;
    }

    cv_bridge::CvImagePtr cv_ptr;
    try
    {
      cv_ptr = cv_bridge::toCvCopy(msg, sensor_msgs::image_encodings::BGR8);
    }
    catch (cv_bridge::Exception& e)
    {
      ROS_ERROR("%s: cv_bridge exception: %s", _action_name.c_str(), e.what());
      return;
    }

    if (_window_rows == 0) {
      _window_rows = cv_ptr->image.rows;
      _window_cols = cv_ptr->image.cols;
    }

    // clear previous feedback
    _feedback.names.clear();
    _feedback.confidence.clear();
    // _result.names.clear();
    // _result.confidence.clear();

    std::vector<cv::Rect> faces;
    std::vector<cv::Mat> faceImgs = _fd.getFaceImgs(cv_ptr->image, faces, true);
    std::map<string, std::pair<string, double> > results;
    
    for( size_t i = 0; i < faceImgs.size(); i++ ) {
      cv::resize(faceImgs[i], faceImgs[i], cv::Size(100.0, 100.0));
      cv::cvtColor( faceImgs[i], faceImgs[i], CV_BGR2GRAY );
      cv::equalizeHist( faceImgs[i], faceImgs[i] );

      // perform recognition
      results = _fr->recognize(faceImgs[i],
                                ("eigenfaces" == _recognitionAlgo),
                                ("fisherfaces" == _recognitionAlgo),
                                ("lbph" == _recognitionAlgo)
                              );

      ROS_INFO("Face %lu:", i);
      if ("eigenfaces" == _recognitionAlgo)
        ROS_INFO("\tEigenfaces: %s %f", results["eigenfaces"].first.c_str(), results["eigenfaces"].second);
      if ("fisherfaces" == _recognitionAlgo)
        ROS_INFO("\tFisherfaces: %s %f", results["fisherfaces"].first.c_str(), results["fisherfaces"].second);
      if ("lbph" == _recognitionAlgo)
        ROS_INFO("\tLBPH: %s %f", results["lbph"].first.c_str(), results["lbph"].second);
    }


    // update GUI window
    // TODO check gui parameter
    appendStatusBar(cv_ptr->image, "RECOGNITION", "");
    cv::imshow(_windowName, cv_ptr->image);
    cv::waitKey(3);

    // if faces were detected
    if (faceImgs.size() > 0) {
      // recognize only once
      if (_goal_id == 0) {
        // std::cout << "goal_id 0. setting succeeded." << std::endl;
        // cout << _recognitionAlgo << endl;
        _result.names.push_back(results[_recognitionAlgo].first);
        _result.confidence.push_back(results[_recognitionAlgo].second);
        _as.setSucceeded(_result);
      }
      // recognize continuously
      else {
        _feedback.names.push_back(results[_recognitionAlgo].first);
        _feedback.confidence.push_back(results[_recognitionAlgo].second);
        _as.publishFeedback(_feedback);
      }
    }
  } 
Exemplo n.º 10
0
u1_t handler_dev_arm_read(u2_t addr)
{
	u1_t data, key;

	assert (addr == RREG_LDACSR || addr == RREG_A16_SWITCHES || addr == RREG_I1 || addr == RREG_ST ||
		addr == RREG_N0ST || addr == RREG_N0H || addr == RREG_N0L || addr == RREG_N1N2H || addr == RREG_N1N2L ||
		addr == RREG_N3H || addr == RREG_N3L);

	// derive N0ST values from PRU collection of overflow data
	if (use_pru && hold_off && (addr == RREG_N0ST)) {
		bool sent=FALSE, done_before=FALSE;

		if (pru->count == PRU_DONE) done_before=TRUE;

		if ((pru->n3_ovfl - n3_ovfl_sent) > 0) {
			n3_ovfl_sent++;
			sent=TRUE;
			data = inactive(N0ST_EOM) | active(N0ST_N3_OVFL) | inactive(N0ST_N0_OVFL);
		} else
		if ((pru->n0_ovfl - n0_ovfl_sent) > 0) {
			n0_ovfl_sent++;
			sent=TRUE;
			data = inactive(N0ST_EOM) | inactive(N0ST_N3_OVFL) | active(N0ST_N0_OVFL);
		} else {
			ovfl_none++;
			data = inactive(N0ST_EOM) | inactive(N0ST_N3_OVFL) | inactive(N0ST_N0_OVFL);
		}

		// PRU saw EOM: be careful about the race condition when looking at the counters
		if (!sent && done_before && (pru->count == PRU_DONE)) {
			freq_record(0, REG_STR, 0, 0, 0, "H");
			hold_off = FALSE;
		}
		
		return data;
	}

	data = bus_read(addr);

#ifdef FREQ_DEBUG
	if (use_pru && !hold_off) {
		if (addr == RREG_N0ST && (isActive(N0ST_EOM, data) || isActive(N0ST_N3_OVFL, data) || isActive(N0ST_N0_OVFL, data))) {
			freq_record(0, REG_READ, addr, data, 0, 0);
		}
	}
#endif

//#define SELF_TEST
#ifdef SELF_TEST
	if (addr == RREG_A16_SWITCHES) data = 0;	// force self-test mode (simulate all switches down)
#endif

	// The interrupt from pressing the LCL/RMT key causes the RREG_I1 to be read.
	// Check for a regular key being simultaneously pressed and then when the
	// register is accessed outside of the interrupt routine use the "sim key"
	// mechanism to process the "shifted" key press.
	if (addr == RREG_I1) {
		if (!(data & I1_IRQ)) {
			if (!(data & I1_LRTL)) {
				key = bus_read(RREG_KEY_SCAN);
				if ((key & KEY_IDLE2) != KEY_IDLE2) {
					shifted_key = key;
				}
			}
		} else {
			if (shifted_key) {
				sim_key = shifted_key;
				shifted_key = 0;
				sim_key_intr = 1;
			}
		}
	}

	DUMP_AREG(N0ST, addr, data);
	DUMP_AREG(N1N2H, addr, data);
	DUMP_AREG(N1N2L, addr, data);
	DUMP_AREG(N0H, addr, data);
	DUMP_AREG(N0L, addr, data);
	
#ifdef DEBUG
	if (trace_regs) {
		if (addr == RREG_N0ST) {
			if (isActive(N0ST_EOM, data)) printf("EOM");
			if (isActive(N0ST_N3_OVFL, data)) printf("3");
			if (isActive(N0ST_N0_OVFL, data)) printf("0");
		}
		if (addr == RREG_I1 && data == 0x7f) printf("_"); else
		if (addr == RREG_ST) { ; } else
		if (addr == RREG_A16_SWITCHES) ; else
		printf("%s=%02x ", arm_rreg[addr - ADDR_ARM(0)], data);
	}
#endif

	return data;
}
Exemplo n.º 11
0
double swmd::SReac::rate(void) const
{
    if (inactive()) return 0.0;

    // First we compute the combinatorial part.
    //   1/ for the surface part of the stoichiometry
    //   2/ for the inner or outer volume part of the stoichiometry, pool
    //      depending on whether the sreac is inner() or outer()
    // Then we multiply with mesoscopic constant.

    ssolver::Patchdef * pdef = pPatch->def();
    uint lidx = pdef->sreacG2L(defsr()->gidx());

    double h_mu = 1.0;

    uint * lhs_s_vec = pdef->sreac_lhs_S_bgn(lidx);
    double * cnt_s_vec = pdef->pools();
    uint nspecs_s = pdef->countSpecs();
    for (uint s = 0; s < nspecs_s; ++s)
    {
        uint lhs = lhs_s_vec[s];
        if (lhs == 0) continue;
        uint cnt = static_cast<uint>(cnt_s_vec[s]);
        if (lhs > cnt)
        {
            return 0.0;
        }
        switch (lhs)
        {
            case 4:
            {
                h_mu *= static_cast<double>(cnt - 3);
            }
            case 3:
            {
                h_mu *= static_cast<double>(cnt - 2);
            }
            case 2:
            {
                h_mu *= static_cast<double>(cnt - 1);
            }
            case 1:
            {
                h_mu *= static_cast<double>(cnt);
                break;
            }
            default:
            {
                assert(0);
                return 0.0;
            }
        }
    }

    if (defsr()->inside())
    {
        uint * lhs_i_vec = pdef->sreac_lhs_I_bgn(lidx);
        double * cnt_i_vec = pPatch->iComp()->def()->pools();
        uint nspecs_i = pdef->countSpecs_I();
        for (uint s = 0; s < nspecs_i; ++s)
        {
            uint lhs = lhs_i_vec[s];
            if (lhs == 0) continue;
            uint cnt = static_cast<double>(cnt_i_vec[s]);
            if (lhs > cnt)
            {
                return 0.0;
            }
            switch (lhs)
            {
                case 4:
                {
                    h_mu *= static_cast<double>(cnt - 3);
                }
                case 3:
                {
                    h_mu *= static_cast<double>(cnt - 2);
                }
                case 2:
                {
                    h_mu *= static_cast<double>(cnt - 1);
                }
                case 1:
                {
                    h_mu *= static_cast<double>(cnt);
                    break;
                }
                default:
                {
                    assert(0);
                    return 0.0;
                }
            }
        }
    }
    else if (defsr()->outside())
    {
        uint * lhs_o_vec = pdef->sreac_lhs_O_bgn(lidx);
        double * cnt_o_vec = pPatch->oComp()->def()->pools();
        uint nspecs_o = pdef->countSpecs_O();
        for (uint s = 0; s < nspecs_o; ++s)
        {
            uint lhs = lhs_o_vec[s];
            if (lhs == 0) continue;
            uint cnt = static_cast<double>(cnt_o_vec[s]);
            if (lhs > cnt)
            {
                return 0.0;
            }
            switch (lhs)
            {
                case 4:
                {
                    h_mu *= static_cast<double>(cnt - 3);
                }
                case 3:
                {
                    h_mu *= static_cast<double>(cnt - 2);
                }
                case 2:
                {
                    h_mu *= static_cast<double>(cnt - 1);
                }
                case 1:
                {
                    h_mu *= static_cast<double>(cnt);
                    break;
                }
                default:
                {
                    assert(0);
                    return 0.0;
                }
            }
        }
    }

    return h_mu * pCcst;
}
Exemplo n.º 12
0
void HistogramOnGrid::calculate( const unsigned& current, MultiValue& myvals, std::vector<double>& buffer, std::vector<unsigned>& der_list ) const {
    if( addOneKernelAtATime ) {
        plumed_dbg_assert( myvals.getNumberOfValues()==2 && !wasforced );
        std::vector<double> der( dimension );
        for(unsigned i=0; i<dimension; ++i) der[i]=myvals.getDerivative( 1, i );
        accumulate( getAction()->getPositionInCurrentTaskList(current), myvals.get(0), myvals.get(1), der, buffer );
    } else {
        plumed_dbg_assert( myvals.getNumberOfValues()==dimension+2 );
        std::vector<double> point( dimension );
        double weight=myvals.get(0)*myvals.get( 1+dimension );
        for(unsigned i=0; i<dimension; ++i) point[i]=myvals.get( 1+i );

        // Get the kernel
        unsigned num_neigh;
        std::vector<unsigned> neighbors;
        std::vector<double> der( dimension );
        KernelFunctions* kernel=getKernelAndNeighbors( point, num_neigh, neighbors );
        // If no kernel normalize the vector so von misses distribution is calculated correctly
        if( !kernel ) {
            double norm=0;
            for(unsigned j=0; j<dimension; ++j) norm += point[j]*point[j];
            norm=sqrt( norm );
            for(unsigned j=0; j<dimension; ++j) point[j] = point[j] / norm;
        }

        if( !kernel && getType()=="flat" ) {
            plumed_dbg_assert( num_neigh==1 );
            accumulate( neighbors[0], weight, 1.0, der, buffer );
        } else {
            double totwforce=0.0;
            std::vector<double> intforce( 2*dimension, 0.0 );
            std::vector<Value*> vv( getVectorOfValues() );

            double newval;
            std::vector<double> xx( dimension );
            for(unsigned i=0; i<num_neigh; ++i) {
                unsigned ineigh=neighbors[i];
                if( inactive( ineigh ) ) continue ;
                getGridPointCoordinates( ineigh, xx );
                for(unsigned j=0; j<dimension; ++j) vv[j]->set(xx[j]);
                if( kernel ) {
                    newval = kernel->evaluate( vv, der, true );
                } else {
                    // Evalulate dot product
                    double dot=0;
                    for(unsigned j=0; j<dimension; ++j) {
                        dot+=xx[j]*point[j];
                        der[j]=xx[j];
                    }
                    // Von misses distribution for concentration parameter
                    newval = von_misses_norm*exp( von_misses_concentration*dot );
                    // And final derivatives
                    for(unsigned j=0; j<dimension; ++j) der[j] *= von_misses_concentration*newval;
                }
                accumulate( ineigh, weight, newval, der, buffer );
                if( wasForced() ) {
                    accumulateForce( ineigh, weight, der, intforce );
                    totwforce += myvals.get( 1+dimension )*newval*forces[ineigh];
                }
            }
            if( wasForced() ) {
                unsigned nder = getAction()->getNumberOfDerivatives();
                unsigned gridbuf = getNumberOfBufferPoints()*getNumberOfQuantities();
                for(unsigned j=0; j<dimension; ++j) {
                    for(unsigned k=0; k<myvals.getNumberActive(); ++k) {
                        // Minus sign here as we are taking derivative with respect to position of center of kernel NOT derivative wrt to
                        // grid point
                        unsigned kder=myvals.getActiveIndex(k);
                        buffer[ bufstart + gridbuf + kder ] -= intforce[j]*myvals.getDerivative( j+1, kder );
                    }
                }
                // Accumulate the sum of all the weights
                buffer[ bufstart + gridbuf + nder ] += myvals.get(0);
                // Add the derivatives of the weights into the force -- this is separate loop as weights of all parts are considered together
                for(unsigned k=0; k<myvals.getNumberActive(); ++k) {
                    unsigned kder=myvals.getActiveIndex(k);
                    buffer[ bufstart + gridbuf + kder ] += totwforce*myvals.getDerivative( 0, kder );
                    buffer[ bufstart + gridbuf + nder + 1 + kder ] += myvals.getDerivative( 0, kder );
                }
            }
            delete kernel;
            for(unsigned i=0; i<dimension; ++i) delete vv[i];
        }
    }
}
Exemplo n.º 13
0
void HeadProvider::setActive()
{
    isDone() ? inactive() : active();
}