Skip to content
Snippets Groups Projects
petrack.cpp 151 KiB
Newer Older
  • Learn to ignore specific revisions
  • d.kilic's avatar
    d.kilic committed
    
    
    /**
     * @brief Splits the given text to get a set of integers.
     *
     * The given text will be split on ',' and then each element will be checked if it is a range. Ranges are marked with
     * '-' as divider. Only positive integer values are allowed.
     *
     * Examples:
     * '1,5,6' -> (1, 5, 6)
     * '1-5' -> (1, 2, 3, 4, 5)
     *
     * @param input given text
     * @return Set of int in the given text
     */
    std::optional<QSet<int>> util::splitStringToInt(const QString &input)
    {
        QSet<int> ids;
    
        for(const auto &id : input.split(",", Qt::SkipEmptyParts))
        {
            bool ok        = false;
            int  enteredID = id.toInt(&ok);
            if(ok && enteredID >= 0) // parse single values
            {
                ids.insert(enteredID);
            }
            else // error or IDs range (e.g. 1-3, 6-10, etc.)
            {
                if(id.startsWith("-"))
                {
                    ok = false;
                }
                auto range = id.split("-");
                int  first = range[0].toInt(&ok);
                ok         = ok && range.size() == 2 && !range[1].isEmpty();
                if(ok)
                {
                    int last = range[1].toInt(&ok);
                    if(ok)
    
    d.kilic's avatar
    d.kilic committed
                        {
    
                        for(int i = first; i <= last; i++)
                        {
                            ids.insert(i);
    
    }
    
    /**
     * @brief Checks which pedestrians/trajectories are selected for evaluation.
     *
     * If "only for selected" is checked, then only selected people (@see
     * Petrack::getPedestrianUserSelection()) are going to be tracked, all people
     * otherwise.
     *
     * @return all trajectories which should be evaluated; empty when all should be evaluated
     */
    QSet<int> Petrack::getPedestriansToTrack()
    {
    
        if(mControlWidget->trackOnlySelected->checkState() == Qt::Checked)
    
            return getPedestrianUserSelection();
    
    d.kilic's avatar
    d.kilic committed
    }
    
    
    void Petrack::addManualTrackPointOnlyVisible(const QPointF &pos)
    
    d.kilic's avatar
    d.kilic committed
    {
    
        int pers = addOrMoveManualTrackPoint(pos) + 1;
        if(pers == 0)
    
            pers = static_cast<int>(mPersonStorage.nbPersons()) + 1;
    
    d.kilic's avatar
    d.kilic committed
        mControlWidget->trackShowOnlyNr->setValue(pers);
        mControlWidget->trackShowOnly->setChecked(true);
    }
    
    void Petrack::updateControlWidget()
    {
    
        mControlWidget->trackNumberAll->setText(QString("%1").arg(mPersonStorage.nbPersons()));
        mControlWidget->trackShowOnlyNr->setMaximum(MAX(mPersonStorage.nbPersons(), 1));
        mControlWidget->trackNumberVisible->setText(
            QString("%1").arg(mPersonStorage.visible(mAnimation->getCurrentFrameNum())));
    
    d.kilic's avatar
    d.kilic committed
    }
    
    void Petrack::splitTrackPerson(QPointF pos)
    {
    
        mPersonStorage.splitPersonAt((Vec2F) pos, mAnimation->getCurrentFrameNum(), getPedestrianUserSelection());
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
    }
    
    
     * @brief Lets the user add or move a TrackPoint manually
     *
     * There is an check inside addPoint which inhibits adding a point,
     * if only selected trajectories are visualized, since one wouldn't
     * see the newly added TrackPoint.
    
     *
     * @param pos pixel position of mouse on image
    
     * @return index of person whose point was moved; -1 if failed or new trajectory is started
    
    int Petrack::addOrMoveManualTrackPoint(const QPointF &pos)
    
    d.kilic's avatar
    d.kilic committed
    {
    
        int        pers = -1;
    
        TrackPoint tP(Vec2F{pos}, 110); // 110 is higher than 100 (max. quality) and gets clamped to 100 after insertion
        // allows replacemet of every point (check for better quality always passes)
    
        mPersonStorage.addPoint(
    
            tP, mAnimation->getCurrentFrameNum(), getPedestrianUserSelection(), mReco.getRecoMethod(), &pers);
    
        updateControlWidget();
        return pers;
    
    d.kilic's avatar
    d.kilic committed
    }
    
    // direction zeigt an, ob bis zum aktuellen (-1), ab dem aktuellen (1) oder ganzer trackpath (0)
    // loeschen von Trackpoints einer Trajektorie
    
    void Petrack::deleteTrackPoint(QPointF pos, int direction) // const QPoint &pos
    
    d.kilic's avatar
    d.kilic committed
    {
    
        mPersonStorage.delPoint((Vec2F) pos, direction, mAnimation->getCurrentFrameNum(), getPedestrianUserSelection());
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
    }
    void Petrack::editTrackPersonComment(QPointF pos)
    {
    
        mPersonStorage.editTrackPersonComment((Vec2F) pos, mAnimation->getCurrentFrameNum(), getPedestrianUserSelection());
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
    }
    void Petrack::setTrackPersonHeight(QPointF pos)
    {
    
        mPersonStorage.setTrackPersonHeight((Vec2F) pos, mAnimation->getCurrentFrameNum(), getPedestrianUserSelection());
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
    }
    void Petrack::resetTrackPersonHeight(QPointF pos)
    {
    
        mPersonStorage.resetTrackPersonHeight((Vec2F) pos, mAnimation->getCurrentFrameNum(), getPedestrianUserSelection());
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
    }
    
    
    /**
     * @brief Delete the following, previous or whole trajectory of **all** trajectories
     * @param direction previous, following or whole
     */
    void Petrack::deleteTrackPointAll(PersonStorage::Direction direction) // const QPoint &pos
    
    d.kilic's avatar
    d.kilic committed
    {
    
        mPersonStorage.delPointAll(direction, mAnimation->getCurrentFrameNum());
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
    }
    
    void Petrack::deleteTrackPointROI()
    {
    
        mPersonStorage.delPointROI();
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
        mScene->update();
    }
    
    void Petrack::deleteTrackPointInsideROI()
    {
    
        getPersonStorage().delPointInsideROI();
    
    d.kilic's avatar
    d.kilic committed
        updateControlWidget();
        mScene->update();
    }
    void Petrack::updateSourceInOutFrames()
    {
        mPlayerWidget->setFrameInNum(mAnimation->getSourceInFrameNum());
    
        mPlayerWidget->setFrameOutNum(mAnimation->getSourceOutFrameNum());
    
    d.kilic's avatar
    d.kilic committed
    }
    
    // delta gibt menge an Umdrehungen und richtung an
    void Petrack::skipToFrameWheel(int delta)
    {
    
        mPlayerWidget->skipToFrame(mPlayerWidget->getPos() + delta);
    
    d.kilic's avatar
    d.kilic committed
    }
    
    void Petrack::setPeTrackVersion(const std::string &petrackVersion)
    
    {
        mPetrackVersion = QString::fromStdString(petrackVersion);
    }
    
    void Petrack::setGitInformation(
    
        const std::string &gitCommitID,
        const std::string &gitCommitDate,
        const std::string &gitCommitBranch)
    
        mGitCommitID     = QString::fromStdString(gitCommitID);
        mGitCommitDate   = QString::fromStdString(gitCommitDate);
    
        mGitCommitBranch = QString::fromStdString(gitCommitBranch);
    }
    
    
    void Petrack::setCompileInformation(
        const std::string &compileTimeStamp,
        const std::string &compilerID,
        const std::string &compilerVersion)
    
        mCompileDate     = QString::fromStdString(compileTimeStamp);
        mCompilerID      = QString::fromStdString(compilerID);
    
        mCompilerVersion = QString::fromStdString(compilerVersion);
    }
    
    
    #include "moc_petrack.cpp"