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 | |
---|
10 | bool |
---|
11 | Preprocessor::LoadViewcells(const string filename) |
---|
12 | { |
---|
13 | |
---|
14 | return true; |
---|
15 | } |
---|
16 | |
---|
17 | bool |
---|
18 | Preprocessor::GenerateViewcells() |
---|
19 | { |
---|
20 | return BuildBspTree(); |
---|
21 | } |
---|
22 | |
---|
23 | bool |
---|
24 | Preprocessor::LoadScene(const string filename) |
---|
25 | { |
---|
26 | // use leaf nodes of the original spatial hiearrchy as occludees |
---|
27 | |
---|
28 | mSceneGraph = new SceneGraph; |
---|
29 | |
---|
30 | |
---|
31 | Parser *parser; |
---|
32 | |
---|
33 | if (strstr(filename.c_str(), ".x3d")) |
---|
34 | parser = new X3dParser; |
---|
35 | else |
---|
36 | parser = new UnigraphicsParser; |
---|
37 | |
---|
38 | bool result = parser->ParseFile(filename, &mSceneGraph->mRoot); |
---|
39 | |
---|
40 | return result; |
---|
41 | } |
---|
42 | |
---|
43 | bool |
---|
44 | Preprocessor::ExportPreprocessedData(const string filename) |
---|
45 | { |
---|
46 | return false; |
---|
47 | } |
---|
48 | |
---|
49 | bool |
---|
50 | Preprocessor::BuildKdTree() |
---|
51 | { |
---|
52 | mKdTree = new KdTree; |
---|
53 | // add mesh instances of the scene graph to the root of the tree |
---|
54 | KdLeaf *root = (KdLeaf *)mKdTree->GetRoot(); |
---|
55 | mSceneGraph->CollectObjects(&root->mObjects); |
---|
56 | |
---|
57 | mKdTree->Construct(); |
---|
58 | return true; |
---|
59 | } |
---|
60 | |
---|
61 | bool |
---|
62 | Preprocessor::BuildBspTree() |
---|
63 | { |
---|
64 | ObjectContainer objects; |
---|
65 | mSceneGraph->CollectObjects(&objects); |
---|
66 | |
---|
67 | mBspTree = new BspTree(); |
---|
68 | |
---|
69 | char constructionMethodStr[64]; |
---|
70 | int maxViewCells = 0; |
---|
71 | |
---|
72 | environment->GetIntValue("BspTree.maxViewCells", maxViewCells); |
---|
73 | environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr); |
---|
74 | |
---|
75 | int constructionMethod = BspTree::VIEWCELLS; |
---|
76 | |
---|
77 | if (strcmp(constructionMethodStr, "viewCells") == 0) |
---|
78 | constructionMethod = BspTree::VIEWCELLS; |
---|
79 | else if (strcmp(constructionMethodStr, "sceneGeometry") == 0) |
---|
80 | constructionMethod = BspTree::SCENE_GEOMETRY; |
---|
81 | else |
---|
82 | { |
---|
83 | cerr << "Wrong bsp construction method " << constructionMethodStr << endl; |
---|
84 | exit(1); |
---|
85 | } |
---|
86 | |
---|
87 | switch (constructionMethod) |
---|
88 | { |
---|
89 | case BspTree::VIEWCELLS: |
---|
90 | |
---|
91 | mViewcells.clear(); |
---|
92 | |
---|
93 | // derive viewcells from the scene objects |
---|
94 | ViewCell::DeriveViewCells(objects, mViewcells, maxViewCells); |
---|
95 | |
---|
96 | mBspTree->Construct(mViewcells); |
---|
97 | break; |
---|
98 | case BspTree::SCENE_GEOMETRY: |
---|
99 | mBspTree->Construct(objects); |
---|
100 | break; |
---|
101 | default: |
---|
102 | break; |
---|
103 | } |
---|
104 | return true; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | void |
---|
109 | Preprocessor::KdTreeStatistics(ostream &s) |
---|
110 | { |
---|
111 | s<<mKdTree->GetStatistics(); |
---|
112 | } |
---|
113 | |
---|
114 | void |
---|
115 | Preprocessor::BspTreeStatistics(ostream &s) |
---|
116 | { |
---|
117 | s << mBspTree->GetStatistics(); |
---|
118 | } |
---|
119 | |
---|
120 | bool |
---|
121 | Preprocessor::Export( const string filename, |
---|
122 | const bool scene, |
---|
123 | const bool kdtree, |
---|
124 | const bool bsptree |
---|
125 | ) |
---|
126 | { |
---|
127 | Exporter *exporter = Exporter::GetExporter(filename); |
---|
128 | |
---|
129 | if (exporter) { |
---|
130 | if (scene) |
---|
131 | exporter->ExportScene(mSceneGraph->mRoot); |
---|
132 | |
---|
133 | if (kdtree) { |
---|
134 | exporter->SetWireframe(); |
---|
135 | exporter->ExportKdTree(*mKdTree); |
---|
136 | } |
---|
137 | |
---|
138 | if (bsptree) { |
---|
139 | exporter->SetWireframe(); |
---|
140 | exporter->ExportBspTree(*mBspTree); |
---|
141 | } |
---|
142 | |
---|
143 | delete exporter; |
---|
144 | return true; |
---|
145 | } |
---|
146 | |
---|
147 | return false; |
---|
148 | } |
---|
149 | |
---|
150 | |
---|
151 | |
---|