Exemplo n.º 1
0
void setFactor(Node* node)
{
	 if (node != NULL)
     {
		 node ->factor =(height(node->left)- height(node -> right));
		 setFactor(node -> left);
		 setFactor(node -> right);
     }
}
Exemplo n.º 2
0
void DisplayItem::touchEvent(QTouchEvent* event) {
  if (event->touchPointStates() & Qt::TouchPointPressed) {
    if (event->touchPoints().size() == 2) {
      QPointF p1 = mapFromScreen(event->touchPoints()[0].pos());
      QPointF p2 = mapFromScreen(event->touchPoints()[1].pos());

      m_distance = QVector2D(p1 - p2).length();
    }
  }

  if (event->touchPoints().size() == 1) {
    if (flickable()) {
      QPointF p1 = mapFromScreen(event->touchPoints().front().lastPos());
      QPointF p2 = mapFromScreen(event->touchPoints().front().pos());

      setLookAt(effectiveLookAt() - p2 + p1);
    } else
      event->ignore();
  } else if (event->touchPoints().size() == 2) {
    QPointF p1 = mapFromScreen(event->touchPoints()[0].pos());
    QPointF p2 = mapFromScreen(event->touchPoints()[1].pos());

    qreal distance = QVector2D(p1 - p2).length();

    setFactor(factor() * distance / m_distance);
  } else
    event->ignore();
}
Exemplo n.º 3
0
void PowerLawWidgetManager::loadFromXml(TiXmlElement *_root) {
    std::vector < PowerLawWidget * > widgets;

    double valFactor, valExponent, valOffset, valMin, valMax;
    for (auto child = _root->FirstChildElement("PowerLawParameters"); child; child = child->NextSiblingElement()) {
        auto r0 = child->QueryDoubleAttribute("factor", &valFactor);
        auto r1 = child->QueryDoubleAttribute("exponent", &valExponent);
        auto r2 = child->QueryDoubleAttribute("offset", &valOffset);
        auto r3 = child->QueryDoubleAttribute("rangeMin", &valMin);
        auto r4 = child->QueryDoubleAttribute("rangeMax", &valMax);

        if (r0 == TIXML_SUCCESS && r1 == TIXML_SUCCESS && r2 == TIXML_SUCCESS && r3 == TIXML_SUCCESS &&
            r4 == TIXML_SUCCESS) {
            auto w = new PowerLawWidget();
            w->setFactor(valFactor);
            w->setExponent(valExponent);
            w->setOffset(valOffset);
            w->setMin(valMin);
            w->setMax(valMax);
            widgets.push_back(w);
        } else {
            QMessageBox::warning(0, "failed to load power laws", "could not load power laws: invalid file structure.");
            return;
        }
    }

    setPowerLawWidgets(widgets);
}
Exemplo n.º 4
0
/**
 * Zooms the view in a way that the given window is visible and fills the view.
 * The view is updated.
 */
void RGraphicsView::zoomTo(const RBox& window, int margin) {
    if (!window.isValid()) {
        return;
    }

    saveViewport();

    RVector f(RMAXDOUBLE, RMAXDOUBLE);
    double w = window.getWidth();
    double h = window.getHeight();

    if (w<1.0e-6 && h<1.0e-6) {
        return;
    }

    if (w>1.0e-6) {
        f.x = (getWidth() - 2 * margin) / w;
    }
    if (h>1.0e-6) {
        f.y = (getHeight() - 2 * margin) / h;
    }

    f.x = f.y = qMin(f.x, f.y);

    if (RSettings::getLimitZoomAndScroll() && f.x < 1.0e-9) {
        //f.x = f.y = 1.0;
        return;
    }

    setFactor(f.x);

    /*
    RBox viewWindow = mapToView(window);
    qDebug() << "viewWindow: " << viewWindow;
    RVector size = viewWindow.getSize();
    RVector f;

    if (size.x > 1.0e-6) {
        f.x = (getWidth() - 2 * margin) / size.x;
    } else {
        f.x = RMAXDOUBLE;
    }

    if (size.y > 1.0e-6) {
        f.y = (getHeight() - 2 * margin) / size.y;
    } else {
        f.y = RMAXDOUBLE;
    }

    f.x = f.y = qMin(f.x, f.y);

    if (f.x < 1.0e-6 || f.x == RMAXDOUBLE) {
        f.x = f.y = 1.0;
    }

    setFactor(factor * f.x);
    */

    centerToBox(window);
}
Exemplo n.º 5
0
void DisplayItem::returnScaleToBounds() {
  qreal w = size().width();
  qreal h = size().height();
  qreal aspect =
      std::max(m_frame->size().width() / w, m_frame->size().height() / h);

  setFactor(std::max(factor(), (qreal)aspect));
}
Exemplo n.º 6
0
PowerLawWidgetManager::PowerLawWidgetManager(QWidget *_parent) : m_Parent(_parent) {
    // defaults from paper
    addPowerLaw();
    auto w1 = addPowerLaw();
    w1->setMin(0);
    w1->setFactor(6850);
    w1->setExponent(1.49);
}
Exemplo n.º 7
0
/**
 * Zooms in / out by the given factor towards / from the given center
 * in scene coordinates.
 */
