int _tmain(int argc, _TCHAR* argv[])
{
	//Create Matrices of different types and print them
	cv::Mat m1(4, 5, CV_8UC1, cv::Scalar(23));
	printMat1D(m1);

	cv::Mat m2(3, 2, CV_8SC1, cv::Scalar(-27));
	printMat1D(m2);

	cv::Mat m3(5, 3, CV_16UC1, cv::Scalar(1939));
	printMat1D(m3);

	cv::Mat m4(2, 4, CV_16SC1, cv::Scalar(-1961));
	printMat1D(m4);

	cv::Mat m5(5, 3, CV_32SC1, cv::Scalar(23985));
	printMat1D(m5);

	cv::Mat m6(2, 4, CV_32FC1, cv::Scalar(2011.02));
	printMat1D(m6);

	cv::Mat m7(2, 4, CV_64FC1, cv::Scalar(242012.36));
	printMat1D(m7);

	std::getchar();
	return 0;
}
Esempio n. 2
0
TEST(Matrix, shouldCompare) {
  
	Matrix m1(1,1,1);
  Matrix m2(1,1,1);
  Matrix m3(2,1,1);
  Matrix m4(1,2,1);
  Matrix m5(1,1,2);

  CHECK(m1 == m1);
  CHECK(m1 == m2);
  CHECK(m2 == m1);
  CHECK(!(m1 == m3));
  CHECK(!(m1 == m4));
  CHECK(!(m5 == m1));
  CHECK(m5 != m1);

  float v6[] = { 1, 1, 1, 1 };
  Matrix m6(2,2);
  m6.setAll(v6);
  float v7[] = { 1, 1, 1, 1 };
  Matrix m7(2,2);
  m7.setAll(v7);
  float v8[] = { 1, 1, 1, 2 };
  Matrix m8(2,2);
  m8.setAll(v8);

  CHECK(m7 == m6);
  CHECK(!(m8 == m6));
  CHECK(m6 != m8);

  CHECK(m1 != m6);
  CHECK(m6 != m1);

  
}
MatrixXd Utils::calculateHomographyMatrixFromFiveOrtoghonalLines(QList<Line*> firstOrtoghonalLines, QList<Line*> secondOrthogonalLines,
                     QList<Line*> thirdOrthogonalLines, QList<Line*> fourthOrthogonalLines,
                     QList<Line*> fifthOrthogonalLines)
{
    // A * x = b.
    MatrixXd A(5, 6);
    MatrixXd b(5, 1);
    MatrixXd x(5, 1);

    Vector3d l1 = getLineInHomogeneousCoordinates(firstOrtoghonalLines.at(0));
    Vector3d m1 = getLineInHomogeneousCoordinates(firstOrtoghonalLines.at(1));
    Vector3d l2 = getLineInHomogeneousCoordinates(secondOrthogonalLines.at(0));
    Vector3d m2 = getLineInHomogeneousCoordinates(secondOrthogonalLines.at(1));
    Vector3d l3 = getLineInHomogeneousCoordinates(thirdOrthogonalLines.at(0));
    Vector3d m3 = getLineInHomogeneousCoordinates(thirdOrthogonalLines.at(1));
    Vector3d l4 = getLineInHomogeneousCoordinates(fourthOrthogonalLines.at(0));
    Vector3d m4 = getLineInHomogeneousCoordinates(fourthOrthogonalLines.at(1));
    Vector3d l5 = getLineInHomogeneousCoordinates(fifthOrthogonalLines.at(0));
    Vector3d m5 = getLineInHomogeneousCoordinates(fifthOrthogonalLines.at(1));

    b << -l1(1)*m1(1), -l2(1)*m2(1), -l3(1)*m3(1), -l4(1)*m4(1), -l5(1)*m5(1);
    A << l1(0)*m1(0), (l1(0)*m1(1)+l1(1)*m1(0))/2, l1(1)*m1(1), (l1(0)*m1(2)+l1(2)*m1(0))/2, (l1(1)*m1(2)+l1(2)*m1(1))/2, l1(2)*m1(2),
         l2(0)*m2(0), (l2(0)*m2(1)+l2(1)*m2(0))/2, l2(1)*m2(1), (l2(0)*m2(2)+l2(2)*m2(0))/2, (l2(1)*m2(2)+l2(2)*m2(1))/2, l2(2)*m2(2),
         l3(0)*m3(0), (l3(0)*m3(1)+l3(1)*m3(0))/2, l3(1)*m3(1), (l3(0)*m3(2)+l3(2)*m3(0))/2, (l3(1)*m3(2)+l3(2)*m3(1))/2, l3(2)*m3(2),
         l4(0)*m4(0), (l4(0)*m4(1)+l4(1)*m4(0))/2, l4(1)*m4(1), (l4(0)*m4(2)+l4(2)*m4(0))/2, (l4(1)*m4(2)+l4(2)*m4(1))/2, l4(2)*m4(2),
         l5(0)*m5(0), (l5(0)*m5(1)+l5(1)*m5(0))/2, l5(1)*m5(1), (l5(0)*m5(2)+l5(2)*m5(0))/2, (l5(1)*m5(2)+l5(2)*m5(1))/2, l5(2)*m5(2);

   x = A.colPivHouseholderQr().solve(b);

   x/=x(2);

   Matrix3d C;
   C << x(0), x(1)/2, x(3)/2,
        x(1)/2, x(2), x(4)/2,
        x(3)/2, x(4)/2, 1;

   Matrix2d kkt;
   kkt << C(0,0), C(0,1),
          C(1,0), C(1,1);

   MatrixXd vKKt(1,2);
   vKKt << C(2,0), C(2,1);

   MatrixXd V(1,2);
   V = vKKt * kkt.inverse();

   LLT<MatrixXd> llt(kkt);
   MatrixXd U = llt.matrixU();

   MatrixXd J (3,3);
   J << U(0,0), U(0,1),0, U(1,0), U(1,1),0, V(0), V(1), 1;

   return J;
}
Esempio n. 4
0
	void testMat3DeterminantAndInverse() {
		glam::mat3 m5(std::make_pair(M5, &M5[9]));
		float d = glam::determinant(m5);
		TS_ASSERT_DELTA(d, M5D, 1e-6f);
		glam::mat3 m5i = glam::inverse(m5);
		TS_ASSERT_DELTA(m5i[0][0], M5I[0], 1e-6f);
		TS_ASSERT_DELTA(m5i[0][1], M5I[1], 1e-6f);
		TS_ASSERT_DELTA(m5i[0][2], M5I[2], 1e-6f);
		TS_ASSERT_DELTA(m5i[1][0], M5I[3], 1e-6f);
		TS_ASSERT_DELTA(m5i[1][1], M5I[4], 1e-6f);
		TS_ASSERT_DELTA(m5i[1][2], M5I[5], 1e-6f);
		TS_ASSERT_DELTA(m5i[2][0], M5I[6], 1e-6f);
		TS_ASSERT_DELTA(m5i[2][1], M5I[7], 1e-6f);
		TS_ASSERT_DELTA(m5i[2][2], M5I[8], 1e-6f);
	}
