예제 #1
0
/*
QPair<int, int> ClassItem::ganttIndex() const
{
	int class_ix = startSlotItem()->classItemIndex(this);
	int slot_ix = ganttItem()->startSlotItemIndex(startSlotItem());
	return QPair<int, int>(slot_ix, class_ix);
}
*/
void ClassItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	QColor c_runner = color();
	QColor c_free = c_runner;
	c_free.setAlpha(64);
	auto r = rect();
	QRectF r1 = r;
	r1.setWidth(minToPx(1));
	r1.setHeight(r.height() / 8);
	painter->save();
	painter->fillRect(r, c_free);
	auto dt = data();
	int interval = dt.startIntervalMin();
	for (int i = 0; i < runsAndVacantCount(); ++i) {
		r1.moveLeft(minToPx(i * interval));
		//QColor c = (i == 0)? c_first: c_runner;
		painter->fillRect(r1, c_runner);
		painter->drawRect(r1);
	}
	if(isSelected()) {
		painter->save();
		qreal w = r.height() / 15;
		QPen p;
		p.setColor(QColor(Qt::blue).lighter());
		p.setWidthF(w);
		painter->setPen(p);
		w /= 2;
		QRectF r2 = r.adjusted(w, w, -w, -w);
		painter->drawRect(r2);
		painter->restore();
	}
	if(clashingClasses().count()) {
		painter->save();
		qreal w = r.height() / 15;
		QPen p;
		p.setColor(Qt::red);
		p.setWidthF(w);
		painter->setPen(p);
		w /= 2;
		QRectF r2 = r.adjusted(w, w, -w, -w);
		painter->drawRect(r2);
		painter->restore();
	}
	if(m_dropInsertsBefore.isValid()) {
		QColor c_insert = c_runner;
		//c_insert.setAlpha(128);
		QRectF r2 = r;
		r2.setWidth(minToPx(2));
		if(!m_dropInsertsBefore.toBool()) {
			r2.moveLeft(r.width() - r2.width());
		}
		painter->fillRect(r2, c_insert);
		QPen p;
		p.setColor(color());
		painter->setPen(p);
		painter->drawRect(r2);
	}
	painter->restore();
	Super::paint(painter, option, widget);
}
예제 #2
0
RcppExport SEXP adjust(SEXP calSexp, SEXP bdcSEXP, SEXP dateSexp){

    try {
        boost::shared_ptr<QuantLib::Calendar> pcal( getCalendar(Rcpp::as<std::string>(calSexp)) );
        QuantLib::BusinessDayConvention bdc = getBusinessDayConvention( Rcpp::as<double>(bdcSEXP) );
        Rcpp::DateVector dates  = Rcpp::DateVector(dateSexp);
        int n = dates.size();
        std::vector<QuantLib::Date> adjusted(n);

        for (int i=0; i<n; i++) {
            QuantLib::Date day( dateFromR(dates[i]) );
            adjusted[i] = pcal->adjust(day, bdc);
            dates[i] =  Rcpp::Date(adjusted[i].month(), 
                                   adjusted[i].dayOfMonth(), 
                                   adjusted[i].year());
        }

        return Rcpp::wrap(dates);

    } catch(std::exception &ex) { 
        forward_exception_to_r(ex); 
    } catch(...) { 
        ::Rf_error("c++ exception (unknown reason)"); 
    }

    return R_NilValue;
}
예제 #3
0
QString CoreDbUrl::album() const
{
    // obey trailing slash in the path - albums have a trailing slash
    // get result without trailing slash
    QUrl url = adjusted(QUrl::RemoveFilename);

    return ( url.adjusted(QUrl::StripTrailingSlash).path() );
}
예제 #4
0
// [[Rcpp::export]]
std::vector<QuantLib::Date> adjust(std::string calendar, std::vector<QuantLib::Date> dates, int bdc=0) {
    boost::shared_ptr<QuantLib::Calendar> pcal(getCalendar(calendar));
    QuantLib::BusinessDayConvention bdcval = getBusinessDayConvention(bdc);
    int n = dates.size();
    std::vector<QuantLib::Date> adjusted(n);
    for (int i=0; i<n; i++) {
        adjusted[i] = pcal->adjust(dates[i], bdcval);
    }
    return adjusted;
}
예제 #5
0
void MinimapWindow::draw(gcn::Graphics *graphics)
{
    Graphics *g = static_cast<Graphics*>(graphics);

    g->drawImageRect(adjusted(mMinimap->getDimension(),
                            -5, -10 - mRegionLabel->getHeight(),
                            8, 8),
                     mWindowSkin->getBorder());

    drawChildren(graphics);
}
QMessageFilter QMessageFilter::byReceptionTimeStamp(const QDateTime &value, QMessageDataComparator::RelationComparator cmp)
{
    QMessageFilter result;
    result.d_ptr->_key = QMailMessageKey::receptionTimeStamp(adjusted(value), convert(cmp));
    return result;
}
QMessageFilter QMessageFilter::byTimeStamp(const QDateTime &value, QMessageDataComparator::EqualityComparator cmp)
{
    QMessageFilter result;
    result.d_ptr->_key = QMailMessageKey::timeStamp(adjusted(value), convert(cmp));
    return result;
}
예제 #8
0
qint64 QPulseAudioInput::read(char *data, qint64 len)
{
    m_bytesAvailable = checkBytesReady();

    setError(QAudio::NoError);
    setState(QAudio::ActiveState);

    int readBytes = 0;

    if (!m_pullMode && !m_tempBuffer.isEmpty()) {
        readBytes = qMin(static_cast<int>(len), m_tempBuffer.size());
        memcpy(data, m_tempBuffer.constData(), readBytes);
        m_totalTimeValue += readBytes;

        if (readBytes < m_tempBuffer.size()) {
            m_tempBuffer.remove(0, readBytes);
            return readBytes;
        }

        m_tempBuffer.clear();
    }

    while (pa_stream_readable_size(m_stream) > 0) {
        size_t readLength = 0;

#ifdef DEBUG_PULSE
        qDebug() << "QPulseAudioInput::read -- " << pa_stream_readable_size(m_stream) << " bytes available from pulse audio";
#endif

        QPulseAudioEngine *pulseEngine = QPulseAudioEngine::instance();
        pulseEngine->lock();

        const void *audioBuffer;

        // Second and third parameters (audioBuffer and length) to pa_stream_peek are output parameters,
        // the audioBuffer pointer is set to point to the actual pulse audio data,
        // and the length is set to the length of this data.
        if (pa_stream_peek(m_stream, &audioBuffer, &readLength) < 0) {
            qWarning() << QString("pa_stream_peek() failed: %1").arg(pa_strerror(pa_context_errno(pa_stream_get_context(m_stream))));
            pulseEngine->unlock();
            return 0;
        }

        qint64 actualLength = 0;
        if (m_pullMode) {
            QByteArray adjusted(readLength, Qt::Uninitialized);
            applyVolume(audioBuffer, adjusted.data(), readLength);
            actualLength = m_audioSource->write(adjusted);

            if (actualLength < qint64(readLength)) {
                pulseEngine->unlock();

                setError(QAudio::UnderrunError);
                setState(QAudio::IdleState);

                return actualLength;
            }
        } else {
            actualLength = qMin(static_cast<int>(len - readBytes), static_cast<int>(readLength));
            applyVolume(audioBuffer, data + readBytes, actualLength);
        }

#ifdef DEBUG_PULSE
        qDebug() << "QPulseAudioInput::read -- wrote " << actualLength << " to client";
#endif

        if (actualLength < qint64(readLength)) {
#ifdef DEBUG_PULSE
            qDebug() << "QPulseAudioInput::read -- appending " << readLength - actualLength << " bytes of data to temp buffer";
#endif
            int diff = readLength - actualLength;
            int oldSize = m_tempBuffer.size();
            m_tempBuffer.resize(m_tempBuffer.size() + diff);
            applyVolume(static_cast<const char *>(audioBuffer) + actualLength, m_tempBuffer.data() + oldSize, diff);
            QMetaObject::invokeMethod(this, "userFeed", Qt::QueuedConnection);
        }

        m_totalTimeValue += actualLength;
        readBytes += actualLength;

        pa_stream_drop(m_stream);
        pulseEngine->unlock();

        if (!m_pullMode && readBytes >= len)
            break;

        if (m_intervalTime && (m_timeStamp.elapsed() + m_elapsedTimeOffset) > m_intervalTime) {
            emit notify();
            m_elapsedTimeOffset = m_timeStamp.elapsed() + m_elapsedTimeOffset - m_intervalTime;
            m_timeStamp.restart();
        }
    }

#ifdef DEBUG_PULSE
    qDebug() << "QPulseAudioInput::read -- returning after reading " << readBytes << " bytes";
#endif

    return readBytes;
}
예제 #9
0
void SpatialAverageSpotter::maximizeAlignment(vector<vector<tuple<int,Point2f> > > &features)
{
    int stayCount=0;
    int iters=0;
    vector<bool> adjusted(features.size(),false);
    while (stayCount<STAY_THRESH*features.size() && iters<MAX_REF_ITER*features.size())//20
    {
        iters++;
        int imageNum= rand()%features.size();
        int imageNumOld=imageNum;
        while(1)
        {
            if (!adjusted[imageNum])
            {
                adjusted[imageNum]=true;
                break;
            }
            imageNum = (imageNum+1)%features.size();
            if ((imageNum) == imageNumOld)
            {
                adjusted.assign(features.size(),false);
                adjusted[imageNum]=true;
//                stayCount /= 2;
                stayCount=0;
                break;
            }
        }
        
        
        double shiftStep = 2*(1.0-iters/(0.0+MAX_REF_ITER*features.size()));//3* DD 2* TT
        if (shiftStep<1) shiftStep=1.0; //1.0 DD
        double scaleStep = .03*(1.0-iters/(0.0+MAX_REF_ITER*features.size()));//.01 DD
        double scaleStep2 = .06*(1.0-iters/(0.0+MAX_REF_ITER*features.size()));// .015 DD
        if (scaleStep<1) scaleStep=.003; //DD remove
        if (scaleStep2<1) scaleStep2=.006; //DD remove
        //examine gradient at each f point (discluding self)
        //if gradients agrre, make scale step
        guassColorOut(features[imageNum]);
        
        double bestScore=0;
        ExemplarTransform bestMove=STAY;
        
        double leftScore=0;
        double rightScore=0;
        double upScore=0;
        double downScore=0;
        double smallerScore=0;
        double biggerScore=0;
        double shortenScore=0;
        double hightenScore=0;
        double slimScore=0;
        double fattenScore=0;
//        double leftSmallerScore=0;
//        double rightSmallerScore=0;
//        double upSmallerScore=0;
//        double downSmallerScore=0;
//        double leftBiggerScore=0;
//        double rightBiggerScore=0;
//        double upBiggerScore=0;
//        double downBiggerScore=0;
        
              
        for (tuple<int,Point2f> f : features[imageNum])
        {
            bestScore += getUsingOffset(featureAverages[get<0>(f)],get<1>(f).x,get<1>(f).y);
            leftScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x-shiftStep, get<1>(f).y);
            rightScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x+shiftStep, get<1>(f).y);
            upScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x, get<1>(f).y-shiftStep);
            downScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x, get<1>(f).y+shiftStep);
            smallerScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x*(1-scaleStep), get<1>(f).y*(1-scaleStep));
            biggerScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x*(1+scaleStep), get<1>(f).y*(1+scaleStep));
            shortenScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x,get<1>(f).y*(1-scaleStep2));
            hightenScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x, get<1>(f).y*(1+scaleStep2));
            slimScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x*(1-scaleStep2), get<1>(f).y);
            fattenScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x*(1+scaleStep2), get<1>(f).y);
