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

Revision 463, 5.7 KB checked in by bittner, 19 years ago (diff)

removed mT from vss ray

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#include "ViewCellsManager.h"
9#include "ViewCellBsp.h"
10#include "VspBspTree.h"
11#include "VspKdTree.h"
12
13Preprocessor::Preprocessor():
14mKdTree(NULL),
15mBspTree(NULL),
16mVspKdTree(NULL),
17mVspBspTree(NULL),
18mViewCellsManager(NULL)
19{
20}
21
22
23Preprocessor::~Preprocessor()
24{
25        DEL_PTR(mViewCellsManager);
26
27        DEL_PTR(mBspTree);
28        DEL_PTR(mKdTree);
29        DEL_PTR(mVspKdTree);
30        DEL_PTR(mVspBspTree);
31}
32
33int
34SplitFilenames(const string str, vector<string> &filenames)
35{
36        int pos = 0;
37
38        while(1) {
39                int npos = str.find(';', pos);
40               
41                if (npos < 0 || npos - pos < 1)
42                        break;
43                filenames.push_back(string(str, pos, npos - pos));
44                pos = npos + 1;
45        }
46       
47        filenames.push_back(string(str, pos, str.size() - pos));
48        return (int)filenames.size();
49}
50
51bool
52Preprocessor::LoadScene(const string filename)
53{
54  // use leaf nodes of the original spatial hiearrchy as occludees
55
56  mSceneGraph = new SceneGraph;
57
58 
59  Parser *parser;
60        vector<string> filenames;
61        int files = SplitFilenames(filename, filenames);
62        cout<<files<<endl;
63        bool result = false;
64        if (files == 1) {
65               
66                if (strstr(filename.c_str(), ".x3d"))
67                        parser = new X3dParser;
68                else
69                        parser = new UnigraphicsParser;
70
71                cout<<filename<<endl;
72                result = parser->ParseFile(filename, &mSceneGraph->mRoot);
73
74                delete parser;
75
76        } else {
77                // root for different files
78                mSceneGraph->mRoot = new SceneGraphNode;
79                for (int i= 0; i < filenames.size(); i++) {
80                        if (strstr(filenames[i].c_str(), ".x3d"))
81                                parser = new X3dParser;
82                        else
83                                parser = new UnigraphicsParser;
84                       
85                        SceneGraphNode *node;
86                        if (parser->ParseFile(filenames[i], &node)) {
87                                mSceneGraph->mRoot->mChildren.push_back(node);
88                                // at least one file parsed
89                                result = true;
90                        }
91                        delete parser;
92                }
93        }
94       
95
96        if (result) {
97                mSceneGraph->AssignObjectIds();
98                int intersectables, faces;
99                mSceneGraph->GetStatistics(intersectables, faces);
100                cout<<filename<<" parsed successfully."<<endl;
101                cout<<"#NUM_OBJECTS (Total numner of objects)\n"<<intersectables<<endl;
102                cout<<"#NUM_FACES (Total numner of faces)\n"<<faces<<endl;
103        }
104
105       
106  return result;
107}
108
109bool
110Preprocessor::ExportPreprocessedData(const string filename)
111{
112  return false;
113}
114
115bool
116Preprocessor::BuildKdTree()
117{
118  mKdTree = new KdTree;
119  // add mesh instances of the scene graph to the root of the tree
120  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
121  mSceneGraph->CollectObjects(&root->mObjects);
122 
123  mKdTree->Construct();
124  return true;
125}
126
127void
128Preprocessor::KdTreeStatistics(ostream &s)
129{
130  s<<mKdTree->GetStatistics();
131}
132
133void
134Preprocessor::BspTreeStatistics(ostream &s)
135{
136        s << mBspTree->GetStatistics();
137}
138
139bool
140Preprocessor::Export( const string filename,
141                                                                                        const bool scene,
142                                                                                        const bool kdtree,
143                                                                                        const bool bsptree
144                                                                                        )
145{
146  Exporter *exporter = Exporter::GetExporter(filename);
147       
148  if (exporter) {
149    if (scene)
150      exporter->ExportScene(mSceneGraph->mRoot);
151
152    if (kdtree) {
153      exporter->SetWireframe();
154      exporter->ExportKdTree(*mKdTree);
155    }
156
157        if (bsptree) {
158                //exporter->SetWireframe();
159                exporter->ExportBspTree(*mBspTree);
160        }
161
162    delete exporter;
163    return true;
164  }
165
166  return false;
167}
168
169bool Preprocessor::PrepareViewCells()
170{
171        //-- parse type of view cell container
172        char viewCellsStr[64];
173        environment->GetStringValue("ViewCells.type", viewCellsStr);
174
175        int constructionSamples = 0;
176
177        if (strcmp(viewCellsStr, "kdTree") == 0)
178        {
179                mViewCellsManager = new KdViewCellsManager(mKdTree);
180        }
181        else if (strcmp(viewCellsStr, "bspTree") == 0)
182        {
183                mBspTree = new BspTree();
184
185                Debug << "view cell type: Bsp" << endl;
186
187                environment->GetIntValue("BspTree.Construction.samples", constructionSamples);
188                mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples);
189        }
190        else if (strcmp(viewCellsStr, "vspBspTree") == 0)
191        {
192                mVspBspTree = new VspBspTree();
193
194                Debug << "view cell type: VspBsp" << endl;
195
196                environment->GetIntValue("VspBspTree.Construction.samples", constructionSamples);
197                mViewCellsManager = new VspBspViewCellsManager(mVspBspTree, constructionSamples);
198        }
199        else if (strcmp(viewCellsStr, "vspKdTree") == 0)
200        {
201                mVspKdTree = new VspKdTree();           
202       
203                environment->GetIntValue("VspKdTree.Construction.samples", constructionSamples);
204        mViewCellsManager = new VspKdViewCellsManager(mVspKdTree, constructionSamples);
205        }
206        else if (strcmp(viewCellsStr, "sceneDependent") == 0)
207        {
208                //TODO
209                mBspTree = new BspTree();
210
211                Debug << "view cell type: Bsp" << endl;
212                environment->GetIntValue("BspTree.Construction.samples", constructionSamples);
213                mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples);
214        }
215        else
216        {
217                cerr<<"Wrong view cells type" << viewCellsStr << endl;
218                exit(1);
219        }
220
221        int postProcessSamples = 0;
222        int visSamples = 0;
223
224        environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples);
225        environment->GetIntValue("ViewCells.Visualization.samples", visSamples);
226
227        mViewCellsManager->SetPostProcessSamples(postProcessSamples);
228        mViewCellsManager->SetVisualizationSamples(visSamples);
229
230        //Debug << "Visualization samples: " << mViewCellsManager->GetVisualizationSamples() << endl;
231
232        //-- parse view cells construction method
233
234        bool loadViewCells = false;
235        environment->GetBoolValue("ViewCells.loadFromFile", loadViewCells);
236
237        //-- load view cells from file if requested
238        if (loadViewCells)
239        {
240                char buff[100];
241                environment->GetStringValue("ViewCells.filename", buff);
242                string vcFilename(buff);
243                mViewCellsManager->LoadViewCells(vcFilename);
244        }
245
246        return true;
247}
Note: See TracBrowser for help on using the repository browser.