improved clustering effect with a non linear edge length

git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@3739 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
csoler 2010-11-01 15:15:56 +00:00
parent 0fcc298801
commit c5a8d25067
3 changed files with 23 additions and 27 deletions

View File

@ -54,21 +54,6 @@ NetworkView::NetworkView(QWidget *parent)
connect( ui.edgeLengthSB, SIGNAL(valueChanged(int)), this, SLOT(setEdgeLength(int)));
insertPeers();
/* hide the Tree +/- */
// ui.linkTreeWidget -> setRootIsDecorated( false );
/* Set header resize modes and initial section sizes */
// QHeaderView * _header = ui.linkTreeWidget->header () ;
// _header->setResizeMode (0, QHeaderView::Interactive);
// _header->setResizeMode (1, QHeaderView::Interactive);
// _header->setResizeMode (2, QHeaderView::Interactive);
//
// _header->resizeSection ( 0, 400 );
// _header->resizeSection ( 1, 50 );
// _header->resizeSection ( 2, 150 );
}
void NetworkView::setEdgeLength(int l)
@ -224,17 +209,17 @@ void NetworkView::insertPeers()
node_ids[info.gpg_id] = ui.graphicsView->addNode(" "+detail.name, detail.name+"@"+info.gpg_id,type,auth);
std::cerr << " inserted node " << info.gpg_id << ", type=" << type << ", auth=" << auth << std::endl ;
std::cerr << "NetworkView::insertPeers() Added Friend: " << info.gpg_id << std::endl;
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); ++sit)
if(nodes_considered.find(*sit) == nodes_considered.end())
{
std::cerr << " adding to queue: " << *sit << ", with level " << info.friend_level+1 << std::endl ;
nodes_to_treat.push_front( NodeInfo(*sit,info.friend_level + 1) ) ;
nodes_considered.insert(*sit) ;
}
}
std::cerr << "NetworkView::insertPeers() Added Friend: " << info.gpg_id << std::endl;
for(std::list<std::string>::const_iterator sit(detail.gpgSigners.begin()); sit != detail.gpgSigners.end(); ++sit)
if(nodes_considered.find(*sit) == nodes_considered.end())
{
std::cerr << " adding to queue: " << *sit << ", with level " << info.friend_level+1 << std::endl ;
nodes_to_treat.push_front( NodeInfo(*sit,info.friend_level + 1) ) ;
nodes_considered.insert(*sit) ;
}
}
/* iterate through all friends */

View File

@ -138,16 +138,26 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
yforce = REPULSION_FACTOR * dej/25.0;
// Now subtract all forces pulling items together
double weight = (edgeList.size() + 1) ;
double weight = (n_edges() + 1) ;
foreach (Edge *edge, edgeList) {
QPointF pos;
double w2 ; // This factor makes the edge length depend on connectivity, so clusters of friends tend to stay in the
// same location.
//
if (edge->sourceNode() == this)
{
pos = mapFromItem(edge->destNode(), 0, 0);
w2 = sqrtf(std::min(n_edges(),edge->destNode()->n_edges())) ;
}
else
{
pos = mapFromItem(edge->sourceNode(), 0, 0);
w2 = sqrtf(std::min(n_edges(),edge->sourceNode()->n_edges())) ;
}
float dist = sqrtf(pos.x()*pos.x() + pos.y()*pos.y()) ;
float val = dist - graph->edgeLength() ;
float val = dist - graph->edgeLength() * w2 ;
xforce += 0.01*pos.x() * val / weight;
yforce += 0.01*pos.y() * val / weight;

View File

@ -69,6 +69,7 @@ public:
QPainterPath shape() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
int n_edges() const { return edgeList.size() ; }
protected:
virtual QVariant itemChange(GraphicsItemChange change, const QVariant &value);