mirror of
https://github.com/RetroShare/RetroShare.git
synced 2024-10-01 02:35:48 -04:00
added adaptive factor to force convergence of network graph
git-svn-id: http://svn.code.sf.net/p/retroshare/code/trunk@6264 b45a01b8-16f6-495d-af2f-9b41ad6348cc
This commit is contained in:
parent
b913c8ae4f
commit
ff5fde090c
@ -134,6 +134,7 @@ GraphWidget::GraphWidget(QWidget *)
|
||||
setRenderHint(QPainter::Antialiasing);
|
||||
setTransformationAnchor(AnchorUnderMouse);
|
||||
setResizeAnchor(AnchorViewCenter);
|
||||
_friction_factor = 1.0f ;
|
||||
|
||||
|
||||
|
||||
@ -158,6 +159,7 @@ void GraphWidget::clearGraph()
|
||||
scene()->setSceneRect(-200, -200, 1000, 1000);
|
||||
_edges.clear();
|
||||
_nodes.clear();
|
||||
_friction_factor = 1.0f ;
|
||||
}
|
||||
|
||||
GraphWidget::NodeId GraphWidget::addNode(const std::string& node_short_string,const std::string& node_complete_string,NodeType type,AuthType auth,const std::string& ssl_id,const std::string& gpg_id)
|
||||
@ -220,6 +222,7 @@ void GraphWidget::itemMoved()
|
||||
std::cout << "starting timer" << std::endl;
|
||||
#endif
|
||||
timerId = startTimer(1000 / 25); // hit timer 25 times per second.
|
||||
_friction_factor = 1.0f ;
|
||||
}
|
||||
}
|
||||
|
||||
@ -342,15 +345,13 @@ void GraphWidget::timerEvent(QTimerEvent *event)
|
||||
convolveWithGaussian(forceMap,S,20) ;
|
||||
}
|
||||
|
||||
static float speedf=1.0f;
|
||||
|
||||
foreach (Node *node, _nodes)
|
||||
{
|
||||
QPointF pos = node->mapToScene(QPointF(0,0)) ;
|
||||
float x = S*(pos.x()-R.left())/R.width() ;
|
||||
float y = S*(pos.y()-R.top())/R.height() ;
|
||||
|
||||
node->calculateForces(forceMap,R.width(),R.height(),S,S,x,y,speedf);
|
||||
node->calculateForces(forceMap,R.width(),R.height(),S,S,x,y,_friction_factor);
|
||||
}
|
||||
|
||||
bool itemsMoved = false;
|
||||
@ -365,6 +366,8 @@ void GraphWidget::timerEvent(QTimerEvent *event)
|
||||
#endif
|
||||
timerId = 0;
|
||||
}
|
||||
_friction_factor *= 1.001f ;
|
||||
// std::cerr << "Friction factor = " << _friction_factor << std::endl;
|
||||
}
|
||||
|
||||
void GraphWidget::setEdgeLength(uint32_t l)
|
||||
@ -377,6 +380,7 @@ void GraphWidget::setEdgeLength(uint32_t l)
|
||||
std::cout << "starting timer" << std::endl;
|
||||
#endif
|
||||
timerId = startTimer(1000 / 25);
|
||||
_friction_factor = 1.0f ;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -101,6 +101,7 @@ private:
|
||||
std::map<std::string,QPointF> _node_cached_positions ;
|
||||
|
||||
uint32_t _edge_length ;
|
||||
float _friction_factor ;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -111,7 +111,7 @@ const QList<Edge *>& Node::edges() const
|
||||
// +di *( (1-dj)*map[2*(i+1+W*j)] + dj*map[2*(i+1+W*(j+1))]) ;
|
||||
//}
|
||||
|
||||
void Node::calculateForces(const double *map,int width,int height,int W,int H,float x,float y,float /*speedf*/)
|
||||
void Node::calculateForces(const double *map,int width,int height,int W,int H,float x,float y,float friction_factor)
|
||||
{
|
||||
if (!scene() || scene()->mouseGrabberItem() == this)
|
||||
{
|
||||
@ -192,8 +192,8 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
||||
|
||||
// now time filter:
|
||||
|
||||
_speedx += xforce / MASS_FACTOR;
|
||||
_speedy += yforce / MASS_FACTOR;
|
||||
_speedx += xforce / MASS_FACTOR ;
|
||||
_speedy += yforce / MASS_FACTOR ;
|
||||
|
||||
if(_speedx > 10) _speedx = 10.0f ;
|
||||
if(_speedy > 10) _speedy = 10.0f ;
|
||||
@ -201,7 +201,7 @@ void Node::calculateForces(const double *map,int width,int height,int W,int H,fl
|
||||
if(_speedy <-10) _speedy =-10.0f ;
|
||||
|
||||
QRectF sceneRect = scene()->sceneRect();
|
||||
newPos = pos() + QPointF(_speedx, _speedy);
|
||||
newPos = pos() + QPointF(_speedx, _speedy) / friction_factor;
|
||||
newPos.setX(qMin(qMax(newPos.x(), sceneRect.left() + 10), sceneRect.right() - 10));
|
||||
newPos.setY(qMin(qMax(newPos.y(), sceneRect.top() + 10), sceneRect.bottom() - 10));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user