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

Revision 331, 3.4 KB checked in by mattausch, 19 years ago (diff)

fixed box error at from ray construction of bsp view cells

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
9Preprocessor::Preprocessor():
10mKdTree(NULL),
11mBspTree(NULL),
12mViewCellsType(BSP_VIEW_CELLS)
13{
14}
15
16Preprocessor::~Preprocessor()
17{
18        DeleteViewCells();
19               
20        DEL_PTR(mBspTree);
21        DEL_PTR(mKdTree);
22}
23
24bool
25Preprocessor::LoadViewCells(const string filename)
26{
27        X3dParser parser;
28        int maxViewCells = 0;
29        environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight);
30        environment->GetIntValue("ViewCells.maxViewCells", maxViewCells);
31
32        bool loaded = parser.ParseFile(filename, mViewCells);
33
34        if (maxViewCells > 0)
35        {
36                while (mViewCells.size() > maxViewCells)
37                {
38                        ViewCell *vc = mViewCells.back();
39                        DEL_PTR(vc);
40                        mViewCells.pop_back();
41                }
42        }
43        return loaded;
44}
45
46bool Preprocessor::ParseViewCellsOptions()
47{
48        // parse type of view cells
49        char viewCellsStr[64];
50        environment->GetStringValue("ViewCells.hierarchy", viewCellsStr);
51
52        int vcType = BSP_VIEW_CELLS;
53 
54        if (strcmp(viewCellsStr, "bspTree") == 0)
55                mViewCellsType = BSP_VIEW_CELLS;
56        else if (strcmp(viewCellsStr, "kdTree") == 0)
57                mViewCellsType = KD_VIEW_CELLS;
58        else if (strcmp(viewCellsStr, "sceneDependent") == 0)
59        {
60                //TODO
61        }
62        else
63        {
64                cerr<<"Wrong view cells type" << viewCellsStr << endl;
65                exit(1);
66        }
67
68        if (mViewCellsType == KD_VIEW_CELLS)
69                Debug << "kdtree" << endl;
70        else if (mViewCellsType == BSP_VIEW_CELLS)
71                Debug << "bsptree" << endl;
72
73        return true;
74}
75
76void Preprocessor::DeleteViewCells()
77{
78        for (int i = 0; i < mViewCells.size(); ++ i)
79                delete mViewCells[i]->GetMesh();
80
81        CLEAR_CONTAINER(mViewCells);
82}
83
84bool
85Preprocessor::GenerateViewCells()
86{
87        // TODO
88        // HACK: derive view cells from the scene objects
89        ObjectContainer objects;
90
91        int maxViewCells = 0;
92        environment->GetIntValue("ViewCells.maxViewCells", maxViewCells);
93
94        mSceneGraph->CollectObjects(&objects);
95        ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells);
96
97        return true;
98}
99
100bool
101Preprocessor::LoadScene(const string filename)
102{
103  // use leaf nodes of the original spatial hiearrchy as occludees
104
105  mSceneGraph = new SceneGraph;
106
107 
108  Parser *parser;
109
110  if (strstr(filename.c_str(), ".x3d"))
111    parser = new X3dParser;
112  else
113    parser = new UnigraphicsParser;
114
115  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
116 
117  delete parser;
118
119  return result;
120}
121
122bool
123Preprocessor::ExportPreprocessedData(const string filename)
124{
125  return false;
126}
127
128bool
129Preprocessor::BuildKdTree()
130{
131  mKdTree = new KdTree;
132  // add mesh instances of the scene graph to the root of the tree
133  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
134  mSceneGraph->CollectObjects(&root->mObjects);
135 
136  mKdTree->Construct();
137  return true;
138}
139
140void
141Preprocessor::KdTreeStatistics(ostream &s)
142{
143  s<<mKdTree->GetStatistics();
144}
145
146void
147Preprocessor::BspTreeStatistics(ostream &s)
148{
149        s << mBspTree->GetStatistics();
150}
151
152bool
153Preprocessor::Export( const string filename,
154                      const bool scene,
155                      const bool kdtree,
156                          const bool bsptree
157                      )
158{
159  Exporter *exporter = Exporter::GetExporter(filename);
160
161  if (exporter) {
162    if (scene)
163      exporter->ExportScene(mSceneGraph->mRoot);
164
165    if (kdtree) {
166      exporter->SetWireframe();
167      exporter->ExportKdTree(*mKdTree);
168    }
169
170        if (bsptree) {
171                //exporter->SetWireframe();
172                exporter->ExportBspTree(*mBspTree);
173        }
174
175    delete exporter;
176    return true;
177  }
178
179  return false;
180}
Note: See TracBrowser for help on using the repository browser.