Esempio n. 5
0
void Csf::save()
{
    char path[255];
    strcpy(path, "aries/");
    strcpy(path + 6, _path);
    strcpy(path + strlen(path) - 4, ".bone");

    cout << "[SAVE]" << path << endl;
    Util::mkdir(path);
    ofstream fout(path, ios::out|ios::binary);

    uint8 bn = (uint8)_list.size();
    fout.write((char *)&bn, 1);

    for(int i = 0; i < _list.size(); i++)
    {
        CsfBone b = _list[i];

        int8 id = (int8)i;
        fout.write((char *)&id, 1);

        int8 bp = (int8)b.parent;
        fout.write((char *)&bp, 1);

        uint8 bs = strlen(b.name);
        fout.write((char *)&bs, 1);
        fout.write((char *)b.name, bs);


	    Matrix4f m4 = Matrix4f::TransMat(b.invpos.x, b.invpos.y, b.invpos.z);
	    Matrix4f m5(Quaternion(b.invrot.x, b.invrot.y, b.invrot.z, b.invrot.w));
        Matrix4f m6 = m5 * m4;

        //cout << "====================================" << endl;
        //m6.print();
        //getMatById(i)->inverted().print();

        //fout.write((char *)m6.inverted().x, 4 * 16);
        fout.write((char *)(getMatById(i)->x), 4 * 16);
    }

    fout.close();
}
Esempio n. 6
0
/*int testMat3Implementation()
{
    int nrOfErrors = 0;
    
    std::cout << "Testing mat3 class" << std::endl;
    
    float a1[] = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f};
    float a2[] = {3.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 1.0f};
    float a3[] = {4.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 1.0f, 1.0f, 2.0f};
    
    egc::mat3 m1(a1), m2(a2), m3(a3), m4;
    
    m4 = m1 + m2;
    if(m4 == m3)
        std::cout << "\tCorrect + operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect + operation" << std::endl;
        nrOfErrors++;
    }
    
    float a5[] = {3.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 3.0f, 3.0f, 3.0f};
    egc::mat3 m5(a5);
    
    m4 = m1 * 3.0f;
    if(m4 == m5)
        std::cout << "\tCorrect * (with scalar value) operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect * (with scalar value) operation" << std::endl;
        nrOfErrors++;
    }

    float a6[] = {3.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 1.0f, 1.0f, 1.0f};
    egc::mat3 m6(a6);
    
    m4 = m1 * m2;
    if(m4 == m6)
        std::cout << "\tCorrect * (with another matrix) operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect * (with another matrix) operation" << std::endl;
        nrOfErrors++;
    }

    egc::vec3 v1(1.0f, 1.0f, 1.0f);
    egc::vec3 v2(4.0f, 4.0f, 1.0f);
    egc::vec3 v3;
    
    v3 = m4 * v1;
    if(v3 == v2)
        std::cout << "\tCorrect * (with a vec3) operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect * (with a vec3) operation" << std::endl;
        nrOfErrors++;
    }
    
    float a7[] = {-4.0f, 0.0f, 1.0f, -3.0f, 2.0f, 4.0f, 3.0f, -2.0f, -1.0f};
    egc::mat3 m7(a7);
    
    if(std::abs(m7.determinant() + 24.0f) < std::numeric_limits<float>::epsilon())
        std::cout << "\tCorrect determinant operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect determinant operation" << std::endl;
        nrOfErrors++;
    }
    
    float a8[] = {-4.0f, -3.0f, 3.0f, 0.0f, 2.0f, -2.0f, 1.0f, 4.0f, -1.0f};
    egc::mat3 m8(a8);
    
    if(m7.transpose() == m8)
        std::cout << "\tCorrect transpose operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect transpose operation" << std::endl;
        nrOfErrors++;
    }
    
    float a9[] = {-1.0f/4.0f, 1.0f/12.0f, 1.0f/12.0f, -3.0f/8.0f, -1.0f/24.0f, -13.00f/24.0f, 0.0f, 1.0f/3.0f, 1.0f/3.0f};
    egc::mat3 m9(a9);
    
    if(m7.inverse() == m9)
        std::cout << "\tCorrect inverse operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect inverse operation" << std::endl;
        nrOfErrors++;
    }
    
    return nrOfErrors;
}
*/
int testMat4Implementation()
{
    int nrOfErrors = 0;
    
    std::cout << "Testing mat4 class" << std::endl;
    
    float a1[] = {1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f};
    float a2[] = {3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f};
    float a3[] = {4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 0.0f, 0.0f, 0.0f, 4.0f, 0.0f, 1.0f, 1.0f, 1.0f, 2.0f};
    
    egc::mat4 m1(a1), m2(a2), m3(a3), m4;
    
    m4 = m1 + m2;
    if(m4 == m3)
        std::cout << "\tCorrect + operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect + operation" << std::endl;
        nrOfErrors++;
    }
    
    float a5[] = {3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 3.0f, 3.0f, 3.0f, 3.0f};
    egc::mat4 m5(a5);
    
    m4 = m1 * 3.0f;
    if(m4 == m5)
        std::cout << "\tCorrect * (with scalar value) operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect * (with scalar value) operation" << std::endl;
        nrOfErrors++;
    }
    
    float a6[] = {3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 0.0f, 0.0f, 0.0f, 3.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f};
    egc::mat4 m6(a6);
    
    m4 = m1 * m2;
    if(m4 == m6)
        std::cout << "\tCorrect * (with another matrix) operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect * (with another matrix) operation" << std::endl;
        nrOfErrors++;
    }
    
    egc::vec4 v1(1.0f, 1.0f, 1.0f, 1.0f);
    egc::vec4 v2(4.0f, 4.0f, 4.0f, 1.0f);
    egc::vec4 v3;
    
    v3 = m4 * v1;
    if(v3 == v2)
        std::cout << "\tCorrect * (with a vec4) operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect * (with a vec4) operation" << std::endl;
        nrOfErrors++;
    }
    
    
    float a7[] = {3.0f, 4.0f, 3.0f, 9.0f, 2.0f, 0.0f, 0.0f, 2.0f, 0.0f, 1.0f, 2.0f, 3.0f, 1.0f, 2.0f, 1.0f, 1.0f};
    egc::mat4 m7(a7);
    
    if(std::abs(m7.determinant() - 24.0f) < std::numeric_limits<float>::epsilon())
        std::cout << "\tCorrect determinant operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect determinant operation" << std::endl;
        nrOfErrors++;
    }
    
    float a8[] = {3.0f, 2.0f, 0.0f, 1.0f, 4.0f, 0.0f, 1.0f, 2.0f, 3.0f, 0.0f, 2.0f, 1.0f, 9.0f, 2.0f, 3.0f, 1.0f};
    egc::mat4 m8(a8);
    
    if(m7.transpose() == m8)
        std::cout << "\tCorrect transpose operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect transpose operation" << std::endl;
        nrOfErrors++;
    }
    
    float a9[] = {-1.0f/4.0f, 2.0f/3.0f, 1.0f/6.0f, 5.0f/12.0f, 1.0f/4.0f, -1.0f/2.0f, -1.0/2.0f, 1.0f/4.0f, -1.0f/2.0f, 1.0f/2.0f, 1.0f, 1.0f/2.0f, 1.0f/4.0f, -1.0f/6.0f, -1.0/6.0f, -5.0f/12.0f};
    egc::mat4 m9(a9);
    
    if(m7.inverse() == m9)
        std::cout << "\tCorrect inverse operation" << std::endl;
    else
    {
        std::cout << "\tIncorrect inverse operation" << std::endl;
        nrOfErrors++;
    }
    
    return nrOfErrors;
}
void MatrixTest::test_constructor(void)
{
   message += "test_constructor\n";

   std::string file_name = "../data/matrix.dat";

   // Default

   Matrix<size_t> m1;

   assert_true(m1.get_rows_number() == 0, LOG);
   assert_true(m1.get_columns_number() == 0, LOG);

   // Rows and columns numbers

   Matrix<size_t> m2(0, 0);

   assert_true(m2.get_rows_number() == 0, LOG);
   assert_true(m2.get_columns_number() == 0, LOG);
  
   Matrix<double> m3(1, 1, 1.0);
   assert_true(m3.get_rows_number() == 1, LOG);
   assert_true(m3.get_columns_number() == 1, LOG);

   // Rows and columns numbers and initialization

   Matrix<size_t> m4(0, 0, 1);

   assert_true(m4.get_rows_number() == 0, LOG);
   assert_true(m4.get_columns_number() == 0, LOG);

   Matrix<size_t> m5(1, 1, 1);

   assert_true(m5.get_rows_number() == 1, LOG);
   assert_true(m5.get_columns_number() == 1, LOG);
   assert_true(m5 == true, LOG);

   // File constructor

   m1.save(file_name);

   Matrix<size_t> m6(file_name);
   assert_true(m6.get_rows_number() == 0, LOG);
   assert_true(m6.get_columns_number() == 0, LOG);

   m2.save(file_name);
   Matrix<size_t> m7(file_name);
   assert_true(m7.get_rows_number() == 0, LOG);
   assert_true(m7.get_columns_number() == 0, LOG);

   m3.save(file_name);

   Matrix<double> m8(file_name);
   assert_true(m8.get_rows_number() == 1, LOG);
   assert_true(m8.get_columns_number() == 1, LOG);

   m4.save(file_name);
   Matrix<size_t> m9(file_name);
   assert_true(m9.get_rows_number() == 0, LOG);
   assert_true(m9.get_columns_number() == 0, LOG);

   m5.save(file_name);

   Matrix<size_t> m10(file_name);
   assert_true(m10.get_rows_number() == 1, LOG);
   assert_true(m10.get_columns_number() == 1, LOG);
   assert_true(m10 == true, LOG); 

   // Copy constructor

   Matrix<double> a5;
   Matrix<double> b5(a5);

   assert_true(b5.get_rows_number() == 0, LOG);
   assert_true(b5.get_columns_number() == 0, LOG);

   Matrix<size_t> a6(1, 1, true);

   Matrix<size_t> b6(a6);

   assert_true(b6.get_rows_number() == 1, LOG);
   assert_true(b6.get_columns_number() == 1, LOG);
   assert_true(b6 == true, LOG);

   // Operator ++

   Matrix<size_t> m11(2, 2, 0);
   m11(0,0)++;
   m11(1,1)++;

   assert_true(m11(0,0) == 1, LOG);
   assert_true(m11(0,1) == 0, LOG);
   assert_true(m11(1,0) == 0, LOG);
   assert_true(m11(1,1) == 1, LOG);
}
Esempio n. 8
0
void snoopy()
{
   TGeoManager *geom = new TGeoManager("snoopy", "Snoopy Detector");

   // define some materials
   TGeoMaterial *matVacuum = new TGeoMaterial("Vacuum", 0, 0, 0);
   TGeoMaterial *matAl     = new TGeoMaterial("Al", 26.98, 13, 2.7);
   TGeoMaterial *matFe     = new TGeoMaterial("Fe", 55.84, 26, 7.9);
      
   // define some media
   TGeoMedium *Vacuum = new TGeoMedium("Vacuum", 1, matVacuum);
   TGeoMedium *Al     = new TGeoMedium("Al", 2, matAl);
   TGeoMedium *Fe     = new TGeoMedium("Fe", 3, matFe);
      
   // create top volume
   TGeoVolume *top = geom->MakeBox("top", Vacuum, 600, 600, 2500);
   geom->SetTopVolume(top);
   geom->SetTopVisible(0);
   
   // first part of vacuum chamber up to veto station
   TGeoVolume *tub1 = geom->MakeTube("tub1", Al, 245, 250, 50);
   tub1->SetLineColor(18);  // silver/gray
   top->AddNode(tub1, 1, new TGeoTranslation(0, 0, -2450));
   
   // veto station
   TGeoBBox *detbox1 = new TGeoBBox("detbox1", 250, 250, 10);
   TGeoBBox *detbox2 = new TGeoBBox("detbox2", 245, 245, 10);
   
   TGeoCompositeShape *detcomp1 = new TGeoCompositeShape("detcomp1", "detbox1-detbox2");
   TGeoVolume *det1 = new TGeoVolume("det1", detcomp1,Vacuum);
   det1->SetLineColor(kRed);
   top->AddNode(det1, 1, new TGeoTranslation(0, 0, -2390));
   TGeoRotation r0;
   r0.SetAngles(15,0,0);
   TGeoTranslation t0(0, 0, -2370);
   TGeoCombiTrans c0(t0, r0);
   TGeoHMatrix *h0 = new TGeoHMatrix(c0);
   top->AddNode(det1, 11, h0);
   
   // second part of vacuum chamber up to first tracking station
   TGeoVolume *tub2 = geom->MakeTube("tub2", Al, 245, 250, 3880/2);  // 1890
   tub2->SetLineColor(18);
   top->AddNode(tub2, 1, new TGeoTranslation(0, 0, -440));
   
   // tracking station 1
   top->AddNode(det1, 2, new TGeoTranslation(0, 0, 1510));
   TGeoRotation r1;
   r1.SetAngles(15,0,0);
   TGeoTranslation t1(0, 0, 1530);
   TGeoCombiTrans c1(t1, r1);
   TGeoHMatrix *h1 = new TGeoHMatrix(c1);
   top->AddNode(det1, 3, h1);
   
   // third part of vacuum chamber up to second tracking station
   TGeoVolume *tub3 = geom->MakeTube("tub3", Al, 245, 250, 80);
   tub3->SetLineColor(18);
   top->AddNode(tub3, 1, new TGeoTranslation(0, 0, 1620));
   
   // tracking station 2
   top->AddNode(det1, 4, new TGeoTranslation(0, 0, 1710));
   TGeoRotation r2;
   r2.SetAngles(15,0,0);
   TGeoTranslation t2(0, 0, 1730);
   TGeoCombiTrans c2(t2, r2);
   TGeoHMatrix *h2 = new TGeoHMatrix(c2);
   top->AddNode(det1, 5, h2);
 
   // fourth part of vacuum chamber up to third tracking station and being covered by magnet
   TGeoVolume *tub4 = geom->MakeTube("tub4", Al, 245, 250, 200);
   tub4->SetLineColor(18);
   top->AddNode(tub4, 1, new TGeoTranslation(0, 0, 1940));

   // magnet yoke
   TGeoBBox *magyoke1 = new TGeoBBox("magyoke1", 350, 350, 125);
   TGeoBBox *magyoke2 = new TGeoBBox("magyoke2", 250, 250, 126);
   
   TGeoCompositeShape *magyokec = new TGeoCompositeShape("magyokec", "magyoke1-magyoke2");
   TGeoVolume *magyoke = new TGeoVolume("magyoke", magyokec, Fe);
   magyoke->SetLineColor(kBlue);
   //magyoke->SetTransparency(50);
   top->AddNode(magyoke, 1, new TGeoTranslation(0, 0, 1940));

   // magnet
   TGeoTubeSeg *magnet1a = new TGeoTubeSeg("magnet1a", 250, 300, 35, 45, 135);
   TGeoTubeSeg *magnet1b = new TGeoTubeSeg("magnet1b", 250, 300, 35, 45, 135);
   TGeoTubeSeg *magnet1c = new TGeoTubeSeg("magnet1c", 250, 270, 125, 45, 60);
   TGeoTubeSeg *magnet1d = new TGeoTubeSeg("magnet1d", 250, 270, 125, 120, 135);

   // magnet composite shape matrices   
   TGeoTranslation *m1 = new TGeoTranslation(0, 0, 160);
   m1->SetName("m1");
   m1->RegisterYourself();
   TGeoTranslation *m2 = new TGeoTranslation(0, 0, -160);
   m2->SetName("m2");
   m2->RegisterYourself();

   TGeoCompositeShape *magcomp1 = new TGeoCompositeShape("magcomp1", "magnet1a:m1+magnet1b:m2+magnet1c+magnet1d");
   TGeoVolume *magnet1 = new TGeoVolume("magnet1", magcomp1, Fe);
   magnet1->SetLineColor(kYellow);
   top->AddNode(magnet1, 1, new TGeoTranslation(0, 0, 1940));

   TGeoRotation m3;
   m3.SetAngles(180, 0, 0);
   TGeoTranslation m4(0, 0, 1940);
   TGeoCombiTrans m5(m4, m3);
   TGeoHMatrix *m6 = new TGeoHMatrix(m5);
   top->AddNode(magnet1, 2, m6);

   // tracking station 3
   top->AddNode(det1, 6, new TGeoTranslation(0, 0, 2150));
   TGeoRotation r3;
   r3.SetAngles(15,0,0);
   TGeoTranslation t3(0, 0, 2170);
   TGeoCombiTrans c3(t3, r3);
   TGeoHMatrix *h3 = new TGeoHMatrix(c3);
   top->AddNode(det1, 7, h3);
   
   // fifth part of vacuum chamber up to fourth tracking station
   TGeoVolume *tub5 = geom->MakeTube("tub5", Al, 245, 250, 90);
   tub5->SetLineColor(18);
   top->AddNode(tub5, 1, new TGeoTranslation(0, 0, 2270));

   // tracking station 4
   top->AddNode(det1, 8, new TGeoTranslation(0, 0, 2370));
   TGeoRotation r4;
   r4.SetAngles(15,0,0);
   TGeoTranslation t4(0, 0, 2390);
   TGeoCombiTrans c4(t4, r4);
   TGeoHMatrix *h4 = new TGeoHMatrix(c4);
   top->AddNode(det1, 9, h4);

   // ecal
   TGeoVolume *ecal = geom->MakeBox("ecal", Al, 250, 250, 40);
   ecal->SetLineColor(6); // purple
   top->AddNode(ecal, 1, new TGeoTranslation(0, 0, 2440)); 
   
   // muon filter
   TGeoVolume *muonfilter = geom->MakeBox("muonfilter", Al, 250, 250, 20);
   muonfilter->SetLineColor(kGreen);
   top->AddNode(muonfilter, 1, new TGeoTranslation(0, 0, 2500));

   // sixth part of vacuum chamber up to muon detector
   TGeoVolume *tub6 = geom->MakeTube("tub6", Al, 245, 250, 20);
   tub6->SetLineColor(18);
   top->AddNode(tub6, 1, new TGeoTranslation(0, 0, 2540));

   // muon detector
   top->AddNode(det1, 10, new TGeoTranslation(0, 0, 2570));
   TGeoRotation r5;
   r5.SetAngles(15,0,0);
   TGeoTranslation t5(0, 0, 2590);
   TGeoCombiTrans c5(t5, r5);
   TGeoHMatrix *h5 = new TGeoHMatrix(c5);
   top->AddNode(det1, 12, h5);
   
   geom->CloseGeometry();   
   top->Draw("ogl");
   geom->Export("snoopy.gdml");

}
Esempio n. 9
0
int main() try 
{
    // Several ways to create and initialize band matrices:

    // Create with uninitialized values
    tmv::BandMatrix<double> m1(6,6,1,2);
    for(int i=0;i<m1.nrows();i++) 
        for(int j=0;j<m1.ncols();j++) 
            if (i<=j+m1.nlo() && j<=i+m1.nhi())
                m1(i,j) = 3.*i-j*j+7.; 
    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )

    // Create with all 2's.
    tmv::BandMatrix<double> m2(6,6,1,3,2.);
    std::cout<<"m2 =\n"<<m2;
    //! m2 =
    //! 6  6  
    //! ( 2  2  2  2  0  0 )
    //! ( 2  2  2  2  2  0 )
    //! ( 0  2  2  2  2  2 )
    //! ( 0  0  2  2  2  2 )
    //! ( 0  0  0  2  2  2 )
    //! ( 0  0  0  0  2  2 )

    // A BandMatrix can be non-square:
    tmv::BandMatrix<double> m3(6,8,1,3,2.);
    std::cout<<"m3 =\n"<<m3;
    //! m3 =
    //! 6  8  
    //! ( 2  2  2  2  0  0  0  0 )
    //! ( 2  2  2  2  2  0  0  0 )
    //! ( 0  2  2  2  2  2  0  0 )
    //! ( 0  0  2  2  2  2  2  0 )
    //! ( 0  0  0  2  2  2  2  2 )
    //! ( 0  0  0  0  2  2  2  2 )

    // Create from given elements:
    double mm[20] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20};
    tmv::BandMatrix<double,tmv::ColMajor> m4(6,6,2,1);
    std::copy(mm,mm+20,m4.colmajor_begin());
    std::cout<<"m4 (ColMajor) =\n"<<m4;
    //! m4 (ColMajor) =
    //! 6  6  
    //! ( 1  4  0  0  0  0 )
    //! ( 2  5  8  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  7  10  13  16  0 )
    //! ( 0  0  11  14  17  19 )
    //! ( 0  0  0  15  18  20 )
    tmv::BandMatrix<double,tmv::RowMajor> m5(6,6,2,1);
    std::copy(mm,mm+20,m5.rowmajor_begin());
    std::cout<<"m5 (RowMajor) =\n"<<m5;
    //! m5 (RowMajor) =
    //! 6  6  
    //! ( 1  2  0  0  0  0 )
    //! ( 3  4  5  0  0  0 )
    //! ( 6  7  8  9  0  0 )
    //! ( 0  10  11  12  13  0 )
    //! ( 0  0  14  15  16  17 )
    //! ( 0  0  0  18  19  20 )
    tmv::BandMatrix<double,tmv::DiagMajor> m6(6,6,2,1);
    std::copy(mm,mm+20,m6.diagmajor_begin());
    std::cout<<"m6 (DiagMajor) =\n"<<m6;
    //! m6 (DiagMajor) =
    //! 6  6  
    //! ( 10  16  0  0  0  0 )
    //! ( 5  11  17  0  0  0 )
    //! ( 1  6  12  18  0  0 )
    //! ( 0  2  7  13  19  0 )
    //! ( 0  0  3  8  14  20 )
    //! ( 0  0  0  4  9  15 )

    // Can make from the banded portion of a regular Matrix:
    tmv::Matrix<double> xm(6,6);
    for(int i=0;i<xm.nrows();i++) 
        for(int j=0;j<xm.ncols();j++) 
            xm(i,j) = 5.*i-j*j+3.; 
    tmv::BandMatrix<double> m7(xm,3,2);
    std::cout<<"m7 =\n"<<m7;
    //! m7 =
    //! 6  6  
    //! ( 3  2  -1  0  0  0 )
    //! ( 8  7  4  -1  0  0 )
    //! ( 13  12  9  4  -3  0 )
    //! ( 18  17  14  9  2  -7 )
    //! ( 0  22  19  14  7  -2 )
    //! ( 0  0  24  19  12  3 )
    // Or from a wider BandMatrix:
    tmv::BandMatrix<double> m8(m7,3,0);
    std::cout<<"m8 =\n"<<m8;
    //! m8 =
    //! 6  6  
    //! ( 3  0  0  0  0  0 )
    //! ( 8  7  0  0  0  0 )
    //! ( 13  12  9  0  0  0 )
    //! ( 18  17  14  9  0  0 )
    //! ( 0  22  19  14  7  0 )
    //! ( 0  0  24  19  12  3 )

    // Shortcuts to Bi- and Tri-diagonal matrices:
    tmv::Vector<double> v1(5,1.);
    tmv::Vector<double> v2(6,2.);
    tmv::Vector<double> v3(5,3.);
    tmv::BandMatrix<double> m9 = LowerBiDiagMatrix(v1,v2);
    tmv::BandMatrix<double> m10 = UpperBiDiagMatrix(v2,v3);
    tmv::BandMatrix<double> m11 = TriDiagMatrix(v1,v2,v3);
    std::cout<<"LowerBiDiagMatrix(v1,v2) =\n"<<m9;
    //! LowerBiDiagMatrix(v1,v2) =
    //! 6  6  
    //! ( 2  0  0  0  0  0 )
    //! ( 1  2  0  0  0  0 )
    //! ( 0  1  2  0  0  0 )
    //! ( 0  0  1  2  0  0 )
    //! ( 0  0  0  1  2  0 )
    //! ( 0  0  0  0  1  2 )
    std::cout<<"UpperBiDiagMatrix(v2,v3) =\n"<<m10;
    //! UpperBiDiagMatrix(v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 0  2  3  0  0  0 )
    //! ( 0  0  2  3  0  0 )
    //! ( 0  0  0  2  3  0 )
    //! ( 0  0  0  0  2  3 )
    //! ( 0  0  0  0  0  2 )
    std::cout<<"TriDiagMatrix(v1,v2,v3) =\n"<<m11;
    //! TriDiagMatrix(v1,v2,v3) =
    //! 6  6  
    //! ( 2  3  0  0  0  0 )
    //! ( 1  2  3  0  0  0 )
    //! ( 0  1  2  3  0  0 )
    //! ( 0  0  1  2  3  0 )
    //! ( 0  0  0  1  2  3 )
    //! ( 0  0  0  0  1  2 )


    // Norms, etc. 

    std::cout<<"Norm1(m1) = "<<Norm1(m1)<<std::endl;
    //! Norm1(m1) = 30
    std::cout<<"Norm2(m1) = "<<Norm2(m1)<<std::endl;
    //! Norm2(m1) = 24.0314
    std::cout<<"NormInf(m1) = "<<NormInf(m1)<<std::endl;
    //! NormInf(m1) = 28
    std::cout<<"NormF(m1) = "<<NormF(m1)<<" = "<<Norm(m1)<<std::endl;
    //! NormF(m1) = 32.0312 = 32.0312
    std::cout<<"MaxAbsElement(m1) = "<<MaxAbsElement(m1)<<std::endl;
    //! MaxAbsElement(m1) = 12
    std::cout<<"Trace(m1) = "<<Trace(m1)<<std::endl;
    //! Trace(m1) = 32
    std::cout<<"Det(m1) = "<<Det(m1)<<std::endl;
    //! Det(m1) = 67635


    // Views:

    std::cout<<"m1 =\n"<<m1;
    //! m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"m1.diag() = "<<m1.diag()<<std::endl;
    //! m1.diag() = 6  ( 7  9  9  7  3  -3 )
    std::cout<<"m1.diag(1) = "<<m1.diag(1)<<std::endl;
    //! m1.diag(1) = 5  ( 6  6  4  0  -6 )
    std::cout<<"m1.diag(-1) = "<<m1.diag(-1)<<std::endl;
    //! m1.diag(-1) = 5  ( 10  12  12  10  6 )
    std::cout<<"m1.subBandMatrix(0,3,0,3,1,1) =\n"<<
        m1.subBandMatrix(0,3,0,3,1,1);
    //! m1.subBandMatrix(0,3,0,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"m1.transpose() =\n"<<m1.transpose();
    //! m1.transpose() =
    //! 6  6  
    //! ( 7  10  0  0  0  0 )
    //! ( 6  9  12  0  0  0 )
    //! ( 3  6  9  12  0  0 )
    //! ( 0  1  4  7  10  0 )
    //! ( 0  0  -3  0  3  6 )
    //! ( 0  0  0  -9  -6  -3 )

    // rowRange, colRange shrink both dimensions of the matrix to include only
    // the portions that are in those rows or columns:
    std::cout<<"m1.rowRange(0,4) =\n"<<m1.rowRange(0,4);
    //! m1.rowRange(0,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"m1.colRange(1,4) =\n"<<m1.colRange(1,4);
    //! m1.colRange(1,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"m1.diagRange(0,2) =\n"<<m1.diagRange(0,2);
    //! m1.diagRange(0,2) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"m1.diagRange(-1,1) =\n"<<m1.diagRange(-1,1);
    //! m1.diagRange(-1,1) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Fortran Indexing:

    tmv::BandMatrix<double,tmv::FortranStyle> fm1 = m1;
    std::cout<<"fm1 = m1 =\n"<<fm1;
    //! fm1 = m1 =
    //! 6  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    //! ( 0  0  0  10  3  -6 )
    //! ( 0  0  0  0  6  -3 )
    std::cout<<"fm1(1,1) = "<<fm1(1,1)<<std::endl;
    //! fm1(1,1) = 7
    std::cout<<"fm1(4,3) = "<<fm1(4,3)<<std::endl;
    //! fm1(4,3) = 12
    std::cout<<"fm1.subBandMatrix(1,3,1,3,1,1) =\n"<<
        fm1.subBandMatrix(1,3,1,3,1,1);
    //! fm1.subBandMatrix(1,3,1,3,1,1) =
    //! 3  3  
    //! ( 7  6  0 )
    //! ( 10  9  6 )
    //! ( 0  12  9 )
    std::cout<<"fm1.rowRange(1,4) =\n"<<fm1.rowRange(1,4);
    //! fm1.rowRange(1,4) =
    //! 4  6  
    //! ( 7  6  3  0  0  0 )
    //! ( 10  9  6  1  0  0 )
    //! ( 0  12  9  4  -3  0 )
    //! ( 0  0  12  7  0  -9 )
    std::cout<<"fm1.colRange(2,4) =\n"<<fm1.colRange(2,4);
    //! fm1.colRange(2,4) =
    //! 5  3  
    //! ( 6  3  0 )
    //! ( 9  6  1 )
    //! ( 12  9  4 )
    //! ( 0  12  7 )
    //! ( 0  0  10 )
    std::cout<<"fm1.diagRange(0,1) =\n"<<fm1.diagRange(0,1);
    //! fm1.diagRange(0,1) =
    //! 6  6  
    //! ( 7  6  0  0  0  0 )
    //! ( 0  9  6  0  0  0 )
    //! ( 0  0  9  4  0  0 )
    //! ( 0  0  0  7  0  0 )
    //! ( 0  0  0  0  3  -6 )
    //! ( 0  0  0  0  0  -3 )
    std::cout<<"fm1.diagRange(-1,0) =\n"<<fm1.diagRange(-1,0);
    //! fm1.diagRange(-1,0) =
    //! 6  6  
    //! ( 7  0  0  0  0  0 )
    //! ( 10  9  0  0  0  0 )
    //! ( 0  12  9  0  0  0 )
    //! ( 0  0  12  7  0  0 )
    //! ( 0  0  0  10  3  0 )
    //! ( 0  0  0  0  6  -3 )


    // Matrix arithmetic:

    tmv::BandMatrix<double> m1pm2 = m1 + m2;
    std::cout<<"m1 + m2 =\n"<<m1pm2;
    //! m1 + m2 =
    //! 6  6  
    //! ( 9  8  5  2  0  0 )
    //! ( 12  11  8  3  2  0 )
    //! ( 0  14  11  6  -1  2 )
    //! ( 0  0  14  9  2  -7 )
    //! ( 0  0  0  12  5  -4 )
    //! ( 0  0  0  0  8  -1 )
    // Works correctly even if matrices are stored in different order:
    tmv::BandMatrix<double> m5pm6 = m5 + m6; 
    std::cout<<"m5 + m6 =\n"<<m5pm6;
    //! m5 + m6 =
    //! 6  6  
    //! ( 11  18  0  0  0  0 )
    //! ( 8  15  22  0  0  0 )
    //! ( 7  13  20  27  0  0 )
    //! ( 0  12  18  25  32  0 )
    //! ( 0  0  17  23  30  37 )
    //! ( 0  0  0  22  28  35 )
    // Also expands the number of off-diagonals appropriately as needed:
    tmv::BandMatrix<double> m2pm4 = m2 + m4; 
    std::cout<<"m2 + m4 =\n"<<m2pm4;
    //! m2 + m4 =
    //! 6  6  
    //! ( 3  6  2  2  0  0 )
    //! ( 4  7  10  2  2  0 )
    //! ( 3  8  11  14  2  2 )
    //! ( 0  7  12  15  18  2 )
    //! ( 0  0  11  16  19  21 )
    //! ( 0  0  0  15  20  22 )

    m1 *= 2.;
    std::cout<<"m1 *= 2 =\n"<<m1;
    //! m1 *= 2 =
    //! 6  6  
    //! ( 14  12  6  0  0  0 )
    //! ( 20  18  12  2  0  0 )
    //! ( 0  24  18  8  -6  0 )
    //! ( 0  0  24  14  0  -18 )
    //! ( 0  0  0  20  6  -12 )
    //! ( 0  0  0  0  12  -6 )

    m2 += m1;
    std::cout<<"m2 += m1 =\n"<<m2;
    //! m2 += m1 =
    //! 6  6  
    //! ( 16  14  8  2  0  0 )
    //! ( 22  20  14  4  2  0 )
    //! ( 0  26  20  10  -4  2 )
    //! ( 0  0  26  16  2  -16 )
    //! ( 0  0  0  22  8  -10 )
    //! ( 0  0  0  0  14  -4 )

    tmv::Vector<double> v = xm.col(0);
    std::cout<<"v = "<<v<<std::endl;
    //! v = 6  ( 3  8  13  18  23  28 )
    std::cout<<"m1 * v = "<<m1*v<<std::endl;
    //! m1 * v = 6  ( 216  396  432  60  162  108 )
    std::cout<<"v * m1 = "<<v*m1<<std::endl;
    //! v * m1 = 6  ( 202  492  780  832  396  -768 )

    // Matrix * matrix product also expands bands appropriately:
    tmv::BandMatrix<double> m1m2 = m1 * m2; 
    std::cout<<"m1 * m2 =\n"<<m1m2;
    //! m1 * m2 =
    //! 6  6  
    //! ( 488  592  400  136  0  12 )
    //! ( 716  952  704  264  -8  -8 )
    //! ( 528  948  904  272  -56  -32 )
    //! ( 0  624  844  464  -320  -104 )
    //! ( 0  0  520  452  -80  -332 )
    //! ( 0  0  0  264  12  -96 )

    // Can mix BandMatrix with other kinds of matrices:
    std::cout<<"xm * m1 =\n"<<xm*m1;
    //! xm * m1 =
    //! 6  6  
    //! ( 82  48  -120  -348  -336  396 )
    //! ( 252  318  180  -128  -276  216 )
    //! ( 422  588  480  92  -216  36 )
    //! ( 592  858  780  312  -156  -144 )
    //! ( 762  1128  1080  532  -96  -324 )
    //! ( 932  1398  1380  752  -36  -504 )
    tmv::UpperTriMatrix<double> um(xm);
    std::cout<<"um + m1 =\n"<<um+m1;
    //! um + m1 =
    //! 6  6  
    //! ( 17  14  5  -6  -13  -22 )
    //! ( 20  25  16  1  -8  -17 )
    //! ( 0  24  27  12  -9  -12 )
    //! ( 0  0  24  23  2  -25 )
    //! ( 0  0  0  20  13  -14 )
    //! ( 0  0  0  0  12  -3 )
    tmv::LowerTriMatrix<double> lm(xm);
    lm *= m8;
    std::cout<<"lm *= m8 =\n"<<lm;
    //! lm *= m8 =
    //! 6  6  
    //! ( 9  0  0  0  0  0 )
    //! ( 80  49  0  0  0  0 )
    //! ( 252  192  81  0  0  0 )
    //! ( 534  440  252  81  0  0 )
    //! ( 744  774  500  224  49  0 )
    //! ( 954  1064  782  396  120  9 )
    tmv::DiagMatrix<double> dm(xm);
    m1 *= dm;
    std::cout<<"m1 *= dm =\n"<<m1;
    //! m1 *= dm =
    //! 6  6  
    //! ( 42  84  54  0  0  0 )
    //! ( 60  126  108  18  0  0 )
    //! ( 0  168  162  72  -42  0 )
    //! ( 0  0  216  126  0  -54 )
    //! ( 0  0  0  180  42  -36 )
    //! ( 0  0  0  0  84  -18 )
    return 0;
} catch (tmv::Error& e) {
    std::cerr<<e<<std::endl;
    return 1;
}
Esempio n. 10
0
int main(int, char** argv)
{
    verbose = getenv("PEGASUS_TEST_VERBOSE") ? true : false;

    try
    {
        CIMMethod m1(CIMName ("getHostName"), CIMTYPE_STRING);
        m1.addQualifier(CIMQualifier(CIMName ("stuff"), true));
        m1.addQualifier(CIMQualifier(CIMName ("stuff2"), true));
        m1.addParameter(CIMParameter(CIMName ("ipaddress"), CIMTYPE_STRING));


        // Tests for Qualifiers
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 2);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuf")) == PEG_NOT_FOUND);

        Uint32 posQualifier;
        posQualifier = m1.findQualifier(CIMName ("stuff"));
        PEGASUS_TEST_ASSERT(posQualifier != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(posQualifier < m1.getQualifierCount());

        m1.removeQualifier(posQualifier);
        PEGASUS_TEST_ASSERT(m1.getQualifierCount() == 1);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(
            m1.findQualifier(CIMName ("stuff2")) != PEG_NOT_FOUND);

        // Tests for Parameters
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.findParameter(
            CIMName ("noparam"))  == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(m1.getParameterCount()  == 1);
        CIMParameter cp = m1.getParameter(
            m1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cp.getName() == CIMName ("ipaddress"));

        m1.removeParameter (m1.findParameter (
            CIMName (CIMName ("ipaddress"))));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 0);
        m1.addParameter (CIMParameter (CIMName ("ipaddress"),
                                       CIMTYPE_STRING));
        PEGASUS_TEST_ASSERT (m1.getParameterCount ()  == 1);

        // throws OutOfBounds
        try
        {
            m1.removeParameter (1);
        }
        catch (IndexOutOfBoundsException & oob)
        {
            if (verbose)
            {
                PEGASUS_STD (cout) << "Caught expected exception: "
                                   << oob.getMessage () << PEGASUS_STD (endl);
            }
        }

        CIMMethod m2(CIMName ("test"), CIMTYPE_STRING);
        m2.setName(CIMName ("getVersion"));
        PEGASUS_TEST_ASSERT(m2.getName() == CIMName ("getVersion"));

        m2.setType(CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(m2.getType() == CIMTYPE_STRING);

        m2.setClassOrigin(CIMName ("test"));
        PEGASUS_TEST_ASSERT(m2.getClassOrigin() == CIMName ("test"));

        m2.setPropagated(true);
        PEGASUS_TEST_ASSERT(m2.getPropagated() == true);

        const CIMMethod cm1(m1);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff21")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuf")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT((cm1.getParameterCount() != 3));
        PEGASUS_TEST_ASSERT(cm1.findParameter(
            CIMName ("ipaddress")) != PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(cm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);

        CIMQualifier q = m1.getQualifier(posQualifier);
        CIMConstParameter ccp = cm1.getParameter(
                    cm1.findParameter(CIMName ("ipaddress")));
        PEGASUS_TEST_ASSERT(cm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(cm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(cm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!cm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!m1.identical(m2));

        // throws OutOfBounds
        try
        {
            CIMConstParameter p = cm1.getParameter(cm1.findParameter(
                                        CIMName ("ipaddress")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = cm1.getQualifier(cm1.findQualifier(
                                        CIMName ("abstract")));
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(cm1);
        }
        Buffer out;
        XmlWriter::appendMethodElement(out, cm1);
        MofWriter::appendMethodElement(out, cm1);

        Boolean nullMethod = cm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        CIMMethod m3 = m2.clone();
        m3 = cm1.clone();

        CIMMethod m4;
        CIMMethod m5(m4);

        CIMConstMethod ccm1(CIMName ("getHostName"),CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));

        PEGASUS_TEST_ASSERT(ccm1.getName() == CIMName ("getHostName"));
        PEGASUS_TEST_ASSERT(ccm1.getType() == CIMTYPE_STRING);
        PEGASUS_TEST_ASSERT(!(ccm1.getClassOrigin() == CIMName ("test")));
        PEGASUS_TEST_ASSERT(!ccm1.getPropagated() == true);
        PEGASUS_TEST_ASSERT(!(ccm1.getParameterCount() == 3));
        PEGASUS_TEST_ASSERT(ccm1.getQualifierCount() == 0);
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("Stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        if (verbose)
        {
            XmlWriter::printMethodElement(m1);
            XmlWriter::printMethodElement(ccm1);
        }

        XmlWriter::appendMethodElement(out, ccm1);

        CIMConstMethod ccm2(ccm1);
        CIMConstMethod ccm3;

        ccm3 = ccm1.clone();
        ccm1 = ccm3;
        PEGASUS_TEST_ASSERT(ccm1.identical(ccm3));
        PEGASUS_TEST_ASSERT(ccm1.findQualifier(
            CIMName ("stuff")) == PEG_NOT_FOUND);
        PEGASUS_TEST_ASSERT(ccm1.findParameter(
            CIMName ("ipaddress")) == PEG_NOT_FOUND);

        nullMethod = ccm1.isUninitialized();
        PEGASUS_TEST_ASSERT(!nullMethod);

        // throws OutOfBounds
        try
        {
            //CIMParameter p = m1.getParameter(
            //     m1.findParameter(CIMName ("ipaddress")));
            CIMConstParameter p = ccm1.getParameter(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }

        // throws OutOfBounds
        try
        {
            CIMConstQualifier q1 = ccm1.getQualifier(0);
        }
        catch(IndexOutOfBoundsException&)
        {
        }
    }
    catch(Exception& e)
    {
        cerr << "Exception: " << e.getMessage() << endl;
    }

    // Test for add second qualifier with same name.
    // Should do exception

    cout << argv[0] << " +++++ passed all tests" << endl;

    return 0;
}
Esempio n. 11
0
int main(void)
{
   struct tm *newtime;
   time_t ltime; 
   time(&ltime);                 /* Get the time in seconds */
   newtime = localtime(&ltime);  /* Convert it to the structure tm */
   char * st;            // gen purpose string for bcd's
   st = new char[35];   // 32 digits + sign + decimal pt + '\0'
 ofstream dout("bcdrun.log");
   bcd numa("1234567890987654.123");  // fraction will be dropped
   bcd numb(4321.6789);               // ditto - we are using integer rules
   bcd numc(-24681357L);
   bcd numd = numa + numb;
   bcd e(0.0);
   bcd f(0L);
   bcd g(-0.0);
   bcd h(-0L);
   bcd w(1L);
   bcd x(-1.0);
   bcd y("-2.0");
   bcd z("300.");
   bcd aa("99999999999999999999999999999999");
   bcd bb("1");
   bcd cc("10000000000000000");
   bcd dd(".00000000000000001");
   bcd m1(12L);
   bcd m2(2L);
   bcd m3(123456789L);
   bcd m4(4096L);
   bcd m5(748345987654321.0);
   bcd m6(288834570200345.0);
   bcd m7("8599238847786248452455563809");
   bcd d1("8765432109876");
   bcd d2(24687L);
   bcd d3(75237L);
   bcd d4(45263L);
   bcd d5 ("92732081006447");
   bcd s1("1234567890987654");

   dout << "                 Regression Log for " << asctime(newtime) << endl;

   dout << "significant digits test: 1 = " << w.sigD() << ", 3 = " << z.sigD()
        << ", 32 = " << aa.sigD() << ", 0 = " << dd.sigD() << "\n" << endl;

   int rc = numa.bcdToString(st); // convert numa to string no decimal point
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +1234567890987654" << endl;
   rc = numa.bcdToString(st,1);   // numa to str with 1 psn to right of dec pt
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +123456789098765.4" << endl;
   rc = numa.bcdToString(st,6);   // numa to str with 6 psns to rt of decimal pt
   dout << "bcd to string test = " << st << "\n"
        << "          expected:  +1234567890.987654" << "\n" << endl;

   rc = m3.bcdToString(st); // convert m3 to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +123456789" << endl;
   rc = m3.bcdToString(st,1);   // m3 to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +12345678.9" << endl;
   rc = m3.bcdToString(st,6);   // m3 to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +123.456789" << "\n" << endl;

   rc = h.bcdToString(st); // convert h to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0" << endl;
   rc = h.bcdToString(st,1);   // convert h to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.0" << endl;
   rc = h.bcdToString(st,6);   // h to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.0" << "\n" << endl;

   rc = m2.bcdToString(st); // convert m2 to string no decimal point
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +2" << endl;
   rc = m2.bcdToString(st,1);   // m2 to str with 1 psn to right of dec pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.2" << endl;
   rc = m2.bcdToString(st,6);   // m2 to str with 6 psns to rt of decimal pt
   dout << "bcd to string test  = " << st << "\n"
        << "          expected:   +0.000002" << "\n" << endl;

   s1.shl(1);
   dout << "shift test 1234567890987654 shifted left 1 = " << s1 
        << "   expected                                = +00000000000000012345678909876540 cc: 0\n" << endl;
   s1.shl(2);
   dout << "shift test 1234567890987654 shifted left 2 = " << s1 
        << "   expected                                = +00000000000001234567890987654000 cc: 0\n" << endl;
   s1.shl(3);
   dout << "shift test 1234567890987654 shifted left 3 = " << s1 
        << "   expected                                = +00000000001234567890987654000000 cc: 0\n" << endl;
   s1.shl(13);
   dout << "shift test 1234567890987654 shfted left 13 = " << s1 
        << "   expected                                = +00000000001234567890987654000000 cc: 16\n" << endl;
   s1.shr(1);
   dout << "shift test 1234567890987654 shifted rt 1 = " << s1 
        << "   expected                              = +00000000000123456789098765400000 cc: 0\n" << endl;
   s1.shr(2);
   dout << "shift test 1234567890987654 shifted rt 2 = " << s1 
        << "   expected                              = +00000000000001234567890987654000 cc: 0\n" << endl;
   s1.shr(5);
   dout << "shift test 1234567890987654 shifted rt 5 = " << s1 
        << "   expected                              = +00000000000000000012345678909876 cc: 0\n" << endl;
   s1.shrRnd(4);
   dout << "shift test 12345678909876 sh rt 4 & rnd  = " << s1
        << "   expected                              = +00000000000000000000001234567891 cc: 0\n" << endl;
   s1.shrRnd(4);
   dout << "shift test 12345678909876 sh rt 4 & rnd  = " << s1
        << "   expected                              = +00000000000000000000000000123457 cc: 0\n" << endl;
   s1.shrRnd(5);
   dout << "shift test 12345678909876 sh rt 5 & rnd  = " << s1
        << "   expected                              = +00000000000000000000000000000001 cc: 0\n" << endl;
   s1.shl(31);
   dout << "shift test 12345678909876 sh lt 31       = " << s1
        << "   expected                              = +10000000000000000000000000000000 cc: 0\n" << endl;

   bcd s2("1234567890987654321");
   s2.shrCpld(s1,6);               // odd shift even
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000654321 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000001234567890987 cc: 0\n" << endl;
   s2.shrCpld(s1,5);               // odd shift odd
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000090987 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000012345678 cc: 0\n" << endl;
   s2.shrCpld(s1,4);               // even shift even
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000005678 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000000001234 cc: 0\n" << endl;
   s2.shrCpld(s1,3);               // odd shift odd
   dout << "coupled shift s2 > s1,   s1 = " << s1
        << "                expected s1 = +00000000000000000000000000000234 cc: 0\n"
        << "                         s2 = " << s2
        << "                expected s2 = +00000000000000000000000000000001 cc: 0\n" << endl;

   dout << "logical test 1 < 2   = " << int(bb<m2) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 1 > 2   = " << int(bb>m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 = 2   = " << int(bb==m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 < 1   = " << int(m2<bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 > 1   = " << int(m2>bb) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 2 = 1   = " << int(m2==bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 < 12  = " << int(bb<m1) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 1 > 12  = " << int(bb>m1) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 1 = 12  = " << int(bb==m1) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 12 < 1  = " << int(m1<bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 12 > 1  = " << int(m1>bb) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 12 = 1  = " << int(m1==bb) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 < 2  = " << int(x<m2) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -1 > 2  = " << int(x>m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 = 2  = " << int(x==m2) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test 2 < -1  = " << int(m2<x) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test -1 != 2  = " << int(x!=m2) << "\n"
        << "expected              = 1 \n" << endl;
   dout << "logical test 2 != -1  = " << int(m2!=x) << "\n"
        << "expected              = 1 \n" << endl;
   dout << "logical test 2 != 2   = " << int(m2!=m2) << "\n"
        << "expected              = 0 \n" << endl;
   dout << "logical test 2 > -1  = " << int(m2>x) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 2 = -1  = " << int(m2==x) << "\n"
        << "expected             = 0 \n" << endl;
   dout << "logical test d1 = d1 = " << int(d1==d1) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 0 = -0  = " << int(f==h) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -0 = 0  = " << int(h==f) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test 0 = 0   = " << int(f==f) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "logical test -0 = -0 = " << int(h==h) << "\n"
        << "expected             = 1 \n" << endl;
   dout << "divide test 8765432109876/24687 = " << d1/d2
        << "expected                        = +00000000000000000000000355062669 cc: 0\n" << endl;
   dout << "divide tst 92732081006447/45263 = " << d5/d4
        << "expected                        = +00000000000000000000002048739169 cc: 0\n" << endl;
   dout << "divide test 8765432109876/75237 = " << d1/d3
        << "expected                        = +00000000000000000000000116504274 cc: 0\n" << endl;
   dout << "divide test 1/24687             = " << bb/d2
        << "expected                        = +00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "   test 10000000000000000/24687 = " << cc/d2
        << "expected                        = +00000000000000000000405071495118 cc: 0\n" << endl;
   dout << "   test 10000000000000000/3     = " << cc/3L
        << "expected                        = +00000000000000003333333333333333 cc: 0\n" << endl;
   dout << "   test 10000000000000000/6     = " << cc/6L
        << "expected                        = +00000000000000001666666666666666 cc: 0\n" << endl;
   dout << "   test 10000000000000000/7     = " << cc/7L
        << "expected                        = +00000000000000001428571428571428 cc: 0\n" << endl;
   dout << " div test 22000000000000000/7   = " << (cc*22L)/7L
        << "expected                        = +00000000000000031428571428571428 cc: 0\n" << endl;
   dout << "modulus test 24687%1000         = " << d2%1000L
        << "expected                        = +00000000000000000000000000000687 cc: 0\n" << endl;
   dout << "divide by zero test 75237/0     = " << d3/0L
        << "expected                        = +00000000000000000000000000075237 cc: 16\n" << endl;
   dout << "divide d1/d1 test               = " << d1/d1
        << "expected                        = +00000000000000000000000000000001 cc: 0\n" << endl;
   dout << "re-subtract test: 12345 - 12346 = " << bcd(12345L) - 12346L
        << "expected                        = -00000000000000000000000000000001 cc: 0\n"
        << " reverse opnds:   12346 - 12345 = " << bcd(12346L) - 12345L
        << "expected                        = +00000000000000000000000000000001 cc: 0\n" << endl;
   dout << "8599238847786248452455563809*45263       = " << m7 * d4
        << "                               expected:   +00008599238847786248452455563809 cc: 15\n" << endl;
   dout << "748345987654321 x 288834570200345        = " << m5 * m6
        << "                               expected:   +00216148191705288491573574940745 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 10   = " << m5 * m6 * 10.0
        << "                               expected:   +02161481917052884915735749407450 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 100  = " << m5 * m6 * 100.0
        << "                               expected:   +21614819170528849157357494074500 cc: 0\n" << endl;
   dout << "748345987654321 x 288834570200345 x 1000 = " << m5 * m6 * 1000.0
        << "                               expected:   +00216148191705288491573574940745 cc: 16\n" << endl;
   dout << "123456789 x 123456789 x 123456789        = " << m3 * m3 * m3
        << "                               expected:   +00000001881676371789154860897069 cc: 0\n" << endl;
   dout << "123456789 x 123456789 x 123456789 x 123456789 = " << m3 * m3 * m3 * m3
        << "                                    expected:   +00000001881676371789154860897069 cc: 16\n" << endl;
   dout << "                                        2 x 2 = " << m2*m2
        << "                                    expected:   +00000000000000000000000000000004 cc: 0\n" << endl;
   dout << "                                       2 x 12 = " << m2*m1
        << "                                    expected:   +00000000000000000000000000000024 cc: 0\n" << endl;
   dout << "                                2 x 123456789 = " << m2 * m3
        << "                                    expected:   +00000000000000000000000246913578 cc: 0\n" << endl;
   dout << "                                123456789 x 2 = " << m3 * m2
        << "                                    expected:   +00000000000000000000000246913578 cc: 0\n" << endl;
   dout << " 4096 x 2 = " << m4 * m2
        << "expected:   +00000000000000000000000000008192 cc: 0\n" << endl;
   dout << " 2 x 4096 = " << m2 * m4
        << "expected:   +00000000000000000000000000008192 cc: 0\n" << endl;
   dout << " 2 x 12 x 4096 = " << m2 * m1 * m4
        << "expected:        +00000000000000000000000000098304 cc: 0\n" << endl;
   dout << "    aa = " << aa
        << "    bb = " << bb
        << " aa-bb = " << aa-bb
        << "expected:+99999999999999999999999999999998 cc: 0\n"
        << " aa+bb = " << aa+bb 
        << "expected:+00000000000000000000000000000000 cc: 1\n" << endl;
   dout << "     e = " << e
        << "     f = " << f
        << " e + f = " << e+f
        << "expected:+00000000000000000000000000000000 cc: 0\n" 
        << " e - f = " << e-f 
        << "expected:+00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "     g = " << g
        << "     h = " << h
        << " g + h = " << g+h
        << "expected:+00000000000000000000000000000000 cc: 0\n"
        << " g - h = " << g-h 
        << "expected:+00000000000000000000000000000000 cc: 0\n" << endl;
   dout << "     w = " << w
        << "     x = " << x
        << " w + x = " << w+x
        << "expected:+00000000000000000000000000000000 cc: 0\n"
        << " w - x = " << w-x 
        << "expected:+00000000000000000000000000000002 cc: 0\n" << endl;
   dout << "     y = " << y
        << "     z = " << z
        << " y + z = " << y+z
        << "expected:+00000000000000000000000000000298 cc: 0\n"
        << " y - z = " << y-z 
        << "expected:-00000000000000000000000000000302 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numb =      " << numb
        << "numa+numb = " << numd
        << "expected:   +00000000000000001234567890991975 cc: 0\n"
        << "numb+numa = " << numb+numa 
        << "expected:   +00000000000000001234567890991975 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numc =      " << numc
        << "numa+numc = " << numa+numc 
        << "expected:   +00000000000000001234567866306297 cc: 0\n"
        << "numc+numa = " << numc+numa
        << "expected:   +00000000000000001234567866306297 cc: 0\n" << endl;
   dout << "numb =      " << numb
        << "numc =      " << numc
        << "numb+numc = " << numb+numc 
        << "expected:   -00000000000000000000000024677036 cc: 0\n"
        << "numc+numb = " << numc+numb 
        << "expected:   -00000000000000000000000024677036 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numb =      " << numb
        << "numa-numb = " << numa-numb 
        << "expected:   +00000000000000001234567890983333 cc: 0\n" 
        << "numb-numa = " << numb-numa 
        << "expected:   -00000000000000001234567890983333 cc: 0\n" << endl;
   dout << "numa =      " << numa 
        << "numc =      " << numc
        << "numa-numc = " << numa-numc 
        << "expected:   +00000000000000001234567915669011 cc: 0\n"
        << "numc-numa = " << numc-numa 
        << "expected:   -00000000000000001234567915669011 cc: 0\n" << endl;
   dout << "numb =      " << numb
        << "numc =      " << numc
        << "numb-numc = " << numb-numc 
        << "expected:   +00000000000000000000000024685678 cc: 0\n"
        << "numc-numb = " << numc-numb
        << "expected:   -00000000000000000000000024685678 cc: 0\n" << endl;
   dout.close();
   delete st;
   return 0;
}