COIN-OR::LEMON - Graph Library

Changeset 1673:8919ca9e70f3 in lemon-0.x for lemon/graph_to_eps.h


Ignore:
Timestamp:
09/01/05 21:21:35 (19 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2189
Message:

negateY() option added.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/graph_to_eps.h

    r1642 r1673  
    170170}
    171171
     172template<class MT>
     173class _NegY {
     174public:
     175  typedef typename MT::Key Key;
     176  typedef typename MT::Value Value;
     177  const MT &map;
     178  int yscale;
     179  _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
     180  Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
     181};
     182
    172183///Default traits class of \ref GraphToEps
    173184
     
    191202  std::ostream& os;
    192203 
    193   ConstMap<typename Graph::Node,xy<double> > _coords;
     204  typedef ConstMap<typename Graph::Node,xy<double> > CoordsMapType;
     205  CoordsMapType _coords;
    194206  ConstMap<typename Graph::Node,double > _nodeSizes;
    195207  ConstMap<typename Graph::Node,int > _nodeShapes;
     
    238250  bool _autoEdgeWidthScale;
    239251
     252  bool _negY;
    240253  ///Constructor
    241254
     
    264277    _nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
    265278    _autoNodeScale(false),
    266     _autoEdgeWidthScale(false)
     279    _autoEdgeWidthScale(false),
     280    _negY(false)
    267281  {}
    268282};
     
    414428 
    415429  template<class X> struct CoordsTraits : public T {
     430  typedef X CoordsMapType;
    416431    const X &_coords;
    417432    CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
     
    580595    _autoNodeScale=b;return *this;
    581596  }
     597
     598  ///Negates the Y coordinates.
     599
     600  ///Negates the Y coordinates.
     601  ///
     602  ///\todo More docs.
     603  ///
     604  GraphToEps<T> &negateY(bool b=true) {
     605    _negY=b;return *this;
     606  }
     607
    582608  ///Sets a global scale factor for edge widths
    583609
     
    744770    if(dontPrint) return;
    745771   
     772    _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
     773
    746774    os << "%!PS-Adobe-2.0 EPSF-2.0\n";
    747775    if(_title.size()>0) os << "%%Title: " << _title << '\n';
     
    784812      double ns=_nodeSizes[n]*_nodeScale;
    785813      xy<double> p(ns,ns);
    786       bb.add(p+_coords[n]);
    787       bb.add(-p+_coords[n]);
     814      bb.add(p+mycoords[n]);
     815      bb.add(-p+mycoords[n]);
    788816    }
    789817    if (bb.empty()) {
     
    889917          sw-=_parEdgeDist;
    890918          sw/=-2.0;
    891           xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]);
     919          xy<double> dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
    892920          double l=std::sqrt(dvec.normSquare());
    893921          ///\todo better 'epsilon' would be nice here.
    894922          xy<double> d(dvec/std::max(l,1e-9));
    895923          xy<double> m;
    896 //        m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0;
    897 
    898 //        m=xy<double>(_coords[g.source(*i)])+
     924//        m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
     925
     926//        m=xy<double>(mycoords[g.source(*i)])+
    899927//          dvec*(double(_nodeSizes[g.source(*i)])/
    900928//             (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
    901929
    902           m=xy<double>(_coords[g.source(*i)])+
     930          m=xy<double>(mycoords[g.source(*i)])+
    903931            d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
    904932
     
    908936            if(_drawArrows) {
    909937              int node_shape;
    910               xy<double> s=_coords[g.source(*e)];
    911               xy<double> t=_coords[g.target(*e)];
     938              xy<double> s=mycoords[g.source(*e)];
     939              xy<double> t=mycoords[g.target(*e)];
    912940              double rn=_nodeSizes[g.target(*e)]*_nodeScale;
    913941              node_shape=_nodeShapes[g.target(*e)];
     
    949977            }
    950978            else {
    951               os << _coords[g.source(*e)].x << ' '
    952                  << _coords[g.source(*e)].y << ' '
     979              os << mycoords[g.source(*e)].x << ' '
     980                 << mycoords[g.source(*e)].y << ' '
    953981                 << mm.x << ' ' << mm.y << ' '
    954                  << _coords[g.target(*e)].x << ' '
    955                  << _coords[g.target(*e)].y << ' '
     982                 << mycoords[g.target(*e)].x << ' '
     983                 << mycoords[g.target(*e)].y << ' '
    956984                 << _edgeColors[*e].red() << ' '
    957985                 << _edgeColors[*e].green() << ' '
     
    966994        if((!_undir||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
    967995          if(_drawArrows) {
    968             xy<double> d(_coords[g.target(e)]-_coords[g.source(e)]);
     996            xy<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
    969997            double rn=_nodeSizes[g.target(e)]*_nodeScale;
    970998            int node_shape=_nodeShapes[g.target(e)];
     
    9791007               << _edgeWidths[e]*_edgeWidthScale << ' '
    9801008               << d.x << ' ' << d.y << ' '
    981                << _coords[g.source(e)].x << ' '
    982                << _coords[g.source(e)].y << ' '
     1009               << mycoords[g.source(e)].x << ' '
     1010               << mycoords[g.source(e)].y << ' '
    9831011               << _edgeColors[e].red() << ' '
    9841012               << _edgeColors[e].green() << ' '
    9851013               << _edgeColors[e].blue() << " arr\n";
    9861014          }
    987           else os << _coords[g.source(e)].x << ' '
    988                   << _coords[g.source(e)].y << ' '
    989                   << _coords[g.target(e)].x << ' '
    990                   << _coords[g.target(e)].y << ' '
     1015          else os << mycoords[g.source(e)].x << ' '
     1016                  << mycoords[g.source(e)].y << ' '
     1017                  << mycoords[g.target(e)].x << ' '
     1018                  << mycoords[g.target(e)].y << ' '
    9911019                  << _edgeColors[e].red() << ' '
    9921020                  << _edgeColors[e].green() << ' '
     
    9981026      os << "%Nodes:\ngsave\n";
    9991027      for(NodeIt n(g);n!=INVALID;++n) {
    1000         os << _coords[n].x << ' ' << _coords[n].y << ' '
     1028        os << mycoords[n].x << ' ' << mycoords[n].y << ' '
    10011029           << _nodeSizes[n]*_nodeScale << ' '
    10021030           << _nodeColors[n].red() << ' '
     
    10331061          os << "0 0 0 setrgbcolor\n";
    10341062        }
    1035         os << _coords[n].x << ' ' << _coords[n].y
     1063        os << mycoords[n].x << ' ' << mycoords[n].y
    10361064           << " (" << _nodeTexts[n] << ") cshow\n";
    10371065      }
     
    10411069      os << "%Node PS blocks:\ngsave\n";
    10421070      for(NodeIt n(g);n!=INVALID;++n)
    1043         os << _coords[n].x << ' ' << _coords[n].y
     1071        os << mycoords[n].x << ' ' << mycoords[n].y
    10441072           << " moveto\n" << _nodePsTexts[n] << "\n";
    10451073      os << "grestore\n";
Note: See TracChangeset for help on using the changeset viewer.