コード例 #1
0
ファイル: nodeList_sV.cpp プロジェクト: Eric013/slowmoVideo
void NodeList_sV::setSpeed(qreal segmentTime, qreal speed)
{
    int left, right;
    findBySegment(segmentTime, left, right);
    if (left >= 0 && right >= 0) {
        Node_sV *leftN = &m_list[left];
        Node_sV *rightN = &m_list[right];
        qreal y = leftN->y() + speed*(rightN->x()-leftN->x());
        if (y > m_maxY || y < 0) {
            if (y > m_maxY) {
                qDebug() << speed << "x speed would shoot over maximum time. Correcting.";
                y = m_maxY;
            } else {
                qDebug() << speed << "x speed goes below 0. Correcting.";
                y = 0;
            }
            qreal xNew = leftN->x() + (y - leftN->y())/speed;
            rightN->setY(y);
            if (xNew - leftN->x() >= m_minDist) {
                add(Node_sV(xNew, y));
            } else {
                qDebug() << "New node would be too close, not adding it.";
            }
        } else {
            rightN->setY(y);
        }
    } else {
        qDebug() << "Outside segment.";
    }
    validate();
}
コード例 #2
0
void ShutterFunctionDialog::slotUpdateNode()
{
    qDebug() << "slotUpdateNode();";
    if (m_project->nodes()->size() >= 2) {
        Q_ASSERT(m_segment+1 < m_project->nodes()->size());
        QString id = ui->cbFunction->currentText();
        if (id == emptyFunction) {
            id = "";
        }
        Node_sV *node = &(*m_project->nodes())[m_segment];
        node->setShutterFunctionID(id);
        qDebug() << "Shutter function ID of node " << node << "set to " << id;
    }
}
コード例 #3
0
void MainWindow::slotNewProject()
{
    NewProjectDialog npd(this);
    if (npd.exec() == QDialog::Accepted) {
        try {
            Project_sV *project = npd.buildProject();

            // Save project
            XmlProjectRW_sV writer;
            
            //qDebug() << "Saving project as " << npd.filename;
            // check if directory exist ...
            QFileInfo projfile(npd.projectFilename());
            QDir dir(projfile.absoluteDir());
            if (!dir.exists()) {
                dir.mkpath(".");
            }
            
            try {
                writer.saveProject(project, npd.projectFilename());
                statusBar()->showMessage(QString(tr("Saved project as: %1")).arg(npd.projectFilename()));
                setWindowModified(false);
            } catch (Error_sV &err) {
                QMessageBox(QMessageBox::Warning, tr("Error writing project file"), err.message()).exec();
            }
            
            m_projectPath = npd.projectFilename();

            project->preferences()->viewport_secRes() = QPointF(400, 400)/project->frameSource()->framesCount()*project->frameSource()->fps()->fps();
            
            /* add a first (default) node */
            Node_sV snode;
            
            snode.setX(0.0);
            snode.setY(0.0);
            project->nodes()->add(snode);
            
            loadProject(project);

            m_wCanvas->showHelp(true);
			setWindowModified(true);

        } catch (FrameSourceError &err) {
            QMessageBox(QMessageBox::Warning, "Frame source error", err.message()).exec();
        }
    }
}
コード例 #4
0
ファイル: nodeList_sV.cpp プロジェクト: Eric013/slowmoVideo
void NodeList_sV::moveHandle(const NodeHandle_sV *handle, Node_sV relPos)
{
    Node_sV otherNode;
    Node_sV *currentNode = const_cast<Node_sV*>(handle->parentNode());

    int nodeIndex = indexOf(handle->parentNode());
    Q_ASSERT(nodeIndex >= 0);
    Q_ASSERT(nodeIndex < m_list.size());

    if (handle == &currentNode->leftNodeHandle()) {
        //  o------[]
        if (nodeIndex > 0) {
            // Ensure that it does not overlap with the left node's handle (injectivity)
            otherNode = m_list.at(nodeIndex-1);
            qDebug() << "Left node: " << otherNode;
            qDebug() << "Right node: " << currentNode;
            qDebug() << "Before overlapping check: " << relPos;
            relPos.setX(qMax(relPos.x(), -(currentNode->x() - otherNode.x() - otherNode.rightNodeHandle().x())));
            qDebug() << "After overlapping check: " << relPos;
            qDebug() << "Space left: " << currentNode->x() + relPos.x() - (otherNode.x() + otherNode.rightNodeHandle().x());
        }
        // Additionally the handle has to stay on the left of its node
        relPos.setX(qMin(relPos.x(), .0));

        currentNode->setLeftNodeHandle(relPos.x(), relPos.y());

    } else {
        // []-------o
        if (nodeIndex+1 < m_list.size()) {
            otherNode = m_list.at(nodeIndex+1);
            relPos.setX(qMin(relPos.x(), otherNode.x() - currentNode->x() + otherNode.leftNodeHandle().x()));
        }
        relPos.setX(qMax(relPos.x(), .0));

        currentNode->setRightNodeHandle(relPos.x(), relPos.y());
    }
    validate();
}
コード例 #5
0
ファイル: nodeList_sV.cpp プロジェクト: Eric013/slowmoVideo
void NodeList_sV::moveSelected(const Node_sV &time)
{
    qreal maxRMove = 100000;
    qreal maxLMove = -100000;
    qreal maxUMove = 100000;
    qreal maxDMove = -100000;
    const Node_sV *left = NULL;
    const Node_sV *right;
    for (int i = 0; i < m_list.size(); i++) {
        right = &m_list.at(i);

        /*
          Get the maximum allowed horizontal movement distance here such that there is no
          overlapping. For moving the selected nodes to the left, only unselected nodes
          which are directly followed by a selected node need to be taken into account.
                 O----O
                /      \               x
          -----x        \             /
                         x-----------O

         min(  ^1^,      ^-----2-----^    ) + minDist

         */
        if (left != NULL) {
            if (left->selected() && !right->selected()) {
                // Move-right distance
                maxRMove = qMin(maxRMove,
                                right->xUnmoved()+right->leftNodeHandle().x() -
                                (left->xUnmoved()+left->rightNodeHandle().x()) -
                                m_minDist);
            } else if (!left->selected() && right->selected()) {
                // Move-left distance
                maxLMove = qMax(maxLMove,
                                left->xUnmoved()+left->rightNodeHandle().x() -
                                (right->xUnmoved()+right->leftNodeHandle().x()) +
                                m_minDist);
            }
        }

        if (right->selected()) {
            maxDMove = qMax(maxDMove, -right->yUnmoved());
            maxUMove = qMin(maxUMove, m_maxY-right->yUnmoved());
        }

        left = right;
    }
    if (m_list.size() > 0 && m_list.at(0).selected()) {
        // Do not allow to move nodes to x < 0
        maxLMove = qMax(maxLMove, -m_list.at(0).xUnmoved());
    }
#ifdef DEBUG_NL
    qDebug() << "Max move: left " << maxLMove << ", right: " << maxRMove;
#endif
    Node_sV newTime(
                qMax(maxLMove, qMin(maxRMove, time.x())),
                qMax(maxDMove, qMin(maxUMove, time.y()))
                );
    for (int i = 0; i < m_list.size(); i++) {
        if (m_list.at(i).selected()) {
            m_list[i].move(newTime);
        }
    }
}
コード例 #6
0
ファイル: nodeList_sV.cpp プロジェクト: Eric013/slowmoVideo
bool NodeList_sV::add(Node_sV node)
{
    bool add = true;

#ifdef DEBUG_NL
    qDebug() << "Before adding: \n" << *this;
#endif

    node.setX(qMax(.0, node.x()));
    node.setY(qMax(.0, qMin(m_maxY, node.y())));

    int pos = find(node.x());
    if (pos >= 0 && m_list.size() > pos) {
        add = fabs(node.x()-m_list.at(pos).x()) > m_minDist;
#ifdef DEBUG_NL
        qDebug() << "Left distance is " << fabs(node.x()-m_list.at(pos).x());
#endif
        if (add && m_list.size() > pos+1) {
            add = fabs(node.x()-m_list.at(pos+1).x()) > m_minDist;
#ifdef DEBUG_NL
            qDebug() << "Right distance is " << fabs(node.x()-m_list.at(pos+1).x());
#endif
        }
    }
#ifdef DEBUG_NL
    qDebug() << "Adding? " << add;
#endif
    if (add) {
        m_list.append(node);
        qSort(m_list);

        if (m_list.size() > 1) {
            m_segments.grow();
        }

        // Reset curve type of neighbours if this is a linear node
        int index = m_list.indexOf(node);
        if (index > 0 && node.leftCurveType() == CurveType_Linear) {
            m_list[index-1].setRightCurveType(CurveType_Linear);
        }
        if (index < m_list.size()-1 && node.rightCurveType() == CurveType_Linear) {
            m_list[index+1].setLeftCurveType(CurveType_Linear);
        }

        fixHandles(index-1);
        fixHandles(index);
    }
#ifdef DEBUG_NL
    qDebug() << "After adding: \n" << *this;
#endif

    validate();
    return add;
}