67 printf(
"\n%d vertices and %d facets with normals:\n",
68 qh num_vertices,
qh num_facets);
70 for (k=0; k <
qh hull_dim; k++)
71 printf(
"%6.2g ", facet->
normal[k]);
84 for (j=0; j<numpoints; j++) {
85 point= points + j*dim;
105 printf(
"seed: %d\n", seed);
107 for (j=0; j<numpoints; j++) {
108 point= points + j*dim;
109 for (k= 0; k < dim; k++) {
133 for (k= 0; k < dim; k++)
138 fprintf(stderr,
"findDelaunay: not implemented for triangulated, non-simplicial Delaunay regions (tricoplanar facet, f%d).\n",
143 for (k=0; k < dim; k++)
144 printf(
"%5.2f ", vertex->
point[k]);
159 for (j=0; j<numpoints; j++) {
160 point= points + j*(dim+1);
172 #define SIZEcube (1<<DIM) 173 #define SIZEdiamond (2*DIM) 174 #define TOTpoints (SIZEcube + SIZEdiamond) 185 int main(
int argc,
char *argv[]) {
192 FILE *outfile= stdout;
194 FILE *errfile= stderr;
197 int curlong, totlong;
202 printf(
"This is the output from user_eg.c\n\n\ 203 It shows how qhull() may be called from an application using the qhull\n\ 204 shared library. user_eg is not part of qhull itself. If it appears\n\ 205 accidently, please remove user_eg.c from your project. If it fails\n\ 206 immediately, user_eg.c was incorrectly linked to the reentrant library.\n\ 207 Also try 'user_eg T1 2>&1'\n\n");
211 printf(
"QH6233: Qhull link error. The global variable qh_qh was not initialized\n\ 212 to NULL by global.c. Please compile user_eg.c with -Dqh_QHpointer_dllimport\n\ 213 as well as -Dqh_QHpointer, or use libqhullstatic, or use a different tool chain.\n\n");
221 printf(
"\ncompute convex hull of cube after rotating input\n");
222 sprintf(flags,
"qhull s Tcv %s", argc >= 2 ? argv[1] :
"");
225 for (i=numpoints; i--; )
226 rows[i]= points+dim*i;
228 exitcode=
qh_new_qhull(dim, numpoints, points, ismalloc,
229 flags, outfile, errfile);
239 if (curlong || totlong)
240 fprintf(errfile,
"qhull internal warning (user_eg, #1): did not free %d bytes of long memory (%d pieces)\n", totlong, curlong);
246 printf(
"\ncompute %d-d Delaunay triangulation\n", dim);
247 sprintf(flags,
"qhull s d Tcv %s", argc >= 3 ? argv[2] :
"");
250 for (i=numpoints; i--; )
251 rows[i]= points+dim*i;
253 exitcode=
qh_new_qhull(dim, numpoints, points, ismalloc,
254 flags, outfile, errfile);
263 printf(
"\nfind %d-d Delaunay triangle closest to [0.5, 0.5, ...]\n", dim);
264 exitcode= setjmp(
qh errexit);
275 qhT *oldqhA, *oldqhB;
278 printf(
"\nsave first triangulation and compute a new triangulation\n");
279 oldqhA= qh_save_qhull();
280 sprintf(flags,
"qhull s d Tcv %s", argc >= 3 ? argv[2] :
"");
282 makeDelaunay(pointsB, numpoints, dim, (
int)time(NULL)+1);
283 for (i=numpoints; i--; )
284 rows[i]= pointsB+dim*i;
286 exitcode=
qh_new_qhull(dim, numpoints, pointsB, ismalloc,
287 flags, outfile, errfile);
290 printf(
"\nsave second triangulation and restore first one\n");
291 oldqhB= qh_save_qhull();
292 qh_restore_qhull(&oldqhA);
294 printf(
"\nfree first triangulation and restore second one.\n");
297 qh_restore_qhull(&oldqhB);
303 if (curlong || totlong)
304 fprintf(errfile,
"qhull internal warning (user_eg, #2): did not free %d bytes of long memory (%d pieces)\n", totlong, curlong);
309 printf(
"\ncompute halfspace intersection about the origin for a diamond\n");
310 sprintf(flags,
"qhull H0 s Tcv %s", argc >= 4 ? argv[3] :
"Fp");
313 for (i=numpoints; i--; )
314 rows[i]= points+(dim+1)*i;
315 qh_printmatrix(outfile,
"input as halfspace coefficients + offsets", rows, numpoints, dim+1);
319 exitcode=
qh_new_qhull(dim+1, numpoints, points, ismalloc,
320 flags, outfile, errfile);
325 if (curlong || totlong)
326 fprintf(stderr,
"qhull internal warning (user_eg, #3): did not free %d bytes of long memory (%d pieces)\n",
facetT * qh_findbestfacet(pointT *point, boolT bestoutside, realT *bestdist, boolT *isoutside)
int main(int argc, char *argv[])
#define FOREACHvertex_(vertices)
void qh_setdelaunay(int dim, int count, pointT *points)
void qh_freeqhull(boolT allmem)
void makecube(coordT *points, int numpoints, int dim)
void qh_printmatrix(FILE *fp, const char *string, realT **rows, int numrow, int numcol)
void findDelaunay(int dim)
void makeDelaunay(coordT *points, int numpoints, int dim, int seed)
void qh_memfreeshort(int *curlong, int *totlong)
void makehalf(coordT *points, int numpoints, int dim)
int qh_new_qhull(int dim, int numpoints, coordT *points, boolT ismalloc, char *qhull_cmd, FILE *outfile, FILE *errfile)
void qh_errexit(int exitcode, facetT *facet, ridgeT *ridge)
#define qh_RANDOMseed_(seed)