VALUE method_read_one(VALUE self, VALUE fp) { struct Shape * shape = NULL; shape = read_shape(GET_STDIO_FILE(fp)); VALUE shape_rb = rb_shape_new(shape); free_shape(shape); return shape_rb; }
VALUE method_read_each(VALUE self, VALUE fp) { struct Shape * shape = NULL; while ((shape = read_shape(GET_STDIO_FILE(fp)))) { rb_yield(rb_shape_new(shape)); free_shape(shape); } }
int reduce_by_attribute(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { char name[21] = ""; char value[200] = ""; int invert_search = 0; int c; while ((c = getopt(argc, argv, "n:v:i")) != -1) switch (c) { case 'n': strncpy(name, optarg, 20); break; case 'v': strncpy(value, optarg, 20); break; case 'i': invert_search = 1; break; default: abort(); } struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) { if (shape->num_attributes == 0) continue; if (!invert_search) { if (strcmp(get_attribute(shape, name), value)!=0) continue; } else { if (strcmp(get_attribute(shape, name), value)==0) continue; } write_shape(pipe_out, shape); free_shape(shape); } }
int add_color_from_mysql(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { MYSQL mysql; if ((mysql_init(&mysql) == NULL)) { printf("mysql_init error\n"); return 0; } if (!mysql_real_connect(&mysql, "localhost", "root", "", "ADDRESS_POINT_WGS84", 0, NULL, 0)) { fprintf(stderr, "mysql_real_connect error (%s) (password for root should be blank)\n", mysql_error(&mysql)); return 0; } int min_cost = 0; int max_cost = 0; char sql[500] = "SELECT MIN(cost), MAX(cost) FROM results WHERE exec_id = 1096411009"; if (mysql_query(&mysql, sql) == 0) { MYSQL_RES * res = mysql_store_result(&mysql); MYSQL_ROW row; row = mysql_fetch_row(res); min_cost = atoi(row[0]); max_cost = atoi(row[1]); mysql_free_result(res); } int count_bad = 0; struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) { sprintf(sql, "SELECT cost FROM results WHERE dbf_id = %d AND exec_id = 1096411009 LIMIT 1", shape->unique_set_id); if (mysql_query(&mysql, sql) == 0) { MYSQL_RES * res = mysql_store_result(&mysql); MYSQL_ROW row = mysql_fetch_row(res); if (shape->num_vertex_arrays != 1 || shape->num_vertexs != 1) { fprintf(stderr, "shape->num_vertex_arrays != 1 || shape->num_vertexs != 1\n"); exit(1); } shape->num_vertex_arrays ++; shape->vertex_arrays = realloc(shape->vertex_arrays, sizeof(struct VertexArray)*shape->num_vertex_arrays); struct VertexArray *va = &shape->vertex_arrays[1]; va->array_type = GL_COLOR_ARRAY; va->num_dimensions = 3; va->vertexs = (float*)malloc(sizeof(float)*va->num_dimensions*shape->num_vertexs); if (row == NULL || row[0] == NULL) { va->vertexs[0] = 1; va->vertexs[1] = 0; va->vertexs[2] = 0; count_bad ++; } else { va->vertexs[0] = atof(row[0]) / (float)(max_cost - min_cost); va->vertexs[1] = atof(row[0]) / (float)(max_cost - min_cost); va->vertexs[2] = atof(row[0]) / (float)(max_cost - min_cost); } mysql_free_result(res); } write_shape(pipe_out, shape); free_shape(shape); } fprintf(stderr, "count_bad = %d\n", count_bad); }
int read_walk_distance_via_osm_to_bus_stop_from_iroquois(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { //char filename[300] = ""; //int num_attributes = -1; //int c; //while ((c = getopt(argc, argv, "f:a:")) != -1) //switch (c) //{ // case 'f': // strncpy(filename, optarg, 300); // break; // case 'a': // num_attributes = atoi(optarg); // break; // default: // abort(); //} CURL *curl = NULL; CURLcode res; struct MemoryStruct chunk; char url[400]; curl = curl_easy_init(); struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) // address points { if (shape->num_vertexs > 1) { fprintf(stderr, "This is likely not the data this script was expecting. (was expecting addres points, single vertex shapes)\n"); break; } float * v = get_vertex(shape, 0, 0); chunk.memory = NULL; chunk.size = 0; sprintf(url, "http://localhost:3333/walk_distance_to_a_bus_stop?from=%f,%f", v[1], v[0]); curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void *)&chunk); curl_easy_setopt(curl, CURLOPT_USERAGENT, "libcurl-agent/1.0"); res = curl_easy_perform(curl); if (chunk.size == 0) { set_attribute(shape, "route_error", "can not find a bus stop"); } else { char * walk_distance = strtok(chunk.memory, ","); char * myttc_stop_id = strtok(NULL, ","); char * myttc_stop_name = strtok(NULL, ","); if (walk_distance != NULL) set_attribute(shape, "walk_distance", walk_distance); if (myttc_stop_id != NULL) set_attribute(shape, "myttc_stop_id", myttc_stop_id); if (myttc_stop_name != NULL) set_attribute(shape, "myttc_stop_name", myttc_stop_name); } free(chunk.memory); // manipulate data here if you like write_shape(pipe_out, shape); free_shape(shape); } }
int write_json(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { char file_name[300] = ""; int add_whitespace = 0; int c; while ((c = getopt(argc, argv, "f:w")) != -1) switch (c) { case 'f': strncpy(file_name, optarg, 300); break; case 'w': add_whitespace = 1; break; default: abort(); } if (file_name[0] == 0 && argc == 2 && argv[1] != NULL && argv[1][0] != '-') strncpy(file_name, argv[1], sizeof(file_name)); //char gl_types_c[8][20] = {"GL_POINTS", "GL_LINES", "GL_LINE_LOOP", "GL_LINE_STRIP", "GL_TRIANGLES", "GL_TRIANGLE_STRIP", "GL_TRIANGLE_FAN"}; FILE * fp = NULL; if (file_name[0] != 0) { fp = fopen(file_name, "w"); if (fp == NULL) fprintf(stderr, "%s: ERROR: could not write to '%s'\n", argv[0], file_name); } if (fp == NULL) fp = pipe_out; int num_shapes = 0; fprintf(fp, "["); struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) { if (num_shapes != 0) fprintf(fp, ", "); fprintf(fp, "{%s", (add_whitespace ? "\n" : "")); fprintf(fp, "%s\"unique_set_id\":\"%d\",%s", (add_whitespace ? " " : ""), shape->unique_set_id, (add_whitespace ? "\n" : "")); if (shape->num_attributes > 0) { fprintf(fp, "%s\"attributes\":{%s", (add_whitespace ? " " : ""), (add_whitespace ? "\n" : "")); int i; for (i = 0 ; i < shape->num_attributes ; i++) { struct Attribute * attribute = &shape->attributes[i]; fprintf(fp, "%s\"%s\":\"%s\"%s%s", (add_whitespace ? " " : ""), attribute->name, attribute->value, (i == shape->num_attributes-1)?"":",", (add_whitespace ? "\n" : "")); } fprintf(fp, "%s},%s", (add_whitespace ? " " : ""), (add_whitespace ? "\n" : "")); } if (shape->num_vertex_arrays > 0 || shape->num_vertexs > 0) { fprintf(fp, "%s\"vertex_arrays\":[", (add_whitespace ? " " : "")); int i; for (i = 0 ; i < shape->num_vertex_arrays ; i++) { struct VertexArray * va = &shape->vertex_arrays[i]; fprintf(fp, "%s{%s", (i!=0?",":""), (add_whitespace ? "\n" : "")); fprintf(fp, "%s\"array_type\":\"%s\",%s", (add_whitespace ? " " : ""), get_array_type_name(va->array_type), (add_whitespace ? "\n" : "")); fprintf(fp, "%s\"num_dimensions\":\"%d\",%s", (add_whitespace ? " " : ""), va->num_dimensions, (add_whitespace ? "\n" : "")); fprintf(fp, "%s\"vertexs\":[", (add_whitespace ? " " : "")); int j; for (j = 0 ; j < shape->num_vertexs ; j++) { float * v = get_vertex(shape, i, j); if (va->num_dimensions == 1) fprintf(fp, "%f%s", v[0], j==shape->num_vertexs-1?"":","); else if (va->num_dimensions == 2) fprintf(fp, "[%f,%f]%s", v[0], v[1], j==shape->num_vertexs-1?"":","); else if (va->num_dimensions == 3) fprintf(fp, "[%f,%f,%f]%s", v[0], v[1], v[2], j==shape->num_vertexs-1?"":","); else if (va->num_dimensions == 4) fprintf(fp, "[%f,%f,%f,%f]%s", v[0], v[1], v[2], v[3], j==shape->num_vertexs-1?"":","); } fprintf(fp, "]%s", (add_whitespace ? "\n" : "")); fprintf(fp, "%s}", (add_whitespace ? " " : "")); } fprintf(fp, "],%s", (add_whitespace ? "\n" : "")); } fprintf(fp, "%s\"gl_type\":\"%s\"%s", (add_whitespace ? " " : ""), get_gl_type_name(shape->gl_type), (add_whitespace ? "\n" : "")); free_shape(shape); fprintf(fp, "}"); num_shapes++; } fprintf(fp, "]%s", (add_whitespace ? "\n" : "")); if (fp != pipe_out) fclose(fp); }
int inspect(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { int num_to_display = 4; char selected_attribute[100] = ""; int c; while ((c = getopt(argc, argv, "n:a:")) != -1) switch (c) { case 'n': num_to_display = clamp_int(atoi(optarg), 3, 100); break; case 'a': strncpy(selected_attribute, optarg, sizeof(selected_attribute)); break; default: abort(); } int num_shapes_without_selected_attribute = 0; int num_values = 0; char ** values = NULL; int * value_counts = NULL; int num_shapes = 0; int num_shapes_with_no_attributes = 0; int num_shapes_with_no_vertexs = 0; int num_vertexs = 0; int num_each_gl_type[7] = {0,0,0,0,0,0,0}; struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) { if (shape->gl_type < 7) num_each_gl_type[shape->gl_type]++; if (shape->num_vertexs == 0) num_shapes_with_no_vertexs++; num_vertexs += shape->num_vertexs; num_shapes++; long i; if (selected_attribute[0] != 0) // -a [selected_attribute] provided { int has_attribute = 0; for (i = 0 ; i < shape->num_attributes ; i++) { struct Attribute * attribute = &shape->attributes[i]; // only process the selected attribute if (strcmp(shape->attributes[i].name, &selected_attribute[0]) != 0) continue; has_attribute = 1; // has this value been found previously? int j, found = 0; for (j = 0 ; j < num_values ; j++) if (strcmp(shape->attributes[i].value, values[j])==0) { found = 1; value_counts[j]++; break; } if (found) continue; // value hasn't been found, add it to the list values = realloc(values, sizeof(char*)*(num_values+1)); value_counts = realloc(value_counts, sizeof(int)*(num_values+1)); values[num_values] = malloc(shape->attributes[i].value_length+1); value_counts[num_values] = 1; strncpy(values[num_values], shape->attributes[i].value, shape->attributes[i].value_length); num_values++; } if (has_attribute == 0) num_shapes_without_selected_attribute++; } else if (num_shapes <= 2) { long count_zero = 0; fprintf(stderr, "shape:\n"); fprintf(stderr, " version: %d\n", shape->version); fprintf(stderr, " unique_set_id: %d\n", shape->unique_set_id); fprintf(stderr, " gl_type: %s\n", get_gl_type_name(shape->gl_type)); fprintf(stderr, " num_attributes: %d\n", shape->num_attributes); if (shape->num_attributes) fprintf(stderr, " attributes:\n"); for (i = 0 ; i < shape->num_attributes ; i++) { struct Attribute * attribute = &shape->attributes[i]; fprintf(stderr, " %s(%d): '%s'\n", attribute->name, attribute->value_length, attribute->value); } fprintf(stderr, " num_vertexs: %d\n", shape->num_vertexs); fprintf(stderr, " num_vertex_arrays: %d\n", shape->num_vertex_arrays); if (shape->num_vertex_arrays) fprintf(stderr, " vertex_arrays:\n"); for (i = 0 ; i < shape->num_vertex_arrays ; i++) { fprintf(stderr, " array_type: %s\n", get_array_type_name(shape->vertex_arrays[i].array_type)); fprintf(stderr, " num_dimensions: %d\n", shape->vertex_arrays[i].num_dimensions); fprintf(stderr, " vertexs:\n"); if (shape->num_vertexs > 0 && shape->vertex_arrays[i].num_dimensions > 0) { long j,k; for (k = 0 ; k < shape->num_vertexs ; k++) { if (k < num_to_display) fprintf(stderr, " "); int is_zero = 1; for (j = 0 ; j < shape->vertex_arrays[i].num_dimensions ; j++) { if (shape->vertex_arrays[i].vertexs[k*shape->vertex_arrays[i].num_dimensions + j] != 0.0) is_zero = 0; if (k < num_to_display) fprintf(stderr, "%f ", shape->vertex_arrays[i].vertexs[k*shape->vertex_arrays[i].num_dimensions + j]); } if (is_zero) count_zero ++; if (k < num_to_display) fprintf(stderr, "\n"); else if (k == num_to_display) fprintf(stderr, " ...\n"); } } if (i == num_to_display) fprintf(stderr, " [...]\n"); } if (count_zero > 0) fprintf(stderr, " count_zero: %ld\n", count_zero); } } fprintf(pipe_err, "{\n"); if (selected_attribute[0] != 0) // -a [attribute_name] provided { fprintf(pipe_err, " \"num_unique_values\": %d,\n", num_values); fprintf(pipe_err, " \"selected_attribute\": \"%s\",\n", selected_attribute); if (num_shapes_without_selected_attribute > 0) fprintf(pipe_err, " \"num_shapes_without_selected_attribute\": %d,\n", num_shapes_without_selected_attribute); if (num_values > 0) fprintf(pipe_err, " \"first_%d_unique_values\": [\n", (num_to_display < num_values) ? num_to_display : num_values); int i; for (i = 0 ; i < num_values ; i++) { if (i < num_to_display) fprintf(pipe_err, " \"%s (%d)\"%s\n", values[i], value_counts[i], (i==num_values-1)?"":","); free(values[i]); } if (num_values > 0) fprintf(pipe_err, " ]\n"); free(values); free(value_counts); } if (num_shapes_with_no_vertexs > 0) printf(" \"num_shapes_with_no_vertexs\": %d,\n", num_shapes_with_no_vertexs); fprintf(pipe_err, " \"num_shapes\": %d,\n", num_shapes); fprintf(pipe_err, " \"num_vertexs\": %d,\n", num_vertexs); fprintf(pipe_err, " \"num_each_gl_type\": [%d,%d,%d,%d,%d,%d,%d]\n", num_each_gl_type[0], num_each_gl_type[1], num_each_gl_type[2], num_each_gl_type[3], num_each_gl_type[4], num_each_gl_type[5], num_each_gl_type[6]); fprintf(pipe_err, "}\n"); }
int add_color_from_source_interpolation(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { char filename[300] = ""; int num_attributes = -1; int c; while ((c = getopt(argc, argv, "f:a:")) != -1) switch (c) { case 'f': strncpy(filename, optarg, 300); break; case 'a': num_attributes = atoi(optarg); break; default: abort(); } if (filename[0] == 0) { fprintf(stderr, "%s: ERROR, -f [filename] required.\n", argv[0]); return EXIT_FAILURE; } FILE * fp = fopen(filename, "r"); if (fp == NULL) { fprintf(stderr, "%s: ERROR, -f '%s' is not a file or does not exist.\n", argv[0], filename); return EXIT_FAILURE; } struct Shape * source_shape = read_shape(fp); fclose(fp); if (source_shape->num_vertex_arrays != 1) { fprintf(stderr, "%s: ERROR, source shape has %d vertex_arrays (should be only 1)\n", argv[0], source_shape->num_vertex_arrays); return EXIT_FAILURE; } if (source_shape->num_vertexs == 0) { fprintf(stderr, "%s: ERROR, source shape has no vertexs\n", argv[0]); return EXIT_FAILURE; } //if (source_shape->vertex_arrays[0].num_dimensions != 1) { fprintf(stderr, "%s: ERROR, source shape has %d dimensions, supports only 1\n", argv[0], source_shape->vertex_arrays[0].num_dimensions); return EXIT_FAILURE; } //write_shape(pipe_out, source_shape); struct BBox * source_bbox = get_bbox(source_shape, NULL); struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) { if (shape->vertex_arrays[0].num_dimensions != source_shape->vertex_arrays[0].num_dimensions) { fprintf(stderr, "%s: ERROR, shape has %d dimensions, source shape has %d\n", argv[0], shape->vertex_arrays[0].num_dimensions, source_shape->vertex_arrays[0].num_dimensions); return EXIT_FAILURE; } struct VertexArray * cva = get_or_add_array(shape, GL_COLOR_ARRAY); set_num_dimensions(shape, 1, shape->vertex_arrays[0].num_dimensions); struct BBox * bbox = get_bbox(shape, NULL); int i; for (i = 0 ; i < shape->num_vertexs ; i++) { float j = i / (float)shape->num_vertexs * (float)source_shape->num_vertexs; float * v = get_vertex(shape, 0, i); float * cv = get_vertex(shape, 1, i); float * s1 = get_vertex(source_shape, 0, (int)floor(j)); //float * s2 = ((int)ceil(j) == shape->num_vertexs) ? s1 : get_vertex(source_shape, 0, (int)ceil(j)); // kbfu, should table s2 into account, would produce a better result int d; for (d = 0 ; d < shape->vertex_arrays[0].num_dimensions ; d++) { float * sv = get_vertex(source_shape, 0, (int)floor(j)); cv[d] = (s1[d] - bbox->minmax[d].min) / (bbox->minmax[d].max - bbox->minmax[d].min) + bbox->minmax[d].min; } //float value = (s1[0] - bbox->minmax[0].min) / (bbox->minmax[0].max - bbox->minmax[0].min) + bbox->minmax[0].min; //fprintf(stderr, "s%d[0] = %f s%d[0] = %f\n", (int)floor(j), s1[0], (int)ceil(j), s2[0]); //cv[0] = value; // i / (float)shape->num_vertexs; //cv[1] = 0.0; // i / (float)shape->num_vertexs; //cv[2] = 1.0 - value; // i / (float)shape->num_vertexs; //if (i > 10) break; } // manipulate data here if you like write_shape(pipe_out, shape); free_shape(shape); } free_shape(source_shape); free_bbox(source_bbox); }
int main(int argc,char **argv) { char arg; int count=1; int *tlist; double time; char *out_file=NULL; int VERBOSE=0; double *vlist; int nfac=0,nvert=0; double E0[]={0,0,0}; double t0=0,Gamma=50,A=0.1,R=1.0; int N=1024; double *Tres; double angles[]={0,0,0}; double Angles[]={0,0,0}; char shape_file[100]; shape_file[0]='\0'; if(argc==1) { printf("This program calculates the temperature distribution of an asteroid. Shadowing effects are taken into account, but not self-heating due to reflected radiation.\n"); printf("Usage:\n"); printf("thermal -a beta lambda P -E e0 e1 e2 -S shapefile -A albedo -G Gamma -N nFouriercoeffs -t obstime [-o outfile -R Heliodist -V]\n"); printf("Where beta lambda are the directions of rotation axis, P rotation period in hours, [e0,e1,e2] is the asteroid->Sun vector (in AU), shapefile is the file containing vertex and facet list,\n"); printf("nFouriercoeffs is the length of FFT used, obstime is the observation time (JD), Gamma is the thermal inertia, Heliodist is the distance (AU) between the asteroid and the Sun (if not set, norm of the vector [e0,e1,e2] is used)\n"); printf("-V prints values of input parameters\n"); printf("if outfile is not set, results are printed to stdout\n"); exit(0); } while(count<argc) { if(argv[count][0]=='-') arg=argv[count][1]; else { fprintf(stderr,"Bad argument %s\n",argv[count]); exit(1); } switch(arg) { case 'a': Angles[0]=atof(argv[count+1]); Angles[1]=atof(argv[count+2]); Angles[2]=atof(argv[count+3]); angles[0]=(90-Angles[0])*PI/180; angles[1]=Angles[1]*PI/180; angles[2]=24.0*2*PI/Angles[2]; count=count+4; break; case 'S': strcpy(shape_file,argv[count+1]); count=count+2; break; case 'E': E0[0]=atof(argv[count+1]); E0[1]=atof(argv[count+2]); E0[2]=atof(argv[count+3]); count=count+4; R=NORM(E0); E0[0]=E0[0]/R; E0[1]=E0[1]/R; E0[2]=E0[2]/R; break; case 'A': A=atof(argv[count+1]); count=count+2; break; case 'N': N=atoi(argv[count+1]); count=count+2; break; case 'G': Gamma=atof(argv[count+1]); count=count+2; break; case 'o': out_file=calloc(100,sizeof(char)); strcpy(out_file,argv[count+1]); count=count+2; break; case 't': time=atof(argv[count+1]); count=count+2; break; case 'R': R=atof(argv[count+1]); count=count+2; break; case 'V': VERBOSE=1; count=count+2; break; default: printf("Unknown argument: %s\n",argv[count]); count=count+1; } } if(shape_file[0]=='\0') { fprintf(stderr,"Shape file is not set, aborting\n"); exit(1); } if(E0[0]==0&&E0[1]==0&&E0[2]==0) { fprintf(stderr,"E is not set, aborting\n"); exit(1); } read_shape(shape_file,&tlist,&vlist,&nfac,&nvert,0); if(VERBOSE==1) { printf("Angles: %f %f %f\n",Angles[0],Angles[1],Angles[2]); printf("Input Shape file: %s\n",shape_file); printf("Vertices: %d Facets: %d\n",nvert,nfac); printf("E: %f %f %f\n",E0[0],E0[1],E0[2]); printf("Range: %f Albedo: %f Gamma: %f\n",R,A,Gamma); printf("Number of Fourier coefficients: %d\n",N); } read_shape(shape_file,&tlist,&vlist,&nfac,&nvert,0); Tres=calloc(nfac,sizeof(double)); Calculate_Temp(tlist,vlist,nfac,nvert,angles,E0,time,Gamma,A,R,N,Tres); if(out_file!=NULL) { FILE *fid=fopen(out_file,"w"); for(int j=0;j<nfac;j++) fprintf(fid,"%4.2f ",Tres[j]); fprintf(fid,"\n"); fclose(fid); } else { for(int j=0;j<nfac;j++) fprintf(stdout,"%4.2f ",Tres[j]); fprintf(stdout,"\n"); } }
int write_pdf(int argc, char ** argv, FILE * pipe_in, FILE * pipe_out, FILE * pipe_err) { char * filename = argc > 1 ? argv[1] : "output.pdf"; if (argc == 1) { fprintf(stderr, "no filename specified, using '%s'\n", filename); } float b[3][2] = { {FLT_MAX, -FLT_MAX}, {FLT_MAX, -FLT_MAX}, {FLT_MAX, -FLT_MAX} }; HPDF_Doc pdf; pdf = HPDF_New(NULL, NULL); if (!pdf) { fprintf(stderr, "ERROR: cannot create pdf object.\n"); return 1; } HPDF_SetCompressionMode (pdf, HPDF_COMP_ALL); HPDF_SetPageMode (pdf, HPDF_PAGE_MODE_USE_OUTLINE); int num_shapes = 0; struct Shape ** shapes = NULL; HPDF_Page page; page = HPDF_AddPage (pdf); HPDF_Page_SetSize (page, HPDF_PAGE_SIZE_LETTER, HPDF_PAGE_PORTRAIT); long i = 0; struct Shape * shape = NULL; while ((shape = read_shape(pipe_in))) { num_shapes++; shapes = (struct Shape **)realloc(shapes, sizeof(struct Shape*)*num_shapes); if (shapes == NULL) { fprintf(stderr, "realloc for shapes failed :(\n"); exit(0); } shapes[num_shapes-1] = shape; long j; for (j = 0 ; j < shape->num_vertexs ; j++) { float * v = get_vertex(shape, 0, j); if (v[0] < b[0][0]) b[0][0] = v[0]; if (v[0] > b[0][1]) b[0][1] = v[0]; if (v[1] < b[1][0]) b[1][0] = v[1]; if (v[1] > b[1][1]) b[1][1] = v[1]; } } float dx = b[0][1] - b[0][0]; float dy = b[1][1] - b[1][0]; float ratio = dy / dx; HPDF_Page_SetWidth(page, 2000); HPDF_Page_SetHeight(page, 2000.0 * ratio); for (i = 0 ; i < num_shapes ; i++) { shape = shapes[i]; //if (shape->vertex_arrays[0].num_dimensions < 2) { fprintf(stderr, "\n"); continue; } long j; for (j = 0 ; j < shape->num_vertexs ; j++) { float * v = get_vertex(shape, 0, j); if (j == 0) HPDF_Page_MoveTo(page, (v[0] - b[0][0]) / dx * 2000.0, (v[1] - b[1][0]) / dy * (2000.0 * ratio)); else HPDF_Page_LineTo(page, (float)(v[0] - b[0][0]) / dx * 2000.0, (float)(v[1] - b[1][0]) / dy * (2000.0 * ratio)); } if (shape->gl_type == GL_LINE_LOOP) { float * v = get_vertex(shape, 0, 0); HPDF_Page_LineTo(page, (float)(v[0] - b[0][0]) / dx * 2000.0, (float)(v[1] - b[1][0]) / dy * (2000.0 * ratio)); } HPDF_Page_Stroke(page); free_shape(shape); } free(shapes); HPDF_SaveToFile (pdf, filename); HPDF_Free(pdf); }