Пример #1
0
void
test_invert () {
  tree t1= test_tree ();
  for (int i=0; i<42; i++) {
    modification m1= test_modification (i);
    tree t2= clean_apply (t1, m1);
    modification m2= invert (m1, t1);
    tree t3= clean_apply (t2, m2);
    modification m3= invert (m2, t2);
    if (m1 != m3 || t1 != t3) {
      cout << "t1= " << t1 << "\n";
      cout << "m1= " << m1 << "\n";
      cout << "t2= " << t2 << "\n";
      cout << "m2= " << m2 << "\n";
      cout << "t3= " << t3 << "\n";
      FAILED ("inconsistency");
    }
 }
}
Пример #2
0
glyph glyph::hilite(nc_color back)
{
  if (fg == back) {
    return invert();
  }
  glyph ret = (*this);
  
  ret.bg = back;
  return ret;
}
Пример #3
0
/**
 * Sets the button as the pressed button if it's part of a group,
 * and inverts the colors when pressed.
 * @param action Pointer to an action.
 * @param state State that the action handlers belong to.
 */
void ImageButton::mousePress(Action *action, State *state)
{
	if (_group != 0)
	{
		(*_group)->invert((*_group)->getColor());
		*_group = this;
	}
	invert(_color);
	InteractiveSurface::mousePress(action, state);
}
Пример #4
0
Remotes unmap_owners(
    Mesh* old_mesh, Int ent_dim, LOs new_ents2old_ents, LOs old_ents2new_ents) {
  auto old_copies2old_owners = old_mesh->ask_dist(ent_dim);
  auto old_owners2old_copies = old_copies2old_owners.invert();
  auto old_copies2new_owners = old_owners2old_copies.exch(old_ents2new_ents, 1);
  auto new_ents2new_owners = unmap(new_ents2old_ents, old_copies2new_owners, 1);
  auto old_own_ranks = old_mesh->ask_owners(ent_dim).ranks;
  auto new_own_ranks = unmap(new_ents2old_ents, old_own_ranks, 1);
  return Remotes(new_own_ranks, new_ents2new_owners);
}
Пример #5
0
/**
Calculates backprojection error and returns number of points within error tolerance
@param pL: Number of indices 
@param pR: Storage of the indices
@param numMatch: Number of Matches
@param H: Storage matrix used by RunRansac function
@param ind: array to store good matches
@param totErr: array to store error matches 
@param srcIm: Source Image 
@param dstIm: Destination Image
@return void
*/
int InterframeRegister::CalcErr(vector<Point2f> pL, vector<Point2f> pR, int numMatch, Mat H, vector<int>& ind, double *totErr) 
{
	//float err;
	Mat HInv(3,3,CV_64FC1);

	// check for singularity
	double matDet = invert(H,HInv,DECOMP_LU);
	if (abs(matDet)<0.00001)
	{
		*totErr = numMatch*MATCH_ERR_THRESH;
		return 0;
	}
	
	// compute error and number of matches
	int nGoodMatches = 0;
	Mat matLeft(3, 1, CV_64FC1);
	Mat matRight (3, 1, CV_64FC1);
	Mat matLeftEst (3, 1, CV_64FC1);
	Mat matRightEst (3, 1, CV_64FC1);
	Mat matLeftDiff (3, 1, CV_64FC1);
	Mat matRightDiff (3, 1, CV_64FC1);
	
	for (int cnt = 0; cnt < numMatch; cnt++)
	{
		matLeft = (Mat_<double>(3,1) << pL[cnt].x,pL[cnt].y,1.0);
		matRightEst = H * matLeft;
		
		matRight = (Mat_<double>(3,1) << pR[cnt].x,pR[cnt].y,1.0);

		matLeftEst = HInv * matRight;
		
		for(int i = 0; i < 3; i++)
		{
			matLeftEst.data[i] /= matLeftEst.data[2];
			matRightEst.data[i] /= matRightEst.data[2];
		}
		
		matLeftDiff = matLeftEst-matLeft;
		matRightDiff = matRightEst -matRight;

		double dLeftErr = norm(matLeftDiff);
		double dRightErr = norm(matRightDiff);
		double dErr = (dLeftErr * dLeftErr) + (dRightErr * dRightErr);
		

		if (dErr<MATCH_ERR_THRESH)
		{
			*totErr = *totErr+dErr;
			ind[nGoodMatches++] = cnt;			
		}
		else *totErr = *totErr+MATCH_ERR_THRESH;
	}
	
	return nGoodMatches;
}
Пример #6
0
    /**
     * Inversion operator, i.e. "this->addBefore( ~this ) == Parent".
     * \note Forces are negated and rotated.
     */
    self operator ~() const {
      return self(this->Parent,
			 (-this->Position) * this->Rotation,
			 invert(this->Rotation),
			 ((AngVelocity % this->Position) - Velocity) * this->Rotation,
			 -AngVelocity,
			 ((AngVelocity * AngVelocity * this->Position) + (value_type(2.0) * AngVelocity) % Velocity + AngAcceleration % this->Position - Acceleration ) * this->Rotation,
			 -AngAcceleration,
			 -Force * this->Rotation,
			 -Torque);
    };
