unsigned int draw_layer(idx<float> &layer, const char *s, unsigned int h, unsigned int w) { #ifdef __GUI__ draw_matrix(layer, s, h, w, 1.0, 1.0, (float)-1.0, (float)1.0); #endif return layer.dim(1) + 3; }
void tracking_thread<Tnet>::draw(bbox *b) { #ifdef __GUI__ disable_window_updates(); clear_window(); draw_matrix(frame, "in"); draw_matrix(tpl, "tpl", 0, frame.dim(1)); if (b) { ubyte red = 0, green = 0, blue = 0; if (b->class_id == -42) green = 255; else blue = 255; draw_box(b->h0, b->w0, b->width, b->height, red, green, blue); } enable_window_updates(); #endif }
void draw_ground_plane_estimator(const FastGroundPlaneEstimator &ground_plane_estimator, const AbstractVideoInput::input_image_view_t &input_view, const StereoCameraCalibration &stereo_calibration, boost::gil::rgb8_view_t &screen_view) { // copy right screen image --- copy_and_convert_pixels(input_view, screen_view); // draw v-disparity image in the right screen image -- FastGroundPlaneEstimator::v_disparity_const_view_t raw_v_disparity_view = ground_plane_estimator.get_v_disparity_view(); boost::gil::rgb8_view_t screen_subview = boost::gil::subimage_view(screen_view, 0,0, raw_v_disparity_view.width(), screen_view.height()); fill_pixels(screen_subview, boost::gil::rgb8_pixel_t()); boost::gil::rgb8_view_t screen_subsubview = boost::gil::subimage_view(screen_subview, 0, raw_v_disparity_view.height(), raw_v_disparity_view.width(), raw_v_disparity_view.height()); Eigen::MatrixXf v_disparity_data; v_disparity_data_to_matrix(ground_plane_estimator.get_v_disparity(), v_disparity_data); normalize_each_row(v_disparity_data); draw_matrix(v_disparity_data, screen_subsubview); if(false) { log_debug() << "(over)Writing ground_v_disparity_data.png" << std::endl; boost::gil::png_write_view("ground_v_disparity_data.png", screen_subsubview); } const bool draw_lines_on_top = true; if(draw_lines_on_top) { draw_v_disparity_lines(ground_plane_estimator, stereo_calibration, screen_subview); // draw the points used to estimate the objects typedef std::pair<int, int> point_t; const FastGroundPlaneEstimator::points_t &points = ground_plane_estimator.get_points(); BOOST_FOREACH(const point_t &point, points) { *screen_subsubview.at(point.first, point.second) = rgb8_colors::orange; } }
void test_hall(INT n, INT nb_inc, INT verbose_level) { matrix H; Vector S; Vector matching, matching_inv; INT i, k; INT f_v = (verbose_level >= 1); INT f_vv = (verbose_level >= 2); INT xmax = 1000; INT ymax = 1000; INT f_cartesian = TRUE; #if 0 get_random_Hall_matrix(n, nb_inc, H, verbose_level - 2); get_random_Hall_matrix(n, nb_inc, H, verbose_level - 2); get_random_Hall_matrix(n, nb_inc, H, verbose_level - 2); get_random_Hall_matrix(n, nb_inc, H, verbose_level - 2); get_random_Hall_matrix(n, nb_inc, H, verbose_level - 2); matchmaker(H, matching, matching_inv, verbose_level); #else for (i = 0; i < 20; i++) { BYTE fname[1000]; if (f_v) { cout << "i=" << i << " "; } get_random_matrix(n, nb_inc, H, verbose_level); if (!test_hall_condition(H, S, n, k)) { if (f_vv) { cout << "H=\n" << H << endl; cout << "Hall condition not satisfied for selection" << S << endl; } } else { matchmaker(H, matching, matching_inv, verbose_level); if (f_vv) { cout << "H=" << endl << H << endl; cout << "matching=" << matching << endl; cout << "matching_inv=" << matching_inv << endl; } } sprintf(fname, "Hall_%ld", i); draw_matrix(H, fname, xmax, ymax, f_cartesian); } #endif }
void FluxErr_nomcheck(){ //TFile *fop = TFile::Open("/home/kikawa/for_pm_v3/flux_cov/flux_cov_full.root"); TFile *fop = TFile::Open("/home/cvson/cc1picoh/syst/flux_cov_full.root"); TMatrixDSym *mat = (TMatrixDSym*)fop->Get("flux_cov"); if(mat==NULL){ cout << "Cannot get matrix from " << fop->GetPath() << endl; exit; } float cov_mat[nbin][nbin]; for(int i=0; i<nbin; i++) for(int j=0; j<nbin; j++) cov_mat[i][j] = (*mat)(i+258, j+258); #ifdef MKPLOT draw_matrix(cov_mat); #endif float chol_mat[nbin][nbin]; cholcov_conv(cov_mat, chol_mat); #ifdef MKPLOT draw_matrix(chol_mat); #endif int nthrows = 1000000; float weight[nbin],nrand[nbin]; TH1F* hqeint; TH1F* hqedet; TH1F* hnqeint; TH1F* hnqedet; TH1F* hflux; //TFile *fccqe = new TFile("cccoh.root"); //TFile *fccqe = new TFile("cccoh_frkikawa.root"); //TFile *fccqe = new TFile("cccoh_mva.root"); TFile *fccqe = new TFile("cccoh_nomcheck.root"); hqeint = (TH1F*)fccqe -> Get("qeint");//all signal hnqeint = (TH1F*)fccqe -> Get("nqeint");//all background hqedet = (TH1F*)fccqe -> Get("qedet");//all signal-selected hnqedet = (TH1F*)fccqe -> Get("nqedet");// all background-selected hflux = (TH1F*)fccqe -> Get("flux"); //TFile *fout = new TFile("toymc_nom.root","recreate"); TFile *fout = new TFile("toymc_nomcheck.root","recreate"); TTree *tree = new TTree("tree","tree"); //float pm,ing,pm_int,ing_int,pm_det,ing_det; //float pm_ccint,ing_ccint,pm_ccdet,ing_ccdet,pm_ncint,ing_ncint,pm_ncdet,ing_ncdet,pm_cceff,ing_cceff,pm_nceff,ing_nceff,pm_flux,ing_flux; float qeint,nqeint, qedet,nqedet, qeeff,nqeeff, flux; tree->Branch("qeint",&qeint,"qeint/F");//all signal interaction tree->Branch("nqeint",&nqeint,"nqeint/F");//all background interaction tree->Branch("qedet",&qedet,"qedet/F");// all selected-signal tree->Branch("nqedet",&nqedet,"nqedet/F");//all selected-background tree->Branch("qeeff",&qeeff,"qeeff/F");//efficiency of signal selection tree->Branch("nqeeff",&nqeeff,"nqeeff/F");//efficiency of background selection tree->Branch("flux",&flux,"flux/F"); //float pm0_ccint=0,ing0_ccint=0,pm0_ccdet=0,ing0_ccdet=0,pm0_ncint=0,ing0_ncint=0,pm0_ncdet=0,ing0_ncdet=0,pm0_cceff=0,ing0_cceff=0,pm0_nceff=0,ing0_nceff=0,pm0_flux=0,ing0_flux=0; float qeint_nomi=0,nqeint_nomi=0, qedet_nomi=0,nqedet_nomi=0, qeeff_nomi=0,nqeeff_nomi=0, flux_nomi=0; for(int j=0;j<nbin;j++){ qeint_nomi += hqeint -> GetBinContent(j+1); nqeint_nomi += hnqeint -> GetBinContent(j+1); qedet_nomi += hqedet -> GetBinContent(j+1); nqedet_nomi += hnqedet -> GetBinContent(j+1); flux_nomi += hflux -> GetBinContent(j+1); } //make toy simulation for(int i=0;i<nthrows;i++){ if(i%10000==0)cout<<i<<endl; //pm_ccint=0,ing_ccint=0,pm_ccdet=0,ing_ccdet=0,pm_ncint=0,ing_ncint=0,pm_ncdet=0,ing_ncdet=0,pm_cceff=0,ing_cceff=0,pm_nceff=0,ing_nceff=0,pm_flux=0,ing_flux=0; qeint=0;nqeint=0; qedet=0;nqedet=0; qeeff=0;nqeeff=0; flux=0; for(int k=0;k<nbin;k++){ nrand[k]=rand.Gaus();//gaussian random } //fluctuate the weight for(int j=0;j<nbin;j++){ weight[j]=1; for(int k=0;k<=j;k++){ weight[j]+=chol_mat[j][k]*nrand[k]; } qeint += hqeint -> GetBinContent(j+1)*weight[j]; nqeint += hnqeint -> GetBinContent(j+1)*weight[j]; qedet += hqedet -> GetBinContent(j+1)*weight[j]; nqedet += hnqedet -> GetBinContent(j+1)*weight[j]; flux += hflux -> GetBinContent(j+1)*weight[j]; } qeint /= qeint_nomi; nqeint /= nqeint_nomi; qedet /= qedet_nomi; nqedet /= nqedet_nomi; flux /= flux_nomi; qeeff = qedet/qeint; nqeeff = nqedet/nqeint; tree->Fill(); } tree->Write(); hqedet ->Write(); hnqedet ->Write(); fout->Close(); }
int display(list<string>::iterator &ifname, bool signd, bool load, list<string> *mats) { //cout << "displaying " << ifname->c_str() << endl; // conf mode if (conf) return display_net<T>(ifname, signd, load, mats); // mat mode if (is_matrix(ifname->c_str())) { idxdim d = get_matrix_dims(ifname->c_str()); if (interleaved) d.shift_dim(0, 2); if (save_individually || print || !(d.order() == 2 || (d.order() == 3 && (d.dim(2) == 1 || d.dim(2) == 3)))) { // this is probably not an image, just display info and print matrix string type; get_matrix_type(ifname->c_str(), type); idx<T> m = load_matrix<T>(ifname->c_str()); cout << "Matrix " << ifname->c_str() << " is of type " << type << " with dimensions " << d << " (min " << idx_min(m) << ", max " << idx_max(m) << ", mean " << idx_mean(m) << "):" << endl; m.print(); if (has_multiple_matrices(ifname->c_str())) { midx<T> ms = load_matrices<T>(ifname->c_str(), true); // saving sub-matrices if (save_individually) { cout << "Saving each sub-matrix of " << *ifname << " individually..." << endl; save_matrices_individually(ms, *ifname, true); } // printing sub-matrices cout << "This file contains " << m << " matrices: "; if (ms.order() == 1) { for (intg i = 0; i < ms.dim(0); ++i) { idx<T> tmp = ms.mget(i); cout << tmp.info() << " "; } } else if (ms.order() == 2) { for (intg i = 0; i < ms.dim(0); ++i) { for (intg j = 0; j < ms.dim(1); ++j) { idx<T> tmp = ms.mget(i, j); cout << tmp.info() << " "; } cout << endl; } } cout << endl; } else cout << "This is a single-matrix file." << endl; return 0; } } // image mode int loaded = 0; static idx<T> mat; uint h = 0, w = 0, rowh = 0, maxh = 0; list<string>::iterator fname = ifname; #ifdef __GUI__ disable_window_updates(); clear_window(); if (show_filename) { gui << at(h, w) << black_on_white() << ifname->c_str(); h += 16; } #endif maxh = h; for (uint i = 0; i < nh; ++i) { rowh = maxh; for (uint j = 0; j < nw; ++j) { if (fname == mats->end()) fname = mats->begin(); try { // if (load) mat = load_image<T>(*fname); if (print) cout << *fname << ": " << mat << endl << mat.str() << endl; // show only some channels if (chans >= 0) mat = mat.select(2, chans); loaded++; maxh = (std::max)(maxh, (uint) (rowh + mat.dim(0))); T min = 0, max = 0; #ifdef __GUI__ if (autorange || signd) { if (autorange) { min = idx_min(mat); max = idx_max(mat); } else if (signd) { T matmin = idx_min(mat); if ((double)matmin < 0) { min = -1; max = -1; } } draw_matrix(mat, rowh, w, zoom, zoom, min, max); } else draw_matrix(mat, rowh, w, zoom, zoom, (T) range[0], (T) range[1]); #endif w += mat.dim(1) + 1; } catch(string &err) { ERROR_MSG(err.c_str()); } fname++; if (fname == ifname) break ; } if (fname == ifname) break ; maxh++; w = 0; } #ifdef __GUI__ // info if (show_info) { set_text_colors(0, 0, 0, 255, 255, 255, 255, 200); gui << mat; gui << at(15, 0) << *fname; gui << at(29, 0) << "min: " << idx_min(mat) << " max: " << idx_max(mat); } // help if (show_help) { h = 0; w = 0; uint hstep = 14; set_text_colors(0, 0, 255, 255, 255, 255, 255, 200); gui << at(h, w) << "Controls:"; h += hstep; set_text_colors(0, 0, 0, 255, 255, 255, 255, 200); gui << at(h, w) << "Right/Space: next image"; h += hstep; gui << at(h, w) << "Left/Backspace: previous image"; h += hstep; gui << at(h, w) << "i: image info"; h += hstep; gui << at(h, w) << "a: auto-range (use min and max as range)"; h += hstep; gui << at(h, w) << "x/z: show more/less images on width axis"; h += hstep; gui << at(h, w) << "y/t: show more/less images on height axis"; h += hstep; gui << at(h, w) << "0,1,2: show channel 0, 1 or 2 only"; h += hstep; gui << at(h, w) << "9: show alls channels"; h += hstep; gui << at(h, w) << "h: help"; } // update title string title; title << "matshow: " << ebl::basename(ifname->c_str()); set_window_title(title.c_str()); enable_window_updates(); #endif return loaded; }
int main() { srand( time(NULL) ); struct termios defs; //Se guarda el estado actual de termios. tcgetattr(0,&defs); //No queremos contaminar el tty del usuario //(Asi es, el tty, no solo el proceso!) int startx, starty; initscr(); /* Start curses mode */ cbreak(); /* Line buffering disabled, Pass on */ /* everty thing to me */ start_color(); use_default_colors(); init_pair(1, COLOR_GREEN, -1); init_pair(2, COLOR_RED, -1); init_pair(3, COLOR_YELLOW, COLOR_RED); init_pair(4, COLOR_YELLOW,-1); keypad(stdscr, TRUE); /* Activa las teclas de control. */ starty = (LINES - HEIGHT) / 4; /* Calcula la posición del centro de la pantalla */ startx = (COLS - WIDTH) / 2; printw("Presione Q para salir"); refresh(); my_win = create_newwin(HEIGHT, WIDTH, starty, startx); stats = create_newwin(6,30,starty, startx+60); msgs = create_newwin(9,80,starty+30,startx-13); struct Animal *player; player = (struct Animal *)malloc(sizeof(struct Animal)); draw_welcome(my_win,msgs,&player); my_win = create_newwin(HEIGHT, WIDTH, starty, startx); struct Nodo *cList = NULL; // ] struct Nodo *hList = NULL; // -> Los animales leidos se guardan en éstas listas. struct Nodo *pList = NULL; // ] int lim = loadData(&cList,&hList,&pList); //Carga las listas de animales, y devuelve el número de comidas. struct Cell matrix[9][9]; initMatrix(matrix); int px = matrix[4][4].xpos; int py = matrix[4][4].ypos; //GAME LOOP: //Primero, setear modo no-canonico //Esto permite obtener input en tiempo real //y no bloquar la ejecución mientras el usuario juega. nonCanonical(); char ch; int end = 0; int i = 0; int j = 0; while(!end) { ch = '0'; read(0,&ch,1); //Se lée el (posible) input del usuario. if(!(i % 3)) iterateMatrix(matrix,player); //Los NPC reaccionan cada 3 ticks. i++; switch(ch) { case 'a': if(!apply(matrix,player,&cList,&hList,&pList,'l')) draw_matrix(my_win,matrix,player); wrefresh(my_win); break; case 'd': if(!apply(matrix,player,&cList,&hList,&pList,'r')) draw_matrix(my_win,matrix,player); wrefresh(my_win); break; case 'w': if(!apply(matrix,player,&cList,&hList,&pList,'u')) draw_matrix(my_win,matrix,player); wrefresh(my_win); break; case 's': if(!apply(matrix,player,&cList,&hList,&pList,'d')) draw_matrix(my_win,matrix,player); wrefresh(my_win); break; case 'q': end = 1; break; default: draw_matrix(my_win,matrix,player); } if(player->eat(player,0) >= lim) { draw_msg("Limite de comidas alcanzado! Felicitaciones!",msg_buffer); draw_msg(" ",msg_buffer); draw_msg(" ",msg_buffer); canonical(&defs); getch(); end = 1; } if(player) draw_stats(stats, player, lim); if(player->getHP(player) < 1) { wattron(my_win,COLOR_PAIR(3)); for(i=-1;i<2;i++) for(j=-1;j<2;j++) mvwprintw(my_win,px+i,py+j," "); mvwprintw(my_win,px,py,"X"); wattroff(my_win,COLOR_PAIR(3)); wrefresh(my_win); draw_msg("Has sido devorado... ",msg_buffer); draw_msg(" ",msg_buffer); draw_msg(" ",msg_buffer); end = 1; canonical(&defs); getch(); } } canonical(&defs); endwin(); /* End curses mode */ return 0; }