A basic VisionX program that illustrates all the main features of the structured VisionX programming tools is shown in Figure 1. Since this structure is similar for most VisionX programs, the example program may be used as a template for developing other programs.
Any VisionX program should be able to deal with any VisionX file, and should accept the flexible VisionX command line structure. The following code walk through illustrates the five stage framework that is used in all structured VisionX programs.
#include "VisXV4.h" /* VisionX structure include file */ #include "Vutil.h" /* useful macros, stdio.h etc. */ /* */ VisXfile_t *VXin, /* input file structure */ *VXout; /* output file structure */ VisXelem_t *vxlist; /* VisX data structure */
In general, every file is associated with a file structure ``VisXfile_t *'', also a data list ``VisXelem_t *'' is used to hold the data read from or to be written to files.
VXparam_t par[] = /* command line structure */ { { "if=", 0, "input file vcp: file copy"}, { "of=", 0, "output file"}, { "-f", 0, "frame-i/o option"}, { 0, 0, 0}, /* list termination */ }; #define IVAL par[0].val #define OVAL par[1].val #define FFLAG par[2].valEach prefix is specified by two statements. For example, the string matched to the "of=" command parameter is referred to by OVAL in the program. The VXparse subroutine parses the command line and sets the .val elements of the par data structure to the text strings associated with the matched parameters. If the user does not specify the "of=" parameter then OVAL is set to a NULL string by VXparse.
main(argc, argv) int argc; char *argv[]; { VXparse(&argc, &argv, par); /* parse the command line */ VXin = VXopen(IVAL, 0); /* open input file */ VXout = VXopen(OVAL, 1); /* open the output file */
vxlist = VXread(VXin); /* read data */ /* do any modifications to vxlist or create */ /* a separate list for output */ VXwrite(VXout, vxlist); /* write data */To process the data file one frame at a time the structure is:
while ((vxlist = VXreadframe(VXin)) != VXNIL){ /* for each frame read */ VXfupdate(VXout, VXin); /* update global constants */ /* do any modifications to vxlist or create */ /* a separate list for output */ VXwriteframe(VXout,vxlist); /* write frame */ VXdellist(vxlist); /* delete the frame */ }In this case a new vxlist is created with each call to VXreadframe. Any global constants that are to be used for all frames are maintained in a list VXflist(VXout). The VXupdate command ensures that this list is maintained with any new global information that is extracted from the input file with the call to VXreadframe.
VXclose(VXin); /* close input file */ VXclose(VXout); /* close output file */ exit(0); }