COIN-OR::LEMON - Graph Library

Changeset 2178:0d7c0f96a5ee in lemon-0.x for lemon/graph_to_eps.h


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.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.