random_graph_t() : m_graph(), m_fully_occupied_vertices_count(0) { memset(m_connections_per_vertex, 0, sizeof(m_connections_per_vertex)); while (m_fully_occupied_vertices_count < size) assign_edge(random_possible_edge()); /* * Now label edges */ for(size_t i = 0; i < size; ++i) { bool label_available[] = { true, true, true }; unsigned int labels_available_count = sizeof(label_available) / sizeof(bool); for(size_t j = 0; j < size; ++j) { for(typename connection_t::iterator it = m_graph[i][j].begin(); it != m_graph[i][j].end(); ++it) { bool *rit = random_index(label_available, label_available + sizeof(label_available) / sizeof(bool), labels_available_count, identity<bool>()); *rit = false; *it = connection_types[rit - label_available]; --labels_available_count; } } } }
static void merge_boundary(GwyDataField *dfield1, GwyDataField *dfield2, GwyDataField *result, GwyRectangle res_rect, GwyCoord f1_pos, GwyCoord f2_pos, GwyMergeBoundaryType boundary) { gint xres1, xres2, xres, yres1, yres2, col, row; gdouble weight, val1, val2; gint w1top = 0, w1bot = 0, w1left = 0, w1right = 0; gint w2top = 0, w2bot = 0, w2left = 0, w2right = 0; const gdouble *d1, *d2; gdouble *d; xres1 = dfield1->xres; yres1 = dfield1->yres; xres2 = dfield2->xres; yres2 = dfield2->yres; xres = result->xres; gwy_debug("dfield1: %d x %d at (%d, %d)", xres1, yres1, f1_pos.x, f1_pos.y); gwy_debug("dfield2: %d x %d at (%d, %d)", xres2, yres2, f2_pos.x, f2_pos.y); gwy_debug("result: %d x %d", xres, result->yres); gwy_debug("rect in result : %d x %d at (%d,%d)", res_rect.width, res_rect.height, res_rect.x, res_rect.y); assign_edge(res_rect.x, f1_pos.x, f2_pos.x, &w1left, &w2left); gwy_debug("left: %d %d", w1left, w2left); assign_edge(res_rect.y, f1_pos.y, f2_pos.y, &w1top, &w2top); gwy_debug("top: %d %d", w1top, w2top); assign_edge(res_rect.width, xres1 - f1_pos.x, xres2 - f2_pos.x, &w1right, &w2right); gwy_debug("right: %d %d", w1right, w2right); assign_edge(res_rect.height, yres1 - f1_pos.y, yres2 - f2_pos.y, &w1bot, &w2bot); gwy_debug("bot: %d %d", w1bot, w2bot); d1 = gwy_data_field_get_data_const(dfield1); d2 = gwy_data_field_get_data_const(dfield2); d = gwy_data_field_get_data(result); for (row = 0; row < res_rect.height; row++) { gint dtop = row + 1, dbot = res_rect.height - row; for (col = 0; col < res_rect.width; col++) { weight = 0.5; if (boundary == GWY_MERGE_BOUNDARY_INTERPOLATE) { gint dleft = col + 1, dright = res_rect.width - col; gint d1min = G_MAXINT, d2min = G_MAXINT; /* FIXME: This can be probably simplified... */ if (w1top && dtop < d1min) d1min = dtop; if (w1bot && dbot < d1min) d1min = dbot; if (w1left && dleft < d1min) d1min = dleft; if (w1right && dright < d1min) d1min = dright; if (w2top && dtop < d2min) d2min = dtop; if (w2bot && dbot < d2min) d2min = dbot; if (w2left && dleft < d2min) d2min = dleft; if (w2right && dright < d2min) d2min = dright; weight = (gdouble)d2min/(d1min + d2min); } val1 = d1[xres1*(row + f1_pos.y) + (col + f1_pos.x)]; val2 = d2[xres2*(row + f2_pos.y) + (col + f2_pos.x)]; d[xres*(row + res_rect.y) + col + res_rect.x] = (1.0 - weight)*val1 + weight*val2; } } }