Esempio n. 1
0
// TODO: second plane
void SliceAdjustmentTool::toolMouseReleaseEvent(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->ctrlDown){
        if(this->rotatingInProgress){
            this->rotatingInProgress = false;
            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 is 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 is 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);
            }
            rotateSlice(this->slice, this->slice->normal(), ((angle)/3.1415f) * 180 * sign);
        }
    }
}
Esempio n. 2
0
static bool addCircle(const QBezier *b, qreal offset, QBezier *o)
{
    QPointF normals[3];

    normals[0] = QPointF(b->y2 - b->y1, b->x1 - b->x2);
    qreal dist = qSqrt(normals[0].x()*normals[0].x() + normals[0].y()*normals[0].y());
    if (qFuzzyIsNull(dist))
        return false;
    normals[0] /= dist;
    normals[2] = QPointF(b->y4 - b->y3, b->x3 - b->x4);
    dist = qSqrt(normals[2].x()*normals[2].x() + normals[2].y()*normals[2].y());
    if (qFuzzyIsNull(dist))
        return false;
    normals[2] /= dist;

    normals[1] = QPointF(b->x1 - b->x2 - b->x3 + b->x4, b->y1 - b->y2 - b->y3 + b->y4);
    normals[1] /= -1*qSqrt(normals[1].x()*normals[1].x() + normals[1].y()*normals[1].y());

    qreal angles[2];
    qreal sign = 1.;
    for (int i = 0; i < 2; ++i) {
        qreal cos_a = normals[i].x()*normals[i+1].x() + normals[i].y()*normals[i+1].y();
        if (cos_a > 1.)
            cos_a = 1.;
        if (cos_a < -1.)
            cos_a = -1;
        angles[i] = qAcos(cos_a)/Q_PI;
    }

    if (angles[0] + angles[1] > 1.) {
        // more than 180 degrees
        normals[1] = -normals[1];
        angles[0] = 1. - angles[0];
        angles[1] = 1. - angles[1];
        sign = -1.;

    }

    QPointF circle[3];
    circle[0] = QPointF(b->x1, b->y1) + normals[0]*offset;
    circle[1] = QPointF(qreal(0.5)*(b->x1 + b->x4), qreal(0.5)*(b->y1 + b->y4)) + normals[1]*offset;
    circle[2] = QPointF(b->x4, b->y4) + normals[2]*offset;

    for (int i = 0; i < 2; ++i) {
        qreal kappa = qreal(2.0) * KAPPA * sign * offset * angles[i];

        o->x1 = circle[i].x();
        o->y1 = circle[i].y();
        o->x2 = circle[i].x() - normals[i].y()*kappa;
        o->y2 = circle[i].y() + normals[i].x()*kappa;
        o->x3 = circle[i+1].x() + normals[i+1].y()*kappa;
        o->y3 = circle[i+1].y() - normals[i+1].x()*kappa;
        o->x4 = circle[i+1].x();
        o->y4 = circle[i+1].y();

        ++o;
    }
    return true;
}
Esempio n. 3
0
void KinematicPoints::SetS4C4()
{
    s[4] = s234 * c23 - c234 * s23;
    c[4] = c234*c23 + s234*s23;
    fi[4] = qFabs(c[4])>qFabs(s[4])? qAsin(s[4]) : qAcos(c[4]);
    //if(fi[4]!=fi[4]) {emit outOfRange(); return;}

}
Esempio n. 4
0
double
angle(const QVector2D& norm) {
     qreal result = qAcos(norm.x());
     if (norm.y() > 0)
         result = 2 * M_PI - result;

     return result / M_PI * 180.0;
}
Esempio n. 5
0
void KinematicPoints::SetS5C5()
{
    s[5] = ctheta * (spsi * c[1] - cpsi * s[1]);
    c[5] = delta5 * qSqrt(1 - qPow(s[5], 2));
    fi[5] = qFabs(c[5])>qFabs(s[5])? qAsin(s[5]) : qAcos(c[5]);
    //if(fi[5]!=fi[5]) {emit outOfRange(); return;}

}
Esempio n. 6
0
Rpn::Operand Arccosine::calculate(FunctionCalculator *calculator, QList<Rpn::Operand> actualArguments)
{
	Q_UNUSED(calculator);

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

	return result;
}
Esempio n. 7
0
void KinematicPoints::SetS3C3()
{
    double zr = regionalPoint.z();

   s[3] = 1/l[3] * ( zr*c[2] - a*s[2] );
   c[3] = 1/l[3]* (a*c[2]+zr*s[2] - l[2]) ;
   fi[3] = qFabs(c[3])>qFabs(s[3])? qAsin(s[3]) : qAcos(c[3]);

   //if(fi[3]!=fi[3]) {emit outOfRange(); return;}

}
Esempio n. 8
0
void KinematicPoints::SetS2C2()
{
    double zr = regionalPoint.z();

    s[2] = 1/(qPow(a, 2) + qPow(zr,2)) * (zr * b + delta2 * a * qSqrt(qPow(a, 2) + qPow(zr,2) - qPow(b,2)));
    c[2] = 1/(qPow(a, 2) + qPow(zr,2)) * (a * b - delta2 * zr * qSqrt(qPow(a, 2) + qPow(zr,2) - qPow(b,2)) );
    fi[2] = qFabs(c[2])>qFabs(s[2])? qAsin(s[2]) : qAcos(c[2]);

    //if(fi[2]!=fi[2]) {emit outOfRange(); return;}

}
Esempio n. 9
0
void ArrowItem::updateHeadGeometry(GraphicsHeadItem **headItem, const QPointF &pos, const QPointF &otherPos)
{
    if (!*headItem)
        return;

    (*headItem)->setPos(pos);

    QVector2D directionVector(pos - otherPos);
    directionVector.normalize();
    double angle = qAcos(directionVector.x()) * 180.0 / 3.1415926535;
    if (directionVector.y() > 0.0)
        angle = -angle;
    (*headItem)->setRotation(-angle);
}
Esempio n. 10
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));
}
Esempio n. 11
0
void GLGameModel::pointInDirection(QVector3D d)
{
    if(d.isNull())
    {
        setAngleY(0.0);
        return;
    }

    // roate the object to point in direction
    // we only rotate in the x-z plane
    float cos_y = d.normalized().z();
    setAngleY(360.0 * qAcos(cos_y) / (2*M_PI));

    //qDebug() << "pointing to" << d << "with angles" << angleX << angleY << angleZ;
}
Esempio n. 12
0
void PlotKnotPithProfile::update( const KnotPithProfile & histogram )
{
	QVector<QwtIntervalSample> datasHistogram(0);
	if ( histogram.size() > 0 )
	{
		datasHistogram.reserve(histogram.size());
		int i=0;
		QVector<qreal>::ConstIterator begin = histogram.begin();
		const QVector<qreal>::ConstIterator end = histogram.end();
		while ( begin != end )
		{
			datasHistogram.append(QwtIntervalSample(qAcos(*begin++)*RAD_TO_DEG_FACT,i,i+1));
			++i;
		}
	}
	_histogramData.setSamples(datasHistogram);
}
/*!
 * \brief RectifyToVector::setUpResult
 * \param plane
 * \return
 */
