A figure consisting of many lines that are drawn by the Graphics::DrawLine function from GDI+ library is not drawn.

  • Thread starter Thread starter Purple_Apple
  • Start date Start date
P

Purple_Apple

Guest
My application is Win32 C++ application for triangulation of set of point with Cartesian coordinates. Cannot display the triangulation as follows: xMin == 12.5, xMax == 259.5, yMin == 39.5, yMax == 511.5. In this case I try to draw in the first quadrant of coordinate system where positive numbers only. The number of triangulated points is 39,000 points (thirty nine thousand).

VOID OnPaint(HWND hWnd, HDC hdc)
{
if (!isnan(xMin) && !isnan(xMax) && !isnan(yMin) && !isnan(yMax))
{
// This is the Graphics instatnce to draw the triangulation with.
Graphics* g = Graphics::FromHDC(hdc);

// Get height of toolbar.
RECT toolbarRect;
GetWindowRect(g_hWndToolbar, &toolbarRect);
LONG toolbarHeight = toolbarRect.bottom - toolbarRect.top;
// Get width and height of the client area of the application window.
RECT r;
::GetClientRect(hWnd, &r);
int width = r.right - r.left;
int height = r.bottom - (r.top);

// X axis scaling factor
double xScale = 0;
// Y axis scaling factor
double yScale = 0;
// The maximum value on the coordinate axes
double maximal = max(xMax, yMax);

// Move the origin:
if (xMin < 0 && xMax > 0 && yMin < 0 && yMax > 0)
{
// to center if all of four quadrants of coordinate system are used
g->TranslateTransform((r.right - r.left) / 2, (r.bottom - r.top) / 2 + toolbarHeight);
xScale = (((double)width / 2.0) / maximal);
yScale = ((double)height / 2.0) / maximal;
}
.
.
.
/*** HERE I'M TRYING TO DRAW A TRIANGULATION MESH IN FIRST QUADRANT OF COORDINATES***/
else if (xMin >= 0 && xMax > 0 && yMin >= 0 && yMax > 0)
{
// origin is not moved anywhere since we are working here
// in the first quadrant of the coordinate plane
g->TranslateTransform(0.0, 0.0);
xScale = (double)width / maximal;
yScale = (double)height / maximal;
}
.
.
.
// Set the bottom-up orientation of Y
g->ScaleTransform(1, -1);
// -- scale; 511.5 is the maximal expected value of coordinates --.
// Factor that prevents “stretching” the image along the X axis.
double X_axis_correction_factor = ((abs((double)r.right - (double)r.left))) / ((abs((double)r.bottom - (double)r.top)));
// Perform scaling.
g->ScaleTransform(xScale / X_axis_correction_factor, yScale);

Pen pen(Color(255, 0, 0, 255), 100.0f);
g->SetSmoothingMode(SmoothingModeAntiAlias);
// Draw next edge.
EdgeToDraw* drawnEdge = new EdgeToDraw();
while (MeshEdgesBuffer.try_pop(*drawnEdge))
g->DrawLine(&pen, drawnEdge->Begin, drawnEdge->End);
}
}

Now, at the end of all DrawLine() function calls, I don’t show a single line. I deliberately set as large as 100.0f width of the drawn line as you can see at the code listing. But I see nothing. I suppose that I could make two mistakes:

1) I incorrectly described the actions inside the if condition of drawing a triangulation in the first quadrant.

else if (xMin >= 0 && xMax > 0 && yMin >= 0 && yMax > 0)
{
// origin is not moved anywhere since we are working here
// in the first quadrant of the coordinate plane
g->TranslateTransform(0.0, 0.0);
xScale = (double)width / maximal;
yScale = (double)height / maximal;
}

2) I could have done something wrong in scaling:

g->ScaleTransform(xScale / X_axis_correction_factor, yScale);
I remember the advice of Tim Roberts that: "Remember that the scale factor applies to EVERYTHING." from In the Win32 C++ application, when using the DrawLine() function, wide strokes are drawn instead of lines. and try to follow it as much as possible. Since to use (in my case) ScaleTransform seems to me the most acceptable. But I myself can’t get to the bottom of the reason and correct my defect described here. Therefore, I ask for your tip and help, for which I will be very grateful.

Continue reading...
 
Back
Top