예제 #1
0
  bool exportGraph(ostream &os) {

    os << "graph [" << endl;
    os << "directed 1" << endl;
    os << "version 2" << endl;

    LayoutProperty *layout = graph->getProperty<LayoutProperty>("viewLayout");
    StringProperty *label = graph->getProperty<StringProperty>("viewLabel");
    //    IntegerProperty *shape =getProperty<IntegerProperty>(graph->getPropertyManager(),"viewShape");
    ColorProperty *colors = graph->getProperty<ColorProperty>("viewColor");
    SizeProperty  *sizes = graph->getProperty<SizeProperty>("viewSize");
    //Save Nodes
    Iterator<node> *itN=graph->getNodes();

    if (itN->hasNext())  {

      for (; itN->hasNext();) {
        node itn=itN->next();
        os << "node [" << endl;
        os << "id "<< itn.id << endl ;
        os << "label \"" << convert(label->getNodeValue(itn)) << "\"" << endl;
        os << "graphics [" << endl;
        printCoord(os,layout->getNodeValue(itn));
        printSize(os,sizes->getNodeValue(itn));
        os << "type \"rectangle\"" << endl;
        os << "width 0.12" << endl;
        os << "fill \"#"<< hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getR()
           << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getG()
           << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getB() << "\""<< endl;

        //      os << "outline \"#"<< hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getR()
        //         << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getG()
        //         << hex << setfill('0') << setw(2) <<(int)colors->getNodeValue(itn).getB() << "\""<< endl;

        os << "outline \"#000000\"" << endl;
        os << dec << setfill(' ') << setw(6) << "]" << endl;
        os << ']' << endl;
      }
    }

    delete itN;

    //Save edges
    Iterator<edge> *itE=graph->getEdges();

    for (; itE->hasNext();) {
      edge ite=itE->next();
      os << "edge [" << endl;
      os << "source " << graph->source(ite).id << endl;
      os << "target " << graph->target(ite).id << endl;
      os << "id " << ite.id << endl;
      os << "label \"" << label->getEdgeValue(ite) << "\"" << endl;
      os << "graphics [" << endl;
      os << "type \"line\"" << endl;
      os << "arrow \"last\"" << endl;
      os << "width 0.1" << endl;
      os << "Line [" << endl;
      vector<Coord> lcoord;
      vector<Coord>::const_iterator it;
      lcoord=layout->getEdgeValue(ite);

      if (!lcoord.empty()) {
        node itn=graph->source(ite);
        printPoint(os,layout->getNodeValue(itn));
      }

      for (it=lcoord.begin(); it!=lcoord.end(); ++it) {
        printPoint(os,*it);
      }

      if (!lcoord.empty()) {
        node itn=graph->target(ite);
        printPoint(os,layout->getNodeValue(itn));
      }

      os << "]" << endl;
      os << "]" << endl;
      os << "]" << endl;
    }

    delete itE;
    os << "]" << endl;
    return true;
  }
//====================================================================
bool ConnectedComponentPacking::run() {

  LayoutProperty *layout = NULL;
  SizeProperty *size = NULL;
  DoubleProperty *rotation = NULL;
  string complexity("auto");

  workingGraph = graph->addCloneSubGraph("workingGraph");

  if ( dataSet!=NULL ) {
    dataSet->get("coordinates", layout);
    getNodeSizePropertyParameter(dataSet, size);
    dataSet->get("rotation", rotation);
    StringCollection complexityCol;

    if (dataSet->get("complexity", complexityCol))
      complexity = complexityCol.getCurrentString();
  }

  if (layout==NULL)
    layout = workingGraph->getProperty<LayoutProperty>("viewLayout");

  if (size==NULL)
    size = workingGraph->getProperty<SizeProperty>("viewSize");

  if (rotation==NULL)
    rotation = workingGraph->getProperty<DoubleProperty>("viewRotation");

  if (complexity=="none")
    complexity = "auto";

  // compute the connected components's subgraphs
  std::vector<std::set<node> > components;
  ConnectedTest::computeConnectedComponents(workingGraph, components);

  for (unsigned int i = 0; i < components.size(); ++i) {
    workingGraph->inducedSubGraph(components[i]);
  }

  vector<Rectangle<float> > rectangles;
  Iterator<Graph *> *it = workingGraph->getSubGraphs();

  while(it->hasNext()) {
    Graph *sg = it->next();
    BoundingBox tmp = tlp::computeBoundingBox(sg, layout, size, rotation);
    Rectangle<float> tmpRec;
    tmpRec[1][0] = tmp[1][0] + spacing;
    tmpRec[1][1] = tmp[1][1] + spacing;
    tmpRec[0][0] = tmp[0][0] + spacing;
    tmpRec[0][1] = tmp[0][1] + spacing;
    assert(tmpRec.isValid());
    rectangles.push_back(tmpRec);
  }

  delete it;

  if (complexity == "auto") {
    if (rectangles.size()<25) {
      complexity="n5";
    }
    else if (rectangles.size()<50) {
      complexity="n4logn";
    }
    else if (rectangles.size()<100) {
      complexity="n4";
    }
    else if (rectangles.size()<150) {
      complexity="n3logn";
    }
    else if (rectangles.size()<250) {
      complexity="n3";
    }
    else if (rectangles.size()<500) {
      complexity="n2logn";
    }
    else if (rectangles.size()<1000) {
      complexity="n2";
    }
    else if (rectangles.size()<5000) {
      complexity="nlogn";
    }
    else
      complexity="n";
  }

  vector<Rectangle<float> > rectanglesBackup(rectangles);
  RectanglePackingLimitRectangles(rectangles, complexity.c_str(), pluginProgress);
  Iterator<node> *itN = graph->getNodes();

  while(itN->hasNext()) {
    node n = itN->next();
    layoutResult->setNodeValue(n, layout->getNodeValue(n));
  }

  delete itN;
  Iterator<edge> *itE = graph->getEdges();

  while(itE->hasNext()) {
    edge e = itE->next();
    layoutResult->setEdgeValue(e, layout->getEdgeValue(e));
  }

  delete itE;
  unsigned int i = 0;
  it = workingGraph->getSubGraphs();

  while(it->hasNext()) {
    Graph *sg = it->next();
    Coord move(rectangles[i][0][0]-rectanglesBackup[i][0][0], rectangles[i][0][1]-rectanglesBackup[i][0][1], 0);
    layoutResult->translate(move, sg);
    ++i;
  }

  delete it;
  graph->delAllSubGraphs(workingGraph);

  return true;
}