QIS Library Logo

Code Example 1 Page 2

Simple Window Extraction and Clip/Boolean

/* Collect Boundaries */


  longlong N;
  int* NV = 0;
  int** XY = 0;
  storageHandle = QStore_GetDataVectorBoundaries(&N, &XY, &NV);
  if(storageHandle < 0) {
   "QStore returned %d.", storageHandle); 
   err = 1; break;
Normally the user would have to use
a call back function to collect and
store the boundaries from QisLib's
GetDataVector function. However we
now include Qstore to simpllfy
the process.

Set the returned data units
Force path to boundary conversion
Create variables for Qstore
 number of polys
 array of poly vertex counts
 array of array of coordinates
Call Qstore to get boundaries
 check for error

/* Write input boundaries as text */
    FILE* fptr = fopen("inputpolys.txt", "w");
    if(fptr) {
      fprintf(fptr, "%d\n", (int)(N));
      for(int i=0; i<N; i++) {
        fprintf(fptr, "[%d] ", NV[i]);
        for(int j=0; j<(NV[i]*2); j+=2)
          fprintf(fptr, "%d,%d ", XY[j], XY[j+1]);
        fprintf(fptr, "\n");
For this example we are just going to write
the polygons that Qstore just collected to a 
file to illustrate how the data is organized.

/* Create QisBool instance */

 char errMsg[1024];
 boolHandle = QisBool_Create(errMsg);
 if(!boolHandle) {
   fprintf(stderr, "error: QisBool_Create %s\n", errMsg);
   err = 1; break;

 /* Set clipping window */
 if(User_SetClipWindow()) {
  int minx, miny, maxx, maxy;
  User_ClipWindow(&minx, &miny, &maxx, &maxy);
  QisBoolOptions_SetClipWindow(minx, miny, maxx, maxy, boolHandle);

 /* Set Max. Output vertex count */
 QisBoolOptions_SetMaxPoints(8190, boolHandle);
Now we will initialize and use
QisBool to clip and unionize the 
polygons we just collected. 

set a variable to hold message
initialize QisBool
check for valid handle

set a clipping window

limit max vertex count to 8190
so that if needed, output could
be converted back to GDSII.

 /* Unionize collected boundaries */
    ret = QisBool_Booleanize
          (eUNION_OPCODE, XY, NV, N, NULL, NULL, 0, 
           &XYOut, &NVOut, &NOut, boolHandle);

    if(ret < 0) {
      fprintf(stderr, "error: QisBool_Booleanize %s\n", 
              QisBool_ErrorMsg(ret, boolHandle));
      err = 1; break;
    } else if(ret > 0) {
      fprintf(stderr, "warning: QisBool_Booleanize %s\n", 
              QisBool_ErrorMsg(ret, boolHandle));

    /* Write output boundaries as text */
    fptr = fopen("outputpolys.txt", "w");
    if(fptr) {
      fprintf(fptr, "%d\n", (int)(NOut));
      for(int i=0; i<NOut; i++) {
        fprintf(fptr, "[%d] ", NVOut[i]);
        for(int j=0; j<(NVOut[i]*2); j+=2)
          fprintf(fptr, "%d,%d ", XYOut[j], XYOut[j+1]);
        fprintf(fptr, "\n");

  } while(0);

  /* Cleanup and Close */
  if((NOut > 0) && NVOut && XYOut) 
    QisBool_Release(&XYOut, &NVOut, &NOut);
  if(boolHandle) QisBool_Destroy(&boolHandle);
  if(storageHandle >= 0) QStore_Release(storageHandle);
  return err;
Now that the library is set up, pull
the trigger on the Unionize function.

check for error (neg return code)

check for warning (pos return code)

write the newly generated polygons
to disk.

end of the do loop

release memory for polys created
by QisBool
Destroy the instance of QisBool
release memory used by Qstore
close the QisLib instance