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