| 50 | void populateBins(Bitmap& bmp, int *hist_array, const unsigned nbins, float *hist_cols); |
| 51 | |
| 52 | int main(void) |
| 53 | { |
| 54 | Bitmap bmp = createBitmap(IMGW, IMGH); |
| 55 | /* |
| 56 | * First Forge call should be a window creation call |
| 57 | * so that necessary OpenGL context is created for any |
| 58 | * other forge::* object to be created successfully |
| 59 | */ |
| 60 | forge::Window wnd(DIMX, DIMY, "Histogram Demo"); |
| 61 | wnd.makeCurrent(); |
| 62 | |
| 63 | forge::Image img(IMGW, IMGH, FG_RGBA, forge::u8); |
| 64 | |
| 65 | forge::Chart chart(FG_CHART_2D); |
| 66 | |
| 67 | /* set x axis limits to maximum and minimum values of data |
| 68 | * and y axis limits to range [0, number of pixels ideally] |
| 69 | * but practically total number of pixels as y range will skew |
| 70 | * the histogram graph vertically. Therefore setting it to |
| 71 | * 25% of total number of pixels */ |
| 72 | chart.setAxesLimits(0, 1, 0, IMGW*IMGH/(float)(NBINS/4.0)); |
| 73 | |
| 74 | /* |
| 75 | * Create histogram object specifying number of bins |
| 76 | */ |
| 77 | forge::Histogram hist = chart.histogram(NBINS, forge::s32); |
| 78 | /* |
| 79 | * Set histogram colors |
| 80 | */ |
| 81 | hist.setColor(FG_YELLOW); |
| 82 | |
| 83 | GfxHandle* handles[3]; |
| 84 | |
| 85 | createGLBuffer(&handles[0], img.pixels(), FORGE_IMAGE_BUFFER); |
| 86 | createGLBuffer(&handles[1], hist.vertices(), FORGE_VERTEX_BUFFER); |
| 87 | createGLBuffer(&handles[2], hist.colors(), FORGE_VERTEX_BUFFER); |
| 88 | |
| 89 | do { |
| 90 | /* |
| 91 | * generate image, and prepare data to pass into |
| 92 | * Histogram's underlying vertex buffer object |
| 93 | */ |
| 94 | kernel(bmp); |
| 95 | |
| 96 | copyToGLBuffer(handles[0], (ComputeResourceHandle)bmp.ptr, img.size()); |
| 97 | |
| 98 | //forge::copy(img, (const void*)bmp.ptr); |
| 99 | |
| 100 | /* copy your data into the vertex buffer object exposed by |
| 101 | * forge::Histogram class and then proceed to rendering. |
| 102 | * To help the users with copying the data from compute |
| 103 | * memory to display memory, Forge provides copy headers |
| 104 | * along with the library to help with this task |
| 105 | */ |
| 106 | std::vector<int> histArray(NBINS, 0); |
| 107 | std::vector<float> colArray(3*NBINS, 0.0f); |
| 108 | populateBins(bmp, histArray.data(), NBINS, colArray.data()); |
| 109 |
nothing calls this directly
no test coverage detected