示例#1
0
void BezierCurveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)
{
	painter->setRenderHint(QPainter::Antialiasing, true);
	QPen pen;
	pen.setColor(Qt::red);
	pen.setWidth(2);
	pen.setStyle(Qt::DashDotLine);
	painter->setPen(pen);
	
	//drawPath;
	QPainterPath aPath(m_startPos);
	aPath.quadTo(m_midStartPos, m_midPos);
	painter->drawPath(aPath);

	QPainterPath bPath(m_midPos);
	bPath.quadTo(m_midEndPos, m_endPos);
	painter->drawPath(bPath);

	QPen penshaper;
	penshaper.setStyle(Qt::SolidLine);
	penshaper.setColor(Qt::darkRed);
	painter->setPen(penshaper);
	
	//#define the rect size;
	QSize rect_size(60, 60);
	QRect rect_shape1(m_startPos - QPoint(rect_size.height() / 2, rect_size.width() / 2), rect_size);
	QRect rect_shape2(m_endPos - QPoint(rect_size.height() / 2, rect_size.width() / 2), rect_size);
	
	QBrush brush(Qt::darkGray, Qt::CrossPattern);
	painter->fillRect(rect_shape1, brush);
	painter->fillRect(rect_shape2, brush);
	painter->drawRoundedRect(rect_shape1, 10, 10);
	painter->drawRoundedRect(rect_shape2, 10, 10);
	
	QPen dotpen;
	dotpen.setWidth(8);
	dotpen.setColor(Qt::red);
	
	brush.setStyle(Qt::SolidPattern);
	painter->setPen(dotpen);
	painter->drawPoint(m_startPos);
	painter->drawPoint(m_endPos);
}
示例#2
0
    /*
     * optimally partition an input sequence with random ks
     */
    optimal_partition(const std::vector<element_t>& seq,
                      cost_t fixedCost = 64) {

        FILE* stat = fopen("./share/oploops", "a");

        ASSERT(seq.size() != 0);

        //所有元素均使用32bit表示
        std::vector<element_t>::const_iterator begin = seq.begin();
        cost_t single_blcok_cost = seq.size() * 32;
        std::vector<cost_t> min_cost(seq.size() + 1, single_blcok_cost);
        min_cost[0] = 0;

        // create the required window: one for each power of approx_factor
        std::vector<cost_window> windows;
        cost_t cost_lower_bound = fixedCost;
        cost_t cost_bound = cost_lower_bound;
        while (/*eps1 == 0 ||*/cost_bound < cost_lower_bound / eps1) {
            //FIXME 由于begin作为每个窗口的滑动指针,如果是引用传递,那么操作一个begin++
            // 会不会导致所有的begin都向前移动?
            windows.emplace_back(begin, cost_bound);
            if (cost_bound >= single_blcok_cost)
                break;
            cost_bound = cost_bound * (1 + eps2);
        }
        // step 2: calculate optimal path
        std::vector<posIndex_t> path(seq.size() + 1, 0);
        std::vector<element_t> bPath(seq.size() + 1, 0);
        //XXX 1 in 3
        int ind = 0;

        bool firsttime;
        uint32_t firsttimeB = 0;
        for (posIndex_t i = 0; i < seq.size(); i++) {

            posIndex_t last_end = i + 1;
            element_t maxB = firsttimeB;
            firsttime = true;

            for (auto& window : windows) {
                assert(window.start == i);
                while (window.end < last_end) {
                    window.advance_end();
                }
                cost_t window_cost;

                //从当前window的begin到endIndex之间计算maximum bitwidth
                if (UNLIKELY(maxB == 0)) {
                    for (posIndex_t i = 0; i < window.size(); i++)
                        maxB = maxB > *(window.start_it + i) ?
                               maxB : *(window.start_it + i);
                }

                while (true) {
                    //XXX 2 in 3
                    ind++;
                    maxB = maxB > window.end_p ? maxB : window.end_p;
                    window_cost = window.size() * maxB;
                    if (min_cost[i] + window_cost < min_cost[window.end]) {
                        min_cost[window.end] = min_cost[i] + window_cost;
                        path[window.end] = i;
                        bPath[window.end] = maxB;
                    }
                    last_end = window.end;
                    if (window.end == seq.size())
                        break;
                    if (window_cost >= window.cost_upper_bound)
                        break;
                    window.advance_end();
                }
                if (firsttime) {
                    firsttime = false;
                    if (maxB == window.start_p)
                        firsttimeB = 0;
                    else
                        firsttimeB = maxB;
                }
                window.advance_start();
            }
        }
        /* for (int i = 0; i < bPath.size(); i++)
         std::cout <<i<<":"<< bPath[i] << std::endl;*/
        //XXX 3 in 3
        //		std::cout << "times of loop: " << ind << std::endl;
        fwrite(&ind, 4, 1, stat);
        fflush(stat);
        fclose(stat);

        posIndex_t curr_pos = seq.size();
        posIndex_t last_pos = curr_pos;

        while (curr_pos != 0) {
            partition.emplace_back(curr_pos);
            Bs.emplace_back(bPath[curr_pos]);

            last_pos = curr_pos;
            curr_pos = path[curr_pos];
            Ks.emplace_back(last_pos - curr_pos);

        }
        partition.emplace_back(0);
        std::reverse(partition.begin(), partition.end());
        std::reverse(Bs.begin(), Bs.end());
        std::reverse(Ks.begin(), Ks.end());
        cost_opt = min_cost[seq.size()];
    }
