void test_add_point_with_stamp_center() { heatmap_t* hm = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); ENSURE_THAT("the heatmap equals the stamp", heatmap_eq(hm, g_3x3_stamp.buf)); ENSURE_THAT("the max of the heatmap is one", hm->max == 1.0f); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); static float expected[] = { 0.0f, 1.0f, 0.0f, 1.0f, 2.0f, 1.0f, 0.0f, 1.0f, 0.0f, }; ENSURE_THAT("the heatmap equals double the stamp", heatmap_eq(hm, expected)); ENSURE_THAT("the max of the heatmap is two", hm->max == 2.0f); heatmap_t* hm2 = heatmap_new(3, 3); heatmap_add_weighted_point_with_stamp(hm2, 1, 1, 2.0f, &g_3x3_stamp); ENSURE_THAT("a point with weight 2.0 generates the same heatmap.", heatmaps_eq(hm2, hm)); heatmap_free(hm); heatmap_free(hm2); }
void test_render_to_saturating() { static unsigned char expected1[] = { 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 255, 255, 255, 255, 0, 0, 0, 0, }; static unsigned char expected2[] = { 0, 0, 0, 0, 191, 191, 191, 255, 0, 0, 0, 0, 191, 191, 191, 255, 255, 255, 255, 255, 191, 191, 191, 255, 0, 0, 0, 0, 191, 191, 191, 255, 0, 0, 0, 0, }; heatmap_t* hm = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); unsigned char img[3*3*4] = {1}; heatmap_render_saturated_to(hm, heatmap_cs_b2w, 1.0f, img); ENSURE_THAT("saturated (1) rendered 3x3 heatmap is correct", 0 == memcmp(img, expected1, 3*3*4)); heatmap_render_saturated_to(hm, heatmap_cs_b2w, 2.0f, img); ENSURE_THAT("saturated (2) rendered 3x3 heatmap is correct", 0 == memcmp(img, expected2, 3*3*4)); heatmap_free(hm); // TODO: (Also try negative and non-one-max stamps?) }
void test_add_point_with_stamp_outside() { static float expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, }; heatmap_t* hm = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 3, 2, &g_3x3_stamp); heatmap_add_point_with_stamp(hm, 2, 3, &g_3x3_stamp); heatmap_add_point_with_stamp(hm, 3, 3, &g_3x3_stamp); ENSURE_THAT("no point outside the map got added", heatmap_eq(hm, expected)); ENSURE_THAT("the max of the heatmap is zero", hm->max == 0.0f); heatmap_add_weighted_point_with_stamp(hm, 3, 2, 1.5f, &g_3x3_stamp); heatmap_add_weighted_point_with_stamp(hm, 2, 3, 1.5f, &g_3x3_stamp); heatmap_add_weighted_point_with_stamp(hm, 3, 3, 1.5f, &g_3x3_stamp); ENSURE_THAT("no weighted point outside the map got added", heatmap_eq(hm, expected)); ENSURE_THAT("the max of the heatmap is zero", hm->max == 0.0f); heatmap_free(hm); }
void test_add_point_with_stamp_botright() { static float expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.5f, 0.0f, 0.5f, 1.0f, }; heatmap_t* hm = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 2, 2, &g_3x3_stamp); ENSURE_THAT("bot-right point is correct", heatmap_eq(hm, expected)); ENSURE_THAT("the max of the heatmap is one", hm->max == 1.0f); heatmap_t* hm2 = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 2, 2, &g_3x3_stamp); heatmap_add_weighted_point_with_stamp(hm2, 2, 2, 2.0f, &g_3x3_stamp); ENSURE_THAT("a point with weight 2.0 generates the same heatmap as two regular ones.", heatmaps_eq(hm2, hm)); heatmap_free(hm); heatmap_free(hm2); }
void test_add_nothing() { heatmap_t* hm = heatmap_new(3, 3); static float expected[] = { 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f, }; ENSURE_THAT("the heatmap is full of zeros", heatmap_eq(hm, expected)); ENSURE_THAT("the max of the heatmap is zero", hm->max == 0.0f); heatmap_free(hm); }
void test_render_to_nothing() { static unsigned char expected[] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; heatmap_t* hm = heatmap_new(3, 3); unsigned char img[3*3*4] = {1}; heatmap_render_to(hm, heatmap_cs_b2w, img); ENSURE_THAT("empty rendered 3x3 heatmap is correct", 0 == memcmp(img, expected, 3*3*4)); heatmap_free(hm); }
void test_render_to_creation() { static unsigned char expected[] = { 0, 0, 0, 0, 127, 127, 127, 255, 0, 0, 0, 0, 127, 127, 127, 255, 255, 255, 255, 255, 127, 127, 127, 255, 0, 0, 0, 0, 127, 127, 127, 255, 0, 0, 0, 0, }; heatmap_t* hm = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); unsigned char* img = heatmap_render_to(hm, heatmap_cs_b2w, nullptr); ENSURE_THAT("simple rendered 3x3 heatmap is correct", 0 == memcmp(img, expected, 3*3*4)); heatmap_free(hm); free(img); }
void test_render_to_normalizing() { static unsigned char expected[] = { 0, 0, 0, 0, 127, 127, 127, 255, 0, 0, 0, 0, 127, 127, 127, 255, 255, 255, 255, 255, 127, 127, 127, 255, 0, 0, 0, 0, 127, 127, 127, 255, 0, 0, 0, 0, }; heatmap_t* hm = heatmap_new(3, 3); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); unsigned char img[3*3*4] = {1}; heatmap_render_to(hm, heatmap_cs_b2w, img); ENSURE_THAT("simple rendered 3x3 heatmap is correct", 0 == memcmp(img, expected, 3*3*4)); heatmap_add_point_with_stamp(hm, 1, 1, &g_3x3_stamp); heatmap_render_to(hm, heatmap_cs_b2w, img); ENSURE_THAT("two points on one spot don't change the outcome, due to normalization.", 0 == memcmp(img, expected, 3*3*4)); heatmap_free(hm); // TODO: (Also try negative and non-one-max stamps?) }
void App::dumpHeatmap() { static const size_t size = 1000; heatmap_t* hm = heatmap_new(size, size); int M = 21; float hist[M][M]; // for(int i = 0; i < M; i ++){ // for(int j = 0; j < M; j ++){ // hist[i][j] = 0; // } // } for(int i = 1; i < session->getSize(); i ++) { float y = ofAngleDifferenceDegrees(rotations[X].data[i], heatmap.rot_x->ref); float x = ofAngleDifferenceDegrees(rotations[Y].data[i], heatmap.rot_y->ref); x = ofMap(x, 120, -120, 0, size); y = ofMap(y, -120, 120, 0, size); heatmap_add_point(hm, x, y); x = ofMap(x, 0, size, 0, M - 1, true); y = ofMap(y, 0, size, 0, M - 1, true); hist[(int) x][(int) y] += 1; } // string str = "1;2;3;4;5;6;7;8;9;10;11;12;13;14;15;16;17;18;19;20;21"; // str += "\n"; // for(int j = 0; j < M; j ++){ // for(int i = 0; i < M; i ++){ // hist[i][j] = hist[i][j] / (float) session->getSize(); // hist[i][j] *= 100; // str += ofToString(round(hist[i][j] * 100) / 100.0); // if( i != M - 1) // str += ";"; // } // if( j != M - 1) // str += "\n"; // } // // // ofFile file( Assets::getInstance()->dataPath() + ofToString(metadata.name)+ "-" + session->timestamp + ".csv", ofFile::WriteOnly); // file << str; unsigned char * pixels = new unsigned char[size*size*4]; heatmap_render_default_to(hm, pixels); ofImage img; img.allocate(size, size, OF_IMAGE_COLOR_ALPHA); img.setFromPixels(pixels, size, size, OF_IMAGE_COLOR_ALPHA); string filename = Assets::getInstance()->dataPath() + session->timestamp + "_" + ofToString(metadata.name) + ".png"; cout << filename << endl; img.saveImage( filename); }