//            leftSmallerScore += getUsingOffset(featureAverages[get<0>(f)], (get<1>(f).x-shiftStep)*(1-scaleStep), get<1>(f).y*(1-scaleStep));
//            rightSmallerScore += getUsingOffset(featureAverages[get<0>(f)], (get<1>(f).x+shiftStep)*(1-scaleStep), get<1>(f).y*(1-scaleStep));
//            upSmallerScore += getUsingOffset(featureAverages[get<0>(f)], (get<1>(f).x)*(1-scaleStep), (get<1>(f).y-shiftStep)*(1-scaleStep));
//            downSmallerScore += getUsingOffset(featureAverages[get<0>(f)], (get<1>(f).x)*(1-scaleStep), (get<1>(f).y+shiftStep)*(1-scaleStep));
//            leftBiggerScore += getUsingOffset(featureAverages[get<0>(f)], (get<1>(f).x-shiftStep)*(1+scaleStep), get<1>(f).y*(1+scaleStep));
//            rightBiggerScore += getUsingOffset(featureAverages[get<0>(f)], (get<1>(f).x+shiftStep)*(1+scaleStep), get<1>(f).y*(1+scaleStep));
//            upBiggerScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x*(1+scaleStep), (get<1>(f).y-shiftStep)*(1+scaleStep));
//            downBiggerScore += getUsingOffset(featureAverages[get<0>(f)], get<1>(f).x*(1+scaleStep), (get<1>(f).y+shiftStep)*(1+scaleStep));
        }
        
        double test=bestScore;
        
        if (leftScore > bestScore)
        {
            bestScore=leftScore; bestMove = LEFT;
        }
        if (rightScore > bestScore)
        {
            bestScore=rightScore; bestMove = RIGHT;
        }
        if (upScore > bestScore)
        {
            bestScore=upScore; bestMove = UP;
        }
        if (downScore > bestScore)
        {
            bestScore=downScore; bestMove = DOWN;
        }
        if (smallerScore > bestScore)
        {
            bestScore=smallerScore; bestMove = SHRINK;
        }
        if (biggerScore > bestScore)
        {
            bestScore=biggerScore; bestMove = GROW;
        }
        if (shortenScore > bestScore)
        {
            bestScore=shortenScore; bestMove = SHORTEN;
        }
        if (hightenScore > bestScore)
        {
            bestScore=hightenScore; bestMove = HIGHTEN;
        }
        if (slimScore > bestScore)
        {
            bestScore=slimScore; bestMove = SLIM;
        }
        if (fattenScore > bestScore)
        {
            bestScore=fattenScore; bestMove = FATTEN;
        }
