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

Revision 366, 3.2 KB checked in by mattausch, 19 years ago (diff)

some ideas abou saving bspleaves with the ray and t

RevLine 
[162]1#include "SceneGraph.h"
2#include "Exporter.h"
3#include "UnigraphicsParser.h"
[170]4#include "X3dParser.h"
[65]5#include "Preprocessor.h"
[235]6#include "ViewCell.h"
7#include "Environment.h"
[65]8
[262]9Preprocessor::Preprocessor():
10mKdTree(NULL),
[366]11mBspTree(NULL)
[262]12{
13}
[261]14
[339]15
[261]16Preprocessor::~Preprocessor()
[308]17{
18        DeleteViewCells();
19               
20        DEL_PTR(mBspTree);
21        DEL_PTR(mKdTree);
[261]22}
23
[162]24bool
[261]25Preprocessor::LoadViewCells(const string filename)
[162]26{
[312]27        X3dParser parser;
[313]28        int maxViewCells = 0;
[312]29        environment->GetFloatValue("ViewCells.height", parser.mViewCellHeight);
[313]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;
[162]44}
[65]45
[339]46bool
47Preprocessor::ParseViewCellsOptions()
[310]48{
49        // parse type of view cells
50        char viewCellsStr[64];
[329]51        environment->GetStringValue("ViewCells.hierarchy", viewCellsStr);
[310]52
53        if (strcmp(viewCellsStr, "bspTree") == 0)
[366]54                ViewCell::sHierarchy = ViewCell::BSP;
[310]55        else if (strcmp(viewCellsStr, "kdTree") == 0)
[366]56                ViewCell::sHierarchy = ViewCell::KD;
[310]57        else if (strcmp(viewCellsStr, "sceneDependent") == 0)
[329]58        {
59                //TODO
60        }
[310]61        else
62        {
63                cerr<<"Wrong view cells type" << viewCellsStr << endl;
64                exit(1);
65        }
66
67        return true;
68}
69
[308]70void Preprocessor::DeleteViewCells()
71{
72        for (int i = 0; i < mViewCells.size(); ++ i)
73                delete mViewCells[i]->GetMesh();
74
75        CLEAR_CONTAINER(mViewCells);
76}
77
[162]78bool
[261]79Preprocessor::GenerateViewCells()
[162]80{
[263]81        // TODO
82        // HACK: derive view cells from the scene objects
83        ObjectContainer objects;
84
85        int maxViewCells = 0;
[313]86        environment->GetIntValue("ViewCells.maxViewCells", maxViewCells);
[263]87
88        mSceneGraph->CollectObjects(&objects);
89        ViewCell::DeriveViewCells(objects, mViewCells, maxViewCells);
90
91        return true;
[162]92}
[65]93
[162]94bool
95Preprocessor::LoadScene(const string filename)
96{
97  // use leaf nodes of the original spatial hiearrchy as occludees
98
99  mSceneGraph = new SceneGraph;
[170]100
101 
102  Parser *parser;
103
104  if (strstr(filename.c_str(), ".x3d"))
105    parser = new X3dParser;
106  else
107    parser = new UnigraphicsParser;
108
[162]109  bool result = parser->ParseFile(filename, &mSceneGraph->mRoot);
[339]110
111       
112       
[261]113  delete parser;
114
[339]115        if (result)
116                mSceneGraph->AssignObjectIds();
117       
[162]118  return result;
119}
120
121bool
122Preprocessor::ExportPreprocessedData(const string filename)
123{
124  return false;
125}
126
127bool
128Preprocessor::BuildKdTree()
129{
130  mKdTree = new KdTree;
131  // add mesh instances of the scene graph to the root of the tree
132  KdLeaf *root = (KdLeaf *)mKdTree->GetRoot();
[176]133  mSceneGraph->CollectObjects(&root->mObjects);
[65]134 
[162]135  mKdTree->Construct();
136  return true;
137}
[65]138
[162]139void
140Preprocessor::KdTreeStatistics(ostream &s)
[65]141{
[162]142  s<<mKdTree->GetStatistics();
[65]143}
[162]144
[234]145void
146Preprocessor::BspTreeStatistics(ostream &s)
147{
[235]148        s << mBspTree->GetStatistics();
[234]149}
[162]150
151bool
152Preprocessor::Export( const string filename,
[339]153                                                                                        const bool scene,
154                                                                                        const bool kdtree,
155                                                                                        const bool bsptree
156                                                                                        )
[162]157{
158  Exporter *exporter = Exporter::GetExporter(filename);
[339]159       
[162]160  if (exporter) {
161    if (scene)
162      exporter->ExportScene(mSceneGraph->mRoot);
163
164    if (kdtree) {
165      exporter->SetWireframe();
166      exporter->ExportKdTree(*mKdTree);
167    }
168
[242]169        if (bsptree) {
[264]170                //exporter->SetWireframe();
[242]171                exporter->ExportBspTree(*mBspTree);
172        }
173
[162]174    delete exporter;
175    return true;
176  }
177
178  return false;
[339]179}
Note: See TracBrowser for help on using the repository browser.