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

Revision 262, 3.9 KB checked in by mattausch, 19 years ago (diff)

debugged bsp

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