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