⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 global.c

📁 这是一个新的用于图像处理的工具箱
💻 C
📖 第 1 页 / 共 3 页
字号:
/* global.c -- contains all the globals of the qhull application   see README       see qhull.h for qh globals and function prototypes   see qhull_a.h for internal functions   copyright (c) 1993-1995, The Geometry Center*/#include "qhull_a.h"#if qh_QHpointerqhT *qh_qh= NULL;#elseqhT qh_qh= {0};   /* remove "= {0}" if this causes a compiler error.  Also		     qh_qhstat in stat.c and qhmem in mem.c.  */#endif/*--------------------------------------------appendprint- append output format to qh PRINTout unless already defined*/void qh_appendprint (qh_PRINT format) {  int i;  for (i=0; i < qh_PRINTEND; i++) {    if (qh PRINTout[i] == format)      break;    if (!qh PRINTout[i]) {      qh PRINTout[i]= format;      break;    }  }} /* appendprint */     /*--------------------------------------------freebuffers- free up global memory buffers  must match initbuffers()*/void qh_freebuffers (void) {  trace5((qh ferr, "qh_freebuffers: freeing up global memory buffers\n"));  qh_memfree (qh NEARzero, qh hull_dim * sizeof(realT));  qh_memfree (qh lower_threshold, (qh input_dim+1) * sizeof(realT));  qh_memfree (qh upper_threshold, (qh input_dim+1) * sizeof(realT));  qh_memfree (qh lower_bound, (qh input_dim+1) * sizeof(realT));  qh_memfree (qh upper_bound, (qh input_dim+1) * sizeof(realT));  qh_memfree (qh gm_matrix, (qh hull_dim+1) * qh hull_dim * sizeof(coordT));  qh_memfree (qh gm_row, (qh hull_dim+1) * sizeof(coordT *));  qh_setfree (&qh hash_table);  qh_setfree (&qh other_points);  qh_setfree (&qh del_vertices);  qh_setfree (&qh searchset);  /* qh facet_mergeset is a temp */  qh NEARzero= qh lower_threshold= qh upper_threshold= NULL;  qh lower_bound= qh upper_bound= NULL;  qh gm_matrix= NULL;  qh gm_row= NULL;  if (qh line)    free (qh line);  if (qh half_space)    free (qh half_space);  if (qh feasible_point)    free (qh feasible_point);  if (qh feasible_string)    free (qh feasible_string);  if (qh temp_malloc)    free (qh temp_malloc);  qh line= qh feasible_string= NULL;  qh half_space= qh feasible_point= qh temp_malloc= NULL;  if (qh first_point && qh POINTSmalloc) {    free(qh first_point);    qh first_point= NULL;  }  trace5((qh ferr, "qh_freebuffers: finished\n"));} /* freebuffers *//*--------------------------------------------freeqhull- free global memory  if allmem, frees all allocated data structures  else, frees all long memory    rest of memory freed by qh_memfreeshort();*/void qh_freeqhull (boolT allmem) {  facetT *facet;  vertexT *vertex;  ridgeT *ridge, **ridgep;  mergeT *merge, **mergep;  trace1((qh ferr, "qh_freeqhull: free global memory\n"));  qh NOerrexit= True;  /* no more setjmp */  if (allmem) {    qh_clearcenters (qh_ASnone);    while ((vertex= qh vertex_list)) {      if (vertex->next)        qh_delvertex (vertex);      else {        qh_memfree (vertex, sizeof(vertexT));        qh vertex_list= NULL;      }    }  }else if (qh VERTEXneighbors) {    FORALLvertices       qh_setfreelong (&(vertex->neighbors));  }  if (allmem) {    FORALLfacets {      if (!facet->visible) {	FOREACHridge_(facet->ridges)	  ridge->seen= False;      }    }    FORALLfacets {      FOREACHridge_(facet->ridges)        ridge->seen ^= True;    }    while ((facet= qh facet_list)) {      FOREACHridge_(facet->ridges) {        if (ridge->seen) {          qh_setfree(&(ridge->vertices));          qh_memfree(ridge, sizeof(ridgeT));        }else          ridge->seen= True;      }      if (facet->next)        qh_delfacet (facet);      else {        qh_memfree (facet, sizeof(facetT));        qh facet_list= NULL;      }    }  }else {    FORALLfacets {      qh_setfreelong (&(facet->outsideset));      qh_setfreelong (&(facet->coplanarset));      if (!facet->simplicial) {        qh_setfreelong (&(facet->neighbors));        qh_setfreelong (&(facet->ridges));        qh_setfreelong (&(facet->vertices));      }    }  }  qh_setfree (&qh hash_table);  FOREACHmerge_(qh facet_mergeset)  /* usually empty */    qh_memfree (merge, sizeof(mergeT));  qh_freebuffers();  qh_freestatistics();  qh_settempfree_all();#if qh_QHpointer  free (qh_qh);  qh_qh= NULL;#endif} /* freeqhull *//*----------------------------------------------init_A- called before error handling initialized  argc/argv is used to initialize qh qhull_command.  argc may be 0  qh_errexit() may not be used*/void qh_init_A (FILE *infile, FILE *outfile, FILE *errfile, int argc, char *argv[]) {  qh_meminit (errfile);  qh_initqhull_start (infile, outfile, errfile);   qh_init_qhull_command (argc, argv);} /* init_A *//*----------------------------------------------init_B- called after points are defined  uses qh qhull_command from qh_init_qhull_command or qh_initflags  qh_errexit() may be used*/void qh_init_B (coordT *points, int numpoints, int dim, boolT ismalloc) {   qh_initqhull_globals (points, numpoints, dim, ismalloc);  qh_initqhull_mem();  /* mem.c and set.c are initialized */  qh_initqhull_buffers();  qh_initthresholds (qh qhull_command);  if (qh PROJECTinput || (qh DELAUNAY && qh PROJECTdelaunay))    qh_projectinput();  if (qh SCALEinput)    qh_scaleinput();  if (qh ROTATErandom >= 0) {    qh_randommatrix (qh gm_matrix, qh hull_dim, qh gm_row);    if (qh DELAUNAY) {      int k, lastk= qh hull_dim-1;      for (k= 0; k < lastk; k++) {        qh gm_row[k][lastk]= 0.0;        qh gm_row[lastk][k]= 0.0;      }      qh gm_row[lastk][lastk]= 1.0;    }    qh_gram_schmidt (qh hull_dim, qh gm_row);    qh_rotateinput (qh gm_row);  }} /* init_B *//*----------------------------------------------init_qhull_command- build qhull_command from argc/argv*/void qh_init_qhull_command(int argc, char *argv[]) {  int i;  if (argc)    strcpy (qh qhull_command, argv[0]);  for (i=1; i<argc; i++) {    if (strlen (qh qhull_command) + strlen(argv[i]) + 1 < sizeof(qh qhull_command)) {      strcat (qh qhull_command, " ");      strcat (qh qhull_command, argv[i]);    }else {      fprintf (qh ferr, "qhull input error: more than %d characters in command line\n",        (int)sizeof(qh qhull_command));      exit (1);  /* can not use qh_errexit */    }  }} /* init_qhull_command *//*----------------------------------------------initflags- set flags and initialized constants from command line  ignores first word (e.g., "qhull d"  see 'prompt' in unix.c for documentation  see also qh_initthresholds  strtol/strtod may or may not skip trailing spaces  sets qh qhull_command to command if needed*/void qh_initflags(char *command) {  int k, i, lastproject;  char *s= command, *t, *prev_s, *start, key;  boolT isgeom= False, wasproject;  realT r;  if (command != &qh qhull_command[0]) {    *qh qhull_command= '\0';    strncat( qh qhull_command, command, sizeof( qh qhull_command));  }  while (*s && !isspace(*s))  /* skip program name */    s++;  while (*s) {    while (*s && isspace(*s))      s++;    if (*s == '-')      s++;    prev_s= s;    switch (*s++) {    case 'd':      qh_option ("delaunay", NULL, NULL);      qh DELAUNAY= True;      break;    case 'f':      qh_option ("facets", NULL, NULL);      qh_appendprint (qh_PRINTfacets);      break;    case 'i':      qh_option ("incidence", NULL, NULL);      qh_appendprint (qh_PRINTincidences);      break;    case 'm':      qh_option ("mathematica", NULL, NULL);      qh_appendprint (qh_PRINTmathematica);      break;    case 'n':      qh_option ("normals", NULL, NULL);      qh_appendprint (qh_PRINTnormals);      break;    case 'o':      qh_option ("offFile", NULL, NULL);      qh_appendprint (qh_PRINToff);      break;    case 'p':      qh_option ("points", NULL, NULL);      qh_appendprint (qh_PRINTpoints);      break;    case 's':      qh_option ("summary", NULL, NULL);      qh PRINTsummary= True;      break;    case 'v':      qh_option ("voronoi", NULL, NULL);      qh VORONOI= True;      qh DELAUNAY= True;      break;    case 'A':      if (!isdigit(*s) && *s != '.' && *s != '-') 	fprintf(qh ferr, "qhull warning: no maximum cosine angle given for option A.  Ignored.\n");      else {	if (*s == '-') {	  qh premerge_cos= -qh_strtod (s, &s);          qh_option ("Angle-premerge-", NULL, &qh premerge_cos);	  qh PREmerge= True;	}else {	  qh postmerge_cos= qh_strtod (s, &s);          qh_option ("Angle-postmerge", NULL, &qh postmerge_cos);	  qh POSTmerge= True;	}	qh MERGING= True;       }      break;    case 'C':      if (!isdigit(*s) && *s != '.' && *s != '-')	fprintf(qh ferr, "qhull warning: no centrum radius given for option C.  Ignored.\n");      else {	if (*s == '-') {	  qh premerge_centrum= -qh_strtod (s, &s);          qh_option ("Centrum-premerge-", NULL, &qh premerge_centrum);	  qh PREmerge= True;	}else {	  qh postmerge_centrum= qh_strtod (s, &s);          qh_option ("Centrum-postmerge", NULL, &qh postmerge_centrum);	  qh POSTmerge= True;	}	qh MERGING= True;       }      break;    case 'E':      if (*s == '-')	fprintf(qh ferr, "qhull warning: negative maximum roundoff given for option A.  Ignored.\n");      else if (!isdigit(*s))	fprintf(qh ferr, "qhull warning: no maximum roundoff given for option E.  Ignored.\n");      else {	qh DISTround= qh_strtod (s, &s);        qh_option ("Error-roundoff", NULL, &qh DISTround);	qh SETroundoff= True;      }      break;    case 'H':      start= s;      qh HALFspace= True;      qh_strtod (s, &t);      while (t > s)  {        if (*t && !isspace (*t)) {	  if (*t == ',')	    t++;	  else	    fprintf (qh ferr, "qhull warning: origin for Halfspace intersection should be 'Hn,n,n,...'\n");	}        s= t;	qh_strtod (s, &t);      }      if (start < t) {        if (!(qh feasible_string= (char*)calloc (t-start+1, 1))) {          fprintf(qh ferr, "qhull error: insufficient memory for 'Hn,n,n'\n");          qh_errexit(qh_ERRmem, NULL, NULL);        }        strncpy (qh feasible_string, start, t-start);        qh_option ("Halfspace-about", NULL, NULL);        qh_option (qh feasible_string, NULL, NULL);      }else        qh_option ("Halfspace", NULL, NULL);      break;    case 'R':      if (!isdigit(*s))	fprintf(qh ferr, "qhull warning: no random perturbation given for option R.  Ignored\n");      else {	qh RANDOMfactor= qh_strtod (s, &s);        qh_option ("Random_perturbation", NULL, &qh RANDOMfactor);        qh RANDOMdist= True;      }      break;    case 'V':      if (!isdigit(*s) && *s != '-')	fprintf(qh ferr, "qhull warning: distance not given for option V.  Ignored\n");      else {	qh MINvisible= qh_strtod (s, &s);        qh_option ("Visible", NULL, &qh MINvisible);      }      break;    case 'U':      if (!isdigit(*s) && *s != '-')	fprintf(qh ferr, "qhull warning: distance not given for option U.  Ignored\n");      else {	qh MAXcoplanar= qh_strtod (s, &s);        qh_option ("U-coplanar", NULL, &qh MAXcoplanar);      }      break;    case 'W':      if (*s == '-')	fprintf(qh ferr, "qhull warning: negative width for option W.  Ignored.\n");      else if (!isdigit(*s))	fprintf(qh ferr, "qhull warning: no hull width given for option W.  Ignored\n");      else {	qh MINoutside= qh_strtod (s, &s);        qh_option ("W-outside", NULL, &qh MINoutside);        qh APPROXhull= True;      }      break;    /************  sub menus ***************/#pragma mark option_F    case 'F':      while (*s && !isspace(*s)) {	switch(*s++) {	case 'a':	  qh_option ("Farea", NULL, NULL);	  qh_appendprint (qh_PRINTarea);	  qh GETarea= True;	  break;	case 'A':	  qh_option ("FArea-total", NULL, NULL);	  qh GETarea= True;	  break;        case 'c':          qh_option ("Fcoplanars", NULL, NULL);          qh_appendprint (qh_PRINTcoplanars);          break;        case 'C':          qh_option ("FCentrums", NULL, NULL);          qh_appendprint (qh_PRINTcentrums);          break;	case 'd':          qh_option ("Fd-cdd-in", NULL, NULL);	  qh CDDinput= True;	  break;	case 'D':          qh_option ("FD-cdd-out", NULL, NULL);	  qh CDDoutput= True;	  break;	case 'F':	  qh_option ("FFacets-xridge", NULL, NULL);          qh_appendprint (qh_PRINTfacets_xridge);	  break;        case 'i':          qh_option ("Finner", NULL, NULL);          qh_appendprint (qh_PRINTinner);          break;        case 'I':          qh_option ("FIds", NULL, NULL);          qh_appendprint (qh_PRINTids);          break;        case 'm':          qh_option ("Fmerges", NULL, NULL);          qh_appendprint (qh_PRINTmerges);          break;        case 'n':          qh_option ("Fneighbors", NULL, NULL);          qh_appendprint (qh_PRINTneighbors);          break;        case 'N':          qh_option ("FNeighbors-vertex", NULL, NULL);          qh_appendprint (qh_PRINTvneighbors);          break;        case 'o':          qh_option ("Fouter", NULL, NULL);          qh_appendprint (qh_PRINTouter);          break;	case 'O':	  if (qh PRINToptions1st) {	    qh_option ("FOptions", NULL, NULL);	    qh_appendprint (qh_PRINToptions);	  }else 	    qh PRINToptions1st= True;	  break;	case 'p':	  qh_option ("Fpoint-intersect", NULL, NULL);	  qh_appendprint (qh_PRINTpointintersect);	  break;	case 'P':	  qh_option ("FPoint-nearest", NULL, NULL);	  qh_appendprint (qh_PRINTpointnearest);	  break;	case 'Q':	  qh_option ("FQhull", NULL, NULL);	  qh_appendprint (qh_PRINTqhull);	  break;        case 's':          qh_option ("Fsummary", NULL, NULL);          qh_appendprint (qh_PRINTsummary);          break;        case 'S':          qh_option ("FSize", NULL, NULL);          qh_appendprint (qh_PRINTsize);          qh GETarea= True;          break;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -