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

Revision 261, 3.4 KB checked in by mattausch, 19 years ago (diff)

added viewcell loader

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
9
10Preprocessor::~Preprocessor()
11{
12  // delete view cells
13  while (!mViewCells.empty())
14  {
15          DEL_PTR(mViewCells.back());
16          mViewCells.pop_back();
17  }
18
19  // delete psp tree
20  DEL_PTR(mBspTree);
21}
22
23bool
24Preprocessor::LoadViewCells(const string filename)
25{
26        X3dParser *parser = new X3dParser;
27
28        delete parser;
29
30        bool result = parser->ParseFile(filename, mViewCells);
31
32        if (result)
33        {
34                Exporter *exporter = Exporter::GetExporter(filename);
35
36                if (exporter)
37                        exporter->ExportViewCells(&mViewCells);
38
39                GenerateViewCells();
40        }
41        return result;
42}
43
44bool
45Preprocessor::GenerateViewCells()
46{
47        return BuildBspTree();
48}
49
50bool
51Preprocessor::LoadScene(const string filename)
52{
53  // use leaf nodes of the original spatial hiearrchy as occludees
54
55  mSceneGraph = new SceneGraph;
56
57 
58  Parser *parser;
59
60  if (strstr(filename.c_str(), ".x3d"))
61    parser = new X3dParser;
62  else
63    parser = new UnigraphicsParser;
64
65  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
66 
67  delete parser;
68
69  return result;
70}
71
72bool
73Preprocessor::ExportPreprocessedData(const string filename)
74{
75  return false;
76}
77
78bool
79Preprocessor::BuildKdTree()
80{
81  mKdTree = new KdTree;
82  // add mesh instances of the scene graph to the root of the tree
83  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
84  mSceneGraph->CollectObjects(&root->mObjects);
85 
86  mKdTree->Construct();
87  return true;
88}
89
90bool
91Preprocessor::BuildBspTree()
92{
93        ObjectContainer objects;
94        mSceneGraph->CollectObjects(&objects);
95
96        mBspTree = new BspTree();
97
98        char constructionMethodStr[64];
99        int maxViewCells = 0;
100
101        environment->GetIntValue("BspTree.maxViewCells", maxViewCells);
102        environment->GetStringValue("BspTree.constructionMethod", constructionMethodStr);
103
104        int constructionMethod = BspTree::VIEWCELLS;
105       
106        if (strcmp(constructionMethodStr, "viewCells") == 0)
107                constructionMethod = BspTree::VIEWCELLS;
108        else if (strcmp(constructionMethodStr, "sceneGeometry") == 0)
109                constructionMethod = BspTree::SCENE_GEOMETRY;
110        else if (strcmp(constructionMethodStr, "rays") == 0)
111                constructionMethod = BspTree::RAYS;
112        else
113        {
114                cerr << "Wrong bsp construction method " << constructionMethodStr << endl;
115                exit(1);
116    }
117
118        switch (constructionMethod)
119        {
120        case BspTree::VIEWCELLS:
121                // derive view cells from the scene objects
122                //ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells);
123               
124                mBspTree->Construct(mViewCells);
125                break;
126        case BspTree::SCENE_GEOMETRY:
127                CLEAR_CONTAINER(mViewCells);
128                mBspTree->Construct(objects, &mViewCells);
129                break;
130        case BspTree::RAYS:
131                CLEAR_CONTAINER(mViewCells);
132                mBspTree->Construct(objects, &mViewCells);
133                break;
134        default:
135                break;
136        }
137        return true;
138}
139
140
141void
142Preprocessor::KdTreeStatistics(ostream &s)
143{
144  s<<mKdTree->GetStatistics();
145}
146
147void
148Preprocessor::BspTreeStatistics(ostream &s)
149{
150        s << mBspTree->GetStatistics();
151}
152
153bool
154Preprocessor::Export( const string filename,
155                      const bool scene,
156                      const bool kdtree,
157                          const bool bsptree
158                      )
159{
160  Exporter *exporter = Exporter::GetExporter(filename);
161
162  if (exporter) {
163    if (scene)
164      exporter->ExportScene(mSceneGraph->mRoot);
165
166    if (kdtree) {
167      exporter->SetWireframe();
168      exporter->ExportKdTree(*mKdTree);
169    }
170
171        if (bsptree) {
172                exporter->SetWireframe();
173                exporter->ExportBspTree(*mBspTree);
174        }
175
176    delete exporter;
177    return true;
178  }
179
180  return false;
181}
182
183
184
Note: See TracBrowser for help on using the repository browser.