Example #1
0
//only for x^2 - 2y^2= -1;
void max_dig_pell(int num, vector<int>& vroot, vector<I64Pair>& results)
{
    results.clear();
    i64 p0(vroot[0]);
    i64 q0(1);
    i64 p1(vroot[0]*vroot[1]+1);
    i64 q1(vroot[1]);
    i64 p2(1);
    i64 q2(1);
    results.push_back(I64Pair(p0,q0));

    vroot.erase(vroot.begin());
    int vsize = vroot.size();
    //int r = vsize - 1;
    int start = 2;
    for(int s = start; true; ++s){
        int idx = (s-1)%vsize;
        int value = vroot[idx];
        p2 = p1*(value) + p0;
        q2 = q1*(value) + q0;
        p0 = p1; q0 = q1; 
        p1 = p2; q1 = q2;
        if(p2 > 1e18) break;
        if((s)%(2) == 0) {
            assert(p1*p1-5*q1*q1==-1);
            results.push_back(I64Pair(p1, q1));
        }
    }
}
Example #2
0
vector<double> CIEColor::SinglehueSequential(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);
	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;
}
Example #3
0
void bench_inter_Hor()
{

   for (INT k=0; k<5000 ; k++)
   {
       Pt2dr p0 = random_pt();
       Pt2dr p1 = random_pt();
       if (std::abs(p0.y-p1.y)<1e-2)
          p1.y += 1;
       SegComp aSp(p0,p1);

       REAL anY =  NRrandom3() *100;
       Pt2dr q0 (0,anY);
       Pt2dr q1 (1,anY);

       SegComp aSq(q0,q1);

       bool OkInter;
       Pt2dr aInter0 = aSp.inter(aSq,OkInter);
       Pt2dr aInter2(aSp.AbsiceInterDroiteHoriz(anY),anY);

       REAL DH = euclid(aInter0,aInter2) ;
       BENCH_ASSERT(DH<BIG_epsilon);
   }
}
Example #4
0
File: seis.c Project: mangel45/esc
void q2(const char *cad, int *p, int *c)
{
    if(cad[*p] == '\0')
        return;
    if(cad[*p] == 'g' || cad[*p] == 'G')
    {
        (*p)++;
        (*c)++;
        q0(cad, p, c);
    }
    else
    {
        (*p)++;
        q0(cad, p, c);
    }
}
Example #5
0
    ///////////////////////////////////////////////////////////////////////////////
    //
    // Quake::SetQuake
    //
    // shake it up baby now
    //
    Bool SetWorldMatrix( FamilyNode & node, const Matrix & matrix)
    {
      ASSERT( sysInit);

      if (!*active)
      {
        // setup world position
        //
        node.SetWorldAll(matrix);

        return FALSE;
      }

      Quaternion q0( matrix);
      Quaternion q1( quakeAnim.Current().intensity * 0.2f, Vector( filterX.Current(), filterY.Current(), filterZ.Current()));
      Matrix mat( q0 * q1);
      mat.posit.x = matrix.posit.x + filterX.Current();
      mat.posit.y = matrix.posit.y + filterY.Current();
      mat.posit.z = matrix.posit.z + filterZ.Current();

      // setup world position
      //
      node.SetWorldAll(mat);

      return TRUE;
    }