//        if (leftSmallerScore > bestScore)
//        {
//            bestScore=leftSmallerScore; bestMove = LEFT_SHRINK;
//        }
//        if (rightSmallerScore > bestScore)
//        {
//            bestScore=rightSmallerScore; bestMove = RIGHT_SHRINK;
//        }
//        if (upSmallerScore > bestScore)
//        {
//            bestScore=upSmallerScore; bestMove = UP_SHRINK;
//        }
//        if (downSmallerScore > bestScore)
//        {
//            bestScore=downSmallerScore; bestMove = DOWN_SHRINK;
//        }
//        if (leftBiggerScore > bestScore)
//        {
//            bestScore=leftBiggerScore; bestMove = LEFT_GROW;
//        }
//        if (rightBiggerScore > bestScore)
//        {
//            bestScore=rightBiggerScore; bestMove = RIGHT_GROW;
//        }
//        if (upBiggerScore > bestScore)
//        {
//            bestScore=upBiggerScore; bestMove = UP_GROW;
//        }
//        if (downBiggerScore > bestScore)
//        {
//            bestScore=downBiggerScore; bestMove = DOWN_GROW;
//        }
        
        auto fI = features[imageNum].begin();
        for(; fI!=features[imageNum].end(); fI++)
        {
            switch(bestMove)
            {
            case LEFT:
                get<1>(*fI) = Point2f(get<1>(*fI).x-shiftStep, get<1>(*fI).y);
                
                break;
            case RIGHT:
                get<1>(*fI) = Point2f(get<1>(*fI).x+shiftStep, get<1>(*fI).y);
                
                break;
            case UP:
                get<1>(*fI) = Point2f(get<1>(*fI).x, get<1>(*fI).y-shiftStep);
//                cout << "upscore:"<<upScore<<" stayscore:"<<test<<endl;
                break;
            case DOWN:
                get<1>(*fI) = Point2f(get<1>(*fI).x, get<1>(*fI).y+shiftStep);
                
                break;
            case SHRINK:
                get<1>(*fI) = Point2f(get<1>(*fI).x*(1-scaleStep), get<1>(*fI).y*(1-scaleStep));
                
                break;
            case GROW:
                get<1>(*fI) = Point2f(get<1>(*fI).x*(1+scaleStep), get<1>(*fI).y*(1+scaleStep));
                
                break;
            case SHORTEN:
                get<1>(*fI) = Point2f(get<1>(*fI).x, get<1>(*fI).y*(1-scaleStep2));
                
                break;
            case HIGHTEN:
                get<1>(*fI) = Point2f(get<1>(*fI).x, get<1>(*fI).y*(1+scaleStep2));
                
                break;
            case SLIM:
                get<1>(*fI) = Point2f(get<1>(*fI).x*(1-scaleStep2), get<1>(*fI).y);
                
                break;
            case FATTEN:
                get<1>(*fI) = Point2f(get<1>(*fI).x*(1+scaleStep2), get<1>(*fI).y);
                
                break;
//            case LEFT_SHRINK:
//                get<1>(*fI) = Point2f((get<1>(*fI).x-shiftStep)*(1-scaleStep), get<1>(*fI).y*(1-scaleStep));
                
//                break;
//            case RIGHT_SHRINK:
//                get<1>(*fI) = Point2f((get<1>(*fI).x+shiftStep)*(1-scaleStep), get<1>(*fI).y*(1-scaleStep));
                
//                break;
//            case UP_SHRINK:
//                get<1>(*fI) = Point2f((get<1>(*fI).x)*(1-scaleStep), (get<1>(*fI).y-shiftStep)*(1-scaleStep));
                
//                break;
//            case DOWN_SHRINK:
//                get<1>(*fI) = Point2f((get<1>(*fI).x)*(1-scaleStep), (get<1>(*fI).y+shiftStep)*(1-scaleStep));
                
//                break;
//            case LEFT_GROW:
//                get<1>(*fI) = Point2f((get<1>(*fI).x-shiftStep)*(1+scaleStep), get<1>(*fI).y*(1+scaleStep));
                
//                break;
//            case RIGHT_GROW:
//                get<1>(*fI) = Point2f((get<1>(*fI).x+shiftStep)*(1+scaleStep), get<1>(*fI).y*(1+scaleStep));
                
//                break;
//            case UP_GROW:
//                get<1>(*fI) = Point2f(get<1>(*fI).x*(1+scaleStep), (get<1>(*fI).y-shiftStep)*(1+scaleStep));
                
//                break;
//            case DOWN_GROW:
//                get<1>(*fI) = Point2f(get<1>(*fI).x*(1+scaleStep), (get<1>(*fI).y+shiftStep)*(1+scaleStep));
                
//                break;
            case STAY:
                break;
            }
        }
        if(bestMove == STAY)
        {
            stayCount+=1;
        }
        else if (stayCount>0)
        {
           stayCount--;
        }
        
        
        //////
        switch(bestMove)
        {
        case LEFT:
            translateImg(adjustedTrainingImages[imageNum],-shiftStep,0);
            
            break;
        case RIGHT:
            translateImg(adjustedTrainingImages[imageNum],shiftStep,0);
            
            break;
        case UP:
            translateImg(adjustedTrainingImages[imageNum],0,-shiftStep);
            break;
        case DOWN:
            translateImg(adjustedTrainingImages[imageNum],0,shiftStep);
            
            break;
        case SHRINK:
            strechImg(adjustedTrainingImages[imageNum],(1-scaleStep),(1-scaleStep));
            break;
        case GROW:
            strechImg(adjustedTrainingImages[imageNum],(1+scaleStep),(1+scaleStep));
            
            break;
        case SHORTEN:
            strechImg(adjustedTrainingImages[imageNum],1,(1-scaleStep2));
            
            break;
        case HIGHTEN:
            strechImg(adjustedTrainingImages[imageNum],1,(1+scaleStep2));
            
            break;
        case SLIM:
            strechImg(adjustedTrainingImages[imageNum],(1-scaleStep2),1);
            
            break;
        case FATTEN:
            strechImg(adjustedTrainingImages[imageNum],(1+scaleStep2),1);
            
            break;
        case STAY:
            break;
        }
        
        //////
        
        guassColorIn(features[imageNum]);
        
        cout <<"image "<<imageNum<<" move "<<bestMove<<", staycount="<<stayCount<<endl;
        showAverages();
        
        Mat averageImage(adjustedTrainingImages[0].rows,adjustedTrainingImages[0].cols,CV_8U);
        for (int x=0; x< averageImage.cols; x++)
            for (int y=0; y<averageImage.rows; y++)
            {
                int sum=0;
                for (Mat image : adjustedTrainingImages)
                {
                    sum += image.at<unsigned char>(y,x);
                }
                sum /= adjustedTrainingImages.size();
                assert(sum>=0 && sum<256);
                averageImage.at<unsigned char>(y,x) = sum;
            }
        
        imshow("average",averageImage);
        waitKey(5);
        
//        imshow("adjusted",adjustedTrainingImages[imageNum]);
//        waitKey();
    }
    
    Mat averageImage(adjustedTrainingImages[0].rows,adjustedTrainingImages[0].cols,CV_8U);
    for (int x=0; x< averageImage.cols; x++)
        for (int y=0; y<averageImage.rows; y++)
        {
            int sum=0;
            for (Mat image : adjustedTrainingImages)
            {
                sum += image.at<unsigned char>(y,x);
            }
            sum /= adjustedTrainingImages.size();
            assert(sum>=0 && sum<256);
            averageImage.at<unsigned char>(y,x) = sum;
        }
    int i=0;
    for (Mat image : adjustedTrainingImages)
    {
        imshow("adjusted",image);
        cout << "image "<<i++<<endl;
        waitKey(5);
    }
    
    imshow("average",averageImage);
    waitKey(5);
}