Пример #7
0
int main (){
    char *string="ABCDE";
    int i;
    for (i=0;i<5;i++){
        printf("- %s \n",string+i);
        putchar(*string);
    }

    invert("Fernando");
    return 0;
}
Пример #8
0
bool MxQuadric3::optimize(Vec3& v) const
{
    Mat3 Ainv;
    double det = invert(Ainv, tensor());
    if( FEQ(det, 0.0, 1e-12) )
	return false;

    v = -(Ainv*vector());

    return true;
}
Пример #9
0
int main()
{
    unsigned x;
    int p, n;

    x = 209U;
    p = 4;
    n = 3;

    printf("%u\n", invert(x,p,n));
}
Пример #10
0
void inertia_3D::doForce(kte_pass_flag aFlag, const shared_ptr<frame_storage>& aStorage) { RK_UNUSED(aFlag); RK_UNUSED(aStorage);
  if((!mCenterOfMass) || (!mCenterOfMass->mFrame))
    return;

  frame_3D<double> global_frame = mCenterOfMass->mFrame->getGlobalFrame(); //get the inertial frame

  mCenterOfMass->mFrame->Force -= mMass * (invert(global_frame.Quat) * global_frame.Acceleration);

  mCenterOfMass->mFrame->Torque -= mInertiaTensor * global_frame.AngAcceleration + global_frame.AngVelocity % (mInertiaTensor * global_frame.AngVelocity);

};
Пример #11
0
void extract_init(struct SigSet *S)
{
    int m;
    int i;
    int b1, b2;
    int nbands;
    double *lambda;
    struct ClassSig *C;
    struct SubSig *SubS;

    nbands = S->nbands;
    /* allocate scratch memory */
    lambda = (double *)G_malloc(nbands * sizeof(double));

    /* invert matrix and compute constant for each subclass */

    /* for each class */
    for (m = 0; m < S->nclasses; m++) {
	C = &(S->ClassSig[m]);

	/* for each subclass */
	for (i = 0; i < C->nsubclasses; i++) {
	    SubS = &(C->SubSig[i]);

	    /* Test for symetric  matrix */
	    for (b1 = 0; b1 < nbands; b1++)
		for (b2 = 0; b2 < nbands; b2++) {
		    if (SubS->R[b1][b2] != SubS->R[b2][b1])
			G_warning(_("Nonsymetric covariance for class %d subclass %d"),
				  m + 1, i + 1);

		    SubS->Rinv[b1][b2] = SubS->R[b1][b2];
		}

	    /* Test for positive definite matrix */
	    eigen(SubS->Rinv, NULL, lambda, nbands);
	    for (b1 = 0; b1 < nbands; b1++) {
		if (lambda[b1] <= 0.0)
		    G_warning(_("Nonpositive eigenvalues for class %d subclass %d"),
			      m + 1, i + 1);
	    }

	    /* Precomputes the cnst */
	    SubS->cnst = (-nbands / 2.0) * log(2 * PI);
	    for (b1 = 0; b1 < nbands; b1++) {
		SubS->cnst += -0.5 * log(lambda[b1]);
	    }

	    /* Precomputes the inverse of tex->R */
	    invert(SubS->Rinv, nbands);
	}
    }
    G_free((char *)lambda);
}
Пример #12
0
	m3* graphics::getNormalMatrix()
	{
		m4 matrix;
		
		copyMatrix(&matrix, getModelMatrix());
		invert(&matrix);
		transpose(&matrix);
		
		copyMatrix(&normalMatrix, &matrix);
		return &normalMatrix;
	}