void run_multiport_test(int num_threads) {
    typedef typename tbb::flow::multifunction_node<InputType, OutputTuple> mo_node_type;
    typedef typename std::tuple_element<0,OutputTuple>::type EvenType;
    typedef typename std::tuple_element<1,OutputTuple>::type OddType;
    tbb::task_scheduler_init init(num_threads);
    tbb::flow::graph g;
    mo_node_type mo_node(g, tbb::flow::unlimited, oddEvenBody<InputType, OutputTuple>() );

    tbb::flow::queue_node<EvenType> q0(g);
    tbb::flow::queue_node<OddType> q1(g);

    tbb::flow::make_edge(tbb::flow::output_port<0>(mo_node), q0);
    tbb::flow::make_edge(tbb::flow::output_port<1>(mo_node), q1);

    for(InputType i = 0; i < N; ++i) {
        mo_node.try_put(i);
    }

    g.wait_for_all();
    for(int i = 0; i < N/2; ++i) {
        EvenType e;
        OddType o;
        ASSERT(q0.try_get(e) && (int)e % 2 == 0, NULL);
        ASSERT(q1.try_get(o) && (int)o % 2 == 1, NULL);
    }
}
Example #7
0
void Database::CreateDefaultSqlPlaylists()
{
	QSqlQuery q0("", db);
	q0.prepare("insert into SQLPlaylist (value, data) values (:val, :dat)");
	q0.bindValue(":val", tr("The Best"));
	q0.bindValue(":dat", "SongRating > 40");
	q0.exec();
	q0.prepare("insert into SQLPlaylist (value, data) values (:val, :dat)");
	q0.bindValue(":val", tr("Good music"));
	q0.bindValue(":dat", "SongRating > 20");
	q0.exec();
	q0.prepare("insert into SQLPlaylist (value, data) values (:val, :dat)");
	q0.bindValue(":val", tr("Unrated"));
	q0.bindValue(":dat", "SongRating = 0");
	q0.exec();
	q0.prepare("insert into SQLPlaylist (value, data) values (:val, :dat)");
	q0.bindValue(":val", tr("Added today"));
	q0.bindValue(":dat", "(julianday('now') - julianday(Date, 'utc')) < 1");
	q0.exec();
	q0.prepare("insert into SQLPlaylist (value, data) values (:val, :dat)");
	q0.bindValue(":val", tr("Added this week"));
	q0.bindValue(":dat", "(julianday('now') - julianday(Date, 'utc')) <= 7");
	q0.exec();
	q0.prepare("insert into SQLPlaylist (value, data) values (:val, :dat)");
	q0.bindValue(":val", tr("Added this month"));
	q0.bindValue(":dat", "(julianday('now') - julianday(Date, 'utc')) <= 30");
	q0.exec();
	CreateDefaultSqlPlaylists2();
}
Example #8
0
File: seis.c Project: mangel45/esc
void initAutomata(const char *cad, int *p, int *c)
{
    *c = 0;
    if(*p < strlen(cad))
        q0(cad, p, c);
    fprintf(stdout, "La cadena \"ing\" fue encontrada %d veces\n", *c);

    inicializar();
    colorearPantalla();
    tituloVentana();

    estadoCualquiera(120.0, 250.0, "q0");
    estadoCualquiera(270.0, 250.0, "q1");
    estadoCualquiera(420.0, 250.0, "q2");
    estadoFinal(570.0, 250.0, "q3");
    grafoDirigido(120.0+40.0, 250.0, 270.0-40.0, 250.0, 1, "i");
    grafoDirigido(270.0+40.0, 250.0, 420.0-40.0, 250.0, 1, "n");
    grafoDirigido(420.0+40.0, 250.0, 570.0-40.0, 250.0, 1, "g");
    grafoDirigido(270.0, 250.0-40.0, 0.0, 0.0, 0, "i");
    grafoDirigido(110.0+40.0, 250.0+30, 280.0-40.0, 250.0+30, -1, "E-n");
    grafoDirigido(110.0+40.0, 190.0+30, 420.0-40.0, 190.0+30, -1, "E-n-g");

    al_flip_display();

    while(1)
    {
        al_wait_for_event(queue_evento, &evento);
        if(evento.type == ALLEGRO_EVENT_DISPLAY_CLOSE)
            break;
    }

    about();
    finalizar();
}
void Test() {
  std::string str('x', 4);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor parameters are probably swapped [misc-string-constructor]
  std::wstring wstr(L'x', 4);
  // CHECK-MESSAGES: [[@LINE-1]]:16: warning: constructor parameters are probably swapped
  std::string s0(0, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
  std::string s1(-4, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
  std::string s2(0x1000000, 'x');
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
  
  std::string q0("test", 0);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: constructor creating an empty string
  std::string q1(kText, -4);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: negative value used as length parameter
  std::string q2("test", 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q3(kText, 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q4(kText2, 200);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: length is bigger then string literal size
  std::string q5(kText3,  0x1000000);
  // CHECK-MESSAGES: [[@LINE-1]]:15: warning: suspicious large length parameter
}
Example #10
0
/// rearrange the quadrants of Fourier image  so that the origin is at the image center
void frequency_domain::shift( cv::Mat& image )
{
    if( image.rows == 1 && image.cols == 1)
    {
        return;
    }

    cv::vector< cv::Mat > planes;
    cv::split( image, planes );

    int xMid = image.cols >> 1;
    int yMid = image.rows >> 1;

    for( unsigned int i = 0; i < planes.size(); i++ )
    {
        cv::Mat tmp;
        cv::Mat q0(planes[i], cv::Rect(0,    0,    xMid, yMid));
        cv::Mat q1(planes[i], cv::Rect(xMid, 0,    xMid, yMid));
        cv::Mat q2(planes[i], cv::Rect(0,    yMid, xMid, yMid));
        cv::Mat q3(planes[i], cv::Rect(xMid, yMid, xMid, yMid));

        q0.copyTo(tmp);
        q3.copyTo(q0);
        tmp.copyTo(q3);

        q1.copyTo(tmp);
        q2.copyTo(q1);
        tmp.copyTo(q2);
    }

    cv::merge( planes, image );

}
Example #11
0
void MSNewton::Fixed::submit_constraints(const NewtonJoint* joint, dgFloat32 timestep, int thread_index) {
	JointData* joint_data = (JointData*)NewtonJointGetUserData(joint);

	// Calculate position of pivot points and Jacobian direction vectors in global space.
	dMatrix matrix0, matrix1, matrix2;
	MSNewton::Joint::c_calculate_global_matrix(joint_data, matrix0, matrix1, matrix2);

	const dVector& p0 = matrix0.m_posit;
	const dVector& p1 = matrix1.m_posit;
	// Get a point along the pin axis at some reasonable large distance from the pivot.
	dVector q0(p0 + matrix0.m_right.Scale(MIN_JOINT_PIN_LENGTH));
	dVector q1(p1 + matrix1.m_right.Scale(MIN_JOINT_PIN_LENGTH));
	// Get the ankle point.
	dVector r0(p0 + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
	dVector r1(p1 + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));

	// Restrict movement on the pivot point along all three orthonormal directions
	NewtonUserJointAddLinearRow(joint, &p0[0], &p1[0], &matrix0.m_front[0]);
	if (joint_data->ctype == CT_FLEXIBLE)
		NewtonUserJointSetRowSpringDamperAcceleration(joint, Joint::LINEAR_STIFF, Joint::LINEAR_DAMP);
	else if (joint_data->ctype == CT_ROBUST)
		NewtonUserJointSetRowAcceleration(joint, NewtonUserCalculateRowZeroAccelaration(joint));
	NewtonUserJointSetRowStiffness(joint, joint_data->stiffness);

	NewtonUserJointAddLinearRow(joint, &p0[0], &p1[0], &matrix0.m_up[0]);
	if (joint_data->ctype == CT_FLEXIBLE)
		NewtonUserJointSetRowSpringDamperAcceleration(joint, Joint::LINEAR_STIFF, Joint::LINEAR_DAMP);
	else if (joint_data->ctype == CT_ROBUST)
		NewtonUserJointSetRowAcceleration(joint, NewtonUserCalculateRowZeroAccelaration(joint));
	NewtonUserJointSetRowStiffness(joint, joint_data->stiffness);

	NewtonUserJointAddLinearRow(joint, &p0[0], &p1[0], &matrix0.m_right[0]);
	if (joint_data->ctype == CT_FLEXIBLE)
		NewtonUserJointSetRowSpringDamperAcceleration(joint, Joint::LINEAR_STIFF, Joint::LINEAR_DAMP);
	else if (joint_data->ctype == CT_ROBUST)
		NewtonUserJointSetRowAcceleration(joint, NewtonUserCalculateRowZeroAccelaration(joint));
	NewtonUserJointSetRowStiffness(joint, joint_data->stiffness);

	// Restrict rotation along all three orthonormal directions
	NewtonUserJointAddLinearRow(joint, &q0[0], &q1[0], &matrix0.m_front[0]);
	if (joint_data->ctype == CT_FLEXIBLE)
		NewtonUserJointSetRowSpringDamperAcceleration(joint, Joint::LINEAR_STIFF, Joint::LINEAR_DAMP);
	else if (joint_data->ctype == CT_ROBUST)
		NewtonUserJointSetRowAcceleration(joint, NewtonUserCalculateRowZeroAccelaration(joint));
	NewtonUserJointSetRowStiffness(joint, joint_data->stiffness);

	NewtonUserJointAddLinearRow(joint, &q0[0], &q1[0], &matrix0.m_up[0]);
	if (joint_data->ctype == CT_FLEXIBLE)
		NewtonUserJointSetRowSpringDamperAcceleration(joint, Joint::LINEAR_STIFF, Joint::LINEAR_DAMP);
	else if (joint_data->ctype == CT_ROBUST)
		NewtonUserJointSetRowAcceleration(joint, NewtonUserCalculateRowZeroAccelaration(joint));
	NewtonUserJointSetRowStiffness(joint, joint_data->stiffness);

	NewtonUserJointAddLinearRow(joint, &r0[0], &r1[0], &matrix0.m_up[0]);
	if (joint_data->ctype == CT_FLEXIBLE)
		NewtonUserJointSetRowSpringDamperAcceleration(joint, Joint::LINEAR_STIFF, Joint::LINEAR_DAMP);
	else if (joint_data->ctype == CT_ROBUST)
		NewtonUserJointSetRowAcceleration(joint, NewtonUserCalculateRowZeroAccelaration(joint));
	NewtonUserJointSetRowStiffness(joint, joint_data->stiffness);
}
Example #12
0
dFloat dMeshNodeInfo::RayCast (const dVector& p0, const dVector& p1) const
{
	dVector q0 (m_matrix.UntransformVector(p0));
	dVector q1 (m_matrix.UntransformVector(p1));

	//	int vertexCount = NewtonMeshGetVertexCount(m_mesh);
	int strideInBytes = NewtonMeshGetVertexStrideInByte(m_mesh);
	float* const vertexList = NewtonMeshGetVertexArray(m_mesh);
	dFloat t = 1.2f;
int xxx = 0;
int xxx2 = 0;
	for (void* face = NewtonMeshGetFirstFace (m_mesh); face; face = NewtonMeshGetNextFace (m_mesh, face)) {
		if (!NewtonMeshIsFaceOpen (m_mesh, face)) {

xxx ++;
			int indices[1024];
			int vertexCount = NewtonMeshGetFaceIndexCount (m_mesh, face);
			NewtonMeshGetFaceIndices (m_mesh, face, indices);

			dFloat t1 = dPolygonRayCast (q0, q1, vertexCount, vertexList, strideInBytes, indices);
			if (t1 < t) {
xxx2 = xxx;
if (xxx2 == 40276)
xxx2 = xxx;
				t = t1;		
			}
		}
	}
	return t;
}
	void SubmitConstraints(dFloat timestep, int threadIndex)
	{
		CustomBallAndSocket::SubmitConstraints(timestep, threadIndex);
		float invTimestep = 1.0f / timestep;

		dMatrix matrix0;
		dMatrix matrix1;

		CalculateGlobalMatrix(matrix0, matrix1);

		if (m_anim_speed != 0.0f) // some animation to illustrate purpose
		{
			m_anim_time += timestep * m_anim_speed;
			float a0 = sin(m_anim_time);
			float a1 = m_anim_offset * 3.14f;
			dVector axis(sin(a1), 0.0f, cos(a1));
			//dVector axis (1,0,0);
			m_target = dQuaternion(axis, a0 * 0.5f);
		}

		// measure error
		dQuaternion q0(matrix0);
		dQuaternion q1(matrix1);
		dQuaternion qt0 = m_target * q1;
		dQuaternion qErr = ((q0.DotProduct(qt0) < 0.0f)	? dQuaternion(-q0.m_q0, q0.m_q1, q0.m_q2, q0.m_q3) : dQuaternion(q0.m_q0, -q0.m_q1, -q0.m_q2, -q0.m_q3)) * qt0;

		float errorAngle = 2.0f * acos(dMax(-1.0f, dMin(1.0f, qErr.m_q0)));
		dVector errorAngVel(0, 0, 0);

		dMatrix basis;
		if (errorAngle > 1.0e-10f) {
			dVector errorAxis(qErr.m_q1, qErr.m_q2, qErr.m_q3, 0.0f);
			errorAxis = errorAxis.Scale(1.0f / dSqrt(errorAxis % errorAxis));
			errorAngVel = errorAxis.Scale(errorAngle * invTimestep);

			basis = dGrammSchmidt(errorAxis);
		} else {
			basis = dMatrix(qt0, dVector(0.0f, 0.0f, 0.0f, 1.0f));
		}

		dVector angVel0, angVel1;
		NewtonBodyGetOmega(m_body0, (float*)&angVel0);
		NewtonBodyGetOmega(m_body1, (float*)&angVel1);

		dVector angAcc = (errorAngVel.Scale(m_reduceError) - (angVel0 - angVel1)).Scale(invTimestep);

		// motor
		for (int n = 0; n < 3; n++) {
			// calculate the desired acceleration
			dVector &axis = basis[n];
			float relAccel = angAcc % axis;

			NewtonUserJointAddAngularRow(m_joint, 0.0f, &axis[0]);
			NewtonUserJointSetRowAcceleration(m_joint, relAccel);
			NewtonUserJointSetRowMinimumFriction(m_joint, -m_angularFriction);
			NewtonUserJointSetRowMaximumFriction(m_joint, m_angularFriction);
			NewtonUserJointSetRowStiffness(m_joint, m_stiffness);
		}
	}
dgUnsigned32 dgHingeConstraint::JacobianDerivative (dgContraintDescritor& params)
{
	dgMatrix matrix0;
	dgMatrix matrix1;
	dgVector angle (CalculateGlobalMatrixAndAngle (matrix0, matrix1));

	m_angle = -angle.m_x;

	dgAssert (dgAbsf (1.0f - (matrix0.m_front % matrix0.m_front)) < dgFloat32 (1.0e-5f)); 
	dgAssert (dgAbsf (1.0f - (matrix0.m_up % matrix0.m_up)) < dgFloat32 (1.0e-5f)); 
	dgAssert (dgAbsf (1.0f - (matrix0.m_right % matrix0.m_right)) < dgFloat32 (1.0e-5f)); 

	const dgVector& dir0 = matrix0.m_front;
	const dgVector& dir1 = matrix0.m_up;
	const dgVector& dir2 = matrix0.m_right;

	const dgVector& p0 = matrix0.m_posit;
	const dgVector& p1 = matrix1.m_posit;
	dgVector q0 (p0 + matrix0.m_front.Scale3(MIN_JOINT_PIN_LENGTH));
	dgVector q1 (p1 + matrix1.m_front.Scale3(MIN_JOINT_PIN_LENGTH));

//	dgAssert (((p1 - p0) % (p1 - p0)) < 1.0e-2f);

	dgPointParam pointDataP;
	dgPointParam pointDataQ;
	InitPointParam (pointDataP, m_stiffness, p0, p1);
	InitPointParam (pointDataQ, m_stiffness, q0, q1);

	CalculatePointDerivative (0, params, dir0, pointDataP, &m_jointForce[0]); 
	CalculatePointDerivative (1, params, dir1, pointDataP, &m_jointForce[1]); 
	CalculatePointDerivative (2, params, dir2, pointDataP, &m_jointForce[2]); 
	CalculatePointDerivative (3, params, dir1, pointDataQ, &m_jointForce[3]); 
	CalculatePointDerivative (4, params, dir2, pointDataQ, &m_jointForce[4]); 

	dgInt32 ret = 5;
	if (m_jointAccelFnt) {
		dgJointCallbackParam axisParam;
		axisParam.m_accel = dgFloat32 (0.0f);
		axisParam.m_timestep = params.m_timestep;
		axisParam.m_minFriction = DG_MIN_BOUND;
		axisParam.m_maxFriction = DG_MAX_BOUND;

		if (m_jointAccelFnt (*this, &axisParam)) {
			if ((axisParam.m_minFriction > DG_MIN_BOUND) || (axisParam.m_maxFriction < DG_MAX_BOUND)) {
				params.m_forceBounds[5].m_low = axisParam.m_minFriction;
				params.m_forceBounds[5].m_upper = axisParam.m_maxFriction;
				params.m_forceBounds[5].m_normalIndex = DG_BILATERAL_FRICTION_CONSTRAINT;
			}

			CalculateAngularDerivative (5, params, dir0, m_stiffness, dgFloat32 (0.0f), &m_jointForce[5]);
//			params.m_jointAccel[5] = axisParam.m_accel;
			SetMotorAcceleration (5, axisParam.m_accel, params);
			ret = 6;
		}
	}

	return dgUnsigned32 (ret);
}
Example #15
0
void initAutomata(char *cad, int *p)
{
	if(*p < strlen(cad))
		if(cad[0] == '0')
			q0(cad, p);
		else
			fprintf(stderr, "Cadena no aceptada\n");
	exit(1);
}
Example #16
0
ofRectangle ofxSymbolInstance::getBoundingBox(ofMatrix4x4 mat) {
//    cout << "bounding box" << endl;
    ofRectangle rect(0,0,0,0);
    mat.preMult(this->mat);
    
    switch (type) {
        case BITMAP_INSTANCE: {
            ofVec2f p0 = mat.preMult(ofVec3f(0,0,0));
            ofVec2f p1 = mat.preMult(ofVec3f(bitmapItem->getWidth(),bitmapItem->getHeight()));
            rect = ofRectangle(p0.x,p0.y,p1.x-p0.x,p1.y-p0.y);
        } break;
            
        case SYMBOL_INSTANCE: {
            
            for (vector<layer>::iterator liter=layers.begin();liter!=layers.end();liter++) {
                frame &f = liter->frames[liter->currentFrame];
                
                vector<ofxSymbolInstance>::iterator iter=f.instances.begin();
                while (iter!=f.instances.end()) {
                    rect = iter->getBoundingBox(mat);
                    iter++;
                    if (rect.width!=0 || rect.height!=0) {
                        break;
                    }
                }
                
                while (iter!=f.instances.end()) {
                    
                    ofRectangle iterect = iter->getBoundingBox();
                    if (iterect.width!=0 || iterect.height!=0) {
                    
                        ofVec2f p0(rect.x,rect.y);
                        ofVec2f p1(p0.x+rect.width,p0.y+rect.height);
                        
                        ofVec2f q0(iterect.x,iterect.y);
                        ofVec2f q1(q0.x+iterect.width,q0.y+iterect.height);
                        
                        ofVec2f pos(MIN(p0.x,q0.x),MIN(p0.y,q0.y));
                        rect = ofRectangle(pos.x,pos.y,MAX(p1.x,q1.x)-pos.x,MAX(p1.y,q1.y)-pos.y);
                            
                       
                            //                    cout << rect.x << "\t" << rect.y << "\t" << rect.width << "\t" << rect.height << endl;
                            
                    }
                    iter++;
                   
                }
            }
        } break;
            
        default:
            break;
    } 
    
        
    return rect;
}
Example #17
0
void fftShift(cv::InputOutputArray _out)
{
    cv::Mat out = _out.getMat();

    if(out.rows == 1 && out.cols == 1)
    {
        // trivially shifted.
        return;
    }

    std::vector<cv::Mat> planes;
    planes.push_back(out);

    int xMid = out.cols >> 1;
    int yMid = out.rows >> 1;

    bool is_1d = xMid == 0 || yMid == 0;

    if(is_1d)
    {
        xMid = xMid + yMid;

        for(size_t i = 0; i < planes.size(); i++)
        {
            Mat tmp;
            Mat half0(planes[i], Rect(0, 0, xMid, 1));
            Mat half1(planes[i], Rect(xMid, 0, xMid, 1));

            half0.copyTo(tmp);
            half1.copyTo(half0);
            tmp.copyTo(half1);
        }
    }
    else
    {
        for(size_t i = 0; i < planes.size(); i++)
        {
            // perform quadrant swaps...
            Mat tmp;
            Mat q0(planes[i], Rect(0,    0,    xMid, yMid));
            Mat q1(planes[i], Rect(xMid, 0,    xMid, yMid));
            Mat q2(planes[i], Rect(0,    yMid, xMid, yMid));
            Mat q3(planes[i], Rect(xMid, yMid, xMid, yMid));

            q0.copyTo(tmp);
            q3.copyTo(q0);
            tmp.copyTo(q3);

            q1.copyTo(tmp);
            q2.copyTo(q1);
            tmp.copyTo(q2);
        }
    }

    merge(planes, out);
}
Example #18
0
void q3(char *cad, int *p)
{
	fprintf(stdout, "Q3 cad[%d] - %s\n", *p, cad);
	(*p)--;
	if(cad[*p] == '0')
		q0(cad, p);
	else if(cad[*p] == 'X' || cad[*p] == 'Y' || cad[*p] == '1')
		q3(cad, p);
	else
		q4(cad, p);
}
Example #19
0
//from phasecorr.cpp within opencv library code
void fftShift(cv::Mat& out)
{
    if(out.rows == 1 && out.cols == 1)
    {
        // trivially shifted.
        return;
    }

    std::vector<cv::Mat> planes;
    cv::split(out, planes);

    int xMid = out.cols >> 1;
    int yMid = out.rows >> 1;

    bool is_1d = xMid == 0 || yMid == 0;

    if(is_1d)
    {
        xMid = xMid + yMid;

        for(size_t i = 0; i < planes.size(); i++)
        {
            cv::Mat tmp;
            cv::Mat half0(planes[i], cv::Rect(0, 0, xMid, 1));
            cv::Mat half1(planes[i], cv::Rect(xMid, 0, xMid, 1));

            half0.copyTo(tmp);
            half1.copyTo(half0);
            tmp.copyTo(half1);
        }
    }
    else
    {
        for(size_t i = 0; i < planes.size(); i++)
        {
            // perform quadrant swaps...
            cv::Mat tmp;
            cv::Mat q0(planes[i], cv::Rect(0,    0,    xMid, yMid));
            cv::Mat q1(planes[i], cv::Rect(xMid, 0,    xMid, yMid));
            cv::Mat q2(planes[i], cv::Rect(0,    yMid, xMid, yMid));
            cv::Mat q3(planes[i], cv::Rect(xMid, yMid, xMid, yMid));

            q0.copyTo(tmp);
            q3.copyTo(q0);
            tmp.copyTo(q3);

            q1.copyTo(tmp);
            q2.copyTo(q1);
            tmp.copyTo(q2);
        }
    }

    cv::merge(planes, out);
}
Example #20
0
void SPCtrlCurve::setCoords( gdouble x0, gdouble y0, gdouble x1, gdouble y1,
                             gdouble x2, gdouble y2, gdouble x3, gdouble y3 )
{

    Geom::Point q0( x0, y0 );
    Geom::Point q1( x1, y1 );
    Geom::Point q2( x2, y2 );
    Geom::Point q3( x3, y3 );

    setCoords( q0, q1, q2, q3 );

}
Example #21
0
/*

Differentiate qdot with respect to time

*/
void Segment::seg_qdotdot(Segment **segment_data[]) {

	double t0=segment_data[(this->frame)-1][this->segnum]->time, t2=segment_data[(this->frame)+1][this->segnum]->time;
	Vec_DP q0(segment_data[(this->frame)-1][this->segnum]->qdot,4), q2(segment_data[(this->frame)+1][this->segnum]->qdot,4), q1(4);

	MATHEMATICS::math_deriv(q1,q0,q2,t0,t2);

	for (int i=0; i<4; i++) {
		this->qdotdot[i]=q1[i];
	}

}
Example #22
0
bool Database::createDatabase()
{
	QSqlQuery q0("create table Artist (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250), mbid varchar(50))", db);
	QSqlQuery q1("create table Album (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250), artist integer, mbid varchar(50))", db);
	QSqlQuery q2("create table Genre (ID integer primary key autoincrement, value varchar(200), refs integer, rating integer, art varchar(250))", db);
	QSqlQuery q4("create table Song (ID integer primary key autoincrement, File varchar(250), Track integer, Title varchar(200), Artist integer, Album integer, Genre integer, Year integer, Comment varchar(200), Length varchar(20), Rating integer, Type varchar(30), Date varchar(50))", db);
	QSqlQuery q5("create table Version (value integer)", db);
	QSqlQuery q6("insert into Version (value) values ("+QString::number(DB_VERSION)+")", db);
	QSqlQuery q8("create table Info(Mbid varchar(50) primary key, text varchar(10000))", db);
	QSqlQuery q9("create table SQLPlaylist (ID integer primary key autoincrement, value varchar(200), art varchar(250), data varchar(250))", db);
	CreateDefaultSqlPlaylists();
	return true;
}
Example #23
0
void fingerDetector::setModel(Bottle q_0, Bottle q_1, double m, double M, double t, double T)
{
    q0.resize(q_0.size());
    q1.resize(q_1.size());
    for(int i =0; i < q_0.size(); i++)
        q0(i) = q_0.get(i).asDouble();
    for(int i =0; i < q_1.size(); i++)
        q1(i) = q_1.get(i).asDouble();
    min = m;
    max = M;
    minT = t;
    maxT = T;
}
dFloat64 dBezierSpline::CalculateLength (dFloat64 tol) const
{
	dBigVector stackPool[32][3];
	int stack = 0;

	dFloat64 length = 0.0f;
	dFloat64 tol2 = tol * tol;
	dFloat64 u0 = m_knotVector[m_degree];
	dBigVector p0 (CurvePoint (u0));

	for (int i = m_degree; i < (m_knotsCount - m_degree - 1); i ++) {
		dFloat64 u1 = m_knotVector[i + 1];
		dBigVector p1 (CurvePoint (u1));
		stackPool[stack][0] = p0;
		stackPool[stack][1] = p1;
		stackPool[stack][2] = dBigVector (u0, u1, dFloat64(0.0f), dFloat64(0.0f));
		stack ++;
		while (stack) {
			stack --;
			dBigVector q0 (stackPool[stack][0]);
			dBigVector q1 (stackPool[stack][1]);
			dFloat64 t0 = stackPool[stack][2][0];
			dFloat64 t1 = stackPool[stack][2][1];
			dFloat64 t01 = (t1 + t0) * 0.5f;

			dBigVector p01 ((q1 + q0).Scale (0.5f));
			dBigVector q01 (CurvePoint (t01));
			dBigVector err (q01 - p01);

			dFloat64 err2 = err.DotProduct3(err);
			if (err2 < tol2) {
				dBigVector step (q1 - q0);
				length += dSqrt (step.DotProduct3(step));
			} else {
				stackPool[stack][0] = q01;
				stackPool[stack][1] = q1;
				stackPool[stack][2] = dBigVector (t01, t1, dFloat64(0.0f), dFloat64(0.0f));
				stack ++;

				stackPool[stack][0] = q0;
				stackPool[stack][1] = q01;
				stackPool[stack][2] = dBigVector (t0, t01, dFloat64(0.0f), dFloat64(0.0f));
				stack ++;
			}
		}
		u0 = u1;
		p0 = p1;
	}

	return length;
}
Example #25
0
void CustomPathFollow::SubmitConstraints (dFloat timestep, int threadIndex)
{
	dMatrix matrix0;
		
	// Get the global matrices of each rigid body.
	NewtonBodyGetMatrix(m_body0, &matrix0[0][0]);
	matrix0 = m_localMatrix0 * matrix0;

	dMatrix matrix1 (EvalueCurve (matrix0.m_posit));

	// Restrict the movement on the pivot point along all tree the normal and binormal of the path
	const dVector& p0 = matrix0.m_posit;
	const dVector& p1 = matrix1.m_posit;

	NewtonUserJointAddLinearRow (m_joint, &p0[0], &p1[0], &matrix0.m_up[0]);
	NewtonUserJointAddLinearRow (m_joint, &p0[0], &p1[0], &matrix0.m_right[0]);
	
	// get a point along the ping axis at some reasonable large distance from the pivot
	dVector q0 (p0 + matrix0.m_front.Scale(MIN_JOINT_PIN_LENGTH));
	dVector q1 (p1 + matrix1.m_front.Scale(MIN_JOINT_PIN_LENGTH));

	// two more constraints rows to inforce the normal and binormal 
 	NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_up[0]);
	NewtonUserJointAddLinearRow (m_joint, &q0[0], &q1[0], &matrix0.m_right[0]);


//	Julio: at this point the path follow will maintaing the pivot fixed to the path and will allow it to slide freelly
//	it will also spin around the path tangent, if more control is needed then more constraion rows need to be submited 
//	for example friction along the oath tangent be added to make more realistic behavior
//  or anothet point contration along the binormal to make no spin around the path tangent

/*
	// example of ading friction
	dVector veloc0; 
	dVector omega0; 

	NewtonBodyGetVelocity(m_body0, &veloc0[0]);
	NewtonBodyGetOmega(m_body0, &omega0[0]);

	veloc0 += omega0 * (matrix0.m_posit - p0);

	dFloat relAccel; 
	relAccel = - (veloc0 % matrix0.m_front) / timestep;

	#define MaxFriction 10.0f
	NewtonUserJointAddLinearRow (m_joint, &p0[0], &p0[0], &matrix0.m_front[0]);
	NewtonUserJointSetRowAcceleration (m_joint, relAccel);
	NewtonUserJointSetRowMinimumFriction (m_joint, -MaxFriction);
	NewtonUserJointSetRowMaximumFriction(m_joint, MaxFriction);
*/
}
Example #26
0
int Database::AddFile(QString file)
{
    if(!open) return 0;
    QMutexLocker locker(&lock);
	TRN;
    QSqlQuery q0("", db);
    q0.prepare("select ID from Song where File = :file");
    q0.bindValue(":file", file);
    q0.exec();
    if(q0.next()) return q0.value(0).toString().toInt();
	QUrl url = QUrl::fromLocalFile(file);
    //QString title, artist, album, comment, genre, length, type;
    //int track, year;
	TagEntry tags = Tagger::readTags(url);
    if(tags.title.size()) {
		// type = Tagger::getFileType(url);
    //	TagLib::FileRef fr(file.toLocal8Bit().constData());
        int art = _AddArtist(tags.artist);
        int alb = _AddAlbum(tags.album, art);
        int gen = _AddGenre(tags.genre);
        //QString com = QString("insert into Song (File, Track, Title, Artist, Album, Genre, Year, Comment) values ('%1', %2, '%3', %4, %5, %6, %7, '%8')")
        //.arg(file, QString::number(fr.tag()->track()), QS(fr.tag()->title()), QString::number(art), QString::number(alb), QString::number(gen), QString::number(fr.tag()->year()), QS(fr.tag()->comment()));
        QString com = QString("insert into Song (File, Track, Title, Artist, Album, Genre, Year, Comment, Length, Type, Date) values (:file, %1, :title, %2, %3, %4, %5, :comment, :length, :type, :date) ")
        .arg(QString::number(tags.track), QString::number(art), QString::number(alb), QString::number(gen), QString::number(tags.year));
        QSqlQuery q("", db);
        q.prepare(com);
        q.bindValue(":file", file);
        q.bindValue(":title", tags.title);
        q.bindValue(":comment", tags.comment);
        q.bindValue(":length", tags.slength);
		q.bindValue(":type", tags.filetype);
		q.bindValue(":date", QDateTime::currentDateTime().toString(Qt::ISODate));
        q.exec();
        QSqlQuery q1("", db);
        q1.prepare("select ID from Song where File = :file");
        q1.bindValue(":file", file);
        q1.exec();
        if (q1.next()) {
            RefAttribute(nArtist, art, 1, 0);
            RefAttribute(nAlbum, alb, 1, 0);
            RefAttribute(nGenre, gen, 1, 0);
			if(filling) {
				fillingProgress ++;
				emit status(tr("proccessed %n file(s)", "", fillingProgress));
			}
            return q1.value(0).toString().toInt();
        } else qDebug() << "something went wrong...";
    } else qDebug() << "can't read tags for file" << file;
    return -1;
}
Example #27
0
File: seis.c Project: mangel45/esc
void q0(const char *cad, int *p, int *c)
{
    if(cad[*p] == '\0')
        return;
    if(cad[*p] == 'i' || cad[*p] == 'I')
    {
        (*p)++;
        q1(cad, p, c); //Q1
    }
    else
    {
        (*p)++;
        q0(cad, p, c);
    }
}
void applyDFTOperation(Mat &image,Mat &magImage)
{
    int row = getOptimalDFTSize(image.rows);
    int col = getOptimalDFTSize(image.cols);
    
    Mat image2;
    copyMakeBorder(image,image2,0,row-image.rows,0,col-image.cols,BORDER_CONSTANT, Scalar::all(0));
    
    Mat planes[] = {Mat_<float>(image2), Mat::zeros(image2.size(), CV_32F)};
    Mat complexI;
    merge(planes,2, complexI);
    
    
    dft(complexI,complexI);
    
    split(complexI,planes);
    magnitude(planes[0],planes[1],planes[0]);
    
    
    magImage = planes[0];
    
    magImage += Scalar::all(1);
    log(magImage,magImage);
    
    magImage = magImage(Rect(0,0,magImage.cols & -2,magImage.rows & -2));
    
    int cx = magImage.cols/2;
    int cy = magImage.rows/2;
    Mat q0(magImage,Rect(0,0,cx,cy));       //左上
    Mat q1(magImage,Rect(cx,0,cx,cy));      //右上
    Mat q2(magImage,Rect(0,cy,cx,cy));      //左下
    Mat q3(magImage,Rect(cx,cy,cx,cy));     //右下
    
    
    //将左上和右下交换    右上和左下交换
    Mat tmp;
    q0.copyTo(tmp);
    q3.copyTo(q0);
    tmp.copyTo(q3);
    
    q1.copyTo(tmp);
    q2.copyTo(q1);
    tmp.copyTo(q2);
    
    normalize(magImage, magImage, 0, 1, CV_MINMAX);
    magImage.convertTo(magImage, CV_8UC1, 255);
}
Example #29
0
const Ellipsoid3<Real> MergeEllipsoids (const Ellipsoid3<Real>& ellipsoid0,
    const Ellipsoid3<Real>& ellipsoid1)
{
    Ellipsoid3<Real> merge;

    // compute the average of the input centers
    merge.Center = ((Real)0.5)*(ellipsoid0.Center + ellipsoid1.Center);

    // bounding ellipsoid orientation is average of input orientations
    Quaternion<Real> q0(ellipsoid0.Axis), q1(ellipsoid1.Axis);
    if (q0.Dot(q1) < (Real)0)
    {
        q1 = -q1;
    }
    Quaternion<Real> q = q0 + q1;
    q = Math<Real>::InvSqrt(q.Dot(q))*q;
    q.ToRotationMatrix(merge.Axis);

    // Project the input ellipsoids onto the axes obtained by the average
    // of the orientations and that go through the center obtained by the
    // average of the centers.
    for (int i = 0; i < 3; ++i)
    {
        // Projection axis.
        Line3<Real> line(merge.Center, merge.Axis[i]);

        // Project ellipsoids onto the axis.
        Real min0, max0, min1, max1;
        ProjectEllipsoid(ellipsoid0, line, min0, max0);
        ProjectEllipsoid(ellipsoid1, line, min1, max1);

        // Determine the smallest interval containing the projected
        // intervals.
        Real maxIntr = (max0 >= max1 ? max0 : max1);
        Real minIntr = (min0 <= min1 ? min0 : min1);

        // Update the average center to be the center of the bounding box
        // defined by the projected intervals.
        merge.Center += line.Direction*(((Real)0.5)*(minIntr + maxIntr));

        // Compute the extents of the box based on the new center.
        merge.Extent[i] = ((Real)0.5)*(maxIntr - minIntr);
    }

    return merge;
}
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");
}