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

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

worked on ray based subdivision

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        {
56                Debug << "here bsp" << endl;
57        mViewCellsType = BSP_VIEW_CELLS;
58        }
59        else if (strcmp(viewCellsStr, "kdTree") == 0)
60                {
61                Debug << "here kd" << endl;
62        mViewCellsType = KD_VIEW_CELLS;
63        }
64        else if (strcmp(viewCellsStr, "sceneDependent") == 0)
65        {
66                //TODO
67        }
68        else
69        {
70                cerr<<"Wrong view cells type" << viewCellsStr << endl;
71                exit(1);
72        }
73
74        if (mViewCellsType == KD_VIEW_CELLS)
75                Debug << "kdtree" << endl;
76        else if (mViewCellsType == BSP_VIEW_CELLS)
77                Debug << "bsptree" << endl;
78
79        return true;
80}
81
82void Preprocessor::DeleteViewCells()
83{
84        for (int i = 0; i < mViewCells.size(); ++ i)
85                delete mViewCells[i]->GetMesh();
86
87        CLEAR_CONTAINER(mViewCells);
88}
89
90bool
91Preprocessor::GenerateViewCells()
92{
93        // TODO
94        // HACK: derive view cells from the scene objects
95        ObjectContainer objects;
96
97        int maxViewCells = 0;
98        environment->GetIntValue("ViewCells.maxViewCells", maxViewCells);
99
100        mSceneGraph->CollectObjects(&objects);
101        ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells);
102
103        return true;
104}
105
106bool
107Preprocessor::LoadScene(const string filename)
108{
109  // use leaf nodes of the original spatial hiearrchy as occludees
110
111  mSceneGraph = new SceneGraph;
112
113 
114  Parser *parser;
115
116  if (strstr(filename.c_str(), ".x3d"))
117    parser = new X3dParser;
118  else
119    parser = new UnigraphicsParser;
120
121  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
122 
123  delete parser;
124
125  return result;
126}
127
128bool
129Preprocessor::ExportPreprocessedData(const string filename)
130{
131  return false;
132}
133
134bool
135Preprocessor::BuildKdTree()
136{
137  mKdTree = new KdTree;
138  // add mesh instances of the scene graph to the root of the tree
139  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
140  mSceneGraph->CollectObjects(&root->mObjects);
141 
142  mKdTree->Construct();
143  return true;
144}
145
146void
147Preprocessor::KdTreeStatistics(ostream &s)
148{
149  s<<mKdTree->GetStatistics();
150}
151
152void
153Preprocessor::BspTreeStatistics(ostream &s)
154{
155        s << mBspTree->GetStatistics();
156}
157
158bool
159Preprocessor::Export( const string filename,
160                      const bool scene,
161                      const bool kdtree,
162                          const bool bsptree
163                      )
164{
165  Exporter *exporter = Exporter::GetExporter(filename);
166
167  if (exporter) {
168    if (scene)
169      exporter->ExportScene(mSceneGraph->mRoot);
170
171    if (kdtree) {
172      exporter->SetWireframe();
173      exporter->ExportKdTree(*mKdTree);
174    }
175
176        if (bsptree) {
177                //exporter->SetWireframe();
178                exporter->ExportBspTree(*mBspTree);
179        }
180
181    delete exporter;
182    return true;
183  }
184
185  return false;
186}
Note: See TracBrowser for help on using the repository browser.