source: trunk/VUT/GtpVisibilityPreprocessor/src/main.cpp @ 322

Revision 322, 4.1 KB checked in by mattausch, 19 years ago (diff)
Line 
1#include "SamplingPreprocessor.h"
2#include "ExactPreprocessor.h"
3#include "Parser.h"
4#include "UnigraphicsParser.h"
5#include "X3dParser.h"
6#include "Environment.h"
7#include "Camera.h"
8#include "MeshKdTree.h"
9#include "Exporter.h"
10#include "X3dExporter.h" // delete later
11#include "ViewCell.h"
12#include "SceneGraph.h"
13
14#define USE_EXE_PATH false
15
16
17int
18main(int argc, const char **argv)
19{
20  Debug.open("debug.log");
21  environment = new Environment;
22  environment->Parse(argc, argv, USE_EXE_PATH);
23  MeshKdTree::ParseEnvironment();
24  BspTree::ParseEnvironment();
25
26  Preprocessor *p =
27    new SamplingPreprocessor();
28
29  char buff[128];
30  environment->GetStringValue("Scene.filename", buff);
31  string filename(buff);
32
33  p->LoadScene(filename);
34
35  p->BuildKdTree();
36  p->KdTreeStatistics(cout);
37 
38  // parse view cell hierarchy options
39  p->ParseViewCellsOptions();
40
41  if (p->mViewCellsType == Preprocessor::BSP_VIEW_CELLS &&
42          !(BspTree::sConstructionMethod == BspTree::FROM_RAYS)) // construct tree later
43  {
44          if (BspTree::sConstructionMethod == BspTree::FROM_INPUT_VIEW_CELLS)
45          {
46                   // view cells input file name
47                  environment->GetStringValue("ViewCells.filename", buff);
48                  string vcFilename(buff);
49
50                  if (vcFilename != "")
51                          p->LoadViewCells(vcFilename);
52                  else
53                          p->GenerateViewCells();
54
55                  Debug << "Viewcells loaded / generated. Number of view cells: " << (int)p->mViewCells.size() << endl;
56          }
57       
58          p->BuildBspTree();
59          p->Export("vc_bsptree.x3d", false, false, true);
60          p->BspTreeStatistics(Debug);
61
62          bool exportSplits = false;
63          environment->GetBoolValue("BspTree.exportSplits", exportSplits);
64
65          // export the bsp splits
66          if (exportSplits)
67          {
68                  Exporter *exporter = Exporter::GetExporter("bsp_splits.x3d");
69
70                  if (exporter)
71                  {     
72                          Material m;
73                          m.mDiffuseColor = RgbColor(1, 0, 0);
74                          exporter->SetForcedMaterial(m);
75                          exporter->SetWireframe();
76                          exporter->ExportBspSplits(*p->mBspTree);
77
78                          // take forced material because does not load for big scenes otherwise
79                          m.mDiffuseColor = RgbColor(0, 1, 0);
80                          exporter->SetForcedMaterial(m);
81                          exporter->SetFilled();
82
83                          exporter->ResetForcedMaterial();
84
85                          if (1)
86                          {
87                                  ObjectContainer objects;
88                                  p->mSceneGraph->CollectObjects(&objects);
89                  Material m;//= RandomMaterial();
90                                  m.mDiffuseColor = RgbColor(0, 0, 1);
91                                  exporter->SetForcedMaterial(m);
92                 
93                                  for (int j = 0; j < objects.size(); ++ j)
94                                           exporter->ExportIntersectable(objects[j]);
95                       
96                                  delete exporter;
97                          }
98                  }
99          }
100#if 0
101          //-- export the complementary view cells
102          // i.e., the view cells not associated with leafs in the tree.
103          Exporter *exporter = Exporter::GetExporter("viewcells_compl.x3d");
104
105          ViewCellContainer::iterator vc_compl_it;
106          ViewCellContainer vc_compl(p->mViewCells.size() + X3dExporter::foundViewCells.size());
107 
108          sort(p->mViewCells.begin(), p->mViewCells.end());
109
110          vc_compl_it = set_difference(p->mViewCells.begin(), p->mViewCells.end(),
111                  X3dExporter::foundViewCells.begin(), X3dExporter::foundViewCells.end(), vc_compl.begin());
112
113          vc_compl.erase(vc_compl_it, vc_compl.end());
114 
115
116          if (exporter)
117          {     
118                  Debug << "Exporting complementary view cells" << endl;
119                  exporter->ExportViewCells(vc_compl); // export view cells
120                  delete exporter;
121          }
122#endif
123  }
124
125  //  p->mSceneGraph->Export("soda.x3d");
126  if (0) {
127    p->Export(filename + "-out.x3d", true, false, false);
128    p->Export(filename + "-kdtree.x3d", false, true, false);   
129  }
130 
131   
132  if (1) {
133    p->ComputeVisibility();
134    p->ExportPreprocessedData("scene.vis");
135  }
136
137  if (1) {
138    Camera camera;
139    //camera.LookAtBox(p->mKdTree->GetBox());
140        camera.LookInBox(p->mKdTree->GetBox());
141        camera.SetPosition(camera.mPosition + Vector3(0,300,0));
142    camera.SnapImage("camera.jpg", p->mKdTree);
143
144   
145    camera.LookInBox(p->mKdTree->GetBox());
146    camera.SetPosition(camera.mPosition - Vector3(0,100,0));
147    camera.SnapImage("camera2.png", p->mKdTree);
148  }
149
150  // clean up
151  DEL_PTR(p);
152  DEL_PTR(environment);
153
154  return 0;
155}
156
Note: See TracBrowser for help on using the repository browser.