lemon/graph_to_eps.h
changeset 1577 15098fb5275c
parent 1574 697ed4dd309a
child 1588 b79bcba43661
equal deleted inserted replaced
5:fb5e39f31832 6:c07061cf2986
    53   ///Default constructor
    53   ///Default constructor
    54   Color() {}
    54   Color() {}
    55   ///Constructor
    55   ///Constructor
    56   Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
    56   Color(double r,double g,double b) :_r(r),_g(g),_b(b) {};
    57   ///Returns the red component
    57   ///Returns the red component
    58  
    58   double & red() {return _r;}
    59   ///\todo \c red() could be a better name...
    59   ///Returns the red component
    60   ///
    60   const double & red() const {return _r;}
    61   double getR() const {return _r;}
       
    62   ///Returns the green component
    61   ///Returns the green component
    63   double getG() const {return _g;}
    62   double & green() {return _g;}
       
    63   ///Returns the green component
       
    64   const double & green() const {return _g;}
    64   ///Returns the blue component
    65   ///Returns the blue component
    65   double getB() const {return _b;}
    66   double & blue() {return _b;}
       
    67   ///Returns the blue component
       
    68   const double & blue() const {return _b;}
    66   ///Set the color components
    69   ///Set the color components
    67   void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
    70   void set(double r,double g,double b) { _r=r;_g=g;_b=b; };
    68 };
    71 };
    69 
    72 
    70 ///Maps <tt>int</tt>s to different \ref Color "Color"s
    73 ///Maps <tt>int</tt>s to different \ref Color "Color"s
   154 
   157 
   155 ///Returns a \ref Color which is as different from the given parameter
   158 ///Returns a \ref Color which is as different from the given parameter
   156 ///as it is possible.
   159 ///as it is possible.
   157 inline Color distantColor(const Color &c) 
   160 inline Color distantColor(const Color &c) 
   158 {
   161 {
   159   return Color(c.getR()<.5?1:0,c.getG()<.5?1:0,c.getB()<.5?1:0);
   162   return Color(c.red()<.5?1:0,c.green()<.5?1:0,c.blue()<.5?1:0);
   160 }
   163 }
   161 ///Returns black for light colors and white for the dark ones.
   164 ///Returns black for light colors and white for the dark ones.
   162 
   165 
   163 ///Returns black for light colors and white for the dark ones.
   166 ///Returns black for light colors and white for the dark ones.
   164 inline Color distantBW(const Color &c){
   167 inline Color distantBW(const Color &c){
   165   double v=(.2125*c.getR()+.7154*c.getG()+.0721*c.getB())<.5?1:0;
   168   double v=(.2125*c.red()+.7154*c.green()+.0721*c.blue())<.5?1:0;
   166   return Color(v,v,v);
   169   return Color(v,v,v);
   167 }
   170 }
   168 
   171 
   169 ///Default traits class of \ref GraphToEps
   172 ///Default traits class of \ref GraphToEps
   170 
   173 
   391       return os.str();
   394       return os.str();
   392     }
   395     }
   393   static std::string psOut(const Color &c) 
   396   static std::string psOut(const Color &c) 
   394     {
   397     {
   395       std::ostringstream os;	
   398       std::ostringstream os;	
   396       os << c.getR() << ' ' << c.getG() << ' ' << c.getB();
   399       os << c.red() << ' ' << c.green() << ' ' << c.blue();
   397       return os.str();
   400       return os.str();
   398     }
   401     }
   399   
   402   
   400 public:
   403 public:
   401   GraphToEps(const T &t) : T(t), dontPrint(false) {};
   404   GraphToEps(const T &t) : T(t), dontPrint(false) {};
   700     
   703     
   701     os << "%!PS-Adobe-2.0 EPSF-2.0\n";
   704     os << "%!PS-Adobe-2.0 EPSF-2.0\n";
   702     if(_title.size()>0) os << "%%Title: " << _title << '\n';
   705     if(_title.size()>0) os << "%%Title: " << _title << '\n';
   703      if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
   706      if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
   704 //        << "%%Copyright: XXXX\n"
   707 //        << "%%Copyright: XXXX\n"
   705     os << "%%Creator: LEMON GraphToEps function\n";
   708     os << "%%Creator: LEMON, graphToEps()\n";
   706     
   709     
   707     {
   710     {
   708       char cbuf[50];
   711       char cbuf[50];
   709       timeval tv;
   712       timeval tv;
   710       gettimeofday(&tv, 0);
   713       gettimeofday(&tv, 0);
   723       bb = BoundingBox<double>(xy<double>(0,0));
   726       bb = BoundingBox<double>(xy<double>(0,0));
   724     }
   727     }
   725     if(_scaleToA4)
   728     if(_scaleToA4)
   726       os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
   729       os <<"%%BoundingBox: 0 0 596 842\n%%DocumentPaperSizes: a4\n";
   727     else os << "%%BoundingBox: "
   730     else os << "%%BoundingBox: "
   728 	    << bb.left()*  _scale-_xBorder << ' '
   731 	    << bb.left()   * _scale - _xBorder << ' '
   729 	    << bb.bottom()*_scale-_yBorder << ' '
   732 	    << bb.bottom() * _scale - _yBorder << ' '
   730 	    << bb.right()* _scale+_xBorder << ' '
   733 	    << bb.right()  * _scale + _xBorder << ' '
   731 	    << bb.top()*   _scale+_yBorder << '\n';
   734 	    << bb.top()    * _scale + _yBorder << '\n';
   732     
   735     
   733     os << "%%EndComments\n";
   736     os << "%%EndComments\n";
   734     
   737     
   735     //x1 y1 x2 y2 x3 y3 cr cg cb w
   738     //x1 y1 x2 y2 x3 y3 cr cg cb w
   736     os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
   739     os << "/lb { setlinewidth setrgbcolor newpath moveto\n"
   863 // 	      for(int i=0;i<INTERPOL_PREC;++i)
   866 // 	      for(int i=0;i<INTERPOL_PREC;++i)
   864 // 		if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
   867 // 		if(isInsideNode(bez((t1+t2)/2)-t,rn,node_shape)) t1=(t1+t2)/2;
   865 // 		else t2=(t1+t2)/2;
   868 // 		else t2=(t1+t2)/2;
   866 // 	      bez=bez.after((t1+t2)/2);
   869 // 	      bez=bez.after((t1+t2)/2);
   867 	      os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth "
   870 	      os << _edgeWidths[*e]*_edgeWidthScale << " setlinewidth "
   868 		 << _edgeColors[*e].getR() << ' '
   871 		 << _edgeColors[*e].red() << ' '
   869 		 << _edgeColors[*e].getG() << ' '
   872 		 << _edgeColors[*e].green() << ' '
   870 		 << _edgeColors[*e].getB() << " setrgbcolor newpath\n"
   873 		 << _edgeColors[*e].blue() << " setrgbcolor newpath\n"
   871 		 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
   874 		 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
   872 		 << bez.p2.x << ' ' << bez.p2.y << ' '
   875 		 << bez.p2.x << ' ' << bez.p2.y << ' '
   873 		 << bez.p3.x << ' ' << bez.p3.y << ' '
   876 		 << bez.p3.x << ' ' << bez.p3.y << ' '
   874 		 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
   877 		 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
   875 	      xy<double> dd(rot90(linend-apoint));
   878 	      xy<double> dd(rot90(linend-apoint));
   883 	      os << _coords[g.source(*e)].x << ' '
   886 	      os << _coords[g.source(*e)].x << ' '
   884 		 << _coords[g.source(*e)].y << ' '
   887 		 << _coords[g.source(*e)].y << ' '
   885 		 << mm.x << ' ' << mm.y << ' '
   888 		 << mm.x << ' ' << mm.y << ' '
   886 		 << _coords[g.target(*e)].x << ' '
   889 		 << _coords[g.target(*e)].x << ' '
   887 		 << _coords[g.target(*e)].y << ' '
   890 		 << _coords[g.target(*e)].y << ' '
   888 		 << _edgeColors[*e].getR() << ' '
   891 		 << _edgeColors[*e].red() << ' '
   889 		 << _edgeColors[*e].getG() << ' '
   892 		 << _edgeColors[*e].green() << ' '
   890 		 << _edgeColors[*e].getB() << ' '
   893 		 << _edgeColors[*e].blue() << ' '
   891 		 << _edgeWidths[*e]*_edgeWidthScale << " lb\n";
   894 		 << _edgeWidths[*e]*_edgeWidthScale << " lb\n";
   892 	    }
   895 	    }
   893 	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist;
   896 	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0+_parEdgeDist;
   894 	  }
   897 	  }
   895 	}
   898 	}
   910 	    os << l*(1-(t1+t2)/2) << ' '
   913 	    os << l*(1-(t1+t2)/2) << ' '
   911 	       << _edgeWidths[e]*_edgeWidthScale << ' '
   914 	       << _edgeWidths[e]*_edgeWidthScale << ' '
   912 	       << d.x << ' ' << d.y << ' '
   915 	       << d.x << ' ' << d.y << ' '
   913 	       << _coords[g.source(e)].x << ' '
   916 	       << _coords[g.source(e)].x << ' '
   914 	       << _coords[g.source(e)].y << ' '
   917 	       << _coords[g.source(e)].y << ' '
   915 	       << _edgeColors[e].getR() << ' '
   918 	       << _edgeColors[e].red() << ' '
   916 	       << _edgeColors[e].getG() << ' '
   919 	       << _edgeColors[e].green() << ' '
   917 	       << _edgeColors[e].getB() << " arr\n";
   920 	       << _edgeColors[e].blue() << " arr\n";
   918 	  }
   921 	  }
   919 	  else os << _coords[g.source(e)].x << ' '
   922 	  else os << _coords[g.source(e)].x << ' '
   920 		  << _coords[g.source(e)].y << ' '
   923 		  << _coords[g.source(e)].y << ' '
   921 		  << _coords[g.target(e)].x << ' '
   924 		  << _coords[g.target(e)].x << ' '
   922 		  << _coords[g.target(e)].y << ' '
   925 		  << _coords[g.target(e)].y << ' '
   923 		  << _edgeColors[e].getR() << ' '
   926 		  << _edgeColors[e].red() << ' '
   924 		  << _edgeColors[e].getG() << ' '
   927 		  << _edgeColors[e].green() << ' '
   925 		  << _edgeColors[e].getB() << ' '
   928 		  << _edgeColors[e].blue() << ' '
   926 		  << _edgeWidths[e]*_edgeWidthScale << " l\n";
   929 		  << _edgeWidths[e]*_edgeWidthScale << " l\n";
   927       os << "grestore\n";
   930       os << "grestore\n";
   928     }
   931     }
   929     if(_showNodes) {
   932     if(_showNodes) {
   930       os << "%Nodes:\ngsave\n";
   933       os << "%Nodes:\ngsave\n";
   931       for(NodeIt n(g);n!=INVALID;++n) {
   934       for(NodeIt n(g);n!=INVALID;++n) {
   932 	os << _coords[n].x << ' ' << _coords[n].y << ' '
   935 	os << _coords[n].x << ' ' << _coords[n].y << ' '
   933 	   << _nodeSizes[n]*_nodeScale << ' '
   936 	   << _nodeSizes[n]*_nodeScale << ' '
   934 	   << _nodeColors[n].getR() << ' '
   937 	   << _nodeColors[n].red() << ' '
   935 	   << _nodeColors[n].getG() << ' '
   938 	   << _nodeColors[n].green() << ' '
   936 	   << _nodeColors[n].getB() << ' ';
   939 	   << _nodeColors[n].blue() << ' ';
   937 	switch(_nodeShapes[n]) {
   940 	switch(_nodeShapes[n]) {
   938 	case CIRCLE:
   941 	case CIRCLE:
   939 	  os<< "nc";break;
   942 	  os<< "nc";break;
   940 	case SQUARE:
   943 	case SQUARE:
   941 	  os<< "nsq";break;
   944 	  os<< "nsq";break;