void RGraphicsView::zoom(const RVector& center, double f) {
    saveViewport();

    RVector newOffset = offset - (center*f - center);
    newOffset/=f;

    setFactor(factor*f);

    setOffset(newOffset, true);
}
Exemplo n.º 8
0
 const Polynomial<T>& operator+=(Polynomial<T> const& other)
 {
     const std::size_t otherDegree = other.getDegree();
     if (otherDegree > getDegree())
         mFactors.resize(otherDegree);
     for (std::size_t i = 0; i < otherDegree; ++i)
     {
         setFactor(i, other.mFactors[i] + mFactors[i]);
     }
     return *this;
 }
Exemplo n.º 9
0
void RS_ActionDrawImage::commandEvent(RS_CommandEvent* e) {
    RS_String c = e->getCommand().lower();

    if (checkCommand("help", c)) {
        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
                                         + getAvailableCommands().join(", "));
        return;
    }

    switch (getStatus()) {
    case SetTargetPoint:
        if (checkCommand("angle", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetAngle);
        } else if (checkCommand("factor", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetFactor);
        }
        break;

    case SetAngle: {
            bool ok;
            double a = RS_Math::eval(c, &ok);
            if (ok==true) {
                setAngle(RS_Math::deg2rad(a));
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    case SetFactor: {
            bool ok;
            double f = RS_Math::eval(c, &ok);
            if (ok==true) {
                setFactor(f);
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    default:
        break;
    }
}
Exemplo n.º 10
0
 const Polynomial<T>& operator*=(Polynomial<T>& other)
 {
     const std::size_t degree = getDegree();
     const std::size_t otherDegree = other.getDegree();
     std::vector<T> tmp(mFactors);
     mFactors.clear();
     mFactors.resize(degree + otherDegree - 1);
     for (std::size_t i = 0; i < degree; ++i)
     {
         for (std::size_t j = 0; j < otherDegree; ++j)
         {
             setFactor(i+j, tmp[i] * other[j] + mFactors[i+j]);
         }
     }
     return *this;
 }
Exemplo n.º 11
0
//------------------------------------------------------------
void input::updateInput(ofxCvGrayscaleImage grayThres){
    
    int w = grayThres.width;
    int h = grayThres.height;
    
    contours.findContours(grayThres, 1000, w*h , 1, false); //only one blob, no holes.
    if (contours.nBlobs){
        blob = contours.blobs[0]; //we always work with the biggest blob.

        setPos();
        setArea();
        setFactor();
        setRatio();
        empty = false;
    } else {
        empty = true;
    }

}
Exemplo n.º 12
0
void RS_ActionBlocksInsert::commandEvent(RS_CommandEvent* e) {
    QString c = e->getCommand().toLower();

    if (checkCommand("help", c)) {
        RS_DIALOGFACTORY->commandMessage(msgAvailableCommands()
                                         + getAvailableCommands().join(", "));
        return;
    }

    switch (getStatus()) {
    case SetTargetPoint:
        if (checkCommand("angle", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetAngle);
        } else if (checkCommand("factor", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetFactor);
        } else if (checkCommand("columns", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetColumns);
        } else if (checkCommand("rows", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetRows);
        } else if (checkCommand("columnspacing", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetColumnSpacing);
        } else if (checkCommand("rowspacing", c)) {
            deletePreview();
            lastStatus = (Status)getStatus();
            setStatus(SetRowSpacing);
        }
        break;

    case SetAngle: {
            bool ok;
            double a = RS_Math::eval(c, &ok);
            if (ok) {
				data->angle = RS_Math::deg2rad(a);
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    case SetFactor: {
            bool ok;
            double f = RS_Math::eval(c, &ok);
            if (ok) {
                setFactor(f);
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    case SetColumns: {
            bool ok;
            int cols = (int)RS_Math::eval(c, &ok);
            if (ok) {
				data->cols = cols;
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    case SetRows: {
            bool ok;
            int rows = (int)RS_Math::eval(c, &ok);
            if (ok) {
				data->rows = rows;
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    case SetColumnSpacing: {
            bool ok;
            double cs = (int)RS_Math::eval(c, &ok);
            if (ok) {
				data->spacing.x = cs;
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    case SetRowSpacing: {
            bool ok;
            int rs = (int)RS_Math::eval(c, &ok);
            if (ok) {
				data->spacing.y = rs;
            } else {
                RS_DIALOGFACTORY->commandMessage(tr("Not a valid expression"));
            }
            RS_DIALOGFACTORY->requestOptions(this, true, true);
            setStatus(lastStatus);
        }
        break;

    default:
        break;
    }
}
Exemplo n.º 13
0
Scale::Scale(GLfloat* factor)
{
    setFactor(factor);
}
Exemplo n.º 14
0
void DisplayItem::wheelEvent(QWheelEvent* event) {
  if (event->angleDelta().y() > 0)
    setFactor(factor() * 1.1);
  else
    setFactor(factor() / 1.1);
}
Exemplo n.º 15
0
 CustomTimeLine(): QTimeLine(), useLogisticFunction(false) {
     setFactor(4);
 }