RBDMAPContainerDbAdapter * rb_dmap_container_db_adapter_new (RBPlaylistManager *playlist_manager) { RBDMAPContainerDbAdapter *db; GList *playlists; playlists = rb_playlist_manager_get_playlists (playlist_manager); /* These IDs are DAAP-specific, so they are not a part of the * general-purpose RBPlaylistSource class: */ if (playlists != NULL && playlists->data != NULL) { GList *l; for (l = playlists; l != NULL; l = l->next) { assign_id (playlist_manager, RB_SOURCE (l->data)); } } g_signal_connect (G_OBJECT (playlist_manager), "playlist_created", G_CALLBACK (assign_id), NULL); g_signal_connect (G_OBJECT (playlist_manager), "playlist_added", G_CALLBACK (assign_id), NULL); db = RB_DMAP_CONTAINER_DB_ADAPTER (g_object_new (RB_TYPE_DMAP_CONTAINER_DB_ADAPTER, NULL)); db->priv->playlist_manager = playlist_manager; return db; }
float get_value(char * pch, bool read_only, const char * linebuf_debug, int i){ float ret; if (!fc.rehash_value){ if ( pch[0] == '"' ) { pch++; } ret = atof(pch); } else { uint id; if (read_only){ // find if node was in map std::map<std::string,uint>::iterator it = fc.val_map.string2nodeid.find(pch); if (it != fc.val_map.string2nodeid.end()){ ret = it->second; } else ret = -1; } else { //else enter node into map (in case it did not exist) and return its position assign_id(fc.val_map, id, pch); assert(id < fc.val_map.string2nodeid.size()); ret = id; } } if (std::isnan(ret) || std::isinf(ret)) logstream(LOG_FATAL)<<"Failed to read value (inf/nan) on line: " << i << " " << "[" << linebuf_debug << "]" << std::endl; return ret; }
/** * return a numeric node ID out of the string text read from file (training, validation or test) */ float get_node_id(char * pch, int pos, int token, size_t i, bool read_only = false){ //if (pos>=2) std::cout<<"get_node_id" << pch << " " << pos << " token: " << token << " i " << i << " " << read_only << std::endl; assert(pch != NULL); assert(i >= 0); float ret; //read numeric id if (!fc.hash_strings){ ret = (pos < 2 ? atoi(pch) : atof(pch)); if (pos < 2) ret-=input_file_offset; if (pos == 0 && ret >= M) logstream(LOG_FATAL)<<"Row index larger than the matrix row size " << ret << " > " << M << " in line: " << i << std::endl; else if (pos == 1 && ret >= N) logstream(LOG_FATAL)<<"Col index larger than the matrix row size " << ret << " > " << N << " in line: " << i << std::endl; } //else read string id and assign numeric id else { uint id; assert(pos < (int)fc.node_id_maps.size()); if (read_only){ // find if node was in map std::map<std::string,uint>::iterator it = fc.node_id_maps[pos].string2nodeid.find(pch); if (it != fc.node_id_maps[pos].string2nodeid.end()){ ret = it->second; assert(ret < fc.node_id_maps[pos].string2nodeid.size()); } else ret = -1; } else { //else enter node into map (in case it did not exist) and return its position assign_id(fc.node_id_maps[pos], id, pch); //if (pos>=2) std::cout<<"id assigned: " << pos << " " << id << " " << pch << std::endl; assert(id < fc.node_id_maps[pos].string2nodeid.size()); ret = id; } } if (!read_only) assert(ret != -1); return ret; }
object *baseline(unsigned char *image, unsigned char *mask, int width, int height, int *n_object) { int i = 0, j = 0, k = 0; int n; /* number of objects */ int *area; /* area */ double *len; /* perimeter length */ double *circ; /* circularity index */ double *input_val; /*Color features*/ double *clr_mn_value, *clr_std_dev, *clr_skew, *clr_kurtosis, **clr_hist; /*Texture features*/ double ***glcmat, *ang_sec_mom, *contr, *corr, *var; double *inv_diff_mom, *sum_av, *sum_entrp, *sum_varnc; double *entrp, *diff_var, *diff_entrp; object *obj; /* for storing results */ int **obj_id = (int **)malloc(height*sizeof(int *)); if (obj_id == NULL){ printf("Could not allocate %d bytes.\n", height*sizeof(int *)); exit(0); } else{ for (i = 0; i < height; i++){ obj_id[i] = (int *)malloc(width*sizeof(int)); if (obj_id[i] == NULL){ printf("Could not allocate %d bytes for i=%d index.\n", width*sizeof(int), i); exit(0); } } } /* assign ID to each object and returns the number of objects */ n = assign_id(mask, width, height, obj_id); /* allocate memories */ area = (int *)malloc(n * sizeof(int)); if (area == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(int))); exit(-1); } len = (double *)malloc(n * sizeof(double)); if (len == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } circ = (double *)malloc(n * sizeof(double)); if (circ == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } obj = (object *)malloc(n * sizeof(object)); if (obj == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(object))); exit(-1); } /*Colors*/ clr_mn_value = (double *)malloc(n * sizeof(double)); if (clr_mn_value == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } input_val = (double *)malloc(n * sizeof(double)); if (input_val == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_std_dev = (double *)malloc(n * sizeof(double)); if (clr_std_dev == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_skew = (double *)malloc(n * sizeof(double)); if (clr_skew == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_kurtosis = (double *)malloc(n * sizeof(double)); if (clr_kurtosis == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } clr_hist = (double **)malloc(n*sizeof(double *)); if (clr_hist == NULL){ printf("Could not allocate %d bytes.\n", n*sizeof(double *)); exit(0); } else{ for (i = 0; i < n; i++){ clr_hist[i] = (double *)malloc(256*sizeof(double)); if (clr_hist[i] == NULL){ printf("Could not allocate %d bytes for i=%d index.\n", 256*sizeof(double), i); exit(0); } else{ for (j = 0; j<256; j++){ clr_hist[i][j] = 0.0; } } } } /*Texture*/ glcmat = (double ***)malloc(n * sizeof(double**)); if (glcmat == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double**))); exit(-1); } else{ for (i = 0;i < n; i++){ glcmat[i] = (double **)malloc(256 * sizeof(double *)); if (glcmat[i] == NULL){ printf("Cannot allocate %d bytes for memory.\n", (256 * sizeof(double *))); exit(-1); } else{ for (j = 0;j < 256; j++){ glcmat[i][j] = (double *)malloc(256 * sizeof(double)); if (glcmat[i][j] == NULL){ printf("Cannot allocate %d bytes for memory.\n", (256 * sizeof(double))); exit(-1); } else{ for (k = 0;k < 256;k++){ glcmat[i][j][k] = 0.0; } } }/*for j*/ } }/*for i*/ } ang_sec_mom = (double *)malloc(n * sizeof(double)); if (ang_sec_mom == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(ang_sec_mom, 0, (n * sizeof(double))); contr = (double *)malloc(n * sizeof(double)); if (contr == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(contr, 0, (n * sizeof(double))); corr = (double *)malloc(n * sizeof(double)); if (corr == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(corr, 0, (n * sizeof(double))); var = (double *)malloc(n * sizeof(double)); if (var == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(var, 0, (n * sizeof(double))); inv_diff_mom = (double *)malloc(n * sizeof(double)); if (inv_diff_mom == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(inv_diff_mom, 0, (n * sizeof(double))); sum_av = (double *)malloc(n * sizeof(double)); if (sum_av == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(sum_av, 0, (n * sizeof(double))); sum_entrp = (double *)malloc(n * sizeof(double)); if (sum_entrp == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(sum_entrp, 0, (n * sizeof(double))); sum_varnc = (double *)malloc(n * sizeof(double)); if (sum_varnc == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(sum_varnc, 0, (n * sizeof(double))); entrp = (double *)malloc(n * sizeof(double)); if (entrp == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(entrp, 0, (n * sizeof(double))); diff_var = (double *)malloc(n * sizeof(double)); if (diff_var == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(diff_var, 0, (n * sizeof(double))); diff_entrp = (double *)malloc(n * sizeof(double)); if (diff_entrp == NULL){ printf("Cannot allocate %d bytes for memory.\n", (n * sizeof(double))); exit(-1); } memset(diff_entrp, 0, (n * sizeof(double))); /* calcuate areas */ calculate_area(obj_id, width, height, n, area); /* calcuate perimeter length */ calculate_length(obj_id, width, height, n, len, image); /* calcuate cirularity index */ /* morphological_feature_circularity_index(area, len, n, circ); morphological_feature_object_moment(1.0, 1.0, obj_id, width, height, n, image, circ); morphological_feature_central_moments(0.0, 0.0, obj_id, width, height, n, image, circ); morphological_feature_object_orientation(obj_id, width, height, n, image, circ); */ morphological_feature_object_eccentricity(obj_id, width, height, n, image, circ); /* morphological_feature_central_invariant_moments(1.0, 1.0, obj_id, width, height, n, image, circ); */ /*color features*/ /* color_feature_mean(obj_id, width, height, n, area, image, clr_mn_value); color_feature_standard_deviation(obj_id, width, height, n, area, image, clr_mn_value, clr_std_dev); color_feature_skewness(obj_id, width, height, n, area, image, clr_mn_value, clr_skew); color_feature_kurtosis(obj_id, width, height, n, area, image, clr_mn_value, clr_kurtosis); color_feature_histogram(0, obj_id, width, height, n, area, image, clr_hist); */ /*texture features*/ /* glcm(0, obj_id, width, height, n, image, glcmat); texture_feature_angular_second_moment(glcmat, n, ang_sec_mom); texture_feature_contrast(glcmat, n, contr); texture_feature_correlation(glcmat, n, corr); texture_feature_variance(glcmat, n, var); texture_feature_inverse_diff_moment(glcmat, n, inv_diff_mom); texture_feature_sum_average(glcmat, n, sum_av); texture_feature_sum_entropy(glcmat, n, sum_entrp); texture_feature_sum_variance(glcmat, n, sum_entrp, sum_varnc); texture_feature_entropy(glcmat, n, entrp); texture_feature_difference_variance(glcmat, n, diff_var); texture_feature_difference_entropy(glcmat, n, diff_entrp); */ double weight = 0.0; for (i = 0; i < n; i++) { /*Morphological feature*/ input_val[i] = circ[i]; /*Color features*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_mn_value[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_std_dev[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_skew[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*clr_kurtosis[i];*/ /*input_val[i] = weight*circ[i] + weight*clr_mn_value[i] + weight*clr_std_dev[i] + weight*clr_skew[i] + weight*clr_kurtosis[i];*/ /*input_val[i] = weight*clr_mn_value[i] + weight*clr_std_dev[i] + weight*clr_skew[i] + weight*clr_kurtosis[i];*/ /*Texture features*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*ang_sec_mom[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*contr[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*corr[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*var[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*inv_diff_mom[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*sum_av[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*sum_entrp[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*sum_varnc[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*entrp[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*diff_var[i];*/ /*input_val[i] = weight*circ[i] + (1.0 - weight)*diff_entrp[i];*/ } /* k-means clustering */ /*k_means(circ, obj, n);*/ k_means(input_val, obj, n); /* choose representatives (smallest number for each cluster) */ for (i = 0; i < n; i++) obj[i].rep = 0; for (j = 0; j < NUM_CLASS; j++) { for (i = 0; i < n; i++) { if (obj[i].label == j) { obj[i].rep = 1; break; } } } /* find bounding box */ find_rect(obj_id, width, height, n, obj); for (i = 0; i < height; i++) free(obj_id[i]); free(obj_id); free(area); free(len); free(circ); free(input_val); /*color features*/ free(clr_mn_value); free(clr_std_dev); free(clr_skew); free(clr_kurtosis); for (i = 0; i < n; i++) free(clr_hist[i]); free(clr_hist); /*texture features*/ for (i=0;i<n;i++){ for (j=0;j<256;j++){ free(glcmat[i][j]); }/*for j*/ free(glcmat[i]); }/*for i*/ free(glcmat); free(ang_sec_mom); free(contr); free(corr); free(var); free(inv_diff_mom); free(sum_av); free(sum_entrp); free(sum_varnc); free(entrp); free(diff_var); free(diff_entrp); *n_object = n; return obj; }
void main(void) { unsigned char backup_ultimo_caracter; //Var auxiliar para la rec serie unsigned int backup_tiempo_rampa; //Var auxiliar para la cuenta char paquete[4]; //arreglo para el envio serie unsigned char broadcast_flag=0; //flag auxiliar de broadcast backup_tiempo_rampa = ReadADC(); pic_ini13(); //inicializa las ent/salidas del shield 1.3 timer_ini13(); //inicializa el timer en 1ms para habilitar //el multiplexado de displays y la cuenta timer1_ini13(); //inicializa el timer 1 para generar 38.2KHz usart_ini13(); //inicializa el puerto serie a 9600 /* Si no se utiliza el MAX232 se debe de ejecutar lo siguiente: */ BAUDCONbits.RXCKP = 1; BAUDCONbits.TXCKP = 1; /* En caso contrario comentar las lineas */ ei(); //habilitación global de interrupciones assign_id('a'); //en caso de tratarse de un esclavo, asigna //el número enviado a slave_id rampa_ini13(); //inicialización while(1){ if(caracter_recibido != backup_ultimo_caracter){ backup_ultimo_caracter=caracter_recibido; /*decodifico el comando la secuencia correcta es: * * <address> <comando><EOM> * * * address: es el estado que verifica si es solicitado el dispositivo especico * la misma corresponde a un único byte codificado en ASCII * comando: se pueden enviar todos los bytes ASCII que uno desee pero * unicamente se utilizará el primero de todos * EOM: Sin este dato al final del paquete no se ejecuta el comando enviado * Si la secuencia es correcta se devuelve el comando************************** */ //****Que hago con el comando************************************************// switch(decode(caracter_recibido)){ case ninguno:; break; case per2per:{ broadcast_flag=OFF; }break; case broadcast:{ broadcast_flag=ON; }break; case start:{ rampa_status=ON; INTCONbits.INT0IF=0; INTCONbits.INT0IE=1; SOLENOIDE_ON; demora_solenoide = demora_solenoide_set; }break; case stop:{ rampa_status=OFF; INTCONbits.INT0IE=0; INTCONbits.INT0IF=0; }break; case lectura:{ if(!broadcast_flag) informar(paquete,4); //envia la lectura }break; case reset:{ tiempo_rampa=0; }break; } } /*para no hacer la siguiente conversión a menos que sea necesario se realiza una *comprobación */ if(tiempo_rampa !=backup_tiempo_rampa){ //separa la cuenta en BCD paquete[0]=tiempo_rampa/1000; //obtiene los segundos paquete[1]=(tiempo_rampa%1000)/100; //obtiene las decimas paquete[2]=(tiempo_rampa%100)/10; //obtiene la centesimas paquete[3]=tiempo_rampa%10; //obtiene las milesimas backup_tiempo_rampa=tiempo_rampa; } Send_4Disp(paquete[0],paquete[1],paquete[2],paquete[3]); //se actualiza la info del disp } }
static bool is_lvalue(typecheck_t* t, ast_t* ast, bool need_value) { switch(ast_id(ast)) { case TK_DONTCARE: // Can only assign to it if we don't need the value. return !need_value; case TK_VAR: case TK_LET: return assign_id(t, ast_child(ast), ast_id(ast) == TK_LET, need_value); case TK_VARREF: { ast_t* id = ast_child(ast); return assign_id(t, id, false, need_value); } case TK_LETREF: { ast_error(ast, "can't assign to a let local"); return false; } case TK_FVARREF: { AST_GET_CHILDREN(ast, left, right); if(ast_id(left) == TK_THIS) return assign_id(t, right, false, need_value); return true; } case TK_FLETREF: { AST_GET_CHILDREN(ast, left, right); if(ast_id(left) != TK_THIS) { ast_error(ast, "can't assign to a let field"); return false; } if(t->frame->loop_body != NULL) { ast_error(ast, "can't assign to a let field in a loop"); return false; } return assign_id(t, right, true, need_value); } case TK_EMBEDREF: { AST_GET_CHILDREN(ast, left, right); if(ast_id(left) != TK_THIS) { ast_error(ast, "can't assign to an embed field"); return false; } if(t->frame->loop_body != NULL) { ast_error(ast, "can't assign to an embed field in a loop"); return false; } return assign_id(t, right, true, need_value); } case TK_TUPLE: { // A tuple is an lvalue if every component expression is an lvalue. ast_t* child = ast_child(ast); while(child != NULL) { if(!is_lvalue(t, child, need_value)) return false; child = ast_sibling(child); } return true; } case TK_SEQ: { // A sequence is an lvalue if it has a single child that is an lvalue. // This is used because the components of a tuple are sequences. ast_t* child = ast_child(ast); if(ast_sibling(child) != NULL) return false; return is_lvalue(t, child, need_value); } default: {} } return false; }