Exemple #1
0
QLineF Util::rectSlice(QPointF p1, QPointF p2, QRectF r)
{
    // https://gist.github.com/ChickenProp/3194723
    qreal minX = r.x();
    qreal minY = r.y();
    qreal maxX = minX + r.width();
    qreal maxY = minY + r.height();

    qreal dx = p2.x() - p1.x();
    qreal dy = p2.y() - p1.y();

    qreal v[4] = { -dx, dx, -dy, dy };
    qreal u[4] = { p1.x() - minX, maxX - p1.x(), p1.y() - minY, maxY - p1.y() };
    qreal t[4];


    qreal tMax = Inf, tMin = -Inf;
    for (int i=0; i<4; ++i) {
        if (v[i] != 0) {
            t[i] = u[i]/v[i];
            if (v[i] < 0 && tMin < t[i])
                tMin = t[i];
            if (v[i] > 0 && tMax > t[i])
                tMax = t[i];

        } else if (u[i] >= 0) {
            return QLineF(p1, p2); // Inside rect
        } else {
            return QLineF(); // Outside rect
        }
    }

    if (tMin >= tMax)
        return QLineF();

    if (tMax > 1) tMax = 1;
    if (tMax < 0) tMax = 0;
    if (tMin > 1) tMin = 1;
    if (tMin < 0) tMin = 0;

    QPointF q1(p1.x() + tMin*dx, p1.y() + tMin*dy);
    QPointF q2(p1.x() + tMax*dx, p1.y() + tMax*dy);

    return QLineF(q1, q2);
}
void dSceneRender::DrawCylinder(int segments, dFloat radius, dFloat heigh)
{
	dVector q0 ( heigh / 2.0f, radius, 0.0f, 0.0f);
	dVector q1 (-heigh / 2.0f, radius, 0.0f, 0.0f);
	dMatrix rotation (dPitchMatrix(2.0f * 3.1614f/segments));
	dVector cap0[1024];
	dVector cap1[1024];
	dAssert (segments < sizeof (cap0)/sizeof (cap0[0]));
	cap0[segments] = q0;
	cap1[segments] = q1;
	for (int i = 0; i < segments; i ++) {
		cap0[i] = q0;
		cap1[i] = q1;
		q0 = rotation.RotateVector(q0);
		q1 = rotation.RotateVector(q1);
	}
	dVector normal0 ( 1.0f, 0.0f, 0.0f, 0.0f);
	dVector normal1 (-1.0f, 0.0f, 0.0f, 0.0f);

	BeginTriangle();	
	for (int i = 2; i < segments; i ++) {
		SubmitNormal(normal0);
		DrawTriangle(cap0[0], cap0[i-1], cap0[i]);

		SubmitNormal(normal1);
		DrawTriangle(cap1[0], cap1[i], cap1[i - 1]);
	}

	for (int i = 0; i < segments; i ++) {
		dVector p0 (cap0[i]);
		dVector p1 (cap0[i + 1]);
		dVector p2 (cap1[i + 1]);
		dVector p3 (cap1[i]);

		dVector normal ((p1 - p0) * (p2 - p0));
		normal = normal.Scale (1.0f / dSqrt(normal % normal));

		SubmitNormal(normal);
		DrawTriangle(p0, p2, p1);

		SubmitNormal(normal);
		DrawTriangle(p0, p3, p2);
	}
	End();	
}
void
TestJoinNode() {
    tbb::flow::graph g;

    TestSimpleSuccessorArc<tbb::flow::queueing>("queueing");
    TestSimpleSuccessorArc<tbb::flow::reserving>("reserving");
    TestSimpleSuccessorArc<tbb::flow::tag_matching>("tag_matching");

    // queueing and tagging join nodes have input queues, so the input ports do not reverse.
    REMARK(" reserving preds");
    {
        tbb::flow::join_node<tbb::flow::tuple<int,int>, tbb::flow::reserving> rj(g);
        tbb::flow::queue_node<int> q0(g);
        tbb::flow::queue_node<int> q1(g);
        tbb::flow::make_edge(q0,tbb::flow::input_port<0>(rj));
        tbb::flow::make_edge(q1,tbb::flow::input_port<1>(rj));
        q0.try_put(1);
        g.wait_for_all();  // quiesce
        ASSERT(!(tbb::flow::input_port<0>(rj).my_predecessors.empty()),"reversed port missing predecessor");
        ASSERT((tbb::flow::input_port<1>(rj).my_predecessors.empty()),"non-reversed port has pred");
        g.reset();
        ASSERT((tbb::flow::input_port<0>(rj).my_predecessors.empty()),"reversed port has pred after reset()");
        ASSERT((tbb::flow::input_port<1>(rj).my_predecessors.empty()),"non-reversed port has pred after reset()");
        q1.try_put(2);
        g.wait_for_all();  // quiesce
        ASSERT(!(tbb::flow::input_port<1>(rj).my_predecessors.empty()),"reversed port missing predecessor");
        ASSERT((tbb::flow::input_port<0>(rj).my_predecessors.empty()),"non-reversed port has pred");
        g.reset();
        ASSERT((tbb::flow::input_port<1>(rj).my_predecessors.empty()),"reversed port has pred after reset()");
        ASSERT((tbb::flow::input_port<0>(rj).my_predecessors.empty()),"non-reversed port has pred after reset()");
#if TBB_PREVIEW_FLOW_GRAPH_FEATURES
        // should reset predecessors just as regular reset.
        q1.try_put(3);
        g.wait_for_all();  // quiesce
        ASSERT(!(tbb::flow::input_port<1>(rj).my_predecessors.empty()),"reversed port missing predecessor");
        ASSERT((tbb::flow::input_port<0>(rj).my_predecessors.empty()),"non-reversed port has pred");
        g.reset(tbb::flow::rf_extract);
        ASSERT((tbb::flow::input_port<1>(rj).my_predecessors.empty()),"reversed port has pred after reset()");
        ASSERT((tbb::flow::input_port<0>(rj).my_predecessors.empty()),"non-reversed port has pred after reset()");
        ASSERT(q0.my_successors.empty(), "edge not removed by reset(rf_extract)");
        ASSERT(q1.my_successors.empty(), "edge not removed by reset(rf_extract)");
#endif
    }
    REMARK(" done\n");
}
cv::Mat sg::padKernelFFT( cv::Mat const & input, cv::Size const & paddedSize )
{
  cv::Mat result = cv::Mat::zeros( paddedSize, input.type() );

  // Get the 4 quadrants of the input kernel
  int hwx = input.cols / 2;
  int hwy = input.rows / 2;
  int px = hwx;
  int py = hwy;

  int fftW = paddedSize.width;
  int fftH = paddedSize.height;

  if( input.cols %2 != 0 )
    ++px;

  if( input.rows % 2 != 0 )
    ++py;

  cv::Mat  q0( input, cv::Rect( 0, 0, px, py ) );
  cv::Mat q02( result, cv::Rect( fftW - px, fftH - py, px, py ) );

  cv::Mat  q1( input, cv::Rect( px, 0, hwx, py ) );
  cv::Mat q12( result, cv::Rect( 0, fftH - py, hwx, py ) );

  cv::Mat  q2( input, cv::Rect( 0, py, px, hwy ) );
  cv::Mat q22( result, cv::Rect( fftW - px, 0, px, hwy ) );

  cv::Mat  q3( input, cv::Rect( px, py, hwx, hwy ) );
  cv::Mat q32( result, cv::Rect( 0, 0, hwx, hwy ) );

  q0.copyTo( q02 );
  q1.copyTo( q12 );
  q2.copyTo( q22 );
  q3.copyTo( q32 );

  // if our filter doesn't have real and complex components, make the complex part zeros
  if( result.channels() < 2 )
  {
    cv::Mat planes[] = { result, cv::Mat::zeros( result.size(), CV_32F ) };
    cv::merge( planes, 2, result );
  }

  return result;
}
Mat THDUtil::computeOrientation(Mat frame)
{
	Mat padded; //expanding input image to optimal size by making boarder
	int m = getOptimalDFTSize(frame.rows);
	int n = getOptimalDFTSize(frame.cols);
	copyMakeBorder(frame, padded, m - frame.rows, 0, n - frame.cols, BORDER_CONSTANT, 0);

	Mat planes[] = { Mat_<float>(padded), Mat::zeros(padded.size(), CV_32F) };
	Mat complexI;
	merge(planes, 2, complexI);

	dft(complexI, complexI);

	split(complexI, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
	magnitude(planes[0], planes[1], planes[0]);// planes[0] = magnitude
	Mat magI = planes[0];

	magI += Scalar::all(1);                    // switch to logarithmic scale
	log(magI, magI);

	// crop the spectrum, if it has an odd number of rows or columns
	magI = magI(Rect(0, 0, magI.cols & -2, magI.rows & -2));

	// rearrange the quadrants of Fourier image  so that the origin is at the image center
	int cx = magI.cols / 2;
	int cy = magI.rows / 2;

	Mat q0(magI, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant
	Mat q1(magI, Rect(cx, 0, cx, cy));  // Top-Right
	Mat q2(magI, Rect(0, cy, cx, cy));  // Bottom-Left
	Mat q3(magI, Rect(cx, cy, cx, cy)); // Bottom-Right

	Mat tmp;                           // swap quadrants (Top-Left with Bottom-Right)
	q0.copyTo(tmp);
	q3.copyTo(q0);
	tmp.copyTo(q3);

	q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)
	q2.copyTo(q1);
	tmp.copyTo(q2);

	normalize(magI, magI, 0, 1, CV_MINMAX); // Transform the matrix with float values into a
	// viewable image form (float between values 0 and 1).
	return magI;
}
Exemple #6
0
void Database::_RemoveAlbum(QString album, int artist)
{
    if(!artist)
        RemoveAttribute(nAlbum, album);
    else {
        if(!open) return;
        int id = _AddAlbum(album, artist);
        if(id > 0) {
            QSqlQuery q("", db);
            q.prepare("select File from Song where Album = "+QString::number(id));
            q.exec();
            while(q.next()) {
                _RemoveFile(q.value(0).toString());
            }
            QSqlQuery q1("delete from Album where ID = "+QString::number(id), db);
        }
    }
}
	static dFloat PlaneMeshCollisionRayHitCallback (NewtonUserMeshCollisionRayHitDesc* const rayDesc)
	{
		dVector q0 (rayDesc->m_p0[0], rayDesc->m_p0[1], rayDesc->m_p0[2]);
		dVector q1 (rayDesc->m_p1[0], rayDesc->m_p1[1], rayDesc->m_p1[2]);
		dVector dq (q1 - q0);

		// calculate intersection between point lien a plane and return intersection parameter
		dInfinitePlane* const me = (dInfinitePlane*) rayDesc->m_userData;
		dFloat t = -(me->m_plane.DotProduct3(q0) + me->m_plane.m_w) / (me->m_plane.DotProduct3(dq));
		if ((t > 0.0f) && (t < 1.0f)) {
			rayDesc->m_normalOut[0] = me->m_plane[0];
			rayDesc->m_normalOut[1] = me->m_plane[1];
			rayDesc->m_normalOut[2] = me->m_plane[2];
		} else {
			t = 1.2f;
		}
		return t;
	}
void tst_QQuaternion::dotProduct()
{
    QFETCH(float, x1);
    QFETCH(float, y1);
    QFETCH(float, z1);
    QFETCH(float, scalar1);
    QFETCH(float, x2);
    QFETCH(float, y2);
    QFETCH(float, z2);
    QFETCH(float, scalar2);
    QFETCH(float, dot);

    QQuaternion q1(scalar1, x1, y1, z1);
    QQuaternion q2(scalar2, x2, y2, z2);

    QCOMPARE(QQuaternion::dotProduct(q1, q2), dot);
    QCOMPARE(QQuaternion::dotProduct(q2, q1), dot);
}
void    rotate_FromCenter(Mat &magI) {
    int cx = magI.cols/2;
    int cy = magI.rows/2;

    Mat q0(magI, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant
    Mat q1(magI, Rect(cx, 0, cx, cy));  // Top-Right
    Mat q2(magI, Rect(0, cy, cx, cy));  // Bottom-Left
    Mat q3(magI, Rect(cx, cy, cx, cy)); // Bottom-Right

    Mat tmp;                           // swap quadrants (Top-Left with Bottom-Right)
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);

    q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)
    q2.copyTo(q1);
    tmp.copyTo(q2);
}
void tst_QQuaternion::multiply()
{
    QFETCH(qreal, x1);
    QFETCH(qreal, y1);
    QFETCH(qreal, z1);
    QFETCH(qreal, w1);
    QFETCH(qreal, x2);
    QFETCH(qreal, y2);
    QFETCH(qreal, z2);
    QFETCH(qreal, w2);

    QQuaternion q1(w1, x1, y1, z1);
    QQuaternion q2(w2, x2, y2, z2);

    QBENCHMARK {
        QQuaternion q3 = q1 * q2;
    }
}
int CreateCylinder (dVector* const points, dVector* const normals, int segments, dFloat radius, dFloat height, int maxPoints)
{
	dMatrix rotation (dPitchMatrix((-360.0f / segments) * 3.141592f/180.0f));
	dVector p0 (0.0, 0.0f, 0.0f, 0.0f);
	dVector p1 (0.0, radius, 0.0f, 0.0f);

	dVector q0 (height, 0.0f, 0.0f, 0.0f);
	dVector q1 (height, radius, 0.0f, 0.0f);
	dVector n (0, 1.0f, 0.0f, 0.0f);

	int count = 0;
	for (int i = 0; (i < segments) && (count < maxPoints); i ++) {
		dVector p2 (rotation.RotateVector(p1));
		normals[count] = dVector (-1.0f, 0.0f, 0.0f, 0.0f);
		points[count * 3 + 0] = p0;
		points[count * 3 + 1] = p1;
		points[count * 3 + 2] = p2;
		count ++;

		dVector q2 (rotation.RotateVector(q1));
		normals[count] = dVector (1.0f, 0.0f, 0.0f, 0.0f);
		points[count * 3 + 0] = q0;
		points[count * 3 + 1] = q2;
		points[count * 3 + 2] = q1;
		count ++;

		normals[count] = n;
		points[count * 3 + 0] = p1;
		points[count * 3 + 1] = q1;
		points[count * 3 + 2] = p2;
		count ++;

		normals[count] = n;
		points[count * 3 + 0] = p2;
		points[count * 3 + 1] = q1;
		points[count * 3 + 2] = q2;
		count ++;

		n = rotation.RotateVector(n);
		p1 = p2;
		q1 = q2;
	}
	return count;
}
void sg::fftshift( cv::Mat & src )
{
  // If even we can just pivot around the center pixel
  // if odd, we pivot around center + (1,1)
  // quadrants arranged q0 q1
  //                    q2 q3
  // q0 is located at (0, 0) with width px, height py
  // q1 is located at (px, 0) with width hw, height py
  // q2 is located at (0, py) with width px, height hw
  // q3 is located at (px, py) with width hw, height hw
  int hwx = src.cols / 2;
  int hwy = src.rows / 2;
  int px = hwx;
  int py = hwy;

  if( src.cols %2 != 0 )
    ++px;

  if( src.rows % 2 != 0 )
    ++py;

  cv::Mat  q0( src, cv::Rect( 0, 0, px, py ) );
  cv::Mat q02( src, cv::Rect( hwx, hwy, px, py ) );

  cv::Mat  q1( src, cv::Rect( px, 0, hwx, py ) );
  cv::Mat q12( src, cv::Rect( 0, hwy, hwx, py ) );

  cv::Mat  q2( src, cv::Rect( 0, py, px, hwy ) );
  cv::Mat q22( src, cv::Rect( hwx, 0, px, hwy ) );

  cv::Mat  q3( src, cv::Rect( px, py, hwx, hwy ) );
  cv::Mat q32( src, cv::Rect( 0, 0, hwx, hwy ) );

  // q0 is the biggest segment and might overlap with
  // everything else so it gets done last, we hold it in tmp
  cv::Mat tmpq0, tmpq2;
  q0.copyTo( tmpq0 );
  q2.copyTo( tmpq2 );

  q3.copyTo( q32 );
  q1.copyTo( q12 );
  tmpq2.copyTo( q22 );
  tmpq0.copyTo( q02 );
}
Exemple #13
0
	/*四角校正,opencv的fft输出的结果在四个角上,应当稍加处理。(swap)*/
	void reswap4p(Mat &src)
	{
		int cx = src.cols / 2;
		int cy = src.rows / 2;

		Mat q0(src, Rect(0, 0, cx, cy));   // Top-Left - Create a ROI per quadrant 
		Mat q1(src, Rect(cx, 0, cx, cy));  // Top-Right
		Mat q2(src, Rect(0, cy, cx, cy));  // Bottom-Left
		Mat q3(src, Rect(cx, cy, cx, cy)); // Bottom-Right

		Mat tmp;                           // swap quadrants (Top-Left with Bottom-Right)
		q0.copyTo(tmp);
		q3.copyTo(q0);
		tmp.copyTo(q3);

		q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)
		q2.copyTo(q1);
		tmp.copyTo(q2);
	}
