使用OpenGL在C ++中绘制具有大量数据点的散点图的最佳方法 [英] Best way to draw scatter plot with lots of data points in C++ using OpenGL

查看:1184
本文介绍了使用OpenGL在C ++中绘制具有大量数据点的散点图的最佳方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在用C ++编写一个程序,该程序通过UDP套接字获取4维点数据,然后将数据绘制在6个单独的2D散点图中.例如,如果我们将尺寸命名为:A,B,C,D,则六个二维图将为AxB,AxC,AxD,BxC,BxD和CxD.在几个小时的过程中,该程序累积了约5万个积分.

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.

我已经考虑过为每个坐标系维护一个顶点数组(具有2个维),但这将需要6个单独的数组,并且需要的内存是维护所有4个维的数组的3倍.

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?

推荐答案

使用顶点缓冲区对象可以提高渲染速度,因为要绘制的几何图形可以直接存储在图形卡内存中.但是,在您的情况下,如果数据始终更改,则我无法告诉您此方法是否比立即模式更快,因为每次数据更改时您都必须重新构造顶点数组对象".如果仅添加点,则可能可以制作多个VBO来对点进行分组,并使用即时模式渲染最后收到的点,直到可以创建新的组为止.例如,如果您获得了100054分,那么也许您可以进行10组10000分,并在即时模式下渲染最后的54分.

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.

关于内存问题,我认为可能会在图形卡顶点中存储4个元素-然后可以使用不同的顶点着色器,这些顶点着色器选择要用作渲染坐标的顶点分量.使用这种技术,内存使用量将仅为您收到的内存使用量的两倍:一个用于接收数据,一个用于顶点缓冲区对象.

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.

这篇关于使用OpenGL在C ++中绘制具有大量数据点的散点图的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