首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在OGDF中设置节点边界框大小

在OGDF中设置节点边界框大小
EN

Stack Overflow用户
提问于 2020-11-16 11:27:17
回答 1查看 177关注 0票数 1

我试图使用OGDF库和Sugiyama布局在Qt中布局和可视化一个代码流图。我使用的版本是v2020.02,这应该是编写本报告时的最新版本。

My问题:在创建节点时,我将它们设置为不同的大小,但是在调用SugiyamaLayout算法之后,所有节点的大小都重置为20x20 (想必是默认的?)。如果我使用另一种算法(如PlanarizationLayout),问题就消失了,节点大小保持其赋值。我尝试了不同的配置,如排名、crossMins和布局,但节点大小不受这些配置的影响。

最小可重现性示例:

代码语言:javascript
复制
//Create graph and attributes
graph_ = new Graph();
GA_ = new GraphAttributes(*graph_, GraphAttributes::nodeGraphics | GraphAttributes::nodeType |
 GraphAttributes::nodeLabel | GraphAttributes::nodeStyle | GraphAttributes::edgeGraphics | 
 GraphAttributes::edgeType | GraphAttributes::edgeArrow);

//Create node and set size
node n = graph_->newNode();
GA_->width(n) = 80; //Or any other dimensions
GA_->height(n) = 40;
//Other nodes and edges omitted

//Create layout
SugiyamaLayout slayout;
slayout.setRanking(new OptimalRanking());
slayout.setCrossMin(new MedianHeuristic());
OptimalHierarchyLayout* ohl = new OptimalHierarchyLayout;
ohl->layerDistance(30.0);
ohl->nodeDistance(25.0);
ohl->weightBalancing(0.8);
slayout.setLayout(ohl);
slayout.call(*GA_);

//Retrieve new node position and size
double x = GA_->x(n);
double y = GA_->y(n);
double w = GA_->width(n);  //This always retrieves w*h of 20x20,
double h = GA_->height(n); //no matter what node dimensions were initially set

//Draw graph, etc. (omitted)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-11-18 12:32:05

经过进一步的研究,OGDF邮件列表为我提供了答案。

这种行为确实是由HierarchyLayoutModule.h中的一个错误引起的,在该错误中,正确的边框大小没有保留。

相应的Github问题可以找到这里,并将在下一个版本中修复。同时,可以通过用以下代码片段替换\include\ogdf\layered\HierarchyLayoutModule.h中的\include\ogdf\layered\HierarchyLayoutModule.h方法来修复这个问题:

代码语言:javascript
复制
/**
 * \brief Computes a hierarchy layout of \p levels in \p GA
 * @param levels is the input hierarchy.
 * @param GA is assigned the hierarchy layout.
 */
void call(const HierarchyLevelsBase &levels, GraphAttributes &GA) {
    GraphAttributes AGC(levels.hierarchy());
    // Copy over relevant nodeGraphics attributes that may be used by doCall or need to be preserved
    // edgeGraphics' bend points need to be cleared and aren't copied over
    if (GA.has(GraphAttributes::nodeGraphics)) {
        const GraphCopy &GC = dynamic_cast<const GraphCopy&>(AGC.constGraph());
        for (node vOrig: GA.constGraph().nodes)
        {
            node v = GC.copy(vOrig);
            if (v != nullptr) {
                AGC.height(v) = GA.height(vOrig);
                AGC.width(v) = GA.width(vOrig);
                AGC.shape(v) = GA.shape(vOrig);
            }
        }
    }
    doCall(levels,AGC);
    AGC.transferToOriginal(GA);
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64857175

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档