HIDDEN struct halfedge * generate_edge_list(const struct rt_bot_internal *bot) { const size_t num_edges = 3 * bot->num_faces; struct halfedge *edge_list; size_t face_index, edge_index; edge_list = (struct halfedge *)bu_calloc(num_edges, sizeof(struct halfedge), "edge_list"); for (face_index = 0, edge_index = 0; face_index < bot->num_faces; ++face_index) { const int *face = &bot->faces[face_index * 3]; int success = set_edge(&edge_list[edge_index++], face[0], face[1]) && set_edge(&edge_list[edge_index++], face[1], face[2]) && set_edge(&edge_list[edge_index++], face[2], face[0]); if (!success) { bu_free(edge_list, "edge_list"); return NULL; } } qsort(edge_list, num_edges, sizeof(struct halfedge), halfedge_compare); return edge_list; }
void draw_shaded_edges(polygon p, struct screen *s, enum shading_t type, struct constants *k, color ambient, struct light *l, struct vector n[3], struct vector *v) { struct vector centroid; struct vector cv; color c; edge e; if (type == FLAT) { calculate_centroid(¢roid, p); calculate_intensity(&cv, k, ambient, l, ¢roid, n, v); c = vtoc(&cv); set_edge(e, p[0], p[1]); draw_line(e, s, c); set_edge(e, p[1], p[2]); draw_line(e, s, c); set_edge(e, p[2], p[0]); draw_line(e, s, c); } else { draw_shaded_edge(0, p, s, type, k, ambient, l, n, v); draw_shaded_edge(1, p, s, type, k, ambient, l, n, v); draw_shaded_edge(2, p, s, type, k, ambient, l, n, v); } }
/** * \fn PatchVertex( const PatchVertex< VAttrib , EAttrib , PAttrib >& patch ) * * \brief Creates an instance of this class. * * \param patch A reference to an object to be cloned. */ PatchVertex( const PatchVertex< VAttrib , EAttrib , PAttrib >& patch ) { set_edge( patch.get_edge() ) ; set_x_coord( patch.x() ) ; set_y_coord( patch.y() ) ; set_z_coord( patch.z() ) ; this->_attributes = patch._attributes ; return ; }
void gen_geo_graph(char graph[MAX_NR_VERTICES][MAX_NR_VERTICESdiv8], char block[MAX_NR_VERTICES][MAX_NR_VERTICESdiv8], long order, double dist, int dim, long part, int wrap, int dflag, long *size, FILE *file ) { long i,j,k; double d; double *vert; printf("Generating a geometric graph on %ld vertices.\n\ Distance is %f.\n\ Dimension of %d\n\ There is a %ld colouring\n",order,sqrt(dist),dim,part); vert = (double *) malloc(sizeof(double)*dim*order); *size = 0; if(part > order) part = order; /* to randomize assign edges in random order */ /* Still not completely random order - all edges to a vertex are assigned at once - how to do this without too much memory?? */ for (i=0;i<dim;i++) vert[i] = dblrand(); for(i=1;i<order;i++) { for (j=0;j<dim;j++) vert[i*dim+j] = dblrand(); for (j=0;j<i;j++) { d = distance(vert,dim,i,j,dim-1,wrap); if ( (dflag && (d <= dist) && (!get_edge(i,j,block))) || (!dflag && (d > dist) && (!get_edge(i,j,block)))) { set_edge(i,j,1,graph); (*size)++; if (file != NULL) { for(k=0;k<dim;k++) fprintf(file,"%14.12f ",vert[i*dim+k]); fprintf(file,"\n"); for(k=0;k<dim;k++) fprintf(file,"%14.12f ",vert[j*dim+k]); fprintf(file,"\n\n"); } } } } }
/** * \fn PatchVertex( unsigned e , double x , double y , double z ) * * \brief Creates an instance of this class. * * \param e Index of a surface patch edge incident with this * vertex. * \param x The first Cartesian coordinate of the vertex location. * \param y The second Cartesian coordinate of the vertex * location. * \param z The third Cartesian coordinate of the vertex location. */ PatchVertex( unsigned e , double x , double y , double z ) { set_edge( e ) ; set_x_coord( x ) ; set_y_coord( y ) ; set_z_coord( z ) ; return ; }
void BiGraph::read_file(const char *filename) { cout << "Reading " << filename << endl; ifstream ifs; vector<string> ret; string line; ifs.open(filename, ios::in); while(getline(ifs, line)) { ret = split(line,"\t"); string u = ret.at(0); string v = ret.at(1); uint w = atoi(ret.at(2).c_str()); set_edge(u, v, w); } ifs.close(); }
SubdivPatch1Base::SubdivPatch1Base (const unsigned int gID, const unsigned int pID, const unsigned int subPatch, const SubdivMesh *const mesh, const Vec2f uv[4], const float edge_level[4], const int subdiv[4], const int simd_width) : geom(gID),prim(pID),flags(0),type(INVALID_PATCH) { static_assert(sizeof(SubdivPatch1Base) == 5 * 64, "SubdivPatch1Base has wrong size"); mtx.reset(); const HalfEdge* edge = mesh->getHalfEdge(pID); if (edge->patch_type == HalfEdge::REGULAR_QUAD_PATCH) { #if PATCH_USE_BEZIER_PATCH type = BEZIER_PATCH; new (patch_v) BezierPatch3fa(BSplinePatch3fa(CatmullClarkPatch3fa(edge,mesh->getVertexBuffer()))); #else type = BSPLINE_PATCH; new (patch_v) BSplinePatch3fa(CatmullClarkPatch3fa(edge,mesh->getVertexBuffer())); // FIXME: init BSpline directly from half edge structure #endif } #if PATCH_USE_GREGORY == 2 else if (edge->patch_type == HalfEdge::IRREGULAR_QUAD_PATCH) { type = GREGORY_PATCH; new (patch_v) DenseGregoryPatch3fa(GregoryPatch3fa(CatmullClarkPatch3fa(edge,mesh->getVertexBuffer()))); } #endif else { type = EVAL_PATCH; set_edge(mesh->getHalfEdge(pID)); set_subPatch(subPatch); } for (size_t i=0; i<4; i++) { u[i] = (unsigned short)(uv[i].x * 65535.0f); v[i] = (unsigned short)(uv[i].y * 65535.0f); } updateEdgeLevels(edge_level,subdiv,mesh,simd_width); }
/* Build ring of nodes and edges around the current hex */ static gboolean build_network(Hex * hex, G_GNUC_UNUSED gpointer closure) { gint idx; for (idx = 0; idx < 6; idx++) { Node *node = NULL; Edge *edge = NULL; if (get_cc_hex(hex, idx) != NULL) node = get_cc_hex_node(hex, idx); if (node == NULL && get_cw_hex(hex, idx) != NULL) node = get_cw_hex_node(hex, idx); if (node == NULL) { node = g_malloc0(sizeof(*node)); node->map = hex->map; node->owner = -1; node->x = hex->x; node->y = hex->y; node->pos = idx; } set_node(hex, idx, node); set_node_hex(hex, idx, hex); if (get_op_hex(hex, idx) != NULL) edge = get_op_hex_edge(hex, idx); if (edge == NULL) { edge = g_malloc0(sizeof(*edge)); edge->map = hex->map; edge->owner = -1; edge->x = hex->x; edge->y = hex->y; edge->pos = idx; } set_edge(hex, idx, edge); set_edge_hex(hex, idx, hex); } return FALSE; }
int glp_wclique_exact(glp_graph *G, int v_wgt, double *sol, int v_set) { /* find maximum weight clique with exact algorithm */ glp_arc *e; int i, j, k, len, x, *w, *ind, ret = 0; unsigned char *a; double s, t; if (v_wgt >= 0 && v_wgt > G->v_size - (int)sizeof(double)) xerror("glp_wclique_exact: v_wgt = %d; invalid parameter\n", v_wgt); if (v_set >= 0 && v_set > G->v_size - (int)sizeof(int)) xerror("glp_wclique_exact: v_set = %d; invalid parameter\n", v_set); if (G->nv == 0) { /* empty graph has only empty clique */ if (sol != NULL) *sol = 0.0; return 0; } /* allocate working arrays */ w = xcalloc(1+G->nv, sizeof(int)); ind = xcalloc(1+G->nv, sizeof(int)); len = G->nv; /* # vertices */ len = len * (len - 1) / 2; /* # entries in lower triangle */ len = (len + (CHAR_BIT - 1)) / CHAR_BIT; /* # bytes needed */ a = xcalloc(len, sizeof(char)); memset(a, 0, len * sizeof(char)); /* determine vertex weights */ s = 0.0; for (i = 1; i <= G->nv; i++) { if (v_wgt >= 0) { memcpy(&t, (char *)G->v[i]->data + v_wgt, sizeof(double)); if (!(0.0 <= t && t <= (double)INT_MAX && t == floor(t))) { ret = GLP_EDATA; goto done; } w[i] = (int)t; } else w[i] = 1; s += (double)w[i]; } if (s > (double)INT_MAX) { ret = GLP_EDATA; goto done; } /* build the adjacency matrix */ for (i = 1; i <= G->nv; i++) { for (e = G->v[i]->in; e != NULL; e = e->h_next) { j = e->tail->i; /* there exists edge (j,i) in the graph */ if (i > j) set_edge(G->nv, a, i, j); } for (e = G->v[i]->out; e != NULL; e = e->t_next) { j = e->head->i; /* there exists edge (i,j) in the graph */ if (i > j) set_edge(G->nv, a, i, j); } } /* find maximum weight clique in the graph */ len = wclique(G->nv, w, a, ind); /* compute the clique weight */ s = 0.0; for (k = 1; k <= len; k++) { i = ind[k]; xassert(1 <= i && i <= G->nv); s += (double)w[i]; } if (sol != NULL) *sol = s; /* mark vertices included in the clique */ if (v_set >= 0) { x = 0; for (i = 1; i <= G->nv; i++) memcpy((char *)G->v[i]->data + v_set, &x, sizeof(int)); x = 1; for (k = 1; k <= len; k++) { i = ind[k]; memcpy((char *)G->v[i]->data + v_set, &x, sizeof(int)); } } done: /* free working arrays */ xfree(w); xfree(ind); xfree(a); return ret; }
void init_chip_spi_config(void) { set_edge(170); /* clock switch interrupt */ set_edge(171); /* riu/xiu timerout interrupt */ set_edge(172); /* scu event abort interrupt */ /* neon/fpu exception flag */ set_edge(174); set_edge(175); set_edge(176); set_edge(177); set_edge(178); set_edge(179); set_edge(180); /* neon/fpu exception flag */ set_edge(183); set_edge(184); set_edge(185); set_edge(186); set_edge(187); set_edge(188); set_edge(189); /* neon/fpu exception flag */ set_edge(192); set_edge(193); set_edge(194); set_edge(195); set_edge(196); set_edge(197); set_edge(198); /* neon/fpu exception flag */ set_edge(201); set_edge(202); set_edge(203); set_edge(204); set_edge(205); set_edge(206); set_edge(207); }
static void edge_test(struct test *t, enum mask mask, enum edge edge, enum target target) { struct test_target out, ref; XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff }; Picture src_ref, src_out; XTriangle tri; unsigned step, max; test_target_create_render(&t->out, target, &out); set_edge(t->out.dpy, out.picture, edge); src_out = XRenderCreateSolidFill(t->out.dpy, &white); test_target_create_render(&t->ref, target, &ref); set_edge(t->ref.dpy, ref.picture, edge); src_ref = XRenderCreateSolidFill(t->ref.dpy, &white); printf("Testing edges (with mask %s and %s edges) (%s): ", mask_name(mask), edge_name(edge), test_target_name(target)); fflush(stdout); max = 2*(out.width + 128 + out.height+128); step = 0; for (step = 0; step <= max; step++) { char buf[80]; step_to_point(step, out.width, out.height, &tri.p1); step_to_point(step + out.width + 128, out.width, out.height, &tri.p2); step_to_point(step + out.height + 128 + 2*(out.width + 128), out.width, out.height, &tri.p3); sprintf(buf, "tri=((%d, %d), (%d, %d), (%d, %d))\n", tri.p1.x >> 16, tri.p1.y >> 16, tri.p2.x >> 16, tri.p2.y >> 16, tri.p3.x >> 16, tri.p3.y >> 16); clear(&t->out, &out); XRenderCompositeTriangles(t->out.dpy, PictOpSrc, src_out, out.picture, mask_format(t->out.dpy, mask), 0, 0, &tri, 1); clear(&t->ref, &ref); XRenderCompositeTriangles(t->ref.dpy, PictOpSrc, src_ref, ref.picture, mask_format(t->ref.dpy, mask), 0, 0, &tri, 1); test_compare(t, out.draw, out.format, ref.draw, ref.format, 0, 0, out.width, out.height, buf); } XRenderFreePicture(t->out.dpy, src_out); test_target_destroy_render(&t->out, &out); XRenderFreePicture(t->ref.dpy, src_ref); test_target_destroy_render(&t->ref, &ref); printf("pass\n"); }
/** * ==================================================================== * setup_gpios fn: calls fns that export the desired gpios and sets * their edges * ==================================================================== * author(s): Stephan Greto-McGrath * ==================================================================== */ void setup_gpios(){ gpio_export(gpio1); gpio_export(gpio2); set_edge(gpio1,3); set_edge(gpio2,3); }
static void edge_test(struct test *t, enum mask mask, enum edge edge, enum target target) { struct test_target out, ref; XRenderColor white = { 0xffff, 0xffff, 0xffff, 0xffff }; Picture src_ref, src_out; XTrapezoid trap; int left_or_right, p; test_target_create_render(&t->out, target, &out); set_edge(t->out.dpy, out.picture, edge); src_out = XRenderCreateSolidFill(t->out.dpy, &white); test_target_create_render(&t->ref, target, &ref); set_edge(t->ref.dpy, ref.picture, edge); src_ref = XRenderCreateSolidFill(t->ref.dpy, &white); printf("Testing edges (with mask %s and %s edges) (%s): ", mask_name(mask), edge_name(edge), test_target_name(target)); fflush(stdout); for (left_or_right = 0; left_or_right <= 1; left_or_right++) { for (p = -64; p <= out.width + 64; p++) { char buf[80]; if (left_or_right) { trap.left.p1.x = 0; trap.left.p1.y = 0; trap.left.p2.x = 0; trap.left.p2.y = out.height << 16; trap.right.p1.x = p << 16; trap.right.p1.y = 0; trap.right.p2.x = out.width << 16; trap.right.p2.y = out.height << 16; } else { trap.right.p1.x = out.width << 16; trap.right.p1.y = 0; trap.right.p2.x = out.width << 16; trap.right.p2.y = out.height << 16; trap.left.p1.x = 0; trap.left.p1.y = 0; trap.left.p2.x = p << 16; trap.left.p2.y = out.height << 16; } trap.top = 0; trap.bottom = out.height << 16; sprintf(buf, "trap=((%d, %d), (%d, %d)), ((%d, %d), (%d, %d))\n", trap.left.p1.x >> 16, trap.left.p1.y >> 16, trap.left.p2.x >> 16, trap.left.p2.y >> 16, trap.right.p1.x >> 16, trap.right.p1.y >> 16, trap.right.p2.x >> 16, trap.right.p2.y >> 16); clear(&t->out, &out); XRenderCompositeTrapezoids(t->out.dpy, PictOpSrc, src_out, out.picture, mask_format(t->out.dpy, mask), 0, 0, &trap, 1); clear(&t->ref, &ref); XRenderCompositeTrapezoids(t->ref.dpy, PictOpSrc, src_ref, ref.picture, mask_format(t->ref.dpy, mask), 0, 0, &trap, 1); test_compare(t, out.draw, out.format, ref.draw, ref.format, 0, 0, out.width, out.height, buf); } } XRenderFreePicture(t->out.dpy, src_out); test_target_destroy_render(&t->out, &out); XRenderFreePicture(t->ref.dpy, src_ref); test_target_destroy_render(&t->ref, &ref); printf("pass\n"); }