Exemple #14
0
void q1(char palavra[], int cont)
{
    if(palavra[cont] == '\0')
    {
        qf(palavra, cont);
    }
    else if(palavra[cont] == '1')
    {
        q1(palavra, cont+1);
    }
    else if(palavra[cont] == '2')
    {
        qf(palavra, cont+1);
    }
    else
    {
        erro();
    }
}
Exemple #15
0
void rearrange(cv::Mat &img)
{
    // img = img(cv::Rect(0, 0, img.cols & -2, img.rows & -2));
    int cx = img.cols / 2;
    int cy = img.rows / 2;

    cv::Mat q0(img, cv::Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
    cv::Mat q1(img, cv::Rect(cx, 0, cx, cy)); // Top-Right
    cv::Mat q2(img, cv::Rect(0, cy, cx, cy)); // Bottom-Left
    cv::Mat q3(img, cv::Rect(cx, cy, cx, cy)); // Bottom-Right

    cv::Mat tmp; // swap quadrants (Top-Left with Bottom-Right)
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);
    q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left)
    q2.copyTo(q1);
    tmp.copyTo(q2);
}
Exemple #16
0
void CustomHinge::SubmitConstrainst ()
{
	dFloat angle;
	dFloat sinAngle;
	dFloat cosAngle;
	dMatrix matrix0;
	dMatrix matrix1;

	// calculate the position of the pivot point and the jacobian direction vectors, in global space. 
	CalculateGlobalMatrix (m_localMatrix0, m_localMatrix1, matrix0, matrix1);

	// Restrict the movemenet on the pivot point along all tree orthonormal direction
	NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_front[0]);
	NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_up[0]);
	NewtonUserJointAddLinearRow (m_joint, &matrix0.m_posit[0], &matrix1.m_posit[0], &matrix0.m_right[0]);
	
	// get a point along the pin axis at some resonable large distance from the pivot
	dVector q0 (matrix0.m_posit + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
	dVector q1 (matrix1.m_posit + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));

	// two contraints row perpendicular to the pin vector
 	NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
	NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);

	// if limit are enable ...
	if (m_limitsOn) {
		// the joint angle can be determine by getting the angle between any two non parallel vectors
		sinAngle = (matrix0.m_up * matrix1.m_up) % matrix0.m_front;
		cosAngle = matrix0.m_up % matrix1.m_up;
		angle = atan2f (sinAngle, cosAngle);

		if (angle < m_minAngle) {
			// get a point along the up vector and set a constraint  
			NewtonUserJointAddAngularRow (m_joint, 0.0f, &matrix0.m_front[0]);
			NewtonUserJointSetRowMaximunFriction (m_joint, 0.0f);
			
		} else if (angle > m_maxAngle) {
			NewtonUserJointAddAngularRow (m_joint, 0.0f, &matrix0.m_front[0]);
			NewtonUserJointSetRowMinimunFriction (m_joint, 0.0f);
		}
	}
 }
