예제 #1
0
void QAGC::setDecay(float decay) {

    mutex.lock();
    m_decay = 1.0 - qExp(-1000.0 / (decay * m_samplerate));
    m_oneMDecay = qExp(-1000.0 / (decay * m_samplerate));   
    mutex.unlock();
}
예제 #2
0
void GMonteCarloLogNormalPricer::PlotRandIteration()
{
	m_Mutex.lock();
	GPayOff & thePayOff = *m_pPayOff;

	double rootVariance = sqrt(variance);
	double itoCorrection = -0.5 * variance;

	double currentSpot = minRangePlot;

	double previousSampleCount = m_TotalNumberIteration;
	m_TotalNumberIteration++;
	double OneOverNewSampleCount = 1/(double(m_TotalNumberIteration));

	// for each spot currentSpot, we will compute PayOff(exp(-r* - 0.5 * sigma^2))
	for(int i = 0; i < numPointsPlot; i++) {
		// for the average, we re multiply the averaged value by the number of sample
		// latter we will divide by the new number of samples
		m_CurrentPlotValues[i] *= previousSampleCount;

		double drawGauss = rootVariance * RandGaussianBySummation();
		double drawSpot = currentSpot * qExp(r * expiry + itoCorrection + drawGauss);
		double drawPayOff = thePayOff(drawSpot);
		m_CurrentPlotValues[i] += drawPayOff * qExp(-r * expiry);

		// for the average, we divide by the new number of samples
		m_CurrentPlotValues[i] *= OneOverNewSampleCount;
		currentSpot += deltaSpot;
	}
	m_Mutex.unlock();
	QMetaObject::invokeMethod(this, "EventPlotValuesUpdated");
}
예제 #3
0
void MainWindow::setupColorMapTest(QCustomPlot *customPlot)
{
	customPlot->legend->setVisible(true);
	presetInteractive(customPlot);
	QCPColorMap *colorMap = new QCPColorMap(customPlot->xAxis, customPlot->yAxis);
	customPlot->addPlottable(colorMap);
	colorMap->setName("Color Map");
	customPlot->addLayer("maplayer", customPlot->layer("grid"), QCustomPlot::limBelow);
	colorMap->setLayer("maplayer");

	int nx = 400;
	int ny = 400;
	colorMap->data()->setSize(nx, ny);
	colorMap->data()->setRange(QCPRange(0, 10), QCPRange(0, 10));
	colorMap->setInterpolate(true);
	colorMap->setTightBoundary(false);
	for (int x=0; x<nx; ++x)
	{
		for (int y=0; y<ny; ++y)
		{
			colorMap->data()->setCell(x, y, qExp(-qSqrt((x-310)*(x-310)+(y-260)*(y-260))/200.0)+
				qExp(-qSqrt((x-200)*(x-200)+(y-290)*(y-290))/80.0)-qExp(-qSqrt((x-180)*(x-180)+(y-140)*(y-140))/200.0));
		}
	}

	/* manual test of coordinate to cell transformations (and vice versa):
	connect(customPlot, SIGNAL(mouseMove(QMouseEvent*)), this, SLOT(colorMapMouseMove(QMouseEvent*)));
	colorMap->data()->setRange(QCPRange(0, 1), QCPRange(0, 1));
	colorMap->data()->setSize(2,2);
	colorMap->data()->setCell(0, 0, 0);
	colorMap->data()->setCell(0, 1, 0);
	colorMap->data()->setCell(1, 0, 2);
	colorMap->data()->setCell(1, 1, 4);
	*/

	//customPlot->xAxis->setRangeReversed(true);
	//customPlot->yAxis->setRangeReversed(true);

	colorMap->setInterpolate(false);

	QCPColorScale *colorScale = new QCPColorScale(customPlot);
	customPlot->plotLayout()->addElement(0, 1, colorScale);
	colorMap->setColorScale(colorScale);
	colorScale->setLabel("test");

	QCPMarginGroup *group = new QCPMarginGroup(customPlot);
	colorScale->setMarginGroup(QCP::msTop|QCP::msBottom, group);
	customPlot->axisRect()->setMarginGroup(QCP::msTop|QCP::msBottom, group);

	QCPColorGradient gradient = colorMap->gradient();
	gradient.loadPreset(QCPColorGradient::gpJet);
	gradient.setPeriodic(false);
	colorMap->setGradient(gradient);
	colorMap->rescaleDataRange(true);

	connect(customPlot, SIGNAL(beforeReplot()), colorMap, SLOT(updateLegendIcon()));
	customPlot->rescaleAxes();
	customPlot->replot();
}
double CNormalPF::calcPotential(int nIndex, int nTick, double dOwnPosX, double dOwnPosY)
{
	CDatabase* pDatabase = CDatabase::GetInstance();

	int nNumAdjVehicles = pDatabase->GetNumAdjacentVehicles();

	double dMinDistance = DBL_MAX;
	//! For repulsive energy
	double dCoefficientG = 5.0;
	double dCoefficientO = 200.0;
	double dCorrelationG = 20.0;
	double dCorrelationO = 5.0;

	for (int n = 0; n < nNumAdjVehicles; n++)
	{
		if (n == nIndex)
			continue;

		double dPosX = pDatabase->GetData(CDatabase::SIMULATION, nTick - 1, n, PACKET_SIMUL_POSX);
		double dPosY = pDatabase->GetData(CDatabase::SIMULATION, nTick - 1, n, PACKET_SIMUL_POSY);
		double dVelX = pDatabase->GetData(CDatabase::SIMULATION, nTick - 1, n, PACKET_SIMUL_VELX);
		double dVelY = pDatabase->GetData(CDatabase::SIMULATION, nTick - 1, n, PACKET_SIMUL_VELY);
		int nLane = (dPosY - 0.5*LANE_WIDTH) / LANE_WIDTH;

		//! 周辺車両が自車より後ろにいる場合は考慮しない
		if ((dPosX - dOwnPosX) < 0.0)
			continue;

		if (dOwnPosY != dPosY)
			continue;

		double dDistance = qAbs(dPosX - dOwnPosX);

		if (dDistance < dMinDistance)
		{
			dMinDistance = dDistance;
		}
	}

	double dDistanceOfGoal = 0.0;
	double dDistanceOfObstacle = 0.0;

	if (dMinDistance == DBL_MAX)
	{
		return 0.0;
	}
	else
	{
		dDistanceOfObstacle = dMinDistance;
		dDistanceOfGoal = dDistanceOfObstacle + 10.0;
	}

	double dPotential = dCoefficientO * qExp(-dDistanceOfObstacle*dDistanceOfObstacle / (dCorrelationO*dCorrelationO))*(1 - qExp(-dDistanceOfGoal*dDistanceOfGoal / (dCorrelationG*dCorrelationG)));
	dPotential -= dCoefficientG * qExp(-dDistanceOfGoal*dDistanceOfGoal / (dCorrelationG*dCorrelationG));
	dPotential += dCoefficientG;

	return dPotential;
}
예제 #5
0
void QAGC::setAttack(float attack) {

    mutex.lock();
    m_attack = 1.0 - qExp(-1000.0 / (attack * m_samplerate));
    m_oneMAttack = qExp (-1000.0 / (attack * m_samplerate));

    m_sndex = (m_index + (int)(0.003 * m_samplerate * attack)) & m_mask;
    m_fastIndex = (m_sndex + FASTLEAD * m_mask) & m_mask;

    m_fastHangTime = 0.1f;   
    mutex.unlock();
}
예제 #6
0
/*!
  \brief Qt timer event

  The flying wheel effect is implemented using a timer

  \param event Timer event

  \sa updateInterval()
 */
