用于读取和写入矢量图形的库 - 轮询 x,y 的颜色
我正在实现路径规划算法。我真的很希望能够以矢量图形(svg)格式加载二维“环境”,以便可以使用复杂的障碍物。这也使得将路径覆盖到环境中并导出包含算法结果的另一个文件变得相当容易。
我希望能够做的是在我的碰撞测试方法中使用某种库,这样我就可以简单地问“x、y 处是否有障碍物?”并返回 true 或 false。当然,我希望能够将路径本身添加到文件中。
简短的搜索和几次下载给我留下了一些库,这些库要么创建 svg,要么渲染它们,但没有一个真正给我我需要的东西。我是否最好只解析 xml 并手动破解所有内容?这看起来像是浪费了很多精力。
I'm doing an implementation for a path planning algorithm. I'd really like to be able to load in a 2d "environment" in vector graphics (svg) format, so that complex obstacles can be used. This would also make it fairly easy to overlay the path onto the environment and export another file with the result of the algorithm.
What I'm hoping to be able to do is use some kind of library in my collision test method so that I can simply ask, "is there an obstacle at x, y?" and get back true or false. And then of course I'd like to be able to add the path itself to the file.
A brief search and a couple of downloads left me with libraries which either create svg's or render them but none really gave me what I need. Am I better off just parsing the xml and hacking through everything manually? That seems like a lot of wasted effort.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
1.这可能有点粗暴,但 Qt 有一套非常出色的工具,称为图形视图框架。使用这些工具,您可以在 QGraphicsScene 中创建一堆 QGraphicsItems(多边形、路径等),然后通过给定位置来查询场景。使用此功能,您实际上不必将场景渲染为光栅位图。
http://doc.trolltech.com/4.2/graphicsview.html,http://doc.trolltech.com/4.2/qgraphicsscene.html#itemAt
2.开罗也有绘制各种形状的工具,但我相信您必须渲染整个图像,然后检查像素值。 http://cairgraphics.org/
1.This may be a bit heavyhanded, but Qt has a really great set of tools called the Graphics View Framework. Using these tools, you can create a bunch of QGraphicsItems (polygons, paths, etc..) in a QGraphicsScene, and then query the scene by giving it a position. Using this you'll never actually have to render the scene out to a raster bitmap.
http://doc.trolltech.com/4.2/graphicsview.html, http://doc.trolltech.com/4.2/qgraphicsscene.html#itemAt
2.Cairo has tools to draw all sorts of shapes as well, but I believe you'll have to render the whole image and then check the pixel values. http://cairographics.org/
SVG 规范包括一些用于碰撞检测的 DOM 接口:
使用这些方法,所有“障碍”(可以是组)原始元素(使用
元素)应标记为指针事件的目标。然而,这些方法是基于边界框的,因此可能不够复杂,无法满足您的要求。
The SVG specification includes some DOM interfaces for collision detection:
Using these methods, all "obstacles" (which can be groups of primitive elements, using the
<g>
element) should be labelled as a target of pointer events.These methods are bounding-box based, however, so may not be sophisticated enough for your requirements.
感谢您的回复。我没能在 QT(它太大了!)或 Cairo 中运行任何东西,最后我选择了 PNGwriter,它几乎可以完成我想要的功能,当然,除了它读取和写入 PNG 而不是矢量图形。这里的缺点是我的坐标必须四舍五入为偶数像素。也许我会继续研究矢量图形,但这个解决方案对于这个项目来说是令人满意的。
Thanks for the responses. I didn't manage to get anything working in QT (it's massive!) or Cairo, and I ended up going with PNGwriter, which does pretty much what I wanted except, of course, that it reads and writes PNG's instead of vector graphics. The downside here is that my coordinates must be rounded off to even pixels. Maybe I'll continue to look into vector graphics, but this solution is satisfactory for this project.