lemon/graph_to_eps.h
changeset 1908 e225719bde6b
parent 1875 98698b69a902
child 1909 2d806130e700
equal deleted inserted replaced
13:3c95b6fce6f8 14:ebec631b2e08
   383     SQUARE=1, 
   383     SQUARE=1, 
   384     /// = 2
   384     /// = 2
   385     ///\image html nodeshape_2.png
   385     ///\image html nodeshape_2.png
   386     ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
   386     ///\image latex nodeshape_2.eps "DIAMOND shape (2)" width=2cm
   387     ///
   387     ///
   388     DIAMOND=2
   388     DIAMOND=2,
       
   389     /// = 3
       
   390     ///\image html nodeshape_3.png
       
   391     ///\image latex nodeshape_2.eps "MALE shape (4)" width=2cm
       
   392     ///
       
   393     MALE=3,
       
   394     /// = 4
       
   395     ///\image html nodeshape_4.png
       
   396     ///\image latex nodeshape_2.eps "FEMALE shape (4)" width=2cm
       
   397     ///
       
   398     FEMALE=4
   389   };
   399   };
   390 
   400 
   391 private:
   401 private:
   392   class edgeLess {
   402   class edgeLess {
   393     const Graph &g;
   403     const Graph &g;
   748 protected:
   758 protected:
   749   bool isInsideNode(xy<double> p, double r,int t) 
   759   bool isInsideNode(xy<double> p, double r,int t) 
   750   {
   760   {
   751     switch(t) {
   761     switch(t) {
   752     case CIRCLE:
   762     case CIRCLE:
       
   763     case MALE:
       
   764     case FEMALE:
   753       return p.normSquare()<=r*r;
   765       return p.normSquare()<=r*r;
   754     case SQUARE:
   766     case SQUARE:
   755       return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
   767       return p.x<=r&&p.x>=-r&&p.y<=r&&p.y>=-r;
   756     case DIAMOND:
   768     case DIAMOND:
   757       return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
   769       return p.x+p.y<=r && p.x-p.y<=r && -p.x+p.y<=r && -p.x-p.y<=r;
   811     BoundingBox<double> bb;
   823     BoundingBox<double> bb;
   812     ///\bug: Chech whether the graph is empty.
   824     ///\bug: Chech whether the graph is empty.
   813     for(NodeIt n(g);n!=INVALID;++n) {
   825     for(NodeIt n(g);n!=INVALID;++n) {
   814       double ns=_nodeSizes[n]*_nodeScale;
   826       double ns=_nodeSizes[n]*_nodeScale;
   815       xy<double> p(ns,ns);
   827       xy<double> p(ns,ns);
   816       bb.add(p+mycoords[n]);
   828       switch(_nodeShapes[n]) {
   817       bb.add(-p+mycoords[n]);
   829       case CIRCLE:
       
   830       case SQUARE:
       
   831       case DIAMOND:
       
   832 	bb.add(p+mycoords[n]);
       
   833 	bb.add(-p+mycoords[n]);
       
   834 	break;
       
   835       case MALE:
       
   836 	bb.add(-p+mycoords[n]);
       
   837 	bb.add(xy<double>(1.5*ns,1.5*sqrt(3)*ns)+mycoords[n]);
       
   838 	break;
       
   839       case FEMALE:
       
   840 	bb.add(p+mycoords[n]);
       
   841 	bb.add(xy<double>(-ns,-3.01*ns)+mycoords[n]);
       
   842 	break;
       
   843       }
   818     }
   844     }
   819     if (bb.empty()) {
   845     if (bb.empty()) {
   820       bb = BoundingBox<double>(xy<double>(0,0));
   846       bb = BoundingBox<double>(xy<double>(0,0));
   821     }
   847     }
   822     
   848     
   856        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n"
   882        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div sq fill\n"
   857        << "   } bind def\n";
   883        << "   } bind def\n";
   858     os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n"
   884     os << "/ndi { 0 0 0 setrgbcolor 5 index 5 index 5 index di fill\n"
   859        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n"
   885        << "     setrgbcolor " << 1+_nodeBorderQuotient << " div di fill\n"
   860        << "   } bind def\n";
   886        << "   } bind def\n";
       
   887     os << "/nfemale { 0 0 0 setrgbcolor 3 index "
       
   888        << _nodeBorderQuotient/(1+_nodeBorderQuotient)
       
   889        << " 1.5 mul mul setlinewidth\n"
       
   890        << "  newpath 5 index 5 index moveto "
       
   891        << "5 index 5 index 5 index 3.01 mul sub\n"
       
   892        << "  lineto 5 index 4 index .7 mul sub 5 index 5 index 2.2 mul sub moveto\n"
       
   893        << "  5 index 4 index .7 mul add 5 index 5 index 2.2 mul sub lineto stroke\n"
       
   894        << "  5 index 5 index 5 index c fill\n"
       
   895        << "  setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
       
   896        << "  } bind def\n";
       
   897     os << "/nmale {\n"
       
   898        << "  0 0 0 setrgbcolor 3 index "
       
   899        << _nodeBorderQuotient/(1+_nodeBorderQuotient)
       
   900        <<" 1.5 mul mul setlinewidth\n"
       
   901        << "  newpath 5 index 5 index moveto\n"
       
   902        << "  5 index 4 index 1 mul 1.5 mul add\n"
       
   903        << "  5 index 5 index 3 sqrt 1.5 mul mul add\n"
       
   904        << "  1 index 1 index lineto\n"
       
   905        << "  1 index 1 index 7 index sub moveto\n"
       
   906        << "  1 index 1 index lineto\n"
       
   907        << "  exch 5 index 3 sqrt .5 mul mul sub exch 5 index .5 mul sub lineto\n"
       
   908        << "  stroke\n"
       
   909        << "  5 index 5 index 5 index c fill\n"
       
   910        << "  setrgbcolor " << 1+_nodeBorderQuotient << " div c fill\n"
       
   911        << "  } bind def\n";
       
   912     
       
   913 
   861     os << "/arrl " << _arrowLength << " def\n";
   914     os << "/arrl " << _arrowLength << " def\n";
   862     os << "/arrw " << _arrowWidth << " def\n";
   915     os << "/arrw " << _arrowWidth << " def\n";
   863     // l dx_norm dy_norm
   916     // l dx_norm dy_norm
   864     os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
   917     os << "/lrl { 2 index mul exch 2 index mul exch rlineto pop} bind def\n";
   865     //len w dx_norm dy_norm x1 y1 cr cg cb
   918     //len w dx_norm dy_norm x1 y1 cr cg cb
  1037 	  os<< "nc";break;
  1090 	  os<< "nc";break;
  1038 	case SQUARE:
  1091 	case SQUARE:
  1039 	  os<< "nsq";break;
  1092 	  os<< "nsq";break;
  1040 	case DIAMOND:
  1093 	case DIAMOND:
  1041 	  os<< "ndi";break;
  1094 	  os<< "ndi";break;
       
  1095 	case MALE:
       
  1096 	  os<< "nmale";break;
       
  1097 	case FEMALE:
       
  1098 	  os<< "nfemale";break;
  1042 	}
  1099 	}
  1043 	os<<'\n';
  1100 	os<<'\n';
  1044       }
  1101       }
  1045       os << "grestore\n";
  1102       os << "grestore\n";
  1046     }
  1103     }