Re: Scigraphica-gtkextra digest, Vol 1 #486 - 1 msg
Fabio da Silva <[email protected]> Mon, 27 Feb 2006 11:22:03 -0700
| Newsgroups | gmane.comp.scigraphica.gtkextra |
|---|---|
| Message-ID | <[email protected]> |
Hi there, I agree with Al. allocating points dynamically is not that painful or computer intensive. However if you absolutely don't want to change the size of your array dynamically and are plotting points that are connected somehow, you will have to fill up the memory area that is not used with the x-y values of the latest measurement point. This is to avoid the annoyance of seeing the connecting line go to some random place in the screen after the last point is measured. Now, realize that this means you will have to access the memory to write your points N*N times for every cycle. N is the number of points you are statically allocating. Soon enough you will find out that this solution will bog your application down quite a bit. I hope this helps, Fabio. On Sat, 2006-02-25 at 20:41 -0800, [email protected] wrote: > Send Scigraphica-gtkextra mailing list submissions to > [email protected] > > To subscribe or unsubscribe via the World Wide Web, visit > https://lists.sourceforge.net/lists/listinfo/scigraphica-gtkextra > or, via email, send a message with subject or body 'help' to > [email protected] > > You can reach the person managing the list at > [email protected] > > When replying, please edit your Subject line so it is more specific > than "Re: Contents of Scigraphica-gtkextra digest..." > > > Today's Topics: > > 1. Re: Using fixed-size data buffer with GtkPlot (Al Hooton) > > --__--__-- > > Message: 1 > Subject: Re: [gtkextra] Using fixed-size data buffer with GtkPlot > From: Al Hooton <[email protected]> > To: Nickolai Dobrynin <[email protected]> > Cc: [email protected] > Date: Sat, 25 Feb 2006 06:28:55 -0800 > > Nickolai, > > On Wed, 2006-02-22 at 23:42 -0600, Nickolai Dobrynin wrote: > > 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. > > So, if I understand you correctly, you want to have an ever-growing > number of points plotted, but every so often you want to throw away the > points you've already plotted and start over with a clean plot? > > Or, do you want to have an unknown number of points plotted as they > come in, but you do not want to manage the memory for them dynamically? > > Or... ? I'm not sure I understand the question... > dynamically-managing the dataset memory is easy, but are you concerned > about performance? If this is the case, don't worry -- the plotting > machinery will take far more cycles than dynamically reallocating > arrays, etc. > > > > > 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); > > > > It's been a while since I looked at my code that uses gtkplot, but try > this here and see what happens: > > gtk_plot_data_set_numpoints(dataset, 0); > gtk_plot_refresh(plot, NULL); > > > > > > 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 > > !DSPAM:43fd4bb636596333719912! > > > > > --__--__-- > > _______________________________________________ > Scigraphica-gtkextra mailing list > [email protected] > https://lists.sourceforge.net/lists/listinfo/scigraphica-gtkextra > > > End of Scigraphica-gtkextra Digest > ------------------------------------------------------- This SF.Net email is sponsored by xPML, a groundbreaking scripting language that extends applications into web and mobile media. Attend the live webcast and join the prime developer group breaking into this new coding territory! http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642