void QwtWheel::timerEvent( QTimerEvent *event )
{
    if ( event->timerId() != d_data->timerId )
    {
        QWidget::timerEvent( event );
        return;
    }

    d_data->speed *= qExp( -d_data->updateInterval * 0.001 / d_data->mass );

    d_data->flyingValue += d_data->speed * d_data->updateInterval;
    d_data->flyingValue = boundedValue( d_data->flyingValue );

    double value = d_data->flyingValue;
    if ( d_data->stepAlignment )
        value = alignedValue( value );

    if ( qFabs( d_data->speed ) < 0.001 * d_data->singleStep )
    {
        // stop if d_data->speed < one step per second
        stopFlying();
    }

    if ( value != d_data->value )
    {
        d_data->value = value;
        update();

        if ( d_data->tracking || d_data->timerId == 0 )
            Q_EMIT valueChanged( d_data->value );
    }
}
예제 #7
0
GaussianFilter::GaussianFilter(double aSigma)
    : sigma(aSigma)
{
    wRadius = (uint) (sigma * 3 + 1.0);

    double * kernel = new double[wRadius + 1];

    double sum = 0.0;
    kernel[0] = 1.0;

    for (uint w = 1; w <= wRadius; ++w)
    {
        kernel[w] = qExp(- ((int) (w * w)) / (2.0 * sigma * sigma));
        sum += kernel[w];
    }

    sum = sum * 2 + 1.0;

    /* Normalization */
    kernel[0] /= sum;

    for (uint w = 1; w <= wRadius; ++w)
    {
        kernel[w] /= sum;
    }

    setColorCache(kernel);
}
예제 #8
0
QAGC::QAGC(QObject *parent, int size)
	: QObject(parent)
	, set(Settings::instance())
	, m_size(size)
	, m_mask(size * 2)
	, m_index(0)
	, m_sndex(0)
	, m_hangIndex(0)
	, m_fastIndex(FASTLEAD)
	, m_fastHang(0)
	, m_samplerate(set->getSampleRate())
	//, m_agcMode(agcMED)
	, m_gainTop(qPow(10.0f, 120.0f/20.0f))
	, m_gainNow(1.0f)
	, m_gainFastNow(1.0f)
	, m_gainBottom(.001f)
	, m_gainLimit(1.0f)
	//, m_gainFix(pow(10.0, 60.0/20.0))
	, m_gainFix(qPow(10.0f, 80.0f/20.0f))
	, m_attack(0.0f)
	, m_oneMAttack(0.0f)
	, m_decay(0.0f)
	, m_oneMDecay(0.0f)
	, m_slope(1.0f)
	, m_fastAttack(0.0f)
	, m_oneMFastAttack(0.0f)
	, m_fastDecay(0.0f)
	, m_oneMFastDecay(0.0f)
	, m_hangTime(480.0f * 0.001f)
	, m_hangThresh(0.001f)
	, m_fastHangTime(48.0f * 0.001f)
{
	setAttack(1.0);
    setDecay(1.0);
    setMode(agcMED);
    
    m_fastAttack     = 1.0 - qExp(-1000.0 / (0.2f * m_samplerate));
    m_oneMFastAttack = qExp(-1000.0 / (0.2 * m_samplerate));

    m_fastDecay     = 1.0 - qExp(-1000.0 / (3.0 * m_samplerate));
    m_oneMFastDecay = qExp(-1000.0 / (3.0 * m_samplerate));

    InitCPX(G, m_mask, 0.0f);

    m_mask -= 1;
}
예제 #9
0
void QAGC::setMode(AGCMode mode) {

    mutex.lock();
    m_agcMode = mode;
	
    switch (mode) {

        case agcOFF:
            break;

        case agcSLOW:

            m_hangTime = 0.5;
            m_fastHangTime = 0.1F;
            m_decay = 1.0 - qExp(-2.0 / m_samplerate);
            m_oneMDecay = 1.0 - m_decay;
            break;

        case agcMED:

            m_hangTime = 0.25;
            m_fastHangTime = 0.1f;
            m_decay = 1.0 - qExp(-4.0 / m_samplerate);
            m_oneMDecay = 1.0 - m_decay;
            break;

        case agcFAST:

            m_hangTime = 0.1f;
            m_fastHangTime = 0.1f;
            m_decay = 1.0 - qExp(-10.0 / m_samplerate);
            m_oneMDecay = 1.0 - m_decay;
            break;

        case agcLONG:
            m_hangTime = 0.75;
            m_fastHangTime = 0.1f;
            m_decay = 1.0 - qExp(-0.5 / m_samplerate);
            m_oneMDecay = 1.0 - m_decay;
            break;

        case agcUser:
        	break;
    }
    mutex.unlock();
}
예제 #10
0
double QwtScaleTransformation::invXForm( double p, double p1, double p2,
    double s1, double s2 ) const
{
    if ( d_type == Log10 )
        return qExp( ( p - p1 ) / ( p2 - p1 ) * log( s2 / s1 ) ) * s1;
    else
        return s1 + ( s2 - s1 ) / ( p2 - p1 ) * ( p - p1 );
}
예제 #11
0
	gh::Quaternion slerp( const Quaternion& p, const Quaternion& q, float blendFactor )
	{
		Vector3 PIm( p.x, p.y, p.z );
		Vector3 QIm( q.x, q.y, q.z );
		
		Vector4 PInv = qInverse( p );

		return qMult( p, qExp( qMult( qInverse( p ), q ), blendFactor ) );
	}
