Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


Some help with drawing a Wu Xiaoling line


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
7 replies to this topic

#1 VanillaSnake   Members   -  Reputation: 132

Like
0Likes
Like

Posted 24 January 2012 - 05:02 AM

Hey, I'm going trying to draw the Wu line as he describes it in his paper, but I don't understand some of the concepts that he talks about. First thing that I don't understand is the error he calculates for DDA. Let me quote him

The values can be determined by an elegant incremental algorithm opoerating on a single integer D represented by a machine word of n bits. The integer increment involved is d = floor(k*2 + 0.5)"

This part I understand

The operation D <- D + d is a module 2^n addition with the overflow recorded.

This I'm a little fuzzy about. What is a module 2^n addition?

This is essentially a classical DDA method... For the following analysis we may consider D as a fixed point number with the decimal point before its most significant bit, or conceptually percieve the proposed integer arithmetic as fixed point arithmetic. Thus the error between the real DDA increment and our integer DDA increment is e = k - d*2^(-n)


This I don't understand at all. How does he come up with that error. k is the slope and d is the increment, n is the number of bits in D. But how does he come up with a negative exponent and why is he subtracting.

All gray-scale raster devices have 2^m, for some m > 1 discrete intensity levels from 0 to 2^m - 1. The intensity interpolation between the two vertically adjacent pixels becomes a bi-partition of the integer I, the maximum intensity. The intensity of the upper pixel for the line is
I( x, ceil(k*x) ) = (2^m - 1) * (D*2^(-n) + ex) = D*2^(m-n) + ....

Here he lost me completely. I understand that 2^m - 1 is the alpha basically, usually set to 255. But how did he tie in D and the error e? He goes on:

The approximated I(x, ceil(k*x) ) ~ D*2^(m - n) is simply presented by the m most significant bits of D... Now we see that the integer D controls both the pixel positions and intensities


Can anyone tell me what the heck is he talking about?

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


Sponsor:

#2 Syranide   Members   -  Reputation: 375

Like
0Likes
Like

Posted 24 January 2012 - 05:20 AM

Perhaps not an proper answer to your question, but wikipedia may help you:
http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm (shows an implementation of the algorihm)



#3 VanillaSnake   Members   -  Reputation: 132

Like
0Likes
Like

Posted 24 January 2012 - 05:29 AM

Perhaps not an proper answer to your question, but wikipedia may help you:
http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm (shows an implementation of the algorihm)


Oh believe you me, I've devoured that article tens of times, that and all the other articles that I could find on the subject, now I'm reading Michael Abrashes explanation, so far his makes the most sense to me.

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


#4 Sik_the_hedgehog   Crossbones+   -  Reputation: 1817

Like
0Likes
Like

Posted 24 January 2012 - 05:33 AM

Perhaps not an proper answer to your question, but wikipedia may help you:
http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm (shows an implementation of the algorihm)

Your link is broken, for some reason the URL gets cut at the apostrophe =/
Don't pay much attention to "the hedgehog" in my nick, it's just because "Sik" was already taken =/ By the way, Sik is pronounced like seek, not like sick.

#5 Syranide   Members   -  Reputation: 375

Like
1Likes
Like

Posted 24 January 2012 - 05:56 AM


Perhaps not an proper answer to your question, but wikipedia may help you:
http://en.wikipedia.org/wiki/Xiaolin_Wu's_line_algorithm (shows an implementation of the algorihm)


Oh believe you me, I've devoured that article tens of times, that and all the other articles that I could find on the subject, now I'm reading Michael Abrashes explanation, so far his makes the most sense to me.


Ah, I guess you could look at Bresenham's code a bit too on wikipedia, may not be directly applicable, but they do go through some short explanatations and optimizations...

Anyway, as you understand I have little knowledge of this myself, but!


"The operation D <- D + d is a module 2^n addition with the overflow recorded."
I'm pretty sure he just means D = (D + d) % (2^n) ... and he stores the overflow ... somewhere. Or it's just strangely worded?

"e = k - d*2^(-n)"
Again, just my first hand instinct, negative n seems reasonable as the error should go down as the number of bits go up. Especially as it seems that d is related to 2^n, by the above.

"I( x, ceil(k*x) ) = (2^m - 1) * (D*2^(-n) + ex) = D*2^(m-n) + ...."
I'm guessing this is just a continuation on the above to some degree, with d replaced by D (as D is in-fact d, but accumulated).


Again, I may be completely stumbling in the dark here, so if this makes no sense either, it's probably because it doesn't ;)



#6 VanillaSnake   Members   -  Reputation: 132

Like
0Likes
Like

Posted 24 January 2012 - 06:59 AM


Lol, that does make sense, especially the error part, I didn't think of it that way. I've just finished reading Abrashe's article (conveniently his whole book is found right
<a href="http://www.gamedev.net/page/resources/_/technical/graphics-programming-and-theory/graphics-programming-black-book-r1698"> here </a>
at Gamedev, for anyone interested). He explains everything thoroughly, and I do understand the gist of it now. But still I can't seem to get it right in my code! Here's what I came up with, trying not to copy his but do it from my understanding.


void WuFast(int x0, int y0, int x1, int y1)
{
int DeltaY = y1 - y0;
int DeltaX = x1 - x0;
int IntensityShift = 16 - 8;
WORD ErorrAdj = ((unsigned long)DeltaY << 16) / (unsigned long)DeltaX;
WORD ErrorAcc = 0;

Plot(x0, y0, Build_GrayScale(255));

while(--DeltaX)
{
WORD tErrorAcc = ErrorAcc;
ErrorAcc += ErorrAdj;

x0++;

if(ErrorAcc < tErrorAcc)
y0++;


int Weight = ErrorAcc >> IntensityShift;
int InverseWeight = Weight ^ 255;
Plot(x0,y0, Build_GrayScale(Weight));
Plot(x0, y0 + 1, Build_GrayScale(InverseWeight));


}

}


What happens is that I get a very jagged line that looks nowhere near anti-aliased Posted Image
Here's an image to show you what I mean

line

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying


#7 Syranide   Members   -  Reputation: 375

Like
1Likes
Like

Posted 24 January 2012 - 07:10 AM

That line looks correct to me, except it seems like the antialiasing is backwards... flip the white and black and you'll see that it looks right. Tried it quickly in photoshop and indeed, that is the case.

Good work!



#8 VanillaSnake   Members   -  Reputation: 132

Like
0Likes
Like

Posted 24 January 2012 - 07:19 AM

That line looks correct to me, except it seems like the antialiasing is backwards... flip the white and black and you'll see that it looks right. Tried it quickly in photoshop and indeed, that is the case.

Good work!


You're right! Setting the background to white made a huge difference - it looks amazing! You can't believe how many forms of this algorithm I have written thinking that I've been getting it wrong somehow because all the lines have been coming out jagged. I just tested all of them again with white background and surprisingly they all worked flawlessly, hahaha. Anyways thanks Syranide, you literally saved me from a week worth of frustration. So the night has paid off well, time to catch some zzz Posted Image

You didn't come into this world. You came out of it, like a wave from the ocean. You are not a stranger here. -Alan Watts

 

Time flies like an arrow; fruit flies like a banana. - Old Wise Eastern tribesman saying





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS