From: Luigino on
Hello Steve,

> m_MemDC.SetMapMode(MM_ANISOTROPIC);
> m_MemDC.SetWindowExt(m_MaxTime, m_nVMaxY);
> m_MemDC.SetViewportOrg(0, rect.Height());
> m_MemDC.SetWindowOrg(0,0);
> m_MemDC.SetViewportExt(rect.Width(),-rect.Height());
> m_MemDC.SelectObject(&m_VPen);
> m_MemDC.Polyline(&m_VMinPts[0],(int)m_VMinPts.size());

in the array I'm not using time as X coordinates but just integers
1,2,3,4,...,n which are still consecutive integers as time values...so
in the place of m_MaxTime I use current last X value in the array and
in the place of m_nVMaxY I use rect.bottom since Y values in the array
are actually random with this formula:

myarray[i].y = (LONG)( (double)rand() / (RAND_MAX + 1) * (rect.bottom
- 1) + 1 );

(the array is fixed size to the whole window resolution width where
when I add new value at the last place I rotate before the array to
shift-left it.
The matter is setting SetWindowExt with last myarray[myarray.size() -
1].x and rect.bottom produces an assertion error.
Using Newcomer's Viewport example I found on codeproject, i figured to
set the origin at bottom right having axis going back to bottom-left
and top-right it made me setting SetViewportOrg and SetWindowOrg
respectively to 0,0 and rect.BottomRight() so it would start from
bottom-right... and setting SetWindowExt to rect.Width() and
rect.Height() didn't produced any assertion errors but doesn't
repaints rescaled graphic (as you can see in the imageshack
screenshots put before).

Maybe I haven't got well in my mind about right settings of those
SetWindowOrg, SetWindowExt, SetViewportOrg, SetViewportExt...

Any suggest?...

thanks
ciao
Luigi
From: Joseph M. Newcomer on
See below...
On Mon, 8 Feb 2010 02:13:34 -0800 (PST), Luigino <npuleio(a)rocketmail.com> wrote:

>Hello Steve,
>
>> m_MemDC.SetMapMode(MM_ANISOTROPIC);
>> m_MemDC.SetWindowExt(m_MaxTime, m_nVMaxY);
>> m_MemDC.SetViewportOrg(0, rect.Height());
>> m_MemDC.SetWindowOrg(0,0);
>> m_MemDC.SetViewportExt(rect.Width(),-rect.Height());
>> m_MemDC.SelectObject(&m_VPen);
>> m_MemDC.Polyline(&m_VMinPts[0],(int)m_VMinPts.size());
>
****

I just used Viewport Explorer and verified these settings.

Note that the order of setting the WindowExt before the ViewportExt is important, but you
have that right.

One thing I did when doing complex graphics was to put all the drawing in a *separate*
subroutine. I would pass in a CDC & to it. So what I did was

CPaintDC dc(this);
#ifdef _DEBUG_GRAPHICS
DoDrawing(dc);
#else
CDC memDC;
...create compatible DC and bitmap

DoDrawing(memDC);
... transfer bitmap to surface
#endif

This allowed me to see if I was correctly drawing on the surface, and discover errors in
my drawing logic (especially when I had Z-axis errors). Flickered like crazy, but easy to
debug. Then I would remove the #define _DEBUG_GRAPHICS once I knew it worked.


void CMyClass::DoDrawing(CDC & dc)
{
... do drawing here
}

Because at this point, you don't actually know if the error is in the drawing or in the
transfer of the bitmap to the surface, later. So this technique eliminates the
uncertainty.
****

>in the array I'm not using time as X coordinates but just integers
>1,2,3,4,...,n which are still consecutive integers as time values...so
>in the place of m_MaxTime I use current last X value in the array and
>in the place of m_nVMaxY I use rect.bottom since Y values in the array
>are actually random with this formula:
>
>myarray[i].y = (LONG)( (double)rand() / (RAND_MAX + 1) * (rect.bottom
>- 1) + 1 );
>
>(the array is fixed size to the whole window resolution width where
>when I add new value at the last place I rotate before the array to
>shift-left it.
>The matter is setting SetWindowExt with last myarray[myarray.size() -
>1].x and rect.bottom produces an assertion error.
****
Really? I don't suppose you would tell us WHERE this error occurred? Did you check what
routine it was in, what it was asserting for, and check the call to see why? Note that
reporting "an" assertion error only wastes space; the proper report is to say "I got an
assertion error in line XXXXX of file YYYYYY and I'm using VS version N" if you expect any
help. Otherwise we have no idea what went wrong, and only Psychic Vibration Mode can be
used to determine what has gone wrong.

For all we know, your assertion error could be in the array access, which could certainly
happen if the size was 0.
****
>Using Newcomer's Viewport example I found on codeproject, i figured to
>set the origin at bottom right having axis going back to bottom-left
>and top-right it made me setting SetViewportOrg and SetWindowOrg
>respectively to 0,0 and rect.BottomRight() so it would start from
>bottom-right... and setting SetWindowExt to rect.Width() and
>rect.Height() didn't produced any assertion errors but doesn't
>repaints rescaled graphic (as you can see in the imageshack
>screenshots put before).
****
There's another little glitch you may need to be concerned with: in all versions of
Windows < Vista, the DC for drawing has an area which encompasses the client area of the
parent window (as far as I can tell, this was always a stupid design mistake, and they
finally fixed it); therefore, if you want clipping, you may need to create a clipping
region and select it into the DC if you get "spillover".
****
>
>Maybe I haven't got well in my mind about right settings of those
>SetWindowOrg, SetWindowExt, SetViewportOrg, SetViewportExt...
****
One of the reasons I wrote the Viewport Explorer was because I always have trouble with
it, unless I checked with a certain book where I wrote the explanation. But I've
double-checked your settings, and they should scale the drawing to the rectangle, with the
origin in the lower left corner
joe
****
>
>Any suggest?...
>
>thanks
>ciao
>Luigi
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Joseph M. Newcomer on
Since I don't know what the data is or what it represents, or exactly what settings were
used to do those graphics, I really can't tell what the images mean.

It looks to me like nothing is being drawn until the far right of the image.

Check out my advice in an earlier reply about bypassing the bitmap so you can see exactly
what is being drawn. I find this a handy technique for debugging graphics.

Note that if you have two monitors, you run VS in one and your app in the other. But if
you only have one, you need to resize VS so it doesn't overlap your graphics area. Before
I got a second monitor, I sometimes found myself seeing only two lines of source code in
the reduced VS window.
joe

On Sun, 7 Feb 2010 17:30:06 -0800 (PST), Luigino <npuleio(a)rocketmail.com> wrote:

>Hello Joe,
>
>> How do you mean "not rescaled"? �How do you know that? �Perhaps because the lines don't
>> appear? �If so, that is not surprising, since I don't see any place at which the bitmap in
>> the memDC is transferred to the dc. �Also, I don't see where you are actually setting the
>> scale, since the points you are recording cannot be prescaled; they have to be "raw" data,
>> since by the time they are displayed, the size of the window in which they are displayed
>> can change.
>
>About not rescaled I mean this:
>
>http://img707.imageshack.us/img707/3444/44318805.jpg <---- this is the
>control minimized
>
>http://img16.imageshack.us/img16/4699/64174798.jpg <---- this is the
>control maximized
>
>As you can see the initial part of the graphic should be bigger,
>indeed looks rescaled the second part...
>
>Thanks
>Ciao
>Luigi
Joseph M. Newcomer [MVP]
email: newcomer(a)flounder.com
Web: http://www.flounder.com
MVP Tips: http://www.flounder.com/mvp_tips.htm
From: Stephen Myers on
Luigino wrote:
> Hello Steve,
>
>> m_MemDC.SetMapMode(MM_ANISOTROPIC);
>> m_MemDC.SetWindowExt(m_MaxTime, m_nVMaxY);
>> m_MemDC.SetViewportOrg(0, rect.Height());
>> m_MemDC.SetWindowOrg(0,0);
>> m_MemDC.SetViewportExt(rect.Width(),-rect.Height());
>> m_MemDC.SelectObject(&m_VPen);
>> m_MemDC.Polyline(&m_VMinPts[0],(int)m_VMinPts.size());
>
> in the array I'm not using time as X coordinates but just integers
> 1,2,3,4,...,n which are still consecutive integers as time values...so
> in the place of m_MaxTime I use current last X value in the array and
> in the place of m_nVMaxY I use rect.bottom since Y values in the array
> are actually random with this formula:
>
> myarray[i].y = (LONG)( (double)rand() / (RAND_MAX + 1) * (rect.bottom
> - 1) + 1 );
>
> (the array is fixed size to the whole window resolution width where
> when I add new value at the last place I rotate before the array to
> shift-left it.
> The matter is setting SetWindowExt with last myarray[myarray.size() -
> 1].x and rect.bottom produces an assertion error.
> Using Newcomer's Viewport example I found on codeproject, i figured to
> set the origin at bottom right having axis going back to bottom-left
> and top-right it made me setting SetViewportOrg and SetWindowOrg
> respectively to 0,0 and rect.BottomRight() so it would start from
> bottom-right... and setting SetWindowExt to rect.Width() and
> rect.Height() didn't produced any assertion errors but doesn't
> repaints rescaled graphic (as you can see in the imageshack
> screenshots put before).
>
> Maybe I haven't got well in my mind about right settings of those
> SetWindowOrg, SetWindowExt, SetViewportOrg, SetViewportExt...
>
> Any suggest?...
>
> thanks
> ciao
> Luigi

Luigi,

Assume every reference to rect other than the scaling code is wrong.
Your data does not depend on the size of the window you are displaying
it in. Your data is in logical units, not screen units. rect does not
contain anything useful once the scaling has been completed.

Try something like:
myarray[i].y = (LONG)( (double)rand() / (RAND_MAX + 1) * (m_nVMaxY) + 1);

Steve
From: Stephen Myers on
Joseph M. Newcomer wrote:
> See below...
> On Mon, 8 Feb 2010 02:13:34 -0800 (PST), Luigino <npuleio(a)rocketmail.com> wrote:
>
>> Hello Steve,
>>
>>> m_MemDC.SetMapMode(MM_ANISOTROPIC);
>>> m_MemDC.SetWindowExt(m_MaxTime, m_nVMaxY);
>>> m_MemDC.SetViewportOrg(0, rect.Height());
>>> m_MemDC.SetWindowOrg(0,0);
>>> m_MemDC.SetViewportExt(rect.Width(),-rect.Height());
>>> m_MemDC.SelectObject(&m_VPen);
>>> m_MemDC.Polyline(&m_VMinPts[0],(int)m_VMinPts.size());
> ****
>
> I just used Viewport Explorer and verified these settings.
>
> Note that the order of setting the WindowExt before the ViewportExt is important, but you
> have that right.
>
> One thing I did when doing complex graphics was to put all the drawing in a *separate*
> subroutine. I would pass in a CDC & to it. So what I did was
>
> CPaintDC dc(this);
> #ifdef _DEBUG_GRAPHICS
> DoDrawing(dc);
> #else
> CDC memDC;
> ...create compatible DC and bitmap
>
> DoDrawing(memDC);
> ... transfer bitmap to surface
> #endif
>
> This allowed me to see if I was correctly drawing on the surface, and discover errors in
> my drawing logic (especially when I had Z-axis errors). Flickered like crazy, but easy to
> debug. Then I would remove the #define _DEBUG_GRAPHICS once I knew it worked.
>
>
> void CMyClass::DoDrawing(CDC & dc)
> {
> ... do drawing here
> }
>
> Because at this point, you don't actually know if the error is in the drawing or in the
> transfer of the bitmap to the surface, later. So this technique eliminates the
> uncertainty.
> ****
>
>> in the array I'm not using time as X coordinates but just integers
>> 1,2,3,4,...,n which are still consecutive integers as time values...so
>> in the place of m_MaxTime I use current last X value in the array and
>> in the place of m_nVMaxY I use rect.bottom since Y values in the array
>> are actually random with this formula:
>>
>> myarray[i].y = (LONG)( (double)rand() / (RAND_MAX + 1) * (rect.bottom
>> - 1) + 1 );
>>
>> (the array is fixed size to the whole window resolution width where
>> when I add new value at the last place I rotate before the array to
>> shift-left it.
>> The matter is setting SetWindowExt with last myarray[myarray.size() -
>> 1].x and rect.bottom produces an assertion error.
> ****
> Really? I don't suppose you would tell us WHERE this error occurred? Did you check what
> routine it was in, what it was asserting for, and check the call to see why? Note that
> reporting "an" assertion error only wastes space; the proper report is to say "I got an
> assertion error in line XXXXX of file YYYYYY and I'm using VS version N" if you expect any
> help. Otherwise we have no idea what went wrong, and only Psychic Vibration Mode can be
> used to determine what has gone wrong.
>
> For all we know, your assertion error could be in the array access, which could certainly
> happen if the size was 0.
> ****
>> Using Newcomer's Viewport example I found on codeproject, i figured to
>> set the origin at bottom right having axis going back to bottom-left
>> and top-right it made me setting SetViewportOrg and SetWindowOrg
>> respectively to 0,0 and rect.BottomRight() so it would start from
>> bottom-right... and setting SetWindowExt to rect.Width() and
>> rect.Height() didn't produced any assertion errors but doesn't
>> repaints rescaled graphic (as you can see in the imageshack
>> screenshots put before).
> ****
> There's another little glitch you may need to be concerned with: in all versions of
> Windows < Vista, the DC for drawing has an area which encompasses the client area of the
> parent window (as far as I can tell, this was always a stupid design mistake, and they
> finally fixed it); therefore, if you want clipping, you may need to create a clipping
> region and select it into the DC if you get "spillover".
> ****
>> Maybe I haven't got well in my mind about right settings of those
>> SetWindowOrg, SetWindowExt, SetViewportOrg, SetViewportExt...
> ****
> One of the reasons I wrote the Viewport Explorer was because I always have trouble with
> it, unless I checked with a certain book where I wrote the explanation. But I've
> double-checked your settings, and they should scale the drawing to the rectangle, with the
> origin in the lower left corner
> joe
> ****
>> Any suggest?...
>>
>> thanks
>> ciao
>> Luigi
> Joseph M. Newcomer [MVP]
> email: newcomer(a)flounder.com
> Web: http://www.flounder.com
> MVP Tips: http://www.flounder.com/mvp_tips.htm

Joe,

Thanks for making things like viewport explorer available. Hopefully,
it will speed things up for me next time I have to do this sort of thing.

Steve