void dtkComposerNodeNumberOperatorBinaryExpn::run(void)
{
    double *lhs = d->receiver_lhs.data<double>();
    double *rhs = d->receiver_rhs.data<double>();

    d->value_r = qExp((*lhs) * qLn(*rhs));

    d->emitter.setData<double>(&d->value_r);
}
예제 #13
0
void MainWindow:: equals()
{
    sNum = value.toDouble();

    if (addBool){
        total = QString::number(fNum+sNum);
        label -> setText(total);
    }
    if (subtractBool){
        total = QString::number(fNum-sNum);
        label -> setText(total);
    }
    if (multiplyBool){
        total = QString::number(fNum*sNum);
        label -> setText(total);
    }
    if(divideBool){
        total = QString::number(fNum/sNum);
        label -> setText(total);
    }
    if(sinBool){
        total = QString::number(qSin(fNum));
        label -> setText(total);
    }
    if(cosBool){
        total = QString::number(qCos(fNum));
        label -> setText(total);
    }
    if(tanBool){
        total = QString::number(qTan(fNum));
        label -> setText(total);
    }
    if(sqrtBool){
        total = QString::number(qSqrt(fNum));
        label -> setText(total);
    }
    if(powBool){
        total = QString::number(qPow(fNum,2));
        label -> setText(total);
    }
    if(cubicBool){
        total = QString::number(qPow(fNum,3));
        label -> setText(total);
    }
    if(expBool){
        total = QString::number(qExp(fNum));
        label -> setText(total);
    }
    if(lnBool){
        total = QString::number(qLn(fNum));
        label -> setText(total);
    }

    fNum = 0;
    sNum = 0;
}
예제 #14
0
 void planner::graphInit(){
     line=0;
    // add two new graphs and set their look:
    ui->plot->addGraph();
    ui->plot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
    ui->plot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue

    ui->plot->addGraph();
    ui->plot->graph(1)->setPen(QPen(Qt::green)); // line color red for second graph

     fermatSpiral1 = new QCPCurve(ui->plot->xAxis, ui->plot->yAxis);
     ui->plot->addPlottable(fermatSpiral1);
     fermatSpiral1->setPen(QPen(Qt::red));
     fermatSpiral1->setBrush(QBrush(QColor(255, 0, 0, 20)));

     //viuslaize robot triangle instead of trajectory
     trajectoryLine = new QCPCurve(ui->plot->xAxis, ui->plot->yAxis);
     ui->plot->addPlottable(trajectoryLine);
     trajectoryLine->setPen(QPen(Qt::black));
     trajectoryLine->setBrush(QBrush(QColor(0, 0, 0, 20)));

     // generate some points of data (y0 for first, y1 for second graph):
    QVector<double> x(250), y0(250), y1(250);
    for (int i=0; i<250; ++i)
    {
      x[i] = i;
      y0[i] = qExp(-i/150.0)*qCos(i/10.0); // exponentially decaying cosine
      y1[i] = qExp(-i/150.0);              // exponential envelope
    }
    ui->plot->xAxis2->setVisible(true);
    ui->plot->xAxis2->setTickLabels(false);
    ui->plot->yAxis2->setVisible(true);
    ui->plot->yAxis2->setTickLabels(false);
    // make left and bottom axes always transfer their ranges to right and top axes:
    connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->xAxis2, SLOT(setRange(QCPRange)));
    connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->yAxis2, SLOT(setRange(QCPRange)));
    // pass data points to graphs:
    ui->plot->graph(0)->setData(x, y0);
    ui->plot->graph(1)->setData(x, y1);
    ui->plot->graph(0)->rescaleAxes();
    ui->plot->graph(1)->rescaleAxes(true);
    ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
}
예제 #15
0
Rpn::Operand ExponentialFunction::calculate(FunctionCalculator *calculator, QList<Rpn::Operand> actualArguments)
{
	Q_UNUSED(calculator);

	Rpn::Operand result;
	result.type = Rpn::OperandNumber;
	result.value = qExp(actualArguments.at(0).value.value<Number>());

	return result;
}
예제 #16
0
void ContTblPlugin::processRR(QString allele, QVector<QString> names, QVector<int> numH, QVector<int> numI)
{
    double a, b, c, d; // коэфф таблицы сопряж.

    a = 0;
    b = 0;
    c = 0;
    d = 0;

    for (int i = 0; i < names.size(); ++i)
    {
        if (allele == names[i])
        {
            a += numH[i];
            c += numI[i];
        }
        else
            {
                b += numH[i];
                d += numI[i];
            }
    }
    qDebug() << allele << ": a = " << a << "d = " << d << "b =" << b << "c = " << c;
    if (a * b * c * d == 0)
    {
        a = a + 0.5;
        b = b + 0.5;
        c = c + 0.5;
        d = d + 0.5;
    }

    RR = (double) (b * c) / (a * d); // в статье сытина ошибка

    double left, right;
    double V;

    V = 1.96 * qSqrt(1.0 / a + 1.0 / b + 1.0 / c + 1.0 / d);
    left = qExp(qLn(RR) - V); // тоже не указано в статье, но в проге почемуто делаем e^(qLn(RR) - 1.96 * qSqrt(1.0 / a + 1.0 / b + 1.0 / c + 1.0 / d))
    right = qExp(qLn(RR) + V);

    confInt = "[" + QString::number(left) + " ; " + QString::number(right) + "]";
}
예제 #17
0
void MainWindow::setupPlot()
{
  // The following plot setup is mostly taken from the plot demos:
  ui->plot->addGraph();
  ui->plot->graph()->setPen(QPen(Qt::blue));
  ui->plot->graph()->setBrush(QBrush(QColor(0, 0, 255, 20)));
  ui->plot->addGraph();
  ui->plot->graph()->setPen(QPen(Qt::red));
  QVector<double> x(500), y0(500), y1(500);
  for (int i=0; i<500; ++i)
  {
    x[i] = (i/499.0-0.5)*10;
    y0[i] = qExp(-x[i]*x[i]*0.25)*qSin(x[i]*5)*5;
    y1[i] = qExp(-x[i]*x[i]*0.25)*5;
  }
  ui->plot->graph(0)->setData(x, y0);
  ui->plot->graph(1)->setData(x, y1);
  ui->plot->axisRect()->setupFullAxesBox(true);
  ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom);
}
예제 #18
0
float Material::cookTorrance(const QVector3D &v, const QVector3D &n, const QVector3D &L, float F, float m)
{
    QVector3D vL = v + L;
    QVector3D h = vL / vL.length();
    float nh = QVector3D::dotProduct(n, h);
    float nv = QVector3D::dotProduct(n, v);
    float vh = QVector3D::dotProduct(v, h);
    float nL = QVector3D::dotProduct(n, L);
    float m2 = m * m;
    float alpha = qMin(0.999, qAcos(nh));
    float G = qMin(1.0f, qMin(2.0f * nh * nv / vh, 2.0f * nh * nL / vh));
    float D = qExp(-qPow(qTan(alpha), 2.0f) / m2) / (m2 * qPow(qCos(alpha), 4.0f));
    return qMin(24.0f, F * G * D / (4.0f * float(M_PI) * nL * nv));
}
예제 #19
0
void MainWindow::setupPlot()
{
  // The following plot setup is taken from the sine demo:
  // add two new graphs and set their look:
  ui->plot->addGraph();
  ui->plot->graph(0)->setPen(QPen(Qt::blue)); // line color blue for first graph
  ui->plot->graph(0)->setBrush(QBrush(QColor(0, 0, 255, 20))); // first graph will be filled with translucent blue
  ui->plot->addGraph();
  ui->plot->graph(1)->setPen(QPen(Qt::red)); // line color red for second graph
  // generate some points of data (y0 for first, y1 for second graph):
  QVector<double> x(250), y0(250), y1(250);
  for (int i=0; i<250; ++i)
  {
    x[i] = i;
    y0[i] = qExp(-i/150.0)*qCos(i/10.0); // exponentially decaying cosine
    y1[i] = qExp(-i/150.0); // exponential envelope
  }
  // configure right and top axis to show ticks but no labels:
  // (see QCPAxisRect::setupFullAxesBox for a quicker method to do this)
  ui->plot->xAxis2->setVisible(true);
  ui->plot->xAxis2->setTickLabels(false);
  ui->plot->yAxis2->setVisible(true);
  ui->plot->yAxis2->setTickLabels(false);
  // make left and bottom axes always transfer their ranges to right and top axes:
  connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->xAxis2, SLOT(setRange(QCPRange)));
  connect(ui->plot->yAxis, SIGNAL(rangeChanged(QCPRange)), ui->plot->yAxis2, SLOT(setRange(QCPRange)));
  // pass data points to graphs:
  ui->plot->graph(0)->setData(x, y0);
  ui->plot->graph(1)->setData(x, y1);
  // let the ranges scale themselves so graph 0 fits perfectly in the visible area:
  ui->plot->graph(0)->rescaleAxes();
  // same thing for graph 1, but only enlarge ranges (in case graph 1 is smaller than graph 0):
  ui->plot->graph(1)->rescaleAxes(true);
  // Note: we could have also just called customPlot->rescaleAxes(); instead
  // Allow user to drag axis ranges with mouse, zoom with mouse wheel and select graphs by clicking:
  ui->plot->setInteractions(QCP::iRangeDrag | QCP::iRangeZoom | QCP::iSelectPlottables);
}
예제 #20
0
파일: kmath.cpp 프로젝트: ipsusila/radenv
qreal KMath::k0(qreal x)
{
    qreal y,ans;

    if (x <= 2.0) {
        y=x*x/4.0;
        ans=(-qLn(x/2.0)*KMath::i0(x))+(-0.57721566+y*(0.42278420
        +y*(0.23069756+y*(0.3488590e-1+y*(0.262698e-2
        +y*(0.10750e-3+y*0.74e-5))))));
    } else {
        y=2.0/x;
        ans=(qExp(-x)/qSqrt(x))*(1.25331414+y*(-0.7832358e-1
        +y*(0.2189568e-1+y*(-0.1062446e-1+y*(0.587872e-2
        +y*(-0.251540e-2+y*0.53208e-3))))));
    }
    return ans;
}
예제 #21
0
파일: plotaxes.cpp 프로젝트: Sylla/updraft
qreal PlotAxes::findTickIncrement(qreal range, qreal size,
  qreal minTickSpacing) {
  qreal tmp = minTickSpacing * range / size;

  qreal logIncrement = qCeil(qLn(tmp) / LN10);
  qreal increment = qExp(logIncrement * LN10);

  qreal pxPerTick = increment * size / range;

  if (pxPerTick > 5 * minTickSpacing) {
    return increment / 5;
  } else if (pxPerTick > 2 * minTickSpacing) {
    return increment / 2;
  } else {
    return increment;
  }
}
예제 #22
0
static void logSpace( double *array, int size, double xmin, double xmax )
{
    if ( ( xmin <= 0.0 ) || ( xmax <= 0.0 ) || ( size <= 0 ) )
        return;

    const int imax = size - 1;

    array[0] = xmin;
    array[imax] = xmax;

    const double lxmin = log( xmin );
    const double lxmax = log( xmax );
    const double lstep = ( lxmax - lxmin ) / double( imax );

    for ( int i = 1; i < imax; i++ )
        array[i] = qExp( lxmin + double( i ) * lstep );
}
예제 #23
0
파일: kmath.cpp 프로젝트: ipsusila/radenv
qreal KMath::i0(qreal x)
{
    qreal ax,ans;
    qreal y;

    if ((ax=qAbs(x)) < 3.75) {
        y=x/3.75;
        y*=y;
        ans=1.0+y*(3.5156229+y*(3.0899424+y*(1.2067492
        +y*(0.2659732+y*(0.360768e-1+y*0.45813e-2)))));
    } else {
        y=3.75/ax;
        ans=(qExp(ax)/qSqrt(ax))*(0.39894228+y*(0.1328592e-1
        +y*(0.225319e-2+y*(-0.157565e-2+y*(0.916281e-2
        +y*(-0.2057706e-1+y*(0.2635537e-1+y*(-0.1647633e-1
        +y*0.392377e-2))))))));
    }
    return ans;
}
예제 #24
0
void Connections::attract() {

    //for all edges...
    #pragma omp parallel for
    for (int ie = 0; ie < edges.size(); ++ie) {
        Edge* e = edges.at(ie);
        //for every point...
        for (int i=1; i<e->points.length()-1; i++) {
            QVector3D p = e->points.at(i);
            double fsum = 0;
            QVector3D f(0,0,0);
            //for all attracting points...
            for (int ef=0; ef<edges.length(); ef++) {
                float c = comp(ie,ef);
                if (c > c_thr) {
                    QVector3D pe;
                    if (e->flip(edges.at(ef))) {
                        pe = edges.at(ef)->points.at(i);
                    } else {
                        pe = edges.at(ef)->points.at((edges.at(ef)->points.length()-1)-i);
                    }

                    float de = (pe-p).length();
                    double bell = 5;
                    double weight = qExp(-(de*de)/(2*bell*bell));
                    fsum += weight;
                    f += weight*pe;
                    QVector3D df;
                }
            }

            f /= fsum;
            QVector3D force = (f-p);
            e->forces.replace(i,force);
        }
    }
    for (int e=0; e<edges.size(); e++) {
        edges.at(e)->applyForces();
    }
}
예제 #25
0
void AttractThread::run()
{
    int numThreads = GLFunctions::idealThreadCount;

    for ( int ie = m_id; ie < m_edges.length(); ie += numThreads )
    {
        Edge* e = m_edges.at( ie );
        //for every point...
        for ( int i = 1; i < e->points.length() - 1; i++ )
        {
            QVector3D p = e->points.at( i );
            double fsum = 0;
            QVector3D f( 0, 0, 0 );
            //for all attracting points...
            for ( unsigned int ef = 0; ef < m_compatibilities->idxs->at( ie )->size(); ef++ )
            {
                QVector3D pe;
                int idx = m_compatibilities->idxs->at( ie )->at( ef );
                if ( e->flip( m_edges.at( idx ) ) )
                {
                    pe = m_edges.at( idx )->points.at( i );
                }
                else
                {
                    pe = m_edges.at( idx )->points.at( ( m_edges.at( idx )->points.length() - 1 ) - i );
                }
                float de = ( pe - p ).length();
                double weight = qExp( -( de * de ) / ( 2 * m_bell * m_bell ) );
                fsum += weight;
                f += weight * pe;
            }

            f /= fsum;
            QVector3D force = ( f - p );
            e->forces.replace( i, force );
        }
    }
}
예제 #26
0
/*!
   \brief Calculate major ticks for an interval

   \param interval Interval
   \param stepSize Step size

   \return Calculated ticks
*/
QList<double> QwtLogScaleEngine::buildMajorTicks(
    const QwtInterval &interval, double stepSize ) const
{
    double width = qwtLogInterval( base(), interval ).width();

    int numTicks = qRound( width / stepSize ) + 1;
    if ( numTicks > 10000 )
        numTicks = 10000;

    const double lxmin = ::log( interval.minValue() );
    const double lxmax = ::log( interval.maxValue() );
    const double lstep = ( lxmax - lxmin ) / double( numTicks - 1 );

    QList<double> ticks;

    ticks += interval.minValue();

    for ( int i = 1; i < numTicks - 1; i++ )
        ticks += qExp( lxmin + double( i ) * lstep );

    ticks += interval.maxValue();

    return ticks;
}
void dtkComposerNodeNumberOperatorUnaryExp::run(void)
{
    double *value = d->receiver.data<double>();
    *value = qExp(*value);
    d->emitter.setData<double>(value);
}
예제 #28
0
void dtkComposerNodeTestCase::testNumberOperatorUnary(void)
{
    double v_r = qAtan(1);

    dtkComposerNodeReal n_r;
    n_r.setValue(v_r);
    n_r.run();

    dtkComposerNodeReal n_end;

    // INCREMENT
    dtkComposerNodeNumberOperatorUnaryIncr n_incr;
    QVERIFY(n_incr.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_incr.emitters().first()));
    n_incr.run();
    n_end.run();
    QCOMPARE((v_r + 1), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_incr.emitters().first()));

    // DECREMENT
    dtkComposerNodeNumberOperatorUnaryDecr n_decr;
    QVERIFY(n_decr.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_decr.emitters().first()));
    n_decr.run();
    n_end.run();
    QCOMPARE((v_r - 1), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_decr.emitters().first()));

    // SQRT
    dtkComposerNodeNumberOperatorUnarySqrt n_sqrt;
    QVERIFY(n_sqrt.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_sqrt.emitters().first()));
    n_sqrt.run();
    n_end.run();
    QCOMPARE(qSqrt(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_sqrt.emitters().first()));

    // SQUARE
    dtkComposerNodeNumberOperatorUnarySquare n_square;
    QVERIFY(n_square.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_square.emitters().first()));
    n_square.run();
    n_end.run();
    QCOMPARE((v_r * v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_square.emitters().first()));

    // LN
    dtkComposerNodeNumberOperatorUnaryLn n_ln;
    QVERIFY(n_ln.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_ln.emitters().first()));
    n_ln.run();
    n_end.run();
    QCOMPARE(qLn(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_ln.emitters().first()));

    // LOG10
    dtkComposerNodeNumberOperatorUnaryLog10 n_log10;
    QVERIFY(n_log10.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_log10.emitters().first()));
    n_log10.run();
    n_end.run();
    QCOMPARE(qLn(v_r)/qLn(10.), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_log10.emitters().first()));

    // EXP
    dtkComposerNodeNumberOperatorUnaryExp n_exp;
    QVERIFY(n_exp.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_exp.emitters().first()));
    n_exp.run();
    n_end.run();
    QCOMPARE(qExp(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_exp.emitters().first()));

    // COS
    dtkComposerNodeNumberOperatorUnaryCos n_cos;
    QVERIFY(n_cos.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_cos.emitters().first()));
    n_cos.run();
    n_end.run();
    QCOMPARE(qCos(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_cos.emitters().first()));

    // SIN
    dtkComposerNodeNumberOperatorUnarySin n_sin;
    QVERIFY(n_sin.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_sin.emitters().first()));
    n_sin.run();
    n_end.run();
    QCOMPARE(qSin(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_sin.emitters().first()));

    // TAN
    dtkComposerNodeNumberOperatorUnaryTan n_tan;
    QVERIFY(n_tan.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_tan.emitters().first()));
    n_tan.run();
    n_end.run();
    QCOMPARE(qTan(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_tan.emitters().first()));

    // ACOS
    dtkComposerNodeNumberOperatorUnaryAcos n_acos;
    QVERIFY(n_acos.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_acos.emitters().first()));
    n_acos.run();
    n_end.run();
    QCOMPARE(qAcos(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_acos.emitters().first()));

    // ASIN
    dtkComposerNodeNumberOperatorUnaryAsin n_asin;
    QVERIFY(n_asin.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_asin.emitters().first()));
    n_asin.run();
    n_end.run();
    QCOMPARE(qAsin(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_asin.emitters().first()));

    // ATAN
    dtkComposerNodeNumberOperatorUnaryAtan n_atan;
    QVERIFY(n_atan.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_atan.emitters().first()));
    n_atan.run();
    n_end.run();
    QCOMPARE(qAtan(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_atan.emitters().first()));

    // DEG2RAD
    dtkComposerNodeNumberOperatorUnaryDeg2Rad n_d2r;
    QVERIFY(n_d2r.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_d2r.emitters().first()));
    n_d2r.run();
    n_end.run();
    QCOMPARE((v_r * M_PI / 180.), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_d2r.emitters().first()));

    // RAD2DEG
    dtkComposerNodeNumberOperatorUnaryRad2Deg n_r2d;
    QVERIFY(n_r2d.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_r2d.emitters().first()));
    n_r2d.run();
    n_end.run();
    QCOMPARE((v_r / M_PI * 180.), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_r2d.emitters().first()));

    // INVERSE
    dtkComposerNodeNumberOperatorUnaryInv n_inv;
    QVERIFY(n_inv.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_inv.emitters().first()));
    n_inv.run();
    n_end.run();
    QCOMPARE((1. / v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_inv.emitters().first()));

    // OPPOSITE
    dtkComposerNodeNumberOperatorUnaryOpp n_opp;
    QVERIFY(n_opp.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_opp.emitters().first()));
    n_opp.run();
    n_end.run();
    QCOMPARE((-v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_opp.emitters().first()));

    // ABS
    dtkComposerNodeNumberOperatorUnaryAbs n_abs;
    QVERIFY(n_abs.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_end.receivers().first()->connect(n_abs.emitters().first()));
    n_abs.run();
    n_end.run();
    QCOMPARE(qAbs(v_r), n_end.value());
    QVERIFY(n_end.receivers().first()->disconnect(n_abs.emitters().first()));

    dtkComposerNodeInteger n_iend;

    // CEIL
    dtkComposerNodeNumberOperatorUnaryCeil n_ceil;
    QVERIFY(n_ceil.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_iend.receivers().first()->connect(n_ceil.emitters().first()));
    n_ceil.run();
    n_iend.run();
    QCOMPARE(qCeil(v_r), static_cast<int>(n_iend.value()));
    QVERIFY(n_iend.receivers().first()->disconnect(n_ceil.emitters().first()));

    // FLOOR
    dtkComposerNodeNumberOperatorUnaryFloor n_floor;
    QVERIFY(n_floor.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_iend.receivers().first()->connect(n_floor.emitters().first()));
    n_floor.run();
    n_iend.run();
    QCOMPARE(qFloor(v_r), static_cast<int>(n_iend.value()));
    QVERIFY(n_iend.receivers().first()->disconnect(n_floor.emitters().first()));

    // ROUND
    dtkComposerNodeNumberOperatorUnaryRound n_round;
    QVERIFY(n_round.receivers().first()->connect(n_r.emitters().first()));
    QVERIFY(n_iend.receivers().first()->connect(n_round.emitters().first()));
    n_round.run();
    n_iend.run();
    QCOMPARE(qRound(v_r), static_cast<int>(n_iend.value()));
    QVERIFY(n_iend.receivers().first()->disconnect(n_round.emitters().first()));
    
}
예제 #29
0
파일: recuit.cpp 프로젝트: floosh/Agences
bool Recuit::pass(double temp, double delta)
{
    double r = (qrand()%100)/100.0;
    return (r < qExp(-delta/temp));
}
예제 #30
0
void DistortionFXFilter::cilindricalMultithreaded(const Args& prm)
{
    int Width       = prm.orgImage->width();
    int Height      = prm.orgImage->height();
    uchar* data     = prm.orgImage->bits();
    bool sixteenBit = prm.orgImage->sixteenBit();
    int bytesDepth  = prm.orgImage->bytesDepth();
    uchar* pResBits = prm.destImage->bits();

    double nh, nw;

    int    nHalfW      = Width / 2;
    int    nHalfH      = Height / 2;
    double lfCoeffX    = 1.0;
    double lfCoeffY    = 1.0;
    double lfCoeffStep = prm.Coeff / 1000.0;

    if (prm.Horizontal)
    {
        lfCoeffX = (double)nHalfW / qLn(qFabs(lfCoeffStep) * nHalfW + 1.0);
    }

    if (prm.Vertical)
    {
        lfCoeffY = (double)nHalfH / qLn(qFabs(lfCoeffStep) * nHalfH + 1.0);
    }

    for (int w = prm.start; runningFlag() && (w < prm.stop); ++w)
    {
        // we find the distance from the center
        nh = qFabs((double)(prm.h - nHalfH));
        nw = qFabs((double)(w - nHalfW));

        if (prm.Horizontal)
        {
            if (prm.Coeff > 0.0)
            {
                nw = (qExp(nw / lfCoeffX) - 1.0) / lfCoeffStep;
            }
            else
            {
                nw = lfCoeffX * qLn(1.0 + (-1.0 * lfCoeffStep) * nw);
            }
        }

        if (prm.Vertical)
        {
            if (prm.Coeff > 0.0)
            {
                nh = (qExp(nh / lfCoeffY) - 1.0) / lfCoeffStep;
            }
            else
            {
                nh = lfCoeffY * qLn(1.0 + (-1.0 * lfCoeffStep) * nh);
            }
        }

        nw = (double)nHalfW + ((w >= nHalfW)     ? nw : -nw);
        nh = (double)nHalfH + ((prm.h >= nHalfH) ? nh : -nh);

        setPixelFromOther(Width, Height, sixteenBit, bytesDepth, data, pResBits, w, prm.h, nw, nh, prm.AntiAlias);
    }
}