Пример #13
0
/**
 * Draws a gear.
 *
 * @param gear the gear to draw
 * @param transform the current transformation matrix
 * @param x the x position to draw the gear at
 * @param y the y position to draw the gear at
 * @param angle the rotation angle of the gear
 * @param color the color of the gear
 */
static void
draw_gear(struct gear *gear, GLfloat *transform,
      GLfloat x, GLfloat y, GLfloat angle, const GLfloat color[4])
{
   GLfloat model_view[16];
   GLfloat normal_matrix[16];
   GLfloat model_view_projection[16];

   /* Translate and rotate the gear */
   memcpy(model_view, transform, sizeof (model_view));
   translate(model_view, x, y, 0);
   rotate(model_view, 2 * M_PI * angle / 360.0, 0, 0, 1);

   /* Create and set the ModelViewProjectionMatrix */
   memcpy(model_view_projection, ProjectionMatrix, sizeof(model_view_projection));
   multiply(model_view_projection, model_view);

   glUniformMatrix4fv(ModelViewProjectionMatrix_location, 1, GL_FALSE,
                      model_view_projection);

   /* 
    * Create and set the NormalMatrix. It's the inverse transpose of the
    * ModelView matrix.
    */
   memcpy(normal_matrix, model_view, sizeof (normal_matrix));
   invert(normal_matrix);
   transpose(normal_matrix);
   glUniformMatrix4fv(NormalMatrix_location, 1, GL_FALSE, normal_matrix);

   /* Set the gear color */
   glUniform4fv(MaterialColor_location, 1, color);

   /* Set the vertex buffer object to use */
   glBindBuffer(GL_ARRAY_BUFFER, gear->vbo);

   /* Set up the position of the attributes in the vertex buffer object */
   glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE,
         6 * sizeof(GLfloat), NULL);
   glVertexAttribPointer(1, 3, GL_FLOAT, GL_FALSE,
         6 * sizeof(GLfloat), (GLfloat *) 0 + 3);

   /* Enable the attributes */
   glEnableVertexAttribArray(0);
   glEnableVertexAttribArray(1);

   /* Draw the triangle strips that comprise the gear */
   int n;
   for (n = 0; n < gear->nstrips; n++)
      glDrawArrays(GL_TRIANGLE_STRIP, gear->strips[n].first, gear->strips[n].count);

   /* Disable the attributes */
   glDisableVertexAttribArray(1);
   glDisableVertexAttribArray(0);
}
Пример #14
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 ();
}
Пример #15
0
main()
{
	unsigned int x, p, n;

	printf("�������ַ���x: ");
    scanf("%u", &x);
    printf("��������ʼλ: ");
    scanf("%d", &p);
    printf("�������滻��λ��: ");
    scanf("%d", &n);
    printf("�滻���xΪ: %u\n", invert(x, p, n));
}
Пример #16
0
main()
{
	const int pos = 5;
	const int numofbits = 3;
	int i = 0;
	
	while (i < 64)
		printf("The %d bits starting at position %d of integer %d inverted: %d\n", 
			numofbits, pos, i++, invert(i, pos, numofbits));

	return 0;
}
Пример #17
0
 T pow(const T& x0, int n) const {
  T x = n > 0 ? x0 : invert(x0);
  if (n < 0) n *= -1;
  n %= order(x);
  if (n == 0) return identity();
  int i;
  for (i=1; !(n & i); i <<= 1) x = oper(x,x);
  T agg = x;
  for (i <<= 1, x = oper(x,x); i <= n; i <<= 1, x = oper(x,x))
   if (n & i) agg = oper(agg, x);
  return agg;
 }
Пример #18
0
int main()
{
    unsigned x;
    int p, n;

    p = 8, n = 3;
    printf("Input a x: ");
    scanf("%x", &x);
    printf("After invert: %#x\n", invert(x, p, n));

    return 0;
}
Пример #19
0
void transform_state_t::update_mvit()
{
    GLfloat r[16];
    const GLfloat* const mv = modelview.top().elements();
    invert(r, mv);
    // convert to fixed-point and transpose
    GLfixed* const x = mvit4.matrix.m;
    for (int i=0 ; i<4 ; i++)
        for (int j=0 ; j<4 ; j++)
            x[I(i,j)] = gglFloatToFixed(r[I(j,i)]);
    mvit4.picker();
}
Пример #20
0
 void power(ElementType& result, const ElementType& a, int n) const
 {
   if (is_zero(a))
     set_zero(result);
   else if (n < 0)
     {
       invert(result, a);
       fq_zech_pow_ui(&result, &result, -n, mContext);
     }
   else
     fq_zech_pow_ui(&result, &a, n, mContext);
 }
