Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Interface and Graphics > Drawing Smoothed Line


Reply
 
Thread Tools Display Modes
  #1  
Old 12-28-2004, 12:42 AM
Aknod Aknod is offline
Newcomer
 
Join Date: Nov 2004
Location: Ukraine, LD
Posts: 18
Default Drawing Smoothed Line


Is it possible to draw a smoothed line with standart GDI methods and without using any images? Is it possible at all?
Does anybody have an example of such method?
Thanks.
Reply With Quote
  #2  
Old 12-28-2004, 04:29 AM
eXeption's Avatar
eXeption eXeption is offline
Junior Contributor
 
Join Date: Aug 2004
Location: India
Posts: 270
Default

I've already posted an implimentation of Wu algorithm to antialias curves/Straight lines.
Antialiasing in pure VB
'
HK
__________________
"I think; therefore I am."
Reply With Quote
  #3  
Old 12-29-2004, 02:02 AM
Aknod Aknod is offline
Newcomer
 
Join Date: Nov 2004
Location: Ukraine, LD
Posts: 18
Default

Thanks you eXeption. The example is pretty good and usefull for me. Is it possible to reconstruct the LineAA function a little so that it could draw lines with defined strength?
I tried this (a part of LineAA):
Code:
 
            Dim ix as integer
            For loopc = start To finish
                AlphaBlendPixel hdc, CInt(dx - 0.5), loopc, LR, LG, LB, 1 - FracPart(dx)
                for ix = 1 to LineStrength
                   AlphaBlendPixel hdc, CInt(dx - 0.5) + ix, loopc, LR, LG, LB, FracPart(dx)
                next ix
                AlphaBlendPixel hdc, CInt(dx - 0.5) + ix + 1, loopc, LR, LG, LB, 1 - FracPart(dx)
                dx = dx + dydx
            Next loopc
where LineStrength is a new function parameter that defines how fat the line will be.
But it does not seem to work propper. Could you help me with that, please.
__________________
Mr. Zorg: What doesn't kill ya, makes ya stronger!
Reply With Quote
  #4  
Old 12-29-2004, 05:33 AM
eXeption's Avatar
eXeption eXeption is offline
Junior Contributor
 
Join Date: Aug 2004
Location: India
Posts: 270
Default

Quote:
Originally Posted by Aknod
Thanks you eXeption. The example is pretty good and usefull for me. Is it possible to reconstruct the LineAA function a little so that it could draw lines with defined strength?
I tried this (a part of LineAA):
Code:
 
            Dim ix as integer
            For loopc = start To finish
                AlphaBlendPixel hdc, CInt(dx - 0.5), loopc, LR, LG, LB, 1 - FracPart(dx)
                for ix = 1 to LineStrength
                   AlphaBlendPixel hdc, CInt(dx - 0.5) + ix, loopc, LR, LG, LB, FracPart(dx)
                next ix
                AlphaBlendPixel hdc, CInt(dx - 0.5) + ix + 1, loopc, LR, LG, LB, 1 - FracPart(dx)
                dx = dx + dydx
            Next loopc
where LineStrength is a new function parameter that defines how fat the line will be.
But it does not seem to work propper. Could you help me with that, please.
It wont work proper , because my implimentation of WU algorithm can't handle curves with arbitary width.
I have done it some time ago but i think it is not currently with me..
I'll give you some ideas and references...
Try coding usin Gupta-Sproull's 'generalised' algorithm.

Arbitary width curves are antialiased considering any line or curve of some thickness 'W', as two paralell 'single width' lines/curves with a seperation equal to 'W', and then scan converting the resulting vector object.

There is also an 'in-efficient' method of drawing arbitary width, is to prepare lookup tables which stores the boundary points to be blended.

Any way stick to the 'paralell curve method'.

The best and most generalised method is to stroke with a specified width brush (NB: here 'Brush' referes to any shaped bitmap representation, not the 'Brush' in windows GDI), and then applying filters upon it. It gives more control over the the antialiasing quality, the shape, color of your curves. You can even use custom bitmaps (images) to draw a curve.
The method of filtering can be implimented in VB as follows.

1) create a temp DC
2) Create a Brush. For this just create a memory DIB of higher resolution than actually needed. I have used resolutions upto 16 times and gives the best results. Choose the resolution according to the quality you require, i.e. higher the quality required, higher the resolution. In this case the dimensions of the DIB is (W*16 x W*16).
3) Solve the curve or line by assuming width is only '1', and store all the pixels to be drawn in an array. This curve is actually passing through the middle of the required curve/line of width 'W'. Remember this curve should also be solved in the resolution we chose in step 2.
4) Select an appropriate step value to paint. this step value is to step through the array of points we have, and to paint. The most suitable value seems to be W*0.25.
5)In a loop which goes from 0 to the number of points in the coordinate array, with a step value equal to W*.25.
6)In the loop simply Blit the DIB with the coordinates in the array centered.
7)Now blit the contents of our DC, to the destination DC by pixel averaging redusing the resolution to the target DC's resolution (in our case it is 1/16).
8)You have done it!

Some references I found are attatched with this post.

And some more easy to impliment but in-efficient methods do exist, like, If you want to antialias a curve of width 'W', simply draw antialiased lines of length 'W' normal to the curve all the way to the end.

Refer also "Computer Graphics - Principles and practice by James D. Foley".
Attached Files
File Type: zip High Quality rendering of Lines and Curves.zip (159.2 KB, 29 views)
__________________
"I think; therefore I am."
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->