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

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

debugged 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:
[262]97                Debug << "Construction method: view cells\n";
[263]98               
[261]99                mBspTree->Construct(mViewCells);
[235]100                break;
101        case BspTree::SCENE_GEOMETRY:
[262]102                Debug << "Construction method: geometry\n";
103
104        CLEAR_CONTAINER(mViewCells); // we generate new view cells
105
[263]106                mSceneGraph->CollectObjects(&objects);
[261]107                mBspTree->Construct(objects, &mViewCells);
[235]108                break;
[261]109        case BspTree::RAYS:
[262]110                Debug << "Construction method: rays\n";
111
[263]112                CLEAR_CONTAINER(mViewCells); // we generate new view cells     
[262]113                mBspTree->Construct(rays, &mViewCells);
[261]114                break;
[235]115        default:
[262]116                Debug << "Error: Method not available\n";
[235]117                break;
118        }
119        return true;
[234]120}
[162]121
[234]122
[162]123void
124Preprocessor::KdTreeStatistics(ostream &s)
[65]125{
[162]126  s<<mKdTree->GetStatistics();
[65]127}
[162]128
[234]129void
130Preprocessor::BspTreeStatistics(ostream &s)
131{
[235]132        s << mBspTree->GetStatistics();
[234]133}
[162]134
135bool
136Preprocessor::Export( const string filename,
137                      const bool scene,
[242]138                      const bool kdtree,
139                          const bool bsptree
[162]140                      )
141{
142  Exporter *exporter = Exporter::GetExporter(filename);
143
144  if (exporter) {
145    if (scene)
146      exporter->ExportScene(mSceneGraph->mRoot);
147
148    if (kdtree) {
149      exporter->SetWireframe();
150      exporter->ExportKdTree(*mKdTree);
151    }
152
[242]153        if (bsptree) {
[264]154                //exporter->SetWireframe();
[242]155                exporter->ExportBspTree(*mBspTree);
156        }
157
[162]158    delete exporter;
159    return true;
160  }
161
162  return false;
163}
164
165
166
Note: See TracBrowser for help on using the repository browser.