[Lemon-commits] [lemon_svn] alpar: r2189 - hugo/trunk/lemon
Lemon SVN
svn at lemon.cs.elte.hu
Mon Nov 6 20:50:48 CET 2006
Author: alpar
Date: Thu Sep 1 21:21:35 2005
New Revision: 2189
Modified:
hugo/trunk/lemon/graph_to_eps.h
Log:
negateY() option added.
Modified: hugo/trunk/lemon/graph_to_eps.h
==============================================================================
--- hugo/trunk/lemon/graph_to_eps.h (original)
+++ hugo/trunk/lemon/graph_to_eps.h Thu Sep 1 21:21:35 2005
@@ -169,6 +169,17 @@
return Color(v,v,v);
}
+template<class MT>
+class _NegY {
+public:
+ typedef typename MT::Key Key;
+ typedef typename MT::Value Value;
+ const MT ↦
+ int yscale;
+ _NegY(const MT &m,bool b) : map(m), yscale(1-b*2) {}
+ Value operator[](Key n) { return Value(map[n].x,map[n].y*yscale);}
+};
+
///Default traits class of \ref GraphToEps
///Default traits class of \ref GraphToEps
@@ -190,7 +201,8 @@
std::ostream& os;
- ConstMap<typename Graph::Node,xy<double> > _coords;
+ typedef ConstMap<typename Graph::Node,xy<double> > CoordsMapType;
+ CoordsMapType _coords;
ConstMap<typename Graph::Node,double > _nodeSizes;
ConstMap<typename Graph::Node,int > _nodeShapes;
@@ -237,6 +249,7 @@
bool _autoNodeScale;
bool _autoEdgeWidthScale;
+ bool _negY;
///Constructor
///Constructor
@@ -263,7 +276,8 @@
_pleaseRemoveOsStream(_pros), _scaleToA4(false),
_nodeTextColorType(SAME_COL), _nodeTextColors(Color(0,0,0)),
_autoNodeScale(false),
- _autoEdgeWidthScale(false)
+ _autoEdgeWidthScale(false),
+ _negY(false)
{}
};
@@ -413,6 +427,7 @@
GraphToEps(const T &t) : T(t), dontPrint(false) {};
template<class X> struct CoordsTraits : public T {
+ typedef X CoordsMapType;
const X &_coords;
CoordsTraits(const T &t,const X &x) : T(t), _coords(x) {}
};
@@ -579,6 +594,17 @@
GraphToEps<T> &autoNodeScale(bool b=true) {
_autoNodeScale=b;return *this;
}
+
+ ///Negates the Y coordinates.
+
+ ///Negates the Y coordinates.
+ ///
+ ///\todo More docs.
+ ///
+ GraphToEps<T> &negateY(bool b=true) {
+ _negY=b;return *this;
+ }
+
///Sets a global scale factor for edge widths
/// Sets a global scale factor for edge widths.
@@ -743,6 +769,8 @@
void run() {
if(dontPrint) return;
+ _NegY<typename T::CoordsMapType> mycoords(_coords,_negY);
+
os << "%!PS-Adobe-2.0 EPSF-2.0\n";
if(_title.size()>0) os << "%%Title: " << _title << '\n';
if(_copyright.size()>0) os << "%%Copyright: " << _copyright << '\n';
@@ -783,8 +811,8 @@
for(NodeIt n(g);n!=INVALID;++n) {
double ns=_nodeSizes[n]*_nodeScale;
xy<double> p(ns,ns);
- bb.add(p+_coords[n]);
- bb.add(-p+_coords[n]);
+ bb.add(p+mycoords[n]);
+ bb.add(-p+mycoords[n]);
}
if (bb.empty()) {
bb = BoundingBox<double>(xy<double>(0,0));
@@ -888,18 +916,18 @@
sw+=_edgeWidths[*e]*_edgeWidthScale+_parEdgeDist;
sw-=_parEdgeDist;
sw/=-2.0;
- xy<double> dvec(_coords[g.target(*i)]-_coords[g.source(*i)]);
+ 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> m;
-// m=xy<double>(_coords[g.target(*i)]+_coords[g.source(*i)])/2.0;
+// m=xy<double>(mycoords[g.target(*i)]+mycoords[g.source(*i)])/2.0;
-// m=xy<double>(_coords[g.source(*i)])+
+// m=xy<double>(mycoords[g.source(*i)])+
// dvec*(double(_nodeSizes[g.source(*i)])/
// (_nodeSizes[g.source(*i)]+_nodeSizes[g.target(*i)]));
- m=xy<double>(_coords[g.source(*i)])+
+ m=xy<double>(mycoords[g.source(*i)])+
d*(l+_nodeSizes[g.source(*i)]-_nodeSizes[g.target(*i)])/2.0;
for(typename std::vector<Edge>::iterator e=i;e!=j;++e) {
@@ -907,8 +935,8 @@
xy<double> mm=m+rot90(d)*sw/.75;
if(_drawArrows) {
int node_shape;
- xy<double> s=_coords[g.source(*e)];
- xy<double> t=_coords[g.target(*e)];
+ xy<double> s=mycoords[g.source(*e)];
+ xy<double> t=mycoords[g.target(*e)];
double rn=_nodeSizes[g.target(*e)]*_nodeScale;
node_shape=_nodeShapes[g.target(*e)];
Bezier3 bez(s,mm,mm,t);
@@ -948,11 +976,11 @@
<< psOut(linend-dd) << " lineto closepath fill\n";
}
else {
- os << _coords[g.source(*e)].x << ' '
- << _coords[g.source(*e)].y << ' '
+ os << mycoords[g.source(*e)].x << ' '
+ << mycoords[g.source(*e)].y << ' '
<< mm.x << ' ' << mm.y << ' '
- << _coords[g.target(*e)].x << ' '
- << _coords[g.target(*e)].y << ' '
+ << mycoords[g.target(*e)].x << ' '
+ << mycoords[g.target(*e)].y << ' '
<< _edgeColors[*e].red() << ' '
<< _edgeColors[*e].green() << ' '
<< _edgeColors[*e].blue() << ' '
@@ -965,7 +993,7 @@
else for(EdgeIt e(g);e!=INVALID;++e)
if((!_undir||g.source(e)<g.target(e))&&_edgeWidths[e]>0)
if(_drawArrows) {
- xy<double> d(_coords[g.target(e)]-_coords[g.source(e)]);
+ xy<double> d(mycoords[g.target(e)]-mycoords[g.source(e)]);
double rn=_nodeSizes[g.target(e)]*_nodeScale;
int node_shape=_nodeShapes[g.target(e)];
double t1=0,t2=1;
@@ -978,16 +1006,16 @@
os << l*(1-(t1+t2)/2) << ' '
<< _edgeWidths[e]*_edgeWidthScale << ' '
<< d.x << ' ' << d.y << ' '
- << _coords[g.source(e)].x << ' '
- << _coords[g.source(e)].y << ' '
+ << mycoords[g.source(e)].x << ' '
+ << mycoords[g.source(e)].y << ' '
<< _edgeColors[e].red() << ' '
<< _edgeColors[e].green() << ' '
<< _edgeColors[e].blue() << " arr\n";
}
- else os << _coords[g.source(e)].x << ' '
- << _coords[g.source(e)].y << ' '
- << _coords[g.target(e)].x << ' '
- << _coords[g.target(e)].y << ' '
+ else os << mycoords[g.source(e)].x << ' '
+ << mycoords[g.source(e)].y << ' '
+ << mycoords[g.target(e)].x << ' '
+ << mycoords[g.target(e)].y << ' '
<< _edgeColors[e].red() << ' '
<< _edgeColors[e].green() << ' '
<< _edgeColors[e].blue() << ' '
@@ -997,7 +1025,7 @@
if(_showNodes) {
os << "%Nodes:\ngsave\n";
for(NodeIt n(g);n!=INVALID;++n) {
- os << _coords[n].x << ' ' << _coords[n].y << ' '
+ os << mycoords[n].x << ' ' << mycoords[n].y << ' '
<< _nodeSizes[n]*_nodeScale << ' '
<< _nodeColors[n].red() << ' '
<< _nodeColors[n].green() << ' '
@@ -1032,7 +1060,7 @@
default:
os << "0 0 0 setrgbcolor\n";
}
- os << _coords[n].x << ' ' << _coords[n].y
+ os << mycoords[n].x << ' ' << mycoords[n].y
<< " (" << _nodeTexts[n] << ") cshow\n";
}
os << "grestore\n";
@@ -1040,7 +1068,7 @@
if(_showNodePsText) {
os << "%Node PS blocks:\ngsave\n";
for(NodeIt n(g);n!=INVALID;++n)
- os << _coords[n].x << ' ' << _coords[n].y
+ os << mycoords[n].x << ' ' << mycoords[n].y
<< " moveto\n" << _nodePsTexts[n] << "\n";
os << "grestore\n";
}
More information about the Lemon-commits
mailing list