在 C++ 中绘制具有大量数据点的散点图的最佳方法使用OpenGL
我正在用 C++ 编写一个程序,该程序通过 UDP 套接字获取 4 维点数据,然后将数据绘制在 6 个独立的 2D 散点图中。例如,如果我们将维度命名为:A、B、C、D,则六个 2d 图将是 AxB、AxC、AxD、BxC、BxD 和 CxD。在几个小时内,该计划累积了约 50K 积分。
目前,我使用即时模式将每个点绘制一次。我不会清除绘制调用之间的缓冲区,因此之前绘制的点将持续存在,直到缓冲区被清除为止。我对这种方法不满意,因为立即模式很慢并且已被弃用。当我必须清除缓冲区时,例如当窗口调整大小时,我会丢失所有先前绘制的数据。我想提出一个解决方案,允许在清除缓冲区后保留数据。此外,如果绘图也可以通过调整窗口大小来轻松缩放,那就太好了。
我考虑过为每个坐标系维护一个顶点数组(2 维),但这需要 6 个独立的数组,并且需要 3 倍于维护所有 4 维数组的内存。
我是否以正确的方式思考这个问题?这个问题的正确解决方案是什么?
最终目标是拥有一个尽可能接近实时地显示数据的应用程序。
编辑是否可以在点进入时继续逐个绘制点,并且当我需要调整屏幕大小时抓取屏幕图像,然后显示该图像的调整大小版本?
I'm writing a program in C++ that acquires 4 dimensional points data over a UDP socket and then plots the data in 6 separate 2D scatter plots. For example if we name the dimensions: A,B,C,D the six 2d plots would be AxB, AxC, AxD, BxC, BxD, and CxD. Over the course of a few hours the program accrues ~50K points.
Currently I plot each point once, using immediate mode. I don't clear the buffer between draw calls so previously plotted points persist until the buffer is cleared. I'm not happy with this method as immediate mode is slow and deprecated. When I have to clear the buffer, as when a window re-sizes, I lose all previously plotted data. I'd like to come up with a solution that allows data persistence after the buffer is cleared. Additionally it would be nice if the plot could be easily scaled with window re-sizes as well.
I've thought about maintaining a vertex array (with 2 dimensions) for each coordinate system but that would require 6 separate arrays and require 3 times the memory of maintaining an array with all 4 dimensions.
Am I thinking about this in the right way? What is the proper solution to this problem?
The end goal is to have an application that displays the data as close to real-time as possible.
Edit Would it be possible to continue plotting the points one by one as they come in, and when I need to resize the screen grab an image of the screen and then display a resized version of that image?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用顶点缓冲区对象可以提高渲染速度,因为要绘制的几何图形可以直接存储在图形卡内存中。但是,在您的情况下,如果数据总是发生变化,我无法告诉您此方法是否会比立即模式更快,因为每次数据更改时您可能都必须重建顶点数组对象。如果您只添加点,也许您可以制作多个VBO来对点进行分组,并使用立即模式渲染最后接收到的点,直到您可以创建新组为止。例如,如果您收到了 100054 个点,也许您可以制作 10 组,每组 10000 个点,并以立即模式渲染最后 54 个点。
关于内存问题,我认为可以在显卡中存储 4 个元素的顶点 - 然后您可以使用不同的顶点着色器来选择顶点的哪些组件用作渲染坐标。使用这种技术,内存使用量只会是您收到的内存使用量的两倍:一个用于您接收的数据,另一个用于顶点缓冲区对象。
Using Vertex buffer Objects can increase speed rendering, because the geometry to draw can be stored directly in the graphic card memory. However, in your case, if the data always changes, I cannot tell you if this method will be faster than immediate mode because you may have to reconstruct the Vertex Array Object each time the data change. If you only add points, maybe you can make multiple VBOs to group points, and render the last received points using immediate mode until you can create a new group. For instance, if you received 100054 points, maybe you can make 10 groups of 10000 points and render the last 54 points in immediate mode.
Concerning the memory problem, I think it might be possible to store in the graphic card vertexes with 4 elements - then you could use different vertex shaders which select which components of your vertex to use as rendering coordinates. Using this technique, memory usage would only be twice what you received: one for you received data, and one for the vertex buffer object.