ARTWORK CONVERSION SOFTWARE

GDSII | QISBOOL | Index

 

QisBool Sample Code

Booleanize

Single threaded union of polygons obtained from a single window using QisLib

 

 

 


 

booleanize.cpp

 

 

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

 

#include "qislib.h" �////Include file for QisLib Code

#include "qisbool.h" ////Include file for QisBool Code

 

/* User driven input functions.

�* This information will be provided by the client application

�*/

const char* User_ExecDir(const char*);

const char* User_ExecPath(const char*);

const char* User_GDSIIFile();

int User_OpenStructure();

const char* User_ViewStructure();

int User_SetLayers();

const char* User_LayerString();

int User_SetWindow();

void User_GetWindow(CQisWindow*);

int User_SetClipWindow();

void User_ClipWindow(int*, int*, int*, int*);

 

int booleanize_main(int argc, char* argv[])

{

��/* Initialize QisLib */

� #if(defined(WIN32) || defined(WIN64))

� int ret = QisLib_InitLib(User_ExecDir(argv[0]));

� #else

� int ret = QisLib_InitLib(User_ExecPath(argv[0]), NULL, NULL);

� #endif

� if(ret) {

��� fprintf(stderr, "error: QisLib_InitLib returned %d.\n", ret);

��� if(ret == -3) {

����� fprintf(stderr, "License error: %s\n", QisLib_GetErrorMsg());

��� }

��� return 1;

� }

 

� int err = 0;

� int storageHandle = -1;

� void* boolHandle = 0;

� int** XYOut = 0;

� int* NVOut = 0;

� int NOut = 0;

 

� do {

 

��� /* Open a GDSII file */

��� ret = QisLib_OpenGDSII(User_GDSIIFile());

��� if(ret) {

����� fprintf(stderr, "QisLib_OpenGDSII returned %d.\n", ret);

����� err = 1; break;

��� }

 

��� /* If desired, Set view structure otherwise work with the Default top structure */

��� if(User_OpenStructure()) {

����� ret = QisLib_OpenStructure(User_ViewStructure());

����� if(ret) {

������� fprintf(stderr, "QisLib_OpenStructure returned %d.\n", ret);

������� err = 1; break;

����� }

��� }

 

��� /* If desired, Set certain layers otherwise work with all layers */

��� if(User_SetLayers()) {

����� QisLib_SetLayersOff("ALL");

����� QisLib_SetLayersOn(User_LayerString());

��� }

 

��� /* If desired, Set a window of interest

���� * otherwise work with the extents of the current structure

���� */

��� if(User_SetWindow()) {

����� CQisWindow win;

����� User_GetWindow(&win);

����� QisLib_SetExactWindow(win);

��� }

 

��� /* Collect boundaries belonging to the window specified above

���� * Convert any paths to boundaries

���� */

��� QisLib_SetVectorUnit(_QISUNIT_DBU);

��� QisLib_SetGetVectorPath(_QISPATH_BNDRY);

 

��� longlong N;

��� int* NV = 0;

��� int** XY = 0;

��� storageHandle = QStore_GetDataVectorBoundaries(&N, &XY, &NV);

��� if(storageHandle < 0) {

����� fprintf(stderr, "QStore_GetDataVectorBoundaries returned %d.", storageHandle);

����� err = 1; break;

��� }

 

��� /* 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");

����� }

����� fclose(fptr);

��� }

 

��� /* Create QisBool instance */

��� char errMsg[1024];

��� boolHandle = QisBool_Create(errMsg);

��� if(!boolHandle) {

����� fprintf(stderr, "error: QisBool_Create %s\n", errMsg);

����� err = 1; break;

��� }

 

��� /* If desired, Set clipping window otherwise do not clip the boundaries */

��� 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 (QisLib allows max. 8190 vertices per polygon) */

��� QisBoolOptions_SetMaxPoints(8190, boolHandle);

���

��� /* 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");

����� }

����� fclose(fptr);

��� }

 

� } 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);

� QisLib_CloseLib();

� return err;

}

 

 


 

 

 

� 2012 Artwork Conversion Software Inc.

417 Ingalls St. Santa Cruz CA 95060

[T] +1 831-426-6163 [F] +1 831-[E] info@artwork.surf