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), |
---|
12 | mViewCellsType(BSP_VIEW_CELLS) |
---|
13 | { |
---|
14 | } |
---|
15 | |
---|
16 | |
---|
17 | Preprocessor::~Preprocessor() |
---|
18 | {
|
---|
19 | DeleteViewCells();
|
---|
20 | |
---|
21 | DEL_PTR(mBspTree); |
---|
22 | DEL_PTR(mKdTree); |
---|
23 | } |
---|
24 | |
---|
25 | bool |
---|
26 | Preprocessor::LoadViewCells(const string filename) |
---|
27 | { |
---|
28 | X3dParser parser; |
---|
29 | int maxViewCells = 0; |
---|
30 | environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight); |
---|
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; |
---|
45 | } |
---|
46 | |
---|
47 | bool |
---|
48 | Preprocessor::ParseViewCellsOptions() |
---|
49 | { |
---|
50 | // parse type of view cells |
---|
51 | char viewCellsStr[64]; |
---|
52 | environment->GetStringValue("ViewCells.hierarchy", viewCellsStr); |
---|
53 | |
---|
54 | int vcType = BSP_VIEW_CELLS; |
---|
55 | |
---|
56 | if (strcmp(viewCellsStr, "bspTree") == 0) |
---|
57 | mViewCellsType = BSP_VIEW_CELLS; |
---|
58 | else if (strcmp(viewCellsStr, "kdTree") == 0) |
---|
59 | mViewCellsType = KD_VIEW_CELLS; |
---|
60 | else if (strcmp(viewCellsStr, "sceneDependent") == 0) |
---|
61 | { |
---|
62 | //TODO |
---|
63 | } |
---|
64 | else |
---|
65 | { |
---|
66 | cerr<<"Wrong view cells type" << viewCellsStr << endl; |
---|
67 | exit(1); |
---|
68 | } |
---|
69 | |
---|
70 | if (mViewCellsType == KD_VIEW_CELLS) |
---|
71 | Debug << "kdtree" << endl; |
---|
72 | else if (mViewCellsType == BSP_VIEW_CELLS) |
---|
73 | Debug << "bsptree" << endl; |
---|
74 | |
---|
75 | return true; |
---|
76 | } |
---|
77 | |
---|
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 | |
---|
86 | bool |
---|
87 | Preprocessor::GenerateViewCells() |
---|
88 | { |
---|
89 | // TODO |
---|
90 | // HACK: derive view cells from the scene objects |
---|
91 | ObjectContainer objects; |
---|
92 | |
---|
93 | int maxViewCells = 0; |
---|
94 | environment->GetIntValue("ViewCells.maxViewCells", maxViewCells); |
---|
95 | |
---|
96 | mSceneGraph->CollectObjects(&objects); |
---|
97 | ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells); |
---|
98 | |
---|
99 | return true; |
---|
100 | } |
---|
101 | |
---|
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; |
---|
108 | |
---|
109 | |
---|
110 | Parser *parser; |
---|
111 | |
---|
112 | if (strstr(filename.c_str(), ".x3d")) |
---|
113 | parser = new X3dParser; |
---|
114 | else |
---|
115 | parser = new UnigraphicsParser; |
---|
116 | |
---|
117 | bool result = parser->ParseFile(filename, &mSceneGraph->mRoot); |
---|
118 | |
---|
119 | |
---|
120 | |
---|
121 | delete parser; |
---|
122 | |
---|
123 | if (result) |
---|
124 | mSceneGraph->AssignObjectIds(); |
---|
125 | |
---|
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(); |
---|
141 | mSceneGraph->CollectObjects(&root->mObjects); |
---|
142 | |
---|
143 | mKdTree->Construct(); |
---|
144 | return true; |
---|
145 | } |
---|
146 | |
---|
147 | void |
---|
148 | Preprocessor::KdTreeStatistics(ostream &s) |
---|
149 | { |
---|
150 | s<<mKdTree->GetStatistics(); |
---|
151 | } |
---|
152 | |
---|
153 | void |
---|
154 | Preprocessor::BspTreeStatistics(ostream &s) |
---|
155 | { |
---|
156 | s << mBspTree->GetStatistics(); |
---|
157 | } |
---|
158 | |
---|
159 | bool |
---|
160 | Preprocessor::Export( const string filename, |
---|
161 | const bool scene, |
---|
162 | const bool kdtree, |
---|
163 | const bool bsptree |
---|
164 | ) |
---|
165 | { |
---|
166 | Exporter *exporter = Exporter::GetExporter(filename); |
---|
167 | |
---|
168 | if (exporter) { |
---|
169 | if (scene) |
---|
170 | exporter->ExportScene(mSceneGraph->mRoot); |
---|
171 | |
---|
172 | if (kdtree) { |
---|
173 | exporter->SetWireframe(); |
---|
174 | exporter->ExportKdTree(*mKdTree); |
---|
175 | } |
---|
176 | |
---|
177 | if (bsptree) { |
---|
178 | //exporter->SetWireframe(); |
---|
179 | exporter->ExportBspTree(*mBspTree); |
---|
180 | } |
---|
181 | |
---|
182 | delete exporter; |
---|
183 | return true; |
---|
184 | } |
---|
185 | |
---|
186 | return false; |
---|
187 | } |
---|