动态图形与OpenGL在Android的绘制 [英] Dynamic Graph Plotting with openGL in Android

查看:526
本文介绍了动态图形与OpenGL在Android的绘制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从一个蓝牙设备绘制实时数据。我有一个蓝牙设备的手机将连接并读取来自它的数据。该数据是从一些传感器电压电平并具有每秒300个样本的采样率。大部分的绘图库(比如aiChart,Androidplot,achartengine,...)我见过无法处理的数据量,并重新绘制图表。所以,我看着的openGL和Android NDK,似乎我也许可以利用这些任何一个与采样率我要图。是否有人在样本code的OpenGL线图绘制中的Andr​​oid / Java和/或NDK code样?

I want to plot real time data from a bluetooth device. I have a Bluetooth device that the phone will connect to and read the data coming from it. The data is voltage levels from some sensors and having a sample rate of 300 samples per sec. Most of the plotting libs(like aiChart, Androidplot, achartengine,...) I have seen can't handle that amount of data and repainting the graph. So I looked into openGL and Android NDK and it seems that I might be able to graph using either one of these with the sample rates I have. Does anyone have a sample code for openGL line graph plotting in android/Java and/or NDK code sample?

推荐答案

我们做了这样的事情只是通过创建多页点阵列类,并在OpenGL与偏移,因此当前点总是在同一个地方。绘图

We did something like this simply by creating a point array class with several pages and drawing in opengl with offset so the current point is always in the same place.

这个想法使用固定大小的数组与一个独立的计数器这样你就不会打的内存页头问题,这将导致GC一命呜呼。一旦页面已满,循环到下一个页面显示旧的为好。我们的想法是,如果你有5页,你可以写一个,显示其它3和批量写入最后一个sqlite的上SD卡在一个单独的线程,所以你可以拉所有的数据出来以后。

The idea use fixed size arrays with a separate counter so you aren't hitting memory alloc issues which would cause gc to kick in. Once a page is full, cycle to the next page displaying the old as well. The idea is that if you have 5 pages, you can write to one, display the other 3 and batch write the last one to sqlite on an sdcard in a seperate thread so you can pull all the data out later on.

只要你只能有一个线程写入到阵列中,你可以逃脱像

As long as you only have one thread writing to the array you can get away with something like

arrayPoint[] p;
....
int currentPos = 0;
arrayPoint current = p[currentPos];

..... 
while(....

if(current.end < current.max)
{
      .... get datax and datay
     current.end++;
     current.x[current.end] = datax;
     current.y[current.end] = datay;
}
else
{
     currentPos = getNextPos();
     current = p[currentPos];
     current.end = -1; // truncate the array without actually freeing or allocating mem
     ..... flip volatile bool to let other thread know its ok to get exclusive access to its data etc      
}

它的速度非常快,应该做你所需要的。然后,您可以为画布上的一个点或输出绘制的OpenGL ES

Its very fast and should do what you need. You can then output as a point on a canvas or draw in opengl es

希望有所帮助。

这篇关于动态图形与OpenGL在Android的绘制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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