从规则间隔的数据生成轮廓线
我目前正在从事一个数据可视化项目。我的目标是从网格数据中生成等高线,即等值线。数据可以是温度、天气数据或任何其他环境参数,但唯一的条件是它必须是有规律地间隔。 我在互联网上搜索,但是我找不到一个好的算法、伪代码或源代码来从网格生成轮廓线。 有人知道从网格数据生成等高线的库、源代码或算法吗? 如果您的建议具有良好的运行时性能,那就太好了,我不想让我的用户等得太久:)
编辑:感谢您的回复,但等值线有一些限制,比如它们不应该相交 所以仅仅生成贝塞尔曲线并不能实现我的目标。
I am currently working on a data visualization project.My aim is to produce contour lines ,in other words iso-lines, from gridded data.Data can be temperature, weather data or any kind of other environmental parameters but only condition is it must be regularly spaced.
I searched in internet , however i could not find a good algorithm, pseudo-code or source code for producing contour lines from grids.
Does anybody knows a library, source code or an algorithm for producing contour lines from gridded data?
it will be good if your suggestion has a good run time performance, i don't want to wait my users so much :)
Edit: thanks for response but isolines have some constrains like they should not intersects
so just generating bezier curves does not accomplish my goal.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
请参阅此问题:如何从高程栅格?
它几乎是重复的,但使用了完全不同的术语。 您会发现制图学和计算机图形学解决了许多相同的问题,但使用不同的术语。
See this question: How to approximate a vector contour from an elevation raster?
It's a near duplicate, but uses quite different terminology. You'll find that cartography and computer graphics solve many of the same problems, but use different terminology for them.
GNUplot 中提供了一些相当不错的轮廓 - 如果您能够使用可能有帮助的 GPL 代码。
there's some reasonably good contouring available in GNUplot - if you're able to use GPL code that may help.
如果您的数据定期放置,那么这可以相当容易地完成(假设我正确理解您的问题)。 首先,您需要确定轮廓的间隔时间。 接下来创建将用于存储等高线信息的网格(我假设只是在此等高线级别数据类型上进行简单的开/关或高程),该网格应该比源数据小一个间隔。
现在这里的技巧是将 2 个网格偏移 1/2 个间隔(实际上不会显示在这样的代码中,但它是我在这里处理的概念)并比较当前点周围的 4 个坐标您正在计算的等高线数据网格。 如果 4 个点中的任何一个位于不同的间隔范围内,则等高线网格中的“像素”应设置为 true(或被交叉的等高线范围的值)。
使用这种方法会出现一个问题,当间隔太细时,会导致多个轮廓相互重叠。
If your data is placed at regular intervals, this can be done fairly easily (assuming I understand your problem correctly). First you need to determine at what interval you want your contours. Next create the grid you are going to use to store the contour information (i'm assuming just a simple on/off or elevation at this contour level type of data), which should be one interval smaller than the source data.
Now the trick here is to offset the 2 grids by 1/2 an interval (won't actually show up in code like this, but its the concept I'm dealing with here) and compare the 4 coordinates surrounding the current point in the contour data grid you are calculating. If any of the 4 points are in a different interval range, then that 'pixel' in the contour grid should be set to true (or the value of the contour range being crossed).
With this method, there will be a problem when the interval is too fine which will cause several contours to overlap onto each other.
正如 Paul Tomblin 的链接所暗示的那样,贝塞尔曲线(B 样条曲线的子集)是解决您的问题的成熟解决方案。 如果运行时性能是一个问题,贝塞尔曲线还有一个额外的好处,那就是可以通过非常快的 de Casteljau 算法来构造,而不是根据参数方程来绘制它们。 如果您使用 DirectX,它有一个用于 de Casteljau 的库函数,但使用描述它的 1001 个网页自行编写一个库函数应该不成问题。
As the link from Paul Tomblin suggests, Bezier curves (which are a subset of B-splines) are a ripe solution for your problem. If runtime performance is an issue, Bezier curves have the added benefit of being constructable via the very fast de Casteljau algorithm, instead of drawing them according to the parametric equations. On the off chance you're working with DirectX, it has a library function for the de Casteljau, but it should not be challenging to brew one yourself using the 1001 web pages that describe it.