コード例 #1
0
ファイル: envportal.cpp プロジェクト: jaxzin/firebox
bool EnvPortal::GetPlayerAtChild(const QVector3D & player_pos) const
{
    QVector2D local = GetChildLocal(player_pos);
    return (local.x() >= -1.0f && local.x() <= 1.0f && local.y() >= -1.0f && local.y() <= 1.0f);
}
コード例 #2
0
void TMSIImpedanceWidget::addElectrodeItem(QString electrodeName, QVector2D position)
{
    TMSIElectrodeItem *item = new TMSIElectrodeItem(electrodeName, QPointF(position.x(), position.y()), QColor(m_cbColorMap->valueToJet(1)), m_qmElectrodeNameIndex[electrodeName]);
    item->setPos(QPointF(position.x(), position.y()));
    m_qGScene->addItem(item);
}
コード例 #3
0
ファイル: qvector2d.cpp プロジェクト: 13W/phantomjs
QDebug operator<<(QDebug dbg, const QVector2D &vector)
{
    dbg.nospace() << "QVector2D(" << vector.x() << ", " << vector.y() << ')';
    return dbg.space();
}
コード例 #4
0
ファイル: envportal.cpp プロジェクト: jaxzin/firebox
bool EnvPortal::GetPlayerNearParent(const QVector3D & player_pos) const
{
    QVector2D local = GetParentLocal(player_pos);
    return (local.x() >= -1.0f && local.x() <= 1.0f && local.y() >= -1.0f && local.y() <= 3.0f);
}
コード例 #5
0
ファイル: BBox.cpp プロジェクト: Dryuna/BagOfFeatures-1
bool BBox::contains(const QVector2D &pt) const {
	if (pt.x() < minPt.x() || pt.y() < minPt.y()) return false;
	if (pt.x() > maxPt.x() || pt.y() > maxPt.y()) return false;

	return true;
}
コード例 #6
0
ファイル: BBox.cpp プロジェクト: Dryuna/BagOfFeatures-1
BBox::BBox(const QVector2D& pt) {
	minPt.setX(pt.x());
	minPt.setY(pt.y());
	maxPt.setX(pt.x());
	maxPt.setY(pt.y());
}
コード例 #7
0
void //TODO: second plane
SliceAdjustmentTool::toolMouseMoveEvent(QMouseEvent *ev)
{
    voxie::data::SliceImage& currentImg = (currentSlice == 0) ? this->sv->sliceImageFirst() : this->sv->sliceImageSecond();
    voxie::data::SliceImage& otherImg   = (currentSlice == 1) ? this->sv->sliceImageFirst() : this->sv->sliceImageSecond();
    voxie::data::Slice* otherSlice = (currentSlice == 0) ? this->sv->slices().at(0) : this->sv->slices().at(1);

    if(this->dragUpdates){
        if(this->ctrlDown){
            if(this->rotatingInProgress){
                QVector2D cursorOnPlane = QVector2D(currentImg.pixelToPlanePoint(ev->pos(), true)).normalized();
                float angle = (float) qAcos(QVector3D::dotProduct(this->rotationHypotenuse, cursorOnPlane));
                // check clockwise or counterclockwise rotation
                float sign = 1;
                {
                    /* to know if cursor is left of hypotenuse rotate their coordinatesystem so that
                     * hypotenuse points in xAxis direction and check if cursor.y is positive.
                     * Rotation matrix for this can be obtained from hypotenuse since its normalized
                     *      counterclockwise                clockwise
                     *      cos(a)  -sin(a)                 cos(a)/det   sin(a)/det
                     *      sin(a)   cos(a)                -sin(a)/det   cos(a)/det
                     *
                     * with cos(a) = hypotenuse.x , sin(a) = hypotenuse.y , det = determinant(clockwise rotMat)
                     */
                    qreal cos = this->rotationHypotenuse.x();
                    qreal sin = this->rotationHypotenuse.y();
                    qreal det = cos*cos + sin*sin;
                    // y-part of matrix multiplication (clockwise*cursor)
                    qreal rotCursorY = -sin/det * cursorOnPlane.x() + cos/det * cursorOnPlane.y();
                    sign = rotCursorY > 0 ? 1:-1;
                }
                if(this->selectedBoth)
                {
                    QVector2D cursorOnPlane = QVector2D(otherImg.pixelToPlanePoint(ev->pos(), true)).normalized();
                    float angle = (float) qAcos(QVector3D::dotProduct(this->rotationHypotenuse2, cursorOnPlane));
                    // check clockwise or counterclockwise rotation
                    float sign = 1;
                    {
                        /* to know if cursor is left of hypotenuse rotate their coordinatesystem so that
                         * hypotenuse points in xAxis direction and check if cursor.y is positive.
                         * Rotation matrix for this can be obtained from hypotenuse since its normalized
                         *      counterclockwise                clockwise
                         *      cos(a)  -sin(a)                 cos(a)/det   sin(a)/det
                         *      sin(a)   cos(a)                -sin(a)/det   cos(a)/det
                         *
                         * with cos(a) = hypotenuse.x , sin(a) = hypotenuse.y , det = determinant(clockwise rotMat)
                         */
                        qreal cos = this->rotationHypotenuse2.x();
                        qreal sin = this->rotationHypotenuse2.y();
                        qreal det = cos*cos + sin*sin;
                        // y-part of matrix multiplication (clockwise*cursor)
                        qreal rotCursorY = -sin/det * cursorOnPlane.x() + cos/det * cursorOnPlane.y();
                        sign = rotCursorY > 0 ? 1:-1;
                    }
                    rotateSlice(otherSlice, otherSlice->normal(), ((angle)/3.1415f) * 180 * sign);
                    this->rotationHypotenuse2 = cursorOnPlane;
                }
                rotateSlice(this->slice, this->slice->normal(), ((angle)/3.1415f) * 180 * sign);
                this->rotationHypotenuse = cursorOnPlane;
            }
        }
    }
}
コード例 #8
0
ファイル: BBox.cpp プロジェクト: Dryuna/BagOfFeatures-1
bool BBox::hitTestResizingPoint(const QVector2D& pt) const {
	if (fabs(pt.x() - maxPt.x()) < dx() * 0.1f && fabs(pt.y() - minPt.y()) < dy() * 0.1f) return true;
	else return false;
}
コード例 #9
0
SketchJoint::SketchJoint(QObject* rawPoint, QList<QObject*> lines) {

    /**
      * Precondition : note that this is only possible to compute
      * if the angle between each line is greater than
      * 2*Arctan(SketchLine::radius/SketchLine::edgeShortcut) otherwise
      * we would need to cut more than SketchLine::edgeShortcut
      *
      * 1) Sort the line with respect to angle from the rawPoint center
      * 2) Compute two point on the line equation at distance parametrized
      *    via SketchLine::radius  and compute two point on the line
      * 3) compute the intersection
      *    from following equation : http://stackoverflow.com/a/385355
      *
      *    float x12 = x1 - x2;
      *    float x34 = x3 - x4;
      *    float y12 = y1 - y2;
      *    float y34 = y3 - y4;
      *
      *    float c = x12 * y34 - y12 * x34;
      *
      *    if (fabs(c) < 0.01)
      *    {
      *      // No intersection
      *      return false;
      *    }
      *    else
      *    {
      *      // Intersection
      *      float a = x1 * y2 - y1 * x2;
      *      float b = x3 * y4 - y3 * x4;
      *
      *      float x = (a * x34 - b * x12) / c;
      *      float y = (a * y34 - b * y12) / c;
      *
      *      return true;
      *    }
      *
      * 4) We build the list of vertices in this way :
      *     foreach Lines
      *     I.   take the first point on the line drawn by third and fourth point on line 1
      *     II.  take the intersection between the current and next line
      *     III. take the first point on the line drawn by first and sercond point on line 2
      * 5) Compute the 3D vertex
      */

#ifdef CARPENTER_DEBUG
    qDebug() << "SketchJoint: new SketchJoint";
    qDebug() << "SketchJoint: " << lines;
    qDebug() << "SketchJoint: " << rawPoint;
    qDebug() << "SketchJoint: edgeShortcut" << SketchLine::edgeShortcut;
    qDebug() << "SketchJoint: radius" << SketchLine::radius;
#endif

    QVariant startProperty = rawPoint->property("start");

    if(!startProperty.isValid() || !startProperty.canConvert<QVector2D>()) {
        this->setErrorMessage("Cannot find origin in Point");
        return;
    }

    QVector2D point = startProperty.value<QVector2D>();

    // Nothing to do if no more than one line
    if(lines.size() <= 1) {
        this->setValid(true);
        return;
    }

    foreach(QObject* line, lines) {
        // ----------------------------------------------------------------------------------
        // Cast and properties check

        QVariant pointerProperty = line->property("pointer");
        if(!pointerProperty.isValid() || !pointerProperty.canConvert<QVector2D>()) {
            this->setErrorMessage("Cannot find or convert pointer in Line");
            return;
        }

        QVariant endPointProperty = line->property("endPoint");
        if(!endPointProperty.isValid() || !endPointProperty.canConvert<QObject*>()) {
            this->setErrorMessage("Cannot find or convert endPoint in Line");
            return;
        }

        QVariant identifierProperty = line->property("identifier");
        if(!identifierProperty.isValid() || !identifierProperty.canConvert<int>()) {
            this->setErrorMessage("Cannot find or convert identifier in Line");
            return;
        }

        int identifier = identifierProperty.toInt();

        // ----------------------------------------------------------------------------------

        QVector2D pointer = pointerProperty.value<QVector2D>().normalized();
        if(endPointProperty.value<QObject*>() == rawPoint) {
            //qDebug() << "invert the pointer";
            pointer *= -1.0f;
        }

        double angle = qRadiansToDegrees(qAtan2(pointer.y(),pointer.x()));
        // want angle from 0 to 360
        if(angle < 0) {
            angle = 360 + angle;
        }

        line->setProperty("sortAngle", angle);
#ifdef CARPENTER_DEBUG
        qDebug() << "SketchJoint: line #" << identifier << ":" << angle;
#endif

        /*
         * 2) compute the two points
         */

        // need the normal in the inverse direction of angle
        QVector2D normal = QVector2D(pointer.y(), -pointer.x()).normalized();

        QVector2D firstPoint = point + (normal * SketchLine::radius);
        QVector2D secondPoint = point + (pointer * SketchLine::edgeShortcut) + (normal * SketchLine::radius);

        QVector2D thirdPoint = point - (normal * SketchLine::radius);
        QVector2D fourthPoint = point + (pointer * SketchLine::edgeShortcut) - (normal * SketchLine::radius);

#ifdef CARPENTER_DEBUG
        qDebug() << "SketchJoint: #:" <<  identifier;

        qDebug() << "SketchJoint:  -> origin" << point.x() << point.y() <<  "";
        qDebug() << "SketchJoint:  -> normal" << normal <<  "";
        qDebug() << "SketchJoint:  -> normal * radius" << (normal * SketchLine::radius) <<  "\n";
        qDebug() << "SketchJoint:  -> pointer" << pointer <<  "";
        qDebug() << "SketchJoint:  -> pointer * edgeShortcut" << (pointer * SketchLine::edgeShortcut) <<  "\n";

        qDebug() << "SketchJoint:  -> firstPoint (" << firstPoint.x() << "," << firstPoint.y() << ")";
        qDebug() << "SketchJoint:  -> secondPoint (" << secondPoint.x() << "," << secondPoint.y() << ")";

        qDebug() << "SketchJoint:  -> thirdPoint (" << thirdPoint.x() << "," << thirdPoint.y() << ")";
        qDebug() << "SketchJoint:  -> fourthPoint (" << fourthPoint.x() << "," << fourthPoint.y() << ")";
#endif

        line->setProperty("firstPoint", firstPoint);
        line->setProperty("secondPoint", secondPoint);
        line->setProperty("thirdPoint", thirdPoint);
        line->setProperty("fourthPoint", fourthPoint);
    }
コード例 #10
0
    void draw_data(void)
    {
#if 0
        // !!! タイムスタンプのローテーションに対応できていないので、
        // !!! 1つ残して全てのデータを削除するようにする

        // 一定時間以上経過したデータを削除
        size_t data_size = draw_data_.size();
        for (size_t i = 0; i < data_size; ++i) {
            long diff = last_timestamp_ - draw_data_[0]->timestamp;
            if (diff < draw_period_) {
                break;
            }

            remove_front_data();
        }
#else
        // 一定時間以上経過したデータを削除
        // 強度と距離の2つのみ残す
        int remove_size = draw_data_.size() - 2;
        for (int i = 0; i < remove_size; ++i) {
            remove_front_data();
        }
#endif

        // !!! 時間が経過するほど、薄い色で表示するようにする

        double ratio = zoom_ratio();
        QVector2D offset = point_offset(ratio);

        // 注視するステップ位置に線を描画
        if (is_step_line_active_) {
            double radian = step_line_radian_ + (M_PI / 2.0);
            double x = 100000 * cos(radian);
            double y = 100000 * sin(radian);

            glColor4d(0.0, 1.0, 0.0, 0.9);

            glBegin(GL_LINES);
            glVertex2d(-offset.x(), -offset.y());
            glVertex2d(x - offset.x(), y - offset.y());
            glEnd();
        }

        // 中心から測定点への直線を描画
        glBegin(GL_LINES);
        for (deque<Draw_data*>::const_iterator scan_it = draw_data_.begin();
             scan_it != draw_data_.end(); ++scan_it) {

            QColor& color = (*scan_it)->color;
#if 0
            double diff = last_timestamp_ - (*scan_it)->timestamp;
            double alpha = (1.0 - (diff / draw_period_)) * 0.6;
#else
            double alpha = color.alpha() / 255.0;
#endif
            glColor4d(color.red() / 255.0,
                      color.green() / 255.0,
                      color.blue() / 255.0, alpha);

            vector<QPoint>& scan_data = (*scan_it)->points;
            vector<QPoint>::const_iterator end_it = scan_data.end();
            for (vector<QPoint>::const_iterator it = scan_data.begin();
                 it != end_it; ++it) {

                double x = it->x() * ratio;
                double y = it->y() * ratio;
                glVertex2d(-offset.x(), -offset.y());
                glVertex2d(x - offset.x(), y - offset.y());
            }
        }
        glEnd();

#if 0
        // 測定点の描画
        double base_size = 1.4;
        double mm_pixel = max(base_size / pixel_per_mm_, base_size);
        glPointSize(mm_pixel);

        glBegin(GL_POINTS);
        for (DataArray::iterator line_it = draw_data_.begin();
             line_it != draw_data_.end(); ++line_it) {

            // !!! 関数にする
            double diff = last_timestamp_ - line_it->timestamp;
            double alpha = 1.0 - (diff / draw_period_);
            glColor4d(1.0, 0.0, 0.0, alpha);

            vector<QPoint>::iterator end_it = line_it->point_data.end();
            for (vector<QPoint>::iterator it =
                     line_it->point_data.begin();
                 it != end_it; ++it) {

                double x = it->x * ratio;
                double y = it->y * ratio;
                glVertex2d(x - offset.x, y - offset.y);
            }
        }
        glEnd();
#endif
    }
コード例 #11
0
    void tvalue2json(rapidjson::Value & output, const QVariant & input, rapidjson::Value::AllocatorType & allocator)
    {
        switch(input.type())
        {
        case QVariant::Invalid:
        {
            output.SetNull();
            break;
        }
        case QVariant::Bool:
        {
            output.SetBool(input.toBool());
            break;
        }
        case QVariant::Int:
        {
            output.SetInt64(input.toInt());
            break;
        }
        case QVariant::LongLong:
        {
            output.SetInt64(input.toLongLong());
            break;
        }
        case QVariant::Double:
        {
            output.SetDouble(input.toDouble());
            break;
        }
        case QVariant::String:
        {
            QByteArray str = input.toString().toUtf8();
            output.SetString(str.data(), str.size(), allocator);
            break;
        }
        case QVariant::StringList:
        {
            QStringList list = input.toStringList();

            output.SetArray();
            output.Reserve(list.size(), allocator);

            rapidjson::Value temp;
            for(QStringList::const_iterator it = list.begin(); it != list.end(); ++it)
            {
                QByteArray str = it->toUtf8();
                temp.SetString(str.data(), str.size(), allocator);
                output.PushBack(temp, allocator);
            }
            break;
        }
        case QVariant::List:
        {
            QList<QVariant> list = input.toList();

            output.SetArray();
            output.Reserve(list.size(), allocator);

            rapidjson::Value temp;
            for(QList<QVariant>::const_iterator it = list.begin(); it != list.end(); ++it)
            {
                tvalue2json(temp, *it, allocator);
                output.PushBack(temp, allocator);
            }
            break;
        }
        case QVariant::Map:
        {
            output.SetObject();
            rapidjson::Value tempK, tempV;

            QMap<QString, QVariant> qmap = input.toMap();
            for(QMap<QString, QVariant>::const_iterator it = qmap.begin(); it != qmap.end(); ++it)
            {
                tvalue2json(tempK, it.key(), allocator);
                tvalue2json(tempV, it.value(), allocator);
                output.AddMember(tempK, tempV, allocator);
            }
            break;
        }
        case QVariant::Point:
        {
            QPoint pt = input.toPoint();

            output.SetArray();
            output.Reserve(2, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            break;
        }
        case QVariant::PointF:
        {
            QPointF pt = input.toPointF();

            output.SetArray();
            output.Reserve(2, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            break;
        }
        case QVariant::Size:
        {
            QSize pt = input.toSize();

            output.SetArray();
            output.Reserve(2, allocator);

            output.PushBack(pt.width(), allocator);
            output.PushBack(pt.height(), allocator);
            break;
        }
        case QVariant::SizeF:
        {
            QSizeF pt = input.toSizeF();

            output.SetArray();
            output.Reserve(2, allocator);

            output.PushBack(pt.width(), allocator);
            output.PushBack(pt.height(), allocator);
            break;
        }
        case QVariant::Rect:
        {
            QRect pt = input.toRect();

            output.SetArray();
            output.Reserve(4, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            output.PushBack(pt.width(), allocator);
            output.PushBack(pt.height(), allocator);
            break;
        }
        case QVariant::RectF:
        {
            QRectF pt = input.toRectF();

            output.SetArray();
            output.Reserve(4, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            output.PushBack(pt.width(), allocator);
            output.PushBack(pt.height(), allocator);
            break;
        }
        case QVariant::Vector2D:
        {
            QVector2D pt = input.value<QVector2D>();

            output.SetArray();
            output.Reserve(2, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            break;
        }
        case QVariant::Vector3D:
        {
            QVector3D pt = input.value<QVector3D>();

            output.SetArray();
            output.Reserve(3, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            output.PushBack(pt.z(), allocator);
            break;
        }
        case QVariant::Vector4D:
        {
            QVector4D pt = input.value<QVector4D>();

            output.SetArray();
            output.Reserve(4, allocator);

            output.PushBack(pt.x(), allocator);
            output.PushBack(pt.y(), allocator);
            output.PushBack(pt.z(), allocator);
            output.PushBack(pt.w(), allocator);
            break;
        }
        case QVariant::Color:
        {
            QColor pt = input.value<QColor>();

            output.SetArray();
            output.Reserve(4, allocator);

            output.PushBack(pt.red(), allocator);
            output.PushBack(pt.green(), allocator);
            output.PushBack(pt.blue(), allocator);
            output.PushBack(pt.alpha(), allocator);
            break;
        }
        default:
        {
            output.SetNull();
            assert(false && "shuldn't execute to here.");
        }
        }
    }
コード例 #12
0
qreal QGLBezierPatch::intersection
    (qreal result, int depth, const QRay3D& ray, bool anyIntersection,
     qreal xtex, qreal ytex, qreal wtex, qreal htex, QVector2D *tc)
{
    // Check the convex hull of the patch for an intersection.
    // If no intersection with the convex hull, then there is
    // no point subdividing this patch further.
    QBox3D box;
    for (int point = 0; point < 16; ++point)
        box.unite(points[point]);
    if (!box.intersects(ray))
        return result;

    // Are we at the lowest point of subdivision yet?
    if (depth <= 1) {
        // Divide the patch into two triangles and intersect with those.
        QTriangle3D triangle1(points[0], points[3], points[12]);
        qreal t = triangle1.intersection(ray);
        if (!qIsNaN(t)) {
            result = combineResults(result, t);
            if (result == t) {
                QVector2D uv = triangle1.uv(ray.point(t));
                QVector2D tp(xtex, ytex);
                QVector2D tq(xtex + wtex, ytex);
                QVector2D tr(xtex, ytex + htex);
                *tc = uv.x() * tp + uv.y() * tq + (1 - uv.x() - uv.y()) * tr;
            }
        } else {
            QTriangle3D triangle2(points[3], points[15], points[12]);
            qreal t = triangle2.intersection(ray);
            if (!qIsNaN(t)) {
                result = combineResults(result, t);
                if (result == t) {
                    QVector2D uv = triangle2.uv(ray.point(t));
                    QVector2D tp(xtex + wtex, ytex);
                    QVector2D tq(xtex + wtex, ytex + htex);
                    QVector2D tr(xtex, ytex + htex);
                    *tc = uv.x() * tp + uv.y() * tq + (1 - uv.x() - uv.y()) * tr;
                }
            }
        }
    } else {
        // Subdivide the patch to find the point of intersection.
        QGLBezierPatch patch1, patch2, patch3, patch4;
        subDivide(patch1, patch2, patch3, patch4);
        --depth;
        qreal hwtex = wtex / 2.0f;
        qreal hhtex = htex / 2.0f;
        result = patch1.intersection
            (result, depth, ray, anyIntersection,
             xtex, ytex, hwtex, hhtex, tc);
        if (anyIntersection && !qIsNaN(result))
            return result;
        result = patch2.intersection
            (result, depth, ray, anyIntersection,
             xtex + hwtex, ytex, hwtex, hhtex, tc);
        if (anyIntersection && !qIsNaN(result))
            return result;
        result = patch3.intersection
            (result, depth, ray, anyIntersection,
             xtex, ytex + hhtex, hwtex, hhtex, tc);
        if (anyIntersection && !qIsNaN(result))
            return result;
        result = patch4.intersection
            (result, depth, ray, anyIntersection,
             xtex + hwtex, ytex + hhtex, hwtex, hhtex, tc);
    }
    return result;
}
コード例 #13
0
void SettingsManager::Set(QString Key, QVector2D Val)
{    
    Map.insert(Key, QString::number(Val.x()) + ";" + QString::number(Val.y()));
}
コード例 #14
0
ファイル: coordinator.cpp プロジェクト: Rambo2015/TaxiVis
 foreach (ViewWidget *view,  _linkedViews) {
   GeographicalViewWidget *gw = (GeographicalViewWidget*)view->mapWidget();
   gw->getColorBar()->setRealMinMax(range.x(), range.y());
   gw->repaintContents();
 }
コード例 #15
0
ファイル: coordinator.cpp プロジェクト: Rambo2015/TaxiVis
 foreach (ViewWidget *view,  _linkedViews) {
   GeographicalViewWidget *gw = (GeographicalViewWidget*)view->mapWidget();
   QVector2D r = gw->getScalarRange();
   range.setX(std::min(range.x(), r.x()));
   range.setY(std::max(range.y(), r.y()));
 }