COIN-OR::LEMON - Graph Library

Changeset 1085:5b7ca75297b5 in lemon-0.x


Ignore:
Timestamp:
01/16/05 23:34:51 (15 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1481
Message:
  • Parallel edges look a bit better
  • Possibility to insert verbatim PS blocks for each node
File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/graph_to_eps.h

    r1073 r1085  
    106106  double _nodeTextSize;
    107107
     108  bool _showNodePsText;
     109  ConstMap<typename Graph::Node,bool > _nodePsTexts; 
     110  char *_nodePsTextsPreamble;
     111 
    108112  bool _undir;
    109113  bool _pleaseRemoveOsStream;
     
    129133    _enableParallel(false), _parEdgeDist(1),
    130134    _showNodeText(false), _nodeTexts(false), _nodeTextSize(1),
     135    _showNodePsText(false), _nodePsTexts(false), _nodePsTextsPreamble(0),
    131136    _undir(false),
    132137    _pleaseRemoveOsStream(_pros) {}
     
    225230    return GraphToEps<NodeTextsTraits<X> >(NodeTextsTraits<X>(*this,x));
    226231  }
    227    template<class X> struct EdgeWidthsTraits : public T {
     232  template<class X> struct NodePsTextsTraits : public T {
     233    const X &_nodePsTexts;
     234    NodePsTextsTraits(const T &t,const X &x) : T(t), _nodePsTexts(x) {}
     235  };
     236  ///Inserts a PostScript block to the nodes
     237
     238  ///With this command it is possible to insert a verbatim PostScript
     239  ///block to the nodes.
     240  ///The PS current point will be moved to the centre of the node before
     241  ///the PostScript block inserted.
     242  ///
     243  ///Before and after the block a newline character is inserted to you
     244  ///don't have to bother with the separators.
     245  ///
     246  ///\param x must be a node map with type that can be pushed to a standard
     247  ///ostream.
     248  ///
     249  ///\sa nodePsTextsPreamble()
     250  ///\todo Offer the choise not to move to the centre but pass the coordinates
     251  ///to the Postscript block inserted.
     252  template<class X> GraphToEps<NodePsTextsTraits<X> > nodePsTexts(const X &x)
     253  {
     254    dontPrint=true;
     255    _showNodePsText=true;
     256    return GraphToEps<NodePsTextsTraits<X> >(NodePsTextsTraits<X>(*this,x));
     257  }
     258  template<class X> struct EdgeWidthsTraits : public T {
    228259    const X &_edgeWidths;
    229260    EdgeWidthsTraits(const T &t,const X &x) : T(t), _edgeWidths(x) {}
     
    338369  ///
    339370  GraphToEps<T> &nodeTextSize(double d) {_nodeTextSize=d;return *this;}
     371  ///Gives a preamble block for node Postscript block.
     372 
     373  ///Gives a preamble block for node Postscript block.
     374  ///
     375  ///\sa nodePsTexts()
     376  GraphToEps<T> & nodePsTextsPreamble(const char *str) {
     377    _nodePsTextsPreamble=s ;return *this;
     378  }
    340379  ///Sets whether the the graph is undirected
    341380
     
    402441    if(_scale!=1.0) os << _scale << " dup scale\n";
    403442   
    404     os << "%Edges:\ngsave\n";
    405    
    406     if(_showEdges)
     443    if(_showEdges) {
     444      os << "%Edges:\ngsave\n";     
    407445      if(_enableParallel) {
    408446        std::vector<Edge> el;
     
    420458          sw-=_parEdgeDist;
    421459          sw/=-2.0;
    422           xy<double> d(_coords[g.target(*i)]-_coords[g.source(*i)]);
    423           double l=sqrt(d.normSquare());
    424           d/=l;
    425          
     460          xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]);
     461          double l=sqrt(dvec.normSquare());
     462          xy<double> d(dvec/l);
     463          xy<double> m;
     464//        m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0;
     465
     466//        m=xy<double>(_coords[g.source(*i)])+
     467//          dvec*(double(_nodeSizes[g.source(*i)])/
     468//             (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
     469
     470          m=xy<double>(_coords[g.source(*i)])+
     471            d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
     472
    426473          for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
    427474            sw+=_edgeWidths[*e]*_edgeWidthScale/2.0;
    428             xy<double> m(_coords[g.target(*e)]+_coords[g.source(*e)]);
    429             m=m/2.0+rot(d)*sw/.75;
     475            xy<double> mm=m+rot(d)*sw/.75;
    430476            if(_drawArrows) {
    431477              const int INERPOL_PREC=20;
     
    434480              double rn=_nodeSizes[g.target(*e)]*_nodeScale;
    435481              rn*=rn;
    436               Bezier3 bez(s,m,m,t);
     482              Bezier3 bez(s,mm,mm,t);
    437483              double t1=0,t2=1;
    438484              for(int i=0;i<INERPOL_PREC;++i)
     
    473519              os << _coords[g.source(*e)].x << ' '
    474520                 << _coords[g.source(*e)].y << ' '
    475                  << m.x << ' ' << m.y << ' '
     521                 << mm.x << ' ' << mm.y << ' '
    476522                 << _coords[g.target(*e)].x << ' '
    477523                 << _coords[g.target(*e)].y << ' '
     
    510556                  << _edgeColors[e].getB() << ' '
    511557                  << _edgeWidths[e]*_edgeWidthScale << " l\n";
    512     os << "grestore\n%Nodes:\ngsave\n";
    513     if(_showNodes)
     558      os << "grestore\n";
     559    }
     560    if(_showNodes) {
     561      os << "%Nodes:\ngsave\n";
    514562      for(NodeIt n(g);n!=INVALID;++n)
    515563        os << _coords[n].x << ' ' << _coords[n].y << ' '
     
    517565           << _nodeColors[n].getR() << ' '
    518566           << _nodeColors[n].getG() << ' '
    519            << _nodeColors[n].getB() << " n\n";
     567           << _nodeColors[n].getB() << " n\n";
     568      os << "grestore\n";
     569    }
    520570    if(_showNodeText) {
    521       os << "grestore\n%Node texts:\ngsave\n";
     571      os << "%Node texts:\ngsave\n";
    522572      os << "/fosi " << _nodeTextSize << " def\n";
    523573      os << "(Helvetica) findfont fosi scalefont setfont\n";
     
    526576        os << _coords[n].x << ' ' << _coords[n].y
    527577           << " (" << _nodeTexts[n] << ") cshow\n";
     578      os << "grestore\n";
    528579    }
    529     os << "grestore\ngrestore\n";
     580    if(_showNodePsText) {
     581      os << "%Node PS blocks:\ngsave\n";
     582      for(NodeIt n(g);n!=INVALID;++n)
     583        os << _coords[n].x << ' ' << _coords[n].y
     584           << " moveto\n" << _nodePsTexts[n] << "\n";
     585      os << "grestore\n";
     586    }
     587   
     588    os << "grestore\n";
    530589
    531590    //CleanUp:
     
    577636}
    578637
    579 //Generates an EPS file from a graph.
    580 //\param g is a reference to the graph to be printed
    581 //\param file_name is the output file_name.
    582 //
    583 //This function also has a lot of \ref named-templ-param "named parameters",
    584 //they are declared as the members of class \ref GraphToEps. The following
    585 //example shows how to use these parameters.
    586 //\code
    587 // graphToEps(g).scale(10).coords(coords)
    588 //              .nodeScale(2).nodeSizes(sizes)
    589 //              .edgeWidthScale(.4);
    590 //\endcode
    591 //\sa GraphToEps
    592 //\todo Avoid duplicated documentation
    593 //\bug Exception handling is missing? (Or we can just ignore it?)
    594 
    595638} //END OF NAMESPACE LEMON
    596639
Note: See TracChangeset for help on using the changeset viewer.