正确混合QGraphicItems和CGAL

时间:2015-08-20 12:29:25

标签: c++ qt data-structures generic-programming cgal

我在 <div id = "command"><p class = "bg-info">Command for connecting to the server: </p></br> ID:<span id = "command">{{ vm.id }}</span></div> 中有一些QGraphicsItem(主要是QGraphicsTextItems)。

我现在想根据它们的边界框和位置以不同的方式分发这些项目。对于我的所有算法,我想使用 CGAL 并将它们与演示文稿完全分离( Qt )。这样做的原因是能够在保持实际算法完整的同时快速切换前端。

我可以从QGraphicsScene获得

的边界框
QGraphicsItem

可以使用CGAL Qt转换器转换为QrectF bb = item->boundingRect();

到目前为止,我的算法函数签名如下:

CGAL::Iso_rectangle_2<Kernel>

在我的前端:

namespace Backend {

template<typename InputIt, typename OutputIt>
OutputIt distribute(InputIt first, InputIt last, OutputIt result);

}

我的想法是扩展我的原始签名,其功能可以像这样提取边界框:

std::vector<QGraphicsTextItem*> items = { 
    addText("gHello"),
    addText("gWorld"),
    addText("g42") };

distribute(begin(items), end(items), back_inserter(output));

然而,这仍然让我在之后更新namespace Backend { template<typename InputIt, typename OutputIt, typename BoundingBox> OutputIt distribute(InputIt first, InputIt last, OutputIt result, BoundingBox bbox) { // ... CGAL::Iso_rectangle_2<Kernel> bb = bbox(*first); // ... } } 位置的问题。如何设计这样的通用算法,以便将其与演示文稿分离?

更新

现在分配的东西真的是简单的矩形操作和转换。然而,目标是产生不同版本的分布,其可以例如包括扫描线或基于力的方法方法。一个关键点是防止不同边界框的重叠。

0 个答案:

没有答案