Re: plot data stream in realtime
- From: Matt Flax <flatmax flatmax org>
- To: gtkdatabox-list gnome org
- Subject: Re: plot data stream in realtime
- Date: Thu, 15 Nov 2012 13:13:59 -0600
OK . now I see this post... slipped by me at first.
I am open to the idea of removing the static type associated with the
gtkdatabox vectors.
That is probably a good idea.
Currently we use the gtk_databox_values_to_pixels function to convert to
pixel locations on the pixmaps ... I guess that would need addressing ?
Matt
On 11/12/2012 08:32 PM, Amish S. Dave wrote:
Just some thoughts on this topic. Basically, it gets at the idea of
trying to handle different representations for the input data. This is
assumed to be representable by static arrays of gfloats. That's fine,
but it means that all applications that don't start with that
representation need to adapt their representation to what gtkdatabox
wants.
It should be fairly straightforward to implement a slightly different
scheme that could allow the inputs arrays to be
1. the current linear arrays [x0 x1 x2 .. xn] [y0 y1 y2 .. yn]
2. represent a ring-buffer e.g. [xn-1 xn x0 x1 x2 ... xn-2]
3. dynamically growing arrays
4. interleaved X&Y values [x0 y0 x1 y1 x2 y2 ... xn yn]
I'm thinking of something like this:
gtk_databox_graph_data_update(graph, int XYallocpts, void *X, void *Y,
int startpt, int numpts, int xstridebytes, int ystridebytes, GType
XYdatatype);
If this function is never called, backwards compatibility is assured
by assuming that
XYdatatype == G_TYPE_FLOAT;
xstridebytes = ystridebytes = sizeof(float);
startpt = 0;
numpts = XYallocpts
But, if this function *is* called, the graph replaces the existing X
and Y with the new pointers, and it forces a redraw, and updates any
rulers as needed.
For the example of a realtime plot of something where new data is
coming in and the graph is adding points to the rightward end, the
calling program could allocate an array at the beginning large enough
to hold the final size (XYallocpts), but by calling this function
periodically with numpts incremented to reflect number of points
currently available, it would have the effect of adding new data to
the right of the screen. No new allocations, and no unnecessary
copying of arrays.
If you wanted to scroll the data, you could keep numpts fixed once it
reached your number_of_points_to_graph, and then start incrementing
startpt such that the most recently acquired point was startpt +
numpts - 1...
If you need to realloc() a larger array, then this function will note
the change in the XYallocpts value, or the X or Y pointers, and
realize that new arrays are being passed...
If the arrays were actually ring buffers, then calling
...
gtk_databox_graph_data_update(ptsgraph, 10, Xpts, Ypts, 0, 10,
sizeof(float), sizeof(float), G_TYPE_FLOAT);
Ypts[9] = get_data_from_adc();
gtk_databox_graph_data_update(ptsgraph, 10, Xpts, Ypts, 1, 10,
sizeof(float), sizeof(float), G_TYPE_FLOAT);
Ypts[0] = get_data_from_adc();
gtk_databox_graph_data_update(ptsgraph, 10, Xpts, Ypts, 2, 10,
sizeof(float), sizeof(float), G_TYPE_FLOAT);
Ypts[1] = get_data_from_adc();
gtk_databox_graph_data_update(ptsgraph, 10, Xpts, Ypts, 3, 10,
sizeof(float), sizeof(float), G_TYPE_FLOAT);
Ypts[2] = get_data_from_adc();
...
shows 10 points each time but the latest point is always on the right
of the graph. The X Axis could be kept constant, or the application
could update it if so desired by modifying Xpts[x].
This scheme is also an opportunity to add support for types other than
float... I'd suspect most of the time, GtkDatabox is being grafted
onto another already developed application that has it's own data
representations. It's annoying to have to convert
doubles/ints/whatever to floats for example. Most of what needs to be
done to support non-float data is in one function:
gtk_databox_values_to_pixels... and the modification is not hard.
What do people think?
Sincerely,
--
Amish
On 11/12/2012 02:30 PM, Johannes Deutsch wrote:
Hi all,
I'm very thankful for all of your echos. I received interesting
suggestions and was particularly pleased that the mailing list is very
active!
I already wrote a little demo that simulates plotting of data in
realtime. By now the code is messy but i will pretty it up
tomorrow and post i on this list.
Maybe it is a valid example. If not i would be thankful for any
comments to improve it further...
With best regards and thanks for this great project
_______________________________________________
gtkdatabox-list mailing list
gtkdatabox-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkdatabox-list
_______________________________________________
gtkdatabox-list mailing list
gtkdatabox-list gnome org
https://mail.gnome.org/mailman/listinfo/gtkdatabox-list
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]