halcon学习 tuple之算术运算2

//计算数组的积累值,tuple数组中每个元素必须都是数字,输入[1,2,3,4],则输出[1,3,6,10],如果输入的有浮点数,则输出结果也会出现浮点数
void testTupleCumul()
{
    HTuple tuple;
    for (int i = 0; i < 10; i++)
    {
        tuple[i] = i;
    }

    for (int i = 0; i < 10; i++)
    {
        cout << (Hlong)tuple[i] << " ";
    }

    cout << endl;
    HTuple result = tuple.TupleCumul();
    for (int i = 0; i < 10; i++)
    {
        cout << (Hlong)result[i] << " ";
    }
}


//转化数组中的值从弧度到角度.
void testTupleDeg()
{
    HTuple tuple;
    for (int i = 0; i < 10; i++)
    {
        tuple[i] = i;
    }

    for (int i = 0; i < 10; i++)
    {
        cout << (Hlong)tuple[i] << " ";
    }
    cout << endl;
    HTuple result = tuple.TupleDeg();
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}

//数组之间执行相除操作。
void testTupleDiv()
{
    HTuple tuple1;
    for (int i = 0; i < 10; i++)
    {
        tuple1[i] = i+5;
    }
    HTuple tuple2;
    for (int i = 0; i < 10; i++)
    {
        tuple2[i] = i+1;;
    }

    HTuple result = tuple1.TupleDiv(tuple2);
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}

//数组的指数运算,总是返回浮点值,数组中元素必须是数值型,result=e^x
void testTupleExp()
{
    HTuple tuple1;
    for (int i = 0; i < 10; i++)
    {
        tuple1[i] = i + 5;
    }

    HTuple result = tuple1.TupleExp();
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}

//浮点型的数组求绝对值
void testTupleFabs()
{
    HTuple tuple1;
    for (int i = 0; i < 10; i++)
    {
        if (i != 0)
            tuple1[i] = (double)(tuple1[i - 1]) *(-2.5);
        else
            tuple1[i] = i + 1;
    }

    HTuple result = tuple1.TupleFabs();
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}


//通过下限函数计算tuple数组,比如[2.5]=2,[2.1]=2,[3.5]=3
//注意。(double)result[i] 转化格式不能错,一旦出错,程序会中断
void testTupleFloor()
{
    HTuple tuple;
    for (int i = 0; i < 10; i++)
    {
        tuple[i] = (double)(i + 5) / (2.0);
    }
    for (int i = 0; i < 10; i++)
    {
        cout << (double)tuple[i] << " ";
    }

    cout << endl;
    HTuple result = tuple.TupleFloor();
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}

//计算两个浮点数的相除的余数
void testTupleFmod()
{
    HTuple tuple1;
    for (int i = 0; i < 10; i++)
    {
        tuple1[i] = (i + 5)*5.3;
    }
    HTuple tuple2;
    for (int i = 0; i < 10; i++)
    {
        tuple2[i] = (i + 1)*1.5;;
    }

    HTuple result = tuple1.TupleFmod(tuple2);
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}

// 装载浮点数,ldexp(double value, int exp); 功 能: 计算value乘以2的exp次幂 
void testTupleLdexp()
{
    HTuple tuple1;
    for (int i = 0; i < 10; i++)
    {
        tuple1[i] = i *1.2;
    }
    HTuple tuple2;
    for (int i = 0; i < 10; i++)
    {
        tuple2[i] = i;
    }
    HTuple result = tuple1.TupleLdexp(tuple2);
    for (int i = 0; i < 10; i++)
    {
        cout << (double)result[i] << " ";
    }
}

你可能感兴趣的:(Tuple,算术运算,halcon)