src/lemon/graph_to_eps.h
changeset 1224 7f4f2855fa11
parent 1180 f772c360b466
child 1234 49d018060749
equal deleted inserted replaced
12:f5ccc6e9c69b 13:65f445798a01
   155 ///Returns black for light colors and white for the dark ones.
   155 ///Returns black for light colors and white for the dark ones.
   156 
   156 
   157 ///Returns black for light colors and white for the dark ones.
   157 ///Returns black for light colors and white for the dark ones.
   158 ///\todo weighted average would be better
   158 ///\todo weighted average would be better
   159 inline Color distantBW(const Color &c){
   159 inline Color distantBW(const Color &c){
   160   //  double v=(c.getR()+c.getG()+c.getB())<1.5?1:0;
       
   161   double v=(.2125*c.getR()+.7154*c.getG()+.0721*c.getB())<.5?1:0;
   160   double v=(.2125*c.getR()+.7154*c.getG()+.0721*c.getB())<.5?1:0;
   162   return Color(v,v,v);
   161   return Color(v,v,v);
   163 }
   162 }
   164 
   163 
   165 ///Default traits class of \ref GraphToEps
   164 ///Default traits class of \ref GraphToEps
   324   };
   323   };
   325   bool isParallel(Edge e,Edge f) const
   324   bool isParallel(Edge e,Edge f) const
   326   {
   325   {
   327     return (g.source(e)==g.source(f)&&g.target(e)==g.target(f))||
   326     return (g.source(e)==g.source(f)&&g.target(e)==g.target(f))||
   328       (g.source(e)==g.target(f)&&g.target(e)==g.source(f));
   327       (g.source(e)==g.target(f)&&g.target(e)==g.source(f));
   329   }
       
   330   static xy<double> rot(xy<double> v) 
       
   331   {
       
   332     return xy<double>(v.y,-v.x);
       
   333   }
   328   }
   334   template<class TT>
   329   template<class TT>
   335   static std::string psOut(const xy<TT> &p) 
   330   static std::string psOut(const xy<TT> &p) 
   336     {
   331     {
   337       std::ostringstream os;	
   332       std::ostringstream os;	
   773  	  m=xy<double>(_coords[g.source(*i)])+
   768  	  m=xy<double>(_coords[g.source(*i)])+
   774 	    d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
   769 	    d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
   775 
   770 
   776 	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
   771 	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
   777 	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
   772 	    sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
   778 	    xy<double> mm=m+rot(d)*sw/.75;
   773 	    xy<double> mm=m+rot90(d)*sw/.75;
   779 	    if(_drawArrows) {
   774 	    if(_drawArrows) {
   780 	      int node_shape;
   775 	      int node_shape;
   781 	      xy<double> s=_coords[g.source(*e)];
   776 	      xy<double> s=_coords[g.source(*e)];
   782 	      xy<double> t=_coords[g.target(*e)];
   777 	      xy<double> t=_coords[g.target(*e)];
   783 	      double rn=_nodeSizes[g.target(*e)]*_nodeScale;
   778 	      double rn=_nodeSizes[g.target(*e)]*_nodeScale;
   809 		 << _edgeColors[*e].getB() << " setrgbcolor newpath\n"
   804 		 << _edgeColors[*e].getB() << " setrgbcolor newpath\n"
   810 		 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
   805 		 << bez.p1.x << ' ' <<  bez.p1.y << " moveto\n"
   811 		 << bez.p2.x << ' ' << bez.p2.y << ' '
   806 		 << bez.p2.x << ' ' << bez.p2.y << ' '
   812 		 << bez.p3.x << ' ' << bez.p3.y << ' '
   807 		 << bez.p3.x << ' ' << bez.p3.y << ' '
   813 		 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
   808 		 << bez.p4.x << ' ' << bez.p4.y << " curveto stroke\n";
   814 	      xy<double> dd(rot(linend-apoint));
   809 	      xy<double> dd(rot90(linend-apoint));
   815 	      dd*=(.5*_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/
   810 	      dd*=(.5*_edgeWidths[*e]*_edgeWidthScale+_arrowWidth)/
   816 		sqrt(dd.normSquare());
   811 		sqrt(dd.normSquare());
   817 	      os << "newpath " << psOut(apoint) << " moveto "
   812 	      os << "newpath " << psOut(apoint) << " moveto "
   818 		 << psOut(linend+dd) << " lineto "
   813 		 << psOut(linend+dd) << " lineto "
   819 		 << psOut(linend-dd) << " lineto closepath fill\n";
   814 		 << psOut(linend-dd) << " lineto closepath fill\n";