Re: How to make the lines smooth using wxDC

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Re: How to make the lines smooth using wxDC

Post by nandakishore »

I have attached two graph images. I am using wxDC to draw these lines in the graph. My problem is, the drawn lines are not clear enough. They have some disturbance as you can see
smooth1.jpg
when compared to the other graph
smooth.jpg
. What should I be doing in order to make these lines more sharper?
Got a Problem???..No worry..Focus on Solution not on Problem :P
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: How to make the lines smooth using wxDC

Post by iwbnwif »

Please could you provide a close up image to show the 'disturbances' that you mention.

Also, have you drawn both graphs using wxDC - what exactly is the comparison that is being made with these two images?

There seems to be a bit of difference in the anti-aliasing, but I am not sure if this is your program or the screenshot software, browser etc. If your lines are drawn with anti-aliasing then you must be using wxGCDC instead of wxDC.

Out of interest, how are you smoothing your data - are there a large number of data points or do you have a smoothing algorithm?
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
nandakishore
Experienced Solver
Experienced Solver
Posts: 57
Joined: Wed Feb 25, 2015 2:09 pm
Location: Chennai, India

Re: How to make the lines smooth using wxDC

Post by nandakishore »

I have highlighted the aliased line in the image below for your reference.
Capture.PNG
Capture.PNG (42.71 KiB) Viewed 2178 times

Also, have you drawn both graphs using wxDC - what exactly is the comparison that is being made with these two images?
I compared my output with a competing software. Only the first graph was drawn by me using wxDC. The comparison is the smoothing of the lines. My graph lines look aliased.
There seems to be a bit of difference in the anti-aliasing, but I am not sure if this is your program or the screenshot software, browser etc. If your lines are drawn with anti-aliasing then you must be using wxGCDC instead of wxDC.
The disturbance which I was talking about is the aliasing. I wanted my graph lines to be smoother like in the second image.
Out of interest, how are you smoothing your data - are there a large number of data points or do you have a smoothing algorithm?
I am not using any smoothing algorithm. The smooth lines are from a different software which I used to compare my output with.
Got a Problem???..No worry..Focus on Solution not on Problem :P
iwbnwif
Super wx Problem Solver
Super wx Problem Solver
Posts: 282
Joined: Tue Mar 19, 2013 8:52 pm

Re: How to make the lines smooth using wxDC

Post by iwbnwif »

Thanks, that is much clearer!

In order to have aliased lines, you can simply create a wxGCDC from your wxWindowDC or wxMemoryDC as follows:

Code: Select all

wxGCDC gdc(dc);
Then draw to gdc using exactly the same code as you do now.

I have been working on a lot of updates to wxFreeChart here. I found that it is best to draw the grid and text labels using the original wxMemoryDC and then the lines that need anti-aliasing (i.e. the curves) on top. That keeps the grid nice and crisp and avoids 'double anti-aliasing' the text (which seems to occur with wxGCDC).

Unfortunately, my project has taken a bit of a back seat for now. But I hope to restart again later in Autumn.

What I meant about smoothing is a kind of rounding of the data. Consider the following two crude examples:
sine_smoothed.png
sine_smoothed.png (9.69 KiB) Viewed 2171 times
sine_raw.png
sine_raw.png (8.64 KiB) Viewed 2171 times
The second image interpolates the data points to provide a smooth curve. This is done in Excel, but I would also like to add this function to my version of wxFreeChart. Your chart appears to have smoothed the data in the same way because there are no sharp angles at major direction changes.
wxWidgets 3.1.2, MinGW64 8.1.0, g++ 8.1.0, Ubuntu 19.04, Windows 10, CodeLite + wxCrafter
Some people, when confronted with a GUI problem, think "I know, I'll use Eclipse RCP". Now they have two problems.
Post Reply