lemon/graph_to_eps.h
changeset 1673 8919ca9e70f3
parent 1642 a2dda876316f
child 1676 c3e416514759
     1.1 --- a/lemon/graph_to_eps.h	Thu Sep 01 12:14:14 2005 +0000
     1.2 +++ b/lemon/graph_to_eps.h	Thu Sep 01 19:21:35 2005 +0000
     1.3 @@ -169,6 +169,17 @@
     1.4    return Color(v,v,v);
     1.5  }
     1.6  
     1.7 +template<class MT>
     1.8 +class _NegY {
     1.9 +public:
    1.10 +  typedef typename MT::Key Key;
    1.11 +  typedef typename MT::Value Value;
    1.12 +  const MT &map;
    1.13 +  int yscale;
    1.14 +  _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
    1.15 +  Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
    1.16 +};
    1.17 +
    1.18  ///Default traits class of \ref GraphToEps
    1.19  
    1.20  ///Default traits class of \ref GraphToEps
    1.21 @@ -190,7 +201,8 @@
    1.22  
    1.23    std::ostream& os;
    1.24    
    1.25 -  ConstMap<typename Graph::Node,xy<double> > _coords;
    1.26 +  typedef ConstMap<typename Graph::Node,xy<double> > CoordsMapType;
    1.27 +  CoordsMapType _coords;
    1.28    ConstMap<typename Graph::Node,double > _nodeSizes;
    1.29    ConstMap<typename Graph::Node,int > _nodeShapes;
    1.30  
    1.31 @@ -237,6 +249,7 @@
    1.32    bool _autoNodeScale;
    1.33    bool _autoEdgeWidthScale;
    1.34  
    1.35 +  bool _negY;
    1.36    ///Constructor
    1.37  
    1.38    ///Constructor
    1.39 @@ -263,7 +276,8 @@
    1.40      _pleaseRemoveOsStream(_pros), _scaleToA4(false),
    1.41      _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
    1.42      _autoNodeScale(false),
    1.43 -    _autoEdgeWidthScale(false)
    1.44 +    _autoEdgeWidthScale(false),
    1.45 +    _negY(false)
    1.46    {}
    1.47  };
    1.48  
    1.49 @@ -413,6 +427,7 @@
    1.50    GraphToEps(const T &t) : T(t), dontPrint(false) {};
    1.51    
    1.52    template<class X> struct CoordsTraits : public T {
    1.53 +  typedef X CoordsMapType;
    1.54      const X &_coords;
    1.55      CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
    1.56    };
    1.57 @@ -579,6 +594,17 @@
    1.58    GraphToEps<T> &autoNodeScale(bool b=true) {
    1.59      _autoNodeScale=b;return *this;
    1.60    }
    1.61 +
    1.62 +  ///Negates the Y coordinates.
    1.63 +
    1.64 +  ///Negates the Y coordinates.
    1.65 +  ///
    1.66 +  ///\todo More docs.
    1.67 +  ///
    1.68 +  GraphToEps<T> &negateY(bool b=true) {
    1.69 +    _negY=b;return *this;
    1.70 +  }
    1.71 +
    1.72    ///Sets a global scale factor for edge widths
    1.73  
    1.74    /// Sets a global scale factor for edge widths.
    1.75 @@ -743,6 +769,8 @@
    1.76    void run() {
    1.77      if(dontPrint) return;
    1.78      
    1.79 +    _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
    1.80 +
    1.81      os << "%!PS-Adobe-2.0 EPSF-2.0\n";
    1.82      if(_title.size()>0) os << "%%Title: " << _title << '\n';
    1.83       if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
    1.84 @@ -783,8 +811,8 @@
    1.85      for(NodeIt n(g);n!=INVALID;++n) {
    1.86        double ns=_nodeSizes[n]*_nodeScale;
    1.87        xy<double> p(ns,ns);
    1.88 -      bb.add(p+_coords[n]);
    1.89 -      bb.add(-p+_coords[n]);
    1.90 +      bb.add(p+mycoords[n]);
    1.91 +      bb.add(-p+mycoords[n]);
    1.92      }
    1.93      if (bb.empty()) {
    1.94        bb = BoundingBox<double>(xy<double>(0,0));
    1.95 @@ -888,18 +916,18 @@
    1.96  	    sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist;
    1.97  	  sw-=_parEdgeDist;
    1.98  	  sw/=-2.0;
    1.99 -	  xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]);
   1.100 +	  xy<double> dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
   1.101  	  double l=std::sqrt(dvec.normSquare()); 
   1.102  	  ///\todo better 'epsilon' would be nice here.
   1.103  	  xy<double> d(dvec/std::max(l,1e-9));
   1.104   	  xy<double> m;
   1.105 -// 	  m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0;
   1.106 +// 	  m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
   1.107  
   1.108 -//  	  m=xy<double>(_coords[g.source(*i)])+
   1.109 +//  	  m=xy<double>(mycoords[g.source(*i)])+
   1.110  // 	    dvec*(double(_nodeSizes[g.source(*i)])/
   1.111  // 	       (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
   1.112  
   1.113 - 	  m=xy<double>(_coords[g.source(*i)])+
   1.114 + 	  m=xy<double>(mycoords[g.source(*i)])+
   1.115  	    d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
   1.116  
   1.117  	  for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
   1.118 @@ -907,8 +935,8 @@
   1.119  	    xy<double> mm=m+rot90(d)*sw/.75;
   1.120  	    if(_drawArrows) {
   1.121  	      int node_shape;
   1.122 -	      xy<double> s=_coords[g.source(*e)];
   1.123 -	      xy<double> t=_coords[g.target(*e)];
   1.124 +	      xy<double> s=mycoords[g.source(*e)];
   1.125 +	      xy<double> t=mycoords[g.target(*e)];
   1.126  	      double rn=_nodeSizes[g.target(*e)]*_nodeScale;
   1.127  	      node_shape=_nodeShapes[g.target(*e)];
   1.128  	      Bezier3 bez(s,mm,mm,t);
   1.129 @@ -948,11 +976,11 @@
   1.130  		 << psOut(linend-dd) << " lineto closepath fill\n";
   1.131  	    }
   1.132  	    else {
   1.133 -	      os << _coords[g.source(*e)].x << ' '
   1.134 -		 << _coords[g.source(*e)].y << ' '
   1.135 +	      os << mycoords[g.source(*e)].x << ' '
   1.136 +		 << mycoords[g.source(*e)].y << ' '
   1.137  		 << mm.x << ' ' << mm.y << ' '
   1.138 -		 << _coords[g.target(*e)].x << ' '
   1.139 -		 << _coords[g.target(*e)].y << ' '
   1.140 +		 << mycoords[g.target(*e)].x << ' '
   1.141 +		 << mycoords[g.target(*e)].y << ' '
   1.142  		 << _edgeColors[*e].red() << ' '
   1.143  		 << _edgeColors[*e].green() << ' '
   1.144  		 << _edgeColors[*e].blue() << ' '
   1.145 @@ -965,7 +993,7 @@
   1.146        else for(EdgeIt e(g);e!=INVALID;++e)
   1.147  	if((!_undir||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
   1.148  	  if(_drawArrows) {
   1.149 -	    xy<double> d(_coords[g.target(e)]-_coords[g.source(e)]);
   1.150 +	    xy<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
   1.151  	    double rn=_nodeSizes[g.target(e)]*_nodeScale;
   1.152  	    int node_shape=_nodeShapes[g.target(e)];
   1.153  	    double t1=0,t2=1;
   1.154 @@ -978,16 +1006,16 @@
   1.155  	    os << l*(1-(t1+t2)/2) << ' '
   1.156  	       << _edgeWidths[e]*_edgeWidthScale << ' '
   1.157  	       << d.x << ' ' << d.y << ' '
   1.158 -	       << _coords[g.source(e)].x << ' '
   1.159 -	       << _coords[g.source(e)].y << ' '
   1.160 +	       << mycoords[g.source(e)].x << ' '
   1.161 +	       << mycoords[g.source(e)].y << ' '
   1.162  	       << _edgeColors[e].red() << ' '
   1.163  	       << _edgeColors[e].green() << ' '
   1.164  	       << _edgeColors[e].blue() << " arr\n";
   1.165  	  }
   1.166 -	  else os << _coords[g.source(e)].x << ' '
   1.167 -		  << _coords[g.source(e)].y << ' '
   1.168 -		  << _coords[g.target(e)].x << ' '
   1.169 -		  << _coords[g.target(e)].y << ' '
   1.170 +	  else os << mycoords[g.source(e)].x << ' '
   1.171 +		  << mycoords[g.source(e)].y << ' '
   1.172 +		  << mycoords[g.target(e)].x << ' '
   1.173 +		  << mycoords[g.target(e)].y << ' '
   1.174  		  << _edgeColors[e].red() << ' '
   1.175  		  << _edgeColors[e].green() << ' '
   1.176  		  << _edgeColors[e].blue() << ' '
   1.177 @@ -997,7 +1025,7 @@
   1.178      if(_showNodes) {
   1.179        os << "%Nodes:\ngsave\n";
   1.180        for(NodeIt n(g);n!=INVALID;++n) {
   1.181 -	os << _coords[n].x << ' ' << _coords[n].y << ' '
   1.182 +	os << mycoords[n].x << ' ' << mycoords[n].y << ' '
   1.183  	   << _nodeSizes[n]*_nodeScale << ' '
   1.184  	   << _nodeColors[n].red() << ' '
   1.185  	   << _nodeColors[n].green() << ' '
   1.186 @@ -1032,7 +1060,7 @@
   1.187  	default:
   1.188  	  os << "0 0 0 setrgbcolor\n";
   1.189  	}
   1.190 -	os << _coords[n].x << ' ' << _coords[n].y
   1.191 +	os << mycoords[n].x << ' ' << mycoords[n].y
   1.192  	   << " (" << _nodeTexts[n] << ") cshow\n";
   1.193        }
   1.194        os << "grestore\n";
   1.195 @@ -1040,7 +1068,7 @@
   1.196      if(_showNodePsText) {
   1.197        os << "%Node PS blocks:\ngsave\n";
   1.198        for(NodeIt n(g);n!=INVALID;++n)
   1.199 -	os << _coords[n].x << ' ' << _coords[n].y
   1.200 +	os << mycoords[n].x << ' ' << mycoords[n].y
   1.201  	   << " moveto\n" << _nodePsTexts[n] << "\n";
   1.202        os << "grestore\n";
   1.203      }