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

Revision 265, 2.8 KB checked in by mattausch, 19 years ago (diff)

did bsp stuff

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                mBspTree->Construct(mViewCells);
98                break;
99        case BspTree::SCENE_GEOMETRY:
100                CLEAR_CONTAINER(mViewCells); // we generate new view cells
101
102                mSceneGraph->CollectObjects(&objects);
103                mBspTree->Construct(objects, &mViewCells);
104                break;
105        case BspTree::RAYS:
106                CLEAR_CONTAINER(mViewCells); // we generate new view cells     
107                mBspTree->Construct(rays, &mViewCells);
108                break;
109        default:
110                Debug << "Error: Method not available\n";
111                break;
112        }
113        return true;
114}
115
116
117void
118Preprocessor::KdTreeStatistics(ostream &s)
119{
120  s<<mKdTree->GetStatistics();
121}
122
123void
124Preprocessor::BspTreeStatistics(ostream &s)
125{
126        s << mBspTree->GetStatistics();
127}
128
129bool
130Preprocessor::Export( const string filename,
131                      const bool scene,
132                      const bool kdtree,
133                          const bool bsptree
134                      )
135{
136  Exporter *exporter = Exporter::GetExporter(filename);
137
138  if (exporter) {
139    if (scene)
140      exporter->ExportScene(mSceneGraph->mRoot);
141
142    if (kdtree) {
143      exporter->SetWireframe();
144      exporter->ExportKdTree(*mKdTree);
145    }
146
147        if (bsptree) {
148                //exporter->SetWireframe();
149                exporter->ExportBspTree(*mBspTree);
150        }
151
152    delete exporter;
153    return true;
154  }
155
156  return false;
157}
158
159
160
Note: See TracBrowser for help on using the repository browser.