示例#3
0
    /*
     * Optimally partition an input sequence with limited options for k
     * seq represents the input integer sequence
     * lens represents the array containning the options
     */
    optimal_partition(const std::vector<element_t>& seq, const element_t *lens,
                      const uint32_t size, cost_t fixedCost = 64) {
        ASSERT(seq.size() != 0);

        //所有元素均使用32bit表示
        std::vector<element_t>::const_iterator begin = seq.begin();
        cost_t single_blcok_cost = seq.size() * 32;
        std::vector<cost_t> min_cost(seq.size() + 1, single_blcok_cost);
        min_cost[0] = 0;

        // create the required window: one for each power of approx_factor
        std::vector<cost_window> windows;
        cost_t cost_lower_bound = fixedCost;
        cost_t cost_bound = cost_lower_bound;
        while (/*eps1 == 0 ||*/cost_bound < cost_lower_bound / eps1) {
            //FIXME 由于begin作为每个窗口的滑动指针,如果是引用传递,那么操作一个begin++
            // 会不会导致所有的begin都向前移动?
            windows.emplace_back(begin, cost_bound);
            if (cost_bound >= single_blcok_cost)
                break;
            cost_bound = cost_bound * (1 + eps2);
        }
        // step 2: calculate optimal path
        std::vector<posIndex_t> path(seq.size() + 1, 0);
        std::vector<element_t> bPath(seq.size() + 1, 0);

        for (posIndex_t i = 0; i < seq.size(); i++) {
            posIndex_t last_end = i + 1;

            // for each window search for minimum cost path
            for (auto& window : windows) {
                assert(window.start == i);
                while (window.end < last_end) {
                    window.advance_end();
                }
                if (window.size() <= lens[size - 1]) {
                    cost_t window_cost;

                    //从当前window的begin到endIndex之间计算maximum bitwidth
                    element_t maxB = 0;
                    for (posIndex_t g = 0; g < window.size(); g++)
                        maxB = maxB > *(window.start_it + g) ?
                               maxB : *(window.start_it + g);
                    int l = 0;
                    while (l < size) {
                        if (window.size() != lens[l])
                            if (window.end != seq.size()) {
                                last_end = window.end;
                                window.advance_end();
                                maxB = maxB > window.end_p ?
                                       maxB : window.end_p;
                                continue;
                            } else
                                break;
                        else
                            l++;
                        window_cost = window.size() * maxB;
                        if (min_cost[i] + window_cost < min_cost[window.end]) {
                            min_cost[window.end] = min_cost[i] + window_cost;
                            path[window.end] = i;
                            bPath[window.end] = maxB;
                        }
                        if (window_cost >= window.cost_upper_bound)
                            break;
                    }
                }
                window.advance_start();
            }
        }
        //		for (int i = 0; i < bPath.size(); i++)
        //			std::cout <<i<<":"<< bPath[i] << std::endl;

        posIndex_t curr_pos = seq.size();
        posIndex_t last_pos = curr_pos;

        while (curr_pos != 0) {
            partition.emplace_back(curr_pos);
            Bs.emplace_back(bPath[curr_pos]);

            last_pos = curr_pos;
            curr_pos = path[curr_pos];
            Ks.emplace_back(last_pos - curr_pos);

        }
        partition.emplace_back(0);
        std::reverse(partition.begin(), partition.end());
        std::reverse(Bs.begin(), Bs.end());
        std::reverse(Ks.begin(), Ks.end());
        cost_opt = min_cost[seq.size()];
    }