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

RevLine 
[162]1#include "SceneGraph.h"
2#include "Exporter.h"
3#include "UnigraphicsParser.h"
[170]4#include "X3dParser.h"
[65]5#include "Preprocessor.h"
[235]6#include "ViewCell.h"
7#include "Environment.h"
[65]8
[162]9 
10bool
11Preprocessor::LoadViewcells(const string filename)
12{
13 
14  return true;
15}
[65]16
[162]17bool
18Preprocessor::GenerateViewcells()
19{
[235]20        return BuildBspTree();
[162]21}
[65]22
[162]23bool
24Preprocessor::LoadScene(const string filename)
25{
26  // use leaf nodes of the original spatial hiearrchy as occludees
27
28  mSceneGraph = new SceneGraph;
[170]29
30 
31  Parser *parser;
32
33  if (strstr(filename.c_str(), ".x3d"))
34    parser = new X3dParser;
35  else
36    parser = new UnigraphicsParser;
37
[162]38  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
[65]39 
[162]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();
[176]55  mSceneGraph->CollectObjects(&root->mObjects);
[65]56 
[162]57  mKdTree->Construct();
58  return true;
59}
[65]60
[234]61bool
62Preprocessor::BuildBspTree()
63{
[235]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;
[234]103}
[162]104
[234]105
106
[162]107void
108Preprocessor::KdTreeStatistics(ostream &s)
[65]109{
[162]110  s<<mKdTree->GetStatistics();
[65]111}
[162]112
[234]113void
114Preprocessor::BspTreeStatistics(ostream &s)
115{
[235]116        s << mBspTree->GetStatistics();
[234]117}
[162]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.