source: trunk/VUT/GtpVisibilityPreprocessor/src/Preprocessor.cpp @ 263

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