Click to See Complete Forum and Search --> : multithreading(graphics)
dear sir,
I'm sitaram from bangalore requesting you a solution for my problem on threads.
A graph should be plotted between time (seconds) on x_axis .A thread shoould be activated using multimedia timers for every second,so that it updates a file with 33 columns row wise.The first column is time in seconds(x_coordinate).Each column(y_coordinate) should be plotted as a curve against this time.One of the constraints is that one or more columns can be selected dynamically for plotting through a user interface such as a dialog box.Each curve should be plotted with unique color(this is a must).Simultaneously the file should be updated and the curves are to be plotted.This resembles on_line plotting. Throughout the process the file should be in open mode.The thread starting and stopping should be controlled by the user.There won't be any negative x_values.They exist only for y_values.
Waiting for your early reply for the above problem in vc++5.0 code.My e-mail is mnvsr@hotmail.com.
Harvey Hawes
May 3rd, 1999, 03:26 PM
Hi,
Sounds like you are doing some realtime plotting there. Are you doing the acquisition yourself, or are you reading the data from a pre-made file? (It gets more complicated if you are doing the acquistion too...)
I've written a few programs like this. You have a lot of options:
1) For the plotting, look at some of the samples on this site (in the misc section). They should handle the drawing part of the task. It's not hard to make the different "channels" different colors, or to turn them on or off. What is difficult to do is to make the graph redraw smoothly and quickly. The samples on this site use a memory dc and PolyLine to redraw. You will want to do the same (assuming you can't just use their code directly).
2) If this is to be a done rather quickly, look at buying a commercial graphing control (if you have the money...). Most of them will allow to fill them in a timer callback...
3) I'm assuming that you want to plot only once every second. Is this correct? You might not need to multithread at this speed. The user won't be able to distinguish between once every second and once every 1.01 seconds. A simple window timer may suffice.
4) The idea is that you have a Start and Stop button. When the user hits Start, the timer starts to call a callback function periodically. In the callback, just grab the data from the file, update the new position in the file (for next time), and load the data into your chart control and call Invalidate. Then update the x-point (time) position for next time. If you are using multiple threads, then the callback is in a different thread (but is much more complex). Note: The multimedia timer callback is always in a different thread. Pass it a HWND to your view to pass data... (or a CWnd*, I'm not sure what the consensus is now).
If you have to multithread, and are using the doc/view system. Think about just using the callback to post a message back to the view (i.e. WM_UPDATE_DATA_NOW). This message could contain the updated file position etc. In your View handler of this message (i.e. OnUpdateDataNow()), do all of your drawing. It will be much easier to grab gdi resources in the view class, then to try and do it accross threads. You can use CEvents to signal the other thread that its ok to pass the next data. That way, at high speeds, you don't flood the message queue.
Another tip: Use memory mapped files. This will allow you to access the entire data file as an array. Windows will take care of buffering, postitioning etc. They work well. (See the book "Advanced Windows" for details).
I hope this will help.
Harvey Hawes
Software Engineer
BioScience Analysis Software Ltd.
Masters Candidate
Cardiovascular/Respiratory Sciences
Faculty of Medicine
University of Calgary
Calgary, Alberta, Canada
Lyu ABE
June 22nd, 1999, 09:05 PM
Hi,
If you need help with multi-threading for this kind of process, you can try to ask. I have written a real-time acquisition program working with worker threads (including timing control, message posting, main view updating, etc)...
If I can help...
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.