#include "SceneGraph.h" #include "Exporter.h" #include "UnigraphicsParser.h" #include "X3dParser.h" #include "Preprocessor.h" #include "ViewCell.h" #include "Environment.h" #include "ViewCellsManager.h" #include "ViewCellBsp.h" #include "VspBspTree.h" #include "VspKdTree.h" Preprocessor::Preprocessor(): mKdTree(NULL), mBspTree(NULL), mVspKdTree(NULL), mVspBspTree(NULL), mViewCellsManager(NULL) { } Preprocessor::~Preprocessor() { DEL_PTR(mBspTree); DEL_PTR(mKdTree); DEL_PTR(mVspKdTree); DEL_PTR(mVspBspTree); DEL_PTR(mViewCellsManager); } int SplitFilenames(const string str, vector &filenames) { int pos = 0; while(1) { int npos = str.find(';', pos); if (npos < 0 || npos - pos < 1) break; filenames.push_back(string(str, pos, npos - pos)); pos = npos + 1; } filenames.push_back(string(str, pos, str.size() - pos)); return (int)filenames.size(); } bool Preprocessor::LoadScene(const string filename) { // use leaf nodes of the original spatial hiearrchy as occludees mSceneGraph = new SceneGraph; Parser *parser; vector filenames; int files = SplitFilenames(filename, filenames); cout<ParseFile(filename, &mSceneGraph->mRoot); delete parser; } else { // root for different files mSceneGraph->mRoot = new SceneGraphNode; for (int i= 0; i < filenames.size(); i++) { if (strstr(filenames[i].c_str(), ".x3d")) parser = new X3dParser; else parser = new UnigraphicsParser; SceneGraphNode *node; if (parser->ParseFile(filenames[i], &node)) { mSceneGraph->mRoot->mChildren.push_back(node); // at least one file parsed result = true; } delete parser; } } if (result) { mSceneGraph->AssignObjectIds(); int intersectables, faces; mSceneGraph->GetStatistics(intersectables, faces); cout<GetRoot(); mSceneGraph->CollectObjects(&root->mObjects); mKdTree->Construct(); return true; } void Preprocessor::KdTreeStatistics(ostream &s) { s<GetStatistics(); } void Preprocessor::BspTreeStatistics(ostream &s) { s << mBspTree->GetStatistics(); } bool Preprocessor::Export( const string filename, const bool scene, const bool kdtree, const bool bsptree ) { Exporter *exporter = Exporter::GetExporter(filename); if (exporter) { if (scene) exporter->ExportScene(mSceneGraph->mRoot); if (kdtree) { exporter->SetWireframe(); exporter->ExportKdTree(*mKdTree); } if (bsptree) { //exporter->SetWireframe(); exporter->ExportBspTree(*mBspTree); } delete exporter; return true; } return false; } bool Preprocessor::PrepareViewCells() { //-- parse type of view cell container char viewCellsStr[64]; environment->GetStringValue("ViewCells.type", viewCellsStr); int constructionSamples = 0; if (strcmp(viewCellsStr, "kdTree") == 0) { mViewCellsManager = new KdViewCellsManager(mKdTree); } if (strcmp(viewCellsStr, "bspTree") == 0) { mBspTree = new BspTree(); environment->GetIntValue("BspTree.Construction.samples", constructionSamples); mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples); } if (strcmp(viewCellsStr, "vspBspTree") == 0) { mVspBspTree = new VspBspTree(); environment->GetIntValue("VspBspTree.Construction.samples", constructionSamples); mViewCellsManager = new VspBspViewCellsManager(mVspBspTree, constructionSamples); } else if (strcmp(viewCellsStr, "vspKdTree") == 0) { mVspKdTree = new VspKdTree(); environment->GetIntValue("VspKdTree.Construction.samples", constructionSamples); mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, constructionSamples); } else if (strcmp(viewCellsStr, "sceneDependent") == 0) { //TODO mBspTree = new BspTree(); environment->GetIntValue("BspTree.Construction.samples", constructionSamples); mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples); } else { cerr<<"Wrong view cells type" << viewCellsStr << endl; exit(1); } int postProcessSamples = 0; int visSamples = 0; environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples); environment->GetIntValue("ViewCells.Visualization.samples", visSamples); mViewCellsManager->SetPostProcessSamples(postProcessSamples); mViewCellsManager->SetVisualizationSamples(visSamples); //Debug << "Visualization samples: " << mViewCellsManager->GetVisualizationSamples() << endl; //-- parse view cells construction method bool loadViewCells = false; environment->GetBoolValue("ViewCells.loadFromFile", loadViewCells); //-- load view cells from file if requested if (loadViewCells) { char buff[100]; environment->GetStringValue("ViewCells.filename", buff); string vcFilename(buff); mViewCellsManager->LoadViewCells(vcFilename); } return true; }