Using fixed-size data buffer with GtkPlot
"Nickolai Dobrynin" <[email protected]> Wed, 22 Feb 2006 23:42:56 -0600
| Newsgroups | gmane.comp.scigraphica.gtkextra |
|---|---|
| Message-ID | <[email protected]> |
I'm just starting with GtkExtra, and, probably like everybody else on this
list, having troubles learning
the API. I would like to be able to append points and plot them one at a
time, which is pretty much
what the 'testrealtime' example does. The additional constraint I have is
that, unlike 'testrealtime', I
cannot store data points in a dynamically allocated buffer and let this
buffer grow indefinitely.
Here is the 'update' function I call to add a single point to the plot,
while using two C-style arrays:
#define NPOINTS 5000
gint runningCount;
gdouble px[NPOINTS];
gdouble py[NPOINTS];
gboolean update(gpointer)
{
gdouble x,y;
getPoint(runningCount,x,y);
gdouble xmin, xmax; /* [xmin,xmax) */
gtk_plot_get_xrange(plot, &xmin, &xmax);
if (runningCount >= NPOINTS) {
runningCount = 0;
px[0] = x; py[0] = y;
gtk_plot_set_xrange(plot, xmin + 2*M_PI, xmax + 2*M_PI);
gtk_plot_data_set_numpoints(dataset, 1);
gtk_plot_data_dimension_set_points(dataset, "x", px);
gtk_plot_data_dimension_set_points(dataset, "y", py);
gtk_plot_data_draw_points(dataset, 1);
gtk_plot_canvas_paint(GTK_PLOT_CANVAS(canvas));
gtk_widget_queue_draw(GTK_WIDGET(canvas));
}
else {
px[runningCount] = x; py[runningCount] = y;
gtk_plot_data_set_numpoints(dataset, dataset->num_points+1);
gtk_plot_data_draw_points(dataset, 1);
gtk_plot_refresh(plot, NULL);
}
++runningCount;
return TRUE;
}
Unfortunately, I only get meaningful results until the predicate in the
if-statement
becomes true. After that, I don't see anything being plotted at all. Is
there any
way to force the widget to "forget" the previous data I fed to it and start
from
scratch? Once again, my goal is to use a fixed-size array to store data
points,
so I wouldn't have to worry about allocating memory on demand.
Many thanks,
Nickolai