void AutomaticCameraCalibrator::optimize()
{
  if(optimizer == nullptr)
  {
    // since the parameters for the robot pose are correction parameters,
    // an empty RobotPose is used instead of theRobotPose
    optimizationParameters = pack(theCameraCalibration, Pose2f());
    optimizer = new GaussNewtonOptimizer<numOfParameterTranslations>(functor);
    successiveConvergations = 0;
    framesToWait = 0;
  }
  else
  {
    // only do an iteration after some frames have passed
    if(framesToWait <= 0)
    {
      framesToWait = numOfFramesToWait;
      const float delta = optimizer->iterate(optimizationParameters, Parameters::Constant(0.0001f));
      if(!std::isfinite(delta))
      {
        OUTPUT_TEXT("Restart optimize! An optimization error occured!");
        delete optimizer;
        optimizer = nullptr;
        state = Accumulate;
      }
      OUTPUT_TEXT("AutomaticCameraCalibrator: delta = " << delta);

      // the camera calibration is refreshed from the current optimizer state
      Pose2f robotPoseCorrection;
      unpack(optimizationParameters, nextCameraCalibration, robotPoseCorrection);

      if(std::abs(delta) < terminationCriterion)
        ++successiveConvergations;
      else
        successiveConvergations = 0;
      if(successiveConvergations >= minSuccessiveConvergations)
      {
        OUTPUT_TEXT("AutomaticCameraCalibrator: converged!");
        OUTPUT_TEXT("RobotPoseCorrection: " << robotPoseCorrection.translation.x() * 1000.0f
                    << " " << robotPoseCorrection.translation.y() * 1000.0f
                    << " " << robotPoseCorrection.rotation.toDegrees() << "deg");
        currentRobotPose.translation.x() += robotPoseCorrection.translation.x() * 1000.0f;
        currentRobotPose.translation.y() += robotPoseCorrection.translation.y() * 1000.0f;
        currentRobotPose.rotation = Angle::normalize(currentRobotPose.rotation + robotPoseCorrection.rotation);
        abort();

        if(setJointOffsets)
          invert(theCameraCalibration);
      }
    }
    --framesToWait;
  }
}
pair<Mat, Mat> FeaturePointsRANSAC::calculateProjection(vector<pair<string, Point2f> > ffpsAtOrigin, vector<pair<string, Point3f> > mmPointsAtOrigin)
{
	// Construct V
	Mat V(mmPointsAtOrigin.size(), 3, CV_32F);	// As many rows as Ffp's, and 3 cols (x, y, z)
	for (unsigned int i=0; i<mmPointsAtOrigin.size(); ++i) {
		V.at<float>(i, 0) = mmPointsAtOrigin[i].second.x;
		V.at<float>(i, 1) = mmPointsAtOrigin[i].second.y;
		V.at<float>(i, 2) = mmPointsAtOrigin[i].second.z;
	}
	// Construct wx, wy
	Mat wx(mmPointsAtOrigin.size(), 1, CV_32F);
	Mat wy(mmPointsAtOrigin.size(), 1, CV_32F);
	for (unsigned int i=0; i<mmPointsAtOrigin.size(); ++i) {
		wx.at<float>(i, 0) = ffpsAtOrigin[i].second.x;
		wy.at<float>(i, 0) = ffpsAtOrigin[i].second.y;
	}

	// TODO: check if matrix square. If not, use another invert(...) instead of .inv().
	bool useSVD = true;
	if(V.rows==V.cols)
		useSVD = false;

	cout <<  "wx = " << wx << endl;
	cout <<  "wy = " << wy << endl;
	cout <<  "V = " << V << endl;

	Mat s;
	Mat t;

	if(!useSVD) {
		cout << "det(V) = " << determinant(V) << endl;	// Det() of non-symmetric matrix?
		cout <<  "V.inv() = " << V.inv() << endl;
		s = V.inv() * wx;
		t = V.inv() * wy;
	} else {
		Mat Vinv;
		invert(V, Vinv, cv::DECOMP_SVD);
		cout <<  "invert(V) with SVD = " << Vinv << endl;
		s = Vinv * wx;
		t = Vinv * wy;
	}

	cout <<  "s = " << s << endl;
	cout <<  "t = " << t << endl;

	for(unsigned int i=0; i<V.rows; ++i) {
		cout <<  "<v|s> = wx? " << V.row(i).t().dot(s) << " ?= " << wx.row(i) << endl;
		cout <<  "<v|t> = wy? " << V.row(i).t().dot(t) << " ?= " << wy.row(i) << endl;
	}

	return make_pair(s, t);
}
Пример #23
0
//------------------------------------------------------------------------
const trans_affine& trans_affine::parl_to_parl(const double* src,
                                               const double* dst) {
  sx = src[2] - src[0];
  shy = src[3] - src[1];
  shx = src[4] - src[0];
  sy = src[5] - src[1];
  tx = src[0];
  ty = src[1];
  invert();
  multiply(trans_affine(dst[2] - dst[0], dst[3] - dst[1], dst[4] - dst[0],
                        dst[5] - dst[1], dst[0], dst[1]));
  return *this;
}
Пример #24
0
inline
mat< typename detail::promote< T >::type, N >
inv( const mat< T, N >& rhs )
{
    mat< typename detail::promote< T >::type, N > res( rhs );

    if ( !static_cast< bool >( invert( res ) ) )
    {
        throw ::std::runtime_error( "mat<>: inverting singular matrix" );
    }

    return res;
}
Пример #25
0
 /**
  * Inversion operator, i.e. "this->addBefore( ~this ) == Parent".
  * \note Forces are negated and rotated.
  */
 self operator ~() {
   rot_mat_3D<value_type> R(this->Quat.getRotMat());
   self result;
   result.Quat = invert(this->Quat);
   result.AngVelocity = R * (-AngVelocity);
   result.AngAcceleration = R * (-AngAcceleration);
   result.Position = (-this->Position) * R;
   result.Velocity = -((result.AngVelocity % this->Position) + Velocity) * R;
   result.Acceleration = -((result.AngVelocity % (result.AngVelocity % this->Position)) + (value_type(2.0) * result.AngVelocity % Velocity) + (result.AngAcceleration % this->Position) + Acceleration) * R;
   result.Force = -Force * R;
   result.Torque = R * (-Torque); //action-reaction
   return result;
 };
