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