1 | #include "SamplingPreprocessor.h"
|
---|
2 | #include "VssPreprocessor.h"
|
---|
3 | #include "RssPreprocessor.h"
|
---|
4 | #include "ExactPreprocessor.h"
|
---|
5 | #include "Parser.h"
|
---|
6 | #include "UnigraphicsParser.h"
|
---|
7 | #include "X3dParser.h"
|
---|
8 | #include "Environment.h"
|
---|
9 | #include "Camera.h"
|
---|
10 | #include "MeshKdTree.h"
|
---|
11 | #include "Exporter.h"
|
---|
12 | #include "ViewCell.h"
|
---|
13 | #include "SceneGraph.h"
|
---|
14 | #include "BoostPreprocessorThread.h"
|
---|
15 | #include "RenderSampler.h"
|
---|
16 | #include "ResourceManager.h"
|
---|
17 | #include "GlRenderer.h"
|
---|
18 |
|
---|
19 | #define USE_EXE_PATH false
|
---|
20 |
|
---|
21 | #include <crtdbg.h>
|
---|
22 |
|
---|
23 | using namespace GtpVisibilityPreprocessor;
|
---|
24 |
|
---|
25 | Preprocessor *preprocessor = NULL;
|
---|
26 | GlRenderWidget *renderWidget = NULL;
|
---|
27 |
|
---|
28 |
|
---|
29 | void Cleanup()
|
---|
30 | {
|
---|
31 | DEL_PTR(renderWidget);
|
---|
32 | DEL_PTR(preprocessor);
|
---|
33 |
|
---|
34 | Environment::DelSingleton();
|
---|
35 | MeshManager::DelSingleton();
|
---|
36 | MaterialManager::DelSingleton();
|
---|
37 | }
|
---|
38 |
|
---|
39 |
|
---|
40 | void DisplayWidget()
|
---|
41 | {
|
---|
42 | // note matt: capsulate qt dependent code as good as possible
|
---|
43 | renderWidget =
|
---|
44 | new GlRenderWidget(preprocessor->mSceneGraph,
|
---|
45 | preprocessor->mViewCellsManager,
|
---|
46 | preprocessor->mKdTree);
|
---|
47 |
|
---|
48 | renderWidget->Show();
|
---|
49 |
|
---|
50 | #if QT_ENABLED
|
---|
51 |
|
---|
52 | // create a qt application first (must be created before any opengl widget ...)
|
---|
53 | app = new QApplication(argc, argv);
|
---|
54 |
|
---|
55 | if (!QGLFormat::hasOpenGL() || !QGLPixelBuffer::hasOpenGLPbuffers()) {
|
---|
56 | QMessageBox::information(0, "OpenGL pbuffers",
|
---|
57 | "This system does not support OpenGL/pbuffers.",
|
---|
58 | QMessageBox::Ok);
|
---|
59 | return -1;
|
---|
60 | }
|
---|
61 |
|
---|
62 | // note matt: capsulate qt dependent code as good as possible
|
---|
63 | rendererWidget =
|
---|
64 | new GlRendererWidget(p->mSceneGraph, p->mViewCellsManager, p->mKdTree);
|
---|
65 |
|
---|
66 | rendererWidget->resize(640, 480);
|
---|
67 | rendererWidget->show();
|
---|
68 |
|
---|
69 | if (0 && p->GetRenderer())
|
---|
70 | {
|
---|
71 | cout<<"CONNECTING"<<endl;
|
---|
72 | QObject::connect(p->GetRenderer(),
|
---|
73 | SIGNAL(UpdatePvsErrorItem(int i, GlRendererBuffer::PvsErrorEntry &)),
|
---|
74 | rendererWidget->mControlWidget,
|
---|
75 | SLOT(UpdatePvsErrorItem(int i,
|
---|
76 | GlRendererBuffer::PvsErrorEntry &)));
|
---|
77 |
|
---|
78 | cout<<"CONNECTED"<<endl;
|
---|
79 | }
|
---|
80 | #endif
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | int
|
---|
85 | main(int argc, char **argv)
|
---|
86 | {
|
---|
87 |
|
---|
88 | //Now just call this function at the start of your program and if you're
|
---|
89 | //compiling in debug mode (F5), any leaks will be displayed in the Output
|
---|
90 | //window when the program shuts down. If you're not in debug mode this will
|
---|
91 | //be ignored. Use it as you will!
|
---|
92 | //note: from GDNet Direct [3.8.04 - 3.14.04] void detectMemoryLeaks() {
|
---|
93 | _CrtSetDbgFlag(_CRTDBG_LEAK_CHECK_DF|_CRTDBG_ALLOC_MEM_DF);
|
---|
94 | _CrtSetReportMode(_CRT_ASSERT,_CRTDBG_MODE_FILE);
|
---|
95 | _CrtSetReportFile(_CRT_ASSERT,_CRTDBG_FILE_STDERR);
|
---|
96 |
|
---|
97 | int returnCode = 0;
|
---|
98 |
|
---|
99 | InitTiming();
|
---|
100 |
|
---|
101 | Debug.open("debug.log");
|
---|
102 |
|
---|
103 | Environment::GetSingleton()->Parse(argc, argv, USE_EXE_PATH);
|
---|
104 | MeshKdTree::ParseEnvironment();
|
---|
105 |
|
---|
106 | char buff[128];
|
---|
107 | Environment::GetSingleton()->GetStringValue("Preprocessor.type", buff);
|
---|
108 | string preprocessorType(buff);
|
---|
109 |
|
---|
110 | if (preprocessorType == "vss")
|
---|
111 | {
|
---|
112 | preprocessor = new VssPreprocessor();
|
---|
113 | }
|
---|
114 | else
|
---|
115 | {
|
---|
116 | if (preprocessorType == "rss")
|
---|
117 | {
|
---|
118 | preprocessor = new RssPreprocessor();
|
---|
119 | }
|
---|
120 | else
|
---|
121 | {
|
---|
122 | if (preprocessorType == "exact")
|
---|
123 | {
|
---|
124 | preprocessor = new ExactPreprocessor();
|
---|
125 | }
|
---|
126 | else
|
---|
127 | {
|
---|
128 | if (preprocessorType == "sampling")
|
---|
129 | {
|
---|
130 | preprocessor = new SamplingPreprocessor();
|
---|
131 | }
|
---|
132 | else
|
---|
133 | {
|
---|
134 | if (preprocessorType == "render")
|
---|
135 | {
|
---|
136 | preprocessor = new RenderSampler();
|
---|
137 | }
|
---|
138 | else {
|
---|
139 | Environment::DelSingleton();
|
---|
140 | cerr<<"Unknown preprocessor type"<<endl;
|
---|
141 | Debug<<"Unknown preprocessor type"<<endl;
|
---|
142 | exit(1);
|
---|
143 | }
|
---|
144 | }
|
---|
145 | }
|
---|
146 | }
|
---|
147 | }
|
---|
148 |
|
---|
149 |
|
---|
150 | //-- load scene
|
---|
151 |
|
---|
152 | Environment::GetSingleton()->GetStringValue("Scene.filename", buff);
|
---|
153 | string filename(buff);
|
---|
154 | preprocessor->LoadScene(filename);
|
---|
155 |
|
---|
156 | //-- build kd tree from scene geometry
|
---|
157 |
|
---|
158 | preprocessor->BuildKdTree();
|
---|
159 | preprocessor->KdTreeStatistics(cout);
|
---|
160 |
|
---|
161 | // parse view cells related options
|
---|
162 | preprocessor->PrepareViewCells();
|
---|
163 |
|
---|
164 | // p->mSceneGraph->Export("soda.x3d");
|
---|
165 | if (0) {
|
---|
166 | preprocessor->Export(filename + "-out.x3d", true, false, false);
|
---|
167 | preprocessor->Export(filename + "-kdtree.x3d", false, true, false);
|
---|
168 | }
|
---|
169 |
|
---|
170 |
|
---|
171 | // create a preprocessor thread
|
---|
172 | //PreprocessorThread *pt = new PreprocessorThread(p, app);
|
---|
173 | BoostPreprocessorThread pt(preprocessor);
|
---|
174 |
|
---|
175 | if (preprocessor->mUseGlRenderer || preprocessor->mUseGlDebugger)
|
---|
176 | {
|
---|
177 | // display the render widget
|
---|
178 | DisplayWidget();
|
---|
179 |
|
---|
180 | // create and run the preprocessor application in a parallel thread
|
---|
181 | pt.InitThread();
|
---|
182 | pt.RunThread();
|
---|
183 | }
|
---|
184 | else
|
---|
185 | {
|
---|
186 | // just call the mail method -> will be executed in the main thread
|
---|
187 | pt.Main();
|
---|
188 | }
|
---|
189 |
|
---|
190 |
|
---|
191 | Cleanup();
|
---|
192 |
|
---|
193 | return returnCode;
|
---|
194 | }
|
---|
195 |
|
---|