Пример #26
0
void main()
{
	int num;
	scanf("%d", &num);
	num = BinToDec(num);
	DecToBin(num);
	printf("\n inverted bits = ");
	DecToBin(invert(num, 4, 3));
	printf("\n\n0^0 = %d\n", 0^0);
	printf("\n\n1^1 = %d\n", 1^1);
	printf("\n\n1^0 = %d\n", 1^0);
	printf("\n\n0^1 = %d\n", 0^1);
}
Пример #27
0
		gmtl::Vec3f JacobianMatrix::calculateInverse(const Angle& angle, const gmtl::Vec3f& angular)
		{
			gmtl::Matrix33f matrixJ = calculateJacobian(angle);
	
			//gmtl::Matrix<float, 3, 1> velocityMatrix;
			//velocityMatrix[0][0] = velocity[0];
			//velocityMatrix[1][0] = velocity[1];
			//velocityMatrix[2][0] = velocity[2];

			//gmtl::Matrix<float, 3, 1> solution = matrixJ * velocityMatrix;
			//invert(matrixJ);
			return invert(matrixJ) * angular;//gmtl::Vec3f(solution[0][0], solution[1][0], solution[2][0]);
		}
Пример #28
0
int main()
{
	int arr[3][3] = {1,2,3,4,5,6,7,8,9};
	int x = 3;

	invert(arr, x);

	for (int i = 0; i < x; ++i) {
		for (int j = 0; j < 3; ++j) {
			std::cout << arr[i][j] << std::endl;
		}
	}
}
Пример #29
0
int main() {

    {
        // 0111 1010 -> invert 4, 3
        // 0000 1010 (== 10)
        unsigned int result = invert(122, 4, 3);

        printf("result == %u\n", result);
        assert(result == 10);
    }

    {
        // 0111 1010 -> invert 1, 3
        // 0111 0100 (== 116)
        unsigned int result = invert(122, 1, 3);

        printf("result == %u\n", result);
        assert(result == 116);
    }

    return 0;
}
Пример #30
0
int main(void)
{
    int n = 7;
    int p = 16;
    unsigned x = ~0;

    printf("x before:       ");
    print_bits(x, sizeof(x));
    printf("x after invert: ");
    print_bits(invert(x, p, n), sizeof(x));

    return 0;
}