bool RectifyToVector::setUpResult(Plane &plane){

    //get and check point
    if(!this->inputElements.contains(0) || this->inputElements[0].size() != 1){
        return false;
    }
    QPointer<Geometry> geometry = this->inputElements[0].at(0).geometry;
    if(geometry.isNull() || !geometry->getIsSolved() || !geometry->hasDirection()){
        return false;
    }

    //get the sense (positive or negative)
    double sense = 1.0;
    if(this->scalarInputParams.stringParameter.contains("sense")){
        if(this->scalarInputParams.stringParameter.value("sense").compare("negative") == 0){
            sense = -1.0;
        }
    }

    //get the direction to compare
    OiVec r_reference = geometry->getDirection().getVector();
    r_reference.normalize();
    OiVec r_plane = plane.getDirection().getVector();
    r_plane.normalize();

    //calculate the angle between both directions
    double angle = 0.0;
    OiVec::dot(angle, r_reference, r_plane);
    angle = qAbs(qAcos(angle));

    //invert the normal vector if the angle is greater than 90°
    if(angle > PI/2.0){
        r_plane = -1.0 * r_plane;
    }

    //invert the normal vector if sense is negative
    r_plane = sense * r_plane;

    //set result
    Direction direction = plane.getDirection();
    direction.setVector(r_plane);
    plane.setPlane(plane.getPosition(), direction);

    return true;

}
Esempio n. 14
0
void KinematicPoints::CalculateMachineCoordinates(QVector3D toolPoint)
{
    SetToolPoint(toolPoint);
    SetTransitionalPoint();
    SetS1C1();
    SetS5C5();
    SetS234C234();
    SetRegionalPoint();
    SetAB();
    SetS2C2();
    SetS3C3();
    SetS23C23();
    SetS4C4();
    SetJointPoints();
    SetCalculatedJointPoints();

   static bool ok = true;
   for(int i=0; i<5; ++i)
   {
      fi[i] = c[i]>s[i]? qAsin(s[i]) : qAcos(c[i]);
      if(fi[i]!=fi[i])
      {
         if(ok)
         {
             ok = false;
             emit outOfRange();
             return;
         }

        else
         {
             ok = true;
             return;
         }
        }
   }

    if(lastValidPoint != toolPoint)
        emit statusOK();

    lastValidPoint = toolPoint;

}
Esempio n. 15
0
void Window::mouseMoveEvent(QMouseEvent* event) {
	if (m_mouse_draging) {
		//Transform mouse coordinates from pixels to world units
		QVector2D mouse_current_in_pixels = QVector2D(event->pos());
		QVector2D window_center = 0.5f * QVector2D(size().width(), size().height());
		QVector2D scale_factors = QVector2D(2.0f / size().width(), -2.0f / size().height());
		QVector2D mouse_current = scale_factors * (mouse_current_in_pixels - window_center);
		QVector2D mouse_start = scale_factors * (m_mouse_start_drag - window_center);
		//Now we have mouse_current and mouse_start in world coordinates
		//Use the algorithm 
		QVector3D v_1 = QVector3D(mouse_current, projection_on_curve(mouse_current));
		QVector3D v_2 = QVector3D(mouse_start, projection_on_curve(mouse_start));
		v_1.normalize();
		v_2.normalize();
		QVector3D axis = QVector3D::crossProduct(v_1, v_2);
		float angle = qAcos(QVector3D::dotProduct(v_1, v_2));
		m_new_rotation = QQuaternion::fromAxisAndAngle(axis, qRadiansToDegrees(angle));
		m_new_rotation.normalize();
	}
}
Esempio n. 16
0
/*!
    Interpolates along the shortest spherical path between the
    rotational positions \a q1 and \a q2.  The value \a t should
    be between 0 and 1, indicating the spherical distance to travel
    between \a q1 and \a q2.

    If \a t is less than or equal to 0, then \a q1 will be returned.
    If \a t is greater than or equal to 1, then \a q2 will be returned.

    \sa nlerp()
*/
QQuaternion QQuaternion::slerp
    (const QQuaternion& q1, const QQuaternion& q2, qreal t)
{
    // Handle the easy cases first.
    if (t <= 0.0f)
        return q1;
    else if (t >= 1.0f)
        return q2;

    // Determine the angle between the two quaternions.
    QQuaternion q2b;
    qreal dot;
    dot = q1.xp * q2.xp + q1.yp * q2.yp + q1.zp * q2.zp + q1.wp * q2.wp;
    if (dot >= 0.0f) {
        q2b = q2;
    } else {
        q2b = -q2;
        dot = -dot;
    }

    // Get the scale factors.  If they are too small,
    // then revert to simple linear interpolation.
    qreal factor1 = 1.0f - t;
    qreal factor2 = t;
    if ((1.0f - dot) > 0.0000001) {
        qreal angle = qreal(qAcos(dot));
        qreal sinOfAngle = qreal(qSin(angle));
        if (sinOfAngle > 0.0000001) {
            factor1 = qreal(qSin((1.0f - t) * angle)) / sinOfAngle;
            factor2 = qreal(qSin(t * angle)) / sinOfAngle;
        }
    }

    // Construct the result quaternion.
    return q1 * factor1 + q2b * factor2;
}
Esempio n. 17
0
bool GLWidget::isHorizontalSegment(const QPointF &p1, const QPointF &p2)
{
    // Punkt, der auf der Waagrechten von Punkt p1 liegt.
    const QPointF pHorizontal = QPointF(p1.x() + 10, p1.y());

    // Repräsentiert ein horizontales Segment vom Punkt p1
    const QPointF lineSegHorizontal = QPointF(pHorizontal.x() - p1.x(),
                                              pHorizontal.y() - p1.y());

    const QPointF p2p1 = QPointF(p2.x() - p1.x(),
                                 p2.y() - p1.y());

    const double scalarProduct = getScalarProduct(lineSegHorizontal, p2p1);

    const double magnitudeSeg1 = qSqrt(lineSegHorizontal.x() * lineSegHorizontal.x() +
                                       lineSegHorizontal.y() * lineSegHorizontal.y());

    const double magnitudeSeg2 = qSqrt(p2p1.x() * p2p1.x() + p2p1.y() * p2p1.y());

    const double degree = qAcos( scalarProduct / (magnitudeSeg1 * magnitudeSeg2) ) *
                          180 / M_PI;

    return degree < 45 || degree > 135;
}
Esempio n. 18
0
void QQHuntPixmapItem::animate()
{
	m_animation->clear();
	m_listPixmapProp.clear();
	int timeMs = QuteTools::randInt(MIN_DURATION, MAX_DURATION);

	//Recuperation des bornes
	QRectF sceneRect = scene()->sceneRect();
	float maxX = sceneRect.width() - boundingRect().width();
	float maxY = sceneRect.height() - boundingRect().height();

	//Et du point initial
	QPointF curPos = pos();

	//Calcul du nouveau vecteur vitesse
	float angle = (((float) qrand()) / INT_MAX) * M_PI_2;
	angle -= M_PI_4;

	QQMatrix2x2 rotMatrix;
	rotMatrix(0, 0) = qCos(angle);
	rotMatrix(0, 1) = qSin(angle);
	rotMatrix(1, 0) = 0.0 - rotMatrix(0,1);
	rotMatrix(1, 1) = rotMatrix(0,0);

	m_speedVec = rotMatrix * m_speedVec;

	//Decoupage du temps d'animation en tranche selon les rencontres avec les bords.
	while(timeMs > 0)
	{
		QPropertyAnimation *pAnimation = new QPropertyAnimation(this, "pos");
		pAnimation->setStartValue(curPos);
		connect(pAnimation, SIGNAL(finished()), this, SLOT(loadNextPixMap()));

		float angle = qAcos(m_speedVec(X_VALUE)); // 0 <= angle <= Pi
		QQPixmapProp pixmapProp = animPixmapProp(angle);
		m_listPixmapProp.append(pixmapProp);

		QQMatrix1x2 resSpeedVec = m_speedVec * ((float) SPEED_FACTOR)
											 * (timeMs / (float) (MAX_DURATION - MIN_DURATION));
		float destPosX = curPos.x() + resSpeedVec(X_VALUE);
		float destPosY = curPos.y() + resSpeedVec(Y_VALUE);

		float xFactor = 1;
		if(destPosX < 0)
			xFactor = (0.0 - curPos.x() / (destPosX - curPos.x()));
		else if(destPosX > maxX)
			xFactor = (maxX - curPos.x()) / (destPosX - curPos.x());

		float yFactor = 1;
		if(destPosY < 0)
			yFactor = (0.0 - curPos.y() / (destPosY - curPos.y()));
		else if(destPosY > maxY)
			yFactor = (maxY - curPos.y()) / (destPosY - curPos.y());

		//qDebug() << "xFactor" << xFactor << "yFactor" << yFactor;
		//Collision de bord detectee
		if(xFactor < 1 || yFactor < 1)
		{
			float realtime = 0;
			if(xFactor <= yFactor) // on touche gauche/droite avant haut/bas
			{
				realtime = timeMs * xFactor;
				curPos = QPointF(curPos.x() + (destPosX - curPos.x()) * xFactor,
								 curPos.y() + (destPosY - curPos.y()) * xFactor);

				m_speedVec(X_VALUE) = 0.0 - m_speedVec(X_VALUE);
				if(xFactor == yFactor)
					m_speedVec(Y_VALUE) = 0.0 - m_speedVec(Y_VALUE);
			}
			else if(xFactor > yFactor) // on touche haut/bas avant gauche/droite
			{
				realtime = timeMs * yFactor;
				curPos = QPointF(curPos.x() + (destPosX - curPos.x()) * yFactor,
								 curPos.y() + (destPosY - curPos.y()) * yFactor);

				m_speedVec(Y_VALUE) = 0.0 - m_speedVec(Y_VALUE);
			}

			pAnimation->setDuration(realtime);
			timeMs -= realtime;
			pAnimation->setEndValue(curPos);
		}
		else
		{
			pAnimation->setDuration(timeMs);
			timeMs = 0;
			pAnimation->setEndValue(QPointF(destPosX, destPosY));
		}
		m_animation->addAnimation(pAnimation);
	}
	loadNextPixMap();
	m_animation->start(QAbstractAnimation::KeepWhenStopped);
}
Esempio n. 19
0
void MainWindow::on_spButton_clicked()
{
    if (thereIsPlate==false){
        QMessageBox::information(this, "There is no plate to speckle", "Please draw the plate first");
        return;
    }
    on_cleanButton_clicked();
    readRadii();
    float randNum;
    float resultNum;
    float X, Y;
    randomsL.clear();randomsW.clear();
    for (int i=0; i< speckCount; i++){
        randNum=qrand();resultNum=randNum/RAND_MAX;
        randomsL.append(resultNum);
    }
    for (int i=0; i<speckCount; i++){
        randNum=qrand();resultNum=randNum/RAND_MAX;
        randomsW.append(resultNum);
    }
    //Adding circular speckles to the plate
    if(specksElliptic==false){
        for (int i=0; i<speckCount;i++){
            //Keeping the ellipses within the plate
            if(randomsL[i]*pLength-speckDiam < 0){
                X=randomsL[i]*pLength;
            }
            else{
                X=randomsL[i]*pLength-speckDiam;
            }
            if(randomsW[i]*pWidth-speckDiam < 0){
                Y=randomsW[i]*pWidth;
            }
            else{
                Y=randomsW[i]*pWidth-speckDiam;
            }
            speckList.append(scene->addEllipse(X, Y, speckDiam, speckDiam,
                        QPen(), redBrush));
        }
    }
    //Adding elliptic speckles to the plate
    if(specksElliptic==true){
        for (int i=0; i<speckCount;i++){
            //Keeping the ellipses within the plate
            //Major axis in horizontal direction case
            if(dia->directionCount>1){
                QMessageBox::information(this, "You checked more than one speckle direction options", "Please select only one speckle direction option");
                return;
            }
            if(dia->majorAxisHorizontal==true){
                if(randomsL[i]*pLength-2*majorRadius < 0){
                    X=randomsL[i]*pLength;
                }
                else{
                    X=randomsL[i]*pLength-2*majorRadius;//most of the time this is used
                }
                if(randomsW[i]*pWidth-2*minorRadius < 0){
                    Y=randomsW[i]*pWidth;
                }
                else{
                    Y=randomsW[i]*pWidth-2*minorRadius;
                }
                speckList.append(scene->addEllipse(X, Y, 2*majorRadius, 2*minorRadius,
                            QPen(), redBrush));
            }
            //Major axis invertical diection case
            else if(dia->majorAxisVertical==true){
                if(randomsL[i]*pLength-2*minorRadius < 0){
                    X=randomsL[i]*pLength;
                }
                else{
                    X=randomsL[i]*pLength-2*minorRadius;//most of the time this is used
                }
                if(randomsW[i]*pWidth-2*majorRadius < 0){
                    Y=randomsW[i]*pWidth;
                }
                else{
                    Y=randomsW[i]*pWidth-2*majorRadius;
                }
                speckList.append(scene->addEllipse(/*randomsL[i]*pLength-speckDiam*/X, /*randomsW[i]*pWidth-speckDiam*/Y, 2*minorRadius, 2*majorRadius,
                            QPen(), redBrush));
            }
            //Major axis random case
            else if(dia->majorAxisRandom==true){
                float x1, y1, x2, y2, x3, y3, x4, y4, xC, yC;
                float x1Local, y1Local, x2Local, y2Local, x3Local, y3Local, x4Local, y4Local;
                float xR1, yR1, xR2, yR2, xR3, yR3, xR4, yR4;
                if(randomsL[i]*pLength-2*majorRadius < 0){
                    X=randomsL[i]*pLength;
                }
                else{
                    X=randomsL[i]*pLength-2*majorRadius;//most of the time this is used
                }
                if(randomsW[i]*pWidth-2*minorRadius < 0){
                    Y=randomsW[i]*pWidth;
                }
                else{
                    Y=randomsW[i]*pWidth-2*minorRadius;
                }
                //Make sure that speckles stay within the plate
                qreal Pi=qAcos(-1);
                qreal tetaRad,tetaDeg;
                tetaRad=0.5*Pi*pow(-1.0,i)*randomsL[i];
                tetaDeg=180*tetaRad/Pi;
                x1=X;
                y1=Y;
                x2=X+2*majorRadius;
                y2=Y;
                x3=X;
                y3=Y+2*minorRadius;
                x4=X+2*majorRadius;
                y4=Y+2*minorRadius;;
                xC=X+majorRadius;
                yC=Y+minorRadius;
                x1Local=x1-xC; y1Local=yC-y1;
                x2Local=x2-xC; y2Local=yC-y2;
                x3Local=x3-xC; y3Local=yC-y3;
                x4Local=x4-xC; y4Local=yC-y4;
                qDebug()<<"xC="<<xC<<" yC="<<yC;
                xR1=(qCos(tetaRad)*x1Local-qSin(tetaRad)*y1Local)+xC;
                yR1=(qSin(tetaRad)*x1Local+qCos(tetaRad)*y1Local)+yC;
                xR2=(qCos(tetaRad)*x2Local-qSin(tetaRad)*y2Local)+xC;
                yR2=(qSin(tetaRad)*x2Local+qCos(tetaRad)*y2Local)+yC;
                xR3=(qCos(tetaRad)*x3Local-qSin(tetaRad)*y3Local)+xC;
                yR3=(qSin(tetaRad)*x3Local+qCos(tetaRad)*y3Local)+yC;
                xR4=(qCos(tetaRad)*x4Local-qSin(tetaRad)*y4Local)+xC;
                yR4=(qSin(tetaRad)*x4Local+qCos(tetaRad)*y4Local)+yC;
                QList<float> xCoordsAfterRot;QList<float> yCoordsAfterRot;
                xCoordsAfterRot.append(xR1);xCoordsAfterRot.append(xR2);
                xCoordsAfterRot.append(xR3);xCoordsAfterRot.append(xR4);
                yCoordsAfterRot.append(yR1);yCoordsAfterRot.append(yR2);
                yCoordsAfterRot.append(yR3);yCoordsAfterRot.append(yR4);
                float maxX, maxY, minX, minY;
                minX=xCoordsAfterRot[0]; minY=yCoordsAfterRot[0];
                maxX=xCoordsAfterRot[0]; maxY=yCoordsAfterRot[0];
                for(int k=1; k<4 ; k++){
                    if(xCoordsAfterRot[k]<xCoordsAfterRot[k-1]){
                        minX=xCoordsAfterRot[k];
                    }
                    if(xCoordsAfterRot[k]>xCoordsAfterRot[k-1]){
                        maxX=xCoordsAfterRot[k];
                    }
                    if(yCoordsAfterRot[k]<yCoordsAfterRot[k-1]){
                        minY=yCoordsAfterRot[k];
                    }
                    if(yCoordsAfterRot[k]>yCoordsAfterRot[k-1]){
                        maxY=yCoordsAfterRot[k];
                    }
                }
                float xDist, yDist;
                if (minX <0){
                    //shift x coordinates of the speckle to the right xDist kadar
                    xDist=qAbs(minX-0);
                    X=X+xDist;
                }
                if (minY<0){
                    //shift y coordinates down yDist kadar
                    yDist=qAbs(minY-0);
                    Y=Y+yDist;
                }
                if (maxX > pLength){
                    //shift x coordinates of the speckle to the left xDist kadar
                    xDist=qAbs(maxX-pLength);
                    //X=X-xDist;
                }
                if ((maxY+minorRadius)>pWidth){
                    //shift y coordinates up yDist kadar
                    yDist=qAbs(maxY-pWidth);
                    Y=Y-minorRadius-yDist;
                }
                //ellipseBoundryRect=new QGraphicsRectItem()
                speckList.append(scene->addEllipse(X, Y, 2*majorRadius, 2*minorRadius,
                            QPen(), redBrush));
                speckList[i]->setTransformOriginPoint(speckList[i]->boundingRect().center());
                speckList[i]->setRotation(-tetaDeg);
                //-----------------------------------------------
                qDebug()<<"max X="<<maxX;
                qDebug()<<"max Y="<<maxY;
                //qDebug()<<"Corners of the speckle:";
                //qDebug()<<"X1: "<<xR1<<"Y1: "<<yR1;
                //qDebug()<<"X2: "<<xR2<<"Y2: "<<yR2;
                //qDebug()<<"X3: "<<xR3<<"Y3: "<<yR3;
                //qDebug()<<"X4: "<<xR4<<"Y4: "<<yR4;
                xCoordsAfterRot.clear();yCoordsAfterRot.clear();
            }
        }
    }
    speckList.clear();
    qDebug()<<"The number of speckles: "<<speckCount;
    speckCountStr=QString::number(speckCount);
    ui->sCountEdit->setText(speckCountStr);
    //qDebug()<<"The width of the graphicsView is: "<<screenWidth;
    //qDebug()<<"The height of the graphicsView is: "<<screenHeight;
}
void dtkComposerNodeNumberOperatorUnaryAcos::run(void)
{
    double *value = d->receiver.data<double>();
    *value = qAcos(*value);
    d->emitter.setData<double>(value);
}
Esempio n. 21
0
// Member function: calculate
//  This is excluded from the constructor to enable display of progress during calculation
void AstroData::calculate (const QString &AlgorithmIn)
{
    //   Preliminaries
    Algorithm = AlgorithmIn;
    DataDescription["Algorithm"] = QStringList(AlgorithmIn);
    toSiUnits();


    //   Iqbal1983
    if (Algorithm == "Iqbal1983")
    {
        //     Initialisation
        addParameter("SolarZenithAngle");
        addParameter("EarthSunDistance");
        addParameter("DirectExtraTerrestrial");
        addParameter("SwdExtraTerrestrial");
        setDefaultOrder();

        //     Perform calculation
        for (qint32 i = 0; i<size(); i++)
        {
            //       Day number of the year (Chapter 1.2, p. 3)
            qreal dn = DateTime.at(i).date().dayOfYear();
            //       Day angle in radiants (1.2.2)
            qreal Gamma = 2 * M_PI * (dn - 1) / 365;
            //       Eccentricity correction factor of the earth's orbit (Eq. 1.2.1)
            qreal E0 = 1.00011 + 0.034221 * qCos(Gamma) \
                               + 0.001280 * qSin(Gamma) \
                               + 0.000719 * qCos(2*Gamma) \
                               + 0.000077 * qSin(2*Gamma);
            //       Mean sun-earth distance in m (Chapter 1.2, p. 2)
            qreal r0 = 1.496e11;
            //       Sun-earth distance in m (Eq. 1.2.1)
            qreal r = r0 / qSqrt(E0);
            //       Solar declination in degrees (Eq. 1.3.1)
            qreal Delta = (0.006918 - 0.399912 * qCos(Gamma) \
                                    + 0.070257 * qSin(Gamma) \
                                    - 0.006758 * qCos(2*Gamma) \
                                    + 0.000907 * qSin(2*Gamma) \
                                    - 0.002697 * qCos(3*Gamma) \
                                    + 0.001480 * qSin(3*Gamma)) * 180 / M_PI;
            //       Equation of Time in minutes (Eq. 1.4.1)
            qreal Et = (0.000075 + 0.001868 * qCos(Gamma) \
                                 - 0.032077 * qSin(Gamma) \
                                 - 0.014615 * qCos(2*Gamma) \
                                 - 0.04089  * qSin(2*Gamma)) * 229.18;
            //       Local apparent time / true solar time in minutes (Chapter 1.4, pp. 11, 13)
            qreal UTC = - DateTime[i].time().secsTo(QTime::fromString("00:00:00")) / 60;
            qreal LAT = UTC + 4 * Longitude + Et;
            //       Hour angle in degrees (Chapter 1.5, pp. 15, 28)
            qreal Omega = (12 - LAT/60) * 15;
            //       Geographic latitude in degrees (Chapter 1.5, p. 15)
            qreal Phi = Latitude;
            //       Zenith angle in degrees (Eq. 1.5.1)
            qreal ThetaZ = qAcos(qSin(Delta/180*M_PI) * qSin(Phi/180*M_PI) + \
                                 qCos(Delta/180*M_PI) * qCos(Phi/180*M_PI) * qCos(Omega/180*M_PI)) * 180 / M_PI;
            //       Solar constant in W/m^2 (Chapter 3.4, p. 53)
            qreal ISC = 1367;
            //       Extraterrestrial Irradiance in W/m^2 (Eq. 4.2.1)
            qreal I0n = ISC * E0;
            //       Irradiance on a horizontal surface in W/m^2 (Eq. 4.2.2)
            qreal I0 = I0n * qMax(qCos(ThetaZ/180*M_PI), 0.0);

            //     Set AstroData variables
            Values["SolarZenithAngle"][i] = ThetaZ;
            Values["EarthSunDistance"][i] = r;
            Values["DirectExtraTerrestrial"][i] = I0n;
            Values["SwdExtraTerrestrial"][i] = I0;
            SolarConstant = ISC;

            emit lineProcessed(i + 1);
        }
        DataDescription["Solar constant"] = QStringList(QString::number(SolarConstant) + " W/m**2");
    }


    //   Solpos
    if (Algorithm.startsWith("Solpos"))
    {
        //     Initialisation
        addParameter("SolarZenithAngle");
        addParameter("EarthSunDistance");
        addParameter("DirectExtraTerrestrial");
        addParameter("SwdExtraTerrestrial");
        setDefaultOrder();

        //     Perform calculation
        posdata * PosData = new posdata;
        S_init(PosData);
        for (qint32 i = 0; i<size(); ++i)
        {
            //       Define input for solpos
            PosData->year          = DateTime[i].date().year();
            PosData->daynum        = DateTime[i].date().dayOfYear();
            PosData->hour          = DateTime[i].time().hour();
            PosData->minute        = DateTime[i].time().minute();
            PosData->second        = DateTime[i].time().second();
            PosData->longitude     = Longitude;
            PosData->latitude      = Latitude;
            PosData->timezone      = 0;
            if (Algorithm == "Solpos with Refraction")
            {
                if (std::isnan(Values["PoPoPoPo"][i]) == false)
                    PosData->press = Values["PoPoPoPo"][i]/100;
                else
                    PosData->press = -999.9;
                if (std::isnan(Values["T2"][i]) == false)
                    PosData->temp  = Values["T2"][i]-273.15;
                else
                    PosData->temp  = -999.9;
                PosData->function  = (S_GEOM | S_REFRAC | S_ETR);
            }
            else if (Algorithm == "Solpos without Refraction")
                PosData->function  = (S_GEOM | S_ZENETR | S_ETR);
            //       Calculate
            long ErrorCode = S_solpos(PosData);

            //       Set AstroData variables
            if (ErrorCode == 0)
            {
                if (Algorithm == "Solpos with Refraction")
                    Values["SolarZenithAngle"][i]       = PosData->zenref;
                else if (Algorithm == "Solpos without Refraction")
                    Values["SolarZenithAngle"][i]   = PosData->zenetr;
                Values["DirectExtraTerrestrial"][i] = PosData->etrn;
                Values["SwdExtraTerrestrial"][i]    = PosData->etr;
                Values["EarthSunDistance"][i]       = ASTRONOMICALUNIT/sqrt(PosData->erv);
            }
            else
            {
                Values["SolarZenithAngle"][i]       = NAN;
                Values["EarthSunDistance"][i]       = NAN;
                Values["DirectExtraTerrestrial"][i] = NAN;
                Values["SwdExtraTerrestrial"][i]    = NAN;
            }

            emit lineProcessed(i + 1);
        }
        SolarConstant             = PosData->solcon;
        DataDescription["Solar constant"] = QStringList(QString::number(SolarConstant) + " W/m**2");
    }
}
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()));
    
}
Esempio n. 23
0
/// FOR TESTING ... it's correct
uint32_t Arc3D::interpolateAng(const double tol, QList<QVector3D>& path1)
{
	if (interpolated)
		return path.size()-1;
    // no paths
    path.clear();
//diag("pstart = %f/%f/%f", pstart.x(), pstart.y(), pstart.z() );
//diag("pend = %f/%f/%f", pend.x(), pend.y(), pend.z() );
    // number of sectors
    uint32_t nsec ;
    if (radius) {
    	double as = astart
			  ,ae = aend
	          ,da;
	/// TO REWRITE !!
			// radians
		if (cw)
			da = -positive(as - ae);
		else
			da = positive(ae - as);
    /// <--
//diag("as , ae , cw = %f, %f, %s ", astart, aend, cw==0 ? "horaire" : "anti");
	// interpolation segments
	/// -> an another way to ...
		/// radians
		double dda =  2*qAcos(1- (tol/radius));
        nsec = qRound(qAbs(da/dda)+ 0.5);
//diag("tol, radius, dda, seg  : %.3f, %.2f, %.2f, %d", tol, radius, dda, seg);
	/// <--
		// new increment dda
         dda = da / double(nsec);
//diag("dda : %f", dda);
		// generate segments
		if (nsec > 0 ) {
			// with helix ?
			double dx(0), dy(0), dz(0);
			QVector3D pdh(0, 0, 0);
			if (helix) {
				switch (plane) {
					case PLANE_XY_G17:
						dz = (pend.z()-pstart.z())/(1.0*nsec);
						pdh.setZ(dz);
						break;
					case PLANE_ZX_G19:
						dy = (pend.y()-pstart.y())/(1.0*nsec);
						pdh.setY(dy);
						break;
					case PLANE_YZ_G18:
						dx = (pend.x()-pstart.x())/(1.0*nsec);
						pdh.setX(dx);
						break;
				}
			}

			// generate sectors interpolation from 'astart'
			double teta = astart;
			QVector3D p ;
			uint32_t npi = 0;
			do {
				p = pointArc(teta);
				if (helix) {
					p += npi*pdh;
				}
			    path.append(p);
				teta += dda;
			    npi++;
			} while (npi <= nsec) ;
			// 'path' contains the end points of the vectors
			interpolated = true;
		}
		else {  /// one sectort
			nsec = 1;
			path.append(pstart);
			path.append(pend);
		}
    }
    else {
		nsec = 0;
    	path.append(pcenter);
    }

    path1 = path;

	return nsec ;
}
Esempio n. 24
0
void Molecule::mol2_process( QString fileName )
{
    QString line;
    QFile	file( fileName );
    if ( !file.open( QIODevice::ReadOnly | QIODevice::Text ) )
    {
        //QMessageBox::warning( this, "Warnning", "No file name specified", QMessageBox::Yes );
        return;
    }

    QTextStream in( &file );
    i_molecule_number	= 0;
    line			= in.readLine();


    while ( !line.isNull() )
    {
        if ( line.indexOf( "@<TRIPOS>MOLECULE" ) >= 0 )
        {
            strMolname = in.readLine();
            i_molecule_number++;
            atom.clear();
            bond.clear();
        }

        if ( line.indexOf( "@<TRIPOS>ATOM" ) >= 0 )
        {
            line = in.readLine();
            while ( line.indexOf( "@<TRIPOS>BOND" ) < 0 )
            {
                atomtemp = line.split( QRegExp( "\\s{1,}" ) );
                atom.append( atomtemp );
                line = in.readLine();
            }
        }


        if ( line.indexOf( "@<TRIPOS>BOND" ) >= 0 )
        {
            line = in.readLine();
            while ( line.indexOf( " " ) >= 0 )                      /* read bond */
            {
                bondtemp = line.split( QRegExp( "\\s{1,}" ) );
                bond.append( bondtemp );
                line = in.readLine();
            }

            for ( i_h = atom.begin(); i_h != atom.end(); i_h++ )    /* analyse structure */
            {
                if ( i_h->at( 2 ).indexOf( "H" ) >= 0 )
                {
                    for ( j_h = i_h + 1; j_h != atom.end(); j_h++ )
                    {
                        if ( j_h->at( 2 ).indexOf( "H" ) >= 0 )
                        {
                            distance	= qPow( (i_h->at( 3 ).toDouble() - j_h->at( 3 ).toDouble() ), 2 ) + qPow( (i_h->at( 4 ).toDouble() - j_h->at( 4 ).toDouble() ), 2 ) + qPow( (i_h->at( 5 ).toDouble() - j_h->at( 5 ).toDouble() ), 2 );
                            distance	= qSqrt( distance );

                            if ( (distance >= (d_inputdistance - d_inputdistance_std) ) & (distance <= (d_inputdistance + d_inputdistance_std) ) )
                            {
                                /* ///////////////////////////////bond1 vector////////////////////////////////// */
                                d_Vdistance.append( distance );
                                str_hydrogen_num1.append( i_h->at( 1 ) );
                                str_hydrogen_num2.append( j_h->at( 1 ) );

                                for ( i_bond = bond.begin(); i_bond != bond.end(); i_bond++ )
                                {
                                    if ( i_bond->at( 2 ) == i_h->at( 1 ) )
                                    {
                                        for ( i_atom_con = atom.begin(); i_atom_con != atom.end(); i_atom_con++ )
                                        {
                                            if ( i_atom_con->at( 1 ) == i_bond->at( 3 ) )
                                            {
                                                d_bond1.append( i_atom_con->at( 3 ).toDouble() - i_h->at( 3 ).toDouble() );
                                                d_bond1.append( i_atom_con->at( 4 ).toDouble() - i_h->at( 4 ).toDouble() );
                                                d_bond1.append( i_atom_con->at( 5 ).toDouble() - i_h->at( 5 ).toDouble() );
                                            }
                                        }
                                    }
                                    if ( i_bond->at( 3 ) == i_h->at( 1 ) )
                                    {
                                        for ( i_atom_con = atom.begin(); i_atom_con != atom.end(); i_atom_con++ )
                                        {
                                            if ( i_atom_con->at( 1 ) == i_bond->at( 2 ) )
                                            {
                                                d_bond1.append( i_atom_con->at( 3 ).toDouble() - i_h->at( 3 ).toDouble() );
                                                d_bond1.append( i_atom_con->at( 4 ).toDouble() - i_h->at( 4 ).toDouble() );
                                                d_bond1.append( i_atom_con->at( 5 ).toDouble() - i_h->at( 5 ).toDouble() );
                                            }
                                        }
                                    }
                                }


                                /*
                                 * ///////////////////////////////bond1 vector finished////////////////////////////
                                 * ///////////////////////////////bond2 vector//////////////////////////////////
                                 */
                                for ( i_bond = bond.begin(); i_bond != bond.end(); i_bond++ )
                                {
                                    if ( i_bond->at( 2 ) == j_h->at( 1 ) )
                                    {
                                        for ( i_atom_con = atom.begin(); i_atom_con != atom.end(); i_atom_con++ )
                                        {
                                            if ( i_atom_con->at( 1 ) == i_bond->at( 3 ) )
                                            {
                                                d_bond2.append( i_atom_con->at( 3 ).toDouble() - j_h->at( 3 ).toDouble() );
                                                d_bond2.append( i_atom_con->at( 4 ).toDouble() - j_h->at( 4 ).toDouble() );
                                                d_bond2.append( i_atom_con->at( 5 ).toDouble() - j_h->at( 5 ).toDouble() );
                                            }
                                        }
                                    }

                                    if ( i_bond->at( 3 ) == i_h->at( 1 ) )
                                    {
                                        for ( i_atom_con = atom.begin(); i_atom_con != atom.end(); i_atom_con++ )
                                        {
                                            if ( i_atom_con->at( 1 ) == i_bond->at( 2 ) )
                                            {
                                                d_bond2.append( i_atom_con->at( 3 ).toDouble() - j_h->at( 3 ).toDouble() );
                                                d_bond2.append( i_atom_con->at( 4 ).toDouble() - j_h->at( 4 ).toDouble() );
                                                d_bond2.append( i_atom_con->at( 5 ).toDouble() - j_h->at( 5 ).toDouble() );
                                            }
                                        }
                                    }
                                }
                                /* ///////////////////////////////bond2 vector finished//////////////////////////// */
                                angle	= qAcos( (d_bond1.at( 0 ) * d_bond2.at( 0 ) + d_bond1.at( 1 ) * d_bond2.at( 1 ) + d_bond1.at( 2 ) * d_bond2.at( 2 ) ) / (sqrt( d_bond1.at( 0 ) * d_bond1.at( 0 ) + d_bond1.at( 1 ) * d_bond1.at( 1 ) + d_bond1.at( 2 ) * d_bond1.at( 2 ) ) * sqrt( d_bond2.at( 0 ) * d_bond2.at( 0 ) + d_bond2.at( 1 ) * d_bond2.at( 1 ) + d_bond2.at( 2 ) * d_bond2.at( 2 ) ) ) );
                                angle	= angle / 3.141592654 * 180;
                                d_Vangle.append( angle );
                                d_bond1.clear();
                                d_bond2.clear();



                        }
                    }
                }
            }

            if ( line.indexOf( " " ) < 0 ) /* finish bond */
            {

                score_process();

                continue;
            }
        }

        line = in.readLine();
        ui->statusBar->showMessage( QString::number( i_molecule_number ) + " molecules processed" );


        QCoreApplication::processEvents();
        if ( this->i_flag_stop == 1 )
        {
            break;
            file.close();
        }
    }
    if ( this->i_flag_stop == 1 )
    {
        ui->statusBar->showMessage( "Screening Stopped" );
    }else {
        ui->statusBar->showMessage( "Screening Finished" );
    }
    ui->tb_result->sortByColumn( 1 );
    if ( ui->tb_result->rowCount() > ui->le_hit->text().toInt() )
    {
        for (; i_hit_number >= ui->le_hit->text().toInt(); i_hit_number-- )
        {
            ui->tb_result->removeRow( i_hit_number );
        }
    }
    file.close();
}
Esempio n. 25
0
void B9SupportStructure::ForceUpdate()
{
    QVector3D topFinalNormal;//result of combinging angle factor with source normal.
    QVector3D bottomFinalNormal;
    QVector3D alongMidDownNormal;
    QVector3D alongMidUpNormal;
    QVector3D topPivotCross;
    QVector3D bottomPivotCross;


    if(isGrounded)
    {
        bottomPoint.setZ(-instanceParent->GetPos().z());
    }

    length = Distance3D(GetTopPoint(),GetBottomPoint());

    //Compute real normal using angle factors
    topFinalNormal = topNormal;
    topFinalNormal.setX(topNormal.x()*topAngleFactor);
    topFinalNormal.setY(topNormal.y()*topAngleFactor);
    topFinalNormal.normalize();

    bottomFinalNormal = bottomNormal;
    bottomFinalNormal.setX(bottomNormal.x()*bottomAngleFactor);
    bottomFinalNormal.setY(bottomNormal.y()*bottomAngleFactor);
    bottomFinalNormal.normalize();


    //Compute pivot positions
    topPivot = topPoint - topFinalNormal*topLength;
    bottomPivot = bottomPoint - bottomFinalNormal*bottomLength;


    //Compute midExtensions based on normal angles,
    //these extensions are to cover up top and botton shape gaps.
    alongMidDownNormal = (bottomPivot - topPivot);
    alongMidDownNormal.normalize();
    topPivotCross = QVector3D::crossProduct(topFinalNormal,alongMidDownNormal);
    topMidExtension = topPivotCross.length()*topRadius;
    topMidExtensionPoint = topPivot - alongMidDownNormal*topMidExtension;

    alongMidUpNormal = (topPivot - bottomPivot);
    alongMidUpNormal.normalize();
    bottomPivotCross = QVector3D::crossProduct(bottomFinalNormal,alongMidUpNormal);
    if(isGrounded)
    {
        bottomMidExtension = midRadius*2*bottomPivotCross.length();
    }
    else
        bottomMidExtension = bottomPivotCross.length()*bottomRadius;


    bottomMidExtensionPoint = bottomPivot - alongMidUpNormal*bottomMidExtension;



    //True rendered mid length
    midLength = Distance3D(topMidExtensionPoint,bottomMidExtensionPoint);



    //Compute PenetrationPoints (the true end points that are rendered/baked)
    topPenetrationPoint = topPoint + topFinalNormal*topPenetration;
    bottomPenetrationPoint = bottomPoint + bottomFinalNormal*bottomPenetration;


    //Compute Euler rotations for top, mid, and bottom shapes
    topThetaX = qAcos(topFinalNormal.z())*(180/M_PI);
    topThetaZ = qAtan2(topFinalNormal.y(),topFinalNormal.x())*(180/M_PI)-90;

    if(topThetaZ <= 90)
        topThetaZ += 180;

    midThetaX = qAcos((topMidExtensionPoint.z() - bottomMidExtensionPoint.z())/midLength)*(180/M_PI);
    midThetaZ = qAtan2((topMidExtensionPoint.y() - bottomMidExtensionPoint.y()),
                       (topMidExtensionPoint.x() - bottomMidExtensionPoint.x()))*(180/M_PI)-90;

    if(midThetaZ <= 90)
        midThetaZ += 180;


    bottomThetaX = qAcos(bottomFinalNormal.z())*(180/M_PI)+180;
    bottomThetaZ = qAtan2(bottomFinalNormal.y(),bottomFinalNormal.x())*(180/M_PI)-90;

    if(bottomThetaZ <= 90)
        bottomThetaZ += 180;



}