COIN-OR::LEMON - Graph Library

Changeset 2178:0d7c0f96a5ee in lemon-0.x


Ignore:
Timestamp:
08/14/06 17:15:57 (13 years ago)
Author:
Alpar Juttner
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2894
Message:
  • bezier.h went to lemon/bits/
  • new graphToEps() option: absolute/relative node size/link width scaling.
Files:
1 added
1 deleted
2 edited

Legend:

Unmodified
Added
Removed
  • demo/graph_to_eps_demo.cc

    r2172 r2178  
    4343{
    4444  Palette palette;
     45  Palette paletteW(true);
    4546
    4647  ListGraph g;
     
    8182  IdMap<ListGraph,Node> id(g);
    8283
     84  cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
     85  graphToEps(g,"graph_to_eps_demo_out_pure.eps").
     86    //scale(10).
     87    coords(coords).
     88    title("Sample .eps figure").
     89    copyright("(C) 2006 LEMON Project").
     90    run();
     91
    8392  cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
    8493  graphToEps(g,"graph_to_eps_demo_out.eps").
     
    8796    title("Sample .eps figure").
    8897    copyright("(C) 2006 LEMON Project").
     98    absoluteNodeSizes().absoluteEdgeWidths().
    8999    nodeScale(2).nodeSizes(sizes).
    90100    nodeShapes(shapes).
     
    101111    title("Sample .eps figure (with arrowheads)").
    102112    copyright("(C) 2006 LEMON Project").
     113    absoluteNodeSizes().absoluteEdgeWidths().
    103114    nodeColors(composeMap(palette,colors)).
    104115    coords(coords).
     
    127138    title("Sample .eps figure (parallel edges)").
    128139    copyright("(C) 2006 LEMON Project").
     140    absoluteNodeSizes().absoluteEdgeWidths().
    129141    nodeShapes(shapes).
    130142    coords(coords).
     
    142154    title("Sample .eps figure (parallel edges and arrowheads)").
    143155    copyright("(C) 2006 LEMON Project").
     156    absoluteNodeSizes().absoluteEdgeWidths().
    144157    nodeScale(2).nodeSizes(sizes).
    145158    coords(coords).
     
    157170    title("Sample .eps figure (fits to A4)").
    158171    copyright("(C) 2006 LEMON Project").
     172    absoluteNodeSizes().absoluteEdgeWidths().
    159173    nodeScale(2).nodeSizes(sizes).
    160174    coords(coords).
     
    173187 
    174188  int cols=int(sqrt(double(palette.size())));
    175   for(int i=0;i<int(palette.size());i++) {
     189  for(int i=0;i<int(paletteW.size());i++) {
    176190    Node n=h.addNode();
    177191    hcoords[n]=Xy(i%cols,i/cols);
     
    185199    copyright("(C) 2006 LEMON Project").
    186200    coords(hcoords).
    187     nodeScale(.45).
     201    absoluteNodeSizes().absoluteEdgeWidths().
     202    nodeScale(45).
    188203    distantColorNodeTexts().
    189204    //    distantBWNodeTexts().
    190205    nodeTexts(hcolors).nodeTextSize(.6).
    191     nodeColors(composeMap(palette,hcolors)).
    192     run();
    193 
    194 
     206    nodeColors(composeMap(paletteW,hcolors)).
     207    run();
    195208}
  • lemon/graph_to_eps.h

    r2174 r2178  
    3939#include<lemon/maps.h>
    4040#include<lemon/color.h>
    41 #include<lemon/bezier.h>
     41#include<lemon/bits/bezier.h>
    4242
    4343
     
    131131  bool _autoEdgeWidthScale;
    132132
     133  bool _absoluteNodeSizes;
     134  bool _absoluteEdgeWidths;
     135
    133136  bool _negY;
    134137  ///Constructor
     
    144147                          bool _pros=false) :
    145148    g(_g), os(_os),
    146     _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
     149    _coords(xy<double>(1,1)), _nodeSizes(.01), _nodeShapes(0),
    147150    _nodeColors(WHITE), _edgeColors(BLACK),
    148     _edgeWidths(1), _edgeWidthScale(0.3),
     151    _edgeWidths(1.0), _edgeWidthScale(0.003),
    149152    _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
    150153    _nodeBorderQuotient(.1),
     
    159162    _autoNodeScale(false),
    160163    _autoEdgeWidthScale(false),
     164    _absoluteNodeSizes(false),
     165    _absoluteEdgeWidths(false),
    161166    _negY(false)
    162167  {}
     
    229234  using T::_autoNodeScale;
    230235  using T::_autoEdgeWidthScale;
     236
     237  using T::_absoluteNodeSizes;
     238  using T::_absoluteEdgeWidths;
     239
    231240
    232241  using T::_negY;
     
    479488  /// node sizes will be scaled in such a way that the greatest size will be
    480489  /// equal to \c d.
     490  /// \sa nodeSizes()
     491  /// \sa autoNodeScale()
    481492  GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
    482493  ///Turns on/off the automatic node width scaling.
     
    488499  GraphToEps<T> &autoNodeScale(bool b=true) {
    489500    _autoNodeScale=b;return *this;
     501  }
     502
     503  ///Turns on/off the absolutematic node width scaling.
     504
     505  ///Turns on/off the absolutematic node width scaling.
     506  ///
     507  ///\sa nodeScale()
     508  ///
     509  GraphToEps<T> &absoluteNodeSizes(bool b=true) {
     510    _absoluteNodeSizes=b;return *this;
    490511  }
    491512
     
    520541  GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
    521542    _autoEdgeWidthScale=b;return *this;
     543  }
     544  ///Turns on/off the absolutematic edge width scaling.
     545
     546  ///Turns on/off the absolutematic edge width scaling.
     547  ///
     548  ///\sa edgeWidthScale()
     549  ///
     550  GraphToEps<T> &absoluteEdgeWidths(bool b=true) {
     551    _absoluteEdgeWidths=b;return *this;
    522552  }
    523553  ///Sets a global scale factor for the whole picture
     
    665695  ///it draws the graph.
    666696  void run() {
     697    ///\todo better 'epsilon' would be nice here.
     698    const double EPSILON=1e-9;
    667699    if(dontPrint) return;
    668700   
     
    688720        max_w=std::max(double(_edgeWidths[e]),max_w);
    689721      ///\todo better 'epsilon' would be nice here.
    690       if(max_w>1e-9) {
     722      if(max_w>EPSILON) {
    691723        _edgeWidthScale/=max_w;
    692724      }
     
    698730        max_s=std::max(double(_nodeSizes[n]),max_s);
    699731      ///\todo better 'epsilon' would be nice here.
    700       if(max_s>1e-9) {
     732      if(max_s>EPSILON) {
    701733        _nodeScale/=max_s;
    702734      }
    703735    }
    704736
    705 
     737    double diag_len = 1;
     738    if(!(_absoluteNodeSizes&&_absoluteEdgeWidths)) {
     739      BoundingBox<double> bb;
     740      for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]);
     741      if (bb.empty()) {
     742        bb = BoundingBox<double>(xy<double>(0,0));
     743      }
     744      diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare());
     745      if(diag_len<EPSILON) diag_len = 1;
     746      if(!_absoluteNodeSizes) _nodeScale*=diag_len;
     747      if(!_absoluteEdgeWidths) _edgeWidthScale*=diag_len;
     748    }
     749   
    706750    BoundingBox<double> bb;
    707     ///\bug: Chech whether the graph is empty.
    708751    for(NodeIt n(g);n!=INVALID;++n) {
    709752      double ns=_nodeSizes[n]*_nodeScale;
     
    865908          double l=std::sqrt(dvec.normSquare());
    866909          ///\todo better 'epsilon' would be nice here.
    867           xy<double> d(dvec/std::max(l,1e-9));
     910          xy<double> d(dvec/std::max(l,EPSILON));
    868911          xy<double> m;
    869912//        m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
Note: See TracChangeset for help on using the changeset viewer.