static void clean_vertex(vertex_t* v) { int i; for (i = 0; i < NSETS; i += 1) free_set(v->set[i]); free_set(v->prev); free(v->succ); free_list(&v->pred); }
/** * This is the function that should be used to free the set structure. Since * it's a dag, a recursive free function won't work. Every time we create * a set element, we put it in the hash table, so this is OK. */ void free_parse_info(Parse_info pi) { int i, len; X_table_connector *t, *x; len = pi->N_words; xfree(pi->chosen_disjuncts, len * sizeof(Disjunct *)); xfree(pi->image_array, len * sizeof(Image_node*)); xfree(pi->has_fat_down, len * sizeof(Boolean)); for (i=0; i<pi->x_table_size; i++) { for(t = pi->x_table[i]; t!= NULL; t=x) { x = t->next; free_set(t->set); xfree((void *) t, sizeof(X_table_connector)); } } pi->parse_set = NULL; /*printf("Freeing x_table of size %d\n", x_table_size);*/ xfree((void *) pi->x_table, pi->x_table_size * sizeof(X_table_connector*)); pi->x_table_size = 0; pi->x_table = NULL; xfree((void *) pi, sizeof(struct Parse_info_struct)); }
static void free_chip(sensors_chip *chip) { int i; for (i = 0; i < chip->chips.fits_count; i++) free_chip_name(&chip->chips.fits[i]); free(chip->chips.fits); chip->chips.fits_count = chip->chips.fits_max = 0; for (i = 0; i < chip->labels_count; i++) free_label(&chip->labels[i]); free(chip->labels); chip->labels_count = chip->labels_max = 0; for (i = 0; i < chip->sets_count; i++) free_set(&chip->sets[i]); free(chip->sets); chip->sets_count = chip->sets_max = 0; for (i = 0; i < chip->computes_count; i++) free_compute(&chip->computes[i]); free(chip->computes); chip->computes_count = chip->computes_max = 0; for (i = 0; i < chip->ignores_count; i++) free_ignore(&chip->ignores[i]); free(chip->ignores); chip->ignores_count = chip->ignores_max = 0; }
int free_set(set_t** set) { set_t* left; set_t* right; int n; assert(set != NULL); if (*set == NULL) return 0; n = 1; left = (*set)->left; right = (*set)->right; free(*set); *set = NULL; n += free_set(&left); n += free_set(&right); return n; }
void fill_predict_set(void) { GRAMMAR *G_ptr; TOKEN *ptr , *first , *follow , *predict; SET *set_ptr , *set_srtat , *set_end; predict = (TOKEN*) malloc(sizeof(TOKEN)); predict->set = NULL; predict->next = NULL; strncpy( predict->string , "predict" , strlen("predict")+1 ); for ( G_ptr = G_start ; G_ptr != NULL ; G_ptr = G_ptr->next ) { set_srtat = NULL; set_end = NULL; //predict = search_token( predict_set_start , G_ptr->lhs ); for ( ptr = G_ptr->rhs_string ; ptr != NULL ; ptr = ptr->next ) { first = search_token( first_set_start , ptr->string ); if ( first == NULL ) { continue; } else if ( search_set( first , "£f" ) == TRUE ) { add_set( predict , first ); delete_set( &(predict->set) , "£f" ); continue; } else { add_set( predict , first ); break; } } if ( ptr == NULL ) { follow = search_token( follow_set_start , G_ptr->lhs ); add_set( predict , follow ); } for( set_ptr = predict->set ; set_ptr != NULL ; set_ptr = set_ptr->next ) { insert_predict( &set_srtat , &set_end , set_ptr->string ); //printf("%s ",set_ptr->string); } G_ptr->set = set_srtat; //printf("\n"); //view_token(predict); free_set(&(predict->set)); } }
int free_token( TOKEN **free_start ) { TOKEN *ptr; ptr = *free_start; while ( *free_start != NULL ) { ptr = *free_start; *free_start = (*free_start)->next; free_set( &(ptr->set) ); free(ptr); } }
/* process a single dir for cleaning. dir can be a $PKGDIR, $PKGDIR/All/, $PKGDIR/$CAT */ static uint64_t qpkg_clean_dir(char *dirp, set *vdb) { set *ll = NULL; struct dirent **fnames; int i, count; char buf[_Q_PATH_MAX * 2]; struct stat st; uint64_t num_all_bytes = 0; size_t disp_units = 0; char **t; bool ignore; if (dirp == NULL) return 0; if (chdir(dirp) != 0) return 0; if ((count = scandir(".", &fnames, filter_tbz2, alphasort)) < 0) return 0; /* create copy of vdb with only basenames */ for ((void)list_set(vdb, &t); *t != NULL; t++) ll = add_set_unique(basename(*t), ll, &ignore); for (i = 0; i < count; i++) { fnames[i]->d_name[strlen(fnames[i]->d_name)-5] = 0; if (contains_set(fnames[i]->d_name, ll)) continue; snprintf(buf, sizeof(buf), "%s.tbz2", fnames[i]->d_name); if (lstat(buf, &st) != -1) { if (S_ISREG(st.st_mode)) { disp_units = KILOBYTE; if ((st.st_size / KILOBYTE) > 1000) disp_units = MEGABYTE; num_all_bytes += st.st_size; qprintf(" %s[%s%s %3s %s %s%s]%s %s%s/%s%s\n", DKBLUE, NORM, GREEN, make_human_readable_str(st.st_size, 1, disp_units), disp_units == MEGABYTE ? "M" : "K", NORM, DKBLUE, NORM, CYAN, basename(dirp), fnames[i]->d_name, NORM); } if (!pretend) unlink(buf); } } free_set(ll); scandir_free(fnames, count); return num_all_bytes; }
/* * Frees the symbol table (scope nodes) from memory contained in the master list (allScopes) */ void symtab_destroy() { struct scope_t *it = allScopes; struct scope_t *curr = allScopes; while(it != NULL) { curr = it; it = curr->next; free_set(curr->temps); //free_symbol_list(curr->symbol_list); free(curr); } allScopes = NULL; rootScope = NULL; }
set_t put_set(set_t s, int id) { set_head_t *sh = get_set_head(s); int cap = sh->capacity; int sz = sh->size; int tsz = sh->table_size; int *ht = s + cap; int *bt = ht + tsz; int index; if (sz == cap) { set_t ns = alloc_set_inner(sh->properties, sz * 2); int i; if (sh->properties & SP_MAP) { ptr_t *mt = (ptr_t *) (bt + tsz); for (i=0; i<sz; i++) associate_set(ns, s[i], mt[i]); } else for (i=0; i<sz; i++) put_set(ns, s[i]); set_header_set(ns, sh->header); free_set(s); return put_set(ns, id); } index = probe(ht, bt, cap, tsz, id); if (index < 0) { pretty_print_set(stderr, s); fprintf(stderr, "id: %i\n", id); } assert (index >= 0); if (ht[index] == id && bt[index] >= 0) return s; s[sz] = id; ht[index] = id; bt[index] = sz; sh->size ++; return s; }
int free_grammar() { GRAMMAR *ptr; //ptr = G_start; while( G_start != NULL ) { ptr = G_start; G_start = G_start->next; free_token( &(ptr->rhs_string) ); free_set( &(ptr->set) ); free(ptr); } }
/* figure out what dirs we want to process for cleaning and display results. */ static int qpkg_clean(char *dirp) { int i, count; size_t disp_units = 0; uint64_t num_all_bytes; struct dirent **dnames; set *vdb; if (chdir(dirp) != 0) return 1; if ((count = scandir(".", &dnames, filter_hidden, alphasort)) < 0) return 1; vdb = get_vdb_atoms(portroot, portvdb, 1); if (eclean) { size_t n; const char *overlay; array_for_each(overlays, n, overlay) cache_foreach_pkg(portroot, overlay, qpkg_cb, vdb, NULL); } num_all_bytes = qpkg_clean_dir(dirp, vdb); for (i = 0; i < count; i++) { char buf[_Q_PATH_MAX * 2]; snprintf(buf, sizeof(buf), "%s/%s", dirp, dnames[i]->d_name); num_all_bytes += qpkg_clean_dir(buf, vdb); } scandir_free(dnames, count); free_set(vdb); disp_units = KILOBYTE; if ((num_all_bytes / KILOBYTE) > 1000) disp_units = MEGABYTE; qprintf(" %s*%s Total space that would be freed in packages " "directory: %s%s %c%s\n", GREEN, NORM, RED, make_human_readable_str(num_all_bytes, 1, disp_units), disp_units == MEGABYTE ? 'M' : 'K', NORM); return 0; }
void kruskal() { qsort(paths, edge_num, sizeof(edge), cmp_edge); init_set(); int min = 0, k = 0, i; for (i = 0; i < edge_num; i++) { if (union_set(paths[i].u, paths[i].v)) { min += paths[i].w; mst[k++] = i; } if (k == n-1) break; } free_set(); }
// Remove val from the set if it exists void set_remove(struct set_t *set, const char *val) { if(set == NULL || val == NULL) return; // Find val in the set and fix up pointers in the set struct set_t *set_it = set; struct set_t *set_last = set; while(set_it != NULL) { // Val exists, unlink the current set node if(strcmp(set_it->value, val) == 0) { set_last->next = set_it->next; free_set(set_it); return; } set_last = set_it; set_it = set_it->next; } }
void free_x_table(Parse_info * pi) { /* This is the function that should be used to free tha set structure. Since it's a dag, a recursive free function won't work. Every time we create a set element, we put it in the hash table, so this is OK.*/ int i; X_table_connector *t, *x; if (pi->x_table == NULL) { /*fprintf(stderr, "Warning: Tried to free a NULL x_table\n");*/ return; } for (i=0; i<pi->x_table_size; i++) { for(t = pi->x_table[i]; t!= NULL; t=x) { x = t->next; free_set(t->set); xfree((void *) t, sizeof(X_table_connector)); } } /*printf("Freeing x_table of size %d\n", x_table_size);*/ xfree((void *) pi->x_table, pi->x_table_size * sizeof(X_table_connector*)); pi->x_table_size = 0; pi->x_table = NULL; }
/** * This is the function that should be used to free the set structure. Since * it's a dag, a recursive free function won't work. Every time we create * a set element, we put it in the hash table, so this is OK. */ void free_parse_info(Parse_info pi) { unsigned int i; X_table_connector *t, *x; if (!pi) return; for (i=0; i<pi->x_table_size; i++) { for (t = pi->x_table[i]; t!= NULL; t=x) { x = t->next; free_set(&t->set); xfree((void *) t, sizeof(X_table_connector)); } } pi->parse_set = NULL; /*printf("Freeing x_table of size %d\n", x_table_size);*/ xfree((void *) pi->x_table, pi->x_table_size * sizeof(X_table_connector*)); pi->x_table_size = 0; pi->x_table = NULL; xfree((void *) pi, sizeof(struct Parse_info_struct)); }
void setCover(Universe *Uni,int num_houses) { Heap *Q = createHeap(); set_t *covered = create_set(num_houses); for(int i=0;i<Uni->size_of_universe;i++) { insert_in_heap(Q,i,Uni->sets[i].covered_items,max_func); } while(covered->covered_items < num_houses) { if(isEmpty(Q)) { break; } HeapItem max = removeTop(Q,max_func); //updating the covered set for(int i=0;i<Uni->sets[max.dataIndex].covered_items;i++) { //if its not covered if(!covered->set[Uni->sets[max.dataIndex].set[i]]) { //set to the house being covered covered->set[Uni->sets[max.dataIndex].set[i]] = 1; //increment number of covered houses covered->covered_items++; } } //flag the current set to be covered Uni->sets[max.dataIndex].covered = 1; //update the other sets for(int i=0;i<Uni->size_of_universe;i++) { //if they are not already covered if(!Uni->sets[i].covered) { //find set diff and update the heap int diff = set_diff(&Uni->sets[i],covered); changeKey(Q,i,diff,max_func); } } } if(covered->covered_items < num_houses) { fprintf(stderr, "Not enough houses to cover all houses.\n"); exit(EXIT_FAILURE); } for(int i=0; i<Uni->size_of_universe;i++) { if(Uni->sets[i].covered) { printf("%d\n",i); } } destroyHeap(Q); free_set(covered); free_Universe(Uni); }
///identifies edges which are not surrounded by triangles - locations where the surface ///is non manifold. ///This turns the edges variable non-null. // //NOTE: THIS FUNCTION IS CURRENTLY BROKEN // // void SurfaceObject::identifyNonManifoldEdges(void) { int i = 0; int j = 0; ///create a set of sets to hold non-manifold edges set_t nonManifold = alloc_set(SP_MAP); ///Create a set of sets to remember which triangles associate with which vertex. Allocate that here. set_t verticesMappingToTris = alloc_set(SP_MAP); for(i = 0; i<numPoints; i++){ set_t tris = alloc_set(0); verticesMappingToTris = associate_set(verticesMappingToTris, i, tris); } ///associate each vertex with a list of triangles it is part of. ///we do this by interating through all triangles set_t tris; for(i = 0; i<numTriangles; i++){ tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+0]); tris = put_set(tris, i); verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+0], tris); tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+1]); tris = put_set(tris, i); verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+1], tris); tris = (set_t) mapsto_set(verticesMappingToTris, triangles[3*i+2]); tris = put_set(tris, i); verticesMappingToTris = associate_set(verticesMappingToTris, triangles[3*i+2], tris); } int min = 100000; int max = 0; int counter = 0; for(i = 0; i<size_set(verticesMappingToTris); i++){ tris = (set_t) mapsto_set(verticesMappingToTris, verticesMappingToTris[i]); if(min > size_set(tris)){ min = size_set(tris); if(size_set(tris) == 0){ counter++; } } if(max < size_set(tris)){ max = size_set(tris); } } printf("MAXIMUM NUMBER OF TRIANLGES ASSOCIATED WITH A point: %i\n", max); printf("MINIMUM NUMBER OF TRIANLGES ASSOCIATED WITH A point: %i (total 0: %i)\n", min, counter); set_t set1; set_t set2; set_t tempSet; int numCommon; int * tri = new int[3]; ///iterate through all triangles, for(i = 0; i<numTriangles; i++){ tri[0] = triangles[3*i+0]; tri[1] = triangles[3*i+1]; tri[2] = triangles[3*i+2]; ///for each edge on the triangle, verify that exactly two ///distinct triangles are part of that edge. otherwise it is ///a non-manifold edge. for(j = 0; j<3; j++){ //set the two vertices of the edge we are working on int t1 = tri[(j+0)%3]; int t2 = tri[(j+1)%3]; //identify the set of triangles adjacent to each endpoint set1 = (set_t) mapsto_set(verticesMappingToTris, t1); set2 = (set_t) mapsto_set(verticesMappingToTris, t2); ///find out how many triangles are common between these endpoints numCommon = countNumCommon(set1, set2); //if numCommon == 1, then this is an edge of a nonmanifold surface. Store it. if(numCommon == 1){ if(!contains_set(nonManifold, t1)){ tempSet = alloc_set(0); } else{ tempSet = (set_t) mapsto_set(nonManifold, t1); } tempSet = put_set(tempSet, t2); nonManifold = associate_set(nonManifold, t1, tempSet); if(!contains_set(nonManifold, t2)){ tempSet = alloc_set(0); } else{ tempSet = (set_t) mapsto_set(nonManifold, t2); } tempSet = put_set(tempSet, t1); nonManifold = associate_set(nonManifold, t2, tempSet); // printf("Edge: %i %i\n", t1, t2); } //if numCommon is zero, then there is a serious issue with triangle topology. Report it. if(numCommon == 0){ printf("ERROR: Two vertices of the same triangle (vertex %i and %i in triangle %i) \n", t1, t2, i); printf("ERROR: are not members of at least one triangle, according to our data!!\n"); } //if numCommon is greater than two, there is impossible surface occuring. Report it. if(numCommon > 2){ printf("ERROR: Vertices %i and %i appear to be adjacent to an edge which is part of \n", t1, t2); printf("ERROR: more than two triangles, creating a non-manifold surface! error!\n"); } ///if numCommon is equal to two, that is fine. Report nothing. } ///The end of this loop creates a list of non-manifold edges at the border of the surface, if it exists. } edges = nonManifold; delete[](tri); //free the data structure for(i = 0; i<numPoints; i++){ tris = (set_t) mapsto_set(verticesMappingToTris, i); free_set(tris); } free_set(verticesMappingToTris); }
int smo(bow_wv **docs, int *yvect, double *weights, double *a_b, double **W, int ndocs, double *error, float *cvect, int *nsv) { int changed; int inspect_all; struct svm_smo_model model; int nchanged; int num_words; double *original_weights; int i,j,k,n; num_words = bow_num_words(); m1 = m2 = m3 = m4 = 0; model.n_pair_suc = model.n_pair_tot = model.n_single_suc = model.n_single_tot = model.n_outer = 0; model.nsv = *nsv; model.docs = docs; model.error = error; model.ndocs = ndocs; model.cvect = cvect; original_weights = NULL; if (svm_kernel_type == 0 && !(*W)) { *W = model.W = (double *) malloc(sizeof(double)*num_words); } else { model.W = NULL; } model.weights = weights; model.yvect = yvect; /* figure out the # of positives */ for (i=j=k=n=0; i<ndocs; i++) { if (yvect[i] == 1) { k = i; j++; } else { n = i; } } /* k is set to the last positive example found, n is the last negative */ make_set(ndocs,ndocs,&(model.I0)); make_set(ndocs,j,&(model.I1)); make_set(ndocs,ndocs-j,&(model.I2)); make_set(ndocs,j,&(model.I3)); make_set(ndocs,ndocs-j,&(model.I4)); /* this is the code which initializes the sets according to the weights values */ for (i=0; i<ndocs; i++) { struct set *s; if (weights[i] > svm_epsilon_a && weights[i] < cvect[i] - svm_epsilon_a) { s = &(model.I0); } else if (yvect[i] == 1) { if (weights[i] < svm_epsilon_a) s = &(model.I1); else s = &(model.I3); } else { if (weights[i] < svm_epsilon_a) s = &(model.I4); else s = &(model.I2); } set_insert(i, s); } if (model.W) { for (i=0; i<num_words; i++) { model.W[i] = 0.0; } } if (model.I0.ilength == 0) { model.blow = 1; model.bup = -1; model.iup = k; model.ilow = n; error[k] = -1; error[n] = 1; } else { /* compute bup & blow */ int efrom, nitems; int *items; double e; nitems = model.I0.ilength; items = model.I0.items; for (i=0, e=-1*MAXDOUBLE; i<nitems; i++) { if (e < error[items[i]]) { e = error[items[i]]; efrom = items[i]; } } model.blow = e; model.ilow = efrom; for (i=0, e=MAXDOUBLE; i<nitems; i++) { if (e > error[items[i]]) { e = error[items[i]]; efrom = items[i]; } } model.bup = e; model.iup = efrom; if (model.W) { for (i=0; i<nitems; i++) { for (j=0; j<docs[items[i]]->num_entries; j++) { model.W[docs[items[i]]->entry[j].wi] += yvect[items[i]] * weights[items[i]] * docs[items[i]]->entry[j].weight; } } /* also need to include bound sv's (I2 & I3) */ for (k=0, nitems=model.I2.ilength, items=model.I2.items; k<2; k++, nitems=model.I3.ilength, items=model.I3.items) { for (i=0; i<nitems; i++) { for (j=0; j<docs[items[i]]->num_entries; j++) { model.W[docs[items[i]]->entry[j].wi] += yvect[items[i]] * weights[items[i]] * docs[items[i]]->entry[j].weight; } } } } } if (!model.W) { model.W = *W; } if (svm_weight_style == WEIGHTS_PER_MODEL) { kcache_init(ndocs); } inspect_all = 1; nchanged = 0; changed = 0; while (nchanged || inspect_all) { nchanged = 0; #ifdef DEBUG check_inv(&model,ndocs); #endif model.n_outer ++; PRINT_SMO_PROGRESS(stderr, &model); fflush(stderr); if (1 && inspect_all) { int ub = ndocs; i=j=random() % ndocs; for (k=0; k<2; k++,ub=j,i=0) { for (; i<ub; i++) { nchanged += opt_single(i, &model); #ifdef DEBUG check_inv(&model,ndocs); #endif } } inspect_all = 0; } else { /* greg's modification to keerthi, et al's modification 2 */ /* loop of optimizing all pairwise in a row with all elements * in I0 (just like above, but only those in I0) */ do { nchanged = 0; /* here's the continuous iup/ilow loop */ while (1) { if (!set_lookup(model.iup, &(model.I0))) { error[model.iup] = smo_evaluate_error(&model,model.iup); } if (!set_lookup(model.ilow, &(model.I0))) { error[model.ilow] = smo_evaluate_error(&model,model.ilow); } if (opt_pair(model.iup, model.ilow, &model)) { #ifdef DEBUG check_inv(&model,ndocs); #endif nchanged ++; } else { break; } if (model.bup > model.blow - 2*svm_epsilon_crit) break; } if (nchanged) { changed = 1; } nchanged = 0; /* now inspect all of the elements in I0 */ { int ub = ndocs; i=j=random() % ndocs; for (k=0; k<2; k++,ub=j,i=0) { for (; i<ub; i++) { if (set_lookup(i, &(model.I0))) { nchanged += opt_single(i, &model); #ifdef DEBUG check_inv(&model,ndocs); #endif } } } } } while (nchanged); /* of of the loop */ if (nchanged) { changed = 1; } inspect_all = 1; } /* note: both of the above blocks no when they are done so they flip inspect_all */ if (nchanged) { changed = 1; } } free_set(&model.I0); free_set(&model.I1); free_set(&model.I2); free_set(&model.I3); free_set(&model.I4); if (svm_weight_style == WEIGHTS_PER_MODEL) { kcache_clear(); } if (svm_verbosity > 3) fprintf(stderr,"\n"); //printf("bup=%f, blow=%f\n",model.bup,model.blow); *a_b = (model.bup + model.blow) / 2; if (svm_kernel_type == 0) { for (i=j=0; i<num_words; i++) { if (model.W[i] != 0.0) j++; } } //printf("m1: %d, m2: %d, m3: %d, m4: %d", m1,m2,m3,m4); *nsv = model.nsv; return (changed); }
void SurfaceObject::draw(bool drawPoints, bool drawLines, bool drawTransparent, bool pocketView, double * offset, double * c) { int i = 0; int j = 0; int pt1, pt2, pt3; ////Declare Materials GLfloat mat_solid[] = { 1.0, 1.0, 1.0, 1.0 }; GLfloat mat_zero[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat mat_transparent[] = { 0.2, 0.2, 0.2, 0.2 }; GLfloat mat_emission[] = { 0.0, 0.0, 0.0, 1.0 }; GLfloat mat_specular[] = { 0.1, 0.1, 0.1, 0.0 }; GLfloat low_shininess[] = { .5 }; float amb[] = {0.20f, 0.50f, 1.0f, 0.1f}; float diff[] = {0.20f, 0.50f, 1.0f, 0.1f}; float spec[] = {1.0f, 1.0f, 1.0f, 1.0f}; float shine[] = {0.8 * 128.0f}; // The glass is very shiny double * cent = new double[3]; cent[0] = 0; cent[1] = 0; cent[2] = 0; if(offset != NULL){ delete[](cent); cent = offset; } ///drawPoints if(drawPoints){ glBegin(GL_POINTS); glColor3f(1.00000f, 1.00000f, 1.00000f); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); } glEnd(); } if(drawLines){ glBegin(GL_LINES); glColor3f(0.00000f, 1.00000f, 0.00000f); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); } glEnd(); } bool drawNormals = false; if(drawNormals){ glColor3f(1.00000f, 1.00000f, 1.00000f); glBegin(GL_LINES); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; double * p1 = new double[3]; p1[0] = surfacePoints [3*pt1+0]-cent[0]; p1[1] = surfacePoints [3*pt1+1]-cent[1]; p1[2] = surfacePoints [3*pt1+2]-cent[2]; double * p2 = new double[3]; p2[0] = surfacePoints [3*pt2+0]-cent[0]; p2[1] = surfacePoints [3*pt2+1]-cent[1]; p2[2] = surfacePoints [3*pt2+2]-cent[2]; double * p3 = new double[3]; p3[0] = surfacePoints [3*pt3+0]-cent[0]; p3[1] = surfacePoints [3*pt3+1]-cent[1]; p3[2] = surfacePoints [3*pt3+2]-cent[2]; double * v1 = new double[3]; v1[0] = p2[0] - p1[0]; v1[1] = p2[1] - p1[1]; v1[2] = p2[2] - p1[2]; double * v2 = new double[3]; v2[0] = p3[0] - p1[0]; v2[1] = p3[1] - p1[1]; v2[2] = p3[2] - p1[2]; double * cross = crossProd(v1, v2); double * norm = normalizeVector(cross); double * avg = new double[3]; avg[0] = (p1[0]+p2[0]+p3[0])/3; avg[1] = (p1[1]+p2[1]+p3[1])/3; avg[2] = (p1[2]+p2[2]+p3[2])/3; double * newPt = new double[3]; newPt[0] = avg[0] + norm[0]; newPt[1] = avg[1] + norm[1]; newPt[2] = avg[2] + norm[2]; glVertex3f( avg[0], avg[1], avg[2] ); glVertex3f( newPt[0], newPt[1], newPt[2] ); //printf("vectorSize: %lf\n", vectorSize( newPt[0]-avg[0], newPt[1]-avg[1], newPt[2]-avg[2]) ); delete[](p1); delete[](p2); delete[](p3); delete[](v1); delete[](v2); delete[](cross); delete[](norm); delete[](avg); delete[](newPt); } glEnd(); } //set material properties if(drawTransparent == true){ glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, 0); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, amb); glMaterialfv(GL_FRONT_AND_BACK, GL_DIFFUSE, diff); glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, spec); glMaterialfv(GL_FRONT_AND_BACK, GL_SHININESS, shine); glEnable(GL_BLEND); glDepthMask(GL_FALSE); // glBlendFunc(GL_SRC_ALPHA, GL_ONE); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); } else{ glMaterialfv(GL_FRONT, GL_EMISSION, mat_zero); glMaterialfv(GL_FRONT, GL_DIFFUSE, mat_solid); } double * color = new double[3]; if(c != NULL){ color[0] = c[0]; color[1] = c[1]; color[2] = c[2]; } else{ if(drawTransparent){ color[0] = 0.5f; color[1] = 0.5f; color[2] = 0.0f; } else{ color[0] = 0.0f; color[1] = 0.5f; color[2] = 0.5f; } } set_t debug_triangleSet = alloc_set(0); // debug_triangleSet = put_set(debug_triangleSet, 37); // debug_triangleSet = put_set(debug_triangleSet, 38); // debug_triangleSet = put_set(debug_triangleSet, 39); // debug_triangleSet = put_set(debug_triangleSet, 213); // debug_triangleSet = put_set(debug_triangleSet, 215); ///render the triangles glBegin(GL_TRIANGLES); for(i = 0; i<numTriangles; i++){ pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; double s = 1.00; ///surface geometry hack - scales up slightly so there isnt so much z-buffer collision. // if(i == 215){ glColor4f(1, 0, 0, .5); } if(drawTransparent){///surface geometry hack glColor4f(color[0], color[1], color[2], .5); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, .5); } glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( s*(surfacePoints [3*pt1+0]-cent[0]),s*(surfacePoints [3*pt1+1]-cent[1]),s*(surfacePoints [3*pt1+2]-cent[2]) ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( s*(surfacePoints [3*pt2+0]-cent[0]),s*(surfacePoints [3*pt2+1]-cent[1]),s*(surfacePoints [3*pt2+2]-cent[2]) ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( s*(surfacePoints [3*pt3+0]-cent[0]),s*(surfacePoints [3*pt3+1]-cent[1]),s*(surfacePoints [3*pt3+2]-cent[2]) ); } else{ if(colorFlag == true){ glColor4f( colors[3*pt1+0], colors[3*pt1+1], colors[3*pt1+2], 1.0 ); glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glColor4f( colors[3*pt2+0], colors[3*pt2+1], colors[3*pt2+2], 1.0 ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glColor4f( colors[3*pt3+0], colors[3*pt3+1], colors[3*pt3+2], 1.0 ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); } else{ glColor4f(color[0], color[1], color[2], 1.0); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, 1); } glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); } } } for(i = 0; i<numTriangles; i++){ double s = 1.00; ///surface geometry hack - scales up slightly so there isnt so much z-buffer collision. pt1 = triangles[3*i+0]; pt2 = triangles[3*i+1]; pt3 = triangles[3*i+2]; if(pocketView){/// we render both sides by drawing backwards triangles too. //glColor4f(color[0]/2, color[1]/2, color[2]/2, 1.0); if(drawTransparent){///surface geometry hack glColor4f(color[0], color[1], color[2], .3); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, .5); } glNormal3f( -surfaceNormals[3*pt1+0], -surfaceNormals[3*pt1+1], -surfaceNormals[3*pt1+2] ); glVertex3f( s*(surfacePoints [3*pt1+0]-cent[0]),s*(surfacePoints [3*pt1+1]-cent[1]),s*(surfacePoints [3*pt1+2]-cent[2]) ); glNormal3f( -surfaceNormals[3*pt3+0], -surfaceNormals[3*pt3+1], -surfaceNormals[3*pt3+2] ); glVertex3f( s*(surfacePoints [3*pt3+0]-cent[0]),s*(surfacePoints [3*pt3+1]-cent[1]),s*(surfacePoints [3*pt3+2]-cent[2]) ); glNormal3f( -surfaceNormals[3*pt2+0], -surfaceNormals[3*pt2+1], -surfaceNormals[3*pt2+2] ); glVertex3f( s*(surfacePoints [3*pt2+0]-cent[0]),s*(surfacePoints [3*pt2+1]-cent[1]),s*(surfacePoints [3*pt2+2]-cent[2]) ); } else{ glColor4f(color[0]/4, color[1]/4, color[2]/4, 1.0); glColor3f(0.00000f, 0.250000f, 0.2500000f); if( contains_set(debug_triangleSet, i) ){ glColor4f(1, 0, 0, 1); } glNormal3f( surfaceNormals[3*pt1+0], surfaceNormals[3*pt1+1], surfaceNormals[3*pt1+2] ); glVertex3f( surfacePoints [3*pt1+0]-cent[0],surfacePoints [3*pt1+1]-cent[1],surfacePoints [3*pt1+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt3+0], surfaceNormals[3*pt3+1], surfaceNormals[3*pt3+2] ); glVertex3f( surfacePoints [3*pt3+0]-cent[0],surfacePoints [3*pt3+1]-cent[1],surfacePoints [3*pt3+2]-cent[2] ); glNormal3f( surfaceNormals[3*pt2+0], surfaceNormals[3*pt2+1], surfaceNormals[3*pt2+2] ); glVertex3f( surfacePoints [3*pt2+0]-cent[0],surfacePoints [3*pt2+1]-cent[1],surfacePoints [3*pt2+2]-cent[2] ); } } } glEnd(); free_set(debug_triangleSet); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); if( highlights != NULL ){ glBegin(GL_POINTS); for(i = 0; i<numPoints; i++){ if(contains_set(highlights, i)){ //glPushMatrix(); glVertex3f( surfacePoints[3*i+0]-cent[0], surfacePoints[3*i+1]-cent[1], surfacePoints[3*i+2]-cent[2] ); //glTranslatef(surfacePoints[3*i+0], surfacePoints[3*i+1], surfacePoints[3*i+2] ); //glutSolidSphere ( .3, 4, 4) ; //glPopMatrix(); } } glEnd(); } glColor4f(1.0f, 1.0f, 1.0f, 1.0f); if(edges != NULL && drawTransparent == false){ glBegin(GL_LINES); for(i = 0; i<size_set(edges); i++){ set_t tempSet = (set_t) mapsto_set(edges, edges[i]); for(j = 0; j<size_set(tempSet); j++){ if(tempSet[j] > edges[i]){ glVertex3f( surfacePoints[3*edges[i]+0]-cent[0], surfacePoints[3*edges[i]+1]-cent[1], surfacePoints[3*edges[i]+2]-cent[2] ); glVertex3f( surfacePoints[3*tempSet[j]+0]-cent[0], surfacePoints[3*tempSet[j]+1]-cent[1], surfacePoints[3*tempSet[j]+2]-cent[2] ); } } } glEnd(); } ///fix material properties if(drawTransparent == true){ glDepthMask(GL_TRUE); glDisable(GL_BLEND); } if(offset == NULL){ delete[](cent); } delete[](color); }
int comput_first_f( TOKEN *alpha , TOKEN *dst , char *dst_name ) { int change = FALSE; TOKEN *ptr , *ptr2 , *ptr3 , *ptr_end; TOKEN *tmp; is_lambda = FALSE; tmp = (TOKEN*) malloc(sizeof(TOKEN)); strncpy( tmp->string , "tmp" , 4 ); tmp->set = NULL; tmp->next = NULL; if( alpha == NULL ) { is_lambda = TRUE; return FALSE; } if ( strcmp( alpha->string , "£f" ) == 0 ) { //ptr = search_token( dst , dst_name ); //if ( insert_set( ptr , "£f" ) == TRUE ) is_lambda = TRUE; change = TRUE; } else { ptr = search_token( dst , dst_name ); ptr2 = search_token( first_set_start , alpha->string ); add_set( tmp , ptr2 ); delete_set( &(tmp->set) , "£f" ); if ( add_set( ptr , tmp ) == TRUE ) change = TRUE; free_set( &(tmp->set) ); for( ptr3 = alpha ; ptr3 != NULL ; ptr3 = ptr3->next ) { ptr2 = search_token( first_set_start , ptr3->string ); if( search_set( ptr2 , "£f" ) != TRUE ) break; if ( ptr3->next == NULL ) { ptr_end = ptr3; ptr3 = search_token( first_set_start , ptr_end->string ); if( search_set( ptr3 , "£f" ) == TRUE ) { if ( insert_set( ptr , "£f" ) == TRUE ) { is_lambda = TRUE; change = TRUE; } } break; } ptr2 = search_token( first_set_start , ptr3->next->string ); add_set( tmp , ptr2 ); delete_set( &(tmp->set) , "£f" ); if ( add_set( ptr , tmp ) == TRUE ) { delete_set( &(ptr->set) , "£f" ); change = TRUE; } free_set( &(tmp->set) ); } } free_token(&tmp); return change; }
static struct EvalError *check_stdmacro( enum StandardMacro stdmacro, struct Expression *args, size_t n) { size_t length; struct Expression expr; struct Set *set; switch (stdmacro) { case F_DEFINE: case F_SET: if (args[0].type != E_SYMBOL) { return new_eval_error_expr(ERR_TYPE_VAR, args[0]); } break; case F_LAMBDA: expr = args[0]; if (expr.type != E_NULL && expr.type != E_PAIR && expr.type != E_SYMBOL) { return new_syntax_error(expr); } set = new_set(); while (expr.type != E_NULL) { InternId symbol_id; if (expr.type == E_PAIR) { if (expr.box->car.type != E_SYMBOL) { free_set(set); return new_eval_error_expr(ERR_TYPE_VAR, expr.box->car); } symbol_id = expr.box->car.symbol_id; } else if (expr.type == E_SYMBOL) { symbol_id = expr.symbol_id; } else { free_set(set); return new_eval_error_expr(ERR_TYPE_VAR, expr); } if (!add_to_set(set, symbol_id)) { free_set(set); return attach_code( new_eval_error_symbol(ERR_DUP_PARAM, symbol_id), args[0]); } if (expr.type == E_SYMBOL) { break; } expr = expr.box->cdr; } free_set(set); break; case F_UNQUOTE: case F_UNQUOTE_SPLICING: return new_eval_error(ERR_UNQUOTE); case F_COND: for (size_t i = 0; i < n; i++) { if (!count_list(&length, args[i]) || length < 2) { return new_syntax_error(args[i]); } } break; case F_LET: case F_LET_STAR: expr = args[0]; set = new_set(); while (expr.type != E_NULL) { if (expr.type == E_PAIR) { if (!count_list(&length, expr.box->car) || length != 2) { free_set(set); return new_syntax_error(expr.box->car); } if (expr.box->car.box->car.type != E_SYMBOL) { free_set(set); return new_eval_error_expr( ERR_TYPE_VAR, expr.box->car.box->car); } } else { free_set(set); return new_syntax_error(args[0]); } InternId symbol_id = expr.box->car.box->car.symbol_id; if (!add_to_set(set, symbol_id)) { free_set(set); return attach_code( new_eval_error_symbol(ERR_DUP_PARAM, symbol_id), args[0]); } expr = expr.box->cdr; } free_set(set); break; default: break; } return NULL; }