curvedraw
diff src/curvefile.cc @ 6:6e980fddbf3b
curve export
author | John Tsiombikas <nuclear@member.fsf.org> |
---|---|
date | Fri, 18 Dec 2015 07:07:19 +0200 |
parents | |
children | 8bf96e11ed1f |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/curvefile.cc Fri Dec 18 07:07:19 2015 +0200 1.3 @@ -0,0 +1,68 @@ 1.4 +#include <stdlib.h> 1.5 +#include "curvefile.h" 1.6 + 1.7 +static bool save_curve(FILE *fp, const Curve *curve); 1.8 + 1.9 +bool save_curves(const char *fname, const Curve * const *curves, int count) 1.10 +{ 1.11 + FILE *fp = fopen(fname, "wb"); 1.12 + if(!fp) return false; 1.13 + 1.14 + bool res = save_curves(fp, curves, count); 1.15 + fclose(fp); 1.16 + return res; 1.17 +} 1.18 + 1.19 +bool save_curves(FILE *fp, const Curve * const *curves, int count) 1.20 +{ 1.21 + fprintf(stderr, "GCURVES\ncount %d\n", count); 1.22 + 1.23 + for(int i=0; i<count; i++) { 1.24 + if(!save_curve(fp, curves[i])) { 1.25 + return false; 1.26 + } 1.27 + } 1.28 + return true; 1.29 +} 1.30 + 1.31 +static const char *curve_type_str(CurveType type) 1.32 +{ 1.33 + switch(type) { 1.34 + case CURVE_LINEAR: 1.35 + return "polyline"; 1.36 + case CURVE_HERMITE: 1.37 + return "hermite"; 1.38 + case CURVE_BSPLINE: 1.39 + return "bspline"; 1.40 + } 1.41 + abort(); 1.42 +} 1.43 + 1.44 +static bool save_curve(FILE *fp, const Curve *curve) 1.45 +{ 1.46 + fprintf(fp, "curve {\n"); 1.47 + fprintf(fp, " type %s\n", curve_type_str(curve->get_type())); 1.48 + fprintf(fp, " cpcount %d\n", curve->size()); 1.49 + for(int i=0; i<curve->size(); i++) { 1.50 + Vector3 cp = curve->get_homo_point(i); 1.51 + fprintf(fp, " cp %g %g %g\n", cp.x, cp.y, cp.z); 1.52 + } 1.53 + fprintf(fp, "}\n"); 1.54 + return true; 1.55 +} 1.56 + 1.57 +Curve **load_curves(const char *fname, int *countret) 1.58 +{ 1.59 + FILE *fp = fopen(fname, "rb"); 1.60 + if(!fp) return false; 1.61 + 1.62 + Curve **res = load_curves(fp, countret); 1.63 + fclose(fp); 1.64 + return res; 1.65 +} 1.66 + 1.67 +Curve **load_curves(FILE *fp, int *countret) 1.68 +{ 1.69 + return 0; // TODO 1.70 +} 1.71 +