HCrXLD (see figure 5.19) is used for creating XLD objects in the HALCON database of iconic objects. The parameter xld_type allows to specify the kind of XLD to be created: It has to be set to XLD_CONTOUR_ID in case of a contour and to XLD_POLYGON_ID in case of a polygon. Corresponding to the selected type, HCrXLD expects a pointer to Hcont or a pointer to Hpoly in the parameter xld. In both cases, not the underlying XLD data but only the pointers to the data are copied to the database. Thus, you must not deallocate or overwrite the XLD structures after calling HCrXLD.
Note that HCrXLD automatically checks the result state of the underlying procedure with the macro HCkP (see section “HCkP”). Thus, you must not use HCkP on HCrXLD yourself.
Hcpar rows[99], cols[99]; INT4_8 i,num_points; Hkey key_out; Hcont *cont; ... HGetCPar(proc_handle,1,DOUBLE_PAR,rows,1,99,&num_points); HGetCPar(proc_handle,2,DOUBLE_PAR,cols,1,99,&num_points); /* create a contour (in general, this should be done */ /* calling an appropriate action procedure) */ HCkP(HAllocXLDCont(proc_handle,&cont,num_points)); for (i=0; i < num_points; i++ { cont->row[i] = rows[i].par.d; cont->col[i] = cols[i].par.d; } cont->num = num_points; HCrXLD(proc_id,1,cont,XLD_CONTOUR_ID,NULL,0, (DBFreeProc)HXLDFreeContour,&key_out);
Figure 5.24: A typical example for using HCrXLD: Create an XLD contour from a list of points.
HCrXLD expects an appropriate deallocation routine for the XLD data in the parameter free_proc. For XLD contours, please use
(DBFreeProc) HXLDFreeContour
For XLD polygons allocated based on HAlloc use
(DBFreeProc) HXLDFreePolygon
Finally, HCrXLD not only creates a new database object, but also appends this object to the output iconic parameter with index par_num. Figures 5.24 shows a typical application of HCrXLD.