// text callback void text_callback(GLFWwindow* window, unsigned int key) { view_params* view = (view_params*)glfwGetWindowUserPointer(window); switch (key) { case ' ': view->simulating = !view->simulating; break; case '/': { for (int i = 0; i < view->scene->shapes.size(); i++) { view->scene->shapes[i].xform = ym_identity_affine3f; ysr_set_transform(view->rigid_scene, i, ym_identity_frame3f); } } break; case '.': simulate_step(view); break; case '[': view->exposure -= 1; break; case ']': view->exposure += 1; break; case '{': view->gamma -= 0.1f; break; case '}': view->gamma += 0.1f; break; case 'e': view->view_edges = !view->view_edges; break; case 'h': view->view_hull = !view->view_hull; break; case 'b': view->background = (view->background + 1) % 4; break; case 's': save_screenshot(window, view); break; case 'c': view->camera_lights = !view->camera_lights; break; case 'C': view->cur_camera = (view->cur_camera + 1) % view->scene->cameras.size(); break; default: printf("unsupported key\n"); break; } }
// uiloop void ui_loop(const ym_string& filename, const ym_string& imfilename, yo_scene* scene, ysr_scene* rigid_scene, float dt, int w, int h, bool camera_lights, float amb, bool no_ui) { // view data view_params* view = init_view_params( filename, imfilename, scene, rigid_scene, dt, w, h, camera_lights, amb); // glfw if (!glfwInit()) exit(EXIT_FAILURE); GLFWwindow* window = glfwCreateWindow(view->w, view->h, "yshade", 0, 0); glfwMakeContextCurrent(window); glfwSetWindowUserPointer(window, view); // callbacks glfwSetCharCallback(window, text_callback); glfwSetWindowSizeCallback(window, window_size_callback); glfwSetFramebufferSizeCallback(window, framebuffer_size_callback); glfwSetMouseButtonCallback(window, mouse_button_callback); glfwSetCursorPosCallback(window, mouse_pos_callback); glfwSetWindowRefreshCallback(window, window_refresh_callback); // init gl extensions #ifndef __APPLE__ if (glewInit() != GLEW_OK) exit(EXIT_FAILURE); #endif // init shade state view->shade_prog = yg_stdshader_make_program(); view->shade_txt.resize(scene->textures.size()); for (int i = 0; i < scene->textures.size(); i++) { yo_texture* txt = &scene->textures[i]; view->shade_txt[i] = yg_make_texture(txt->pixels.data(), txt->width, txt->height, txt->ncomp, false, true); } // ui loop while (!glfwWindowShouldClose(window)) { window_refresh_callback(window); if (view->simulating) { simulate_step(view); glfwPollEvents(); } else { glfwWaitEvents(); } } glfwDestroyWindow(window); glfwTerminate(); delete view; }
//----------------------------------------------------------------------------------------- //----------------------------------------------------------------------------------------- void ExecThread::run() { LOG_MSG("Invoking DLL..."); int res=0; int hour; const char *infile, *outfile; char version[12]; QString infile_path, outfile_path; int len_infile, len_outfile; int len_version; QString dll_version; bool cused[32]; infile_path = inputFile; QString casename = QFileInfo(inputFile).baseName(); len_infile = infile_path.length(); std::string std_infile = infile_path.toStdString(); infile = std_infile.c_str(); outfile_path = casename.append(".res"); len_outfile = outfile_path.length(); std::string std_outfile = outfile_path.toStdString(); outfile = std_outfile.c_str(); get_dll_build_version(version,&len_version); dll_version = version; // We can compare the version of the actual DLL that is linked // with the GUI's idea of the DLL version (i.e. the version of the library the GUI was built with) if (dll_version != Global::DLL_build_version) { LOG_QMSG("Bad DLL version: " + dll_version); emit(badDLL(dll_version)); return; } paused = false; LOG_MSG("call execute"); execute(&ncpu,const_cast<char *>(infile),&len_infile,const_cast<char *>(outfile),&len_outfile,&res); LOG_MSG("did execute"); if (res) { terminate_run(&res); return; } // char *b; // get_string(&b); // LOG_MSG(b); get_dimensions(&nsteps, &Global::DELTA_T, &Global::NT_DISPLAY, &Global::MAX_CHEMO, &Global::N_EXTRA, cused); // summary_interval = int(3600./Global::DELTA_T); summary_interval = Global::NT_DISPLAY; sprintf(msg,"exthread: nsteps: %d summary_interval: %d",nsteps,summary_interval); LOG_MSG(msg); Global::conc_nc_ic = 0; Global::conc_nc_ex = 0; hour = 0; int ndisplay = nsteps/Global::NT_DISPLAY + 1; mutex1.lock(); emit setupC(ndisplay); mutex1.unlock(); LOG_MSG("did setupC"); // LOG_MSG("call tester"); // tester(); // LOG_MSG("did tester"); // emit run_tester(); get_summary(Global::summaryData, &Global::i_hypoxia_cutoff, &Global::i_growth_cutoff); // getProfiles(); emit summary(hour); // Emit signal to initialise summary plots for (int i=1; i <= nsteps+1; i++) { sleep(10); bool updated = false; if (paused && !updated) { // snapshot(); // sprintf(msg,"got snapshot: i: %d",i); // LOG_MSG(msg); updated = true; } while(paused || Global::leftb) { sleep(100); } if (stopped) { LOG_MSG("stopped"); res = -1; break; } mutex1.lock(); // LOG_MSG("call simulate_step"); simulate_step(&res); // LOG_MSG("did simulate_step"); mutex1.unlock(); if (res != 0) { LOG_MSG("simulate_step: res != 0"); break; } if (i%summary_interval == 0) { mutex1.lock(); get_summary(Global::summaryData, &Global::i_hypoxia_cutoff, &Global::i_growth_cutoff); // get_volprob(&Global::vol_nv, &Global::vol_v0, &Global::vol_dv, Global::volProb); // get_oxyprob(&Global::oxy_nv, &Global::oxy_v0, &Global::oxy_dv, Global::oxyProb); // get_distdata(&Global::dist_nv, Global::distParams, Global::distData); get_concdata(&Global::conc_nvars, &Global::conc_nc_ex, &Global::conc_dx_ex, Global::concData); // get_ic_concdata(&Global::conc_nvars, &Global::conc_nc_ic, &Global::conc_dx_ic, Global::IC_concData); if (Global::showingFACS || Global::recordingFACS) { getFACS(); } mutex1.unlock(); if (Global::showingFACS || Global::recordingFACS) { emit facs_update(); emit histo_update(); } // hour++; hour = int(hour + (Global::DELTA_T*Global::NT_DISPLAY)/3600.); mutex1.lock(); emit summary(hour); // Emit signal to update summary plots, at hourly intervals } if (stopped) { res = -1; break; } // if (i%Global::nt_vtk == 0) { // if (Global::showingVTK || Global::recordingVTK) { // snapshot(); // Global::istep = i; // sleep(10); // } // } if (stopped) { res = -1; break; } } LOG_MSG("ExecThread::run: stopped or completed"); // snapshot(); // LOG_MSG("got snapshot:"); sleep(100); if (Global::simulate_colony) { make_colony_distribution(&Global::colony_days, Global::dist, &Global::ddist, &Global::ndist); } LOG_MSG("ExecThread::run: call terminate_run"); terminate_run(&res); return; }