Results 1 to 12 of 12

Thread: Points

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    Arrow

    Hello,

    I need to make a surf plot in VB using calculated values contained in a matrix which are then converted to an RGB value and then plotted.

    I use the internal PSet function which accepts an RGB value. Is it really that slow compared to SetPixel ? Are there any faster API calls ? Does SetPixel accept an RGB value as a color ?

    Another issue is that I need to set the "point" as a square shape. However, depending on how fine the resolution is chosen by the user, the square should sometimes be "small" and sometimes "big".

    Is there any way I can do this ?

    Thanks in advance guys.

  2. #2
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Well SetPixel is the Windows GDI function you would use if you want to plot one pixel at a time. It's still slow though, if you need more speed then you may want to look at using DirectDraw.

    I'm pretty sure SetPixel takes an RGB value. I don't remember exactly but it's not hard to use.

    Generally, if a user has chosen to have a small resolution, it's because they want things to look smaller than usual so you probably shouldn't worry too much about getting the size correct. However, if it's really bugging you then you can use a function like GetSystemMetrics or look at the Screen object to find out what the user's current resolution is. Once you know that, you can either change the resolution to one you want, or make things bigger. You could make things bigger by drawing your matrix to one DC (either a picture box with visible property set to false or a memory DC, made using the CreateDC function) and using StretchBlt to blit the image from the resource DC to a foreground DC with the appropriate dimensions.

    If you want to improve the quality of the stretch then there are a few things you can do with mapping the pixels from one place to the other, but they would make things complicated.
    Harry.

    "From one thing, know ten thousand things."

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    Thanks Harry, please read

    This is not what I actually meant. Sorry If I didn't make myself clear.

    The resolution of the screen stays unchanged. With "resolution" I meant how coarse or fine the graphical output should be.

    Okay, suppose the screen resolution stays unchanged, let's say 1024x768. Let's say you are calculating a 2D function called f (x,y independant variables, z dependant variable; plot the z as color). You begin the calculation from e.g. x=0 to x=100 with step 10 and from y=0 to y=100 with step 10 also. I want to represent a calculated point e.g. f (40,50) with a square which ranges from x=35 to 45 and y=45 to 50 {so the center of the square (or cell) is (40,50) } The reason I want to do this is because I use a relatively large step size (10%) ==> This is a COARSE representation

    Now, say I use the same x, y bounds but a step size of 1. Calculated point f (40,50) should be now represented with a square (or cell) which ranges from x=39.5 to x=40.5 and y=49.5 to y=50.5. ==> FINE representation


    So, to make things simple, is there any kind of "square brush" with "adjustable size of the square" ?
    If you know there is, please explain.


    Note :
    I tried to use PSet but when making coarse representations I used the DrawWidth property to change the pixel display size, which resulted in filled circles, not filled rectangles !!! However, when creating very fine representations (DrawWidth=1), it appeared OK, because a very small circle looks almost the same with a very small square.

  4. #4
    Zaei
    Guest
    The SetPixelV API function is faster then SetPixel. You can use the Line Method in VB, in combination with the BF flags to draw a rectangle.

    Z.

  5. #5
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Oh right I see, looks like I misunderstood

    If you know where on the screen you want to draw the rectangle, you can use the GDI function Rectangle() to do it. That requires you to select in the right pen and brush for the DC though. You can use BitBlt too, I think, so long as you don't mind using one of the common colour constants for your square colour.

    If you'd rather stick with PSet or SetPixel, you could make a function that will draw a square of a given size at a given point, and in that function just use PSet or SetPixel to create the rectangle pixel by pixel. It will be pretty slow but simple. Personally I think I'd go for Rectangle().
    Harry.

    "From one thing, know ten thousand things."

  6. #6
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    there's built in scaling on the form and most controls, you can change to usermode and set the scaleleft/top/width/height properties and then plotted pixels, lines and circles will be positioned accordingly. However this doesn't work with any GDI functions. You could thought manually convert between your own scale units and pixels, u=c*p+o
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  7. #7
    Zaei
    Guest
    kedaman, you Dune nut =)

    Z.

  8. #8
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

  9. #9
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    If you want something faster than SetPixelV, try using an Offscreen DC or DirectDraw.
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  10. #10
    Frenzied Member HarryW's Avatar
    Join Date
    Jan 2000
    Location
    Heiho no michi
    Posts
    1,827
    Dune is cool I have it on video. I heard the original, uncut, version is something like 5 1/2 hours long.

    Using a Windows GDI function to draw simple primitives (like rectangles) will be faster than using SetPixel or SetPixelV to do it. DirectDraw is faster still since you can use hardware to do colour fills, but it's a lot more complicated. Well it is in C/C++ anyway, I've never used DDraw in VB.
    Harry.

    "From one thing, know ten thousand things."

  11. #11
    Good Ol' Platypus Sastraxi's Avatar
    Join Date
    Jan 2000
    Location
    Ontario, Canada
    Posts
    5,134
    DDraw is fairly simple in VB, although, one mistake, and it's over, if you know what I mean !
    All contents of the above post that aren't somebody elses are mine, not the property of some media corporation.
    (Just a heads-up)

  12. #12

    Thread Starter
    Addicted Member
    Join Date
    Mar 2001
    Location
    Greece
    Posts
    164

    Thanx guys

    I'll propably stick to Rectangle(...) function (thanx Harry)


    However, a Direct Draw implementation would be great , even if for benchmarking purposes...

    I think it's worth the effort...

    Off to Dan's book....

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width