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

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

did 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
[262]9Preprocessor::Preprocessor():
10mKdTree(NULL),
11mBspTree(NULL)
12{
13}
[261]14
15Preprocessor::~Preprocessor()
16{
[262]17  CLEAR_CONTAINER(mViewCells);
[261]18  DEL_PTR(mBspTree);
[262]19  DEL_PTR(mKdTree);
[261]20}
21
[162]22bool
[261]23Preprocessor::LoadViewCells(const string filename)
[162]24{
[263]25        return X3dParser().ParseFile(filename, mViewCells);
[162]26}
[65]27
[162]28bool
[261]29Preprocessor::GenerateViewCells()
[162]30{
[263]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;
[162]42}
[65]43
[162]44bool
45Preprocessor::LoadScene(const string filename)
46{
47  // use leaf nodes of the original spatial hiearrchy as occludees
48
49  mSceneGraph = new SceneGraph;
[170]50
51 
52  Parser *parser;
53
54  if (strstr(filename.c_str(), ".x3d"))
55    parser = new X3dParser;
56  else
57    parser = new UnigraphicsParser;
58
[162]59  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
[65]60 
[261]61  delete parser;
62
[162]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();
[176]78  mSceneGraph->CollectObjects(&root->mObjects);
[65]79 
[162]80  mKdTree->Construct();
81  return true;
82}
[65]83
[263]84
[234]85bool
86Preprocessor::BuildBspTree()
87{
[262]88        DEL_PTR(mBspTree);
[235]89        mBspTree = new BspTree();
90
[262]91        ObjectContainer objects;
92        RayContainer rays;
93
[263]94        switch (BspTree::sConstructionMethod)
[235]95        {
[263]96        case BspTree::VIEW_CELLS:
[261]97                mBspTree->Construct(mViewCells);
[235]98                break;
99        case BspTree::SCENE_GEOMETRY:
[265]100                CLEAR_CONTAINER(mViewCells); // we generate new view cells
[262]101
[263]102                mSceneGraph->CollectObjects(&objects);
[261]103                mBspTree->Construct(objects, &mViewCells);
[235]104                break;
[261]105        case BspTree::RAYS:
[263]106                CLEAR_CONTAINER(mViewCells); // we generate new view cells     
[262]107                mBspTree->Construct(rays, &mViewCells);
[261]108                break;
[235]109        default:
[262]110                Debug << "Error: Method not available\n";
[235]111                break;
112        }
113        return true;
[234]114}
[162]115
[234]116
[162]117void
118Preprocessor::KdTreeStatistics(ostream &s)
[65]119{
[162]120  s<<mKdTree->GetStatistics();
[65]121}
[162]122
[234]123void
124Preprocessor::BspTreeStatistics(ostream &s)
125{
[235]126        s << mBspTree->GetStatistics();
[234]127}
[162]128
129bool
130Preprocessor::Export( const string filename,
131                      const bool scene,
[242]132                      const bool kdtree,
133                          const bool bsptree
[162]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
[242]147        if (bsptree) {
[264]148                //exporter->SetWireframe();
[242]149                exporter->ExportBspTree(*mBspTree);
150        }
151
[162]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.