5.5.7   HGetCPar

HGetCPar (see figure 5.30) reads the parameter values of the input control parameter with the index par (1… n) and writes them to the array val of Hcpar structures that must have been allocated before with a suitable size.

Note that HGetCPar automatically checks the result state of the underlying procedure similarly to the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HGetCPar yourself.

    Hcpar      par1,par2;
    Hcpar      par3[10];

    /* allocate memory for strings  */
    HAllocStringMem(proc_handle,1000);
    /* read a short/int/long value in parameter 1 */
    HGetCPar(proc_handle,1,LONG_PAR,&par1,1,1,&num);
    /* now par1.par.l == 5                 */
    /* read a string in parameter 2 */
    HGetCPar(proc_handle,2,STRING_PAR,&par2,1,1,&num);
    /* now par2.par.s == "Text"                           */
    /* read a tuple of float values in parameter 3 */
    /* (max. 10 values)                                   */
    HGetCPar(proc_handle,3,DOUBLE_PAR,par3,1,10,&num);
    for (i=0; i<num; i++) {
      /* par3[i].par.d == 0.5,1.7,4.4 */
      ...

Figure 5.32: Read the control parameter values of the operator call demo(5,'Text',[0.5,1.7,4.4]) using HGetCPar.

For every input value, its type (LONG_PAR, DOUBLE_PAR, STRING_PAR) is also stored within the Hcpar structure. Thus, it is possible to pass different control data types within one control parameter of a HALCON operator. The current number of values is returned in num. HGetCPar allows to restrict the parameter access in two respects:

If the specified number or types of values are violated, HGetCPar exits the supply procedure with an appropriate error message. Figure 5.32 shows an application of HGetCPar.

Note that in case of string parameters, memory has to be allocated for val[i].par.s. The easiest way to do this is to use HAllocStringMem specifying the expected number of characters for all input strings, see section “HAllocStringMem”.