//---------------------------------------------------------------------------- void NonlocalBlowup::GetSnapshot () { char name[256]; if (mIteration < 10) { sprintf(name, "%s00%d.bmp", mPrefix.c_str(), mIteration); } else if (mIteration < 100) { sprintf(name, "%s0%d.bmp", mPrefix.c_str(), mIteration); } else { sprintf(name, "%s%d.bmp", mPrefix.c_str(), mIteration); } Image2<PixelBGRA8> image(512, 512); glReadPixels(0, 0, 512, 512, GL_BGRA, GL_UNSIGNED_BYTE, image.GetPixels1D()); SaveBMP32(std::string(name), image); }
//---------------------------------------------------------------------------- void SaveGraph (const std::string& folder, int frame, float ymax, int xbound, const float* slice) { const int ybound = 256; Image2<PixelBGRA8> graph(xbound, ybound); PixelBGRA8* pixels = graph.GetPixels1D(); for (int i = 0; i < graph.GetNumPixels(); ++i) { PixelBGRA8& value = *pixels++; value.b = 255; value.g = 255; value.r = 255; value.a = 255; } int x0, y0, x1, y1, cx, cy; float t; x0 = 0; y0 = (int)(ybound*slice[0]/ymax); for (x1 = 1; x1 < xbound; ++x1) { float value = slice[x1]; if (value < ymax) { y1 = (int)(ybound*value/ymax); } else { y1 = ybound; } if (y0 < ybound) { if (y1 < ybound) { DrawLine(x0, y0, x1, y1, DrawCallback, &graph); } else { cy = ybound-1; t = (float)(cy - y0)/(float)(y1 - y0); cx = (int)(x0 + t*(x1 - x0) + 0.5f); DrawLine(x0, y0, cx, cy, DrawCallback, &graph); } } else if (y1 < ybound) { cy = ybound-1; t = (float)(cy - y0)/(float)(y1 - y0); cx = (int)(x0 + t*(x1 - x0) + 0.5f); DrawLine(cx, cy, x1, y1, DrawCallback, &graph); } x0 = x1; y0 = y1; } char name[256]; if (frame < 10) { sprintf(name, "%s/Frame00%d.bmp", folder.c_str(), frame); } else if (frame < 100) { sprintf(name, "%s/Frame0%d.bmp", folder.c_str(), frame); } else { sprintf(name, "%s/Frame%d.bmp", folder.c_str(), frame); } SaveBMP32(name, graph); }