[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"
|
---|
[445] | 9 | #include "ViewCellBsp.h"
|
---|
| 10 | #include "VspBspTree.h"
|
---|
| 11 | #include "VspKdTree.h"
|
---|
[372] | 12 |
|
---|
| 13 | Preprocessor::Preprocessor():
|
---|
| 14 | mKdTree(NULL),
|
---|
[409] | 15 | mBspTree(NULL),
|
---|
[422] | 16 | mVspKdTree(NULL),
|
---|
[445] | 17 | mVspBspTree(NULL),
|
---|
[439] | 18 | mViewCellsManager(NULL)
|
---|
[308] | 19 | {
|
---|
[372] | 20 | }
|
---|
| 21 |
|
---|
| 22 |
|
---|
| 23 | Preprocessor::~Preprocessor()
|
---|
| 24 | {
|
---|
[462] | 25 | DEL_PTR(mViewCellsManager);
|
---|
| 26 |
|
---|
[372] | 27 | DEL_PTR(mBspTree);
|
---|
| 28 | DEL_PTR(mKdTree);
|
---|
[439] | 29 | DEL_PTR(mVspKdTree);
|
---|
[445] | 30 | DEL_PTR(mVspBspTree);
|
---|
[372] | 31 | }
|
---|
| 32 |
|
---|
[387] | 33 | int
|
---|
[419] | 34 | SplitFilenames(const string str, vector<string> &filenames)
|
---|
[387] | 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));
|
---|
[440] | 48 | return (int)filenames.size();
|
---|
[387] | 49 | }
|
---|
| 50 |
|
---|
[372] | 51 | bool
|
---|
| 52 | Preprocessor::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;
|
---|
[387] | 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;
|
---|
[372] | 70 |
|
---|
[387] | 71 | cout<<filename<<endl;
|
---|
| 72 | result = parser->ParseFile(filename, &mSceneGraph->mRoot);
|
---|
[372] | 73 |
|
---|
[387] | 74 | delete parser;
|
---|
[372] | 75 |
|
---|
[387] | 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 | }
|
---|
[372] | 94 |
|
---|
| 95 |
|
---|
[387] | 96 | if (result) {
|
---|
[372] | 97 | mSceneGraph->AssignObjectIds();
|
---|
[387] | 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 |
|
---|
[372] | 105 |
|
---|
| 106 | return result;
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 | bool
|
---|
| 110 | Preprocessor::ExportPreprocessedData(const string filename)
|
---|
| 111 | {
|
---|
| 112 | return false;
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | bool
|
---|
| 116 | Preprocessor::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 |
|
---|
| 127 | void
|
---|
| 128 | Preprocessor::KdTreeStatistics(ostream &s)
|
---|
| 129 | {
|
---|
| 130 | s<<mKdTree->GetStatistics();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | void
|
---|
| 134 | Preprocessor::BspTreeStatistics(ostream &s)
|
---|
| 135 | {
|
---|
| 136 | s << mBspTree->GetStatistics();
|
---|
| 137 | }
|
---|
| 138 |
|
---|
| 139 | bool
|
---|
| 140 | Preprocessor::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 | }
|
---|
[429] | 168 |
|
---|
[463] | 169 | bool Preprocessor::PrepareViewCells()
|
---|
| 170 | {
|
---|
[439] | 171 | //-- parse type of view cell container
|
---|
| 172 | char viewCellsStr[64];
|
---|
| 173 | environment->GetStringValue("ViewCells.type", viewCellsStr);
|
---|
| 174 |
|
---|
[445] | 175 | int constructionSamples = 0;
|
---|
| 176 |
|
---|
[439] | 177 | if (strcmp(viewCellsStr, "kdTree") == 0)
|
---|
| 178 | {
|
---|
[440] | 179 | mViewCellsManager = new KdViewCellsManager(mKdTree);
|
---|
[439] | 180 | }
|
---|
[448] | 181 | else if (strcmp(viewCellsStr, "bspTree") == 0)
|
---|
[439] | 182 | {
|
---|
[441] | 183 | mBspTree = new BspTree();
|
---|
| 184 |
|
---|
[448] | 185 | Debug << "view cell type: Bsp" << endl;
|
---|
| 186 |
|
---|
[445] | 187 | environment->GetIntValue("BspTree.Construction.samples", constructionSamples);
|
---|
| 188 | mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples);
|
---|
[439] | 189 | }
|
---|
[448] | 190 | else if (strcmp(viewCellsStr, "vspBspTree") == 0)
|
---|
[439] | 191 | {
|
---|
[445] | 192 | mVspBspTree = new VspBspTree();
|
---|
| 193 |
|
---|
[448] | 194 | Debug << "view cell type: VspBsp" << endl;
|
---|
| 195 |
|
---|
[445] | 196 | environment->GetIntValue("VspBspTree.Construction.samples", constructionSamples);
|
---|
| 197 | mViewCellsManager = new VspBspViewCellsManager(mVspBspTree, constructionSamples);
|
---|
[439] | 198 | }
|
---|
[445] | 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 | }
|
---|
[439] | 206 | else if (strcmp(viewCellsStr, "sceneDependent") == 0)
|
---|
| 207 | {
|
---|
| 208 | //TODO
|
---|
[445] | 209 | mBspTree = new BspTree();
|
---|
[440] | 210 |
|
---|
[448] | 211 | Debug << "view cell type: Bsp" << endl;
|
---|
[445] | 212 | environment->GetIntValue("BspTree.Construction.samples", constructionSamples);
|
---|
| 213 | mViewCellsManager = new BspViewCellsManager(mBspTree, constructionSamples);
|
---|
[439] | 214 | }
|
---|
| 215 | else
|
---|
| 216 | {
|
---|
| 217 | cerr<<"Wrong view cells type" << viewCellsStr << endl;
|
---|
| 218 | exit(1);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[440] | 221 | int postProcessSamples = 0;
|
---|
| 222 | int visSamples = 0;
|
---|
| 223 |
|
---|
| 224 | environment->GetIntValue("ViewCells.PostProcessing.samples", postProcessSamples);
|
---|
[445] | 225 | environment->GetIntValue("ViewCells.Visualization.samples", visSamples);
|
---|
[440] | 226 |
|
---|
| 227 | mViewCellsManager->SetPostProcessSamples(postProcessSamples);
|
---|
| 228 | mViewCellsManager->SetVisualizationSamples(visSamples);
|
---|
| 229 |
|
---|
[444] | 230 | //Debug << "Visualization samples: " << mViewCellsManager->GetVisualizationSamples() << endl;
|
---|
[440] | 231 |
|
---|
[463] | 232 | //-- parse view cells construction method
|
---|
[440] | 233 |
|
---|
[463] | 234 | bool loadViewCells = false;
|
---|
| 235 | environment->GetBoolValue("ViewCells.loadFromFile", loadViewCells);
|
---|
[439] | 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 | }
|
---|
[463] | 245 |
|
---|
| 246 | return true;
|
---|
[429] | 247 | } |
---|