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