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

Revision 235, 2.6 KB checked in by mattausch, 19 years ago (diff)

added some 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
9 
10bool
11Preprocessor::LoadViewcells(const string filename)
12{
13 
14  return true;
15}
16
17bool
18Preprocessor::GenerateViewcells()
19{
20        return BuildBspTree();
21}
22
23bool
24Preprocessor::LoadScene(const string filename)
25{
26  // use leaf nodes of the original spatial hiearrchy as occludees
27
28  mSceneGraph = new SceneGraph;
29
30 
31  Parser *parser;
32
33  if (strstr(filename.c_str(), ".x3d"))
34    parser = new X3dParser;
35  else
36    parser = new UnigraphicsParser;
37
38  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
39 
40  return result;
41}
42
43bool
44Preprocessor::ExportPreprocessedData(const string filename)
45{
46  return false;
47}
48
49bool
50Preprocessor::BuildKdTree()
51{
52  mKdTree = new KdTree;
53  // add mesh instances of the scene graph to the root of the tree
54  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
55  mSceneGraph->CollectObjects(&root->mObjects);
56 
57  mKdTree->Construct();
58  return true;
59}
60
61bool
62Preprocessor::BuildBspTree()
63{
64        ObjectContainer objects;
65        mSceneGraph->CollectObjects(&objects);
66
67        mBspTree = new BspTree();
68
69        char constructionMethodStr[64];
70
71        environment->GetStringValue("BspTree.constructionMethod",
72                           constructionMethodStr);
73
74        int constructionMethod = BspTree::VIEWCELLS;
75
76        if (strcmp(constructionMethodStr, "viewCells") == 0)
77                constructionMethod = BspTree::VIEWCELLS;
78        else if (strcmp(constructionMethodStr, "sceneGeometry") == 0)
79                constructionMethod = BspTree::SCENE_GEOMETRY;
80        else
81        {
82                cerr << "Wrong bsp construction method " << constructionMethodStr << endl;
83                exit(1);
84    }
85
86        Debug << constructionMethodStr << endl;
87
88        switch (constructionMethod)
89        {
90        case BspTree::VIEWCELLS:
91                mViewcells.clear();
92                // derive viewcells from the scene objects
93                ViewCell::DeriveViewCells(objects, mViewcells, 1000);
94                mBspTree->Construct(mViewcells);
95                break;
96        case BspTree::SCENE_GEOMETRY:
97                mBspTree->Construct(objects);
98                break;
99        default:
100                break;
101        }
102        return true;
103}
104
105
106
107void
108Preprocessor::KdTreeStatistics(ostream &s)
109{
110  s<<mKdTree->GetStatistics();
111}
112
113void
114Preprocessor::BspTreeStatistics(ostream &s)
115{
116        s << mBspTree->GetStatistics();
117}
118
119bool
120Preprocessor::Export( const string filename,
121                      const bool scene,
122                      const bool kdtree
123                      )
124{
125  Exporter *exporter = Exporter::GetExporter(filename);
126
127  if (exporter) {
128    if (scene)
129      exporter->ExportScene(mSceneGraph->mRoot);
130
131    if (kdtree) {
132      exporter->SetWireframe();
133      exporter->ExportKdTree(*mKdTree);
134    }
135
136    delete exporter;
137    return true;
138  }
139
140  return false;
141}
142
143
144
Note: See TracBrowser for help on using the repository browser.