?? ai2mif.c
字號(hào):
/************************************************************* AI-2-MIF Version 1.0 DATE: 5/6/94 BY: Deron Jackson E-mail: (djackson@mit.edu) Platform: Windows/DOS Compiler: Borland C++ Version 2.0 This code is written explicitly for converting MATLAB 4.2's Adobe Illustrator output into Frame MIF (Maker Interchange Format). This allows MATLAB graphics to be imported into Frame. The resulting importing graphic is then EDITABLE in Frame. NOTES: ----- 1) This code is a quick and somewhat dirty solution to the problem of imporing MATLAB graphics. The code should support any MATLAB "line" graphic. This includes any 2D, 3D, mesh and contour plots consisting only of lines and text. However any SURFACE or BITMAPS graphics are not supported. 2) The code contains almost no error checking so use it at your own risk. 3) I am quite certain that this code will NOT WORK with anything other than a MATLAB AI file. I wrote the program by deciphering the symbol meanings from a number of MATLAB outputs. I had no references to the TRUE AI format. 4) Object clipping is rather crudely implemented. This keeps graphs from exceeding their axis edges. However I have not accounted for a few unlikely possibilities. 5) Matlab plots using NON-SOLID linetypes (dashed, dotted, etc.) which have a LARGE number of points will appear solid in FRAME. You can fix this by ungrouping the graphic after it is imported and using the Frame SMOOTH command on the individual traces. Frame seems to display the linetype correctly when the POLYLINE is smoothed. 6) You will notice that if you SCALE the graphic once imported into Frame the text size will not scale with it. This is anoying but I don't know a way around it. You can easily scale the text manually using the "character designer" menu. 7) All colors are mapped to Frame BLACK or NONE. Color support would not be to bad to add but I have no need for it. Modifications Changed handling of text so that the MIF special characters /\<> are escaped by a \. (R. Schreier, 07/29/96) Mex-ified. (R. Schreier, 07/30/97) Added color and text rotation (R. Schreier, 08/20/00) Change a leading minus signs into an EnDash (R. Schreier, 08/20/00)*************************************************************/#include <stdio.h>#include <stdlib.h>#include <string.h>#include <strings.h>#include <math.h>#include "mex.h"#ifdef MACINTOSH#include <unix.h>#endif#define PPI 72.0#define TRUE 1#define FALSE 0#define debug 0/* Make these GLOBALS */FILE *aifile;FILE *miffile;int finished=TRUE;int need_start=FALSE;int need_finish=FALSE;int grp=3;int pen=0;int points=1;int rec_bound=FALSE;int clip_in=FALSE;int clip_out=FALSE;float minx,maxx,miny,maxy;float xoffset=0,yoffset=0;int color = 0;char *ColorTable[]={"Black", "Black", "Yellow", "Black", "Magenta", "Black", "Red", "Black", "Cyan", "Black", "Green", "Black", "Blue", "Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black", "Black"}; /* White and black are both 0 0 0 1??? *//***********************************************************CHECK_FINISH()This procedure finishes a polyline command before addinganything else to the MIF file.************************************************************/void check_finish(){ if(finished==FALSE && need_start==FALSE) { if(points==2) /* All 2 pt. lines go in group 3 */ grp=3; else grp=1; /* Multiple point lines go in group 1 */ fprintf(miffile," <GroupID %d> <NumPoints %d>>\n",grp,points); finished=TRUE; }}/***********************************************************REC_PROCEDURE()This procedure records the limits of the current boundingbox. This is used to CLIP data.************************************************************/void rec_procedure(float x,float y, int start) { if(start) { minx=x; maxx=x; miny=y; maxy=y; } else { if(x<minx) minx=x; if(x>maxx) maxx=x; if(y<miny) miny=y; if(y>maxy) maxy=y; }}/***********************************************************CLIP_END()This procedure clips the end point of a line to the endgeof the bounding box.************************************************************/void clip_end(xs,ys,xe,ye)float xs,ys;float *xe,*ye;{ float xn,yn; if(!rec_bound) { if(*xe>maxx) { if(*xe!=xs) yn=((maxx-xs)/(*xe-xs))*(*ye-ys)+ys; xn=maxx; } if(*xe<minx) { if(*xe!=xs) yn=((xs-minx)/(xs-*xe))*(*ye-ys)+ys; xn=minx; } if(*ye>maxy) { if(*ye!=ys) xn=((maxy-ys)/(*ye-ys))*(*xe-xs)+xs; yn=maxy; } if(*ye<miny) { if(*ye!=ys) xn=((ys-miny)/(ys-*ye))*(*xe-xs)+xs; yn=miny; } *xe=xn; *ye=yn; }}/***********************************************************CLIP_START()This procedure clips the start point of a line to the edgeof the bounding box.************************************************************/void clip_start(xs,ys,xe,ye)float *xs,*ys;float xe,ye;{ float xn,yn; if(!rec_bound) { if(*xs>maxx) { if(*xs!=xe) yn=((*xs-maxx)/(*xs-xe))*(ye-*ys)+*ys; xn=maxx; } if(*xs<minx) { if(*xs!=xe) yn=((minx-*xs)/(xe-*xs))*(ye-*ys)+*ys; xn=minx; } if(*ys>maxy) { if(*ys!=ye) xn=((*ys-maxy)/(*ys-ye))*(xe-*xs)+*xs; yn=maxy; } if(*ys<miny) { xn=((miny-*ys)/(ye-*ys))*(xe-*xs)+*xs; yn=miny; } *xs=xn; *ys=yn; }}/***********************************************************IN_BOUNDS()This procedure checks to see if a point is inside thebounding box.************************************************************/int in_bounds(x,y)float x,y;{ if(x>=minx && x<=maxx && y>=miny && y<=maxy) return(TRUE); return(FALSE);}/***********************************************************DRAW_LINE()This procedure actually writes the MIF POLYLINE command.************************************************************/void draw_line(xs,ys,xe,ye)float xs,ys;float xe,ye;{ if(need_start){ if(debug){ printf("POLYLINE\n"); printf(" Start Point==> X: %f Y: %f",xs,ys); } fprintf(miffile,"<PolyLine <Pen %d> <Fill 15> <ObColor `%s'>\n",pen,ColorTable[color]); fprintf(miffile," <Point %f%c %f%c>",(xs+xoffset)/PPI,34,(-ys+yoffset)/PPI,34); if(debug && clip_in){ printf(" CLIPPED\n"); fprintf(miffile," # CLIPPED\n"); } else{ if(debug) printf("\n"); fprintf(miffile,"\n"); } need_start=FALSE; finished=FALSE; } if(debug) printf(" Next Point==> X: %f Y: %f",xe,ye); fprintf(miffile," <Point %f%c %f%c>",(xe+xoffset)/PPI,34,(-ye+yoffset)/PPI,34); if(clip_out) { if(debug) printf(" CLIPPED\n"); fprintf(miffile," # CLIPPED\n"); } else { if(debug) printf("\n"); fprintf(miffile,"\n"); } if(need_finish) { if(points==2) /* All 2 pt. lines go in group 3 */ grp=3; else grp=1; /* Multiple point lines go in group 1 */ fprintf(miffile," <GroupID %d> <NumPoints %d>>\n",grp,points); need_finish=FALSE; finished=TRUE; need_start=TRUE; points=1; }}/*******************************************//* Main *//*******************************************/void ai2mif(char* filename){ char c, aifilename[256],miffilename[256]; char msg5[256]; char msg4[256];
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -