1 #ifndef XFIG_H_INCLUDED 2 #define XFIG_H_INCLUDED 3 4 #include <stdio.h> 5 #include "vektor.h" 6 #include <string> 7 8 // In time this class should also be used in renderer.cpp and in ep_xfig.cpp 9 10 class XFig 11 { 12 FILE *f; 13 IntegerVectorList p; 14 bool arrowOrigin; 15 bool arrowTarget; 16 int offsetX,offsetY; 17 public: XFig(FILE * f_)18 XFig(FILE *f_): 19 f(f_), 20 offsetX(0), 21 offsetY(0) 22 { 23 fprintf(f,"#FIG 3.2\n" 24 "Landscape\n" 25 "Center\n" 26 "Inches\n" 27 "Letter\n" 28 "100.00\n" 29 "Single\n" 30 "-2\n" 31 "1200 2\n"); 32 } 33 setOffset(int x,int y)34 void setOffset(int x, int y) 35 { 36 offsetX=x; 37 offsetY=y; 38 } 39 void beginDrawLine(bool arrowOrigin_=false, bool arrowTarget_=false, int thickness=1) 40 { 41 arrowOrigin=arrowOrigin_; 42 arrowTarget=arrowTarget_; 43 fprintf(f,"2 1 0 %i 0 7 50 -1 -1 0.000 0 0 -1 %i %i",thickness,int(arrowTarget),int(arrowOrigin)); 44 } addPoint(int x,int y)45 void addPoint(int x, int y) 46 { 47 IntegerVector v(2); 48 v[0]=x+offsetX; 49 v[1]=y+offsetY; 50 p.push_back(v); 51 } endDrawLine()52 void endDrawLine() 53 { 54 assert(p.size()>0); 55 fprintf(f," %i\n",(int)p.size()); 56 if(arrowOrigin) 57 fprintf(f,"\t 2 1 1.00 60.00 120.00\n"); 58 if(arrowTarget) 59 fprintf(f,"\t 2 1 1.00 60.00 120.00\n"); 60 for(IntegerVectorList::const_iterator i=p.begin();i!=p.end();i++) 61 { 62 fprintf(f," %i %i",(*i)[0]+offsetX,(*i)[1]+offsetY); 63 } 64 p=IntegerVectorList(); 65 fprintf(f,"\n"); 66 } 67 void drawString(int x, int y, string const &s, int size=12) 68 { 69 fprintf(f,"4 0 0 48 -1 0 %i 0.0000 4 135 270 %i %i ",size,x+offsetX,y+offsetY); 70 fprintf(f,"%s",s.c_str()); 71 fprintf(f,"\\001\n"); 72 } 73 void drawDot(int x, int y, int color=0, int radius=75) 74 { 75 fprintf(f,"1 3 0 1 %i %i 49 -1 20 0.000 1 0.0000 %i %i %i %i %i %i %i %i\n",0,color,x+offsetX,y+offsetY,radius,radius,x+offsetX,y+offsetY,x+offsetX+radius,y+offsetY); 76 } 77 78 // code for drawing intersection of halfspaces 79 struct Point 80 { 81 float x,y,z; dotPoint82 float dot(const Point &p)const{return x*p.x+y*p.y+z*p.z;} isInsidePoint83 bool isInside(const Point &p)const{return dot(p)>-0.05;} 84 // bool isInside(const Point &p)const{return dot(p)>0;} PointPoint85 Point(float x_, float y_, float z_):x(x_),y(y_),z(z_){} 86 void print()const; intersectPoint87 Point intersect(Point a, Point b)const 88 { 89 float A=dot(a); 90 float B=dot(b); 91 float cA=B/(B-A); 92 float cB=-A/(B-A); 93 94 return Point(a.x*cA+b.x*cB,a.y*cA+b.y*cB,a.z*cA+b.z*cB); 95 } 96 }; 97 typedef list<Point> Polygon; 98 void kickPoint(const Point &p, int mode); 99 void printPolygon(const Polygon &p); 100 void drawPolygon(const Polygon &vertices,int mode); 101 Polygon intersect(const Polygon &polygon, const Point &normal); 102 }; 103 104 105 #endif 106