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

Revision 304, 3.0 KB checked in by mattausch, 19 years ago (diff)

bsp candidate selection heuristics tryout

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),
12mRootViewCell(NULL)
13{
14}
15
16Preprocessor::~Preprocessor()
17{
18  CLEAR_CONTAINER(mViewCells);
19  DEL_PTR(mBspTree);
20  DEL_PTR(mKdTree);
21  DEL_PTR(mRootViewCell);
22}
23
24bool
25Preprocessor::LoadViewCells(const string filename)
26{
27        return X3dParser().ParseFile(filename, mViewCells);
28}
29
30bool
31Preprocessor::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
46bool
47Preprocessor::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
68bool
69Preprocessor::ExportPreprocessedData(const string filename)
70{
71  return false;
72}
73
74bool
75Preprocessor::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
87bool
88Preprocessor::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;
97ViewCellContainer dummy;
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                mSceneGraph->CollectObjects(&objects);
106                mBspTree->Construct(objects, &mViewCells);
107                break;
108        case BspTree::RAYS:
109                CLEAR_CONTAINER(mViewCells); // we generate new view cells     
110                mBspTree->Construct(rays, &mViewCells);
111                break;
112        default:
113                Debug << "Error: Method not available\n";
114                break;
115        }
116        return true;
117}
118
119
120void
121Preprocessor::KdTreeStatistics(ostream &s)
122{
123  s<<mKdTree->GetStatistics();
124}
125
126void
127Preprocessor::BspTreeStatistics(ostream &s)
128{
129        s << mBspTree->GetStatistics();
130}
131
132bool
133Preprocessor::Export( const string filename,
134                      const bool scene,
135                      const bool kdtree,
136                          const bool bsptree
137                      )
138{
139  Exporter *exporter = Exporter::GetExporter(filename);
140
141  if (exporter) {
142    if (scene)
143      exporter->ExportScene(mSceneGraph->mRoot);
144
145    if (kdtree) {
146      exporter->SetWireframe();
147      exporter->ExportKdTree(*mKdTree);
148    }
149
150        if (bsptree) {
151                //exporter->SetWireframe();
152                exporter->ExportBspTree(*mBspTree);
153        }
154
155    delete exporter;
156    return true;
157  }
158
159  return false;
160}
161
162
163
Note: See TracBrowser for help on using the repository browser.