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

Revision 444, 5.2 KB checked in by mattausch, 19 years ago (diff)

fixed error in ray to vssray conversion

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