Exemple #17
0
rsa_priv::rsa_priv (const bigint &n1, const bigint &n2)
  : rsa_pub (n1 * n2), p (n1), q (n2)
{
  bigint p1 (n1-1);
  bigint q1 (n2-1);
  phin = p1 * q1;
  d = mod (invert (e, phin), phin);

  /* Precompute for CRT */
  dp = mod (d, p1);
  dq = mod (d, q1);
  pinvq = mod (invert (p, q), q);

  // warn << "p " << p.getstr () << "\n";
  // warn << "q " << q.getstr () << "\n";
  // warn << "e " << e.getstr << "\n";
  // warn << "d " << d.getstr << "\n";

  init ();
}
Exemple #18
0
cv::Mat DftShift(const cv::Mat spectrum) {
  cv::Mat shifted_spectrum = spectrum.clone();

  int cr = shifted_spectrum.rows / 2;
  int cc = shifted_spectrum.cols / 2;

  cv::Mat q0(shifted_spectrum, cv::Rect(0, 0, cc, cr));
  cv::Mat q1(shifted_spectrum, cv::Rect(cc, 0, cc, cr));
  cv::Mat q2(shifted_spectrum, cv::Rect(0, cr, cc, cr));
  cv::Mat q3(shifted_spectrum, cv::Rect(cc, cr, cc, cr));
  cv::Mat tmp;
  q0.copyTo(tmp);
  q3.copyTo(q0);
  tmp.copyTo(q3);
  q1.copyTo(tmp);
  q2.copyTo(q1);
  tmp.copyTo(q2);

  return shifted_spectrum;
}
Exemple #19
0
void rearrangeQuadrants(cv::Mat& image) {
    // rearrange the quadrants of Fourier image  so that the origin is at the image center
    int cx = image.cols / 2;
    int cy = image.rows / 2;

    cv::Mat q0(image, cv::Rect(0, 0, cx, cy)); // Top-Left - Create a ROI per quadrant
    cv::Mat q1(image, cv::Rect(cx, 0, cx, cy)); // Top-Right
    cv::Mat q2(image, cv::Rect(0, cy, cx, cy)); // Bottom-Left
    cv::Mat q3(image, cv::Rect(cx, cy, cx, cy)); // Bottom-Right

    cv::Mat tmp;
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);

    q1.copyTo(tmp); // swap quadrant (Top-Right with Bottom-Left)
    q2.copyTo(q1);
    tmp.copyTo(q2);

}
Exemple #20
0
int main ()
{
  printf ("Results of quat03_test:\n");
  
  quatf q1 (1.0f, 2.0f, 3.0f, 4.0f), q2 (5.0f, 6.0f, 7.0f, 8.0f);

  dump ("q1+q2", q1+q2);
  dump ("q1-q2", q1-q2);
  dump ("q1*q2", q1*q2);
  dump ("q1*2",  q1*2.0f);
  dump ("q1/2",  q1/2.0f);
  dump ("2*q1",  2.0f*q1);
  dump ("q1+=q2", quatf (q1)+=q2);
  dump ("q1-=q2", quatf (q1)-=q2);
  dump ("q1*=q2", quatf (q1)*=q2);
  dump ("q1*=2",  quatf (q1)*=2.0f);
  dump ("q1/=2",  quatf (q1)/=2.0f);

  return 0;
}
Exemple #21
0
void q2(const char *cad, int *p, int *c)
{
	if(cad[*p] == '\0')
		return;
	if(cad[*p] == '0')
	{
		(*p)++;
		q1(cad, p, c);
	}
	else if(cad[*p] == '1')
	{
		(*p)++;
		q3(cad, p, c);
	}
	else
	{
		fprintf(stderr, "Cadena no reconocida\n");
		exit(-2);
	}
}
TEST(QuaternionTest, Extraction)
{
	Vec4f p(0,5,5,1);
	Quaternion q1(0, 45, 0);
	Quaternion q2(0, 0, 45);

	Vec4f p1 = p.Rotate(q1);
	p1 = p1.Rotate(q2);

	Quaternion q = q2*q1;

	float angle;
	Vec4f axis;
	q.ExtractRotationAxisAndAngle(&angle, &axis);

	Quaternion net(angle, axis);
	Vec4f p2 = p.Rotate(net);

	EXPECT_EQ(p1, p2);
}
Exemple #23
0
void q1(const char *cad, int *p, int *c)
{
    if(cad[*p] == '\0')
        return;
    if(cad[*p] == 'n' || cad[*p] == 'N')
    {
        (*p)++;
        q2(cad, p, c);
    }
    else if(cad[*p] == 'i' || cad[*p] == 'I')
    {
        (*p)++;
        q1(cad, p, c);
    }
    else
    {
        (*p)++;
        q0(cad, p, c);
    }
}
Exemple #24
0
vector<double> CIEColor::SinglehueSequential(vector<vector<double> > MSCs, double t, double s, double b, double c, double h)
{
	int N=10;
	vector<double> Pseg;
	vector<double> p0(3,0),p1(3,0), p2(3,0), q0(3,0), q1(3,0), q2(3,0);
		
	p2[0]=100, p2[1]=0, p2[2]=h;
	//p1=dividingLCHuvforMSC_H(0,100,h);
	int mid1, mid2;
	mid1 = int(h * 100);  
	float ML, MC, dl;
	dl = h*100 - mid1;
	mid1 = mid1%3600;
	mid2 = (mid1+1)%3600;;
	ML = MSCs[mid1][0]*(1-dl) + MSCs[mid2][0]*dl;
	MC = MSCs[mid1][1]*(1-dl) + MSCs[mid2][1]*dl;	

	p1[0]= ML, p1[1]= MC, p1[2]= h;
	p0[0]=0, p0[1]=0, p0[2]=h;

	q0[0] = (1-s) * p0[0] + s *p1[0];
	q0[1] = (1-s) * p0[1] + s *p1[1];
	q0[2] = (1-s) * p0[2] + s *p1[2];

	q2[0] = (1-s) * p2[0] + s *p1[0];
	q2[1] = (1-s) * p2[1] + s *p1[1];
	q2[2] = (1-s) * p2[2] + s *p1[2];

	q1[0] = (q0[0] + q2[0])/2;
	q1[1] = (q0[1] + q2[1])/2;
	q1[2] = (q0[2] + q2[2])/2;

	vector<double> T = getT(p0, p1, p2, q0, q1, q2, 125-125*pow(0.2,(1-c)*b+t*c)); 
	Pseg = getCseg(p0, p1, p2, q0, q1, q2, T[0]);
	Pseg[2]=h;
	double r, g, k;
	//LCHuvtoRGB(Pseg[0], Pseg[1], Pseg[2], r, g, k);
	closestLCHuvtoRGB(Pseg[0], Pseg[1], Pseg[2], r, g, k);
	Pseg[0]= r, Pseg[1]=g, Pseg[2]=k;
	return Pseg;
}
Exemple #25
0
void
QuaternionTest::testAssign()
{
	xpcc::Quaternion<float> q1(1,2,3,4);
	xpcc::Quaternion<float> q5;
	q5 = q1;
	TEST_ASSERT_EQUALS(q5.w, 1);
	TEST_ASSERT_EQUALS(q5.x, 2);
	TEST_ASSERT_EQUALS(q5.y, 3);
	TEST_ASSERT_EQUALS(q5.z, 4);
	
	
	float mData[] = {1,2,3,4};
	xpcc::Matrix<float, 4, 1> m(mData);
	xpcc::Quaternion<float> q6;
	q6 = m;
	TEST_ASSERT_EQUALS(q6.w, 1);
	TEST_ASSERT_EQUALS(q6.x, 2);
	TEST_ASSERT_EQUALS(q6.y, 3);
	TEST_ASSERT_EQUALS(q6.z, 4);
}
int main()
{
  Quaternion<> q0(1, 2, 3, 4);
  Quaternion<> q1(2, 3, 4, 5);
  Quaternion<> q2(3, 4, 5, 6);
  double r = 7;

  cout << "q0:      " << q0 << endl;
  cout << "q1:      " << q1 << endl;
  cout << "q2:      " << q2 << endl;
  cout << "r:       " << r << endl;
  cout << endl;
  cout << "-q0:     " << -q0 << endl;
  cout << "~q0:     " << ~q0 << endl;
  cout << endl;
  cout << "r * q0:  " << r*q0 << endl;
  cout << "r + q0:  " << r+q0 << endl;
  cout << "q0 / r:  " << q0/r << endl;
  cout << "q0 - r:  " << q0-r << endl;
  cout << endl;
  cout << "q0 + q1: " << q0+q1 << endl;
  cout << "q0 - q1: " << q0-q1 << endl;
  cout << "q0 * q1: " << q0*q1 << endl;
  cout << "q0 / q1: " << q0/q1 << endl;
  cout << endl;
  cout << "q0 * ~q0:     " << q0*~q0 << endl;
  cout << "q0 + q1*q2:   " << q0+q1*q2 << endl;
  cout << "(q0 + q1)*q2: " << (q0+q1)*q2 << endl;
  cout << "q0*q1*q2:     " << q0*q1*q2 << endl;
  cout << "(q0*q1)*q2:   " << (q0*q1)*q2 << endl;
  cout << "q0*(q1*q2):   " << q0*(q1*q2) << endl;
  cout << endl;
  cout << "||q0||:  " << sqrt(q0.normSquared()) << endl;
  cout << endl;
  cout << "q0*q1 - q1*q0: " << (q0*q1 - q1*q0) << endl;

  // Other base types
  Quaternion<int> q5(2), q6(3);
  cout << endl << q5*q6 << endl;
}
Exemple #27
0
Database::Database() :QObject(0), subset(false), ssAlbum(0), fillingProgress(0), filling(false)
{
    QMutexLocker locker(&lock);
    db = QSqlDatabase::addDatabase("QSQLITE", "CollectionDB");
    db.setDatabaseName(QDir::homePath()+"/.cuberok/collection.db");
	// db.setConnectOptions("QSQLITE_ENABLE_SHARED_CACHE=1");
    if(QFile::exists(db.databaseName())) {
        if(!db.open()) {
            qDebug("Can not open database");
            proxy->error("Can not open database");
            open = false;
        } else {
            open = true;
            QSqlQuery q1("select value from Version", db);
            int ver = -1;
            if(q1.next()) ver = q1.value(0).toString().toInt();
			if(ver == -1) {
				open = createDatabase();
			} else if(ver < DB_VERSION) {
                open = updateDatabase(ver);
                if(!open) db.close();
            } else if(ver > DB_VERSION) {
                open = false;
                db.close();
                qDebug("Wrong database version (%d)", ver);
                proxy->error("Wrong database version -" + QString::number(ver));
            }
        }
    } else {
        if(!QDir().mkpath(QDir::homePath()+"/.cuberok") || !db.open()) {
            qDebug("Can not create database");
            proxy->error("Can not create database");
            open = false;
        } else {
			open = createDatabase();
        }
    }
    if(open) proxy->message("Database ready");
}
Num solve_Sss(Num X, Num T, Num r, Num b, Num v)
{
  Num N = 2 * b / (v * v);
  Num M = 2 * r / (v * v);
  Num Sj = seed_Sss(N, M, X, T, b, v);

  Num K = 1 - exp(-r * T);
  Num d1 = bsm_general::d1(Sj, X, T, b, v);
  Num q1_ = q1(N, M, K);
  Num VS = X - Sj;
  Num HS = hs(d1, Sj, X, T, r, b, v, q1_);
  Num bj_ = bj(d1, T, r, b, v, q1_);
  Num eps = 1e-6;
  while (std::abs(VS - HS) / X > eps) {
    Sj = (X - HS + bj_ * Sj) / (1 + bj_);
    d1 = bsm_general::d1(Sj, X, T, b, v);
    VS = X - Sj;
    HS = hs(d1, Sj, X, T, r, b, v, q1_);
    bj_ = bj(d1, T, r, b, v, q1_);
  }
  return Sj;
}
void SetKinematicPose(NewtonBody* const body, const dMatrix& matrix1, dFloat timestep)
{
	dMatrix matrix0;
	const dFloat OneOverDt = 1.0f / timestep;
	NewtonBodyGetMatrix(body, &matrix0[0][0]);

	dQuaternion q0(matrix0);
	dQuaternion q1(matrix1);

	dVector omega(q0.CalcAverageOmega(q1, OneOverDt));
//	const dFloat maxOmega = 10.0f;
//	dFloat mag2 = omega.DotProduct3(omega);
//	if (mag2 > maxOmega) {
//		omega = omega.Normalize().Scale(maxOmega);
//	}

	dVector veloc ((matrix1.m_posit - matrix0.m_posit).Scale (OneOverDt));

	NewtonBodySetVelocity(body, &veloc[0]);
	NewtonBodySetOmega(body, &omega[0]);
	NewtonBodyIntegrateVelocity(body, timestep);
}
Exemple #30
0
void rearrangeQuadrants(cv::Mat* magnitude) {
	// rearrange the image so that the bright stuff is in the middle
	int center_x = magnitude->cols/2, center_y = magnitude->rows/2;

	//get a ROI for each quadrant
	cv::Mat q0(*magnitude, cv::Rect(0, 0, center_x, center_y));   // Top-Left
	cv::Mat q1(*magnitude, cv::Rect(center_x, 0, center_x, center_y));  // Top-Right
	cv::Mat q2(*magnitude, cv::Rect(0, center_y, center_x, center_y));  // Bottom-Left
	cv::Mat q3(*magnitude, cv::Rect(center_x, center_y, center_x, center_y)); // Bottom-Right

	//by rearragning these ROIs it modifies the original image
	// swap top left and bottom right
	cv::Mat temp;
	q0.copyTo(temp);
	q3.copyTo(q0);
	temp.copyTo(q3);

	//swap top right and bottom left
	q1.copyTo(temp);
	q2.copyTo(q1);
	temp.copyTo(q2);
}