Discussion:
High spped drawing with MFC is it possible?
(too old to reply)
Electronic75
2006-07-06 07:27:02 UTC
Permalink
Hello, I have an application that receives data from an instrument and plots
it in form of an X vs. Y plot. Amount of data which is stored in a vector in
ram is relatively high (usually about a few millions points). The problem
that I have is whenever window needs update it takes considerable time for
window to redraw(even on a very fast computer) and it can be frustrating for
user. Data drawing function first calculates the location of point on screen
then uses pDC->LineTo() and pDC->MoveTo() functions to draw the plot. Well,
because of amount of data many points will overlap. When I modified the
algorithm so that it first determines whether a point overlaps other points
and if it does, skip this point then performance improved but still not
satisfactory. My question is, whether I should use DirectX for this
application(which I think will be very difficult to learn) or it is possible
to get a satisfactory result with modifying drawing algorithm. Some programs
like LabView have a very smooth drawing with no blinking even with huge
amount of data. I wonder whether they use DirectX. Another question does it
make a significant difference if I write this application using ATL rather
than MFC. Thank you in advance.
Scott McPhillips [MVP]
2006-07-06 12:57:12 UTC
Permalink
Post by Electronic75
Hello, I have an application that receives data from an instrument and plots
it in form of an X vs. Y plot. Amount of data which is stored in a vector in
ram is relatively high (usually about a few millions points). The problem
that I have is whenever window needs update it takes considerable time for
window to redraw(even on a very fast computer) and it can be frustrating for
user. Data drawing function first calculates the location of point on screen
then uses pDC->LineTo() and pDC->MoveTo() functions to draw the plot. Well,
because of amount of data many points will overlap. When I modified the
algorithm so that it first determines whether a point overlaps other points
and if it does, skip this point then performance improved but still not
satisfactory. My question is, whether I should use DirectX for this
application(which I think will be very difficult to learn) or it is possible
to get a satisfactory result with modifying drawing algorithm. Some programs
like LabView have a very smooth drawing with no blinking even with huge
amount of data. I wonder whether they use DirectX. Another question does it
make a significant difference if I write this application using ATL rather
than MFC. Thank you in advance.
Scale the data into an array of x,y CPoint's. Since the screen is not
millions of pixels wide reduce the dimension to something the screen can
display. Then pass the array to pDC->PolyLine. Much faster!
--
Scott McPhillips [VC++ MVP]
David Lowndes
2006-07-06 13:04:20 UTC
Permalink
Post by Electronic75
that I have is whenever window needs update it takes considerable time for
window to redraw(even on a very fast computer) and it can be frustrating for
user. Data drawing function first calculates the location of point on screen
then uses pDC->LineTo() and pDC->MoveTo() functions to draw the plot. Well,
because of amount of data many points will overlap. When I modified the
algorithm so that it first determines whether a point overlaps other points
and if it does, skip this point then performance improved but still not
satisfactory.
So, how many lines are you actually drawing with your refined
algorithm? Have you tried using PolylineTo rather than drawing them
all individually?

I suspect that you need to profile your application to determine where
the lack of speed derives from - it may not be in the drawing itself
since you indicate that your improved algorithm hasn't made a
substantial difference.

Dave
Electronic75
2006-07-06 15:35:27 UTC
Permalink
Thanks alot Scott and David! this newsgroup is really helpful. it is about a
few hundreds of lines, sometimes even many lines ovelap completely. I will
use Polyline(I have not tried it). scott's suggestion to put calculated
values of X, Y in yet another vector and drawing the latter instead of raw
data is very sound and logical and can improve performance even more. in some
microcontroller compilers when you program with C it is possible to simulate
the code and measure actual time spended in any segment of code. this is an
extremely valuable debug tool which reveals some naughty bugs that are
difficult to detect otherwise. to the best of my knowledge there is no such a
tool in windows programing. you are right problem can be somewhere else.
Thanks again!
Post by David Lowndes
Post by Electronic75
that I have is whenever window needs update it takes considerable time for
window to redraw(even on a very fast computer) and it can be frustrating for
user. Data drawing function first calculates the location of point on screen
then uses pDC->LineTo() and pDC->MoveTo() functions to draw the plot. Well,
because of amount of data many points will overlap. When I modified the
algorithm so that it first determines whether a point overlaps other points
and if it does, skip this point then performance improved but still not
satisfactory.
So, how many lines are you actually drawing with your refined
algorithm? Have you tried using PolylineTo rather than drawing them
all individually?
I suspect that you need to profile your application to determine where
the lack of speed derives from - it may not be in the drawing itself
since you indicate that your improved algorithm hasn't made a
substantial difference.
Dave
v***@feinsoftware.com
2006-07-06 22:41:31 UTC
Permalink
...it is about a few hundreds of lines, sometimes even many lines ovelap completely...
Did you consider "purging" your vector? Can you remove duplicate
points, or not even insert them in the first place?
Electronic75
2006-07-07 02:54:02 UTC
Permalink
Hello, there are no duplicate points, user determines how many points he
would like to gather. sometimes he is interested in events that may happen in
a very short time (about 1ms) and instrument will send data to computer
accordingly(every 1ms), but many experiments last many hours and rarely even
days, so amount of data could be huge but all of points are unique(at least
in having different times). the problem is sometimes user wants to see many
hours of data in one graph(millions of points) ; in such case obviously many
points will overlap each other, sometimes user interested in a very narrow
time scale and with zoom tool he enlarges one area (for example 50ms, then
the whole plot is about only 50 points and points won't overlap). so all of
data is necessary and to implement scott's good suggestion I have to
reconstitue drawing vector every time user uses scale tool.
data will remain in ram until user saves it and order for a new experiment
so vectors won't be purged. I had some experiments with LabView from National
Instruments, it is amazingly fast even with huge amount of data. I wonder is
it DirectX magic or a very efficient algorithm.
Post by v***@feinsoftware.com
...it is about a few hundreds of lines, sometimes even many lines ovelap completely...
Did you consider "purging" your vector? Can you remove duplicate
points, or not even insert them in the first place?
Loading...