lemon/graph_to_eps.h
changeset 2178 0d7c0f96a5ee
parent 2174 f9e43b5cc617
child 2207 75a29ac69c19
     1.1 --- a/lemon/graph_to_eps.h	Fri Aug 11 14:55:33 2006 +0000
     1.2 +++ b/lemon/graph_to_eps.h	Mon Aug 14 15:15:57 2006 +0000
     1.3 @@ -38,7 +38,7 @@
     1.4  #include<lemon/xy.h>
     1.5  #include<lemon/maps.h>
     1.6  #include<lemon/color.h>
     1.7 -#include<lemon/bezier.h>
     1.8 +#include<lemon/bits/bezier.h>
     1.9  
    1.10  
    1.11  ///\ingroup eps_io
    1.12 @@ -130,6 +130,9 @@
    1.13    bool _autoNodeScale;
    1.14    bool _autoEdgeWidthScale;
    1.15  
    1.16 +  bool _absoluteNodeSizes;
    1.17 +  bool _absoluteEdgeWidths;
    1.18 +
    1.19    bool _negY;
    1.20    ///Constructor
    1.21  
    1.22 @@ -143,9 +146,9 @@
    1.23    DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
    1.24  			  bool _pros=false) :
    1.25      g(_g), os(_os),
    1.26 -    _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
    1.27 +    _coords(xy<double>(1,1)), _nodeSizes(.01), _nodeShapes(0),
    1.28      _nodeColors(WHITE), _edgeColors(BLACK),
    1.29 -    _edgeWidths(1), _edgeWidthScale(0.3),
    1.30 +    _edgeWidths(1.0), _edgeWidthScale(0.003),
    1.31      _nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
    1.32      _nodeBorderQuotient(.1),
    1.33      _drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
    1.34 @@ -158,6 +161,8 @@
    1.35      _nodeTextColorType(SAME_COL), _nodeTextColors(BLACK),
    1.36      _autoNodeScale(false),
    1.37      _autoEdgeWidthScale(false),
    1.38 +    _absoluteNodeSizes(false),
    1.39 +    _absoluteEdgeWidths(false),
    1.40      _negY(false)
    1.41    {}
    1.42  };
    1.43 @@ -229,6 +234,10 @@
    1.44    using T::_autoNodeScale;
    1.45    using T::_autoEdgeWidthScale;
    1.46  
    1.47 +  using T::_absoluteNodeSizes;
    1.48 +  using T::_absoluteEdgeWidths;
    1.49 +
    1.50 +
    1.51    using T::_negY;
    1.52  
    1.53    // dradnats ++C eht yb deriuqer si ti eveileb t'naC
    1.54 @@ -478,6 +487,8 @@
    1.55    /// If both nodeSizes() and autoNodeScale() are used, then the
    1.56    /// node sizes will be scaled in such a way that the greatest size will be
    1.57    /// equal to \c d.
    1.58 +  /// \sa nodeSizes()
    1.59 +  /// \sa autoNodeScale()
    1.60    GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
    1.61    ///Turns on/off the automatic node width scaling.
    1.62  
    1.63 @@ -489,6 +500,16 @@
    1.64      _autoNodeScale=b;return *this;
    1.65    }
    1.66  
    1.67 +  ///Turns on/off the absolutematic node width scaling.
    1.68 +
    1.69 +  ///Turns on/off the absolutematic node width scaling.
    1.70 +  ///
    1.71 +  ///\sa nodeScale()
    1.72 +  ///
    1.73 +  GraphToEps<T> &absoluteNodeSizes(bool b=true) {
    1.74 +    _absoluteNodeSizes=b;return *this;
    1.75 +  }
    1.76 +
    1.77    ///Negates the Y coordinates.
    1.78  
    1.79    ///Negates the Y coordinates.
    1.80 @@ -520,6 +541,15 @@
    1.81    GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
    1.82      _autoEdgeWidthScale=b;return *this;
    1.83    }
    1.84 +  ///Turns on/off the absolutematic edge width scaling.
    1.85 +
    1.86 +  ///Turns on/off the absolutematic edge width scaling.
    1.87 +  ///
    1.88 +  ///\sa edgeWidthScale()
    1.89 +  ///
    1.90 +  GraphToEps<T> &absoluteEdgeWidths(bool b=true) {
    1.91 +    _absoluteEdgeWidths=b;return *this;
    1.92 +  }
    1.93    ///Sets a global scale factor for the whole picture
    1.94  
    1.95    ///Sets a global scale factor for the whole picture
    1.96 @@ -664,6 +694,8 @@
    1.97    ///this function calles the algorithm itself, i.e. in this case
    1.98    ///it draws the graph.
    1.99    void run() {
   1.100 +    ///\todo better 'epsilon' would be nice here.
   1.101 +    const double EPSILON=1e-9;
   1.102      if(dontPrint) return;
   1.103      
   1.104      _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
   1.105 @@ -687,7 +719,7 @@
   1.106        for(EdgeIt e(g);e!=INVALID;++e)
   1.107  	max_w=std::max(double(_edgeWidths[e]),max_w);
   1.108        ///\todo better 'epsilon' would be nice here.
   1.109 -      if(max_w>1e-9) {
   1.110 +      if(max_w>EPSILON) {
   1.111  	_edgeWidthScale/=max_w;
   1.112        }
   1.113      }
   1.114 @@ -697,14 +729,25 @@
   1.115        for(NodeIt n(g);n!=INVALID;++n)
   1.116  	max_s=std::max(double(_nodeSizes[n]),max_s);
   1.117        ///\todo better 'epsilon' would be nice here.
   1.118 -      if(max_s>1e-9) {
   1.119 +      if(max_s>EPSILON) {
   1.120  	_nodeScale/=max_s;
   1.121        }
   1.122      }
   1.123  
   1.124 -
   1.125 +    double diag_len = 1;
   1.126 +    if(!(_absoluteNodeSizes&&_absoluteEdgeWidths)) {
   1.127 +      BoundingBox<double> bb;
   1.128 +      for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]);
   1.129 +      if (bb.empty()) {
   1.130 +	bb = BoundingBox<double>(xy<double>(0,0));
   1.131 +      }
   1.132 +      diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare());
   1.133 +      if(diag_len<EPSILON) diag_len = 1;
   1.134 +      if(!_absoluteNodeSizes) _nodeScale*=diag_len;
   1.135 +      if(!_absoluteEdgeWidths) _edgeWidthScale*=diag_len;
   1.136 +    }
   1.137 +    
   1.138      BoundingBox<double> bb;
   1.139 -    ///\bug: Chech whether the graph is empty.
   1.140      for(NodeIt n(g);n!=INVALID;++n) {
   1.141        double ns=_nodeSizes[n]*_nodeScale;
   1.142        xy<double> p(ns,ns);
   1.143 @@ -864,7 +907,7 @@
   1.144  	  xy<double> dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
   1.145  	  double l=std::sqrt(dvec.normSquare()); 
   1.146  	  ///\todo better 'epsilon' would be nice here.
   1.147 -	  xy<double> d(dvec/std::max(l,1e-9));
   1.148 +	  xy<double> d(dvec/std::max(l,EPSILON));
   1.149   	  xy<double> m;
   1.150  // 	  m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
   1.151