Esempio n. 1
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");
}