//-------------------------------------------------------------- void MovingObjects::draw(ofColor _c){ drawRectangles(); drawText(); }
// Generate the Graphics void displayFcn(void) { // Clear display window. glClear(GL_COLOR_BUFFER_BIT); // Draw 3 different rectangles drawRectangles(); // Draw triangles drawTriangles(); // Draw house drawHouse(); // Draw square drawSquare(); // Execute glFlush(); }
void render() { glClear(GL_COLOR_BUFFER_BIT); std::vector<Rect> rectangles; Rect ballRect(0, 0, BALL_SIZE, BALL_SIZE); ball.getCoordinates(ballRect.x, ballRect.y); rectangles.push_back(ballRect); rectangles.push_back(leftPlayer.getCoords()); rectangles.push_back(rightPlayer.getCoords()); std::vector<Color> colors; colors.push_back(Color(1.0f, 1.0f, 1.0f)); colors.push_back(Color(1.0f, 0.0f, 0.0f)); colors.push_back(Color(0.0f, 0.0f, 1.0f)); drawRectangles(rectangles, colors); }
int main(int argc, char **argv) { XEvent evt; Colormap colormap; struct timeval tv; int screenNumber; long eventMask; unsigned long white; unsigned long black; Status rc; int iters; int opt; int draw_lines; int draw_rects; int draw_stipples; int draw_fonts; int draw_image; int zero_counters; int scroll_type; char image_file[256]; char proxy_app[256]; char msg[4096]; // set some defaults g_winWidth = 640; g_winHeight = 480; iters = 5000; draw_lines = 1; draw_rects = 1; draw_stipples = 1; draw_fonts = 1; draw_image = 1; g_delay_dur = 1000; scroll_type = SCROLL_SMOOTH1; zero_counters = 0; strcpy(image_file, "yosemite.bmp"); strcpy(msg, "To be or not to be!"); // process cmd line args opterr = 0; while ((opt = getopt(argc, argv, "lrsg:c:f:i:d:o:z:")) != -1) { switch (opt) { case 'g': if (sscanf(optarg, "%dx%d", &g_winWidth, &g_winHeight) != 2) { fprintf(stderr, "\nerror: invalid geometry specified\n\n"); usage(); return -1; } break; case 'c': if (sscanf(optarg, "%d", &iters) != 1) { fprintf(stderr, "\nerror: invalid count specified\n\n"); usage(); return -1; } break; case 'l': draw_lines = 1; draw_rects = 0; draw_stipples = 0; draw_fonts = 0; draw_image = 0; break; case 'r': draw_rects = 1; draw_lines = 0; draw_stipples = 0; draw_fonts = 0; draw_image = 0; break; case 's': draw_stipples = 1; draw_lines = 0; draw_rects = 0; draw_fonts = 0; draw_image = 0; break; case 'f': if (strlen(optarg) <= 0) { fprintf(stderr, "\nerror: -f option requires an argument\n\n"); usage(); return -1; } draw_fonts = 1; strncpy(msg, optarg, 4096); draw_lines = 0; draw_rects = 0; draw_stipples = 0; draw_image = 0; break; case 'i': if (strlen(optarg) <= 0) { fprintf(stderr, "\nerror: -i option requires an argument\n\n"); usage(); return -1; } draw_image = 1; strncpy(image_file, optarg, 255); draw_lines = 0; draw_rects = 0; draw_stipples = 0; draw_fonts = 0; break; case 'h': usage(); return 0; break; case 'v': printf("xdemo Ver 1.0\n"); return 0; break; case 'd': if (sscanf(optarg, "%d", &g_delay_dur) != 1) { fprintf(stderr, "\nerror: -d option requires an argument\n\n"); usage(); return -1; } break; case 'z': if (strlen(optarg) <= 0) { fprintf(stderr, "\nerror: invalid proxy application specified\n\n"); usage(); return -1; } strcpy(proxy_app, optarg); printf("##### LK_TODO: proxy_app=%s\n", proxy_app); zero_counters = 1; break; case 'o': if (strcmp(optarg, "jump") == 0) { scroll_type = SCROLL_JUMP; } else if (strcmp(optarg, "smooth1") == 0) { scroll_type = SCROLL_SMOOTH1; } else if (strcmp(optarg, "smooth2") == 0) { scroll_type = SCROLL_SMOOTH2; } else if (strcmp(optarg, "smooth3") == 0) { scroll_type = SCROLL_SMOOTH3; } else if (strcmp(optarg, "smooth4") == 0) { scroll_type = SCROLL_SMOOTH4; } else { fprintf(stderr, "\ninvalid scroll type specified\n\n"); usage(); return -1; } break; default: usage(); return -1; } } // must have at least one operation if ((!draw_lines) && (!draw_rects) && (!draw_stipples) && (!draw_fonts) && (!draw_image)) { usage(); return -1; } g_disp = XOpenDisplay(NULL); if (!g_disp) { dprint("error opening X display\n"); exit(-1); } screenNumber = DefaultScreen(g_disp); white = WhitePixel(g_disp, screenNumber); black = BlackPixel(g_disp, screenNumber); g_win = XCreateSimpleWindow(g_disp, DefaultRootWindow(g_disp), 50, 50, // origin g_winWidth, g_winHeight, // size 0, black, // border white ); // backgd XMapWindow(g_disp, g_win); //eventMask = StructureNotifyMask | MapNotify | VisibilityChangeMask; eventMask = StructureNotifyMask | VisibilityChangeMask; XSelectInput(g_disp, g_win, eventMask); g_gc = XCreateGC(g_disp, g_win, 0, // mask of values NULL ); // array of values #if 0 do { dprint("about to call XNextEvent(...)\n"); XNextEvent(g_disp, &evt);// calls XFlush dprint("returned from XNextEvent(...)\n"); } //while(evt.type != MapNotify); while(evt.type != VisibilityNotify); #endif // get access to the screen's color map colormap = DefaultColormap(g_disp, screenNumber); // alloc red color rc = XAllocNamedColor(g_disp, colormap, "red", &g_colors[0], &g_colors[0]); if (rc == 0) { printf("XAllocNamedColor - failed to allocated 'red' color.\n"); exit(1); } rc = XAllocNamedColor(g_disp, colormap, "green", &g_colors[1], &g_colors[1]); if (rc == 0) { printf("XAllocNamedColor - failed to allocated 'green' color.\n"); exit(1); } rc = XAllocNamedColor(g_disp, colormap, "blue", &g_colors[2], &g_colors[2]); if (rc == 0) { printf("XAllocNamedColor - failed to allocated 'blue' color.\n"); exit(1); } rc = XAllocNamedColor(g_disp, colormap, "yellow", &g_colors[3], &g_colors[3]); if (rc == 0) { printf("XAllocNamedColor - failed to allocated 'yellow' color.\n"); exit(1); } rc = XAllocNamedColor(g_disp, colormap, "orange", &g_colors[4], &g_colors[4]); if (rc == 0) { printf("XAllocNamedColor - failed to allocated 'orange' color.\n"); exit(1); } if (zero_counters) { signal_tcp_proxy(proxy_app); } if (draw_lines) { start_timer(&tv); drawLines(iters); printf("drew %d lines in %d ms\n", iters, time_elapsed_ms(tv)); } if (draw_rects) { start_timer(&tv); drawRectangles(iters); printf("drew %d rects in %d ms\n", iters, time_elapsed_ms(tv)); } if (draw_stipples) { start_timer(&tv); // LK_TODO } if (draw_fonts) { start_timer(&tv); drawFont(iters, msg); printf("drew %d strings in %d ms\n", iters, time_elapsed_ms(tv)); } if (draw_image) { start_timer(&tv); drawBMP(image_file, scroll_type); printf("drew BMP in %d ms\n", time_elapsed_ms(tv)); } if (zero_counters) { signal_tcp_proxy(proxy_app); } eventMask = ButtonPressMask|ButtonReleaseMask; XSelectInput(g_disp, g_win, eventMask); do { XNextEvent(g_disp, &evt); // calls XFlush() } while(evt.type != ButtonRelease); XDestroyWindow(g_disp, g_win); XCloseDisplay(g_disp); return 0; }
int Detector::detectFaces(ClassifierInterface* ci, const std::string img_path, double ac, int draw, int save){ SubwindowGenerator sg(img_path,_wr,_shift_step); IntegralImage ii(img_path); startClock(); ulong total_sw,total_faces; std::vector<Subwindow> lista = sg.generateSubwindows(_ng); stopClock("Generating Windows"); total_faces=0; total_sw = lista.size(); int res; int cur_gen=-1; std::vector<int*> faces_boxes; std::vector<int*> scenes_boxes; startClock(); for(register int i=0;i<lista.size();++i){ // printf("NEW SUBWINDOW\n"); if(cur_gen!=lista[i]._cur_ng){ ci->resize(lista[i]._ce); cur_gen = lista[i]._cur_ng; } if(ac<0){ res = ci->isFace(ii,(lista[i])); }else{ res = ci->isFace(ii,(lista[i]),ac); } if(res==1){ faces_boxes.push_back(new int[4]); lista[i].cropBox( faces_boxes[faces_boxes.size()-1] ); total_faces+=1; }else{ scenes_boxes.push_back(new int[4]); lista[i].cropBox( scenes_boxes[scenes_boxes.size()-1] ); } } stopClock("Detection Time"); if(draw==1){ int** boxes_array = (int**) malloc(faces_boxes.size()*sizeof(int*)); for(register int i=0;i<faces_boxes.size();i++){ boxes_array[i] = faces_boxes[i]; } std::string save_path = Config::PROJECT_PATH + "/analysis/detector_output/img_det.pgm"; drawRectangles(img_path.c_str(),faces_boxes.size(),boxes_array,"white", save, save_path.c_str() ); free(boxes_array); // int** boxes_array = (int**) malloc(scenes_boxes.size()*sizeof(int*)); // for(register int i=0;i<scenes_boxes.size();i++){ // boxes_array[i] = scenes_boxes[i]; // } // drawRectangles(img_path.c_str(),scenes_boxes.size(),boxes_array,"red"); // free(boxes_array); } printf("\nSW: %lu FACES: %lu\n",total_sw,total_faces); return total_faces; }
static void b_drawRectangles1(task *tsk, pntr *argstack) { /* pointers to the parameters */ pntr val1 = argstack[3]; // userName pntr val2 = argstack[2]; // xPos pntr val3 = argstack[1]; // yPos pntr val4 = argstack[0]; // rect int badtype; /* the result value to be return */ int numRect; char *userName; double xPos; int yPos; Rectangle *rect = new_Rectangle(); /* Check validity of each parameter */ CHECK_ARG(3, CELL_CONS); CHECK_ARG(2, CELL_NUMBER); CHECK_ARG(1, CELL_NUMBER); CHECK_ARG(0, CELL_CONS); /* Initialize all arguments for this method */ if( (badtype = array_to_string(val1, &userName)) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } xPos = pntrdouble(val2); yPos = pntrdouble(val3); /* Initialize the struct: Rectangle */ pntr rect_val1 = head(tsk, val4); rect->width = pntrdouble(rect_val1); pntr rect_val2 = head(tsk, tail(tsk, val4)); if( (badtype = array_to_string(rect_val2, &(rect->creator) )) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } pntr rect_val3 = head(tsk, tail(tsk, tail(tsk, val4))); rect->height = pntrdouble(rect_val3); /* Initialize another struct: Color*/ Color *rect_col = new_Color( ); rect->col = rect_col; /* new root pntr for struct Color */ pntr rect_col_val = head(tsk, tail(tsk, tail(tsk, tail(tsk, val4)))); pntr rect_col_val1 = head(tsk, rect_col_val); rect_col->red = pntrdouble(rect_col_val1); pntr rect_col_val2 = head(tsk, tail(tsk, rect_col_val)); rect_col->blue = pntrdouble(rect_col_val2); pntr rect_col_val3 = head(tsk, tail(tsk, tail(tsk, rect_col_val))); rect_col->green = pntrdouble(rect_col_val3); /* Initialize another struct: gray*/ gray *rect_col_cg = new_gray( ); rect_col->cg = rect_col_cg; /* new root pntr for struct gray */ pntr rect_col_cg_val = head(tsk, tail(tsk, tail(tsk, tail(tsk, rect_col_val)))); pntr rect_col_cg_val1 = head(tsk, rect_col_cg_val); if( (badtype = array_to_string(rect_col_cg_val1, &(rect_col_cg->country) )) > 0) { set_error(tsk, "string: argument is not a string (contains non-char: %s)", cell_types[badtype]); return; } pntr rect_col_cg_val2 = head(tsk, tail(tsk, rect_col_cg_val)); rect_col_cg->grayCode = pntrdouble(rect_col_cg_val2); /* end Initialization of struct Rectangle */ /* Call the method and get the return value */ numRect = drawRectangles(userName, xPos, yPos, rect); setnumber(&argstack[0], numRect); }