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

📄 showme.c

📁 一个用于三角剖分的类.实用性非常好。对于需要从多边形
💻 C
📖 第 1 页 / 共 5 页
字号:
  }  if (*dim != 2) {    printf("  I only understand two-dimensional .poly files.\n");    return 1;  }  stringptr = findfield(stringptr);  if (*stringptr == '\0') {    extras = 0;  } else {    extras = (int) strtol (stringptr, &stringptr, 0);  }  if (extras < 0) {    printf("  Error:  %s has negative value for number of attributes.\n",           fname);    return 1;  }  stringptr = findfield(stringptr);  if (*stringptr == '\0') {    nodemarks = 0;  } else {    nodemarks = (int) strtol (stringptr, &stringptr, 0);  }  if (nodemarks < 0) {    printf("  Warning:  %s has negative value for number of point markers.\n",           fname);  }  if (nodemarks > 1) {    printf(   "  Warning:  %s has value greater than one for number of point markers.\n",           fname);  }  if (*pnodes > 0) {    *nodeptr = (REAL *) malloc((*pnodes + 1) * *dim * sizeof(REAL));    if (*nodeptr == (REAL *) NULL) {      printf("  Out of memory.\n");      return 1;    }    index = *dim;    smallerr = 1;    for (i = 0; i < *pnodes; i++) {      stringptr = readline(inputline, infile, fname);      nodenumber = (int) strtol (stringptr, &stringptr, 0);      if ((i == 0) && (*firstnumber == -1)) {        if (nodenumber == 0) {          *firstnumber = 0;        } else {          *firstnumber = 1;        }      }      if ((nodenumber != *firstnumber + i) && (smallerr)) {        printf("  Warning:  Points in %s are not numbered correctly.\n",               fname);        printf("            (starting with point %d).\n", *firstnumber + i);        smallerr = 0;      }      for (j = 0; j < *dim; j++) {        stringptr = findfield(stringptr);        if (*stringptr == '\0') {          printf("Error:  Point %d is missing a coordinate in %s.\n",                 *firstnumber + i, fname);          free(*nodeptr);          return 1;        }        (*nodeptr)[index++] = (REAL) strtod(stringptr, &stringptr);      }    }  }  stringptr = readline(inputline, infile, fname);  *edges = (int) strtol (stringptr, &stringptr, 0);  if (*edges < 0) {    printf("  Error:  %s contains %d segments.\n", fname, *edges);    free(*nodeptr);    return 1;  }  stringptr = findfield(stringptr);  if (*stringptr == '\0') {    segmentmarks = 0;  } else {    segmentmarks = (int) strtol (stringptr, &stringptr, 0);  }  if (segmentmarks < 0) {    printf("  Error:  %s has negative value for number of segment markers.\n",           fname);    free(*nodeptr);    return 1;  }  if (segmentmarks > 1) {    printf(   "  Error:  %s has value greater than one for number of segment markers.\n",           fname);    free(*nodeptr);    return 1;  }  *edgeptr = (int *) malloc(((*edges + 1) << 1) * sizeof(int));  if (*edgeptr == (int *) NULL) {    printf("  Out of memory.\n");    free(*nodeptr);    return 1;  }  index = 2;  smallerr = 1;  for (i = *firstnumber; i < *firstnumber + *edges; i++) {    stringptr = readline(inputline, infile, fname);    edgenumber = (int) strtol (stringptr, &stringptr, 0);    if ((edgenumber != i) && (smallerr)) {      printf("  Warning:  Segments in %s are not numbered correctly.\n",             fname);      printf("            (starting with segment %d).\n", i);      smallerr = 0;    }    stringptr = findfield(stringptr);    if (*stringptr == '\0') {      printf("Error:  Segment %d is missing its endpoints in %s.\n", i, fname);      free(*nodeptr);      free(*edgeptr);      return 1;    }    (*edgeptr)[index] = (int) strtol (stringptr, &stringptr, 0) + 1 -                        *firstnumber;    if (((*edgeptr)[index] < 1) || ((*edgeptr)[index] > maxnode)) {      printf("Error:  Segment %d has invalid endpoint in %s.\n", i, fname);      return 1;    }    stringptr = findfield(stringptr);    if (*stringptr == '\0') {      printf("Error:  Segment %d is missing an endpoint in %s.\n", i, fname);      free(*nodeptr);      free(*edgeptr);      return 1;    }    (*edgeptr)[index + 1] = (int) strtol (stringptr, &stringptr, 0) + 1 -                            *firstnumber;    if (((*edgeptr)[index + 1] < 1) || ((*edgeptr)[index + 1] > maxnode)) {      printf("Error:  Segment %d has invalid endpoint in %s.\n", i, fname);      return 1;    }    index += 2;  }  stringptr = readline(inputline, infile, fname);  *holes = (int) strtol (stringptr, &stringptr, 0);  if (*holes < 0) {    printf("  Error:  %s contains %d holes.\n", fname, *holes);    free(*nodeptr);    free(*edgeptr);    return 1;  }  *holeptr = (REAL *) malloc((*holes + 1) * *dim * sizeof(REAL));  if (*holeptr == (REAL *) NULL) {    printf("  Out of memory.\n");    free(*nodeptr);    free(*edgeptr);    return 1;  }  index = *dim;  smallerr = 1;  for (i = *firstnumber; i < *firstnumber + *holes; i++) {    stringptr = readline(inputline, infile, fname);    holenumber = (int) strtol (stringptr, &stringptr, 0);    if ((holenumber != i) && (smallerr)) {      printf("  Warning:  Holes in %s are not numbered correctly.\n", fname);      printf("            (starting with hole %d).\n", i);      smallerr = 0;    }    for (j = 0; j < *dim; j++) {      stringptr = findfield(stringptr);      if (*stringptr == '\0') {        printf("Error:  Hole %d is missing a coordinate in %s.\n", i,               fname);        free(*nodeptr);        free(*edgeptr);        free(*holeptr);        return 1;      }      (*holeptr)[index++] = (REAL) strtod(stringptr, &stringptr);    }  }  fclose(infile);  if (*pnodes > 0) {    index = *dim;    *xmin = *xmax = (*nodeptr)[index];    *ymin = *ymax = (*nodeptr)[index + 1];    for (i = 2; i <= *pnodes; i++) {      index += *dim;      x = (*nodeptr)[index];      y = (*nodeptr)[index + 1];      if (x < *xmin) {        *xmin = x;      }      if (y < *ymin) {        *ymin = y;      }      if (x > *xmax) {        *xmax = x;      }      if (y > *ymax) {        *ymax = y;      }    }  }  index = *dim;  for (i = 1; i <= *holes; i++) {    x = (*holeptr)[index];    y = (*holeptr)[index + 1];    if (x < *xmin) {      *xmin = x;    }    if (y < *ymin) {      *ymin = y;    }    if (x > *xmax) {      *xmax = x;    }    if (y > *ymax) {      *ymax = y;    }    index += *dim;  }  return 0;}int load_ele(fname, firstnumber, nodes, elems, corners, ptr)char *fname;int firstnumber;int nodes;int *elems;int *corners;int **ptr;{  FILE *infile;  char inputline[INPUTLINESIZE];  char *stringptr;  int extras;  int index;  int elemnumber;  int i, j;  int smallerr;  if (!quiet) {    printf("Opening %s.\n", fname);  }  infile = fopen(fname, "r");  if (infile == (FILE *) NULL) {    printf("  Error:  Cannot access file %s.\n", fname);    return 1;  }  stringptr = readline(inputline, infile, fname);  *elems = (int) strtol (stringptr, &stringptr, 0);  if (*elems < 1) {    printf("  Error:  %s contains %d triangles.\n", fname, *elems);    return 1;  }  stringptr = findfield(stringptr);  if (*stringptr == '\0') {    *corners = 3;  } else {    *corners = (int) strtol (stringptr, &stringptr, 0);  }  if (*corners < 3) {    printf("  Error:  Triangles in %s have only %d corners.\n", fname,           *corners);    return 1;  }  stringptr = findfield(stringptr);  if (*stringptr == '\0') {    extras = 0;  } else {    extras = (int) strtol (stringptr, &stringptr, 0);  }  if (extras < 0) {    printf("  Error:  %s has negative value for extra fields.\n", fname);    return 1;  }  *ptr = (int *) malloc((*elems + 1) * 3 * sizeof(int));  if (*ptr == (int *) NULL) {    printf("  Out of memory.\n");    return 1;  }  index = 3;  smallerr = 1;  for (i = firstnumber; i < firstnumber + *elems; i++) {    stringptr = readline(inputline, infile, fname);    elemnumber = (int) strtol (stringptr, &stringptr, 0);    if ((elemnumber != i) && (smallerr)) {      printf("  Warning:  Triangles in %s are not numbered correctly.\n",             fname);      printf("            (starting with triangle %d).\n", i);      smallerr = 0;    }    for (j = 0; j < 3; j++) {      stringptr = findfield(stringptr);      if (*stringptr == '\0') {        printf("Error:  Triangle %d is missing a corner in %s.\n", i, fname);        free(*ptr);        return 1;      }      (*ptr)[index] = (int) strtol (stringptr, &stringptr, 0) + 1 -                      firstnumber;      if (((*ptr)[index] < 1) || ((*ptr)[index] > nodes)) {        printf("Error:  Triangle %d has invalid corner in %s.\n", i, fname);        return 1;      }      index++;    }  }  fclose(infile);  return 0;}int load_edge(fname, firstnumber, nodes, edges, edgeptr, normptr)char *fname;int firstnumber;int nodes;int *edges;int **edgeptr;REAL **normptr;{  FILE *infile;  char inputline[INPUTLINESIZE];  char *stringptr;  int index;  int edgenumber;  int edgemarks;  int i;  int smallerr;  if (!quiet) {    printf("Opening %s.\n", fname);  }  infile = fopen(fname, "r");    if (infile == (FILE *) NULL) {      printf("  Error:  Cannot access file %s.\n", fname);      return 1;    }  stringptr = readline(inputline, infile, fname);  *edges = (int) strtol (stringptr, &stringptr, 0);  if (*edges < 1) {    printf("  Error:  %s contains %d edges.\n", fname, *edges);    return 1;  }  stringptr = findfield(stringptr);  if (*stringptr == '\0') {    edgemarks = 0;  } else {    edgemarks = (int) strtol (stringptr, &stringptr, 0);  }  if (edgemarks < 0) {    printf("  Error:  %s has negative value for number of edge markers.\n",           fname);    return 1;  }  if (edgemarks > 1) {    printf(   "  Error:  %s has value greater than one for number of edge markers.\n",           fname);    return 1;  }  *edgeptr = (int *) malloc(((*edges + 1) << 1) * sizeof(int));  if (*edgeptr == (int *) NULL) {    printf("  Out of memory.\n");    return 1;  }  *normptr = (REAL *) malloc(((*edges + 1) << 1) * sizeof(REAL));  if (*normptr == (REAL *) NULL) {    printf("  Out of memory.\n");    free(*edgeptr);    return 1;  }  index = 2;  smallerr = 1;  for (i = firstnumber; i < firstnumber + *edges; i++) {    stringptr = readline(inputline, infile, fname);    edgenumber = (int) strtol (stringptr, &stringptr, 0);    if ((edgenumber != i) && (smallerr)) {      printf("  Warning:  Edges in %s are not numbered correctly.\n", fname);      printf("            (starting with edge %d).\n", i);      smallerr = 0;    }    stringptr = findfield(stringptr);    if (*stringptr == '\0') {      printf("Error:  Edge %d is missing its endpoints in %s.\n", i, fname);      free(*edgeptr);      free(*normptr);      return 1;    }    (*edgeptr)[index] = (int) strtol (stringptr, &stringptr, 0) + 1 -                        firstnumber;    if (((*edgeptr)[index] < 1) || ((*edgeptr)[index] > nodes)) {      printf("Error:  Edge %d has invalid endpoint in %s.\n", i, fname);      return 1;    }    stringptr = findfield(stringptr);    if (*stringptr == '\0') {      printf("Error:  Edge %d is missing an endpoint in %s.\n", i, fname);      free(*edgeptr);      free(*normptr);      return 1;    }    (*edgeptr)[index + 1] = (int) strtol (stringptr, &stringptr, 0);    if ((*edgeptr)[index + 1] == -1) {      stringptr = findfield(stringptr);      if (*stringptr == '\0') {        printf("Error:  Edge %d is missing its direction in %s.\n", i, fname);        free(*edgeptr);        free(*normptr);        return 1;      }      (*normptr)[index] = (REAL) strtod(stringptr, &stringptr);      stringptr = findfield(stringptr);      if (*stringptr == '\0') {        printf("Error:  Edge %d is missing a direction coordinate in %s.\n",               i, fname);        free(*edgeptr);        free(*normptr);        return 1;      }      (*normptr)[index + 1] = (REAL) strtod(stringptr, &stringptr);    } else {

⌨️ 快捷键说明

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