コード例 #1
0
bool exportToGraphvizFormat_Nodal(
  const GraphT & g,
  ostream & os)
{
  os << "graph 1 {" << endl;
  os << "node [shape=circle]" << endl;
  //Export node label
  for(typename GraphT::NodeIt n(g); n!= lemon::INVALID; ++n)
  {
    os << "  n" << g.id(n) << std::endl;
  }

  //-- Export arc (as the graph is bi-directional, export arc only one time)

  map< std::pair<size_t,size_t>, size_t > map_arcs;
  for(typename GraphT::ArcIt e(g); e!=lemon::INVALID; ++e) {
    if( map_arcs.end() == map_arcs.find(std::make_pair(size_t (g.id(g.source(e))), size_t (g.id(g.target(e)))))
      &&
      map_arcs.end() == map_arcs.find(std::make_pair(size_t (g.id(g.target(e))), size_t (g.id(g.source(e))))))
    {
      map_arcs[std::pair<size_t,size_t>(size_t (g.id(g.source(e))),
        size_t (g.id(g.target(e)))) ] = 1;
    }
  }
  //os << "edge [style=bold]" << endl;
  for ( map< std::pair<size_t,size_t>, size_t >::const_iterator iter = map_arcs.begin();
    iter != map_arcs.end();
    ++iter)
  {
    os << "  n" << iter->first.first << " -- " << " n" << iter->first.second << endl;
  }

  os << "}" << endl;
  return os.good();
}
コード例 #2
0
bool exportToGraphvizFormat_Image(
  const GraphT & g,
  const NodeMap & nodeMap,
  const EdgeMap & edgeMap,
  ostream & os, bool bWeightedEdge=false)
{
  os << "graph 1 {" << endl;
  os << "node [shape=none]" << endl;
  //Export node label
  for(typename GraphT::NodeIt n(g); n!=lemon::INVALID; ++n)
  {
    os << "  n" << g.id(n)
       << "[ label ="
      <<
      "< "<< endl
      <<"<table>"<< endl
      <<"<tr><td>" << "\"" << nodeMap[n] <<"\"" <<"</td></tr>"<< endl
      <<"<tr><td><img src=\"" << nodeMap[n] <<"\"/></td></tr>"<< endl
      <<"</table>"<< endl
      <<">, cluster=1];"<< endl;

    //os << "  n" << g.id(n)
    //  << " [ "
    //  << " image=\"" << nodeMap[n] << "\" cluster=1]; " << endl;
  }

  //Export arc value
  map< std::pair<size_t,size_t>, size_t > map_arcs;
  for(typename GraphT::ArcIt e(g); e!=lemon::INVALID; ++e) {
    if( map_arcs.end() == map_arcs.find(std::make_pair(size_t (g.id(g.source(e))), size_t (g.id(g.target(e)))))
      &&
      map_arcs.end() == map_arcs.find(std::make_pair(size_t (g.id(g.target(e))), size_t (g.id(g.source(e))))))
    {
      map_arcs[std::pair<size_t,size_t>(size_t (g.id(g.source(e))),
        size_t (g.id(g.target(e)))) ] = edgeMap[e];
    }
  }

  os << "edge [style=bold]" << endl;
  for ( map< std::pair<size_t,size_t>, size_t >::const_iterator iter = map_arcs.begin();
    iter != map_arcs.end();
    ++iter)
  {
    if (bWeightedEdge)
    {
      os << "  n" << iter->first.first << " -- " << " n" << iter->first.second
        << " [label=\"" << iter->second << "\"]" << endl;
    }
    else
    {
      os << "  n" << iter->first.first << " -- " << " n" << iter->first.second << endl;
    }
  }
  os << "}" << endl;
  return os.good();
}