Click to See Complete Forum and Search --> : Points
Hyperspaced
Apr 4th, 2001, 07:55 PM
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.
HarryW
Apr 4th, 2001, 08:13 PM
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.
Hyperspaced
Apr 4th, 2001, 09:01 PM
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" :eek: ?
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 :o !!! 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.
Zaei
Apr 5th, 2001, 12:10 PM
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.
HarryW
Apr 5th, 2001, 11:14 PM
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().
kedaman
Apr 6th, 2001, 08:37 AM
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
Zaei
Apr 6th, 2001, 11:46 AM
kedaman, you Dune nut =)
Z.
kedaman
Apr 6th, 2001, 11:54 AM
:)
Sastraxi
Apr 6th, 2001, 05:40 PM
If you want something faster than SetPixelV, try using an Offscreen DC or DirectDraw.
HarryW
Apr 6th, 2001, 06:06 PM
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.
Sastraxi
Apr 6th, 2001, 06:21 PM
DDraw is fairly simple in VB, although, one mistake, and it's over, if you know what I mean :rolleyes:!
Hyperspaced
Apr 6th, 2001, 06:48 PM
I'll propably stick to Rectangle(...) function (thanx Harry)
;)
However, a Direct Draw implementation would be great :cool: , even if for benchmarking purposes...
I think it's worth the effort...
Off to Dan's book....
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.