void cutFinished() { if(!g_parser.value_to_int("disjoint")) return; vector<CuttableMesh*> vMeshes; g_lpTissue->convertDisjointPartsToMeshes(vMeshes); if(vMeshes.size() == 0) return; U32 ctMaxCells = 0; U32 idxMaxCell = 0; for(U32 i=0; i < vMeshes.size(); i++) { vMeshes[i]->computeAABB(); vMeshes[i]->setElemToShow(0); TheEngine::Instance().add(vMeshes[i]); if(vMeshes[i]->countCells() > ctMaxCells) { ctMaxCells = vMeshes[i]->countCells(); idxMaxCell = i; } } g_lpTissue = vMeshes[idxMaxCell]; g_lpTissue->setElemToShow(); if(g_lpAvatar) g_lpAvatar->setTissue(g_lpTissue); }
int main(int argc, char* argv[]) { int ctThreads = tbb::task_scheduler_init::default_num_threads(); tbb::task_scheduler_init init(ctThreads); cout << "started tbb with " << ctThreads << " threads." << endl; //parser g_parser.addSwitch("--disjoint", "-d", "converts splitted part to disjoint meshes", "0"); g_parser.addSwitch("--ringscalpel", "-r", "If the switch presents then the ring scalpel will be used"); g_parser.addSwitch("--verbose", "-v", "prints detailed description."); g_parser.addSwitch("--input", "-i", "[filepath] set input file in vega format", "internal"); //g_parser.addSwitch("--example", "-e", "[one, two, cube, eggshell] set an internal example", "two"); //g_parser.addSwitch("--gizmo", "-g", "loads a file to set gizmo location and orientation", "gizmo.ini"); if(g_parser.parse(argc, argv) < 0) exit(0); //file path g_strIniFilePath = AnsiStr(g_parser.value("input").c_str()); if(FileExists(g_strIniFilePath)) vloginfo("input file: %s.", g_strIniFilePath.cptr()); else { vlogerror("Unable to find input filepath: [%s]", g_strIniFilePath.cptr()); exit(1); } //GLFW LIB g_lpWindow = NULL; glfwSetErrorCallback(error_callback); if (!glfwInit()) { vlogerror("Failed to init glfw"); exit(EXIT_FAILURE); } /* glfwWindowHint(GLFW_SAMPLES, 4); glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3); glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3); glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); */ g_lpWindow = glfwCreateWindow(DEFAULT_WIDTH, DEFAULT_HEIGHT, "tetcutter - Pourya Shirazian", NULL, NULL); if (!g_lpWindow) { glfwTerminate(); exit(EXIT_FAILURE); } glfwMakeContextCurrent(g_lpWindow); glfwSwapInterval(1); glfwSetKeyCallback(g_lpWindow, key_callback); glfwSetCursorPosCallback(g_lpWindow, mouse_motion_callback); glfwSetMouseButtonCallback(g_lpWindow, mouse_button_callback); glfwSetScrollCallback(g_lpWindow, scroll_callback); //init gl def_initgl(); //Build Shaders for drawing the mesh IniFile ini(g_strIniFilePath, IniFile::fmRead); AnsiStr strRoot = ini.readString("system", "data"); AnsiStr strShaderRoot = strRoot + "shaders/"; AnsiStr strTextureRoot = strRoot + "textures/"; AnsiStr strFontsRoot = strRoot + "fonts/"; //convert mesh // AnsiStr strNodesFP = strRoot + AnsiStr("data/meshes/matlab/nodes.txt"); // AnsiStr strFacesFP = strRoot + AnsiStr("data/meshes/matlab/faces.txt"); // AnsiStr strCellsFP = strRoot + AnsiStr("data/meshes/matlab/cells.txt"); // VolMeshIO::convertMatlabTextToVega(strNodesFP, strFacesFP, strCellsFP); //Load Shaders TheShaderManager::Instance().addFromFolder(strShaderRoot.cptr()); //Load Textures TheTexManager::Instance().add(strTextureRoot + "wood.png"); TheTexManager::Instance().add(strTextureRoot + "spin.png"); TheTexManager::Instance().add(strTextureRoot + "icefloor.png"); // TheTexManager::Instance().add(strTextureRoot + "rendermask.png"); // TheTexManager::Instance().add(strTextureRoot + "maskalpha.png"); // TheTexManager::Instance().add(strTextureRoot + "maskalphafilled.png"); vloginfo("Floor show is set to: [%d]", ini.readBool("visible", "floor")); //Ground and Room SGQuad* floor = new SGQuad(16.0f, 16.0f, TheTexManager::Instance().get("icefloor")); floor->setName("floor"); floor->transform()->translate(vec3f(0, -0.1f, 0)); floor->transform()->rotate(vec3f(1.0f, 0.0f, 0.0f), 90.0f); floor->setVisible(ini.readBool("visible", "floor")); TheEngine::Instance().add(floor); //Create Scalpel g_lpScalpel = new AvatarScalpel(); g_lpScalpel->setVisible(false); g_lpRing = new AvatarRing(TheTexManager::Instance().get("spin")); g_lpRing->setVisible(false); TheEngine::Instance().add(g_lpScalpel); TheEngine::Instance().add(g_lpRing); if(g_parser.value_to_int("ringscalpel") == 1) { g_lpAvatar = g_lpRing; g_lpRing->setVisible(true); } else { g_lpAvatar = g_lpScalpel; g_lpScalpel->setVisible(true); } g_lpAvatar->setTissue(g_lpTissue); g_lpAvatar->setOnCutFinishedEventHandler(cutFinished); TheGizmoManager::Instance().setFocusedNode(g_lpAvatar); TheGizmoManager::Instance().readConfig(g_strIniFilePath); //setup engine TheEngine::Instance().readConfig(g_strIniFilePath); TheEngine::Instance().headers()->addHeaderLine("cell", "info"); TheEngine::Instance().print(); //reset cuttable mesh resetMesh(); //mainloop while (!glfwWindowShouldClose(g_lpWindow)) { //setup projection matrix int width = DEFAULT_WIDTH; int height = DEFAULT_HEIGHT; glfwGetFramebufferSize(g_lpWindow, &width, &height); def_resize(width, height); //draw frame draw(); timestep(); glfwSwapBuffers(g_lpWindow); glfwPollEvents(); } //destroy window glfwDestroyWindow(g_lpWindow); glfwTerminate(); exit(EXIT_SUCCESS); return 0; }
bool resetMesh() { //remove it from scenegraph TheEngine::Instance().remove(g_lpTissue); SAFE_DELETE(g_lpTissue); if(!FileExists(g_strIniFilePath)) { vlogerror("ini file not exists! [%s]", g_strIniFilePath.c_str()); return false; } vloginfo("reading model config from ini file: [%s]", g_strIniFilePath.c_str()); IniFile ini(g_strIniFilePath, IniFile::fmRead); AnsiStr mdl_type = ini.readString("model", "type"); AnsiStr mdl_name = ini.readString("model", "name"); VolMesh* temp = NULL; //loading internal model if(mdl_type == "internal") { int pos = -1; if(mdl_name == "one") temp = VolMeshSamples::CreateOneTetra(); else if(mdl_name == "two") temp = VolMeshSamples::CreateTwoTetra(); else if(mdl_name.lfindstr(AnsiStr("cube"), pos)) { U32 nx, ny, nz = 0; sscanf(mdl_name.cptr(), "cube_%u_%u_%u", &nx, &ny, &nz); temp = VolMeshSamples::CreateTruthCube(nx, ny, nz, 0.2); } else if(mdl_name.lfindstr(AnsiStr("eggshell"), pos)) { U32 nx, ny; //float radius, thickness; sscanf(mdl_name.cptr(), "eggshell_%u_%u", &nx, &ny); temp = VolMeshSamples::CreateEggShell(nx, ny); } else temp = VolMeshSamples::CreateOneTetra(); } else if(mdl_type == "file") { temp = new VolMesh(); temp->setFlagFilterOutFlatCells(false); temp->setVerbose(g_parser.value_to_int("verbose")); if(!FileExists(mdl_name)) { AnsiStr data_root_path = ini.readString("system", "data"); mdl_name = data_root_path + "meshes/veg/" + mdl_name; vloginfo("resolved model name to [%s]", mdl_name.cptr()); } vloginfo("Begin to read vega file from: %s", mdl_name.cptr()); bool res = VolMeshIO::readVega(temp, mdl_name); if(!res) vlogerror("Unable to load mesh from: %s", mdl_name.cptr()); } vloginfo("Loaded mesh to temp"); g_lpTissue = new CuttableMesh(*temp); g_lpTissue->setFlagSplitMeshAfterCut(true); g_lpTissue->setFlagDrawNodes(true); g_lpTissue->setFlagDrawWireFrame(false); g_lpTissue->setFlagDrawSweepSurf(ini.readBool("visible", "sweepsurf")); g_lpTissue->setColor(Color::skin()); g_lpTissue->setVerbose(g_parser.value_to_int("verbose") != 0); g_lpTissue->syncRender(); SAFE_DELETE(temp); TheEngine::Instance().add(g_lpTissue); if(g_parser.value_to_int("ringscalpel") == 1) g_lpRing->setTissue(g_lpTissue); else g_lpScalpel->setTissue(g_lpTissue); //print stats VolMeshStats::printAllStats(g_lpTissue); vloginfo("mesh load completed"); }