[Lemon-commits] [lemon_svn] alpar: r2894 - in hugo/trunk: demo lemon lemon/bits
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 21:51:05 CET 2006
Author: alpar
Date: Mon Aug 14 17:15:57 2006
New Revision: 2894
Added:
hugo/trunk/lemon/bits/bezier.h
- copied unchanged from r2891, /hugo/trunk/lemon/bezier.h
Removed:
hugo/trunk/lemon/bezier.h
Modified:
hugo/trunk/demo/graph_to_eps_demo.cc
hugo/trunk/lemon/graph_to_eps.h
Log:
- bezier.h went to lemon/bits/
- new graphToEps() option: absolute/relative node size/link width scaling.
Modified: hugo/trunk/demo/graph_to_eps_demo.cc
==============================================================================
--- hugo/trunk/demo/graph_to_eps_demo.cc (original)
+++ hugo/trunk/demo/graph_to_eps_demo.cc Mon Aug 14 17:15:57 2006
@@ -42,6 +42,7 @@
int main()
{
Palette palette;
+ Palette paletteW(true);
ListGraph g;
typedef ListGraph::Node Node;
@@ -80,12 +81,21 @@
IdMap<ListGraph,Node> id(g);
+ cout << "Create 'graph_to_eps_demo_out_pure.eps'" << endl;
+ graphToEps(g,"graph_to_eps_demo_out_pure.eps").
+ //scale(10).
+ coords(coords).
+ title("Sample .eps figure").
+ copyright("(C) 2006 LEMON Project").
+ run();
+
cout << "Create 'graph_to_eps_demo_out.eps'" << endl;
graphToEps(g,"graph_to_eps_demo_out.eps").
//scale(10).
coords(coords).
title("Sample .eps figure").
copyright("(C) 2006 LEMON Project").
+ absoluteNodeSizes().absoluteEdgeWidths().
nodeScale(2).nodeSizes(sizes).
nodeShapes(shapes).
nodeColors(composeMap(palette,colors)).
@@ -100,6 +110,7 @@
//scale(10).
title("Sample .eps figure (with arrowheads)").
copyright("(C) 2006 LEMON Project").
+ absoluteNodeSizes().absoluteEdgeWidths().
nodeColors(composeMap(palette,colors)).
coords(coords).
nodeScale(2).nodeSizes(sizes).
@@ -126,6 +137,7 @@
//scale(10).
title("Sample .eps figure (parallel edges)").
copyright("(C) 2006 LEMON Project").
+ absoluteNodeSizes().absoluteEdgeWidths().
nodeShapes(shapes).
coords(coords).
nodeScale(2).nodeSizes(sizes).
@@ -141,6 +153,7 @@
//scale(10).
title("Sample .eps figure (parallel edges and arrowheads)").
copyright("(C) 2006 LEMON Project").
+ absoluteNodeSizes().absoluteEdgeWidths().
nodeScale(2).nodeSizes(sizes).
coords(coords).
nodeShapes(shapes).
@@ -156,6 +169,7 @@
graphToEps(g,"graph_to_eps_demo_out_a4.eps").scaleToA4().
title("Sample .eps figure (fits to A4)").
copyright("(C) 2006 LEMON Project").
+ absoluteNodeSizes().absoluteEdgeWidths().
nodeScale(2).nodeSizes(sizes).
coords(coords).
nodeShapes(shapes).
@@ -172,7 +186,7 @@
ListGraph::NodeMap<Xy> hcoords(h);
int cols=int(sqrt(double(palette.size())));
- for(int i=0;i<int(palette.size());i++) {
+ for(int i=0;i<int(paletteW.size());i++) {
Node n=h.addNode();
hcoords[n]=Xy(i%cols,i/cols);
hcolors[n]=i;
@@ -184,12 +198,11 @@
title("Sample .eps figure (Palette demo)").
copyright("(C) 2006 LEMON Project").
coords(hcoords).
- nodeScale(.45).
+ absoluteNodeSizes().absoluteEdgeWidths().
+ nodeScale(45).
distantColorNodeTexts().
// distantBWNodeTexts().
nodeTexts(hcolors).nodeTextSize(.6).
- nodeColors(composeMap(palette,hcolors)).
+ nodeColors(composeMap(paletteW,hcolors)).
run();
-
-
}
Modified: hugo/trunk/lemon/graph_to_eps.h
==============================================================================
--- hugo/trunk/lemon/graph_to_eps.h (original)
+++ hugo/trunk/lemon/graph_to_eps.h Mon Aug 14 17:15:57 2006
@@ -38,7 +38,7 @@
#include<lemon/xy.h>
#include<lemon/maps.h>
#include<lemon/color.h>
-#include<lemon/bezier.h>
+#include<lemon/bits/bezier.h>
///\ingroup eps_io
@@ -130,6 +130,9 @@
bool _autoNodeScale;
bool _autoEdgeWidthScale;
+ bool _absoluteNodeSizes;
+ bool _absoluteEdgeWidths;
+
bool _negY;
///Constructor
@@ -143,9 +146,9 @@
DefaultGraphToEpsTraits(const G &_g,std::ostream& _os=std::cout,
bool _pros=false) :
g(_g), os(_os),
- _coords(xy<double>(1,1)), _nodeSizes(1.0), _nodeShapes(0),
+ _coords(xy<double>(1,1)), _nodeSizes(.01), _nodeShapes(0),
_nodeColors(WHITE), _edgeColors(BLACK),
- _edgeWidths(1), _edgeWidthScale(0.3),
+ _edgeWidths(1.0), _edgeWidthScale(0.003),
_nodeScale(1.0), _xBorder(10), _yBorder(10), _scale(1.0),
_nodeBorderQuotient(.1),
_drawArrows(false), _arrowLength(1), _arrowWidth(0.3),
@@ -158,6 +161,8 @@
_nodeTextColorType(SAME_COL), _nodeTextColors(BLACK),
_autoNodeScale(false),
_autoEdgeWidthScale(false),
+ _absoluteNodeSizes(false),
+ _absoluteEdgeWidths(false),
_negY(false)
{}
};
@@ -229,6 +234,10 @@
using T::_autoNodeScale;
using T::_autoEdgeWidthScale;
+ using T::_absoluteNodeSizes;
+ using T::_absoluteEdgeWidths;
+
+
using T::_negY;
// dradnats ++C eht yb deriuqer si ti eveileb t'naC
@@ -478,6 +487,8 @@
/// If both nodeSizes() and autoNodeScale() are used, then the
/// node sizes will be scaled in such a way that the greatest size will be
/// equal to \c d.
+ /// \sa nodeSizes()
+ /// \sa autoNodeScale()
GraphToEps<T> &nodeScale(double d) {_nodeScale=d;return *this;}
///Turns on/off the automatic node width scaling.
@@ -489,6 +500,16 @@
_autoNodeScale=b;return *this;
}
+ ///Turns on/off the absolutematic node width scaling.
+
+ ///Turns on/off the absolutematic node width scaling.
+ ///
+ ///\sa nodeScale()
+ ///
+ GraphToEps<T> &absoluteNodeSizes(bool b=true) {
+ _absoluteNodeSizes=b;return *this;
+ }
+
///Negates the Y coordinates.
///Negates the Y coordinates.
@@ -520,6 +541,15 @@
GraphToEps<T> &autoEdgeWidthScale(bool b=true) {
_autoEdgeWidthScale=b;return *this;
}
+ ///Turns on/off the absolutematic edge width scaling.
+
+ ///Turns on/off the absolutematic edge width scaling.
+ ///
+ ///\sa edgeWidthScale()
+ ///
+ GraphToEps<T> &absoluteEdgeWidths(bool b=true) {
+ _absoluteEdgeWidths=b;return *this;
+ }
///Sets a global scale factor for the whole picture
///Sets a global scale factor for the whole picture
@@ -664,6 +694,8 @@
///this function calles the algorithm itself, i.e. in this case
///it draws the graph.
void run() {
+ ///\todo better 'epsilon' would be nice here.
+ const double EPSILON=1e-9;
if(dontPrint) return;
_NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
@@ -687,7 +719,7 @@
for(EdgeIt e(g);e!=INVALID;++e)
max_w=std::max(double(_edgeWidths[e]),max_w);
///\todo better 'epsilon' would be nice here.
- if(max_w>1e-9) {
+ if(max_w>EPSILON) {
_edgeWidthScale/=max_w;
}
}
@@ -697,14 +729,25 @@
for(NodeIt n(g);n!=INVALID;++n)
max_s=std::max(double(_nodeSizes[n]),max_s);
///\todo better 'epsilon' would be nice here.
- if(max_s>1e-9) {
+ if(max_s>EPSILON) {
_nodeScale/=max_s;
}
}
-
+ double diag_len = 1;
+ if(!(_absoluteNodeSizes&&_absoluteEdgeWidths)) {
+ BoundingBox<double> bb;
+ for(NodeIt n(g);n!=INVALID;++n) bb.add(mycoords[n]);
+ if (bb.empty()) {
+ bb = BoundingBox<double>(xy<double>(0,0));
+ }
+ diag_len = std::sqrt((bb.bottomLeft()-bb.topRight()).normSquare());
+ if(diag_len<EPSILON) diag_len = 1;
+ if(!_absoluteNodeSizes) _nodeScale*=diag_len;
+ if(!_absoluteEdgeWidths) _edgeWidthScale*=diag_len;
+ }
+
BoundingBox<double> bb;
- ///\bug: Chech whether the graph is empty.
for(NodeIt n(g);n!=INVALID;++n) {
double ns=_nodeSizes[n]*_nodeScale;
xy<double> p(ns,ns);
@@ -864,7 +907,7 @@
xy<double> dvec(mycoords[g.target(*i)]-mycoords[g.source(*i)]);
double l=std::sqrt(dvec.normSquare());
///\todo better 'epsilon' would be nice here.
- xy<double> d(dvec/std::max(l,1e-9));
+ xy<double> d(dvec/std::max(l,EPSILON));
xy<double> m;
// m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
More information about the Lemon-commits
mailing list