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