[162] | 1 | #include "SceneGraph.h" |
---|
| 2 | #include "Exporter.h" |
---|
| 3 | #include "UnigraphicsParser.h" |
---|
[170] | 4 | #include "X3dParser.h" |
---|
[65] | 5 | #include "Preprocessor.h" |
---|
[235] | 6 | #include "ViewCell.h" |
---|
| 7 | #include "Environment.h" |
---|
[65] | 8 | |
---|
[262] | 9 | Preprocessor::Preprocessor(): |
---|
| 10 | mKdTree(NULL), |
---|
[297] | 11 | mBspTree(NULL), |
---|
[309] | 12 | mViewCellsType(BSP_VIEW_CELLS) |
---|
[262] | 13 | { |
---|
| 14 | } |
---|
[261] | 15 | |
---|
| 16 | Preprocessor::~Preprocessor() |
---|
[308] | 17 | {
|
---|
| 18 | DeleteViewCells();
|
---|
| 19 | |
---|
| 20 | DEL_PTR(mBspTree); |
---|
| 21 | DEL_PTR(mKdTree); |
---|
[261] | 22 | } |
---|
| 23 | |
---|
[162] | 24 | bool |
---|
[261] | 25 | Preprocessor::LoadViewCells(const string filename) |
---|
[162] | 26 | { |
---|
[312] | 27 | X3dParser parser; |
---|
[313] | 28 | int maxViewCells = 0; |
---|
[312] | 29 | environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); |
---|
[313] | 30 | environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); |
---|
| 31 | |
---|
| 32 | bool loaded = parser.ParseFile(filename, mViewCells); |
---|
| 33 | |
---|
| 34 | if (maxViewCells > 0) |
---|
| 35 | { |
---|
| 36 | while (mViewCells.size() > maxViewCells) |
---|
| 37 | { |
---|
| 38 | ViewCell *vc = mViewCells.back(); |
---|
| 39 | DEL_PTR(vc); |
---|
| 40 | mViewCells.pop_back(); |
---|
| 41 | } |
---|
| 42 | } |
---|
| 43 | return loaded; |
---|
[162] | 44 | } |
---|
[65] | 45 | |
---|
[310] | 46 | bool Preprocessor::ParseViewCellsOptions() |
---|
| 47 | { |
---|
| 48 | // parse type of view cells |
---|
| 49 | char viewCellsStr[64]; |
---|
[329] | 50 | environment->GetStringValue("ViewCells.hierarchy", viewCellsStr); |
---|
[310] | 51 | |
---|
| 52 | int vcType = BSP_VIEW_CELLS; |
---|
| 53 | |
---|
| 54 | if (strcmp(viewCellsStr, "bspTree") == 0) |
---|
[331] | 55 | mViewCellsType = BSP_VIEW_CELLS; |
---|
[310] | 56 | else if (strcmp(viewCellsStr, "kdTree") == 0) |
---|
[331] | 57 | mViewCellsType = KD_VIEW_CELLS; |
---|
[310] | 58 | else if (strcmp(viewCellsStr, "sceneDependent") == 0) |
---|
[329] | 59 | { |
---|
| 60 | //TODO |
---|
| 61 | } |
---|
[310] | 62 | else |
---|
| 63 | { |
---|
| 64 | cerr<<"Wrong view cells type" << viewCellsStr << endl; |
---|
| 65 | exit(1); |
---|
| 66 | } |
---|
| 67 | |
---|
[329] | 68 | if (mViewCellsType == KD_VIEW_CELLS) |
---|
| 69 | Debug << "kdtree" << endl; |
---|
| 70 | else if (mViewCellsType == BSP_VIEW_CELLS) |
---|
| 71 | Debug << "bsptree" << endl; |
---|
[310] | 72 | |
---|
| 73 | return true; |
---|
| 74 | } |
---|
| 75 | |
---|
[308] | 76 | void Preprocessor::DeleteViewCells() |
---|
| 77 | { |
---|
| 78 | for (int i = 0; i < mViewCells.size(); ++ i) |
---|
| 79 | delete mViewCells[i]->GetMesh(); |
---|
| 80 | |
---|
| 81 | CLEAR_CONTAINER(mViewCells); |
---|
| 82 | } |
---|
| 83 | |
---|
[162] | 84 | bool |
---|
[261] | 85 | Preprocessor::GenerateViewCells() |
---|
[162] | 86 | { |
---|
[263] | 87 | // TODO |
---|
| 88 | // HACK: derive view cells from the scene objects |
---|
| 89 | ObjectContainer objects; |
---|
| 90 | |
---|
| 91 | int maxViewCells = 0; |
---|
[313] | 92 | environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); |
---|
[263] | 93 | |
---|
| 94 | mSceneGraph->CollectObjects(&objects); |
---|
| 95 | ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); |
---|
| 96 | |
---|
| 97 | return true; |
---|
[162] | 98 | } |
---|
[65] | 99 | |
---|
[162] | 100 | bool |
---|
| 101 | Preprocessor::LoadScene(const string filename) |
---|
| 102 | { |
---|
| 103 | // use leaf nodes of the original spatial hiearrchy as occludees |
---|
| 104 | |
---|
| 105 | mSceneGraph = new SceneGraph; |
---|
[170] | 106 | |
---|
| 107 | |
---|
| 108 | Parser *parser; |
---|
| 109 | |
---|
| 110 | if (strstr(filename.c_str(), ".x3d")) |
---|
| 111 | parser = new X3dParser; |
---|
| 112 | else |
---|
| 113 | parser = new UnigraphicsParser; |
---|
| 114 | |
---|
[162] | 115 | bool result = parser->ParseFile(filename, &mSceneGraph->mRoot); |
---|
[65] | 116 | |
---|
[261] | 117 | delete parser; |
---|
| 118 | |
---|
[162] | 119 | return result; |
---|
| 120 | } |
---|
| 121 | |
---|
| 122 | bool |
---|
| 123 | Preprocessor::ExportPreprocessedData(const string filename) |
---|
| 124 | { |
---|
| 125 | return false; |
---|
| 126 | } |
---|
| 127 | |
---|
| 128 | bool |
---|
| 129 | Preprocessor::BuildKdTree() |
---|
| 130 | { |
---|
| 131 | mKdTree = new KdTree; |
---|
| 132 | // add mesh instances of the scene graph to the root of the tree |
---|
| 133 | KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); |
---|
[176] | 134 | mSceneGraph->CollectObjects(&root->mObjects); |
---|
[65] | 135 | |
---|
[162] | 136 | mKdTree->Construct(); |
---|
| 137 | return true; |
---|
| 138 | } |
---|
[65] | 139 | |
---|
[162] | 140 | void |
---|
| 141 | Preprocessor::KdTreeStatistics(ostream &s) |
---|
[65] | 142 | { |
---|
[162] | 143 | s<<mKdTree->GetStatistics(); |
---|
[65] | 144 | } |
---|
[162] | 145 | |
---|
[234] | 146 | void |
---|
| 147 | Preprocessor::BspTreeStatistics(ostream &s) |
---|
| 148 | { |
---|
[235] | 149 | s << mBspTree->GetStatistics(); |
---|
[234] | 150 | } |
---|
[162] | 151 | |
---|
| 152 | bool |
---|
| 153 | Preprocessor::Export( const string filename, |
---|
| 154 | const bool scene, |
---|
[242] | 155 | const bool kdtree, |
---|
| 156 | const bool bsptree |
---|
[162] | 157 | ) |
---|
| 158 | { |
---|
| 159 | Exporter *exporter = Exporter::GetExporter(filename); |
---|
| 160 | |
---|
| 161 | if (exporter) { |
---|
| 162 | if (scene) |
---|
| 163 | exporter->ExportScene(mSceneGraph->mRoot); |
---|
| 164 | |
---|
| 165 | if (kdtree) { |
---|
| 166 | exporter->SetWireframe(); |
---|
| 167 | exporter->ExportKdTree(*mKdTree); |
---|
| 168 | } |
---|
| 169 | |
---|
[242] | 170 | if (bsptree) { |
---|
[264] | 171 | //exporter->SetWireframe(); |
---|
[242] | 172 | exporter->ExportBspTree(*mBspTree); |
---|
| 173 | } |
---|
| 174 | |
---|
[162] | 175 | delete exporter; |
---|
| 176 | return true; |
---|
| 177 | } |
---|
| 178 | |
---|
| 179 | return false; |
---|
[310] | 180 | } |
---|