1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
|
/**
*
* This file is part of Tulip (www.tulip-software.org)
*
* Authors: David Auber and the Tulip development Team
* from LaBRI, University of Bordeaux 1 and Inria Bordeaux - Sud Ouest
*
* Tulip is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation, either version 3
* of the License, or (at your option) any later version.
*
* Tulip is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
*/
#include "ConnectedComponent.h"
#include <tulip/ConnectedTest.h>
using namespace tlp;
DOUBLEPLUGINOFGROUP(ConnectedComponent,"Connected Component","David Auber","01/07/2002","Alpha","1.0","Component");
ConnectedComponent::ConnectedComponent(const tlp::PropertyContext &context):DoubleAlgorithm(context) {}
//======================================================
ConnectedComponent::~ConnectedComponent() {}
//======================================================
bool ConnectedComponent::run() {
std::vector<std::set<node> > components;
ConnectedTest::computeConnectedComponents(graph, components);
// assign the index of each component as value for its nodes
//unsigned int curComponent = 0;
for (unsigned int curComponent=0; curComponent < components.size(); ++curComponent) {
std::set<node>& component = components[curComponent];
for(std::set<node>::const_iterator itNode = component.begin(); itNode!=component.end(); ++itNode) {
doubleResult->setNodeValue(*itNode, curComponent);
}
}
// propagate nodes computed value to edges
Iterator<edge> *itE=graph->getEdges();
while (itE->hasNext()) {
edge ite=itE->next();
node source= graph->source(ite);
// node target= graph->target(ite);
// if (doubleResult->getNodeValue(source) == doubleResult->getNodeValue(target))
doubleResult->setEdgeValue(ite, doubleResult->getNodeValue(source));
// else
// doubleResult->setEdgeValue(ite,curComponent);
}
delete itE;
return true;
}
//======================================================
|